Skip to contentSkip to conversation

crypto: arm64/sha256 - fix build when CONFIG_PREEMPT_VOLUNTARY=y

PATCH In review Eric Biggers 3 participants 5 messages May 7, 2025 – May 8, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: arm64/sha256 - fix build when CONFIG_PREEMPT_VOLUNTARY=y

From: Eric Biggers <[email protected]>

Fix the build of sha256-ce.S when CONFIG_PREEMPT_VOLUNTARY=y by passing the correct label to the cond_yield macro. Also adjust the code to execute only one branch instruction when CONFIG_PREEMPT_VOLUNTARY=n.

Fixes 6e36be511d28 ("crypto: arm64/sha256 - implement library instead of shash")
---
 arch/arm64/lib/crypto/sha256-ce.S | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/arm64/lib/crypto/sha256-ce.S +4 -3
index a8461d6dad634..f3e21c6d87d2e 100644
@@ -121,14 +121,15 @@ CPU_LE(	rev32		v19.16b, v19.16b	)
 
 	/* update state */
 	add		dgav.4s, dgav.4s, dg0v.4s
 	add		dgbv.4s, dgbv.4s, dg1v.4s
 
+	/* return early if voluntary preemption is needed */
+	cond_yield	1f, x5, x6
+
 	/* handled all input blocks? */
-	cbz		x2, 1f
-	cond_yield	3f, x5, x6
-	b		0b
+	cbnz		x2, 0b
 
 	/* store new state */
 1:	st1		{dgav.4s, dgbv.4s}, [x0]
 	mov		x0, x2
 	ret

base-commit: 20e9579f11b6cbdf0556d9cd85a0aa7653caf341

Signature · 1 line
2.49.0
maintainer
#1 lore raw
Quoted 6 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Fix the build of sha256-ce.S when CONFIG_PREEMPT_VOLUNTARY=y by passing the correct label to the cond_yield macro. Also adjust the code to execute only one branch instruction when CONFIG_PREEMPT_VOLUNTARY=n.

Quoted 7 lines
Fixes 6e36be511d28 ("crypto: arm64/sha256 - implement library instead of shash")

---
arch/arm64/lib/crypto/sha256-ce.S | 7 ++++---

1 file changed, 4 insertions(+), 3 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#2 lore raw
In reply to Eric Biggers
Quoted 20 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Fix the build of sha256-ce.S when CONFIG_PREEMPT_VOLUNTARY=y by passing the correct label to the cond_yield macro. Also adjust the code to execute only one branch instruction when CONFIG_PREEMPT_VOLUNTARY=n.

Fixes 6e36be511d28 ("crypto: arm64/sha256 - implement library instead of shash")
---
 arch/arm64/lib/crypto/sha256-ce.S | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/arm64/lib/crypto/sha256-ce.S +0 -0
index a8461d6dad634..f3e21c6d87d2e 100644

arch/arm64/lib/crypto/sha256-ce.S CPU_LE( rev32 v19.16b, v19.16b ) · line 128

Quoted 8 lines
arch/arm64/lib/crypto/sha256-ce.S +3 -0
@@ -121,14 +121,15 @@ CPU_LE(   rev32           v19.16b, v19.16b        )
 
        /* update state */
        add             dgav.4s, dgav.4s, dg0v.4s
        add             dgbv.4s, dgbv.4s, dg1v.4s
 
+       /* return early if voluntary preemption is needed */
+       cond_yield      1f, x5, x6
+

This will yield needlessly when the condition hits during the final iteration.

Quoted 15 lines
arch/arm64/lib/crypto/sha256-ce.S +1 -3
        /* handled all input blocks? */
-       cbz             x2, 1f
-       cond_yield      3f, x5, x6
-       b               0b
+       cbnz            x2, 0b
 
        /* store new state */
 1:     st1             {dgav.4s, dgbv.4s}, [x0]
        mov             x0, x2
        ret

base-commit: 20e9579f11b6cbdf0556d9cd85a0aa7653caf341 --
2.49.0

#3 lore raw
Quoted 26 lines · Ard Biesheuvel
Quoted 25 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Fix the build of sha256-ce.S when CONFIG_PREEMPT_VOLUNTARY=y by passing the correct label to the cond_yield macro. Also adjust the code to execute only one branch instruction when CONFIG_PREEMPT_VOLUNTARY=n.

Fixes 6e36be511d28 ("crypto: arm64/sha256 - implement library instead of shash")
---
 arch/arm64/lib/crypto/sha256-ce.S | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/arm64/lib/crypto/sha256-ce.S +0 -0
index a8461d6dad634..f3e21c6d87d2e 100644
@@ -121,14 +121,15 @@ CPU_LE(   rev32           v19.16b, v19.16b        )
 
        /* update state */
        add             dgav.4s, dgav.4s, dg0v.4s
        add             dgbv.4s, dgbv.4s, dg1v.4s
 
Quoted 11 lines

arch/arm64/lib/crypto/sha256-ce.S CPU_LE( rev32 v19.16b, v19.16b ) · line 128

Quoted 3 lines
arch/arm64/lib/crypto/sha256-ce.S +3 -0
+       /* return early if voluntary preemption is needed */
+       cond_yield      1f, x5, x6
+

This will yield needlessly when the condition hits during the final iteration.

Quoted 5 lines
arch/arm64/lib/crypto/sha256-ce.S +1 -3
        /* handled all input blocks? */
-       cbz             x2, 1f
-       cond_yield      3f, x5, x6
-       b               0b
+       cbnz            x2, 0b

cond_yield doesn't actually yield, though. It just checks whether yielding is needed. So the behavior is the same: on the last iteration this function returns 0 (i.e. 0 blocks remaining), regardless of whether it gets to the end by jumping there due to TSK_TI_PREEMPT being set or by falling through after seeing nblocks==0. We could keep the nblocks==0 check first, but the cond_yield check is lightweight and it's probably better to avoid the extra branch instruction on every other iteration.

- Eric

#4 lore raw
Quoted 40 lines · Eric Biggers
Quoted 26 lines · Ard Biesheuvel
Quoted 25 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Fix the build of sha256-ce.S when CONFIG_PREEMPT_VOLUNTARY=y by passing the correct label to the cond_yield macro. Also adjust the code to execute only one branch instruction when CONFIG_PREEMPT_VOLUNTARY=n.

Fixes 6e36be511d28 ("crypto: arm64/sha256 - implement library instead of shash")
---
 arch/arm64/lib/crypto/sha256-ce.S | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/arm64/lib/crypto/sha256-ce.S +0 -0
index a8461d6dad634..f3e21c6d87d2e 100644
@@ -121,14 +121,15 @@ CPU_LE(   rev32           v19.16b, v19.16b        )
 
        /* update state */
        add             dgav.4s, dgav.4s, dg0v.4s
        add             dgbv.4s, dgbv.4s, dg1v.4s
 
Quoted 11 lines

arch/arm64/lib/crypto/sha256-ce.S CPU_LE( rev32 v19.16b, v19.16b ) · line 128

Quoted 3 lines
arch/arm64/lib/crypto/sha256-ce.S +3 -0
+       /* return early if voluntary preemption is needed */
+       cond_yield      1f, x5, x6
+

This will yield needlessly when the condition hits during the final iteration.

Quoted 5 lines
arch/arm64/lib/crypto/sha256-ce.S +1 -3
        /* handled all input blocks? */
-       cbz             x2, 1f
-       cond_yield      3f, x5, x6
-       b               0b
+       cbnz            x2, 0b
Quoted 8 lines

cond_yield doesn't actually yield, though. It just checks whether yielding is needed. So the behavior is the same: on the last iteration this function returns 0 (i.e. 0 blocks remaining), regardless of whether it gets to the end by jumping there due to TSK_TI_PREEMPT being set or by falling through after seeing nblocks==0. We could keep the nblocks==0 check first, but the cond_yield check is lightweight and it's probably better to avoid the extra branch instruction on every other iteration.

Ah yes, you're right.

Hopefully we'll soon be able to get rid of it entirely.