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

Configure Feed

Select the types of activity you want to include in your feed.

selftests/bpf: Fix flaky bpf_cookie selftest

bpf_cookie can fail on perf_event_open(), when it runs after the task_work
selftest. The task_work test causes perf to lower
sysctl_perf_event_sample_rate, and bpf_cookie uses sample_freq,
which is validated against that sysctl. As a result,
perf_event_open() rejects the attr if the (now tighter) limit is
exceeded.

>From perf_event_open():
if (attr.freq) {
if (attr.sample_freq > sysctl_perf_event_sample_rate)
return -EINVAL;
} else {
if (attr.sample_period & (1ULL << 63))
return -EINVAL;
}

Switch bpf_cookie to use sample_period, which is not checked against
sysctl_perf_event_sample_rate.

Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250925215230.265501-1-mykyta.yatsenko5@gmail.com

authored by

Mykyta Yatsenko and committed by
Andrii Nakryiko
105eb5dc 1193c46c

+1 -2
+1 -2
tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
··· 450 450 attr.size = sizeof(attr); 451 451 attr.type = PERF_TYPE_SOFTWARE; 452 452 attr.config = PERF_COUNT_SW_CPU_CLOCK; 453 - attr.freq = 1; 454 - attr.sample_freq = 10000; 453 + attr.sample_period = 100000; 455 454 pfd = syscall(__NR_perf_event_open, &attr, -1, 0, -1, PERF_FLAG_FD_CLOEXEC); 456 455 if (!ASSERT_GE(pfd, 0, "perf_fd")) 457 456 goto cleanup;