public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@kernel.org>
To: Wei Yongjun <weiyj.lk@gmail.com>
Cc: jinqian@android.com, gregkh@linuxfoundation.org,
	lstoakes@gmail.com, jack@suse.cz, christian.koenig@amd.com,
	Wei Yongjun <weiyongjun1@huawei.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] goldfish_pipe: use GFP_ATOMIC under spin lock
Date: Mon, 22 May 2017 13:51:52 +0200	[thread overview]
Message-ID: <20170522115152.GH8509@dhcp22.suse.cz> (raw)
In-Reply-To: <20170521074836.GA24459@dhcp22.suse.cz>

On Sun 21-05-17 09:48:36, Michal Hocko wrote:
> On Sun 21-05-17 00:45:46, Wei Yongjun wrote:
> > From: Wei Yongjun <weiyongjun1@huawei.com>
> > 
> > The function get_free_pipe_id_locked() is called from
> > goldfish_pipe_open() with a lock is held, so we should
> > use GFP_ATOMIC instead of GFP_KERNEL.
> 
> Why is GFP_NOWAIT insufficient? Does this path needs an access to memory
> reserves?

And now when looking at the code more deeply, wouldn't it be much better
to simply do the allocation outside of the spin lock and do assignments
with the lock held?

> 
> > Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> > ---
> >  drivers/platform/goldfish/goldfish_pipe.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/platform/goldfish/goldfish_pipe.c b/drivers/platform/goldfish/goldfish_pipe.c
> > index 2de1e60..5f36721 100644
> > --- a/drivers/platform/goldfish/goldfish_pipe.c
> > +++ b/drivers/platform/goldfish/goldfish_pipe.c
> > @@ -704,7 +704,7 @@ static int get_free_pipe_id_locked(struct goldfish_pipe_dev *dev)
> >  		/* Reallocate the array */
> >  		u32 new_capacity = 2 * dev->pipes_capacity;
> >  		struct goldfish_pipe **pipes =
> > -			kcalloc(new_capacity, sizeof(*pipes), GFP_KERNEL);
> > +			kcalloc(new_capacity, sizeof(*pipes), GFP_ATOMIC);
> >  		if (!pipes)
> >  			return -ENOMEM;
> >  		memcpy(pipes, dev->pipes, sizeof(*pipes) * dev->pipes_capacity);
> > 
> 
> -- 
> Michal Hocko
> SUSE Labs

-- 
Michal Hocko
SUSE Labs

  reply	other threads:[~2017-05-22 11:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-21  0:45 [PATCH] goldfish_pipe: use GFP_ATOMIC under spin lock Wei Yongjun
2017-05-21  7:48 ` Michal Hocko
2017-05-22 11:51   ` Michal Hocko [this message]
2017-05-22 18:48     ` Alan Cox
2017-06-09 19:15       ` Jin Qian
2017-06-13  6:02         ` Greg Kroah-Hartman
2017-06-13 18:45           ` Jin Qian

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=20170522115152.GH8509@dhcp22.suse.cz \
    --to=mhocko@kernel.org \
    --cc=christian.koenig@amd.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jack@suse.cz \
    --cc=jinqian@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lstoakes@gmail.com \
    --cc=weiyj.lk@gmail.com \
    --cc=weiyongjun1@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox