From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.1 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7D4FC41514 for ; Mon, 2 Sep 2019 07:50:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8F5B22343A for ; Mon, 2 Sep 2019 07:50:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="QTN11fqU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729919AbfIBHuM (ORCPT ); Mon, 2 Sep 2019 03:50:12 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:48480 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725839AbfIBHuM (ORCPT ); Mon, 2 Sep 2019 03:50:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=NLbPkO1nBLjxjJMJLtjjfjvIrKkFYiad08Wtr6KwkSw=; b=QTN11fqUWCWaQ1Qfvv9fmTkeg f4Du4MFrH1JeBL/lYO4ZmvejNdqey6NA3y5cyyRlcge584lMTs3yBaKzq33D5bbzOugM4K9b2N1Lo m25L2EcK6DZtpdpqBmXVzn7xsRsLu51Ikl+6Xf9MMGg3cy7oF+OcIWJfCEIGH1vF5U6Nmag8Jwh2m Av5PwuPKTVGxS8fhTUztEdPofUkT3UYw5jibpCXaJJ6AaHv5BM1wnu7XQ4pfeXkUWsuCIJHB32jYo 14YZcDEu6aRqCPSkafuqSYr8vyo9rnjOViyAFQhSPj9fQsY8RRe2ddJpXeKtpNQPI9oRC3cPCc9k7 YoZc6ErOA==; Received: from hch by bombadil.infradead.org with local (Exim 4.92 #3 (Red Hat Linux)) id 1i4h6E-0005zw-La; Mon, 02 Sep 2019 07:50:06 +0000 Date: Mon, 2 Sep 2019 00:50:06 -0700 From: Christoph Hellwig To: YueHaibing Cc: Bjorn Helgaas , Logan Gunthorpe , 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() Message-ID: <20190902075006.GB754@infradead.org> References: <20190831124932.18759-1-yuehaibing@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190831124932.18759-1-yuehaibing@huawei.com> User-Agent: Mutt/1.11.4 (2019-03-13) X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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: 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);