[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAFTtA3OW6nDDZP=bZXeBa8ua05QiXO1L92tKvf77WUuJGoengg@mail.gmail.com>
Date: Fri, 17 Oct 2025 16:50:22 -0500
From: Andy Chiu <andybnac@...il.com>
To: Yong-Xuan Wang <yongxuan.wang@...ive.com>
Cc: linux-kernel@...r.kernel.org, linux-riscv@...ts.infradead.org,
linux-kselftest@...r.kernel.org, greentime.hu@...ive.com,
vincent.chen@...ive.com, Paul Walmsley <pjw@...nel.org>,
Palmer Dabbelt <palmer@...belt.com>, Albert Ou <aou@...s.berkeley.edu>,
Alexandre Ghiti <alex@...ti.fr>
Subject: Re: [PATCH v2 0/2] Optimize the allocation of vector regset
On Mon, Oct 13, 2025 at 4:13 AM Yong-Xuan Wang <yongxuan.wang@...ive.com> wrote:
>
> 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.
For the entire series:
Tested-by: Andy Chiu <andybnac@...il.com>
[on rv64 v enabled qemu]
Thanks!
>
> ---
> v2:
> - fix issues in vector ptrace kselftest (Andy)
>
> 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 | 134 ++++++++++++++++++
> 5 files changed, 162 insertions(+), 4 deletions(-)
> create mode 100644 tools/testing/selftests/riscv/vector/vstate_ptrace.c
>
> --
> 2.43.0
>
Powered by blists - more mailing lists