Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libbpf: Access first syscall argument with CO-RE direct read on arm64

Currently PT_REGS_PARM1 SYSCALL(x) is consistent with PT_REGS_PARM1_CORE
SYSCALL(x), which will introduce the overhead of BPF_CORE_READ(), taking
into account the read pt_regs comes directly from the context, let's use
CO-RE direct read to access the first system call argument.

Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Pu Lehui <pulehui@huawei.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Xu Kuohai <xukuohai@huawei.com>
Link: https://lore.kernel.org/bpf/20240831041934.1629216-3-pulehui@huaweicloud.com

authored by

Pu Lehui and committed by
Andrii Nakryiko
9ab94078 e4db2a82

+2 -2
+2 -2
tools/lib/bpf/bpf_tracing.h
··· 222 222 223 223 struct pt_regs___arm64 { 224 224 unsigned long orig_x0; 225 - }; 225 + } __attribute__((preserve_access_index)); 226 226 227 227 /* arm64 provides struct user_pt_regs instead of struct pt_regs to userspace */ 228 228 #define __PT_REGS_CAST(x) ((const struct user_pt_regs *)(x)) ··· 241 241 #define __PT_PARM4_SYSCALL_REG __PT_PARM4_REG 242 242 #define __PT_PARM5_SYSCALL_REG __PT_PARM5_REG 243 243 #define __PT_PARM6_SYSCALL_REG __PT_PARM6_REG 244 - #define PT_REGS_PARM1_SYSCALL(x) PT_REGS_PARM1_CORE_SYSCALL(x) 244 + #define PT_REGS_PARM1_SYSCALL(x) (((const struct pt_regs___arm64 *)(x))->__PT_PARM1_SYSCALL_REG) 245 245 #define PT_REGS_PARM1_CORE_SYSCALL(x) \ 246 246 BPF_CORE_READ((const struct pt_regs___arm64 *)(x), __PT_PARM1_SYSCALL_REG) 247 247