lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y0eosAIgkvMzYJz8@sol.localdomain>
Date:   Wed, 12 Oct 2022 22:57:04 -0700
From:   Eric Biggers <ebiggers@...nel.org>
To:     Robert Elliott <elliott@....com>
Cc:     herbert@...dor.apana.org.au, davem@...emloft.net,
        tim.c.chen@...ux.intel.com, ap420073@...il.com, ardb@...nel.org,
        linux-crypto@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 04/19] crypto: x86/sha - limit FPU preemption

On Wed, Oct 12, 2022 at 04:59:16PM -0500, Robert Elliott wrote:
> diff --git a/arch/x86/crypto/sha1_ssse3_glue.c b/arch/x86/crypto/sha1_ssse3_glue.c
> index 44340a1139e0..a9f5779b41ca 100644
> --- a/arch/x86/crypto/sha1_ssse3_glue.c
> +++ b/arch/x86/crypto/sha1_ssse3_glue.c
> @@ -26,6 +26,8 @@
>  #include <crypto/sha1_base.h>
>  #include <asm/simd.h>
>  
> +#define FPU_BYTES 4096U /* avoid kernel_fpu_begin/end scheduler/rcu stalls */
> +
>  static int sha1_update(struct shash_desc *desc, const u8 *data,
>  			     unsigned int len, sha1_block_fn *sha1_xform)
>  {
> @@ -41,9 +43,18 @@ static int sha1_update(struct shash_desc *desc, const u8 *data,
>  	 */
>  	BUILD_BUG_ON(offsetof(struct sha1_state, state) != 0);
>  
> -	kernel_fpu_begin();
> -	sha1_base_do_update(desc, data, len, sha1_xform);
> -	kernel_fpu_end();
> +	do {
> +		unsigned int chunk = min(len, FPU_BYTES);
> +
> +		if (chunk) {
> +			kernel_fpu_begin();
> +			sha1_base_do_update(desc, data, chunk, sha1_xform);
> +			kernel_fpu_end();
> +		}
> +
> +		len -= chunk;
> +		data += chunk;
> +	} while (len);

'len' can't be 0 at the beginning of this loop, so the 'if (chunk)' check isn't
needed.  And it wouldn't make sense even if 'len' could be 0, since a while loop
could just be used in that case.

- Eric

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ