Skip to content

Commit 7884448

Browse files
SiFiveHollandpalmer-dabbelt
authored andcommitted
riscv: Allow ptrace control of the tagged address ABI
This allows a tracer to control the ABI of the tracee, as on arm64. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Link: https://lore.kernel.org/r/20241016202814.4061541-7-samuel.holland@sifive.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 2e17430 commit 7884448

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

arch/riscv/kernel/ptrace.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ enum riscv_regset {
2828
#ifdef CONFIG_RISCV_ISA_V
2929
REGSET_V,
3030
#endif
31+
#ifdef CONFIG_RISCV_ISA_SUPM
32+
REGSET_TAGGED_ADDR_CTRL,
33+
#endif
3134
};
3235

3336
static int riscv_gpr_get(struct task_struct *target,
@@ -152,6 +155,35 @@ static int riscv_vr_set(struct task_struct *target,
152155
}
153156
#endif
154157

158+
#ifdef CONFIG_RISCV_ISA_SUPM
159+
static int tagged_addr_ctrl_get(struct task_struct *target,
160+
const struct user_regset *regset,
161+
struct membuf to)
162+
{
163+
long ctrl = get_tagged_addr_ctrl(target);
164+
165+
if (IS_ERR_VALUE(ctrl))
166+
return ctrl;
167+
168+
return membuf_write(&to, &ctrl, sizeof(ctrl));
169+
}
170+
171+
static int tagged_addr_ctrl_set(struct task_struct *target,
172+
const struct user_regset *regset,
173+
unsigned int pos, unsigned int count,
174+
const void *kbuf, const void __user *ubuf)
175+
{
176+
int ret;
177+
long ctrl;
178+
179+
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ctrl, 0, -1);
180+
if (ret)
181+
return ret;
182+
183+
return set_tagged_addr_ctrl(target, ctrl);
184+
}
185+
#endif
186+
155187
static const struct user_regset riscv_user_regset[] = {
156188
[REGSET_X] = {
157189
.core_note_type = NT_PRSTATUS,
@@ -182,6 +214,16 @@ static const struct user_regset riscv_user_regset[] = {
182214
.set = riscv_vr_set,
183215
},
184216
#endif
217+
#ifdef CONFIG_RISCV_ISA_SUPM
218+
[REGSET_TAGGED_ADDR_CTRL] = {
219+
.core_note_type = NT_RISCV_TAGGED_ADDR_CTRL,
220+
.n = 1,
221+
.size = sizeof(long),
222+
.align = sizeof(long),
223+
.regset_get = tagged_addr_ctrl_get,
224+
.set = tagged_addr_ctrl_set,
225+
},
226+
#endif
185227
};
186228

187229
static const struct user_regset_view riscv_user_native_view = {

include/uapi/linux/elf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ typedef struct elf64_shdr {
450450
#define NT_MIPS_MSA 0x802 /* MIPS SIMD registers */
451451
#define NT_RISCV_CSR 0x900 /* RISC-V Control and Status Registers */
452452
#define NT_RISCV_VECTOR 0x901 /* RISC-V vector registers */
453+
#define NT_RISCV_TAGGED_ADDR_CTRL 0x902 /* RISC-V tagged address control (prctl()) */
453454
#define NT_LOONGARCH_CPUCFG 0xa00 /* LoongArch CPU config registers */
454455
#define NT_LOONGARCH_CSR 0xa01 /* LoongArch control and status registers */
455456
#define NT_LOONGARCH_LSX 0xa02 /* LoongArch Loongson SIMD Extension registers */

0 commit comments

Comments
 (0)