Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: Robert Elliott <elliott@hpe.com>
Cc: davem@davemloft.net, linux-crypto@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] crypto: aead/shash - yield at end of operations
Date: Tue, 20 Dec 2022 11:55:19 +0800	[thread overview]
Message-ID: <Y6EyJ3MDOMXZ7Yku@gondor.apana.org.au> (raw)
In-Reply-To: <20221219203733.3063192-3-elliott@hpe.com>

On Mon, Dec 19, 2022 at 02:37:32PM -0600, Robert Elliott wrote:
> Add crypto_yield() calls at the end of all the encrypt and decrypt
> functions to let the scheduler use the CPU after possibly a long
> tenure by the crypto driver.
> 
> This reduces RCU stalls and soft lockups when running crypto
> functions back-to-back that don't have their own yield calls
> (e.g., aligned generic functions).
> 
> Signed-off-by: Robert Elliott <elliott@hpe.com>
> ---
>  crypto/aead.c  |  4 ++++
>  crypto/shash.c | 32 ++++++++++++++++++++++++--------
>  2 files changed, 28 insertions(+), 8 deletions(-)
> 
> diff --git a/crypto/aead.c b/crypto/aead.c
> index 16991095270d..f88378f4d4f5 100644
> --- a/crypto/aead.c
> +++ b/crypto/aead.c
> @@ -93,6 +93,8 @@ int crypto_aead_encrypt(struct aead_request *req)
>  	else
>  		ret = crypto_aead_alg(aead)->encrypt(req);
>  	crypto_stats_aead_encrypt(cryptlen, alg, ret);
> +
> +	crypto_yield(crypto_aead_get_flags(aead));

This is the wrong place to do it.  It should be done by the code
that's actually doing the work, just like skcipher.

> diff --git a/crypto/shash.c b/crypto/shash.c
> index 868b6ba2b3b7..6fea17a50048 100644
> --- a/crypto/shash.c
> +++ b/crypto/shash.c
> @@ -114,11 +114,15 @@ int crypto_shash_update(struct shash_desc *desc, const u8 *data,
>  	struct crypto_shash *tfm = desc->tfm;
>  	struct shash_alg *shash = crypto_shash_alg(tfm);
>  	unsigned long alignmask = crypto_shash_alignmask(tfm);
> +	int ret;
>  
>  	if ((unsigned long)data & alignmask)
> -		return shash_update_unaligned(desc, data, len);
> +		ret = shash_update_unaligned(desc, data, len);
> +	else
> +		ret = shash->update(desc, data, len);
>  
> -	return shash->update(desc, data, len);
> +	crypto_yield(crypto_shash_get_flags(tfm));
> +	return ret;
>  }
>  EXPORT_SYMBOL_GPL(crypto_shash_update);

Ditto.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

  reply	other threads:[~2022-12-20  3:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-19 20:37 [PATCH 0/3] crypto: yield at end of operations Robert Elliott
2022-12-19 20:37 ` [PATCH 1/3] crypto: skcipher - always yield at end of walk Robert Elliott
2022-12-20  3:54   ` Herbert Xu
2022-12-19 20:37 ` [PATCH 2/3] crypto: aead/shash - yield at end of operations Robert Elliott
2022-12-20  3:55   ` Herbert Xu [this message]
2022-12-19 20:37 ` [PATCH 3/3] crypto: tcrypt - yield at end of test Robert Elliott
2022-12-20  3:55   ` 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=Y6EyJ3MDOMXZ7Yku@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=davem@davemloft.net \
    --cc=elliott@hpe.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@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