Linux-RISC-V Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 6.12] lib/crypto: riscv/chacha: Avoid s0/fp register
@ 2025-12-29 22:37 Eric Biggers
  2026-01-05 14:19 ` Patch "lib/crypto: riscv/chacha: Avoid s0/fp register" has been added to the 6.12-stable tree gregkh
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Biggers @ 2025-12-29 22:37 UTC (permalink / raw)
  To: stable; +Cc: linux-crypto, linux-riscv, Vivian Wang, Eric Biggers

From: Vivian Wang <wangruikang@iscas.ac.cn>

commit 43169328c7b4623b54b7713ec68479cebda5465f upstream.

In chacha_zvkb, avoid using the s0 register, which is the frame pointer,
by reallocating KEY0 to t5. This makes stack traces available if e.g. a
crash happens in chacha_zvkb.

No frame pointer maintenance is otherwise required since this is a leaf
function.

Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
Fixes: bb54668837a0 ("crypto: riscv - add vector crypto accelerated ChaCha20")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20251202-riscv-chacha_zvkb-fp-v2-1-7bd00098c9dc@iscas.ac.cn
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 arch/riscv/crypto/chacha-riscv64-zvkb.S | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/crypto/chacha-riscv64-zvkb.S b/arch/riscv/crypto/chacha-riscv64-zvkb.S
index bf057737ac69..fbef93503571 100644
--- a/arch/riscv/crypto/chacha-riscv64-zvkb.S
+++ b/arch/riscv/crypto/chacha-riscv64-zvkb.S
@@ -58,11 +58,12 @@
 #define CONSTS3		t0
 #define TMP		t1
 #define VL		t2
 #define STRIDE		t3
 #define NROUNDS		t4
-#define KEY0		s0
+#define KEY0		t5
+// Avoid s0/fp to allow for unwinding
 #define KEY1		s1
 #define KEY2		s2
 #define KEY3		s3
 #define KEY4		s4
 #define KEY5		s5
@@ -139,11 +140,10 @@
 // The counter is treated as 32-bit, following the RFC7539 convention.
 SYM_FUNC_START(chacha20_zvkb)
 	srli		LEN, LEN, 6	// Bytes to blocks
 
 	addi		sp, sp, -96
-	sd		s0, 0(sp)
 	sd		s1, 8(sp)
 	sd		s2, 16(sp)
 	sd		s3, 24(sp)
 	sd		s4, 32(sp)
 	sd		s5, 40(sp)
@@ -275,11 +275,10 @@ SYM_FUNC_START(chacha20_zvkb)
 	slli		TMP, VL, 6
 	add		OUTP, OUTP, TMP
 	add		INP, INP, TMP
 	bnez		LEN, .Lblock_loop
 
-	ld		s0, 0(sp)
 	ld		s1, 8(sp)
 	ld		s2, 16(sp)
 	ld		s3, 24(sp)
 	ld		s4, 32(sp)
 	ld		s5, 40(sp)

base-commit: 567bd8cbc2fe6b28b78864cbbbc41b0d405eb83c
-- 
2.52.0


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

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

* Patch "lib/crypto: riscv/chacha: Avoid s0/fp register" has been added to the 6.12-stable tree
  2025-12-29 22:37 [PATCH 6.12] lib/crypto: riscv/chacha: Avoid s0/fp register Eric Biggers
@ 2026-01-05 14:19 ` gregkh
  0 siblings, 0 replies; 2+ messages in thread
From: gregkh @ 2026-01-05 14:19 UTC (permalink / raw)
  To: ebiggers, gregkh, linux-riscv, wangruikang; +Cc: stable-commits


This is a note to let you know that I've just added the patch titled

    lib/crypto: riscv/chacha: Avoid s0/fp register

to the 6.12-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     lib-crypto-riscv-chacha-avoid-s0-fp-register.patch
and it can be found in the queue-6.12 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@vger.kernel.org> know about it.


From stable+bounces-204145-greg=kroah.com@vger.kernel.org Mon Dec 29 23:39:13 2025
From: Eric Biggers <ebiggers@kernel.org>
Date: Mon, 29 Dec 2025 14:37:29 -0800
Subject: lib/crypto: riscv/chacha: Avoid s0/fp register
To: stable@vger.kernel.org
Cc: linux-crypto@vger.kernel.org, linux-riscv@lists.infradead.org, Vivian Wang <wangruikang@iscas.ac.cn>, Eric Biggers <ebiggers@kernel.org>
Message-ID: <20251229223729.99861-1-ebiggers@kernel.org>

From: Vivian Wang <wangruikang@iscas.ac.cn>

commit 43169328c7b4623b54b7713ec68479cebda5465f upstream.

In chacha_zvkb, avoid using the s0 register, which is the frame pointer,
by reallocating KEY0 to t5. This makes stack traces available if e.g. a
crash happens in chacha_zvkb.

No frame pointer maintenance is otherwise required since this is a leaf
function.

Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
Fixes: bb54668837a0 ("crypto: riscv - add vector crypto accelerated ChaCha20")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20251202-riscv-chacha_zvkb-fp-v2-1-7bd00098c9dc@iscas.ac.cn
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 arch/riscv/crypto/chacha-riscv64-zvkb.S |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

--- a/arch/riscv/crypto/chacha-riscv64-zvkb.S
+++ b/arch/riscv/crypto/chacha-riscv64-zvkb.S
@@ -60,7 +60,8 @@
 #define VL		t2
 #define STRIDE		t3
 #define NROUNDS		t4
-#define KEY0		s0
+#define KEY0		t5
+// Avoid s0/fp to allow for unwinding
 #define KEY1		s1
 #define KEY2		s2
 #define KEY3		s3
@@ -141,7 +142,6 @@ SYM_FUNC_START(chacha20_zvkb)
 	srli		LEN, LEN, 6	// Bytes to blocks
 
 	addi		sp, sp, -96
-	sd		s0, 0(sp)
 	sd		s1, 8(sp)
 	sd		s2, 16(sp)
 	sd		s3, 24(sp)
@@ -277,7 +277,6 @@ SYM_FUNC_START(chacha20_zvkb)
 	add		INP, INP, TMP
 	bnez		LEN, .Lblock_loop
 
-	ld		s0, 0(sp)
 	ld		s1, 8(sp)
 	ld		s2, 16(sp)
 	ld		s3, 24(sp)


Patches currently in stable-queue which might be from ebiggers@kernel.org are

queue-6.12/lib-crypto-riscv-chacha-avoid-s0-fp-register.patch
queue-6.12/lib-crypto-x86-blake2s-fix-32-bit-arg-treated-as-64-bit.patch

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

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

end of thread, other threads:[~2026-01-05 14:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-29 22:37 [PATCH 6.12] lib/crypto: riscv/chacha: Avoid s0/fp register Eric Biggers
2026-01-05 14:19 ` Patch "lib/crypto: riscv/chacha: Avoid s0/fp register" has been added to the 6.12-stable tree gregkh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox