From: sashiko-bot@kernel.org
To: "Ziyang Men" <ziyang.meme@gmail.com>
Cc: sched-ext@lists.linux.dev, tj@kernel.org, hannes@cmpxchg.org,
bpf@vger.kernel.org, dmitry.torokhov@gmail.com, mkoutny@suse.com,
linux-input@vger.kernel.org
Subject: Re: [PATCH v2 2/4] selftests/cgroup: add memcg_stat_cross_cpu correctness test for flush
Date: Tue, 21 Jul 2026 18:01:12 +0000 [thread overview]
Message-ID: <20260721180114.34E371F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260721174833.1232771-3-ziyang.meme@gmail.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
New issues:
- [Medium] Cross-CPU charge scattering fails to trigger page faults on all K CPUs when resident_bytes / k < PAGE_SIZE.
- [Medium] Commit message contains inaccurate claims regarding the test framework and utility helpers.
- [Low] Multi-line comment does not follow the required BPF subsystem style.
Pre-existing issues:
- [High] Missing bounds checks for negative enum values in kfuncs bpf_mem_cgroup_vm_events and bpf_mem_cgroup_memory_events allow out-of-bounds array access.
--
--- Patch [2]: [PATCH v2 2/4] selftests/cgroup: add memcg_stat_cross_cpu correctness test for flush ---
commit c0bc72e5d098a9cdecf85dcaee9fd0bb8671e354
Author: Ziyang Men <ziyang.meme@gmail.com>
selftests/cgroup: add memcg_stat_cross_cpu correctness test for flush
This commit adds a memory-cgroup BPF selftest that verifies if the
memory-cgroup BPF kfuncs return values that match what userspace reads
from cgroupfs. It builds a cgroup tree, charges memory across multiple
CPUs, and compares the flushed kfunc stats to the traditional memory.stat
reads.
> Add a test_progs selftest that verifies the memory-cgroup BPF kfuncs
[ ... ]
> The traditional path reads memory.stat / memory.current through a new
> read_cgroup_file() helper added to cgroup_helpers (the read counterpart
> of write_cgroup_file).
[Severity: Medium]
The commit message states that a test_progs selftest was added and a new
read_cgroup_file() helper was introduced. However, the patch implements a
standalone kselftest via TEST_GEN_PROGS and relies on the pre-existing
cg_read() helper instead. Could the commit message be updated to accurately
reflect the implemented code?
[ ... ]
> diff --git a/tools/testing/selftests/cgroup/memcg_stat_cross_cpu.bpf.c b/tools/testing/selftests/cgroup/memcg_stat_cross_cpu.bpf.c
[ ... ]
> + snap.file = bpf_mem_cgroup_page_state(memcg, idx_file);
> + snap.shmem = bpf_mem_cgroup_page_state(memcg, idx_shmem);
> + snap.file_mapped = bpf_mem_cgroup_page_state(memcg, idx_fmapped);
> + snap.pgfault = bpf_mem_cgroup_vm_events(memcg, idx_pgfault);
[Severity: High]
This is a pre-existing issue, but the called kfuncs
bpf_mem_cgroup_vm_events() and bpf_mem_cgroup_memory_events() in
mm/bpf_memcontrol.c lack negative bounds checks for their enum arguments.
Since the BPF verifier does not enforce enum ranges, a BPF program could
pass a negative enum value which bypasses the upper-bound check (e.g.,
idx >= NR_VM_EVENT_ITEMS). This happens because the C code evaluates the
signed integer, leading to an out-of-bounds array access.
Can we add the required negative bounds checks to these kfuncs?
> +
> + /* page_counter fields need no kfunc; read them off the trusted ptr. */
[ ... ]
> diff --git a/tools/testing/selftests/cgroup/test_memcg_stat_cross_cpu.c b/tools/testing/selftests/cgroup/test_memcg_stat_cross_cpu.c
[ ... ]
> + /*
> + * Fault the region in K slices, each on a different CPU, so the charge
> + * for this leaf is scattered across K per-cpu rstat trees. A correct
> + * flush must gather all K slices.
> + */
> + per = resident_bytes / k;
> + for (j = 0; j < k; j++) {
> + off = (size_t)j * per;
> + if (pin_cpu(cpu_list[(base + j) % n_cpu]))
> + _exit(3);
> + memset(region + off, 1,
> + (j == k - 1) ? resident_bytes - off : per);
> + }
[Severity: Medium]
If the system has a large number of CPUs, can per (resident_bytes / k)
become smaller than the page size?
For example, in the cross_cpu_large_tree test case with 256KB
resident_bytes and >64 CPUs, multiple CPUs would be assigned offsets
within the same 4KB page. The first CPU writing to the page causes a page
fault, but subsequent CPUs writing to the same page will find it already
mapped and won't trigger faults, defeating the cross-CPU scattering
mechanism.
> +
> + /* Ready: the charge is in place and spread across K CPUs. */
> + if (write(charge_ready[1], "x", 1) != 1)
> + _exit(4);
> + close(charge_ready[1]);
> +
> + /* Hold the charge (region stays mapped) until the parent tells
> + * us to exit by closing the control pipe.
> + */
[Severity: Low]
Does this multi-line comment format match the BPF subsystem style? The BPF
subsystem requires multi-line comments to have the opening /* on its own
line, even in selftests.
> + while (read(charge_ctrl[0], &c, 1) > 0)
> + ;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260721174833.1232771-1-ziyang.meme@gmail.com?part=2
next prev parent reply other threads:[~2026-07-21 18:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 17:48 [PATCH v2 0/4] selftests: shared lib.bpf.mk for building BPF progs and skeletons Ziyang Men
2026-07-21 17:48 ` [PATCH v2 1/4] selftests: add shared lib.bpf.mk to build " Ziyang Men
2026-07-21 17:58 ` sashiko-bot
2026-07-22 6:50 ` Viktor Malik
2026-07-22 9:56 ` bot+bpf-ci
2026-07-21 17:48 ` [PATCH v2 2/4] selftests/cgroup: add memcg_stat_cross_cpu correctness test for flush Ziyang Men
2026-07-21 18:01 ` sashiko-bot [this message]
2026-07-22 9:43 ` Michal Koutný
2026-07-22 18:42 ` JP Kobryn
2026-07-21 17:48 ` [PATCH v2 3/4] selftests/hid: build the BPF program via the shared lib.bpf.mk Ziyang Men
2026-07-21 17:48 ` [PATCH v2 4/4] selftests/sched_ext: build BPF schedulers " Ziyang Men
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=20260721180114.34E371F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=hannes@cmpxchg.org \
--cc=linux-input@vger.kernel.org \
--cc=mkoutny@suse.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sched-ext@lists.linux.dev \
--cc=tj@kernel.org \
--cc=ziyang.meme@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 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.