From: sashiko-bot@kernel.org
To: "Vernon Yang" <vernon2gm@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v2 4/4] samples: bpf: add mthp_ext
Date: Fri, 08 May 2026 22:52:32 +0000 [thread overview]
Message-ID: <20260508225232.93952C2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260508150055.680136-5-vernon2gm@gmail.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Small memory processes bypass the 4KB fallback rule due to a faulty condition that excludes zero memory usage.
- [High] The cgroup memory check is indefinitely bypassed for cgroups that do not experience memory pressure because a stall value of `0` is treated as uninitialized.
- [Medium] The BPF program submits uninitialized memory to the ring buffer if reading the cgroup name fails, which can crash the userspace handler.
- [Medium] The global `exiting` flag is accessed locklessly without the `volatile sig_atomic_t` qualifier, potentially leading to an infinite loop.
--
commit d747c2eece6f13195b37f744a5f3e9fd6d9a2c95
Author: Vernon Yang <yanglincheng@kylinos.cn>
samples: bpf: add mthp_ext
Design mthp_ext case to address real workload issues by adjusting mTHP size
via a cgroup BPF program.
> diff --git a/samples/bpf/mthp_ext.bpf.c b/samples/bpf/mthp_ext.bpf.c
> new file mode 100644
> --- /dev/null
> +++ b/samples/bpf/mthp_ext.bpf.c
[ ... ]
> +SEC("iter.s/cgroup")
> +int cgroup_scan(struct bpf_iter__cgroup *ctx)
> +{
[ ... ]
> + bpf_cgroup_flush_stats(cgrp);
> + curr_stall = bpf_cgroup_stall(cgrp, PSI_MEM_FULL);
> + if (!info->stall) {
Does this logic unintentionally bypass the memory check for cgroups without
memory pressure?
bpf_cgroup_stall() can return exactly 0 for cgroups that have not experienced
any memory pressure. If curr_stall is 0, info->stall will be set to 0.
On subsequent scans, !info->stall will evaluate to true again, continuously
resetting the order to PMD_ORDER and skipping the memory size evaluation
below.
> + info->order = configs.init_order;
> + goto UPDATE;
> + }
> + delta = curr_stall - info->stall;
> + bpf_mem_cgroup_flush_stats(memcg);
> + curr_mem = bpf_mem_cgroup_page_state(memcg, NR_ANON_MAPPED) +
> + bpf_mem_cgroup_page_state(memcg, NR_SHMEM);
> + if ((curr_mem && curr_mem < FROM_MB(configs.min_mem)) ||
Could this condition allow new processes to bypass the 4KB fallback rule?
When a process starts and has not faulted in any anonymous or shmem memory,
its memory usage is 0. The curr_mem && check causes this to evaluate to false,
falling through to the else branch and assigning PMD_ORDER.
This seems to allow small or starting processes to allocate 2MB huge pages
for their first allocations instead of falling back to 4KB.
> + delta >= configs.threshold)
> + info->order = 0;
> + else
> + info->order = PMD_ORDER;
> +
> + if (configs.debug) {
> + e = bpf_ringbuf_reserve(&events, sizeof(*e), 0);
> + if (e) {
> + e->prev_stall = info->stall;
> + e->curr_stall = curr_stall;
> + e->delta = delta;
> + e->mem = curr_mem;
> + e->order = info->order;
> + bpf_probe_read_kernel_str(e->name, sizeof(e->name),
> + cgrp->kn->name);
Is it possible for e->name to contain uninitialized garbage if
bpf_probe_read_kernel_str() fails?
bpf_ringbuf_reserve() does not zero-initialize the memory. If the string
read fails, e->name might lack a null terminator. This could cause a
segmentation fault in the userspace daemon when it processes the event using
printf.
> + bpf_ringbuf_submit(e, 0);
> + }
> + }
[ ... ]
> diff --git a/samples/bpf/mthp_ext.c b/samples/bpf/mthp_ext.c
> new file mode 100644
> --- /dev/null
> +++ b/samples/bpf/mthp_ext.c
[ ... ]
> +static bool exiting;
Should this be declared as volatile sig_atomic_t?
Since exiting is modified asynchronously in the signal handler and read in the
while (!exiting) loops, an optimizing compiler might hoist the read out of
the loop. This could potentially cause the program to hang indefinitely
instead of exiting on a signal.
> +
> +static void usage(const char *name)
> +{
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260508150055.680136-1-vernon2gm@gmail.com?part=4
next prev parent reply other threads:[~2026-05-08 22:52 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 15:00 [PATCH v2 0/4] mm: introduce mthp_ext via cgroup-bpf to make mTHP more transparent Vernon Yang
2026-05-08 15:00 ` [PATCH v2 1/4] psi: add psi_group_flush_stats() function Vernon Yang
2026-05-08 15:19 ` Lorenzo Stoakes
2026-05-08 21:36 ` sashiko-bot
2026-05-08 15:00 ` [PATCH v2 2/4] bpf: add bpf_cgroup_{flush_stats,stall} function Vernon Yang
2026-05-08 15:40 ` bot+bpf-ci
2026-05-08 22:01 ` sashiko-bot
2026-05-08 15:00 ` [PATCH v2 3/4] mm: introduce bpf_mthp_ops struct ops Vernon Yang
2026-05-08 15:40 ` bot+bpf-ci
2026-05-08 15:57 ` Lorenzo Stoakes
2026-05-08 20:54 ` David Hildenbrand (Arm)
2026-05-11 11:25 ` Lorenzo Stoakes
2026-05-08 22:29 ` sashiko-bot
2026-05-08 15:00 ` [PATCH v2 4/4] samples: bpf: add mthp_ext Vernon Yang
2026-05-08 15:40 ` bot+bpf-ci
2026-05-08 22:52 ` sashiko-bot [this message]
2026-05-08 15:14 ` [PATCH v2 0/4] mm: introduce mthp_ext via cgroup-bpf to make mTHP more transparent Lorenzo Stoakes
2026-05-08 16:05 ` Lorenzo Stoakes
2026-05-08 16:53 ` Vernon Yang
2026-05-11 11:20 ` Lorenzo Stoakes
2026-05-08 16:00 ` Pedro Falcato
2026-05-08 16:15 ` Lorenzo Stoakes
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=20260508225232.93952C2BCB0@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=sashiko@lists.linux.dev \
--cc=vernon2gm@gmail.com \
/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