From b112a4e0a1af5745f987a1692553bf02c890babc Mon Sep 17 00:00:00 2001 From: Jeongjun Park Date: Thu, 3 Jul 2025 15:56:00 +0900 Subject: [PATCH] mm/percpu: prevent concurrency problem for pcpu_nr_populated read with spin lock 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 Reported-by: syzbot+e5bd32b79413e86f389e@syzkaller.appspotmail.com Suggested-by: Shakeel Butt Cc: Christoph Lameter (Ampere) Cc: David Rientjes Cc: Dennis Zhou Cc: Roman Gushchin Cc: Tejun Heo Cc: Vlastimil Babka Signed-off-by: Andrew Morton --- mm/percpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/percpu.c b/mm/percpu.c index b35494c8ede2..d9cbaee92b60 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -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; } /* -- 2.25.1