From: Jeongjun Park Date: Thu, 3 Jul 2025 06:56:00 +0000 (+0900) Subject: mm/percpu: prevent concurrency problem for pcpu_nr_populated read with spin lock X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b112a4e0a1af5745f987a1692553bf02c890babc;p=thirdparty%2Fkernel%2Flinux.git 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 --- diff --git a/mm/percpu.c b/mm/percpu.c index b35494c8ede28..d9cbaee92b605 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; } /*