Skip to content

Commit f67ad87

Browse files
fomichevborkmann
authored andcommitted
selftests/bpf: retry tests that expect build-id
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>
1 parent 4af396a commit f67ad87

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tools/testing/selftests/bpf/test_progs.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,9 @@ static void test_stacktrace_build_id(void)
11881188
int i, j;
11891189
struct bpf_stack_build_id id_offs[PERF_MAX_STACK_DEPTH];
11901190
int build_id_matches = 0;
1191+
int retry = 1;
11911192

1193+
retry:
11921194
err = bpf_prog_load(file, BPF_PROG_TYPE_TRACEPOINT, &obj, &prog_fd);
11931195
if (CHECK(err, "prog_load", "err %d errno %d\n", err, errno))
11941196
goto out;
@@ -1301,6 +1303,19 @@ static void test_stacktrace_build_id(void)
13011303
previous_key = key;
13021304
} while (bpf_map_get_next_key(stackmap_fd, &previous_key, &key) == 0);
13031305

1306+
/* stack_map_get_build_id_offset() is racy and sometimes can return
1307+
* BPF_STACK_BUILD_ID_IP instead of BPF_STACK_BUILD_ID_VALID;
1308+
* try it one more time.
1309+
*/
1310+
if (build_id_matches < 1 && retry--) {
1311+
ioctl(pmu_fd, PERF_EVENT_IOC_DISABLE);
1312+
close(pmu_fd);
1313+
bpf_object__close(obj);
1314+
printf("%s:WARN:Didn't find expected build ID from the map, retrying\n",
1315+
__func__);
1316+
goto retry;
1317+
}
1318+
13041319
if (CHECK(build_id_matches < 1, "build id match",
13051320
"Didn't find expected build ID from the map\n"))
13061321
goto disable_pmu;
@@ -1341,7 +1356,9 @@ static void test_stacktrace_build_id_nmi(void)
13411356
int i, j;
13421357
struct bpf_stack_build_id id_offs[PERF_MAX_STACK_DEPTH];
13431358
int build_id_matches = 0;
1359+
int retry = 1;
13441360

1361+
retry:
13451362
err = bpf_prog_load(file, BPF_PROG_TYPE_PERF_EVENT, &obj, &prog_fd);
13461363
if (CHECK(err, "prog_load", "err %d errno %d\n", err, errno))
13471364
return;
@@ -1436,6 +1453,19 @@ static void test_stacktrace_build_id_nmi(void)
14361453
previous_key = key;
14371454
} while (bpf_map_get_next_key(stackmap_fd, &previous_key, &key) == 0);
14381455

1456+
/* stack_map_get_build_id_offset() is racy and sometimes can return
1457+
* BPF_STACK_BUILD_ID_IP instead of BPF_STACK_BUILD_ID_VALID;
1458+
* try it one more time.
1459+
*/
1460+
if (build_id_matches < 1 && retry--) {
1461+
ioctl(pmu_fd, PERF_EVENT_IOC_DISABLE);
1462+
close(pmu_fd);
1463+
bpf_object__close(obj);
1464+
printf("%s:WARN:Didn't find expected build ID from the map, retrying\n",
1465+
__func__);
1466+
goto retry;
1467+
}
1468+
14391469
if (CHECK(build_id_matches < 1, "build id match",
14401470
"Didn't find expected build ID from the map\n"))
14411471
goto disable_pmu;

0 commit comments

Comments
 (0)