* [PATCH RESEND] crypto: x86 - exit fpu context earlier in ECB/CBC macros
@ 2023-01-21 18:34 Peter Lafreniere
2023-01-31 8:30 ` Ard Biesheuvel
2023-02-03 5:03 ` Herbert Xu
0 siblings, 2 replies; 3+ messages in thread
From: Peter Lafreniere @ 2023-01-21 18:34 UTC (permalink / raw)
To: linux-crypto; +Cc: Peter Lafreniere, ardb, linux-kernel, conor.dooley, x86
Currently the ecb/cbc macros hold fpu context unnecessarily when using
scalar cipher routines (e.g. when handling odd sizes of blocks per walk).
Change the macros to drop fpu context as soon as the fpu is out of use.
No performance impact found (on Intel Haswell).
Signed-off-by: Peter Lafreniere <peter@n8pjl.ca>
---
arch/x86/crypto/ecb_cbc_helpers.h | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/arch/x86/crypto/ecb_cbc_helpers.h b/arch/x86/crypto/ecb_cbc_helpers.h
index eaa15c7b29d6..11955bd01af1 100644
--- a/arch/x86/crypto/ecb_cbc_helpers.h
+++ b/arch/x86/crypto/ecb_cbc_helpers.h
@@ -13,13 +13,14 @@
#define ECB_WALK_START(req, bsize, fpu_blocks) do { \
void *ctx = crypto_skcipher_ctx(crypto_skcipher_reqtfm(req)); \
+ const int __fpu_blocks = (fpu_blocks); \
const int __bsize = (bsize); \
struct skcipher_walk walk; \
int err = skcipher_walk_virt(&walk, (req), false); \
while (walk.nbytes > 0) { \
unsigned int nbytes = walk.nbytes; \
- bool do_fpu = (fpu_blocks) != -1 && \
- nbytes >= (fpu_blocks) * __bsize; \
+ bool do_fpu = __fpu_blocks != -1 && \
+ nbytes >= __fpu_blocks * __bsize; \
const u8 *src = walk.src.virt.addr; \
u8 *dst = walk.dst.virt.addr; \
u8 __maybe_unused buf[(bsize)]; \
@@ -35,7 +36,12 @@
} while (0)
#define ECB_BLOCK(blocks, func) do { \
- while (nbytes >= (blocks) * __bsize) { \
+ const int __blocks = (blocks); \
+ if (do_fpu && __blocks < __fpu_blocks) { \
+ kernel_fpu_end(); \
+ do_fpu = false; \
+ } \
+ while (nbytes >= __blocks * __bsize) { \
(func)(ctx, dst, src); \
ECB_WALK_ADVANCE(blocks); \
} \
@@ -53,7 +59,12 @@
} while (0)
#define CBC_DEC_BLOCK(blocks, func) do { \
- while (nbytes >= (blocks) * __bsize) { \
+ const int __blocks = (blocks); \
+ if (do_fpu && __blocks < __fpu_blocks) { \
+ kernel_fpu_end(); \
+ do_fpu = false; \
+ } \
+ while (nbytes >= __blocks * __bsize) { \
const u8 *__iv = src + ((blocks) - 1) * __bsize; \
if (dst == src) \
__iv = memcpy(buf, __iv, __bsize); \
--
2.39.0
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH RESEND] crypto: x86 - exit fpu context earlier in ECB/CBC macros
2023-01-21 18:34 [PATCH RESEND] crypto: x86 - exit fpu context earlier in ECB/CBC macros Peter Lafreniere
@ 2023-01-31 8:30 ` Ard Biesheuvel
2023-02-03 5:03 ` Herbert Xu
1 sibling, 0 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2023-01-31 8:30 UTC (permalink / raw)
To: Peter Lafreniere; +Cc: linux-crypto, linux-kernel, conor.dooley, x86
On Sat, 21 Jan 2023 at 19:40, Peter Lafreniere <peter@n8pjl.ca> wrote:
>
> Currently the ecb/cbc macros hold fpu context unnecessarily when using
> scalar cipher routines (e.g. when handling odd sizes of blocks per walk).
>
> Change the macros to drop fpu context as soon as the fpu is out of use.
>
> No performance impact found (on Intel Haswell).
>
> Signed-off-by: Peter Lafreniere <peter@n8pjl.ca>
The patch seems correct to me, so
Acked-by: Ard Biesheuvel <ardb@kernel.org>
although I seriously doubt whether anyone would ever notice the
difference, given that the algorithms that use these macros are
primarily used in legacy block encryption scenarios, where the data is
always presented in multiples of the largest block size.
> ---
> arch/x86/crypto/ecb_cbc_helpers.h | 19 +++++++++++++++----
> 1 file changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/crypto/ecb_cbc_helpers.h b/arch/x86/crypto/ecb_cbc_helpers.h
> index eaa15c7b29d6..11955bd01af1 100644
> --- a/arch/x86/crypto/ecb_cbc_helpers.h
> +++ b/arch/x86/crypto/ecb_cbc_helpers.h
> @@ -13,13 +13,14 @@
>
> #define ECB_WALK_START(req, bsize, fpu_blocks) do { \
> void *ctx = crypto_skcipher_ctx(crypto_skcipher_reqtfm(req)); \
> + const int __fpu_blocks = (fpu_blocks); \
> const int __bsize = (bsize); \
> struct skcipher_walk walk; \
> int err = skcipher_walk_virt(&walk, (req), false); \
> while (walk.nbytes > 0) { \
> unsigned int nbytes = walk.nbytes; \
> - bool do_fpu = (fpu_blocks) != -1 && \
> - nbytes >= (fpu_blocks) * __bsize; \
> + bool do_fpu = __fpu_blocks != -1 && \
> + nbytes >= __fpu_blocks * __bsize; \
> const u8 *src = walk.src.virt.addr; \
> u8 *dst = walk.dst.virt.addr; \
> u8 __maybe_unused buf[(bsize)]; \
> @@ -35,7 +36,12 @@
> } while (0)
>
> #define ECB_BLOCK(blocks, func) do { \
> - while (nbytes >= (blocks) * __bsize) { \
> + const int __blocks = (blocks); \
> + if (do_fpu && __blocks < __fpu_blocks) { \
> + kernel_fpu_end(); \
> + do_fpu = false; \
> + } \
> + while (nbytes >= __blocks * __bsize) { \
> (func)(ctx, dst, src); \
> ECB_WALK_ADVANCE(blocks); \
> } \
> @@ -53,7 +59,12 @@
> } while (0)
>
> #define CBC_DEC_BLOCK(blocks, func) do { \
> - while (nbytes >= (blocks) * __bsize) { \
> + const int __blocks = (blocks); \
> + if (do_fpu && __blocks < __fpu_blocks) { \
> + kernel_fpu_end(); \
> + do_fpu = false; \
> + } \
> + while (nbytes >= __blocks * __bsize) { \
> const u8 *__iv = src + ((blocks) - 1) * __bsize; \
> if (dst == src) \
> __iv = memcpy(buf, __iv, __bsize); \
> --
> 2.39.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH RESEND] crypto: x86 - exit fpu context earlier in ECB/CBC macros
2023-01-21 18:34 [PATCH RESEND] crypto: x86 - exit fpu context earlier in ECB/CBC macros Peter Lafreniere
2023-01-31 8:30 ` Ard Biesheuvel
@ 2023-02-03 5:03 ` Herbert Xu
1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2023-02-03 5:03 UTC (permalink / raw)
To: Peter Lafreniere
Cc: linux-crypto, peter, ardb, linux-kernel, conor.dooley, x86
Peter Lafreniere <peter@n8pjl.ca> wrote:
> Currently the ecb/cbc macros hold fpu context unnecessarily when using
> scalar cipher routines (e.g. when handling odd sizes of blocks per walk).
>
> Change the macros to drop fpu context as soon as the fpu is out of use.
>
> No performance impact found (on Intel Haswell).
>
> Signed-off-by: Peter Lafreniere <peter@n8pjl.ca>
> ---
> arch/x86/crypto/ecb_cbc_helpers.h | 19 +++++++++++++++----
> 1 file changed, 15 insertions(+), 4 deletions(-)
Patch applied. Thanks.
--
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-02-03 5:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-21 18:34 [PATCH RESEND] crypto: x86 - exit fpu context earlier in ECB/CBC macros Peter Lafreniere
2023-01-31 8:30 ` Ard Biesheuvel
2023-02-03 5:03 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®