Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: "JP Kobryn (Meta)" <jp.kobryn@linux.dev>
To: Hui Zhu <hui.zhu@linux.dev>, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Hui Zhu <zhuhui@kylinos.cn>
Subject: Re: [PATCH bpf-next v4 3/3] selftests/bpf: Check bpf_mem_cgroup_page_state return value
Date: Mon, 2 Mar 2026 10:27:09 -0800	[thread overview]
Message-ID: <ea103a43-7192-4c00-b837-c85ebba6f9b1@linux.dev> (raw)
In-Reply-To: <c6b0c44062f614ddeaae26b17e3a4f1876a9f9ed.1772270591.git.zhuhui@kylinos.cn>

On 2/28/26 1:25 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.
> 
> This patch adds explicit checks to ensure bpf_mem_cgroup_page_state()
> doesn't return -1 before validating the actual statistics values.
> 
> Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
> ---
>   .../selftests/bpf/prog_tests/cgroup_iter_memcg.c       | 10 ++++++++++
>   1 file changed, 10 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 88fc3e83d2b7..9eadfbd3fdb9 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:
> @@ -144,6 +152,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_vm_events PGFAULT");
>   	ASSERT_GT(memcg_query->pgfault, 0, "final pgfault val");
>   
>   cleanup:

Emil mentioned in the v3 thread that we don't need these checks [0]. I
agree. Now that you're using the bpf co-re enum helpers, the stat
indexes won't become an issue in a cross-kernel secenario. This patch
can be dropped.

[0] 
https://lore.kernel.org/bpf/DGQXZVBSVEUP.35P5G9QOL9EAT@etsalapatis.com/T/#m7cb6edf90ed4daaeda38b746363317405f198f20

      reply	other threads:[~2026-03-02 18:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-28  9:25 [PATCH bpf-next v4 0/3] Fix test_cgroup_iter_memcg issues found during back-porting Hui Zhu
2026-02-28  9:25 ` [PATCH bpf-next v4 1/3] selftests/bpf: Remove kmem subtest from cgroup_iter_memcg Hui Zhu
2026-03-02 18:08   ` JP Kobryn (Meta)
2026-02-28  9:25 ` [PATCH bpf-next v4 2/3] bpf: Use bpf_core_enum_value for stats in cgroup_iter_memcg Hui Zhu
2026-03-02 18:10   ` JP Kobryn (Meta)
2026-02-28  9:25 ` [PATCH bpf-next v4 3/3] selftests/bpf: Check bpf_mem_cgroup_page_state return value Hui Zhu
2026-03-02 18:27   ` JP Kobryn (Meta) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ea103a43-7192-4c00-b837-c85ebba6f9b1@linux.dev \
    --to=jp.kobryn@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=hui.zhu@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    --cc=zhuhui@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox