riscv, bpf: Prepare for upcoming daily CI
Subsystems (5)
cover riscv, bpf: Prepare for upcoming daily CI
From: Pu Lehui <[email protected]>
For some time, bpf selftests on riscv64 have suffered from several silent breakages and test failures. These mainly stemmed from changes such as riscv ftrace atomic patching [0], qemu pmu behavior changes, and environment mismatches. While some issues have already been addressed in previous patches [1-3], the remaining ones are handled in this series.
To catch regressions promptly and close this long-standing riscv bpf CI gap, the riscv-bpf-daily project [4] is introduced here. With the assistance of LLMs, putting together this automated workflow was fairly straightforward. The pipeline pulls the latest bpf-next branch daily, executes both test_progs and test_verifier, and automatically creates github issues with brief failure descriptions and sends notifications when failures occur. It has been running smoothly for over a week and has already proven its value by catching some real jit bugs.
To pave the way for riscv-bpf-daily, this patchset addresses the remaining fixes, test adaptations, and environment dependencies.
[0] https://lore.kernel.org/all/[email protected]/
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=2820d227ad4e
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f2aaa6215910
[3] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c7e617552938
[4] https://github.com/pulehui/riscv-bpf-daily
Kumar Kartikeya Dwivedi (1):
bpf, riscv: Fix stack-passed arguments for indirect trampolines
Pu Lehui (4):
selftests/bpf: Set CONFIG_HZ_100 for riscv64 selftests/bpf: Use /tmp for temporary file in d_path selftests/bpf: Update qemu config for riscv64 in vmtest.sh selftests/bpf: Update DENYLIST.riscv64
arch/riscv/net/bpf_jit_comp64.c | 14 ++++++++++---- tools/testing/selftests/bpf/DENYLIST.riscv64 | 2 ++ tools/testing/selftests/bpf/config.riscv64 | 1 + tools/testing/selftests/bpf/prog_tests/d_path.c | 2 +- tools/testing/selftests/bpf/vmtest.sh | 4 ++-- 5 files changed, 16 insertions(+), 7 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/5 bpf, riscv: Fix stack-passed arguments for indirect trampolines
From: Kumar Kartikeya Dwivedi <[email protected]>
store_args() reads stack-passed arguments relative to FP assuming the trampoline was entered through the fentry call from a traced function. In that path, the trampoline pushes the parent frame before establishing its final FP, so the incoming stack arguments start at FP + 16.
An indirect trampoline for a struct_ops callback is called through a function pointer. Its prologue allocates only the trampoline frame and sets FP to the incoming SP. The RISC-V ABI places the first stack argument at that incoming SP, so the arguments start at FP, not FP + 16. Every stack-passed argument of a callback with more than eight argument slots is therefore read two slots late.
Pass the prologue-dependent offset to store_args(), using zero for a direct struct_ops trampoline and 16 for the fentry path.
--- arch/riscv/net/bpf_jit_comp64.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
arch/riscv/net/bpf_jit_comp64.c +10 -4
@@ -895,7 +895,8 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,return ret; } -static void store_args (int nr_arg_slots,int args_off,struct rv_jit_context *ctx) +static void store_args (int nr_arg_slots,int args_off,int stack_args_off, +struct rv_jit_context *ctx) {int i;
@@ -903,8 +904,8 @@ static void store_args(int nr_arg_slots, int args_off, struct rv_jit_context *ctif (i <RV_MAX_REG_ARGS ) {emit_sd (RV_REG_FP , -args_off,RV_REG_A0 + i, ctx); }else { -/* skip slots for T0 and FP of traced function */ -emit_ld (RV_REG_T1 ,16 + (i -RV_MAX_REG_ARGS ) *8 ,RV_REG_FP , ctx); +emit_ld (RV_REG_T1 , stack_args_off + + (i -RV_MAX_REG_ARGS ) *8 ,RV_REG_FP , ctx);emit_sd (RV_REG_FP , -args_off,RV_REG_T1 , ctx); } args_off -=8 ;
@@ -1190,7 +1191,12 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, func_meta = nr_arg_slots;emit_store_stack_imm64 (RV_REG_T1 , -func_meta_off, func_meta, ctx); -store_args (nr_arg_slots, args_off, ctx); +/* +* A direct struct_ops call has its first stack argument at the incoming +* SP, which the trampoline keeps as FP. The fentry path pushes the +* parent frame first, so its incoming stack arguments start at FP + 16. +*/ +store_args (nr_arg_slots, args_off, is_struct_ops ?0 :16 , ctx);if (bpf_fsession_cnt (tnodes)) {/* clear all session cookies' value */
Signature · 1 line
2.34.1
Re: [PATCH bpf-next 1/5] bpf, riscv: Fix stack-passed arguments for indirect trampolines
Quoted 2 lines · Pu Lehui
Signed-off-by Kumar Kartikeya Dwivedi <[email protected]>Reviewed-by Pu Lehui <[email protected]>
You're sending Kumar's patch, so it needs your SOB.
PATCH 2/5 selftests/bpf: Set CONFIG_HZ_100 for riscv64
In reply to Pu LehuiFrom: Pu Lehui <[email protected]>
The setget_sockopt selftest fails on riscv64, specifically in the TCP_BPF_DELACK_MAX and TCP_BPF_RTO_MIN sub-tests.
The test sets a socket option value in microseconds using bpf_setsockopt() and immediately reads it back via bpf_getsockopt() to verify that it matches. However, the kernel converts the value to jiffies internally for storage, and converts it back to microseconds upon retrieval. On riscv64, the default timer frequency is HZ=250 (4000 us per jiffy). When a value cannot be divided evenly (e.g. 30000 us), quantization error occurs during these conversions:
usecs_to_jiffies(30000) -> 8 jiffies
jiffies_to_usecs(8) -> 32000 us (!= 30000 us)
This mismatch triggers an assertion failure.
Let's set CONFIG_HZ_100=y in config.riscv64 to align with other archs and fix this issue.
--- tools/testing/selftests/bpf/config.riscv64 | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/bpf/config.riscv64 +1 -0
@@ -29,6 +29,7 @@ CONFIG_FRAME_POINTER=y CONFIG_HARDLOCKUP_DETECTOR=y CONFIG_HIGH_RES_TIMERS=y CONFIG_HUGETLBFS=y +CONFIG_HZ_100=y CONFIG_INET=y CONFIG_IP_ADVANCED_ROUTER=y CONFIG_IP_MULTICAST=y
Signature · 1 line
2.34.1
Re: [PATCH bpf-next 2/5] selftests/bpf: Set CONFIG_HZ_100 for riscv64
Quoted 2 lines · Pu Lehui
Let's set
CONFIG_HZ_100=yin config.riscv64 to align with other archs and fix this issue.
x86 has HZ_1000 and config.ppc64el doesn't set HZ at all. The test fails with HZ=250 on any arch.
Change 30000 to 40000 in progs/setget_sockopt.c instead ? It converts without loss with HZ=100, 250 and 1000.
PATCH 3/5 selftests/bpf: Use /tmp for temporary file in d_path
In reply to Pu LehuiFrom: Pu Lehui <[email protected]>
When running selftests via vmtest.sh on riscv64, the d_path test fails.
The failure occurs because the rootfs created by libbpf/ci [0] does not mount /dev/shm, causing temporary file creation under /dev/shm to fail.
Let's switch to using /tmp instead to fix this issue.
Note that older rootfs images did not mount tmpfs on /tmp, writing temporary files directly into the image. This has been fixed in [1] for newly built images.
--- tools/testing/selftests/bpf/prog_tests/d_path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/d_path.c +1 -1
@@ -220,7 +220,7 @@ static void test_d_path_check_types(void)static void test_d_path_mem_access (void ) {int localfd =-1 ; -char path_template[] ="/dev/shm/d_path_loadgen.XXXXXX" ; +char path_template[] ="/tmp/d_path_loadgen.XXXXXX" ;struct test_d_path__bss *bss;struct test_d_path *skel;
Signature · 1 line
2.34.1
Re: [PATCH bpf-next 3/5] selftests/bpf: Use /tmp for temporary file in d_path
Quoted 4 lines · Pu Lehui
The failure occurs because the rootfs created by libbpf/ci [0] does not mount
/dev/shm, causing temporary file creation under/dev/shmto fail.Let's switch to using /tmp instead to fix this issue.
This will break BPF CI.
The test was using /tmp up to v4 and was moved to /dev/shm in v5, since /tmp is on 9p in BPF CI and 9p doesn't support fallocate. See
https://lore.kernel.org/all/[email protected]/
vmtest's init mounts tmpfs at /dev/shm, /run and /mnt, but not at /tmp. So fallocate() will return EOPNOTSUPP and d_path/check_mem_access will fail on x86, arm64 and s390.
Mount tmpfs at /dev/shm in mkrootfs_tweak.sh like you did for /tmp in [1] and drop this patch.
pw-bot: cr
Re: [PATCH bpf-next 3/5] selftests/bpf: Use /tmp for temporary file in d_path
Quoted 14 lines · Alexei Starovoitov
Quoted 4 lines · Pu Lehui
The failure occurs because the rootfs created by libbpf/ci [0] does not mount
/dev/shm, causing temporary file creation under/dev/shmto fail.Let's switch to using /tmp instead to fix this issue.
This will break BPF CI.
The test was using /tmp up to v4 and was moved to/dev/shmin v5, since /tmp is on 9p in BPF CI and 9p doesn't support fallocate. See
https://lore.kernel.org/all/[email protected]/
vmtest's init mounts tmpfs at/dev/shm, /run and /mnt, but not at /tmp. Sofallocate()will return EOPNOTSUPP and d_path/check_mem_access will fail on x86, arm64 and s390.
Quoted 4 lines
Mount tmpfs at
/dev/shminmkrootfs_tweak.shlike you did for /tmp in [1] and drop this patch.pw-bot: cr
Hi Alexei and Ihor,
I have been make a pr for mount tmpfs at /dev/shm, pls take a look.
Re: [PATCH bpf-next 3/5] selftests/bpf: Use /tmp for temporary file in d_path
Quoted 19 lines · Pu Lehui
Quoted 17 lines · Alexei Starovoitov
Quoted 4 lines · Pu Lehui
The failure occurs because the rootfs created by libbpf/ci [0] does not mount
/dev/shm, causing temporary file creation under/dev/shmto fail.Let's switch to using /tmp instead to fix this issue.
This will break BPF CI.
The test was using /tmp up to v4 and was moved to/dev/shmin v5, since /tmp is on 9p in BPF CI and 9p doesn't support fallocate. See
https://lore.kernel.org/all/[email protected]/
vmtest's init mounts tmpfs at/dev/shm, /run and /mnt, but not at /tmp. Sofallocate()will return EOPNOTSUPP and d_path/check_mem_access will fail on x86, arm64 and s390.Mount tmpfs at
/dev/shminmkrootfs_tweak.shlike you did for /tmp in [1] and drop this patch.
Quoted 7 lines
Quoted 1 line
pw-bot: cr
Hi Alexei and Ihor,
I have been make a pr for mount tmpfs at
/dev/shm, pls take a look.
Merged, thanks.
Ihor Solodrai
reviewerRe: [PATCH bpf-next 3/5] selftests/bpf: Use /tmp for temporary file in d_path
Quoted 22 lines · Ihor Solodrai
Quoted 21 lines · Pu Lehui
Quoted 18 lines · Alexei Starovoitov
Quoted 4 lines · Pu Lehui
The failure occurs because the rootfs created by libbpf/ci [0] does not mount
/dev/shm, causing temporary file creation under/dev/shmto fail.Let's switch to using /tmp instead to fix this issue.
This will break BPF CI.
The test was using /tmp up to v4 and was moved to/dev/shmin v5, since /tmp is on 9p in BPF CI and 9p doesn't support fallocate. See
https://lore.kernel.org/all/[email protected]/
vmtest's init mounts tmpfs at/dev/shm, /run and /mnt, but not at /tmp. Sofallocate()will return EOPNOTSUPP and d_path/check_mem_access will fail on x86, arm64 and s390.Mount tmpfs at
/dev/shminmkrootfs_tweak.shlike you did for /tmp in [1] and drop this patch.pw-bot: cr
Quoted 8 lines
Quoted 5 lines
Hi Alexei and Ihor,
I have been make a pr for mount tmpfs at
/dev/shm, pls take a look.Merged, thanks.
Pu Lehui,
I just realized that this change may not be enough.
If you want to make sure the selftests will run properly in BPF CI, please try the vmtest tool (a qemu wrapper):
https://github.com/danobi/vmtest
You should be able to run riscv64 in emulation through it.
PATCH 4/5 selftests/bpf: Update qemu config for riscv64 in vmtest.sh
In reply to Pu LehuiFrom: Pu Lehui <[email protected]>
When running vmtest.sh on riscv64, the kernel panic at boot due to an illegal instruction. This is because '-cpu rv64' only enables a baseline set of riscv extensions, whereas the kernel or toolchain requires newer extensions. Switch to '-cpu max' so qemu enables all supported extensions.
Additionally, qemu's pmu emulation for riscv64 currently has issues, causing perf_event_open-related tests to fail. Temporarily disable the sscofpmf extension to bypass these failures for now, and will try to investigate and address it later.
While at it, update the libbpf/ci branch in INDEX_URL from 'master' to 'main'.
--- tools/testing/selftests/bpf/vmtest.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/vmtest.sh +2 -2
@@ -39,7 +39,7 @@ riscv64) QEMU_BINARY=qemu-system-riscv64 QEMU_CONSOLE="ttyS0,115200" HOST_FLAGS=(-M virt -cpu host -enable-kvm -smp 8) - CROSS_FLAGS=(-M virt -cpu rv64,sscofpmf=true -smp 8) + CROSS_FLAGS=(-M virt -cpu max,sscofpmf=false -smp 8) BZIMAGE="arch/riscv/boot/Image" ARCH="riscv" ;;
@@ -65,7 +65,7 @@ OUTPUT_DIR="$HOME/.bpf_selftests" KCONFIG_REL_PATHS=("tools/testing/selftests/bpf/config" "tools/testing/selftests/bpf/config.vm" "tools/testing/selftests/bpf/config.${PLATFORM}") -INDEX_URL="https://raw.githubusercontent.com/libbpf/ci/master/INDEX" +INDEX_URL="https://raw.githubusercontent.com/libbpf/ci/main/INDEX" NUM_COMPILE_JOBS="$(nproc)" LOG_FILE_BASE="$(date +"bpf_selftests.%Y-%m-%d_%H-%M-%S")" LOG_FILE="${LOG_FILE_BASE}.log"
Signature · 1 line
2.34.1
PATCH 5/5 selftests/bpf: Update DENYLIST.riscv64
In reply to Pu LehuiFrom: Pu Lehui <[email protected]>
Add probe_user and stacktrace_build_id testcases to DENYLIST.riscv64, as both tests currently fail due to riscv64's trap-based kprobe handling.
For probe_user, kprobes on riscv64 are handled via traps where the entry path invokes irqentry_nmi_enter(). Because bpf_probe_write_user() rejects execution in NMI context, the test fails. Upstream discussions regarding NMI semantics on riscv are ongoing [0] and will be tracked.
For stacktrace_build_id, under the kprobe trap context with interrupts disabled, bpf_get_stackid() obtains a valid build_id, but the queued irq_work is deferred. As a result, subsequent bpf_get_stack() fails to acquire mmap_read_trylock() and falls back to BPF_STACK_BUILD_ID_IP, causing an inconsistency between the two results.
--- tools/testing/selftests/bpf/DENYLIST.riscv64 | 2 ++ 1 file changed, 2 insertions(+)
tools/testing/selftests/bpf/DENYLIST.riscv64 +2 -0
@@ -1,2 +1,4 @@ # riscv64 deny list for BPF CI and local vmtest exceptions # JIT does not support exceptions +probe_user # kprobe hit in trap +stacktrace_build_id # kprobe hit in trap
Signature · 1 line
2.34.1
Re: [PATCH bpf-next 5/5] selftests/bpf: Update DENYLIST.riscv64
tools/testing/selftests/bpf/DENYLIST.riscv64 line 4
Quoted 6 lines · Pu Lehui
tools/testing/selftests/bpf/DENYLIST.riscv64 +2
-0@@ -1,2 +1,4 @@ # riscv64 deny list for BPF CI and local vmtest exceptions # JIT does not support exceptions +probe_user # kprobe hit in trap +stacktrace_build_id # kprobe hit in trap
stacktrace_build_id is already in the generic DENYLIST.