Re: [PATCH v6] crypto: scompress: remove memcpy if sg_nents is 1 and pages are lowmem
From: Barry Song
Date: Fri Mar 01 2024 - 06:18:05 EST
On Fri, Mar 1, 2024 at 11:28 PM Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx> wrote:
>
> On Thu, Feb 22, 2024 at 03:06:17PM +1300, Barry Song wrote:
> >
> > - scatterwalk_map_and_copy(scratch->src, req->src, 0, req->slen, 0);
> > + if (sg_nents(req->src) == 1 && !PageHighMem(sg_page(req->src))) {
> > + src = page_to_virt(sg_page(req->src)) + req->src->offset;
>
> Incidentally this made me look at other uses of PageHighMem in
> the kernel.
>
> The one in copy_page_from_iter_atomic looks buggy because it assumes
> that the kmap never maps a page if PageHighMem is false, which is not
> the case for CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP.
You are right. This needs to be fixed.
>
> > @@ -152,8 +165,12 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
> > ret = -ENOSPC;
> > goto out;
> > }
> > - scatterwalk_map_and_copy(scratch->dst, req->dst, 0, req->dlen,
> > - 1);
> > + if (dst == scratch->dst) {
> > + scatterwalk_map_and_copy(scratch->dst, req->dst, 0,
> > + req->dlen, 1);
> > + } else {
> > + flush_dcache_page(sg_page(req->dst));
>
> I think this is still wrong for the > PAGE_SIZE case. The existing
> code flushes each page sequentially but the new code only flushes the
> first page.
right, can it be fixed like the below?
diff --git a/crypto/scompress.c b/crypto/scompress.c
index 185d2359f28b..d85f0318f273 100644
--- a/crypto/scompress.c
+++ b/crypto/scompress.c
@@ -169,7 +169,11 @@ static int scomp_acomp_comp_decomp(struct
acomp_req *req, int dir)
scatterwalk_map_and_copy(scratch->dst, req->dst, 0,
req->dlen, 1);
} else {
- flush_dcache_page(sg_page(req->dst));
+ int nr_pages = DIV_ROUND_UP(req->dst->offset +
req->dlen, PAGE_SIZE);
+ int i;
+
+ for (i = 0; i < nr_pages; i++)
+ flush_dcache_page(sg_page(req->dst) + i);
}
}
out:
>
> Thanks,
> --
> Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
> Home Page: http://gondor.apana.org.au/~herbert/
> PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
>
Thanks
Barry