public inbox for linux-riscv@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v 0/2] Optimize the allocation of vector regset
@ 2025-10-01 11:14 Yong-Xuan Wang
  2025-10-01 11:14 ` [PATCH v 1/2] riscv: ptrace: " Yong-Xuan Wang
  2025-10-01 11:14 ` [PATCH v 2/2] selftests: riscv: Add test for the Vector ptrace interface Yong-Xuan Wang
  0 siblings, 2 replies; 7+ messages in thread
From: Yong-Xuan Wang @ 2025-10-01 11:14 UTC (permalink / raw)
  To: linux-kernel, linux-riscv
  Cc: greentime.hu, vincent.chen, andybnac, Yong-Xuan Wang,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti

The vector regset uses the maximum possible vlenb 8192 to allocate a
2^18 bytes buffer to copy the vector register. But most platforms
don’t support the largest vlenb.

The regset has 2 users, ptrace syscall and coredump. When handling the
PTRACE_GETREGSET requests from ptrace syscall, Linux will prepare a
kernel buffer which size is min(user buffer size, limit). A malicious
user process might overwhelm a memory-constrainted system when the
buffer limit is very large. The coredump uses regset_get_alloc() to
get the context of vector register. But this API allocates buffer
before checking whether the target process uses vector extension, this
wastes time to prepare a large memory buffer. 

The buffer limit can be determined after getting platform vlenb in the
early boot stage, this can let the regset buffer match real hardware
limits. Also add .active callbacks to let the coredump skip vector part
when target process doesn't use it.

After this patchset, userspace process needs 2 ptrace syscalls to
retrieve the vector regset with PTRACE_GETREGSET. The first ptrace call
only reads the header to get the vlenb information. Then prepare a
suitable buffer to get the register context. The new vector ptrace
kselftest demonstrates it.

Yong-Xuan Wang (2):
  riscv: ptrace: Optimize the allocation of vector regset
  selftests: riscv: Add test for the Vector ptrace interface

 arch/riscv/include/asm/vector.h               |   1 +
 arch/riscv/kernel/ptrace.c                    |  24 +++-
 arch/riscv/kernel/vector.c                    |   2 +
 tools/testing/selftests/riscv/vector/Makefile |   5 +-
 .../selftests/riscv/vector/vstate_ptrace.c    | 132 ++++++++++++++++++
 5 files changed, 160 insertions(+), 4 deletions(-)
 create mode 100644 tools/testing/selftests/riscv/vector/vstate_ptrace.c

-- 
2.43.0


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

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

end of thread, other threads:[~2025-10-02  5:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-01 11:14 [PATCH v 0/2] Optimize the allocation of vector regset Yong-Xuan Wang
2025-10-01 11:14 ` [PATCH v 1/2] riscv: ptrace: " Yong-Xuan Wang
2025-10-01 14:50   ` Andy Chiu
2025-10-01 11:14 ` [PATCH v 2/2] selftests: riscv: Add test for the Vector ptrace interface Yong-Xuan Wang
2025-10-01 15:12   ` Andy Chiu
2025-10-02  5:53   ` Andy Chiu
2025-10-02  5:59     ` Charlie Jenkins

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