* [PATCH v11 mm-new 10/10] selftests/bpf: add test case for BPF-THP inheritance across fork
@ 2025-10-20 3:20 Yafang Shao
0 siblings, 0 replies; only message in thread
From: Yafang Shao @ 2025-10-20 3:20 UTC (permalink / raw)
To: akpm, ast, daniel, andrii, martin.lau, eddyz87, song,
yonghong.song, john.fastabend, kpsingh, sdf, haoluo, jolsa,
david, ziy, lorenzo.stoakes, Liam.Howlett, npache, ryan.roberts,
dev.jain, hannes, usamaarif642, gutierrez.asier, willy,
ameryhung, rientjes, corbet, 21cnbao, shakeel.butt, tj,
lance.yang, rdunlap
Cc: bpf, linux-mm, linux-doc, linux-kernel, Yafang Shao
Verify that child processes correctly inherit BPF-THP policy from their
parent during fork() operations.
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
.../selftests/bpf/prog_tests/thp_adjust.c | 33 +++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/thp_adjust.c b/tools/testing/selftests/bpf/prog_tests/thp_adjust.c
index 0d570cee9006..f585e60882e8 100644
--- a/tools/testing/selftests/bpf/prog_tests/thp_adjust.c
+++ b/tools/testing/selftests/bpf/prog_tests/thp_adjust.c
@@ -267,6 +267,37 @@ static void subtest_thp_global_policy(void)
bpf_link__destroy(global_link);
}
+static void subtest_thp_fork(void)
+{
+ int elighble, child, pid, status;
+ struct bpf_link *ops_link;
+ char *ptr;
+
+ ops_link = bpf_map__attach_struct_ops(skel->maps.thp_eligible_ops);
+ if (!ASSERT_OK_PTR(ops_link, "attach struct_ops"))
+ return;
+
+ child = fork();
+ if (!ASSERT_GE(child, 0, "fork"))
+ goto destroy;
+
+ if (child == 0) {
+ ptr = thp_alloc();
+ elighble = get_thp_eligible(getpid(), (unsigned long)ptr);
+ ASSERT_EQ(elighble, 0, "THPeligible");
+ thp_free(ptr);
+
+ exit(EXIT_SUCCESS);
+ }
+
+ pid = waitpid(child, &status, 0);
+ ASSERT_EQ(pid, child, "waitpid");
+
+destroy:
+ bpf_link__destroy(ops_link);
+
+}
+
static int thp_adjust_setup(void)
{
int err = -1, pmd_order;
@@ -319,6 +350,8 @@ void test_thp_adjust(void)
subtest_thp_policy_update();
if (test__start_subtest("global_policy"))
subtest_thp_global_policy();
+ if (test__start_subtest("thp_fork"))
+ subtest_thp_fork();
thp_adjust_destroy();
}
--
2.47.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-10-20 3:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-20 3:20 [PATCH v11 mm-new 10/10] selftests/bpf: add test case for BPF-THP inheritance across fork Yafang Shao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox