From: Jeongjun Park <aha310510@gmail.com>
To: dennis@kernel.org, tj@kernel.org, cl@gentwo.org
Cc: akpm@linux-foundation.org, roman.gushchin@linux.dev,
rientjes@google.com, vbabka@suse.cz, shakeel.butt@linux.dev,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
syzbot+e5bd32b79413e86f389e@syzkaller.appspotmail.com,
Jeongjun Park <aha310510@gmail.com>
Subject: [PATCH v2] mm/percpu: prevent concurrency problem for pcpu_nr_populated read with spin lock
Date: Thu, 3 Jul 2025 15:56:00 +0900 [thread overview]
Message-ID: <20250703065600.132221-1-aha310510@gmail.com> (raw)
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.
Reported-by: syzbot+e5bd32b79413e86f389e@syzkaller.appspotmail.com
Fixes: 7e8a6304d541 ("/proc/meminfo: add percpu populated pages count")
Suggested-by: Shakeel Butt <shakeel.butt@linux.dev>
Signed-off-by: Jeongjun Park <aha310510@gmail.com>
---
v2: Change it as suggested by Shakeel Butt
- Link to v1: https://lore.kernel.org/all/20250702082749.141616-1-aha310510@gmail.com/
---
mm/percpu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/percpu.c b/mm/percpu.c
index b35494c8ede2..782cc148b39c 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);
}
/*
--
next reply other threads:[~2025-07-03 6:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-03 6:56 Jeongjun Park [this message]
2025-07-11 15:56 ` [PATCH v2] mm/percpu: prevent concurrency problem for pcpu_nr_populated read with spin lock Vlastimil Babka
2025-07-12 22:28 ` Andrew Morton
2025-07-14 7:10 ` Vlastimil Babka
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=20250703065600.132221-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=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--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;
as well as URLs for NNTP newsgroup(s).