Skip to content

Commit 8cdb04b

Browse files
mmamayka01-starPaul Walmsley
authored andcommitted
riscv: ptrace: return ENODATA for inactive vector extension
Currently, ptrace returns EINVAL when the vector extension is supported but not yet activated for the traced process. This error code is not always appropriate since the ptrace arguments may be valid. Debug tools like gdbserver expect ENODATA when the requested register set is not active, e.g. see [1]. This expectation seems to be more appropriate, so modify the vector ptrace implementation to return: - EINVAL when V extension is not supported - ENODATA when V extension is supported but not active [1] https://github.com/bminor/binutils-gdb/blob/637f25e88675fa47e47f9cc5e2cf37384836b8a2/gdbserver/linux-low.cc#L5020 Signed-off-by: Ilya Mamay <mmamayka01@gmail.com> Signed-off-by: Sergey Matyukevich <geomatsi@gmail.com> Reviewed-by: Andy Chiu <andybnac@gmail.com> Tested-by: Andy Chiu <andybnac@gmail.com> Link: https://patch.msgid.link/20251214163537.1054292-2-geomatsi@gmail.com Signed-off-by: Paul Walmsley <pjw@kernel.org>
1 parent d30c168 commit 8cdb04b

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

arch/riscv/kernel/ptrace.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,12 @@ static int riscv_vr_get(struct task_struct *target,
9999
struct __riscv_v_ext_state *vstate = &target->thread.vstate;
100100
struct __riscv_v_regset_state ptrace_vstate;
101101

102-
if (!riscv_v_vstate_query(task_pt_regs(target)))
102+
if (!(has_vector() || has_xtheadvector()))
103103
return -EINVAL;
104104

105+
if (!riscv_v_vstate_query(task_pt_regs(target)))
106+
return -ENODATA;
107+
105108
/*
106109
* Ensure the vector registers have been saved to the memory before
107110
* copying them to membuf.
@@ -134,9 +137,12 @@ static int riscv_vr_set(struct task_struct *target,
134137
struct __riscv_v_ext_state *vstate = &target->thread.vstate;
135138
struct __riscv_v_regset_state ptrace_vstate;
136139

137-
if (!riscv_v_vstate_query(task_pt_regs(target)))
140+
if (!(has_vector() || has_xtheadvector()))
138141
return -EINVAL;
139142

143+
if (!riscv_v_vstate_query(task_pt_regs(target)))
144+
return -ENODATA;
145+
140146
/* Copy rest of the vstate except datap */
141147
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ptrace_vstate, 0,
142148
sizeof(struct __riscv_v_regset_state));

0 commit comments

Comments
 (0)