mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] lib/crypto: x86/aes-ctr: Remove some unreachable code
@ 2026-10-02  3:44 Eric Biggers
  2026-10-02  9:35 ` Ard Biesheuvel
  2026-10-02 21:42 ` Eric Biggers
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Biggers @ 2026-10-02  3:44 UTC (permalink / raw)
  To: linux-crypto
  Cc: linux-kernel, Ard Biesheuvel, Jason A . Donenfeld, Herbert Xu,
	Eric Biggers

In the AES-CTR and AES-XCTR code that handles a remainder of '4*VL < LEN
< 8*VL', first 4 full vectors are processed, leaving 0 < LEN < 4*VL.
After that, five different cases are handled depending on whether there
are 0, 1, 2, 3, or 4 full vectors remaining.  But the case of 4 vectors
is never reached there, making the code handling it unused.  Remove it.

With that done, the '.Lxor_tail_partial_vec_3\@' block would be reached
only via an unconditional jump.  Therefore, relocate it to the only
place that jumps to it.  This allows removing the jump at the end of the
'.Lxor_tail_partial_vec_2\@' block and making it fall through.

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 lib/crypto/x86/aes-ctr-avx-x86_64.S | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/lib/crypto/x86/aes-ctr-avx-x86_64.S b/lib/crypto/x86/aes-ctr-avx-x86_64.S
index c232337899b6..13b3e2cfae37 100644
--- a/lib/crypto/x86/aes-ctr-avx-x86_64.S
+++ b/lib/crypto/x86/aes-ctr-avx-x86_64.S
@@ -419,10 +419,12 @@
 	cmp		$3*VL-1, LEN32
 	jle		.Lxor_tail_partial_vec_2\@
 	_xor_data	2
-	cmp		$4*VL-1, LEN32
-	jle		.Lxor_tail_partial_vec_3\@
-	_xor_data	3
-	jmp		.Ldone\@
+	add		$-3*VL, LEN32
+	jz		.Ldone\@
+	sub		$-3*VL, SRC
+	sub		$-3*VL, DST
+	_vmovdqa	AESDATA3, AESDATA0
+	jmp		.Lxor_tail_partial_vec_0\@
 
 .Lenc_tail_atmost4vecs\@:
 	cmp		$2*VL, LEN32
@@ -469,14 +471,6 @@
 	sub		$-2*VL, SRC
 	sub		$-2*VL, DST
 	_vmovdqa	AESDATA2, AESDATA0
-	jmp		.Lxor_tail_partial_vec_0\@
-
-.Lxor_tail_partial_vec_3\@:
-	add		$-3*VL, LEN32
-	jz		.Ldone\@
-	sub		$-3*VL, SRC
-	sub		$-3*VL, DST
-	_vmovdqa	AESDATA3, AESDATA0
 
 .Lxor_tail_partial_vec_0\@:
 	// XOR the remaining 1 <= LEN < VL bytes.  It's easy if masked

base-commit: 9ca77aa621027149c43551308112eba06b1de3af
-- 
2.56.0


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

* Re: [PATCH] lib/crypto: x86/aes-ctr: Remove some unreachable code
  2026-10-02  3:44 [PATCH] lib/crypto: x86/aes-ctr: Remove some unreachable code Eric Biggers
@ 2026-10-02  9:35 ` Ard Biesheuvel
  2026-10-02 21:42 ` Eric Biggers
  1 sibling, 0 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2026-10-02  9:35 UTC (permalink / raw)
  To: Eric Biggers, linux-crypto; +Cc: linux-kernel, Jason A . Donenfeld, Herbert Xu


On Fri, 2 Oct 2026, at 05:44, Eric Biggers wrote:
> In the AES-CTR and AES-XCTR code that handles a remainder of '4*VL < LEN
> < 8*VL', first 4 full vectors are processed, leaving 0 < LEN < 4*VL.
> After that, five different cases are handled depending on whether there
> are 0, 1, 2, 3, or 4 full vectors remaining.  But the case of 4 vectors
> is never reached there, making the code handling it unused.  Remove it.
>
> With that done, the '.Lxor_tail_partial_vec_3\@' block would be reached
> only via an unconditional jump.  Therefore, relocate it to the only
> place that jumps to it.  This allows removing the jump at the end of the
> '.Lxor_tail_partial_vec_2\@' block and making it fall through.
>
> Signed-off-by: Eric Biggers <ebiggers@kernel.org>
> ---
>  lib/crypto/x86/aes-ctr-avx-x86_64.S | 18 ++++++------------
>  1 file changed, 6 insertions(+), 12 deletions(-)
>

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>

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

* Re: [PATCH] lib/crypto: x86/aes-ctr: Remove some unreachable code
  2026-10-02  3:44 [PATCH] lib/crypto: x86/aes-ctr: Remove some unreachable code Eric Biggers
  2026-10-02  9:35 ` Ard Biesheuvel
@ 2026-10-02 21:42 ` Eric Biggers
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Biggers @ 2026-10-02 21:42 UTC (permalink / raw)
  To: linux-crypto
  Cc: linux-kernel, Ard Biesheuvel, Jason A . Donenfeld, Herbert Xu

On Thu, Oct 01, 2026 at 08:44:05PM -0700, Eric Biggers wrote:
> In the AES-CTR and AES-XCTR code that handles a remainder of '4*VL < LEN
> < 8*VL', first 4 full vectors are processed, leaving 0 < LEN < 4*VL.
> After that, five different cases are handled depending on whether there
> are 0, 1, 2, 3, or 4 full vectors remaining.  But the case of 4 vectors
> is never reached there, making the code handling it unused.  Remove it.
> 
> With that done, the '.Lxor_tail_partial_vec_3\@' block would be reached
> only via an unconditional jump.  Therefore, relocate it to the only
> place that jumps to it.  This allows removing the jump at the end of the
> '.Lxor_tail_partial_vec_2\@' block and making it fall through.
> 
> Signed-off-by: Eric Biggers <ebiggers@kernel.org>
> ---
>  lib/crypto/x86/aes-ctr-avx-x86_64.S | 18 ++++++------------
>  1 file changed, 6 insertions(+), 12 deletions(-)

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=libcrypto-next

- Eric

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

end of thread, other threads:[~2026-10-02 21:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-02  3:44 [PATCH] lib/crypto: x86/aes-ctr: Remove some unreachable code Eric Biggers
2026-10-02  9:35 ` Ard Biesheuvel
2026-10-02 21:42 ` Eric Biggers

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®