Skip to content

Commit 1739785

Browse files
laoarKernel Patches Daemon
authored andcommitted
selftests/bpf: add test case for BPF-THP inheritance across fork
Verify that child processes correctly inherit BPF-THP policy from their parent during fork() operations. Signed-off-by: Yafang Shao <[email protected]>
1 parent 0c557e2 commit 1739785

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tools/testing/selftests/bpf/prog_tests/thp_adjust.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,37 @@ static void subtest_thp_global_policy(void)
267267
bpf_link__destroy(global_link);
268268
}
269269

270+
static void subtest_thp_fork(void)
271+
{
272+
int elighble, child, pid, status;
273+
struct bpf_link *ops_link;
274+
char *ptr;
275+
276+
ops_link = bpf_map__attach_struct_ops(skel->maps.thp_eligible_ops);
277+
if (!ASSERT_OK_PTR(ops_link, "attach struct_ops"))
278+
return;
279+
280+
child = fork();
281+
if (!ASSERT_GE(child, 0, "fork"))
282+
goto destroy;
283+
284+
if (child == 0) {
285+
ptr = thp_alloc();
286+
elighble = get_thp_eligible(getpid(), (unsigned long)ptr);
287+
ASSERT_EQ(elighble, 0, "THPeligible");
288+
thp_free(ptr);
289+
290+
exit(EXIT_SUCCESS);
291+
}
292+
293+
pid = waitpid(child, &status, 0);
294+
ASSERT_EQ(pid, child, "waitpid");
295+
296+
destroy:
297+
bpf_link__destroy(ops_link);
298+
299+
}
300+
270301
static int thp_adjust_setup(void)
271302
{
272303
int err = -1, pmd_order;
@@ -319,6 +350,8 @@ void test_thp_adjust(void)
319350
subtest_thp_policy_update();
320351
if (test__start_subtest("global_policy"))
321352
subtest_thp_global_policy();
353+
if (test__start_subtest("thp_fork"))
354+
subtest_thp_fork();
322355

323356
thp_adjust_destroy();
324357
}

0 commit comments

Comments
 (0)