All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roman Gushchin <roman.gushchin@linux.dev>
To: Shakeel Butt <shakeel.butt@linux.dev>
Cc: bpf@vger.kernel.org,  linux-mm@kvack.org,
	 linux-kernel@vger.kernel.org, JP Kobryn <inwardvessel@gmail.com>,
	 Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	 Michal Hocko <mhocko@kernel.org>,
	 Johannes Weiner <hannes@cmpxchg.org>
Subject: Re: [PATCH bpf-next v1 6/6] bpf: selftests: selftests for memcg stat kfuncs
Date: Fri, 19 Dec 2025 19:20:04 -0800	[thread overview]
Message-ID: <87cy49g7q3.fsf@linux.dev> (raw)
In-Reply-To: <2xhmcrporen72rskghn6hmg6obnojptuerwzqgu7mqzhnxaxs5@33dxlwa6rqlh> (Shakeel Butt's message of "Fri, 19 Dec 2025 15:07:11 -0800")

Shakeel Butt <shakeel.butt@linux.dev> writes:

> On Thu, Dec 18, 2025 at 05:57:50PM -0800, Roman Gushchin wrote:
>> From: JP Kobryn <inwardvessel@gmail.com>
>> 
>> Add test coverage for the kfuncs that fetch memcg stats. Using some common
>> stats, test scenarios ensuring that the given stat increases by some
>> arbitrary amount. The stats selected cover the three categories represented
>> by the enums: node_stat_item, memcg_stat_item, vm_event_item.
>> 
>> Since only a subset of all stats are queried, use a static struct made up
>> of fields for each stat. Write to the struct with the fetched values when
>> the bpf program is invoked and read the fields in the user mode program for
>> verification.
>> 
>> Signed-off-by: JP Kobryn <inwardvessel@gmail.com>
>
> Need your signoff

Sure, will add, thanks.

>
> [...]
>> +
>> +#define NR_PIPES 64
>> +static void test_kmem(struct bpf_link *link, struct memcg_query *memcg_query)
>> +{
>> +	int fds[NR_PIPES][2], i;
>> +
>> +	/*
>> +	 * Increase kmem value by creating pipes which will allocate some
>> +	 * kernel buffers.
>> +	 */
>> +	for (i = 0; i < NR_PIPES; i++) {
>> +		if (!ASSERT_OK(pipe(fds[i]), "pipe"))
>> +			goto cleanup;
>> +	}
>> +
>> +	if (!ASSERT_OK(read_stats(link), "read stats"))
>> +		goto cleanup;
>> +
>> +	ASSERT_GT(memcg_query->memcg_kmem, 0, "kmem value");
>> +
>> +cleanup:
>> +	for (i = 0; i < NR_PIPES; i++) {
>
> Instead of from 0 to NR_PIPES, we need to go from i-1 to (and equal to) 0
> otherwise we can potentially close() junk values.

Good catch, will fix.

>
>> +		close(fds[i][0]);
>> +		close(fds[i][1]);
>> +	}
>> +}
>> +
>
> [...]
>
>> +
>> +SEC("iter.s/cgroup")
>> +int cgroup_memcg_query(struct bpf_iter__cgroup *ctx)
>> +{
>> +	struct cgroup *cgrp = ctx->cgroup;
>> +	struct cgroup_subsys_state *css;
>> +	struct mem_cgroup *memcg;
>> +
>> +	if (!cgrp)
>> +		return 1;
>> +
>> +	css = &cgrp->self;
>> +	if (!css)
>
> Will css ever be NULL here?

Hm, I think previously the verifier wasn't smart enough to understand
that it's always a valid pointer, but I just tested it with linux-next
and it worked well. I'll drop the check.

Thanks!

  reply	other threads:[~2025-12-20  3:20 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-19  1:57 [PATCH bpf-next v1 0/6] mm: bpf kfuncs to access memcg data Roman Gushchin
2025-12-19  1:57 ` [PATCH bpf-next v1 1/6] mm: declare memcg_page_state_output() in memcontrol.h Roman Gushchin
2025-12-19 21:35   ` Shakeel Butt
2025-12-19  1:57 ` [PATCH bpf-next v1 2/6] mm: introduce BPF kfuncs to deal with memcg pointers Roman Gushchin
2025-12-19 21:51   ` Shakeel Butt
2025-12-19 22:42     ` Roman Gushchin
2025-12-19  1:57 ` [PATCH bpf-next v1 3/6] mm: introduce bpf_get_root_mem_cgroup() BPF kfunc Roman Gushchin
2025-12-19 22:10   ` Shakeel Butt
2025-12-19  1:57 ` [PATCH bpf-next v1 4/6] mm: introduce BPF kfuncs to access memcg statistics and events Roman Gushchin
2025-12-19  2:15   ` bot+bpf-ci
2025-12-19  2:49     ` Roman Gushchin
2025-12-19 22:45   ` Shakeel Butt
2025-12-19  1:57 ` [PATCH bpf-next v1 5/6] mm: introduce BPF kfunc to access memory events Roman Gushchin
2025-12-19  2:21   ` bot+bpf-ci
2025-12-19  2:51     ` Roman Gushchin
2025-12-19 22:46   ` Shakeel Butt
2025-12-19  1:57 ` [PATCH bpf-next v1 6/6] bpf: selftests: selftests for memcg stat kfuncs Roman Gushchin
2025-12-19 23:07   ` Shakeel Butt
2025-12-20  3:20     ` Roman Gushchin [this message]
2025-12-19 19:40 ` [PATCH bpf-next v1 0/6] mm: bpf kfuncs to access memcg data Roman Gushchin
2025-12-20  3:25   ` Alexei Starovoitov
2025-12-20  3:27     ` Alexei Starovoitov
2025-12-20  3:36     ` Roman Gushchin

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=87cy49g7q3.fsf@linux.dev \
    --to=roman.gushchin@linux.dev \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=hannes@cmpxchg.org \
    --cc=inwardvessel@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=shakeel.butt@linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.