* [PATCH bpf-next 0/3] Fix test_cgroup_iter_memcg issues found during back-porting
@ 2026-02-12 8:23 Hui Zhu
2026-02-12 8:23 ` [PATCH bpf-next 1/3] selftests/bpf: Check bpf_mem_cgroup_page_state return value Hui Zhu
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Hui Zhu @ 2026-02-12 8:23 UTC (permalink / raw)
To: Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt,
Muchun Song, Andrew Morton, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, Shuah Khan, Hui Zhu, JP Kobryn, cgroups,
linux-mm, linux-kernel, bpf, linux-kselftest
From: Hui Zhu <zhuhui@kylinos.cn>
While back-porting "mm: bpf kfuncs to access memcg data", I
encountered issues with test_cgroup_iter_memcg, specifically
in test_kmem.
The test_cgroup_iter_memcg test would falsely pass when
bpf_mem_cgroup_page_state() failed due to incompatible enum
values across kernel versions. Additionally, test_kmem would
fail on systems with cgroup.memory=nokmem enabled.
This series addresses these issues:
1. Add return value checks for bpf_mem_cgroup_page_state()
2. Return error when accessing kmem with nokmem enabled
3. Skip test_kmem when cgroup.memory=nokmem is set
Hui Zhu (3):
selftests/bpf: Check bpf_mem_cgroup_page_state return value
mm/memcontrol: Return error when accessing kmem with nokmem
selftests/bpf: Skip test_kmem when cgroup.memory=nokmem
mm/memcontrol.c | 3 +-
.../bpf/prog_tests/cgroup_iter_memcg.c | 40 +++++++++++++++++++
2 files changed, 42 insertions(+), 1 deletion(-)
--
2.43.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH bpf-next 1/3] selftests/bpf: Check bpf_mem_cgroup_page_state return value
2026-02-12 8:23 [PATCH bpf-next 0/3] Fix test_cgroup_iter_memcg issues found during back-porting Hui Zhu
@ 2026-02-12 8:23 ` Hui Zhu
2026-02-12 8:50 ` bot+bpf-ci
2026-02-13 0:14 ` JP Kobryn
2026-02-12 8:23 ` [PATCH bpf-next 2/3] mm/memcontrol: Return error when accessing kmem with nokmem Hui Zhu
2026-02-12 8:23 ` [PATCH bpf-next 3/3] selftests/bpf: Skip test_kmem when cgroup.memory=nokmem Hui Zhu
2 siblings, 2 replies; 10+ messages in thread
From: Hui Zhu @ 2026-02-12 8:23 UTC (permalink / raw)
To: Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt,
Muchun Song, Andrew Morton, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, Shuah Khan, Hui Zhu, JP Kobryn, cgroups,
linux-mm, linux-kernel, bpf, linux-kselftest
From: Hui Zhu <zhuhui@kylinos.cn>
When back-porting test_progs to different kernel versions, I encountered
an issue where the test_cgroup_iter_memcg test would falsely pass even
when bpf_mem_cgroup_page_state() failed.
The problem occurs when test_progs compiled on one kernel version is
executed on another kernel with different enum values for memory
statistics (e.g., NR_ANON_MAPPED, NR_FILE_PAGES). In such cases,
bpf_mem_cgroup_page_state() returns -1 to indicate failure, but the test
didn't check for this error condition and incorrectly reported success.
This patch adds explicit checks to ensure bpf_mem_cgroup_page_state()
doesn't return -1 before validating the actual statistics values. This
prevents false positives when running test_progs in cross-kernel
environments.
Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
---
.../selftests/bpf/prog_tests/cgroup_iter_memcg.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c b/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
index a5afd16705f0..13b299512429 100644
--- a/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
+++ b/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
@@ -53,6 +53,8 @@ static void test_anon(struct bpf_link *link, struct memcg_query *memcg_query)
if (!ASSERT_OK(read_stats(link), "read stats"))
goto cleanup;
+ ASSERT_NEQ(memcg_query->nr_anon_mapped, (unsigned long)-1,
+ "bpf_mem_cgroup_page_state NR_ANON_MAPPED");
ASSERT_GT(memcg_query->nr_anon_mapped, 0, "final anon mapped val");
cleanup:
@@ -88,6 +90,10 @@ static void test_file(struct bpf_link *link, struct memcg_query *memcg_query)
if (!ASSERT_OK(read_stats(link), "read stats"))
goto cleanup_map;
+ ASSERT_NEQ(memcg_query->nr_file_pages, (unsigned long)-1,
+ "bpf_mem_cgroup_page_state NR_FILE_PAGES");
+ ASSERT_NEQ(memcg_query->nr_file_mapped, (unsigned long)-1,
+ "bpf_mem_cgroup_page_state NR_FILE_MAPPED");
ASSERT_GT(memcg_query->nr_file_pages, 0, "final file value");
ASSERT_GT(memcg_query->nr_file_mapped, 0, "final file mapped value");
@@ -119,6 +125,8 @@ static void test_shmem(struct bpf_link *link, struct memcg_query *memcg_query)
if (!ASSERT_OK(read_stats(link), "read stats"))
goto cleanup;
+ ASSERT_NEQ(memcg_query->nr_shmem, (unsigned long)-1,
+ "bpf_mem_cgroup_page_state NR_SHMEM");
ASSERT_GT(memcg_query->nr_shmem, 0, "final shmem value");
cleanup:
@@ -143,6 +151,8 @@ static void test_kmem(struct bpf_link *link, struct memcg_query *memcg_query)
if (!ASSERT_OK(read_stats(link), "read stats"))
goto cleanup;
+ ASSERT_NEQ(memcg_query->memcg_kmem, (unsigned long)-1,
+ "bpf_mem_cgroup_page_state MEMCG_KMEM");
ASSERT_GT(memcg_query->memcg_kmem, 0, "kmem value");
cleanup:
@@ -170,6 +180,8 @@ static void test_pgfault(struct bpf_link *link, struct memcg_query *memcg_query)
if (!ASSERT_OK(read_stats(link), "read stats"))
goto cleanup;
+ ASSERT_NEQ(memcg_query->pgfault, (unsigned long)-1,
+ "bpf_mem_cgroup_page_state PGFAULT");
ASSERT_GT(memcg_query->pgfault, 0, "final pgfault val");
cleanup:
--
2.43.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH bpf-next 2/3] mm/memcontrol: Return error when accessing kmem with nokmem
2026-02-12 8:23 [PATCH bpf-next 0/3] Fix test_cgroup_iter_memcg issues found during back-porting Hui Zhu
2026-02-12 8:23 ` [PATCH bpf-next 1/3] selftests/bpf: Check bpf_mem_cgroup_page_state return value Hui Zhu
@ 2026-02-12 8:23 ` Hui Zhu
2026-02-13 0:38 ` JP Kobryn (Meta)
2026-02-12 8:23 ` [PATCH bpf-next 3/3] selftests/bpf: Skip test_kmem when cgroup.memory=nokmem Hui Zhu
2 siblings, 1 reply; 10+ messages in thread
From: Hui Zhu @ 2026-02-12 8:23 UTC (permalink / raw)
To: Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt,
Muchun Song, Andrew Morton, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, Shuah Khan, Hui Zhu, JP Kobryn, cgroups,
linux-mm, linux-kernel, bpf, linux-kselftest
From: Hui Zhu <zhuhui@kylinos.cn>
When running tests on hosts with cgroup.memory=nokmem enabled for
performance reasons, test_kmem always gets a value of 0 for kmem
statistics.
Since BPF programs cannot easily determine whether kmem is enabled,
add a check in memcg_stat_item_valid() to return an error when
attempting to access MEMCG_KMEM statistics while kmem accounting
is disabled via cgroup_memory_nokmem.
This prevents BPF programs from silently receiving zero values and
allows them to properly handle the case where kmem accounting is
unavailable.
Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
---
mm/memcontrol.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 129eed3ff5bb..4d8419623d1c 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -667,7 +667,8 @@ unsigned long memcg_page_state(struct mem_cgroup *memcg, int idx)
bool memcg_stat_item_valid(int idx)
{
- if ((u32)idx >= MEMCG_NR_STAT)
+ if ((u32)idx >= MEMCG_NR_STAT ||
+ (cgroup_memory_nokmem && (u32)idx == MEMCG_KMEM))
return false;
return !BAD_STAT_IDX(memcg_stats_index(idx));
--
2.43.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH bpf-next 3/3] selftests/bpf: Skip test_kmem when cgroup.memory=nokmem
2026-02-12 8:23 [PATCH bpf-next 0/3] Fix test_cgroup_iter_memcg issues found during back-porting Hui Zhu
2026-02-12 8:23 ` [PATCH bpf-next 1/3] selftests/bpf: Check bpf_mem_cgroup_page_state return value Hui Zhu
2026-02-12 8:23 ` [PATCH bpf-next 2/3] mm/memcontrol: Return error when accessing kmem with nokmem Hui Zhu
@ 2026-02-12 8:23 ` Hui Zhu
2026-02-13 0:41 ` JP Kobryn (Meta)
2 siblings, 1 reply; 10+ messages in thread
From: Hui Zhu @ 2026-02-12 8:23 UTC (permalink / raw)
To: Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt,
Muchun Song, Andrew Morton, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, Shuah Khan, Hui Zhu, JP Kobryn, cgroups,
linux-mm, linux-kernel, bpf, linux-kselftest
From: Hui Zhu <zhuhui@kylinos.cn>
When cgroup.memory=nokmem is set in kernel command line, kmem
accounting is disabled and the test_kmem subtest will fail.
Add a check to skip this test when the parameter is present.
Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
---
.../bpf/prog_tests/cgroup_iter_memcg.c | 28 +++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c b/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
index 13b299512429..203e6b091a21 100644
--- a/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
+++ b/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
@@ -134,11 +134,39 @@ static void test_shmem(struct bpf_link *link, struct memcg_query *memcg_query)
shm_unlink("/tmp_shmem");
}
+static bool cmdline_has(const char *arg)
+{
+ char cmdline[4096];
+ int fd;
+ ssize_t len;
+ bool ret = false;
+
+ fd = open("/proc/cmdline", O_RDONLY);
+ if (fd < 0)
+ return false;
+
+ len = read(fd, cmdline, sizeof(cmdline) - 1);
+ close(fd);
+ if (len < 0)
+ return false;
+
+ cmdline[len] = '\0';
+ if (strstr(cmdline, arg))
+ ret = true;
+
+ return ret;
+}
+
#define NR_PIPES 64
static void test_kmem(struct bpf_link *link, struct memcg_query *memcg_query)
{
int fds[NR_PIPES][2], i;
+ if (cmdline_has("cgroup.memory=nokmem")) {
+ test__skip();
+ return;
+ }
+
/*
* Increase kmem value by creating pipes which will allocate some
* kernel buffers.
--
2.43.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next 1/3] selftests/bpf: Check bpf_mem_cgroup_page_state return value
2026-02-12 8:23 ` [PATCH bpf-next 1/3] selftests/bpf: Check bpf_mem_cgroup_page_state return value Hui Zhu
@ 2026-02-12 8:50 ` bot+bpf-ci
2026-02-12 9:23 ` hui.zhu
2026-02-13 0:14 ` JP Kobryn
1 sibling, 1 reply; 10+ messages in thread
From: bot+bpf-ci @ 2026-02-12 8:50 UTC (permalink / raw)
To: hui.zhu, hannes, mhocko, roman.gushchin, shakeel.butt,
muchun.song, akpm, ast, daniel, andrii, martin.lau, eddyz87,
song, yonghong.song, john.fastabend, kpsingh, sdf, haoluo, jolsa,
shuah, zhuhui, inwardvessel, cgroups, linux-mm, linux-kernel,
bpf, linux-kselftest
Cc: ast, andrii, daniel, martin.lau, eddyz87, yonghong.song, clm,
ihor.solodrai
[-- Attachment #1: Type: text/plain, Size: 1644 bytes --]
> diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c b/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
> --- a/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
> +++ b/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
[ ... ]
> @@ -170,6 +180,8 @@ static void test_pgfault(struct bpf_link *link, struct memcg_query *memcg_query)
> if (!ASSERT_OK(read_stats(link), "read stats"))
> goto cleanup;
>
> + ASSERT_NEQ(memcg_query->pgfault, (unsigned long)-1,
> + "bpf_mem_cgroup_page_state PGFAULT");
^^^^^^^^^^^^^^^^^^^^^^^^^^^
The assertion message references bpf_mem_cgroup_page_state(), but the BPF
program actually uses bpf_mem_cgroup_vm_events() to retrieve the pgfault
value:
tools/testing/selftests/bpf/progs/cgroup_iter_memcg.c:
memcg_query.pgfault = bpf_mem_cgroup_vm_events(memcg, PGFAULT);
Should the message be "bpf_mem_cgroup_vm_events PGFAULT" instead?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/21939182103
AI-authorship-score: low
AI-authorship-explanation: The commit message uses first-person narrative describing a real back-porting scenario, and the code changes are simple repetitive assertions typical of human-written test improvements.
issues-found: 1
issue-severity-score: low
issue-severity-explanation: Minor documentation issue where an assertion message references the wrong BPF function name; does not affect test correctness or system behavior.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next 1/3] selftests/bpf: Check bpf_mem_cgroup_page_state return value
2026-02-12 8:50 ` bot+bpf-ci
@ 2026-02-12 9:23 ` hui.zhu
0 siblings, 0 replies; 10+ messages in thread
From: hui.zhu @ 2026-02-12 9:23 UTC (permalink / raw)
To: bot+bpf-ci, hannes, mhocko, roman.gushchin, shakeel.butt,
muchun.song, akpm, ast, daniel, andrii, martin.lau, eddyz87,
song, yonghong.song, john.fastabend, kpsingh, sdf, haoluo, jolsa,
shuah, zhuhui, inwardvessel, cgroups, linux-mm, linux-kernel,
bpf, linux-kselftest
Cc: ast, andrii, daniel, martin.lau, eddyz87, yonghong.song, clm,
ihor.solodrai
2026年2月12日 16:50, bot+bpf-ci@kernel.org mailto:bot+bpf-ci@kernel.org 写到:
>
> >
> > diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c b/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
> > --- a/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
> >
> [ ... ]
>
> >
> > @@ -170,6 +180,8 @@ static void test_pgfault(struct bpf_link *link, struct memcg_query *memcg_query)
> > if (!ASSERT_OK(read_stats(link), "read stats"))
> > goto cleanup;
> >
> > + ASSERT_NEQ(memcg_query->pgfault, (unsigned long)-1,
> > + "bpf_mem_cgroup_page_state PGFAULT");
> >
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> The assertion message references bpf_mem_cgroup_page_state(), but the BPF
> program actually uses bpf_mem_cgroup_vm_events() to retrieve the pgfault
> value:
>
> tools/testing/selftests/bpf/progs/cgroup_iter_memcg.c:
> memcg_query.pgfault = bpf_mem_cgroup_vm_events(memcg, PGFAULT);
>
> Should the message be "bpf_mem_cgroup_vm_events PGFAULT" instead?
Good catch! I will fix it in the next version.
Best,
Hui
>
> ---
> AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
> See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
>
> CI run summary: https://github.com/kernel-patches/bpf/actions/runs/21939182103
>
> AI-authorship-score: low
> AI-authorship-explanation: The commit message uses first-person narrative describing a real back-porting scenario, and the code changes are simple repetitive assertions typical of human-written test improvements.
> issues-found: 1
> issue-severity-score: low
> issue-severity-explanation: Minor documentation issue where an assertion message references the wrong BPF function name; does not affect test correctness or system behavior.
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next 1/3] selftests/bpf: Check bpf_mem_cgroup_page_state return value
2026-02-12 8:23 ` [PATCH bpf-next 1/3] selftests/bpf: Check bpf_mem_cgroup_page_state return value Hui Zhu
2026-02-12 8:50 ` bot+bpf-ci
@ 2026-02-13 0:14 ` JP Kobryn
2026-02-13 7:29 ` hui.zhu
1 sibling, 1 reply; 10+ messages in thread
From: JP Kobryn @ 2026-02-13 0:14 UTC (permalink / raw)
To: Hui Zhu, Johannes Weiner, Michal Hocko, Roman Gushchin,
Shakeel Butt, Muchun Song, Andrew Morton, Alexei Starovoitov,
Daniel Borkmann, Andrii Nakryiko, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, Shuah Khan,
Hui Zhu, cgroups, linux-mm, linux-kernel, bpf, linux-kselftest
On 2/12/26 12:23 AM, Hui Zhu wrote:
> From: Hui Zhu <zhuhui@kylinos.cn>
>
> When back-porting test_progs to different kernel versions, I encountered
> an issue where the test_cgroup_iter_memcg test would falsely pass even
> when bpf_mem_cgroup_page_state() failed.
>
> The problem occurs when test_progs compiled on one kernel version is
> executed on another kernel with different enum values for memory
> statistics (e.g., NR_ANON_MAPPED, NR_FILE_PAGES). [...]
This patch looks good but I think to fully solve this cross-kernel issue
we should use co-re in the bpf program. In your second revision, can you
add an additional patch to make use of bpf_core_enum_value()? This way
instead of relying on enum values in vmlinux.h at compile-time, we use
the btf info at load-time instead to get the proper value for the given
kernel.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next 2/3] mm/memcontrol: Return error when accessing kmem with nokmem
2026-02-12 8:23 ` [PATCH bpf-next 2/3] mm/memcontrol: Return error when accessing kmem with nokmem Hui Zhu
@ 2026-02-13 0:38 ` JP Kobryn (Meta)
0 siblings, 0 replies; 10+ messages in thread
From: JP Kobryn (Meta) @ 2026-02-13 0:38 UTC (permalink / raw)
To: Hui Zhu, Johannes Weiner, Michal Hocko, Roman Gushchin,
Shakeel Butt, Muchun Song, Andrew Morton, Alexei Starovoitov,
Daniel Borkmann, Andrii Nakryiko, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, Shuah Khan,
Hui Zhu, cgroups, linux-mm, linux-kernel, bpf, linux-kselftest
On 2/12/26 12:23 AM, Hui Zhu wrote:
> From: Hui Zhu <zhuhui@kylinos.cn>
>
> When running tests on hosts with cgroup.memory=nokmem enabled for
> performance reasons, test_kmem always gets a value of 0 for kmem
> statistics.
>
> Since BPF programs cannot easily determine whether kmem is enabled,
> add a check in memcg_stat_item_valid() to return an error when
> attempting to access MEMCG_KMEM statistics while kmem accounting
> is disabled via cgroup_memory_nokmem.
>
> This prevents BPF programs from silently receiving zero values and
> allows them to properly handle the case where kmem accounting is
> unavailable.
>
> Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
> ---
> mm/memcontrol.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 129eed3ff5bb..4d8419623d1c 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -667,7 +667,8 @@ unsigned long memcg_page_state(struct mem_cgroup *memcg, int idx)
>
> bool memcg_stat_item_valid(int idx)
> {
> - if ((u32)idx >= MEMCG_NR_STAT)
> + if ((u32)idx >= MEMCG_NR_STAT ||
> + (cgroup_memory_nokmem && (u32)idx == MEMCG_KMEM))
> return false;
It's still a valid stat though, right? When it's disabled the value will
just remain zero. I don't think this is necessary.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next 3/3] selftests/bpf: Skip test_kmem when cgroup.memory=nokmem
2026-02-12 8:23 ` [PATCH bpf-next 3/3] selftests/bpf: Skip test_kmem when cgroup.memory=nokmem Hui Zhu
@ 2026-02-13 0:41 ` JP Kobryn (Meta)
0 siblings, 0 replies; 10+ messages in thread
From: JP Kobryn (Meta) @ 2026-02-13 0:41 UTC (permalink / raw)
To: Hui Zhu, Johannes Weiner, Michal Hocko, Roman Gushchin,
Shakeel Butt, Muchun Song, Andrew Morton, Alexei Starovoitov,
Daniel Borkmann, Andrii Nakryiko, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, Shuah Khan,
Hui Zhu, cgroups, linux-mm, linux-kernel, bpf, linux-kselftest
On 2/12/26 12:23 AM, Hui Zhu wrote:
> From: Hui Zhu <zhuhui@kylinos.cn>
>
> When cgroup.memory=nokmem is set in kernel command line, kmem
> accounting is disabled and the test_kmem subtest will fail.
>
> Add a check to skip this test when the parameter is present.
>
> Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
> ---
> .../bpf/prog_tests/cgroup_iter_memcg.c | 28 +++++++++++++++++++
> 1 file changed, 28 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c b/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
> index 13b299512429..203e6b091a21 100644
> --- a/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
> +++ b/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
> @@ -134,11 +134,39 @@ static void test_shmem(struct bpf_link *link, struct memcg_query *memcg_query)
> shm_unlink("/tmp_shmem");
> }
>
> +static bool cmdline_has(const char *arg)
> +{
> + char cmdline[4096];
> + int fd;
> + ssize_t len;
> + bool ret = false;
> +
> + fd = open("/proc/cmdline", O_RDONLY);
> + if (fd < 0)
> + return false;
> +
> + len = read(fd, cmdline, sizeof(cmdline) - 1);
> + close(fd);
> + if (len < 0)
> + return false;
> +
> + cmdline[len] = '\0';
> + if (strstr(cmdline, arg))
> + ret = true;
> +
> + return ret;
> +}
> +
> #define NR_PIPES 64
> static void test_kmem(struct bpf_link *link, struct memcg_query *memcg_query)
> {
> int fds[NR_PIPES][2], i;
>
> + if (cmdline_has("cgroup.memory=nokmem")) {
> + test__skip();
> + return;
> + }
Instead of just skipping what if we proceed and then confirm we get a
zero value after the allocations?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next 1/3] selftests/bpf: Check bpf_mem_cgroup_page_state return value
2026-02-13 0:14 ` JP Kobryn
@ 2026-02-13 7:29 ` hui.zhu
0 siblings, 0 replies; 10+ messages in thread
From: hui.zhu @ 2026-02-13 7:29 UTC (permalink / raw)
To: JP Kobryn, Johannes Weiner, Michal Hocko, Roman Gushchin,
Shakeel Butt, Muchun Song, Andrew Morton, Alexei Starovoitov,
Daniel Borkmann, Andrii Nakryiko, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, Shuah Khan,
Hui Zhu, cgroups, linux-mm, linux-kernel, bpf, linux-kselftest
2026年2月13日 08:14, "JP Kobryn" <inwardvessel@gmail.com mailto:inwardvessel@gmail.com?to=%22JP%20Kobryn%22%20%3Cinwardvessel%40gmail.com%3E > 写到:
>
> On 2/12/26 12:23 AM, Hui Zhu wrote:
>
> >
> > From: Hui Zhu <zhuhui@kylinos.cn>
> > When back-porting test_progs to different kernel versions, I encountered
> > an issue where the test_cgroup_iter_memcg test would falsely pass even
> > when bpf_mem_cgroup_page_state() failed.
> > The problem occurs when test_progs compiled on one kernel version is
> > executed on another kernel with different enum values for memory
> > statistics (e.g., NR_ANON_MAPPED, NR_FILE_PAGES). [...]
> >
> This patch looks good but I think to fully solve this cross-kernel issue
> we should use co-re in the bpf program. In your second revision, can you
> add an additional patch to make use of bpf_core_enum_value()? This way
> instead of relying on enum values in vmlinux.h at compile-time, we use
> the btf info at load-time instead to get the proper value for the given
> kernel.
>
I post v2 according to your comments.
Thanks for your review.
Best,
Hui
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-02-13 7:29 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-12 8:23 [PATCH bpf-next 0/3] Fix test_cgroup_iter_memcg issues found during back-porting Hui Zhu
2026-02-12 8:23 ` [PATCH bpf-next 1/3] selftests/bpf: Check bpf_mem_cgroup_page_state return value Hui Zhu
2026-02-12 8:50 ` bot+bpf-ci
2026-02-12 9:23 ` hui.zhu
2026-02-13 0:14 ` JP Kobryn
2026-02-13 7:29 ` hui.zhu
2026-02-12 8:23 ` [PATCH bpf-next 2/3] mm/memcontrol: Return error when accessing kmem with nokmem Hui Zhu
2026-02-13 0:38 ` JP Kobryn (Meta)
2026-02-12 8:23 ` [PATCH bpf-next 3/3] selftests/bpf: Skip test_kmem when cgroup.memory=nokmem Hui Zhu
2026-02-13 0:41 ` JP Kobryn (Meta)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox