From: Herbert Xu Subject: Re: [PATCH v2 07/21] crypto: shash, caam: Make use of the new sg_map helper function Date: Fri, 28 Apr 2017 14:30:39 +0800 Message-ID: <20170428063039.GB6817@gondor.apana.org.au> References: <1493144468-22493-1-git-send-email-logang@deltatee.com> <1493144468-22493-8-git-send-email-logang@deltatee.com> <20170427035603.GA32212@gondor.apana.org.au> <94123cbf-3287-f05e-7267-0bcf08ab0a8b@deltatee.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org, dm-devel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org, target-devel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Christoph Hellwig , devel-gWbeCf7V1WCQmaza687I9mD2FQJk+8+b@public.gmane.org, "James E.J. Bottomley" , linux-scsi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-nvdimm-hn68Rpc1hR1g9hUCZPvPmw@public.gmane.org, linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Sumit Semwal , open-iscsi-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org, linux-media-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org, sparmaintainer-GLv8BlqOqDDQT0dZR+AlfA@public.gmane.org, linux-raid-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, megaraidlinux.pdl-dY08KVG/lbpWk0Htik3J/w@public.gmane.org, Jens Axboe , "Martin K. Petersen" , netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Matthew Wilcox , linux-mmc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-crypto-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Greg Kroah-Hartman , "David S. Miller" To: Logan Gunthorpe Return-path: Content-Disposition: inline In-Reply-To: <94123cbf-3287-f05e-7267-0bcf08ab0a8b-OTvnGxWRz7hWk0Htik3J/w@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces-hn68Rpc1hR1g9hUCZPvPmw@public.gmane.org Sender: "Linux-nvdimm" List-Id: linux-crypto.vger.kernel.org On Thu, Apr 27, 2017 at 09:45:57AM -0600, Logan Gunthorpe wrote: > > > On 26/04/17 09:56 PM, Herbert Xu wrote: > > On Tue, Apr 25, 2017 at 12:20:54PM -0600, Logan Gunthorpe wrote: > >> Very straightforward conversion to the new function in the caam driver > >> and shash library. > >> > >> Signed-off-by: Logan Gunthorpe > >> Cc: Herbert Xu > >> Cc: "David S. Miller" > >> --- > >> crypto/shash.c | 9 ++++++--- > >> drivers/crypto/caam/caamalg.c | 8 +++----- > >> 2 files changed, 9 insertions(+), 8 deletions(-) > >> > >> diff --git a/crypto/shash.c b/crypto/shash.c > >> index 5e31c8d..5914881 100644 > >> --- a/crypto/shash.c > >> +++ b/crypto/shash.c > >> @@ -283,10 +283,13 @@ int shash_ahash_digest(struct ahash_request *req, struct shash_desc *desc) > >> if (nbytes < min(sg->length, ((unsigned int)(PAGE_SIZE)) - offset)) { > >> void *data; > >> > >> - data = kmap_atomic(sg_page(sg)); > >> - err = crypto_shash_digest(desc, data + offset, nbytes, > >> + data = sg_map(sg, 0, SG_KMAP_ATOMIC); > >> + if (IS_ERR(data)) > >> + return PTR_ERR(data); > >> + > >> + err = crypto_shash_digest(desc, data, nbytes, > >> req->result); > >> - kunmap_atomic(data); > >> + sg_unmap(sg, data, 0, SG_KMAP_ATOMIC); > >> crypto_yield(desc->flags); > >> } else > >> err = crypto_shash_init(desc) ?: > > > > Nack. This is an optimisation for the special case of a single > > SG list entry. In fact in the common case the kmap_atomic should > > disappear altogether in the no-highmem case. So replacing it > > with sg_map is not acceptable. > > What you seem to have missed is that sg_map is just a thin wrapper > around kmap_atomic. Perhaps with a future check for a mappable page. > This change should have zero impact on performance. You are right. Indeed the existing code looks buggy as they don't take sg->offset into account when doing the kmap. Could you send me some patches that fix these problems first so that they can be easily backported? Thanks, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt