linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/percpu: prevent concurrency problem for pcpu_nr_populated read with spin lock
@ 2025-07-02  8:27 Jeongjun Park
  2025-07-02 15:55 ` Christoph Lameter (Ampere)
  2025-07-02 17:03 ` Shakeel Butt
  0 siblings, 2 replies; 9+ messages in thread
From: Jeongjun Park @ 2025-07-02  8:27 UTC (permalink / raw)
  To: dennis, tj, cl
  Cc: akpm, vbabka, rientjes, linux-mm, linux-kernel,
	syzbot+e5bd32b79413e86f389e, Jeongjun Park

Read/Write to pcpu_nr_populated should be performed while protected
by pcpu_lock. However, pcpu_nr_pages() reads pcpu_nr_populated without any
protection, which causes a data race between read/write.

Therefore, when reading pcpu_nr_populated in pcpu_nr_pages(), it should be
modified to be protected by pcpu_lock.

Reported-by: syzbot+e5bd32b79413e86f389e@syzkaller.appspotmail.com
Fixes: 7e8a6304d541 ("/proc/meminfo: add percpu populated pages count")
Signed-off-by: Jeongjun Park <aha310510@gmail.com>
---
 mm/percpu.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/mm/percpu.c b/mm/percpu.c
index b35494c8ede2..0f98b857fb36 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -3355,7 +3355,13 @@ void __init setup_per_cpu_areas(void)
  */
 unsigned long pcpu_nr_pages(void)
 {
-	return pcpu_nr_populated * pcpu_nr_units;
+	unsigned long flags, ret;
+
+	spin_lock_irqsave(&pcpu_lock, flags);
+	ret = pcpu_nr_populated * pcpu_nr_units;
+	spin_unlock_irqrestore(&pcpu_lock, flags);
+
+	return ret;
 }
 
 /*
--


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-07-03 16:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-02  8:27 [PATCH] mm/percpu: prevent concurrency problem for pcpu_nr_populated read with spin lock Jeongjun Park
2025-07-02 15:55 ` Christoph Lameter (Ampere)
2025-07-03  4:45   ` Jeongjun Park
2025-07-03  5:51     ` Dennis Zhou
2025-07-03  6:09       ` Jeongjun Park
2025-07-03 16:39       ` Tejun Heo
2025-07-02 17:03 ` Shakeel Butt
2025-07-03  5:19   ` Jeongjun Park
2025-07-03  5:57     ` Dennis Zhou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).