Skip to content

Commit 22b304b

Browse files
fomichevgregkh
authored andcommitted
selftests/bpf: retry tests that expect build-id
[ Upstream commit f67ad87 ] While running test_progs in a loop I found out that I'm sometimes hitting "Didn't find expected build ID from the map" error. Looking at stack_map_get_build_id_offset() it seems that it is racy (by design) and can sometimes return BPF_STACK_BUILD_ID_IP (i.e. can't trylock current->mm->mmap_sem). Let's retry this test a single time. Fixes: 13790d1 ("bpf: add selftest for stackmap with build_id in NMI context") Acked-by: Song Liu <songliubraving@fb.com> Signed-off-by: Stanislav Fomichev <sdf@google.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 5c6fdd8 commit 22b304b

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎tools/testing/selftests/bpf/test_progs.c‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,9 @@ static void test_stacktrace_build_id(void)
11361136
int i, j;
11371137
struct bpf_stack_build_id id_offs[PERF_MAX_STACK_DEPTH];
11381138
int build_id_matches = 0;
1139+
int retry = 1;
11391140

1141+
retry:
11401142
err = bpf_prog_load(file, BPF_PROG_TYPE_TRACEPOINT, &obj, &prog_fd);
11411143
if (CHECK(err, "prog_load", "err %d errno %d\n", err, errno))
11421144
goto out;
@@ -1249,6 +1251,19 @@ static void test_stacktrace_build_id(void)
12491251
previous_key = key;
12501252
} while (bpf_map_get_next_key(stackmap_fd, &previous_key, &key) == 0);
12511253

1254+
/* stack_map_get_build_id_offset() is racy and sometimes can return
1255+
* BPF_STACK_BUILD_ID_IP instead of BPF_STACK_BUILD_ID_VALID;
1256+
* try it one more time.
1257+
*/
1258+
if (build_id_matches < 1 && retry--) {
1259+
ioctl(pmu_fd, PERF_EVENT_IOC_DISABLE);
1260+
close(pmu_fd);
1261+
bpf_object__close(obj);
1262+
printf("%s:WARN:Didn't find expected build ID from the map, retrying\n",
1263+
__func__);
1264+
goto retry;
1265+
}
1266+
12521267
if (CHECK(build_id_matches < 1, "build id match",
12531268
"Didn't find expected build ID from the map\n"))
12541269
goto disable_pmu;
@@ -1289,7 +1304,9 @@ static void test_stacktrace_build_id_nmi(void)
12891304
int i, j;
12901305
struct bpf_stack_build_id id_offs[PERF_MAX_STACK_DEPTH];
12911306
int build_id_matches = 0;
1307+
int retry = 1;
12921308

1309+
retry:
12931310
err = bpf_prog_load(file, BPF_PROG_TYPE_PERF_EVENT, &obj, &prog_fd);
12941311
if (CHECK(err, "prog_load", "err %d errno %d\n", err, errno))
12951312
return;
@@ -1384,6 +1401,19 @@ static void test_stacktrace_build_id_nmi(void)
13841401
previous_key = key;
13851402
} while (bpf_map_get_next_key(stackmap_fd, &previous_key, &key) == 0);
13861403

1404+
/* stack_map_get_build_id_offset() is racy and sometimes can return
1405+
* BPF_STACK_BUILD_ID_IP instead of BPF_STACK_BUILD_ID_VALID;
1406+
* try it one more time.
1407+
*/
1408+
if (build_id_matches < 1 && retry--) {
1409+
ioctl(pmu_fd, PERF_EVENT_IOC_DISABLE);
1410+
close(pmu_fd);
1411+
bpf_object__close(obj);
1412+
printf("%s:WARN:Didn't find expected build ID from the map, retrying\n",
1413+
__func__);
1414+
goto retry;
1415+
}
1416+
13871417
if (CHECK(build_id_matches < 1, "build id match",
13881418
"Didn't find expected build ID from the map\n"))
13891419
goto disable_pmu;

0 commit comments

Comments
 (0)