]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm/percpu: prevent concurrency problem for pcpu_nr_populated read with spin lock
authorJeongjun Park <aha310510@gmail.com>
Thu, 3 Jul 2025 06:56:00 +0000 (15:56 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 13 Jul 2025 23:38:21 +0000 (16:38 -0700)
pcpu_nr_pages() reads pcpu_nr_populated without any protection, which
causes a data race between read/write.

However, since this is an intended race, we should add a data_race
annotation instead of add a spin lock.

[akpm@linux-foundation.org: move pcpu_nr_units multiplication outside data_race(), per Vlastimil]
Link: https://lkml.kernel.org/r/20250703065600.132221-1-aha310510@gmail.com
Fixes: 7e8a6304d541 ("/proc/meminfo: add percpu populated pages count")
Signed-off-by: Jeongjun Park <aha310510@gmail.com>
Reported-by: syzbot+e5bd32b79413e86f389e@syzkaller.appspotmail.com
Suggested-by: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Christoph Lameter (Ampere) <cl@gentwo.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Tejun Heo <tj@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/percpu.c

index b35494c8ede2808a2610a32959110b65f69c3d59..d9cbaee92b6053047b778967100fb5a5ebd02405 100644 (file)
@@ -3355,7 +3355,7 @@ void __init setup_per_cpu_areas(void)
  */
 unsigned long pcpu_nr_pages(void)
 {
-       return pcpu_nr_populated * pcpu_nr_units;
+       return data_race(READ_ONCE(pcpu_nr_populated)) * pcpu_nr_units;
 }
 
 /*