Skip to content

Commit e2de164

Browse files
Merge patch series "riscv: fix ptrace and export VLENB"
Andy Chiu <andy.chiu@sifive.com> says: We add a vlenb field in Vector context and save it with the riscv_vstate_save() macro. It should not cause performance regression as VLENB is a design-time constant and is frequently used by hardware. Also, adding this field into the __sc_riscv_v_state may benifit us on a future compatibility issue becuse a hardware may have writable VLENB. Adding and saving VLENB have an immediate benifit as it gives ptrace a better view of the Vector extension and makes it possible to reconstruct Vector register files from the dump without doing an additional csr read. This patchset also sync the number of note types between us and gdb for riscv to solve a conflicting note. This is not an ABI break given that 6.5 has not been released yet. * b4-shazam-merge: RISC-V: vector: export VLENB csr in __sc_riscv_v_state RISC-V: Remove ptrace support for vectors Link: https://lore.kernel.org/r/20230816155450.26200-1-andy.chiu@sifive.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2 parents ca09f77 + c35f3aa commit e2de164

File tree

4 files changed

+3
-71
lines changed

4 files changed

+3
-71
lines changed

arch/riscv/include/asm/vector.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ static __always_inline void __vstate_csr_save(struct __riscv_v_ext_state *dest)
7070
"csrr %1, " __stringify(CSR_VTYPE) "\n\t"
7171
"csrr %2, " __stringify(CSR_VL) "\n\t"
7272
"csrr %3, " __stringify(CSR_VCSR) "\n\t"
73+
"csrr %4, " __stringify(CSR_VLENB) "\n\t"
7374
: "=r" (dest->vstart), "=r" (dest->vtype), "=r" (dest->vl),
74-
"=r" (dest->vcsr) : :);
75+
"=r" (dest->vcsr), "=r" (dest->vlenb) : :);
7576
}
7677

7778
static __always_inline void __vstate_csr_restore(struct __riscv_v_ext_state *src)

arch/riscv/include/uapi/asm/ptrace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ struct __riscv_v_ext_state {
9797
unsigned long vl;
9898
unsigned long vtype;
9999
unsigned long vcsr;
100+
unsigned long vlenb;
100101
void *datap;
101102
/*
102103
* In signal handler, datap will be set a correct user stack offset

arch/riscv/kernel/ptrace.c

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ enum riscv_regset {
2525
#ifdef CONFIG_FPU
2626
REGSET_F,
2727
#endif
28-
#ifdef CONFIG_RISCV_ISA_V
29-
REGSET_V,
30-
#endif
3128
};
3229

3330
static int riscv_gpr_get(struct task_struct *target,
@@ -84,61 +81,6 @@ static int riscv_fpr_set(struct task_struct *target,
8481
}
8582
#endif
8683

87-
#ifdef CONFIG_RISCV_ISA_V
88-
static int riscv_vr_get(struct task_struct *target,
89-
const struct user_regset *regset,
90-
struct membuf to)
91-
{
92-
struct __riscv_v_ext_state *vstate = &target->thread.vstate;
93-
94-
if (!riscv_v_vstate_query(task_pt_regs(target)))
95-
return -EINVAL;
96-
97-
/*
98-
* Ensure the vector registers have been saved to the memory before
99-
* copying them to membuf.
100-
*/
101-
if (target == current)
102-
riscv_v_vstate_save(current, task_pt_regs(current));
103-
104-
/* Copy vector header from vstate. */
105-
membuf_write(&to, vstate, offsetof(struct __riscv_v_ext_state, datap));
106-
membuf_zero(&to, sizeof(vstate->datap));
107-
108-
/* Copy all the vector registers from vstate. */
109-
return membuf_write(&to, vstate->datap, riscv_v_vsize);
110-
}
111-
112-
static int riscv_vr_set(struct task_struct *target,
113-
const struct user_regset *regset,
114-
unsigned int pos, unsigned int count,
115-
const void *kbuf, const void __user *ubuf)
116-
{
117-
int ret, size;
118-
struct __riscv_v_ext_state *vstate = &target->thread.vstate;
119-
120-
if (!riscv_v_vstate_query(task_pt_regs(target)))
121-
return -EINVAL;
122-
123-
/* Copy rest of the vstate except datap */
124-
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, vstate, 0,
125-
offsetof(struct __riscv_v_ext_state, datap));
126-
if (unlikely(ret))
127-
return ret;
128-
129-
/* Skip copy datap. */
130-
size = sizeof(vstate->datap);
131-
count -= size;
132-
ubuf += size;
133-
134-
/* Copy all the vector registers. */
135-
pos = 0;
136-
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, vstate->datap,
137-
0, riscv_v_vsize);
138-
return ret;
139-
}
140-
#endif
141-
14284
static const struct user_regset riscv_user_regset[] = {
14385
[REGSET_X] = {
14486
.core_note_type = NT_PRSTATUS,
@@ -158,17 +100,6 @@ static const struct user_regset riscv_user_regset[] = {
158100
.set = riscv_fpr_set,
159101
},
160102
#endif
161-
#ifdef CONFIG_RISCV_ISA_V
162-
[REGSET_V] = {
163-
.core_note_type = NT_RISCV_VECTOR,
164-
.align = 16,
165-
.n = ((32 * RISCV_MAX_VLENB) +
166-
sizeof(struct __riscv_v_ext_state)) / sizeof(__u32),
167-
.size = sizeof(__u32),
168-
.regset_get = riscv_vr_get,
169-
.set = riscv_vr_set,
170-
},
171-
#endif
172103
};
173104

174105
static const struct user_regset_view riscv_user_native_view = {

include/uapi/linux/elf.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ typedef struct elf64_shdr {
443443
#define NT_MIPS_DSP 0x800 /* MIPS DSP ASE registers */
444444
#define NT_MIPS_FP_MODE 0x801 /* MIPS floating-point mode */
445445
#define NT_MIPS_MSA 0x802 /* MIPS SIMD registers */
446-
#define NT_RISCV_VECTOR 0x900 /* RISC-V vector registers */
447446
#define NT_LOONGARCH_CPUCFG 0xa00 /* LoongArch CPU config registers */
448447
#define NT_LOONGARCH_CSR 0xa01 /* LoongArch control and status registers */
449448
#define NT_LOONGARCH_LSX 0xa02 /* LoongArch Loongson SIMD Extension registers */

0 commit comments

Comments
 (0)