linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/9] riscv: vector: misc ptrace fixes for debug use-cases
@ 2025-11-08 19:41 Sergey Matyukevich
  2025-11-08 19:41 ` [PATCH v4 1/9] selftests: riscv: test ptrace vector interface Sergey Matyukevich
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Sergey Matyukevich @ 2025-11-08 19:41 UTC (permalink / raw)
  To: linux-riscv, linux-kernel, linux-kselftest
  Cc: Paul Walmsley, Palmer Dabbelt, Alexandre Ghiti, Oleg Nesterov,
	Shuah Khan, Thomas Huth, Charlie Jenkins, Andy Chiu,
	Samuel Holland, Joel Granados, Conor Dooley, Yong-Xuan Wang,
	Heiko Stuebner, Sergey Matyukevich

This patch series suggests fixes for several corner cases in the RISC-V
vector ptrace implementation:

- init vector context with proper vlenb, to avoid reading zero vlenb
  by an early attached debugger

- follow gdbserver expectations and return ENODATA instead of EINVAL
  if vector extension is supported but not yet activated for the
  traced process

- validate input vector csr registers in ptrace, to maintain an accurate
  view of the tracee's vector context across multiple halt/resume
  debug cycles

For detailed description see the appropriate commit messages. A new test
suite v_ptrace is added into the tools/testing/selftests/riscv/vector
to verify some of the vector ptrace functionality and corner cases.

Previous versions:
- v3: https://lore.kernel.org/linux-riscv/20251025210655.43099-1-geomatsi@gmail.com/T/#u
- v2: https://lore.kernel.org/linux-riscv/20250821173957.563472-1-geomatsi@gmail.com/T/#u
- v1: https://lore.kernel.org/linux-riscv/20251007115840.2320557-1-geomatsi@gmail.com/T/#u

Changes in v4:
The form 'vsetvli x0, x0, ...' can only be used if VLMAX remains
unchanged, see spec 6.2. This condition was not met by the initial
values in the selftests w.r.t. the initial zeroed context. QEMU accepted
such values, but actual hardware (c908, BananaPi CanMV Zero board) did
not, setting vill. So fix the selftests after testing on hardware:
- replace 'vsetvli x0, x0, ...' by 'vsetvli rd, x0, ...' 
- fixed instruction returns VLMAX, so use it in checks as well
- replace fixed vlenb == 16 in the syscall test

Changes in v3:
Address the review comments by Andy Chiu and rework the approach:
- drop forced vector context save entirely
- perform strict validation of vector csr regs in ptrace

Changes in v2:
- add thread_info flag to allow to force vector context save
- force vector context save after vector ptrace to ensure valid vector
  context in the next ptrace operations
- force vector context save on the first context switch after vector
  context init to get proper vlenb

---

Ilya Mamay (1):
  riscv: ptrace: return ENODATA for inactive vector extension

Sergey Matyukevich (8):
  selftests: riscv: test ptrace vector interface
  selftests: riscv: verify initial vector state with ptrace
  riscv: vector: init vector context with proper vlenb
  riscv: csr: define vtype registers elements
  riscv: ptrace: validate input vector csr registers
  selftests: riscv: verify ptrace rejects invalid vector csr inputs
  selftests: riscv: verify ptrace accepts valid vector csr values
  selftests: riscv: verify syscalls discard vector context

 arch/riscv/include/asm/csr.h                  |  11 +
 arch/riscv/kernel/ptrace.c                    |  72 +-
 arch/riscv/kernel/vector.c                    |  12 +-
 .../testing/selftests/riscv/vector/.gitignore |   1 +
 tools/testing/selftests/riscv/vector/Makefile |   5 +-
 .../testing/selftests/riscv/vector/v_ptrace.c | 754 ++++++++++++++++++
 6 files changed, 847 insertions(+), 8 deletions(-)
 create mode 100644 tools/testing/selftests/riscv/vector/v_ptrace.c


base-commit: e811c33b1f137be26a20444b79db8cbc1fca1c89
-- 
2.51.0


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

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

end of thread, other threads:[~2025-11-08 19:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-08 19:41 [PATCH v4 0/9] riscv: vector: misc ptrace fixes for debug use-cases Sergey Matyukevich
2025-11-08 19:41 ` [PATCH v4 1/9] selftests: riscv: test ptrace vector interface Sergey Matyukevich
2025-11-08 19:41 ` [PATCH v4 2/9] riscv: ptrace: return ENODATA for inactive vector extension Sergey Matyukevich
2025-11-08 19:41 ` [PATCH v4 3/9] selftests: riscv: verify initial vector state with ptrace Sergey Matyukevich
2025-11-08 19:41 ` [PATCH v4 4/9] riscv: vector: init vector context with proper vlenb Sergey Matyukevich
2025-11-08 19:41 ` [PATCH v4 5/9] riscv: csr: define vtype registers elements Sergey Matyukevich
2025-11-08 19:41 ` [PATCH v4 6/9] riscv: ptrace: validate input vector csr registers Sergey Matyukevich
2025-11-08 19:41 ` [PATCH v4 7/9] selftests: riscv: verify ptrace rejects invalid vector csr inputs Sergey Matyukevich
2025-11-08 19:41 ` [PATCH v4 8/9] selftests: riscv: verify ptrace accepts valid vector csr values Sergey Matyukevich
2025-11-08 19:41 ` [PATCH v4 9/9] selftests: riscv: verify syscalls discard vector context Sergey Matyukevich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).