All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dennis Zhou <dennis@kernel.org>
To: Wan Jiabing <wanjiabing@vivo.com>
Cc: Tejun Heo <tj@kernel.org>, Christoph Lameter <cl@linux.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	kael_w@yeah.net
Subject: Re: [PATCH] mm/percpu: Fix gfp flag in pcpu_balance_populated
Date: Fri, 18 Jun 2021 18:20:01 +0000	[thread overview]
Message-ID: <YMzj0V8CVte/Pynx@google.com> (raw)
In-Reply-To: <20210618151436.38217-1-wanjiabing@vivo.com>

Hello,

On Fri, Jun 18, 2021 at 11:14:36PM +0800, Wan Jiabing wrote:
> Fix coccicheck warning:
> 
> ./mm/percpu.c:2045:19-29: ERROR: function pcpu_balance_populated
> called on line 2232 inside lock on line 2228 but uses GFP_KERNEL
> 
> When pcpu_balance_populated() is called in pcpu_balance_workfn(),
> it helds spin_lock but use GFP_KERNEL to alloc mem, which is unsafe.
> 
> Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
> ---
>  mm/percpu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/percpu.c b/mm/percpu.c
> index b4cebeca4c0c..4031f32e6975 100644
> --- a/mm/percpu.c
> +++ b/mm/percpu.c
> @@ -2042,7 +2042,7 @@ static void pcpu_balance_free(bool empty_only)
>  static void pcpu_balance_populated(void)
>  {
>  	/* gfp flags passed to underlying allocators */
> -	const gfp_t gfp = GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN;
> +	const gfp_t gfp = GFP_ATOMIC | __GFP_NORETRY | __GFP_NOWARN;
>  	struct pcpu_chunk *chunk;
>  	int slot, nr_to_pop, ret;
>  
> -- 
> 2.30.2
> 

In both places gfp flags are passed, the pcpu_lock is dropped. So I
think this is an issue with coccicheck. Regardless, the fix wouldn't be
to switch to GFP_ATOMIC but to make the locking correct.

Thanks,
Dennis

      reply	other threads:[~2021-06-18 18:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-18 15:14 [PATCH] mm/percpu: Fix gfp flag in pcpu_balance_populated Wan Jiabing
2021-06-18 18:20 ` Dennis Zhou [this message]

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=YMzj0V8CVte/Pynx@google.com \
    --to=dennis@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=kael_w@yeah.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=tj@kernel.org \
    --cc=wanjiabing@vivo.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.