Skip to content

Commit 9985742

Browse files
Pu Lehuianakryiko
authored andcommitted
libbpf: Fix accessing first syscall argument on RV64
On RV64, as Ilya mentioned before [0], the first syscall parameter should be accessed through orig_a0 (see arch/riscv64/include/asm/syscall.h), otherwise it will cause selftests like bpf_syscall_macro, vmlinux, test_lsm, etc. to fail on RV64. Let's fix it by using the struct pt_regs style CO-RE direct access. Signed-off-by: Pu Lehui <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected] [0] Link: https://lore.kernel.org/bpf/[email protected]
1 parent 4a4c4c0 commit 9985742

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tools/lib/bpf/bpf_tracing.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ struct pt_regs___arm64 {
351351
* https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc#risc-v-calling-conventions
352352
*/
353353

354+
struct pt_regs___riscv {
355+
unsigned long orig_a0;
356+
} __attribute__((preserve_access_index));
357+
354358
/* riscv provides struct user_regs_struct instead of struct pt_regs to userspace */
355359
#define __PT_REGS_CAST(x) ((const struct user_regs_struct *)(x))
356360
#define __PT_PARM1_REG a0
@@ -362,12 +366,15 @@ struct pt_regs___arm64 {
362366
#define __PT_PARM7_REG a6
363367
#define __PT_PARM8_REG a7
364368

365-
#define __PT_PARM1_SYSCALL_REG __PT_PARM1_REG
369+
#define __PT_PARM1_SYSCALL_REG orig_a0
366370
#define __PT_PARM2_SYSCALL_REG __PT_PARM2_REG
367371
#define __PT_PARM3_SYSCALL_REG __PT_PARM3_REG
368372
#define __PT_PARM4_SYSCALL_REG __PT_PARM4_REG
369373
#define __PT_PARM5_SYSCALL_REG __PT_PARM5_REG
370374
#define __PT_PARM6_SYSCALL_REG __PT_PARM6_REG
375+
#define PT_REGS_PARM1_SYSCALL(x) (((const struct pt_regs___riscv *)(x))->__PT_PARM1_SYSCALL_REG)
376+
#define PT_REGS_PARM1_CORE_SYSCALL(x) \
377+
BPF_CORE_READ((const struct pt_regs___riscv *)(x), __PT_PARM1_SYSCALL_REG)
371378

372379
#define __PT_RET_REG ra
373380
#define __PT_FP_REG s0

0 commit comments

Comments
 (0)