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

selftests/bpf: skip test_perf_branches_hw() on unsupported platforms

Gracefully skip the test_perf_branches_hw subtest on platforms that
do not support LBR or require specialized perf event attributes
to enable branch sampling.

For example, AMD's Milan (Zen 3) supports BRS rather than traditional
LBR. This requires specific configurations (attr.type = PERF_TYPE_RAW,
attr.config = RETIRED_TAKEN_BRANCH_INSTRUCTIONS) that differ from the
generic setup used within this test. Notably, it also probably doesn't
hold much value to special case perf event configurations for selected
micro architectures.

Fixes: 67306f84ca78c ("selftests/bpf: Add bpf_read_branch_records() selftest")
Signed-off-by: Matt Bobrowski <mattbobrowski@google.com>
Acked-by: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20251120142059.2836181-1-mattbobrowski@google.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Matt Bobrowski and committed by
Alexei Starovoitov
27746aaf 878ee3c3

+3 -3
+3 -3
tools/testing/selftests/bpf/prog_tests/perf_branches.c
··· 116 116 pfd = syscall(__NR_perf_event_open, &attr, -1, 0, -1, PERF_FLAG_FD_CLOEXEC); 117 117 118 118 /* 119 - * Some setups don't support branch records (virtual machines, !x86), 120 - * so skip test in this case. 119 + * Some setups don't support LBR (virtual machines, !x86, AMD Milan Zen 120 + * 3 which only supports BRS), so skip test in this case. 121 121 */ 122 122 if (pfd < 0) { 123 - if (errno == ENOENT || errno == EOPNOTSUPP) { 123 + if (errno == ENOENT || errno == EOPNOTSUPP || errno == EINVAL) { 124 124 printf("%s:SKIP:no PERF_SAMPLE_BRANCH_STACK\n", 125 125 __func__); 126 126 test__skip();