From: Bjorn Helgaas <helgaas@kernel.org>
To: Logan Gunthorpe <logang@deltatee.com>
Cc: Christoph Hellwig <hch@infradead.org>,
YueHaibing <yuehaibing@huawei.com>,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH -next] PCI: Use GFP_ATOMIC in resource_alignment_store()
Date: Thu, 5 Sep 2019 16:47:12 -0500 [thread overview]
Message-ID: <20190905214712.GJ103977@google.com> (raw)
In-Reply-To: <9d2094f7-eb71-4975-eb9b-166a1483afa0@deltatee.com>
On Tue, Sep 03, 2019 at 09:51:05AM -0600, Logan Gunthorpe wrote:
>
>
> On 2019-09-02 1:50 a.m., Christoph Hellwig wrote:
> > On Sat, Aug 31, 2019 at 12:49:32PM +0000, YueHaibing wrote:
> >> When allocating memory, the GFP_KERNEL cannot be used during the
> >> spin_lock period. It may cause scheduling when holding spin_lock.
> >>
> >> Fixes: f13755318675 ("PCI: Move pci_[get|set]_resource_alignment_param() into their callers")
> >> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> >> ---
> >> drivers/pci/pci.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> >> index 484e35349565..0b5fc6736f3f 100644
> >> --- a/drivers/pci/pci.c
> >> +++ b/drivers/pci/pci.c
> >> @@ -6148,7 +6148,7 @@ static ssize_t resource_alignment_store(struct bus_type *bus,
> >> spin_lock(&resource_alignment_lock);
> >>
> >> kfree(resource_alignment_param);
> >> - resource_alignment_param = kstrndup(buf, count, GFP_KERNEL);
> >> + resource_alignment_param = kstrndup(buf, count, GFP_ATOMIC);
> >>
> >> spin_unlock(&resource_alignment_lock);
> >
> > Why not move the allocation outside the lock? Something like this
> > seems much more sensible:
>
> Yes, that seems like a good way to do it. Bjorn, can you squash
> Christoph's patch or do you want me to resend a new one?
I folded Christoph's fix into it, thanks!
> > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> > index 484e35349565..fe205829f676 100644
> > --- a/drivers/pci/pci.c
> > +++ b/drivers/pci/pci.c
> > @@ -6145,14 +6145,16 @@ static ssize_t resource_alignment_show(struct bus_type *bus, char *buf)
> > static ssize_t resource_alignment_store(struct bus_type *bus,
> > const char *buf, size_t count)
> > {
> > - spin_lock(&resource_alignment_lock);
> > + char *param = kstrndup(buf, count, GFP_KERNEL);
> >
> > - kfree(resource_alignment_param);
> > - resource_alignment_param = kstrndup(buf, count, GFP_KERNEL);
> > + if (!param)
> > + return -ENOMEM;
> >
> > + spin_lock(&resource_alignment_lock);
> > + kfree(resource_alignment_param);
> > + resource_alignment_param = param;
> > spin_unlock(&resource_alignment_lock);
> > -
> > - return resource_alignment_param ? count : -ENOMEM;
> > + return count;
> > }
> >
> > static BUS_ATTR_RW(resource_alignment);
> >
next prev parent reply other threads:[~2019-09-05 21:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-31 12:49 [PATCH -next] PCI: Use GFP_ATOMIC in resource_alignment_store() YueHaibing
2019-09-02 7:50 ` Christoph Hellwig
2019-09-03 15:51 ` Logan Gunthorpe
2019-09-05 21:47 ` Bjorn Helgaas [this message]
2019-09-03 8:22 ` [PATCH v2 -next] PCI: Don't use GFP_KERNEL for kstrbdup in resource_alignment_store YueHaibing
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=20190905214712.GJ103977@google.com \
--to=helgaas@kernel.org \
--cc=hch@infradead.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=logang@deltatee.com \
--cc=yuehaibing@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;
as well as URLs for NNTP newsgroup(s).