[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250926093343.1000-11-laoar.shao@gmail.com>
Date: Fri, 26 Sep 2025 17:33:41 +0800
From: Yafang Shao <laoar.shao@...il.com>
To: akpm@...ux-foundation.org,
david@...hat.com,
ziy@...dia.com,
baolin.wang@...ux.alibaba.com,
lorenzo.stoakes@...cle.com,
Liam.Howlett@...cle.com,
npache@...hat.com,
ryan.roberts@....com,
dev.jain@....com,
hannes@...xchg.org,
usamaarif642@...il.com,
gutierrez.asier@...wei-partners.com,
willy@...radead.org,
ast@...nel.org,
daniel@...earbox.net,
andrii@...nel.org,
ameryhung@...il.com,
rientjes@...gle.com,
corbet@....net,
21cnbao@...il.com,
shakeel.butt@...ux.dev,
tj@...nel.org,
lance.yang@...ux.dev
Cc: bpf@...r.kernel.org,
linux-mm@...ck.org,
linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org,
Yafang Shao <laoar.shao@...il.com>
Subject: [PATCH v8 mm-new 10/12] selftests/bpf: add test case to update THP policy
This test case exercises the BPF THP update mechanism by modifying an
existing policy. The behavior confirms that:
- EBUSY error occurs when attempting to install a new BPF program while
another is active
- Updates to currently running programs are successfully processed
Signed-off-by: Yafang Shao <laoar.shao@...il.com>
---
.../selftests/bpf/prog_tests/thp_adjust.c | 23 +++++++++++++++++++
.../selftests/bpf/progs/test_thp_adjust.c | 14 +++++++++++
2 files changed, 37 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/thp_adjust.c b/tools/testing/selftests/bpf/prog_tests/thp_adjust.c
index b14f57040654..72b2ec31025a 100644
--- a/tools/testing/selftests/bpf/prog_tests/thp_adjust.c
+++ b/tools/testing/selftests/bpf/prog_tests/thp_adjust.c
@@ -208,6 +208,27 @@ static void subtest_thp_eligible(void)
bpf_link__destroy(ops_link);
}
+static void subtest_thp_policy_update(void)
+{
+ struct bpf_link *old_link, *new_link;
+ int err;
+
+ old_link = bpf_map__attach_struct_ops(skel->maps.swap_ops);
+ if (!ASSERT_OK_PTR(old_link, "attach_old_link"))
+ return;
+
+ new_link = bpf_map__attach_struct_ops(skel->maps.thp_eligible_ops);
+ if (!ASSERT_NULL(new_link, "attach_new_link"))
+ goto destory_old;
+ ASSERT_EQ(errno, EBUSY, "attach_new_link");
+
+ err = bpf_link__update_map(old_link, skel->maps.thp_eligible_ops);
+ ASSERT_EQ(err, 0, "update_old_link");
+
+destory_old:
+ bpf_link__destroy(old_link);
+}
+
static int thp_adjust_setup(void)
{
int err = -1, pmd_order;
@@ -253,6 +274,8 @@ void test_thp_adjust(void)
if (test__start_subtest("thp_eligible"))
subtest_thp_eligible();
+ if (test__start_subtest("policy_update"))
+ subtest_thp_policy_update();
thp_adjust_destroy();
}
diff --git a/tools/testing/selftests/bpf/progs/test_thp_adjust.c b/tools/testing/selftests/bpf/progs/test_thp_adjust.c
index ed8c510693a0..8f3bc4768edc 100644
--- a/tools/testing/selftests/bpf/progs/test_thp_adjust.c
+++ b/tools/testing/selftests/bpf/progs/test_thp_adjust.c
@@ -39,3 +39,17 @@ SEC(".struct_ops.link")
struct bpf_thp_ops thp_eligible_ops = {
.thp_get_order = (void *)thp_eligible,
};
+
+SEC("struct_ops/thp_get_order")
+int BPF_PROG(alloc_not_in_swap, struct vm_area_struct *vma, enum tva_type tva_type,
+ unsigned long orders)
+{
+ if (tva_type == TVA_SWAP_PAGEFAULT)
+ return 0;
+ return -1;
+}
+
+SEC(".struct_ops.link")
+struct bpf_thp_ops swap_ops = {
+ .thp_get_order = (void *)alloc_not_in_swap,
+};
--
2.47.3
Powered by blists - more mailing lists