[PATCH bpf-next v4 03/14] selftests/bpf: Compile bpf_syscall_macro test also with user headers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Verify that using linux/ptrace.h instead of vmlinux.h works fine.
Since without vmlinux.h and with CO-RE it's not possible to access the
first syscall argument on arm64 and s390x, and any syscall arguments on
Intel, skip the corresponding checks.

Signed-off-by: Ilya Leoshkevich <iii@xxxxxxxxxxxxx>
---
 ...call_macro.c => test_bpf_syscall_macro_common.h} |  8 +++++++-
 .../bpf/prog_tests/test_bpf_syscall_macro_kernel.c  | 13 +++++++++++++
 .../bpf/prog_tests/test_bpf_syscall_macro_user.c    | 13 +++++++++++++
 ...f_syscall_macro.c => bpf_syscall_macro_common.h} |  8 ++++++--
 .../selftests/bpf/progs/bpf_syscall_macro_kernel.c  |  4 ++++
 .../selftests/bpf/progs/bpf_syscall_macro_user.c    | 10 ++++++++++
 6 files changed, 53 insertions(+), 3 deletions(-)
 rename tools/testing/selftests/bpf/prog_tests/{test_bpf_syscall_macro.c => test_bpf_syscall_macro_common.h} (89%)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_kernel.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_user.c
 rename tools/testing/selftests/bpf/progs/{bpf_syscall_macro.c => bpf_syscall_macro_common.h} (87%)
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_syscall_macro_kernel.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_syscall_macro_user.c

diff --git a/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro.c b/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_common.h
similarity index 89%
rename from tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro.c
rename to tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_common.h
index f5f4c8adf539..9f2a395abff7 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro.c
+++ b/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_common.h
@@ -2,7 +2,6 @@
 /* Copyright 2022 Sony Group Corporation */
 #include <sys/prctl.h>
 #include <test_progs.h>
-#include "bpf_syscall_macro.skel.h"
 
 void test_bpf_syscall_macro(void)
 {
@@ -46,7 +45,13 @@ void test_bpf_syscall_macro(void)
 	ASSERT_EQ(skel->bss->arg5, exp_arg5, "syscall_arg5");
 
 	/* check whether args of syscall are copied correctly for CORE variants */
+#if defined(__BPF_SYSCALL_MACRO_KERNEL_SKEL_H__) || \
+		(!defined(__s390__) && !defined(__aarch64__) && \
+		 !defined(__i386__) && !defined(__x86_64__))
 	ASSERT_EQ(skel->bss->arg1_core, exp_arg1, "syscall_arg1_core_variant");
+#endif
+#if defined(__BPF_SYSCALL_MACRO_KERNEL_SKEL_H__) || \
+		(!defined(__i386__) && !defined(__x86_64__))
 	ASSERT_EQ(skel->bss->arg2_core, exp_arg2, "syscall_arg2_core_variant");
 	ASSERT_EQ(skel->bss->arg3_core, exp_arg3, "syscall_arg3_core_variant");
 	/* it cannot copy arg4 when uses PT_REGS_PARM4_CORE on x86_64 */
@@ -57,6 +62,7 @@ void test_bpf_syscall_macro(void)
 #endif
 	ASSERT_EQ(skel->bss->arg4_core, exp_arg4, "syscall_arg4_core_variant");
 	ASSERT_EQ(skel->bss->arg5_core, exp_arg5, "syscall_arg5_core_variant");
+#endif
 
 cleanup:
 	bpf_syscall_macro__destroy(skel);
diff --git a/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_kernel.c b/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_kernel.c
new file mode 100644
index 000000000000..7ceabd62bb0f
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_kernel.c
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "bpf_syscall_macro_kernel.skel.h"
+
+void test_bpf_syscall_macro_kernel(void);
+
+#define test_bpf_syscall_macro test_bpf_syscall_macro_kernel
+#define bpf_syscall_macro bpf_syscall_macro_kernel
+#define bpf_syscall_macro__open bpf_syscall_macro_kernel__open
+#define bpf_syscall_macro__load bpf_syscall_macro_kernel__load
+#define bpf_syscall_macro__attach bpf_syscall_macro_kernel__attach
+#define bpf_syscall_macro__destroy bpf_syscall_macro_kernel__destroy
+
+#include "test_bpf_syscall_macro_common.h"
diff --git a/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_user.c b/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_user.c
new file mode 100644
index 000000000000..f31558f14e7e
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_user.c
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "bpf_syscall_macro_user.skel.h"
+
+void test_bpf_syscall_macro_user(void);
+
+#define test_bpf_syscall_macro test_bpf_syscall_macro_user
+#define bpf_syscall_macro bpf_syscall_macro_user
+#define bpf_syscall_macro__open bpf_syscall_macro_user__open
+#define bpf_syscall_macro__load bpf_syscall_macro_user__load
+#define bpf_syscall_macro__attach bpf_syscall_macro_user__attach
+#define bpf_syscall_macro__destroy bpf_syscall_macro_user__destroy
+
+#include "test_bpf_syscall_macro_common.h"
diff --git a/tools/testing/selftests/bpf/progs/bpf_syscall_macro.c b/tools/testing/selftests/bpf/progs/bpf_syscall_macro_common.h
similarity index 87%
rename from tools/testing/selftests/bpf/progs/bpf_syscall_macro.c
rename to tools/testing/selftests/bpf/progs/bpf_syscall_macro_common.h
index f5c6ef2ff6d1..8717605358d3 100644
--- a/tools/testing/selftests/bpf/progs/bpf_syscall_macro.c
+++ b/tools/testing/selftests/bpf/progs/bpf_syscall_macro_common.h
@@ -1,7 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright 2022 Sony Group Corporation */
-#include <vmlinux.h>
-
 #include <bpf/bpf_core_read.h>
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_tracing.h>
@@ -46,12 +44,18 @@ int BPF_KPROBE(handle_sys_prctl)
 	bpf_probe_read_kernel(&arg5, sizeof(arg5), &PT_REGS_PARM5_SYSCALL(real_regs));
 
 	/* test for the CORE variant of PT_REGS_PARM */
+#if defined(__KERNEL__) || defined(__VMLINUX_H__) || \
+		(!defined(bpf_target_s390) && !defined(bpf_target_arm64) && \
+		 !defined(bpf_target_x86))
 	arg1_core = PT_REGS_PARM1_CORE_SYSCALL(real_regs);
+#endif
+#if defined(__KERNEL__) || defined(__VMLINUX_H__) || !defined(bpf_target_x86)
 	arg2_core = PT_REGS_PARM2_CORE_SYSCALL(real_regs);
 	arg3_core = PT_REGS_PARM3_CORE_SYSCALL(real_regs);
 	arg4_core_cx = PT_REGS_PARM4_CORE(real_regs);
 	arg4_core = PT_REGS_PARM4_CORE_SYSCALL(real_regs);
 	arg5_core = PT_REGS_PARM5_CORE_SYSCALL(real_regs);
+#endif
 
 	return 0;
 }
diff --git a/tools/testing/selftests/bpf/progs/bpf_syscall_macro_kernel.c b/tools/testing/selftests/bpf/progs/bpf_syscall_macro_kernel.c
new file mode 100644
index 000000000000..1affac21266d
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/bpf_syscall_macro_kernel.c
@@ -0,0 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <vmlinux.h>
+
+#include "bpf_syscall_macro_common.h"
diff --git a/tools/testing/selftests/bpf/progs/bpf_syscall_macro_user.c b/tools/testing/selftests/bpf/progs/bpf_syscall_macro_user.c
new file mode 100644
index 000000000000..1c078d528e8c
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/bpf_syscall_macro_user.c
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/ptrace.h>
+#include <linux/types.h>
+#include <sys/types.h>
+
+#include "bpf_syscall_macro_common.h"
+
+#if defined(__KERNEL__) || defined(__VMLINUX_H__)
+#error This test must be compiled with userspace headers
+#endif
-- 
2.34.1




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux