Skip to contentSkip to conversation

Fix accessing syscall arguments

PATCH Applied Ilya Leoshkevich 3 participants 16 messages Feb 9, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v5 cover Fix accessing syscall arguments

libbpf now has macros to access syscall arguments in an architecture-agnostic manner, but unfortunately they have a number of issues on non-Intel arches, which this series aims to fix.

v1: https://lore.kernel.org/bpf/[email protected]/
v1 -> v2:
* Put orig_gpr2 in place of args[1] on s390 (Vasily).
* Fix arm64, powerpc and riscv (Heiko).

v2: https://lore.kernel.org/bpf/[email protected]/
v2 -> v3:
* Undo args[1] change (Andrii).
* Rename PT_REGS_SYSCALL to PT_REGS_SYSCALL_REGS (Andrii).
* Split the riscv patch (Andrii).

v3: https://lore.kernel.org/bpf/[email protected]/
v3 -> v4:
* Undo arm64's and s390's user_pt_regs changes.
* Use struct pt_regs when vmlinux.h is available (Andrii).
* Use offsetofend for accessing orig_gpr2 and orig_x0 (Andrii).
* Move libbpf's copy of offsetofend to a new header.
* Fix riscv's __PT_FP_REG.
* Use PT_REGS_SYSCALL_REGS in test_probe_user.c.
* Test bpf_syscall_macro with userspace headers.
* Use Naveen's suggestions and code in patches 5 and 6.
* Add warnings to arm64's and s390's ptrace.h (Andrii).

v4: https://lore.kernel.org/bpf/[email protected]/
v4 -> v5:
* Go back to v3.
* Do not touch arch headers.
* Use CO-RE struct flavors to access orig_x0 and orig_gpr2.
* Fail compilation if non-CO-RE macros are used to access the first syscall parameter on arm64 and s390.
* Fix accessing frame pointer on riscv.

Ilya Leoshkevich (10):
selftests/bpf: Fix an endianness issue in bpf_syscall_macro test
libbpf: Add PT_REGS_SYSCALL_REGS macro
selftests/bpf: Use PT_REGS_SYSCALL_REGS in bpf_syscall_macro
libbpf: Fix accessing syscall arguments on powerpc
libbpf: Fix riscv register names
libbpf: Fix accessing syscall arguments on riscv selftests/bpf: Skip test_bpf_syscall_macro:syscall_arg1 on arm64 and

    s390

libbpf: Allow overriding PT_REGS_PARM1{_CORE}_SYSCALL
libbpf: Fix accessing the first syscall argument on arm64
libbpf: Fix accessing the first syscall argument on s390

 tools/lib/bpf/bpf_tracing.h                   | 42 ++++++++++++++++++-
 .../bpf/prog_tests/test_bpf_syscall_macro.c   |  4 ++
 .../selftests/bpf/progs/bpf_syscall_macro.c   |  9 +++-
 3 files changed, 51 insertions(+), 4 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v5 1/10 selftests/bpf: Fix an endianness issue in bpf_syscall_macro test

bpf_syscall_macro reads a long argument into an int variable, which produces a wrong value on big-endian systems. Fix by reading the argument into an intermediate long variable first.

Fixes 77fc0330dfe5 ("selftests/bpf: Add a test to confirm PT_REGS_PARM4_SYSCALL")
---
 tools/testing/selftests/bpf/progs/bpf_syscall_macro.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/progs/bpf_syscall_macro.c +4 -1
index c8e60220cda8..f5c6ef2ff6d1 100644
@@ -28,6 +28,7 @@ int BPF_KPROBE(handle_sys_prctl)
 {
 	struct pt_regs *real_regs;
 	pid_t pid = bpf_get_current_pid_tgid() >> 32;
+	unsigned long tmp;
 
 	if (pid != filter_pid)
 		return 0;
@@ -35,7 +36,9 @@ int BPF_KPROBE(handle_sys_prctl)
 	real_regs = (struct pt_regs *)PT_REGS_PARM1(ctx);
 
 	/* test for PT_REGS_PARM */
-	bpf_probe_read_kernel(&arg1, sizeof(arg1), &PT_REGS_PARM1_SYSCALL(real_regs));
+
+	bpf_probe_read_kernel(&tmp, sizeof(tmp), &PT_REGS_PARM1_SYSCALL(real_regs));
+	arg1 = tmp;
 	bpf_probe_read_kernel(&arg2, sizeof(arg2), &PT_REGS_PARM2_SYSCALL(real_regs));
 	bpf_probe_read_kernel(&arg3, sizeof(arg3), &PT_REGS_PARM3_SYSCALL(real_regs));
 	bpf_probe_read_kernel(&arg4_cx, sizeof(arg4_cx), &PT_REGS_PARM4(real_regs));
Signature · 1 line
2.34.1
#2 lore raw

PATCH v5 2/10 libbpf: Add PT_REGS_SYSCALL_REGS macro

In reply to Ilya Leoshkevich

Architectures that select ARCH_HAS_SYSCALL_WRAPPER pass a pointer to struct pt_regs to syscall handlers, others unpack it into individual function parameters. Introduce a macro to describe what a particular arch does.

---
 tools/lib/bpf/bpf_tracing.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
tools/lib/bpf/bpf_tracing.h +10 -0
index 032ba809f3e5..a5e92656bfba 100644
@@ -326,6 +326,16 @@ struct pt_regs;
 
 #endif /* defined(bpf_target_defined) */
 
+/*
+ * When invoked from a syscall handler kprobe, returns a pointer to a
+ * struct pt_regs containing syscall arguments and suitable for passing to
+ * PT_REGS_PARMn_SYSCALL() and PT_REGS_PARMn_CORE_SYSCALL().
+ */
+#ifndef PT_REGS_SYSCALL_REGS
+/* By default, assume that the arch selects ARCH_HAS_SYSCALL_WRAPPER. */
+#define PT_REGS_SYSCALL_REGS(ctx) ((struct pt_regs *)PT_REGS_PARM1(ctx))
+#endif
+
 #ifndef ___bpf_concat
 #define ___bpf_concat(a, b) a ## b
 #endif
Signature · 1 line
2.34.1
#3 lore raw

PATCH v5 3/10 selftests/bpf: Use PT_REGS_SYSCALL_REGS in bpf_syscall_macro

In reply to Ilya Leoshkevich

Ensure that PT_REGS_SYSCALL_REGS works correctly.

---
 tools/testing/selftests/bpf/progs/bpf_syscall_macro.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/progs/bpf_syscall_macro.c +1 -1
index f5c6ef2ff6d1..e7c622cb6a39 100644
@@ -33,7 +33,7 @@ int BPF_KPROBE(handle_sys_prctl)
 	if (pid != filter_pid)
 		return 0;
 
-	real_regs = (struct pt_regs *)PT_REGS_PARM1(ctx);
+	real_regs = PT_REGS_SYSCALL_REGS(ctx);
 
 	/* test for PT_REGS_PARM */
 
Signature · 1 line
2.34.1
#4 lore raw

PATCH v5 4/10 libbpf: Fix accessing syscall arguments on powerpc

In reply to Ilya Leoshkevich

powerpc does not select ARCH_HAS_SYSCALL_WRAPPER, so its syscall handlers take "unpacked" syscall arguments. Indicate this to libbpf using PT_REGS_SYSCALL_REGS macro.

---
 tools/lib/bpf/bpf_tracing.h | 2 ++
 1 file changed, 2 insertions(+)
tools/lib/bpf/bpf_tracing.h +2 -0
index a5e92656bfba..20bc63770c9f 100644
@@ -180,6 +180,8 @@
 #define __PT_RC_REG gpr[3]
 #define __PT_SP_REG sp
 #define __PT_IP_REG nip
+/* powerpc does not select ARCH_HAS_SYSCALL_WRAPPER. */
+#define PT_REGS_SYSCALL_REGS(ctx) ctx
 
 #elif defined(bpf_target_sparc)
 
Signature · 1 line
2.34.1
#5 lore raw

PATCH v5 5/10 libbpf: Fix riscv register names

In reply to Ilya Leoshkevich

riscv registers are accessed via struct user_regs_struct, not struct pt_regs. The program counter member in this struct is called pc, not epc. The frame pointer is called s0, not fp.

Fixes 3cc31d794097 ("libbpf: Normalize PT_REGS_xxx() macro definitions")
---
 tools/lib/bpf/bpf_tracing.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/lib/bpf/bpf_tracing.h +2 -2
index 20bc63770c9f..03e501ac8f60 100644
@@ -210,10 +210,10 @@
 #define __PT_PARM4_REG a3
 #define __PT_PARM5_REG a4
 #define __PT_RET_REG ra
-#define __PT_FP_REG fp
+#define __PT_FP_REG s0
 #define __PT_RC_REG a5
 #define __PT_SP_REG sp
-#define __PT_IP_REG epc
+#define __PT_IP_REG pc
 
 #endif
 
Signature · 1 line
2.34.1
#6 lore raw

PATCH v5 6/10 libbpf: Fix accessing syscall arguments on riscv

In reply to Ilya Leoshkevich

riscv does not select ARCH_HAS_SYSCALL_WRAPPER, so its syscall handlers take "unpacked" syscall arguments. Indicate this to libbpf using PT_REGS_SYSCALL_REGS macro.

---
 tools/lib/bpf/bpf_tracing.h | 2 ++
 1 file changed, 2 insertions(+)
tools/lib/bpf/bpf_tracing.h +2 -0
index 03e501ac8f60..41a015ee6bfb 100644
@@ -214,6 +214,8 @@
 #define __PT_RC_REG a5
 #define __PT_SP_REG sp
 #define __PT_IP_REG pc
+/* riscv does not select ARCH_HAS_SYSCALL_WRAPPER. */
+#define PT_REGS_SYSCALL_REGS(ctx) ctx
 
 #endif
 
Signature · 1 line
2.34.1
#7 lore raw

PATCH v5 7/10 selftests/bpf: Skip test_bpf_syscall_macro:syscall_arg1 on arm64 and s390

In reply to Ilya Leoshkevich

These architectures can provide access to the first syscall argument only through PT_REGS_PARM1_CORE_SYSCALL().

---
 .../testing/selftests/bpf/prog_tests/test_bpf_syscall_macro.c | 4 ++++
 tools/testing/selftests/bpf/progs/bpf_syscall_macro.c         | 4 +++-
 2 files changed, 7 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro.c +4 -0
index f5f4c8adf539..8bc58bda500d 100644
@@ -33,7 +33,11 @@ void test_bpf_syscall_macro(void)
 
 	/* check whether args of syscall are copied correctly */
 	prctl(exp_arg1, exp_arg2, exp_arg3, exp_arg4, exp_arg5);
+#if defined(__aarch64__) || defined(__s390__)
+	ASSERT_NEQ(skel->bss->arg1, exp_arg1, "syscall_arg1");
+#else
 	ASSERT_EQ(skel->bss->arg1, exp_arg1, "syscall_arg1");
+#endif
 	ASSERT_EQ(skel->bss->arg2, exp_arg2, "syscall_arg2");
 	ASSERT_EQ(skel->bss->arg3, exp_arg3, "syscall_arg3");
 	/* it cannot copy arg4 when uses PT_REGS_PARM4 on x86_64 */
tools/testing/selftests/bpf/progs/bpf_syscall_macro.c +3 -1
index e7c622cb6a39..496e54d0ac22 100644
@@ -28,7 +28,7 @@ int BPF_KPROBE(handle_sys_prctl)
 {
 	struct pt_regs *real_regs;
 	pid_t pid = bpf_get_current_pid_tgid() >> 32;
-	unsigned long tmp;
+	unsigned long tmp = 0;
 
 	if (pid != filter_pid)
 		return 0;
@@ -37,7 +37,9 @@ int BPF_KPROBE(handle_sys_prctl)
 
 	/* test for PT_REGS_PARM */
 
+#if !defined(bpf_target_arm64) && !defined(bpf_target_s390)
 	bpf_probe_read_kernel(&tmp, sizeof(tmp), &PT_REGS_PARM1_SYSCALL(real_regs));
+#endif
 	arg1 = tmp;
 	bpf_probe_read_kernel(&arg2, sizeof(arg2), &PT_REGS_PARM2_SYSCALL(real_regs));
 	bpf_probe_read_kernel(&arg3, sizeof(arg3), &PT_REGS_PARM3_SYSCALL(real_regs));
Signature · 1 line
2.34.1
#8 lore raw

PATCH v5 8/10 libbpf: Allow overriding PT_REGS_PARM1{_CORE}_SYSCALL

In reply to Ilya Leoshkevich

arm64 and s390 need a special way to access the first syscall argument.

---
 tools/lib/bpf/bpf_tracing.h | 4 ++++
 1 file changed, 4 insertions(+)
tools/lib/bpf/bpf_tracing.h +4 -0
index 41a015ee6bfb..f364f1f4710e 100644
@@ -269,7 +269,9 @@ struct pt_regs;
 
 #endif
 
+#ifndef PT_REGS_PARM1_SYSCALL
 #define PT_REGS_PARM1_SYSCALL(x) PT_REGS_PARM1(x)
+#endif
 #define PT_REGS_PARM2_SYSCALL(x) PT_REGS_PARM2(x)
 #define PT_REGS_PARM3_SYSCALL(x) PT_REGS_PARM3(x)
 #ifdef __PT_PARM4_REG_SYSCALL
@@ -279,7 +281,9 @@ struct pt_regs;
 #endif
 #define PT_REGS_PARM5_SYSCALL(x) PT_REGS_PARM5(x)
 
+#ifndef PT_REGS_PARM1_CORE_SYSCALL
 #define PT_REGS_PARM1_CORE_SYSCALL(x) PT_REGS_PARM1_CORE(x)
+#endif
 #define PT_REGS_PARM2_CORE_SYSCALL(x) PT_REGS_PARM2_CORE(x)
 #define PT_REGS_PARM3_CORE_SYSCALL(x) PT_REGS_PARM3_CORE(x)
 #ifdef __PT_PARM4_REG_SYSCALL
Signature · 1 line
2.34.1
#9 lore raw

Re: [PATCH bpf-next v5 08/10] libbpf: Allow overriding PT_REGS_PARM1{_CORE}_SYSCALL

Quoted 23 lines · Ilya Leoshkevich

arm64 and s390 need a special way to access the first syscall argument.

---
 tools/lib/bpf/bpf_tracing.h | 4 ++++
 1 file changed, 4 insertions(+)
tools/lib/bpf/bpf_tracing.h +2 -0
index 41a015ee6bfb..f364f1f4710e 100644
@@ -269,7 +269,9 @@ struct pt_regs;
 
 #endif
 
+#ifndef PT_REGS_PARM1_SYSCALL
 #define PT_REGS_PARM1_SYSCALL(x) PT_REGS_PARM1(x)
+#endif
 #define PT_REGS_PARM2_SYSCALL(x) PT_REGS_PARM2(x)
 #define PT_REGS_PARM3_SYSCALL(x) PT_REGS_PARM3(x)
 #ifdef __PT_PARM4_REG_SYSCALL

tools/lib/bpf/bpf_tracing.h struct pt_regs; · line 289

Quoted 9 lines
tools/lib/bpf/bpf_tracing.h +2 -0
@@ -279,7 +281,9 @@ struct pt_regs;
 #endif
 #define PT_REGS_PARM5_SYSCALL(x) PT_REGS_PARM5(x)
 
+#ifndef PT_REGS_PARM1_CORE_SYSCALL
 #define PT_REGS_PARM1_CORE_SYSCALL(x) PT_REGS_PARM1_CORE(x)
+#endif
 #define PT_REGS_PARM2_CORE_SYSCALL(x) PT_REGS_PARM2_CORE(x)
 #define PT_REGS_PARM3_CORE_SYSCALL(x) PT_REGS_PARM3_CORE(x)
 #ifdef __PT_PARM4_REG_SYSCALL

I've changed PARM4 handling to be the same as for PARM1 for consistency (and flexibility, if we ever need as much)

Quoted 3 lines

--
2.34.1

#10 lore raw

PATCH v5 9/10 libbpf: Fix accessing the first syscall argument on arm64

In reply to Ilya Leoshkevich

On arm64, the first syscall argument should be accessed via orig_x0 (see arch/arm64/include/asm/syscall.h). Currently regs[0] is used instead, leading to bpf_syscall_macro test failure.

orig_x0 cannot be added to struct user_pt_regs, since its layout is a part of the ABI. Therefore provide access to it only through PT_REGS_PARM1_CORE_SYSCALL() by using a struct pt_regs flavor.

---
 tools/lib/bpf/bpf_tracing.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
tools/lib/bpf/bpf_tracing.h +10 -0
index f364f1f4710e..928f85f7961c 100644
@@ -142,8 +142,18 @@
 
 #elif defined(bpf_target_arm64)
 
+struct pt_regs___arm64 {
+	unsigned long orig_x0;
+} __attribute__((preserve_access_index));
+
 /* arm64 provides struct user_pt_regs instead of struct pt_regs to userspace */
 #define __PT_REGS_CAST(x) ((const struct user_pt_regs *)(x))
+#define PT_REGS_PARM1_SYSCALL(x) ({ \
+	_Pragma("GCC error \"PT_REGS_PARM1_SYSCALL() is not supported on arm64, use PT_REGS_PARM1_CORE_SYSCALL() instead\""); \
+	0l; \
+})
+#define PT_REGS_PARM1_CORE_SYSCALL(x) \
+	BPF_CORE_READ((const struct pt_regs___arm64 *)(x), orig_x0)
 #define __PT_PARM1_REG regs[0]
 #define __PT_PARM2_REG regs[1]
 #define __PT_PARM3_REG regs[2]
Signature · 1 line
2.34.1
#11 lore raw

Re: [PATCH bpf-next v5 09/10] libbpf: Fix accessing the first syscall argument on arm64

Quoted 20 lines · Ilya Leoshkevich

On arm64, the first syscall argument should be accessed via orig_x0 (see arch/arm64/include/asm/syscall.h). Currently regs[0] is used instead, leading to bpf_syscall_macro test failure.

orig_x0 cannot be added to struct user_pt_regs, since its layout is a part of the ABI. Therefore provide access to it only through PT_REGS_PARM1_CORE_SYSCALL() by using a struct pt_regs flavor.

---
 tools/lib/bpf/bpf_tracing.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
tools/lib/bpf/bpf_tracing.h +0 -0
index f364f1f4710e..928f85f7961c 100644

tools/lib/bpf/bpf_tracing.h line 148

Quoted 7 lines
tools/lib/bpf/bpf_tracing.h +4 -0
@@ -142,8 +142,18 @@
 
 #elif defined(bpf_target_arm64)
 
+struct pt_regs___arm64 {
+       unsigned long orig_x0;
+} __attribute__((preserve_access_index));
+

I just realized that this will probably break anyone who's using old Clang to compile a non-CORE BPF program because preserve_access_index attribute will be unknown.

But we don't have to use __attribute__((preserve_access_index)) here, because we use BPF_CORE_READ() in those macro, which will make accesses CO-RE-relocatable anyways. So I dropped __attribute__((preserve_access_index)) for better backwards compatibility.

tools/lib/bpf/bpf_tracing.h line 154

Quoted 6 lines
tools/lib/bpf/bpf_tracing.h +4 -0
 /* arm64 provides struct user_pt_regs instead of struct pt_regs to userspace */
 #define __PT_REGS_CAST(x) ((const struct user_pt_regs *)(x))
+#define PT_REGS_PARM1_SYSCALL(x) ({ \
+       _Pragma("GCC error \"PT_REGS_PARM1_SYSCALL() is not supported on arm64, use PT_REGS_PARM1_CORE_SYSCALL() instead\""); \
+       0l; \
+})

I shortened message to just "use PT_REGS_PARM1_CORE_SYSCALL() instead" and made it into a single-liner

tools/lib/bpf/bpf_tracing.h line 156

Quoted 2 lines
tools/lib/bpf/bpf_tracing.h +2 -0
+#define PT_REGS_PARM1_CORE_SYSCALL(x) \
+       BPF_CORE_READ((const struct pt_regs___arm64 *)(x), orig_x0)

also made this into a single-liner

Quoted 6 lines
tools/lib/bpf/bpf_tracing.h +0 -1
 #define __PT_PARM1_REG regs[0]
 #define __PT_PARM2_REG regs[1]
 #define __PT_PARM3_REG regs[2]
--

2.34.1

#12 lore raw

PATCH v5 10/10 libbpf: Fix accessing the first syscall argument on s390

In reply to Ilya Leoshkevich

On s390, the first syscall argument should be accessed via orig_gpr2 (see arch/s390/include/asm/syscall.h). Currently gpr[2] is used instead, leading to bpf_syscall_macro test failure.

orig_gpr2 cannot be added to user_pt_regs, since its layout is a part of the ABI. Therefore provide access to it only through PT_REGS_PARM1_CORE_SYSCALL() by using a struct pt_regs flavor.

---
 tools/lib/bpf/bpf_tracing.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
tools/lib/bpf/bpf_tracing.h +10 -0
index 928f85f7961c..0e0414801457 100644
@@ -114,9 +114,19 @@
 
 #elif defined(bpf_target_s390)
 
+struct pt_regs___s390 {
+	unsigned long orig_gpr2;
+} __attribute__((preserve_access_index));
+
 /* s390 provides user_pt_regs instead of struct pt_regs to userspace */
 #define __PT_REGS_CAST(x) ((const user_pt_regs *)(x))
 #define __PT_PARM1_REG gprs[2]
+#define PT_REGS_PARM1_SYSCALL(x) ({ \
+	_Pragma("GCC error \"PT_REGS_PARM1_SYSCALL() is not supported on s390, use PT_REGS_PARM1_CORE_SYSCALL() instead\""); \
+	0l; \
+})
+#define PT_REGS_PARM1_CORE_SYSCALL(x) \
+	BPF_CORE_READ((const struct pt_regs___s390 *)(x), orig_gpr2)
 #define __PT_PARM2_REG gprs[3]
 #define __PT_PARM3_REG gprs[4]
 #define __PT_PARM4_REG gprs[5]
Signature · 1 line
2.34.1
#13 lore raw

Re: [PATCH bpf-next v5 10/10] libbpf: Fix accessing the first syscall argument on s390

Quoted 26 lines · Ilya Leoshkevich

On s390, the first syscall argument should be accessed via orig_gpr2 (see arch/s390/include/asm/syscall.h). Currently gpr[2] is used instead, leading to bpf_syscall_macro test failure.

orig_gpr2 cannot be added to user_pt_regs, since its layout is a part of the ABI. Therefore provide access to it only through PT_REGS_PARM1_CORE_SYSCALL() by using a struct pt_regs flavor.

---
 tools/lib/bpf/bpf_tracing.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
tools/lib/bpf/bpf_tracing.h +3 -0
index 928f85f7961c..0e0414801457 100644
@@ -114,9 +114,19 @@
 
 #elif defined(bpf_target_s390)
 
+struct pt_regs___s390 {
+       unsigned long orig_gpr2;
+} __attribute__((preserve_access_index));

tools/lib/bpf/bpf_tracing.h line 129

Quoted 10 lines
tools/lib/bpf/bpf_tracing.h +7 -0
+
 /* s390 provides user_pt_regs instead of struct pt_regs to userspace */
 #define __PT_REGS_CAST(x) ((const user_pt_regs *)(x))
 #define __PT_PARM1_REG gprs[2]
+#define PT_REGS_PARM1_SYSCALL(x) ({ \
+       _Pragma("GCC error \"PT_REGS_PARM1_SYSCALL() is not supported on s390, use PT_REGS_PARM1_CORE_SYSCALL() instead\""); \
+       0l; \
+})
+#define PT_REGS_PARM1_CORE_SYSCALL(x) \
+       BPF_CORE_READ((const struct pt_regs___s390 *)(x), orig_gpr2)

same manipulations as on previous patch

Quoted 6 lines
tools/lib/bpf/bpf_tracing.h +0 -1
 #define __PT_PARM2_REG gprs[3]
 #define __PT_PARM3_REG gprs[4]
 #define __PT_PARM4_REG gprs[5]
--

2.34.1

#14 lore raw
In reply to Ilya Leoshkevich
Quoted 45 lines · Ilya Leoshkevich

libbpf now has macros to access syscall arguments in an architecture-agnostic manner, but unfortunately they have a number of issues on non-Intel arches, which this series aims to fix.

v1: https://lore.kernel.org/bpf/[email protected]/
v1 -> v2:
* Put orig_gpr2 in place of args[1] on s390 (Vasily).
* Fix arm64, powerpc and riscv (Heiko).

v2: https://lore.kernel.org/bpf/[email protected]/
v2 -> v3:
* Undo args[1] change (Andrii).
* Rename PT_REGS_SYSCALL to PT_REGS_SYSCALL_REGS (Andrii).
* Split the riscv patch (Andrii).

v3: https://lore.kernel.org/bpf/[email protected]/
v3 -> v4:
* Undo arm64's and s390's user_pt_regs changes.
* Use struct pt_regs when vmlinux.h is available (Andrii).
* Use offsetofend for accessing orig_gpr2 and orig_x0 (Andrii).
* Move libbpf's copy of offsetofend to a new header.
* Fix riscv's __PT_FP_REG.
* Use PT_REGS_SYSCALL_REGS in test_probe_user.c.
* Test bpf_syscall_macro with userspace headers.
* Use Naveen's suggestions and code in patches 5 and 6.
* Add warnings to arm64's and s390's ptrace.h (Andrii).

v4: https://lore.kernel.org/bpf/[email protected]/
v4 -> v5:
* Go back to v3.
* Do not touch arch headers.
* Use CO-RE struct flavors to access orig_x0 and orig_gpr2.
* Fail compilation if non-CO-RE macros are used to access the first syscall parameter on arm64 and s390.
* Fix accessing frame pointer on riscv.

Ilya Leoshkevich (10):
selftests/bpf: Fix an endianness issue in bpf_syscall_macro test
libbpf: Add PT_REGS_SYSCALL_REGS macro
selftests/bpf: Use PT_REGS_SYSCALL_REGS in bpf_syscall_macro
libbpf: Fix accessing syscall arguments on powerpc
libbpf: Fix riscv register names
libbpf: Fix accessing syscall arguments on riscv selftests/bpf: Skip test_bpf_syscall_macro:syscall_arg1 on arm64 and

Quoted 5 lines
    s390

libbpf: Allow overriding PT_REGS_PARM1{_CORE}_SYSCALL
libbpf: Fix accessing the first syscall argument on arm64
libbpf: Fix accessing the first syscall argument on s390

Applied to bpf-next with few adjustments in patches 8-10, thanks. I'll sync all this to Github shortly to run it through s390x CI tests as well.

Quoted 8 lines
 tools/lib/bpf/bpf_tracing.h                   | 42 ++++++++++++++++++-
 .../bpf/prog_tests/test_bpf_syscall_macro.c   |  4 ++
 .../selftests/bpf/progs/bpf_syscall_macro.c   |  9 +++-
 3 files changed, 51 insertions(+), 4 deletions(-)

--
2.34.1

#15 lore raw
In reply to Ilya Leoshkevich
This series was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This series was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Quoted 10 lines · On Wed, 9 Feb 2022 03:17:35 +0100 you wrote:

libbpf now has macros to access syscall arguments in an architecture-agnostic manner, but unfortunately they have a number of issues on non-Intel arches, which this series aims to fix.

v1: https://lore.kernel.org/bpf/[email protected]/
v1 -> v2:
* Put orig_gpr2 in place of args[1] on s390 (Vasily).
* Fix arm64, powerpc and riscv (Heiko).

[...]

Here is the summary with links:
- [bpf-next,v5,01/10] selftests/bpf: Fix an endianness issue in bpf_syscall_macro test

    https://git.kernel.org/bpf/bpf-next/c/4fc49b51ab9d
  - [bpf-next,v5,02/10] libbpf: Add PT_REGS_SYSCALL_REGS macro
    https://git.kernel.org/bpf/bpf-next/c/c5a1ffa0da76
  - [bpf-next,v5,03/10] selftests/bpf: Use PT_REGS_SYSCALL_REGS in bpf_syscall_macro
    https://git.kernel.org/bpf/bpf-next/c/3f928cab927c
  - [bpf-next,v5,04/10] libbpf: Fix accessing syscall arguments on powerpc
    https://git.kernel.org/bpf/bpf-next/c/f07f1503469b
  - [bpf-next,v5,05/10] libbpf: Fix riscv register names
    https://git.kernel.org/bpf/bpf-next/c/5c101153bfd6
  - [bpf-next,v5,06/10] libbpf: Fix accessing syscall arguments on riscv
    https://git.kernel.org/bpf/bpf-next/c/cf0b5b276923
  - [bpf-next,v5,07/10] selftests/bpf: Skip test_bpf_syscall_macro:syscall_arg1 on arm64 and s390
    https://git.kernel.org/bpf/bpf-next/c/9e45a377f29b
  - [bpf-next,v5,08/10] libbpf: Allow overriding PT_REGS_PARM1{_CORE}_SYSCALL
    https://git.kernel.org/bpf/bpf-next/c/60d16c5ccb81
  - [bpf-next,v5,09/10] libbpf: Fix accessing the first syscall argument on arm64
    https://git.kernel.org/bpf/bpf-next/c/fbca4a2f6497
  - [bpf-next,v5,10/10] libbpf: Fix accessing the first syscall argument on s390
    https://git.kernel.org/bpf/bpf-next/c/1f22a6f9f9a0

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html