From: Jeongjun Park <aha310510@gmail.com>
To: dennis@kernel.org, tj@kernel.org, cl@gentwo.org
Cc: akpm@linux-foundation.org, vbabka@suse.cz, rientjes@google.com,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
syzbot+e5bd32b79413e86f389e@syzkaller.appspotmail.com,
Jeongjun Park <aha310510@gmail.com>
Subject: [PATCH] mm/percpu: prevent concurrency problem for pcpu_nr_populated read with spin lock
Date: Wed, 2 Jul 2025 17:27:49 +0900 [thread overview]
Message-ID: <20250702082749.141616-1-aha310510@gmail.com> (raw)
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;
}
/*
--
next reply other threads:[~2025-07-02 8:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-02 8:27 Jeongjun Park [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250702082749.141616-1-aha310510@gmail.com \
--to=aha310510@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cl@gentwo.org \
--cc=dennis@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rientjes@google.com \
--cc=syzbot+e5bd32b79413e86f389e@syzkaller.appspotmail.com \
--cc=tj@kernel.org \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox