All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] crypto: x86 - exit fpu context earlier in ECB/CBC macros
@ 2023-01-16 14:59 Peter Lafreniere
  2023-01-16 15:09 ` Ard Biesheuvel
  0 siblings, 1 reply; 9+ messages in thread
From: Peter Lafreniere @ 2023-01-16 14:59 UTC (permalink / raw)
  To: linux-crypto; +Cc: ardb, x86, linux-kernel, Peter Lafreniere

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..b83085e18ab0 100644
--- a/arch/x86/crypto/ecb_cbc_helpers.h
+++ b/arch/x86/crypto/ecb_cbc_helpers.h
@@ -14,12 +14,13 @@
 #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 related	[flat|nested] 9+ messages in thread

* Re: [PATCH] crypto: x86 - exit fpu context earlier in ECB/CBC macros
  2023-01-16 14:59 [PATCH] crypto: x86 - exit fpu context earlier in ECB/CBC macros Peter Lafreniere
@ 2023-01-16 15:09 ` Ard Biesheuvel
  2023-01-16 15:20   ` Peter Lafreniere
  0 siblings, 1 reply; 9+ messages in thread
From: Ard Biesheuvel @ 2023-01-16 15:09 UTC (permalink / raw)
  To: Peter Lafreniere; +Cc: linux-crypto, x86, linux-kernel

On Mon, 16 Jan 2023 at 16:00, Peter Lafreniere <peter@n8pjl.ca> wrote:

Please don't send encrypted emails to the mailing list. Plaintext
only, with the patch in the message body (not as an attachment).
Please use git send-email if you have trouble configuring your email
client.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] crypto: x86 - exit fpu context earlier in ECB/CBC macros
  2023-01-16 15:09 ` Ard Biesheuvel
@ 2023-01-16 15:20   ` Peter Lafreniere
  2023-01-16 15:32     ` Conor Dooley
  0 siblings, 1 reply; 9+ messages in thread
From: Peter Lafreniere @ 2023-01-16 15:20 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: linux-crypto, x86, linux-kernel

> Please don't send encrypted emails to the mailing list. Plaintext
> only, with the patch in the message body (not as an attachment).
> Please use git send-email if you have trouble configuring your email
> client.

My apologies. I was having difficulties configuring git send-email,
but now I believe that I have the issues resolved. Future patches will
be properly formatted.

- Peter

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] crypto: x86 - exit fpu context earlier in ECB/CBC macros
  2023-01-16 15:20   ` Peter Lafreniere
@ 2023-01-16 15:32     ` Conor Dooley
  2023-01-16 15:40       ` Peter Lafreniere
  2023-01-16 16:33       ` Ard Biesheuvel
  0 siblings, 2 replies; 9+ messages in thread
From: Conor Dooley @ 2023-01-16 15:32 UTC (permalink / raw)
  To: Peter Lafreniere; +Cc: Ard Biesheuvel, linux-crypto, x86, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 745 bytes --]

On Mon, Jan 16, 2023 at 03:20:59PM +0000, Peter Lafreniere wrote:
> > Please don't send encrypted emails to the mailing list. Plaintext
> > only, with the patch in the message body (not as an attachment).
> > Please use git send-email if you have trouble configuring your email
> > client.


> My apologies. I was having difficulties configuring git send-email,
> but now I believe that I have the issues resolved. Future patches will
> be properly formatted.

It landed okay on lore:
https://lore.kernel.org/linux-crypto/IBooTlGWpNE7pOelt0gm21bxW7wBILNYJ1HaoPbbfdEEMwz0Pp92vpd_OUlhNFNAitFThTi27P6q6NvcYMKm-y7tjwiF9YbImWjhgC3UDMk=@n8pjl.ca/#t

I've seen enough of these now to know where this is going, I'd bet that
you're a protonmail user...


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] crypto: x86 - exit fpu context earlier in ECB/CBC macros
  2023-01-16 15:32     ` Conor Dooley
@ 2023-01-16 15:40       ` Peter Lafreniere
  2023-01-16 16:27         ` Conor.Dooley
  2023-01-16 16:33       ` Ard Biesheuvel
  1 sibling, 1 reply; 9+ messages in thread
From: Peter Lafreniere @ 2023-01-16 15:40 UTC (permalink / raw)
  To: Conor Dooley; +Cc: Ard Biesheuvel, linux-crypto, x86, linux-kernel

> > My apologies. I was having difficulties configuring git send-email,
> > but now I believe that I have the issues resolved. Future patches will
> > be properly formatted.
> 
> 
> It landed okay on lore:
> https://lore.kernel.org/linux-crypto/IBooTlGWpNE7pOelt0gm21bxW7wBILNYJ1HaoPbbfdEEMwz0Pp92vpd_OUlhNFNAitFThTi27P6q6NvcYMKm-y7tjwiF9YbImWjhgC3UDMk=@n8pjl.ca/#t

Yup, that's why I'm not resending it.

> 
> I've seen enough of these now to know where this is going, I'd bet that
> you're a protonmail user...

You would be quite correct. They do like making your life difficult when
it comes to using smtp.

Anyway, the patch landed fine on lore and patchwork and I've (finally)
configured git-send-email properly, so I think that this should be all 
good now.

Again, sorry for the issues,
Peter Lafreniere

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] crypto: x86 - exit fpu context earlier in ECB/CBC macros
  2023-01-16 15:40       ` Peter Lafreniere
@ 2023-01-16 16:27         ` Conor.Dooley
  0 siblings, 0 replies; 9+ messages in thread
From: Conor.Dooley @ 2023-01-16 16:27 UTC (permalink / raw)
  To: peter; +Cc: ardb, linux-crypto, x86, linux-kernel

On 16/01/2023 15:40, Peter Lafreniere wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
>>> My apologies. I was having difficulties configuring git send-email,
>>> but now I believe that I have the issues resolved. Future patches will
>>> be properly formatted.
>>
>>
>> It landed okay on lore:
>> https://lore.kernel.org/linux-crypto/IBooTlGWpNE7pOelt0gm21bxW7wBILNYJ1HaoPbbfdEEMwz0Pp92vpd_OUlhNFNAitFThTi27P6q6NvcYMKm-y7tjwiF9YbImWjhgC3UDMk=@n8pjl.ca/#t
> 
> Yup, that's why I'm not resending it.
> 
>>
>> I've seen enough of these now to know where this is going, I'd bet that
>> you're a protonmail user...
> 
> You would be quite correct. They do like making your life difficult when
> it comes to using smtp.
> 
> Anyway, the patch landed fine on lore and patchwork and I've (finally)
> configured git-send-email properly, so I think that this should be all
> good now.

Unfortunately that's the most annoying part. Proton encrypts the copies
to specific recipients only... See:
https://lore.kernel.org/all/20221231152320.1340874-1-conor@kernel.org/

Thanks,
Conor.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] crypto: x86 - exit fpu context earlier in ECB/CBC macros
  2023-01-16 15:32     ` Conor Dooley
  2023-01-16 15:40       ` Peter Lafreniere
@ 2023-01-16 16:33       ` Ard Biesheuvel
  2023-01-27 10:53         ` Herbert Xu
  1 sibling, 1 reply; 9+ messages in thread
From: Ard Biesheuvel @ 2023-01-16 16:33 UTC (permalink / raw)
  To: Conor Dooley; +Cc: Peter Lafreniere, linux-crypto, x86, linux-kernel

On Mon, 16 Jan 2023 at 16:32, Conor Dooley <conor.dooley@microchip.com> wrote:
>
> On Mon, Jan 16, 2023 at 03:20:59PM +0000, Peter Lafreniere wrote:
> > > Please don't send encrypted emails to the mailing list. Plaintext
> > > only, with the patch in the message body (not as an attachment).
> > > Please use git send-email if you have trouble configuring your email
> > > client.
>
>
> > My apologies. I was having difficulties configuring git send-email,
> > but now I believe that I have the issues resolved. Future patches will
> > be properly formatted.
>
> It landed okay on lore:
> https://lore.kernel.org/linux-crypto/IBooTlGWpNE7pOelt0gm21bxW7wBILNYJ1HaoPbbfdEEMwz0Pp92vpd_OUlhNFNAitFThTi27P6q6NvcYMKm-y7tjwiF9YbImWjhgC3UDMk=@n8pjl.ca/#t
>
> I've seen enough of these now to know where this is going, I'd bet that
> you're a protonmail user...
>

I am still receiving encrypted messages, and given that I am a direct
recipient, the mailing list server does not cc me then unencrypted
copies.

I am not going to reply to the patch until it lands in my inbox in
plaintext, sorry ...

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] crypto: x86 - exit fpu context earlier in ECB/CBC macros
  2023-01-16 16:33       ` Ard Biesheuvel
@ 2023-01-27 10:53         ` Herbert Xu
  2023-01-27 11:09           ` Ard Biesheuvel
  0 siblings, 1 reply; 9+ messages in thread
From: Herbert Xu @ 2023-01-27 10:53 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: conor.dooley, peter, linux-crypto, x86, linux-kernel

Ard Biesheuvel <ardb@kernel.org> wrote:
>
> I am still receiving encrypted messages, and given that I am a direct
> recipient, the mailing list server does not cc me then unencrypted
> copies.
> 
> I am not going to reply to the patch until it lands in my inbox in
> plaintext, sorry ...

As Ard needs to review this patch, until this is resolved I won't
be applying this.

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] 9+ messages in thread

* Re: [PATCH] crypto: x86 - exit fpu context earlier in ECB/CBC macros
  2023-01-27 10:53         ` Herbert Xu
@ 2023-01-27 11:09           ` Ard Biesheuvel
  0 siblings, 0 replies; 9+ messages in thread
From: Ard Biesheuvel @ 2023-01-27 11:09 UTC (permalink / raw)
  To: Herbert Xu; +Cc: conor.dooley, peter, linux-crypto, x86, linux-kernel

On Fri, 27 Jan 2023 at 11:53, Herbert Xu <herbert@gondor.apana.org.au> wrote:
>
> Ard Biesheuvel <ardb@kernel.org> wrote:
> >
> > I am still receiving encrypted messages, and given that I am a direct
> > recipient, the mailing list server does not cc me then unencrypted
> > copies.
> >
> > I am not going to reply to the patch until it lands in my inbox in
> > plaintext, sorry ...
>
> As Ard needs to review this patch, until this is resolved I won't
> be applying this.
>

I've received the plaintext version in the mean time, it's on another thread.

So we can close this one.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-01-27 11:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-16 14:59 [PATCH] crypto: x86 - exit fpu context earlier in ECB/CBC macros Peter Lafreniere
2023-01-16 15:09 ` Ard Biesheuvel
2023-01-16 15:20   ` Peter Lafreniere
2023-01-16 15:32     ` Conor Dooley
2023-01-16 15:40       ` Peter Lafreniere
2023-01-16 16:27         ` Conor.Dooley
2023-01-16 16:33       ` Ard Biesheuvel
2023-01-27 10:53         ` Herbert Xu
2023-01-27 11:09           ` Ard Biesheuvel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.