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

selftests/bpf: Fix bpf_cookie and find_vma in nested VM

bpf_cookie and find_vma are flaky in nested VMs, which is used by some CI
systems. It turns out these failures are caused by unreliable perf event
in nested VM. Fix these by:

1. Use PERF_COUNT_SW_CPU_CLOCK in find_vma;
2. Increase sample_freq in bpf_cookie.

Signed-off-by: Song Liu <song@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20240604070700.3032142-1-song@kernel.org

authored by

Song Liu and committed by
Andrii Nakryiko
61ce0ea7 49df0019

+3 -3
+1 -1
tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
··· 451 451 attr.type = PERF_TYPE_SOFTWARE; 452 452 attr.config = PERF_COUNT_SW_CPU_CLOCK; 453 453 attr.freq = 1; 454 - attr.sample_freq = 1000; 454 + attr.sample_freq = 10000; 455 455 pfd = syscall(__NR_perf_event_open, &attr, -1, 0, -1, PERF_FLAG_FD_CLOEXEC); 456 456 if (!ASSERT_GE(pfd, 0, "perf_fd")) 457 457 goto cleanup;
+2 -2
tools/testing/selftests/bpf/prog_tests/find_vma.c
··· 29 29 30 30 /* create perf event */ 31 31 attr.size = sizeof(attr); 32 - attr.type = PERF_TYPE_HARDWARE; 33 - attr.config = PERF_COUNT_HW_CPU_CYCLES; 32 + attr.type = PERF_TYPE_SOFTWARE; 33 + attr.config = PERF_COUNT_SW_CPU_CLOCK; 34 34 attr.freq = 1; 35 35 attr.sample_freq = 1000; 36 36 pfd = syscall(__NR_perf_event_open, &attr, 0, -1, -1, PERF_FLAG_FD_CLOEXEC);