public inbox for linux-crypto@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Linux Crypto Mailing List <linux-crypto@vger.kernel.org>
Subject: Re: [v4 PATCH 1/2] crypto: scatterwalk - Use nth_page instead of doing it by hand
Date: Sat, 15 Mar 2025 20:31:41 -0700	[thread overview]
Message-ID: <20250316033141.GA117195@sol.localdomain> (raw)
In-Reply-To: <96553040a4b37d8b54b9959e859fc057889dfdac.1741922689.git.herbert@gondor.apana.org.au>

On Fri, Mar 14, 2025 at 11:27:20AM +0800, Herbert Xu wrote:
> Curiously, the Crypto API scatterwalk incremented pages by hand
> rather than using nth_page.  Possibly because scatterwalk predates
> nth_page (the following commit is from the history tree):
> 
> 	commit 3957f2b34960d85b63e814262a8be7d5ad91444d
> 	Author: James Morris <jmorris@intercode.com.au>
> 	Date:   Sun Feb 2 07:35:32 2003 -0800
> 
> 	    [CRYPTO]: in/out scatterlist support for ciphers.
> 
> Fix this by using nth_page.

As I said on v2, this needs an explanation of what it's actually fixing.

> @@ -189,14 +195,18 @@ static inline void scatterwalk_done_dst(struct scatter_walk *walk,
>  	 * reliably optimized out or not.
>  	 */
>  	if (ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE) {
> -		struct page *base_page, *start_page, *end_page, *page;
> +		struct page *base_page;
> +		unsigned int offset;
> +		int start, end, i;
>  
>  		base_page = sg_page(walk->sg);
> -		start_page = base_page + (walk->offset >> PAGE_SHIFT);
> -		end_page = base_page + ((walk->offset + nbytes +
> -					 PAGE_SIZE - 1) >> PAGE_SHIFT);
> -		for (page = start_page; page < end_page; page++)
> -			flush_dcache_page(page);
> +		offset = walk->offset;
> +		start = offset >> PAGE_SHIFT;
> +		end = start + (nbytes >> PAGE_SHIFT);
> +		end += (offset_in_page(offset) + offset_in_page(nbytes) +
> +			PAGE_SIZE - 1) >> PAGE_SHIFT;

The change to how the end page index is calculated is unrelated to the nth_page
fix, and it makes the code slower and harder to understand.  My original code
just rounded the new offset up to a page boundary to get the end page index.

- Eric

  reply	other threads:[~2025-03-16  3:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-14  3:27 [v4 PATCH 0/2] crypto: Use nth_page instead of doing it by hand Herbert Xu
2025-03-14  3:27 ` [v4 PATCH 1/2] crypto: scatterwalk - " Herbert Xu
2025-03-16  3:31   ` Eric Biggers [this message]
2025-03-16  4:28     ` Herbert Xu
2025-03-16  4:42       ` Eric Biggers
2025-03-14  3:27 ` [v4 PATCH 2/2] crypto: hash " Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250316033141.GA117195@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox