linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Jeongjun Park <aha310510@gmail.com>,
	dennis@kernel.org, tj@kernel.org, cl@gentwo.org
Cc: akpm@linux-foundation.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: Fri, 11 Jul 2025 17:56:34 +0200	[thread overview]
Message-ID: <b272ce4a-a20c-43de-8080-db8ad14abaff@suse.cz> (raw)
In-Reply-To: <20250703065600.132221-1-aha310510@gmail.com>

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.

>  }
>  
>  /*
> --



  reply	other threads:[~2025-07-11 15:56 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 [this message]
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=b272ce4a-a20c-43de-8080-db8ad14abaff@suse.cz \
    --to=vbabka@suse.cz \
    --cc=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 \
    /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