From: Viktor Malik on gitlab.com Merge Request: https://gitlab.com/cki-project/kernel-ark/-/merge_requests/3958
Currently, BPF selftests do not build in ARK due to multiple reasons. This addresses all of them.
Signed-off-by: Viktor Malik vmalik@redhat.com
--- redhat/kernel.spec.template | 26 ++++++++++++++++-- tools/testing/selftests/bpf/prog_tests/ksyms_btf.c | 31 ---------------------- tools/testing/selftests/bpf/Makefile | 2 +- 3 files changed, 24 insertions(+), 35 deletions(-)
From: Artem Savkov asavkov@redhat.com
redhat/spec: Add EXTRA_CXXFLAGS to bpf samples and selftests make
JIRA: https://issues.redhat.com/browse/RHEL-48593
Upstream status: RHEL-only
This is needed for proper feature detection and linking with PIE llvm.
Signed-off-by: Artem Savkov asavkov@redhat.com Signed-off-by: Viktor Malik vmalik@redhat.com
diff --git a/redhat/kernel.spec.template b/redhat/kernel.spec.template index blahblah..blahblah 100644 --- a/redhat/kernel.spec.template +++ b/redhat/kernel.spec.template @@ -3242,7 +3242,7 @@ if [ ! -f tools/bpf/bpftool/bootstrap/bpftool ]; then fi
%{log_msg "build samples/bpf"} -%{make} %{?_smp_mflags} ARCH=$Arch BPFTOOL=$(pwd)/tools/bpf/bpftool/bootstrap/bpftool V=1 M=samples/bpf/ VMLINUX_H="${RPM_VMLINUX_H}" || true +%{make} %{?_smp_mflags} EXTRA_CXXFLAGS="${RPM_OPT_FLAGS}" ARCH=$Arch BPFTOOL=$(pwd)/tools/bpf/bpftool/bootstrap/bpftool V=1 M=samples/bpf/ VMLINUX_H="${RPM_VMLINUX_H}" || true
pushd tools/testing/selftests # We need to install here because we need to call make with ARCH set which @@ -3254,7 +3254,7 @@ pushd tools/testing/selftests %endif
%{log_msg "main selftests compile"} -%{make} %{?_smp_mflags} ARCH=$Arch V=1 TARGETS="bpf cgroup kmod mm net net/forwarding net/mptcp net/netfilter net/packetdrill tc-testing memfd drivers/net/bonding iommu cachestat pid_namespace rlimits timens pidfd" SKIP_TARGETS="" $force_targets INSTALL_PATH=%{buildroot}%{_libexecdir}/kselftests VMLINUX_H="${RPM_VMLINUX_H}" install +%{make} %{?_smp_mflags} EXTRA_CXXFLAGS="${RPM_OPT_FLAGS}" ARCH=$Arch V=1 TARGETS="bpf cgroup kmod mm net net/forwarding net/mptcp net/netfilter net/packetdrill tc-testing memfd drivers/net/bonding iommu cachestat pid_namespace rlimits timens pidfd" SKIP_TARGETS="" $force_targets INSTALL_PATH=%{buildroot}%{_libexecdir}/kselftests VMLINUX_H="${RPM_VMLINUX_H}" install
%ifarch %{klptestarches} # kernel livepatching selftest test_modules will build against
-- https://gitlab.com/cki-project/kernel-ark/-/merge_requests/3958
From: Viktor Malik vmalik@redhat.com
redhat/spec: Fix BPF selftests build with PIE
JIRA: https://issues.redhat.com/browse/RHEL-48593
Upstream status: RHEL-only
BPF selftests build fails b/c some compiler and linker options (namely -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 and -specs=/usr/lib/rpm/redhat/redhat-hardened-ld) are not passed to sub-makes for bpftool and libbpf. This, for instance, causes that libbpf.a is not build as PIE and other binaries cannot link against it.
Fix the problem by passing the default compiler/linker options via EXTRA_CFLAGS/EXTRA_LDFLAGS to the selftests build. They are then correctly propagated to sub-makes.
Signed-off-by: Viktor Malik vmalik@redhat.com
diff --git a/redhat/kernel.spec.template b/redhat/kernel.spec.template index blahblah..blahblah 100644 --- a/redhat/kernel.spec.template +++ b/redhat/kernel.spec.template @@ -3254,7 +3254,7 @@ pushd tools/testing/selftests %endif
%{log_msg "main selftests compile"} -%{make} %{?_smp_mflags} EXTRA_CXXFLAGS="${RPM_OPT_FLAGS}" ARCH=$Arch V=1 TARGETS="bpf cgroup kmod mm net net/forwarding net/mptcp net/netfilter net/packetdrill tc-testing memfd drivers/net/bonding iommu cachestat pid_namespace rlimits timens pidfd" SKIP_TARGETS="" $force_targets INSTALL_PATH=%{buildroot}%{_libexecdir}/kselftests VMLINUX_H="${RPM_VMLINUX_H}" install +%{make} %{?_smp_mflags} EXTRA_CFLAGS="${RPM_OPT_FLAGS}" EXTRA_CXXFLAGS="${RPM_OPT_FLAGS}" EXTRA_LDFLAGS="%{__global_ldflags}" ARCH=$Arch V=1 TARGETS="bpf cgroup kmod mm net net/forwarding net/mptcp net/netfilter net/packetdrill tc-testing memfd drivers/net/bonding iommu cachestat pid_namespace rlimits timens pidfd" SKIP_TARGETS="" $force_targets INSTALL_PATH=%{buildroot}%{_libexecdir}/kselftests VMLINUX_H="${RPM_VMLINUX_H}" install
%ifarch %{klptestarches} # kernel livepatching selftest test_modules will build against
-- https://gitlab.com/cki-project/kernel-ark/-/merge_requests/3958
From: Viktor Malik vmalik@redhat.com
redhat/spec: Do not use source fortification for selftests
JIRA: https://issues.redhat.com/browse/RHEL-48593
Upstream status: RHEL-only
Some selftests (e.g. BPF) fail to build with the _FORTIFY_SOURCE option defined. Since selftests are not shipped, disable source fortification for them. This is done by undefining the %{_fortify_level} RPM macro and resetting CFLAGS to %{build_flags}.
Similarly, we reset the source fortification after selftests are built.
Signed-off-by: Viktor Malik vmalik@redhat.com
diff --git a/redhat/kernel.spec.template b/redhat/kernel.spec.template index blahblah..blahblah 100644 --- a/redhat/kernel.spec.template +++ b/redhat/kernel.spec.template @@ -3254,8 +3254,19 @@ pushd tools/testing/selftests %endif
%{log_msg "main selftests compile"} + +# Some selftests (especially bpf) do not build with source fortification. +# Since selftests are not shipped, disable source fortification for them. +%global _fortify_level_bak %{_fortify_level} +%undefine _fortify_level +export CFLAGS="%{build_cflags}" + %{make} %{?_smp_mflags} EXTRA_CFLAGS="${RPM_OPT_FLAGS}" EXTRA_CXXFLAGS="${RPM_OPT_FLAGS}" EXTRA_LDFLAGS="%{__global_ldflags}" ARCH=$Arch V=1 TARGETS="bpf cgroup kmod mm net net/forwarding net/mptcp net/netfilter net/packetdrill tc-testing memfd drivers/net/bonding iommu cachestat pid_namespace rlimits timens pidfd" SKIP_TARGETS="" $force_targets INSTALL_PATH=%{buildroot}%{_libexecdir}/kselftests VMLINUX_H="${RPM_VMLINUX_H}" install
+# Restore the original level of source fortification +%define _fortify_level %{_fortify_level_bak} +export CFLAGS="%{build_cflags}" + %ifarch %{klptestarches} # kernel livepatching selftest test_modules will build against # /lib/modules/$(shell uname -r)/build tree unless KDIR is set
-- https://gitlab.com/cki-project/kernel-ark/-/merge_requests/3958
From: Viktor Malik vmalik@redhat.com
redhat/spec: Bypass check-rpaths for kselftests/bpf/urandom_read
JIRA: https://issues.redhat.com/browse/RHEL-48593
Upstream status: RHEL-only
The urandom_read binary doesn't pass the check-rpaths check and upstream refuses to fix it. So, we save it to buildroot_unstripped and delete it so it will be hidden from check-rpaths and will automatically get restored later.
Signed-off-by: Viktor Malik vmalik@redhat.com
diff --git a/redhat/kernel.spec.template b/redhat/kernel.spec.template index blahblah..blahblah 100644 --- a/redhat/kernel.spec.template +++ b/redhat/kernel.spec.template @@ -3291,6 +3291,15 @@ for dir in bpf bpf/no_alu32 bpf/progs; do done %buildroot_save_unstripped "usr/libexec/kselftests/bpf/test_progs" %buildroot_save_unstripped "usr/libexec/kselftests/bpf/test_progs-no_alu32" + +# The urandom_read binary doesn't pass the check-rpaths check and upstream +# refuses to fix it. So, we save it to buildroot_unstripped and delete it so it +# will be hidden from check-rpaths and will automatically get restored later. +%buildroot_save_unstripped "usr/libexec/kselftests/bpf/urandom_read" +%buildroot_save_unstripped "usr/libexec/kselftests/bpf/no_alu32/urandom_read" +rm -f %{buildroot}/usr/libexec/kselftests/bpf/urandom_read +rm -f %{buildroot}/usr/libexec/kselftests/bpf/no_alu32/urandom_read + popd %{log_msg "end build selftests"} %endif
-- https://gitlab.com/cki-project/kernel-ark/-/merge_requests/3958
From: Viktor Malik vmalik@redhat.com
redhat/spec: Add libxml2-devel dependency for selftests build
JIRA: https://issues.redhat.com/browse/RHEL-48593
Upstream status: RHEL-only
The BPF selftests build requires libxml2.
Signed-off-by: Viktor Malik vmalik@redhat.com
diff --git a/redhat/kernel.spec.template b/redhat/kernel.spec.template index blahblah..blahblah 100644 --- a/redhat/kernel.spec.template +++ b/redhat/kernel.spec.template @@ -802,7 +802,7 @@ BuildRequires: clang llvm-devel fuse-devel zlib-devel binutils-devel python3-doc %ifarch x86_64 riscv64 BuildRequires: lld %endif -BuildRequires: libcap-devel libcap-ng-devel rsync libmnl-devel +BuildRequires: libcap-devel libcap-ng-devel rsync libmnl-devel libxml2-devel BuildRequires: numactl-devel %endif BuildConflicts: rhbuildsys(DiskFree) < 500Mb
-- https://gitlab.com/cki-project/kernel-ark/-/merge_requests/3958
From: Artem Savkov asavkov@redhat.com
selftests/bpf: Remove ksyms_weak_lskel test
JIRA: https://issues.redhat.com/browse/RHEL-48593
Upstream status: RHEL-only
The test fails to build in Brew (as the build needs to read /proc/kallsysm which has permission 000 in Brew builders) so disable it until Brew builders are fixed.
Signed-off-by: Viktor Malik vmalik@redhat.com Signed-off-by: Artem Savkov asavkov@redhat.com
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index blahblah..blahblah 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -502,7 +502,7 @@ LSKELS := fentry_test.c fexit_test.c fexit_sleep.c atomics.c \ test_ringbuf_n.c test_ringbuf_map_key.c test_ringbuf_write.c
# Generate both light skeleton and libbpf skeleton for these -LSKELS_EXTRA := test_ksyms_module.c test_ksyms_weak.c kfunc_call_test.c \ +LSKELS_EXTRA := test_ksyms_module.c kfunc_call_test.c \ kfunc_call_test_subprog.c SKEL_BLACKLIST += $$(LSKELS)
diff --git a/tools/testing/selftests/bpf/prog_tests/ksyms_btf.c b/tools/testing/selftests/bpf/prog_tests/ksyms_btf.c index blahblah..blahblah 100644 --- a/tools/testing/selftests/bpf/prog_tests/ksyms_btf.c +++ b/tools/testing/selftests/bpf/prog_tests/ksyms_btf.c @@ -7,7 +7,6 @@ #include "test_ksyms_btf.skel.h" #include "test_ksyms_btf_null_check.skel.h" #include "test_ksyms_weak.skel.h" -#include "test_ksyms_weak.lskel.h" #include "test_ksyms_btf_write_check.skel.h"
static int duration; @@ -111,33 +110,6 @@ static void test_weak_syms(void) test_ksyms_weak__destroy(skel); }
-static void test_weak_syms_lskel(void) -{ - struct test_ksyms_weak_lskel *skel; - struct test_ksyms_weak_lskel__data *data; - int err; - - skel = test_ksyms_weak_lskel__open_and_load(); - if (!ASSERT_OK_PTR(skel, "test_ksyms_weak_lskel__open_and_load")) - return; - - err = test_ksyms_weak_lskel__attach(skel); - if (!ASSERT_OK(err, "test_ksyms_weak_lskel__attach")) - goto cleanup; - - /* trigger tracepoint */ - usleep(1); - - data = skel->data; - ASSERT_EQ(data->out__existing_typed, 0, "existing typed ksym"); - ASSERT_NEQ(data->out__existing_typeless, -1, "existing typeless ksym"); - ASSERT_EQ(data->out__non_existent_typeless, 0, "nonexistent typeless ksym"); - ASSERT_EQ(data->out__non_existent_typed, 0, "nonexistent typed ksym"); - -cleanup: - test_ksyms_weak_lskel__destroy(skel); -} - static void test_write_check(bool test_handler1) { struct test_ksyms_btf_write_check *skel; @@ -180,9 +152,6 @@ void test_ksyms_btf(void) if (test__start_subtest("weak_ksyms")) test_weak_syms();
- if (test__start_subtest("weak_ksyms_lskel")) - test_weak_syms_lskel(); - if (test__start_subtest("write_check1")) test_write_check(true);
-- https://gitlab.com/cki-project/kernel-ark/-/merge_requests/3958
kernel@lists.fedoraproject.org