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

selftests/bpf: Use sys_pidfd_open() helper when possible

SYS_pidfd_open may be undefined for old glibc, so using sys_pidfd_open()
helper defined in task_local_storage_helpers.h instead to fix potential
build failure.

And according to commit 7615d9e1780e ("arch: wire-up pidfd_open()"), the
syscall number of pidfd_open is always 434 except for alpha architure,
so update the definition of __NR_pidfd_open accordingly.

Signed-off-by: Hou Tao <houtao1@huawei.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20221011071249.3471760-1-houtao@huaweicloud.com

authored by

Hou Tao and committed by
Andrii Nakryiko
62c69e89 e94e0a2d

+7 -7
+3 -7
tools/testing/selftests/bpf/prog_tests/bpf_iter.c
··· 3 3 #include <test_progs.h> 4 4 #include <unistd.h> 5 5 #include <sys/syscall.h> 6 + #include <task_local_storage_helpers.h> 6 7 #include "bpf_iter_ipv6_route.skel.h" 7 8 #include "bpf_iter_netlink.skel.h" 8 9 #include "bpf_iter_bpf_map.skel.h" ··· 176 175 bpf_iter_bpf_map__destroy(skel); 177 176 } 178 177 179 - static int pidfd_open(pid_t pid, unsigned int flags) 180 - { 181 - return syscall(SYS_pidfd_open, pid, flags); 182 - } 183 - 184 178 static void check_bpf_link_info(const struct bpf_program *prog) 185 179 { 186 180 LIBBPF_OPTS(bpf_iter_attach_opts, opts); ··· 291 295 union bpf_iter_link_info linfo; 292 296 int pidfd; 293 297 294 - pidfd = pidfd_open(getpid(), 0); 295 - if (!ASSERT_GT(pidfd, 0, "pidfd_open")) 298 + pidfd = sys_pidfd_open(getpid(), 0); 299 + if (!ASSERT_GT(pidfd, 0, "sys_pidfd_open")) 296 300 return; 297 301 298 302 memset(&linfo, 0, sizeof(linfo));
+4
tools/testing/selftests/bpf/task_local_storage_helpers.h
··· 7 7 #include <sys/types.h> 8 8 9 9 #ifndef __NR_pidfd_open 10 + #ifdef __alpha__ 11 + #define __NR_pidfd_open 544 12 + #else 10 13 #define __NR_pidfd_open 434 14 + #endif 11 15 #endif 12 16 13 17 static inline int sys_pidfd_open(pid_t pid, unsigned int flags)