* [PATCH v2] mm/percpu: prevent concurrency problem for pcpu_nr_populated read with spin lock
@ 2025-07-03 6:56 Jeongjun Park
2025-07-11 15:56 ` Vlastimil Babka
0 siblings, 1 reply; 4+ messages in thread
From: Jeongjun Park @ 2025-07-03 6:56 UTC (permalink / raw)
To: dennis, tj, cl
Cc: akpm, roman.gushchin, rientjes, vbabka, shakeel.butt, linux-mm,
linux-kernel, syzbot+e5bd32b79413e86f389e, Jeongjun Park
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);
}
/*
--
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] mm/percpu: prevent concurrency problem for pcpu_nr_populated read with spin lock
2025-07-03 6:56 [PATCH v2] mm/percpu: prevent concurrency problem for pcpu_nr_populated read with spin lock Jeongjun Park
@ 2025-07-11 15:56 ` Vlastimil Babka
2025-07-12 22:28 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: Vlastimil Babka @ 2025-07-11 15:56 UTC (permalink / raw)
To: Jeongjun Park, dennis, tj, cl
Cc: akpm, roman.gushchin, rientjes, shakeel.butt, linux-mm,
linux-kernel, syzbot+e5bd32b79413e86f389e
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.
> }
>
> /*
> --
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] mm/percpu: prevent concurrency problem for pcpu_nr_populated read with spin lock
2025-07-11 15:56 ` Vlastimil Babka
@ 2025-07-12 22:28 ` Andrew Morton
2025-07-14 7:10 ` Vlastimil Babka
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2025-07-12 22:28 UTC (permalink / raw)
To: Vlastimil Babka
Cc: Jeongjun Park, dennis, tj, cl, roman.gushchin, rientjes,
shakeel.butt, linux-mm, linux-kernel, syzbot+e5bd32b79413e86f389e
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;
}
/*
_
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] mm/percpu: prevent concurrency problem for pcpu_nr_populated read with spin lock
2025-07-12 22:28 ` Andrew Morton
@ 2025-07-14 7:10 ` Vlastimil Babka
0 siblings, 0 replies; 4+ messages in thread
From: Vlastimil Babka @ 2025-07-14 7:10 UTC (permalink / raw)
To: Andrew Morton
Cc: Jeongjun Park, dennis, tj, cl, roman.gushchin, rientjes,
shakeel.butt, linux-mm, linux-kernel, syzbot+e5bd32b79413e86f389e
On 7/13/25 00:28, Andrew Morton wrote:
> 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;
Yes, thanks!
> }
>
> /*
> _
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-07-14 7:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-03 6:56 [PATCH v2] mm/percpu: prevent concurrency problem for pcpu_nr_populated read with spin lock Jeongjun Park
2025-07-11 15:56 ` Vlastimil Babka
2025-07-12 22:28 ` Andrew Morton
2025-07-14 7:10 ` Vlastimil Babka
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).