syzbot
KCSAN: data-race in lruvec_page_state_local / mem_cgroup_css_rstat_flush
Status:
moderation: reported on 2026/11/19 00:06
Subsystems:
cgroups
mm
Labels:
prio:low
race:benign
[Documentation on labels]
Reported-by: syzbot+e5fdbda4e31505285cef@syzkaller.appspotmail.com
First crash: 1d21h, last: 4h52m
✨ AI-generated root cause summary:
A KCSAN data race was reported between lruvec_page_state_local() and mem_cgroup_css_rstat_flush() in mm/memcontrol.c. The reader lruvec_page_state_local() accesses pn->lruvec_stats->state_local[i] locklessly using READ_ONCE(), while mem_cgroup_stat_aggregate() updates the same counter via an unmarked compound assignment (ac->local[i] += delta_cpu). Because the writer performs an unmarked read-modify-write without WRITE_ONCE() or data_race(), KCSAN flags the concurrent access as a data race even though it is an intended, benign lockless statistics read.
▶
▼
✨ Full AI root cause analysis
Technical Root Cause Analysis
1. Components and Files Involved
- Source file:
mm/memcontrol.c (called from kernel/cgroup/rstat.c and mm/workingset.c)
- Functions involved:
- Structs and fields involved:
struct lruvec_stats::state_local (long state_local[NR_MEMCG_NODE_STAT_ITEMS] in struct mem_cgroup_per_node).
struct aggregate_control::local pointing to lstats->state_local.
2. Mechanism of the Bug and Invariants
-
Reader Path:
During memory reclamation and slab shrinking (count_shadow_nodes()), the kernel queries local LRU and slab page counts for a memory cgroup's per-node LRU vector:
/* mm/memcontrol.c:582 */
pn = container_of_const(lruvec, struct mem_cgroup_per_node, lruvec);
x = READ_ONCE(pn->lruvec_stats->state_local[i]);
To avoid taking locks and introducing global contention in latency-sensitive paths, stat readers (lruvec_page_state_local, lruvec_page_state, memcg_page_state, etc.) are designed to read these counters locklessly using READ_ONCE(), clamping transient negative values to zero on SMP systems.
-
Writer Path:
Memory cgroup stats update per-CPU delta counters and flush them periodically or when updates exceed a threshold (__mem_cgroup_flush_stats() -> css_rstat_flush()). In kernel/cgroup/rstat.c:426-436, css_rstat_flush() acquires __css_rstat_lock(css, cpu) (ss_rstat_lock(css->ss)), serializing all flushers for the memory cgroup subsystem such that only one flusher runs at any time.
Within mem_cgroup_css_rstat_flush(), the aggregated per-node stats are updated by passing pointers to mem_cgroup_stat_aggregate():
/* mm/memcontrol.c:4603-4604 */
if (delta_cpu && ac->local)
ac->local[i] += delta_cpu;
where ac->local points to lstats->state_local.
-
Concurrency and KCSAN Violation:
While the reader uses marked access via READ_ONCE(), the writer performs an unmarked C read-modify-write (ac->local[i] += delta_cpu) without WRITE_ONCE() or data_race(). According to the Linux Kernel Memory Model (LKMM), any concurrent access between threads where at least one is a write constitutes a data race unless both accesses are marked or annotated.
Because task 3996 on CPU 1 reads pn->lruvec_stats->state_local[i] via READ_ONCE() concurrently with task 39 on CPU 0 modifying it via ac->local[i] += delta_cpu;, KCSAN detects the unmarked read-modify-write and triggers the data-race report.
Sample crash report:
* Struck through repros no longer work on HEAD.