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=-15.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham 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 C3B88C433B4 for ; Tue, 11 May 2021 16:05:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 43E146191C for ; Tue, 11 May 2021 16:05:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 43E146191C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CBDA46B0073; Tue, 11 May 2021 12:05:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C940D8D0002; Tue, 11 May 2021 12:05:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0D026B0075; Tue, 11 May 2021 12:05:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0211.hostedemail.com [216.40.44.211]) by kanga.kvack.org (Postfix) with ESMTP id 961596B0073 for ; Tue, 11 May 2021 12:05:35 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 579C88249980 for ; Tue, 11 May 2021 16:05:35 +0000 (UTC) X-FDA: 78129425430.35.929EE74 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id C20D9A00019E for ; Tue, 11 May 2021 16:05:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620749134; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+Z2k7kEMuOxvMNfv9wyuet8mFypiPJLma4wFOmFQFhU=; b=Wp8f1/wPTwtpkZTz/sa16wBXqnXLwnnFAUYCHl8g0cv5+sTR2RYOm9tD+ywAbynUsb1qxR B6/uIy0tCGFkgTLCvE52gsxlNjivgwjU7E2yOukYeI6hPxE++Brt06uN2Daj4MlzmXtpGd d52XCDjhsDUPATLuk/GGzniwNUmWpaQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-326-Z7LXlEqAMSavyp-h4tVVsA-1; Tue, 11 May 2021 12:05:32 -0400 X-MC-Unique: Z7LXlEqAMSavyp-h4tVVsA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 73FD4107ACED; Tue, 11 May 2021 16:05:29 +0000 (UTC) Received: from [10.3.115.19] (ovpn-115-19.phx2.redhat.com [10.3.115.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id B81FA5C232; Tue, 11 May 2021 16:05:26 +0000 (UTC) Subject: Re: [PATCH 01/16] PCI/P2PDMA: Pass gfp_mask flags to upstream_bridge_distance_warn() To: John Hubbard , Logan Gunthorpe , linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org Cc: Stephen Bates , Christoph Hellwig , Dan Williams , Jason Gunthorpe , =?UTF-8?Q?Christian_K=c3=b6nig?= , Matthew Wilcox , Daniel Vetter , Jakowski Andrzej , Minturn Dave B , Jason Ekstrand , Dave Hansen , Xiong Jianxin , Bjorn Helgaas , Ira Weiny , Robin Murphy , Bjorn Helgaas References: <20210408170123.8788-1-logang@deltatee.com> <20210408170123.8788-2-logang@deltatee.com> From: Don Dutile Message-ID: Date: Tue, 11 May 2021 12:05:26 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Wp8f1/wP"; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf07.hostedemail.com: domain of ddutile@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=ddutile@redhat.com X-Stat-Signature: jkgydj389xjedu94zijy7gt81jsaor95 X-Rspamd-Queue-Id: C20D9A00019E X-Rspamd-Server: rspam02 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf07; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=170.10.133.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620749131-313212 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 5/1/21 11:58 PM, John Hubbard wrote: > On 4/8/21 10:01 AM, Logan Gunthorpe wrote: >> In order to call upstream_bridge_distance_warn() from a dma_map functi= on, >> it must not sleep. The only reason it does sleep is to allocate the se= qbuf >> to print which devices are within the ACS path. >> >> Switch the kmalloc call to use a passed in gfp_mask and don't print th= at >> message if the buffer fails to be allocated. >> >> Signed-off-by: Logan Gunthorpe >> Acked-by: Bjorn Helgaas >> --- >> =C2=A0 drivers/pci/p2pdma.c | 21 +++++++++++---------- >> =C2=A0 1 file changed, 11 insertions(+), 10 deletions(-) >> >> diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c >> index 196382630363..bd89437faf06 100644 >> --- a/drivers/pci/p2pdma.c >> +++ b/drivers/pci/p2pdma.c >> @@ -267,7 +267,7 @@ static int pci_bridge_has_acs_redir(struct pci_dev= *pdev) >> =C2=A0 =C2=A0 static void seq_buf_print_bus_devfn(struct seq_buf *buf,= struct pci_dev *pdev) >> =C2=A0 { >> -=C2=A0=C2=A0=C2=A0 if (!buf) >> +=C2=A0=C2=A0=C2=A0 if (!buf || !buf->buffer) > > This is not great, sort of from an overall design point of view, even t= hough > it makes the rest of the patch work. See below for other ideas, that wi= ll > avoid the need for this sort of odd point fix. > +1. In fact, I didn't see how the kmalloc was changed... you refactored the c= ode to pass-in the GFP_KERNEL that was originally hard-coded into upstream_bridge_distance_w= arn(); I don't see how that avoided the kmalloc() call. in fact, I also see you lost a failed kmalloc() check, so it seems to hav= e taken a step back. >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return; >> =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 seq_buf_printf(buf, "%s;", pci_n= ame(pdev)); >> @@ -495,25 +495,26 @@ upstream_bridge_distance(struct pci_dev *provide= r, struct pci_dev *client, >> =C2=A0 =C2=A0 static enum pci_p2pdma_map_type >> =C2=A0 upstream_bridge_distance_warn(struct pci_dev *provider, struct = pci_dev *client, >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int *dist) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int *dist, gfp_t gfp_mask) >> =C2=A0 { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct seq_buf acs_list; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bool acs_redirects; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int ret; >> =C2=A0 -=C2=A0=C2=A0=C2=A0 seq_buf_init(&acs_list, kmalloc(PAGE_SIZE, = GFP_KERNEL), PAGE_SIZE); >> -=C2=A0=C2=A0=C2=A0 if (!acs_list.buffer) >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return -ENOMEM; > > Another odd thing: this used to check for memory failure and just give > up, and now it doesn't. Yes, I realize that it all still works at the > moment, but this is quirky and we shouldn't stop here. > > Instead, a cleaner approach would be to push the memory allocation > slightly higher up the call stack, out to the > pci_p2pdma_distance_many(). So pci_p2pdma_distance_many() should make > the kmalloc() call, and fail out if it can't get a page for the seq_buf > buffer. Then you don't have to do all this odd stuff. > > Furthermore, the call sites can then decide for themselves which GFP > flags, GFP_ATOMIC or GFP_KERNEL or whatever they want for kmalloc(). > agree, good proposal to avoid a sleep due to kmalloc(). > A related thing: this whole exercise would go better if there were a > preparatory patch or two that changed the return codes in this file to > something less crazy. There are too many functions that can fail, but > are treated as if they sort-of-mostly-would-never-fail, in the hopes of > using the return value directly for counting and such. This is badly > mistaken, and it leads developers to try to avoid returning -ENOMEM > (which is what we need here). > > Really, these functions should all be doing "0 for success, -ERRNO for > failure, and pass other values, including results, in the arg list". > WFM! > >> +=C2=A0=C2=A0=C2=A0 seq_buf_init(&acs_list, kmalloc(PAGE_SIZE, gfp_mas= k), PAGE_SIZE); >> =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret =3D upstream_bridge_distance= (provider, client, dist, &acs_redirects, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = &acs_list); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (acs_redirects) { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pci_warn(client= , "ACS redirect is set between the client and provider (%s)\n", >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 pci_name(provider)); >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Drop final semicolon */ >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 acs_list.buffer[acs_list.l= en-1] =3D 0; >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pci_warn(client, "to disab= le ACS redirect for this path, add the kernel parameter: pci=3Ddisable_ac= s_redir=3D%s\n", >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 acs_list.buffer); >> + >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (acs_list.buffer) { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /*= Drop final semicolon */ >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ac= s_list.buffer[acs_list.len - 1] =3D 0; >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pc= i_warn(client, "to disable ACS redirect for this path, add the kernel par= ameter: pci=3Ddisable_acs_redir=3D%s\n", >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 acs_list.buffer); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >> =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (ret =3D=3D PCI_P2PDMA_MAP_NO= T_SUPPORTED) { >> @@ -566,7 +567,7 @@ int pci_p2pdma_distance_many(struct pci_dev *provi= der, struct device **clients, >> =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (verb= ose) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 ret =3D upstream_bridge_distance_warn(provider, >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pci_client, &distance); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pci_client, &distance, GFP_= KERNEL); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 else >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 ret =3D upstream_bridge_distance(provider, pci_client, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &distance, NULL, NULL); >> > > thanks,