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@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; }