BPF List
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii@kernel.org>
To: <bpf@vger.kernel.org>, <ast@kernel.org>, <daniel@iogearbox.net>
Cc: <andrii@kernel.org>, <kernel-team@fb.com>,
	Alan Maguire <alan.maguire@oracle.com>,
	Ilya Leoshkevich <iii@linux.ibm.com>
Subject: [PATCH v2 bpf-next 24/25] selftests/bpf: add 6-argument syscall tracing test
Date: Fri, 20 Jan 2023 12:09:13 -0800	[thread overview]
Message-ID: <20230120200914.3008030-25-andrii@kernel.org> (raw)
In-Reply-To: <20230120200914.3008030-1-andrii@kernel.org>

Turns out splice() is one of the syscalls that's using current maximum
number of arguments (six). This is perfect for testing, so extend
bpf_syscall_macro selftest to also trace splice() syscall, using
BPF_KSYSCALL() macro. This makes sure all the syscall argument register
definitions are correct.

Tested-by: Alan Maguire <alan.maguire@oracle.com> # arm64
Tested-by: Ilya Leoshkevich <iii@linux.ibm.com> # s390x
Suggested-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 .../bpf/prog_tests/test_bpf_syscall_macro.c   | 17 ++++++++++++
 .../selftests/bpf/progs/bpf_syscall_macro.c   | 26 +++++++++++++++++++
 2 files changed, 43 insertions(+)

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.c
index c381faaae741..2900c5e9a016 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro.c
+++ b/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro.c
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright 2022 Sony Group Corporation */
+#define _GNU_SOURCE
+#include <fcntl.h>
 #include <sys/prctl.h>
 #include <test_progs.h>
 #include "bpf_syscall_macro.skel.h"
@@ -13,6 +15,8 @@ void test_bpf_syscall_macro(void)
 	unsigned long exp_arg3 = 13;
 	unsigned long exp_arg4 = 14;
 	unsigned long exp_arg5 = 15;
+	loff_t off_in, off_out;
+	ssize_t r;
 
 	/* check whether it can open program */
 	skel = bpf_syscall_macro__open();
@@ -33,6 +37,7 @@ 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
@@ -68,6 +73,18 @@ void test_bpf_syscall_macro(void)
 	ASSERT_EQ(skel->bss->arg4_syscall, exp_arg4, "BPF_KPROBE_SYSCALL_arg4");
 	ASSERT_EQ(skel->bss->arg5_syscall, exp_arg5, "BPF_KPROBE_SYSCALL_arg5");
 
+	r = splice(-42, &off_in, 42, &off_out, 0x12340000, SPLICE_F_NONBLOCK);
+	err = -errno;
+	ASSERT_EQ(r, -1, "splice_res");
+	ASSERT_EQ(err, -EBADF, "splice_err");
+
+	ASSERT_EQ(skel->bss->splice_fd_in, -42, "splice_arg1");
+	ASSERT_EQ(skel->bss->splice_off_in, (__u64)&off_in, "splice_arg2");
+	ASSERT_EQ(skel->bss->splice_fd_out, 42, "splice_arg3");
+	ASSERT_EQ(skel->bss->splice_off_out, (__u64)&off_out, "splice_arg4");
+	ASSERT_EQ(skel->bss->splice_len, 0x12340000, "splice_arg5");
+	ASSERT_EQ(skel->bss->splice_flags, SPLICE_F_NONBLOCK, "splice_arg6");
+
 cleanup:
 	bpf_syscall_macro__destroy(skel);
 }
diff --git a/tools/testing/selftests/bpf/progs/bpf_syscall_macro.c b/tools/testing/selftests/bpf/progs/bpf_syscall_macro.c
index e1e11897e99b..1a476d8ed354 100644
--- a/tools/testing/selftests/bpf/progs/bpf_syscall_macro.c
+++ b/tools/testing/selftests/bpf/progs/bpf_syscall_macro.c
@@ -81,4 +81,30 @@ int BPF_KSYSCALL(prctl_enter, int option, unsigned long arg2,
 	return 0;
 }
 
+__u64 splice_fd_in;
+__u64 splice_off_in;
+__u64 splice_fd_out;
+__u64 splice_off_out;
+__u64 splice_len;
+__u64 splice_flags;
+
+SEC("ksyscall/splice")
+int BPF_KSYSCALL(splice_enter, int fd_in, loff_t *off_in, int fd_out,
+		 loff_t *off_out, size_t len, unsigned int flags)
+{
+	pid_t pid = bpf_get_current_pid_tgid() >> 32;
+
+	if (pid != filter_pid)
+		return 0;
+
+	splice_fd_in = fd_in;
+	splice_off_in = (__u64)off_in;
+	splice_fd_out = fd_out;
+	splice_off_out = (__u64)off_out;
+	splice_len = len;
+	splice_flags = flags;
+
+	return 0;
+}
+
 char _license[] SEC("license") = "GPL";
-- 
2.30.2


  parent reply	other threads:[~2023-01-20 20:10 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-20 20:08 [PATCH v2 bpf-next 00/25] libbpf: extend [ku]probe and syscall argument tracing support Andrii Nakryiko
2023-01-20 20:08 ` [PATCH v2 bpf-next 01/25] libbpf: add support for fetching up to 8 arguments in kprobes Andrii Nakryiko
2023-01-20 20:08 ` [PATCH v2 bpf-next 02/25] libbpf: add 6th argument support for x86-64 in bpf_tracing.h Andrii Nakryiko
2023-01-20 20:08 ` [PATCH v2 bpf-next 03/25] libbpf: fix arm and arm64 specs " Andrii Nakryiko
2023-01-20 20:08 ` [PATCH v2 bpf-next 04/25] libbpf: complete mips spec " Andrii Nakryiko
2023-01-20 20:08 ` [PATCH v2 bpf-next 05/25] libbpf: complete powerpc " Andrii Nakryiko
2023-01-20 20:08 ` [PATCH v2 bpf-next 06/25] libbpf: complete sparc " Andrii Nakryiko
2023-01-20 20:08 ` [PATCH v2 bpf-next 07/25] libbpf: complete riscv arch " Andrii Nakryiko
2023-01-20 20:08 ` [PATCH v2 bpf-next 08/25] libbpf: fix and complete ARC " Andrii Nakryiko
2023-01-20 20:08 ` [PATCH v2 bpf-next 09/25] libbpf: complete LoongArch (loongarch) " Andrii Nakryiko
2023-01-20 20:08 ` [PATCH v2 bpf-next 10/25] libbpf: add BPF_UPROBE and BPF_URETPROBE macro aliases Andrii Nakryiko
2023-01-20 20:09 ` [PATCH v2 bpf-next 11/25] selftests/bpf: validate arch-specific argument registers limits Andrii Nakryiko
2023-01-20 20:09 ` [PATCH v2 bpf-next 12/25] libbpf: improve syscall tracing support in bpf_tracing.h Andrii Nakryiko
2023-01-20 20:09 ` [PATCH v2 bpf-next 13/25] libbpf: define x86-64 syscall regs spec " Andrii Nakryiko
2023-01-20 20:09 ` [PATCH v2 bpf-next 14/25] libbpf: define i386 " Andrii Nakryiko
2023-01-20 20:09 ` [PATCH v2 bpf-next 15/25] libbpf: define s390x " Andrii Nakryiko
2023-01-20 20:09 ` [PATCH v2 bpf-next 16/25] libbpf: define arm " Andrii Nakryiko
2023-01-20 20:09 ` [PATCH v2 bpf-next 17/25] libbpf: define arm64 " Andrii Nakryiko
2023-01-20 20:09 ` [PATCH v2 bpf-next 18/25] libbpf: define mips " Andrii Nakryiko
2023-01-20 20:09 ` [PATCH v2 bpf-next 19/25] libbpf: define powerpc " Andrii Nakryiko
2023-01-20 20:09 ` [PATCH v2 bpf-next 20/25] libbpf: define sparc " Andrii Nakryiko
2023-01-20 20:09 ` [PATCH v2 bpf-next 21/25] libbpf: define riscv " Andrii Nakryiko
2023-01-20 20:09 ` [PATCH v2 bpf-next 22/25] libbpf: define arc " Andrii Nakryiko
2023-01-20 20:09 ` [PATCH v2 bpf-next 23/25] libbpf: define loongarch " Andrii Nakryiko
2023-01-20 20:09 ` Andrii Nakryiko [this message]
2023-01-20 20:09 ` [PATCH v2 bpf-next 25/25] libbpf: clean up now not needed __PT_PARM{1-6}_SYSCALL_REG defaults Andrii Nakryiko
2023-01-23 20:10 ` [PATCH v2 bpf-next 00/25] libbpf: extend [ku]probe and syscall argument tracing support patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230120200914.3008030-25-andrii@kernel.org \
    --to=andrii@kernel.org \
    --cc=alan.maguire@oracle.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=iii@linux.ibm.com \
    --cc=kernel-team@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox