[PATCH 2/2] riscv: vector: init vlenb in vector context allocation

Sergey Matyukevich geomatsi at gmail.com
Thu Aug 21 10:39:50 PDT 2025


Currently, vlenb in vstate is set to zero on vector context allocation
and remains zero until the first context switch. This can expose an
inconsistent vlenb value to user-space in early vector debug scenarios,
e.g. when ptrace attaches to a tracee after the first vector instruction
but before the first context switch. Fix this by setting the correct
vlenb value during vector context allocation. Simple reproducer has been
added to selftests:
- tools/testing/selftests/riscv/vector/v_ptrace.c

Signed-off-by: Sergey Matyukevich <geomatsi at gmail.com>
---
 arch/riscv/kernel/vector.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/riscv/kernel/vector.c b/arch/riscv/kernel/vector.c
index 184f780c932d..6ba68568735b 100644
--- a/arch/riscv/kernel/vector.c
+++ b/arch/riscv/kernel/vector.c
@@ -120,6 +120,8 @@ static int riscv_v_thread_zalloc(struct kmem_cache *cache,
 
 	ctx->datap = datap;
 	memset(ctx, 0, offsetof(struct __riscv_v_ext_state, datap));
+	ctx->vlenb = riscv_v_vsize / 32;
+
 	return 0;
 }
 
-- 
2.50.1




More information about the linux-riscv mailing list