Commit e31eec77 authored by Kumar Kartikeya Dwivedi's avatar Kumar Kartikeya Dwivedi Committed by Alexei Starovoitov

bpf: selftests: Fix fd cleanup in get_branch_snapshot

Cleanup code uses while (cpu++ < cpu_cnt) for closing fds, which means
it starts iterating from 1 for closing fds. If the first fd is -1, it
skips over it and closes garbage fds (typically zero) in the remaining
array. This leads to test failures for future tests when they end up
storing fd 0 (as the slot becomes free due to close(0)) in ldimm64's BTF
fd, ending up trying to match module BTF id with vmlinux.

This was observed as spurious CI failure for the ksym_module_libbpf and
module_attach tests. The test ends up closing fd 0 and breaking libbpf's
assumption that module BTF fd will always be > 0, which leads to the
kernel thinking that we are pointing to a BTF ID in vmlinux BTF.

Fixes: 025bd7c7 (selftests/bpf: Add test for bpf_get_branch_snapshot)
Signed-off-by: default avatarKumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Acked-by: default avatarSong Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20210927145941.1383001-12-memxor@gmail.com
parent 31038364
...@@ -38,10 +38,9 @@ static int create_perf_events(void) ...@@ -38,10 +38,9 @@ static int create_perf_events(void)
static void close_perf_events(void) static void close_perf_events(void)
{ {
int cpu = 0; int cpu, fd;
int fd;
while (cpu++ < cpu_cnt) { for (cpu = 0; cpu < cpu_cnt; cpu++) {
fd = pfd_array[cpu]; fd = pfd_array[cpu];
if (fd < 0) if (fd < 0)
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment