Skip to contentSkip to conversation

selftests: riscv: vector: add early ptrace test

PATCH Superseded Sergey Matyukevich 1 participant 2 messages Aug 21, 2025

Subsystems (2)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 selftests: riscv: vector: add early ptrace test

Add test that simulates early vector debug: attach to the process right after enabling vector context and check csr_vlenb.

---
 .../testing/selftests/riscv/vector/.gitignore |  1 +
 tools/testing/selftests/riscv/vector/Makefile |  5 +-
 .../testing/selftests/riscv/vector/v_ptrace.c | 84 +++++++++++++++++++
 3 files changed, 89 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/riscv/vector/v_ptrace.c
tools/testing/selftests/riscv/vector/.gitignore +1 -0
index 7d9c87cd0649..d21c03c3ee0e 100644
@@ -2,3 +2,4 @@ vstate_exec_nolibc
 vstate_prctl
 v_initval
 v_exec_initval_nolibc
+v_ptrace
tools/testing/selftests/riscv/vector/Makefile +4 -1
index 6f7497f4e7b3..c14ad127e7fb 100644
@@ -2,7 +2,7 @@
 # Copyright (C) 2021 ARM Limited
 # Originally tools/testing/arm64/abi/Makefile
 
-TEST_GEN_PROGS := v_initval vstate_prctl
+TEST_GEN_PROGS := v_initval vstate_prctl v_ptrace
 TEST_GEN_PROGS_EXTENDED := vstate_exec_nolibc v_exec_initval_nolibc
 
 include ../../lib.mk
@@ -26,3 +26,6 @@ $(OUTPUT)/v_initval: v_initval.c $(OUTPUT)/sys_hwprobe.o $(OUTPUT)/v_helpers.o
 $(OUTPUT)/v_exec_initval_nolibc: v_exec_initval_nolibc.c
 	$(CC) -nostdlib -static -include ../../../../include/nolibc/nolibc.h \
 		-Wall $(CFLAGS) $(LDFLAGS) $^ -o $@ -lgcc
+
+$(OUTPUT)/v_ptrace: v_ptrace.c $(OUTPUT)/sys_hwprobe.o $(OUTPUT)/v_helpers.o
+	$(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^
tools/testing/selftests/riscv/vector/v_ptrace.c new file +84 -0

84 lines not on this page · raw message

Signature · 1 line
2.50.1
#1 lore raw

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

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

---
 arch/riscv/kernel/vector.c | 2 ++
 1 file changed, 2 insertions(+)
arch/riscv/kernel/vector.c +2 -0
index 184f780c932d..6ba68568735b 100644
@@ -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;
 }
 
Signature · 1 line
2.50.1