From: Andrew Morton <akpm@linux-foundation.org>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Jeongjun Park <aha310510@gmail.com>,
dennis@kernel.org, tj@kernel.org, cl@gentwo.org,
roman.gushchin@linux.dev, rientjes@google.com,
shakeel.butt@linux.dev, linux-mm@kvack.org,
linux-kernel@vger.kernel.org,
syzbot+e5bd32b79413e86f389e@syzkaller.appspotmail.com
Subject: Re: [PATCH v2] mm/percpu: prevent concurrency problem for pcpu_nr_populated read with spin lock
Date: Sat, 12 Jul 2025 15:28:46 -0700 [thread overview]
Message-ID: <20250712152846.58adeea972a6c9caac8003d1@linux-foundation.org> (raw)
In-Reply-To: <b272ce4a-a20c-43de-8080-db8ad14abaff@suse.cz>
On Fri, 11 Jul 2025 17:56:34 +0200 Vlastimil Babka <vbabka@suse.cz> wrote:
> On 7/3/25 08:56, Jeongjun Park wrote:
> > 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);
>
> Nit: pcpu_nr_units should be excluded from the scope of data_race() as no
> race can happen there.
This?
--- a/mm/percpu.c~mm-percpu-prevent-concurrency-problem-for-pcpu_nr_populated-read-with-spin-lock-fix
+++ a/mm/percpu.c
@@ -3355,7 +3355,7 @@ void __init setup_per_cpu_areas(void)
*/
unsigned long pcpu_nr_pages(void)
{
- return data_race(READ_ONCE(pcpu_nr_populated) * pcpu_nr_units);
+ return data_race(READ_ONCE(pcpu_nr_populated)) * pcpu_nr_units;
}
/*
_
next prev parent reply other threads:[~2025-07-12 22:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-03 6:56 Jeongjun Park
2025-07-11 15:56 ` Vlastimil Babka
2025-07-12 22:28 ` Andrew Morton [this message]
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=20250712152846.58adeea972a6c9caac8003d1@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=aha310510@gmail.com \
--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
all inboxes | Powered by JetHome®