From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Roman Gushchin <roman.gushchin@linux.dev>
Cc: bpf <bpf@vger.kernel.org>, linux-mm <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>,
JP Kobryn <inwardvessel@gmail.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Shakeel Butt <shakeel.butt@linux.dev>,
Michal Hocko <mhocko@kernel.org>,
Johannes Weiner <hannes@cmpxchg.org>
Subject: Re: [PATCH bpf-next v3 4/6] mm: introduce BPF kfuncs to access memcg statistics and events
Date: Mon, 22 Dec 2025 16:11:19 -1000 [thread overview]
Message-ID: <CAADnVQJ_WLMRXYV5p4Lk2+nxdC01iAaKQhYecMjx4rXdBeXjNw@mail.gmail.com> (raw)
In-Reply-To: <20251222221754.186191-5-roman.gushchin@linux.dev>
On Mon, Dec 22, 2025 at 12:18 PM Roman Gushchin
<roman.gushchin@linux.dev> wrote:
>
> + if (idx < 0 || idx >= MEMCG_NR_STAT || !memcg_stat_item_valid(idx))
> + return (unsigned long)-1;
memcg_stat_item_valid() and memcg_stat_item_valid()
helpers introduced specifically to be used in these kfuncs,
so I feel it's cleaner to do all idx checking within them
instead of splitting the checks like this.
Then it will be easier to see that
memcg_stat_item_valid(idx) access is in bounds when idx < MEMCG_NR_STAT
Also I'd do one check like (u32)idx >= MEMCG_NR_STAT
and drop idx < 0 part. Compiler is probably smart enough to
optimize this way itself, but I'd still do one check.
next prev parent reply other threads:[~2025-12-23 2:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-22 22:17 [PATCH bpf-next v3 0/6] mm: bpf kfuncs to access memcg data Roman Gushchin
2025-12-22 22:17 ` [PATCH bpf-next v3 1/6] mm: declare memcg_page_state_output() in memcontrol.h Roman Gushchin
2025-12-22 22:17 ` [PATCH bpf-next v3 2/6] mm: introduce BPF kfuncs to deal with memcg pointers Roman Gushchin
2025-12-22 22:17 ` [PATCH bpf-next v3 3/6] mm: introduce bpf_get_root_mem_cgroup() BPF kfunc Roman Gushchin
2025-12-22 22:17 ` [PATCH bpf-next v3 4/6] mm: introduce BPF kfuncs to access memcg statistics and events Roman Gushchin
2025-12-23 2:11 ` Alexei Starovoitov [this message]
2025-12-23 3:09 ` Roman Gushchin
2025-12-22 22:17 ` [PATCH bpf-next v3 5/6] bpf: selftests: selftests for memcg stat kfuncs Roman Gushchin
2025-12-22 22:17 ` [PATCH bpf-next v3 6/6] MAINTAINERS: add an entry for MM BPF extensions 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=CAADnVQJ_WLMRXYV5p4Lk2+nxdC01iAaKQhYecMjx4rXdBeXjNw@mail.gmail.com \
--to=alexei.starovoitov@gmail.com \
--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=roman.gushchin@linux.dev \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox