From patchwork Fri Dec 18 17:39:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982637 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 E8960C2BBD5 for ; Fri, 18 Dec 2020 17:42:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2ABD23B7D for ; Fri, 18 Dec 2020 17:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731636AbgLRRlv (ORCPT ); Fri, 18 Dec 2020 12:41:51 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:37876 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726057AbgLRRlv (ORCPT ); Fri, 18 Dec 2020 12:41:51 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 05733413C8; Fri, 18 Dec 2020 17:41:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313267; x=1610127668; bh=vlhDGWs84jnDn9lker3XX/X6kdDT1STUvKr Mzdw7AQ0=; b=U2inflNqwtIgmlPeeDSyU5RoTBZUcUjrVs540Tuc2ntT6K25n4a X92sRuCyjJBeO5OwqC59Bg4iBMwxIkCab36FcGRDTwXNaTnkHF6wh/8+UZsegkx4 i6YzxyjVbzlRiZZMqTh2Q9P6kog+Z9+vaNqCntABo9zmwql7zWy2a7Ng= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id t1wUiKuRBgiS; Fri, 18 Dec 2020 20:41:07 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 6D9F34137C; Fri, 18 Dec 2020 20:41:06 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:05 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko , Srinath Mannam , Marta Rybczynska Subject: [PATCH v9 01/26] PCI: Fix race condition in pci_enable/disable_device() Date: Fri, 18 Dec 2020 20:39:46 +0300 Message-ID: <20201218174011.340514-2-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org This is a yet another approach to fix an old [1-2] concurrency issue, when: - two or more devices are being hot-added into a bridge which was initially empty; - a bridge with two or more devices is being hot-added; - the BIOS/bootloader/firmware doesn't pre-enable bridges during boot; The problem is that a bridge is reported as enabled before the MEM/IO bits are actually written to the PCI_COMMAND register, so another driver thread starts memory requests through the not-yet-enabled bridge: CPU0 CPU1 pci_enable_device_mem() pci_enable_device_mem() pci_enable_bridge() pci_enable_bridge() pci_is_enabled() return false; atomic_inc_return(enable_cnt) Start actual enabling the bridge ... pci_is_enabled() ... return true; ... Start memory requests <-- FAIL ... Set the PCI_COMMAND_MEMORY bit <-- Must wait for this Protect the pci_enable_bridge(), similarly to the previous solution from commit 40f11adc7cd9 ("PCI: Avoid race while enabling upstream bridges"), but adding per-device mutexes. To prevent false positives from the lockdep, use a lock_nested() with a "depth" of a bridge within the PCI topology. CC: Srinath Mannam CC: Marta Rybczynska Signed-off-by: Sergei Miroshnichenko [1] https://lore.kernel.org/linux-pci/1501858648-22228-1-git-send-email-srinath.mannam@broadcom.com/T/#u [RFC PATCH v3] pci: Concurrency issue during pci enable bridge [2] https://lore.kernel.org/linux-pci/744877924.5841545.1521630049567.JavaMail.zimbra@kalray.eu/T/#u [RFC PATCH] nvme: avoid race-conditions when enabling devices --- drivers/pci/pci.c | 16 ++++++++++++++++ drivers/pci/probe.c | 1 + include/linux/pci.h | 1 + 3 files changed, 18 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index b9fecc25d213..076b908127fe 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1844,11 +1844,25 @@ int pci_reenable_device(struct pci_dev *dev) } EXPORT_SYMBOL(pci_reenable_device); +#ifdef CONFIG_PROVE_LOCKING +static int pci_bridge_depth(struct pci_dev *dev) +{ + struct pci_dev *bridge = pci_upstream_bridge(dev); + + if (!bridge) + return 0; + + return 1 + pci_bridge_depth(bridge); +} +#endif /* CONFIG_PROVE_LOCKING */ + static void pci_enable_bridge(struct pci_dev *dev) { struct pci_dev *bridge; int retval; + mutex_lock_nested(&dev->enable_mutex, pci_bridge_depth(dev)); + bridge = pci_upstream_bridge(dev); if (bridge) pci_enable_bridge(bridge); @@ -1856,6 +1870,7 @@ static void pci_enable_bridge(struct pci_dev *dev) if (pci_is_enabled(dev)) { if (!dev->is_busmaster) pci_set_master(dev); + mutex_unlock(&dev->enable_mutex); return; } @@ -1864,6 +1879,7 @@ static void pci_enable_bridge(struct pci_dev *dev) pci_err(dev, "Error enabling bridge (%d), continuing\n", retval); pci_set_master(dev); + mutex_unlock(&dev->enable_mutex); } static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 953f15abc850..2f9631287719 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2240,6 +2240,7 @@ struct pci_dev *pci_alloc_dev(struct pci_bus *bus) INIT_LIST_HEAD(&dev->bus_list); dev->dev.type = &pci_dev_type; dev->bus = pci_bus_get(bus); + mutex_init(&dev->enable_mutex); return dev; } diff --git a/include/linux/pci.h b/include/linux/pci.h index b32126d26997..81d54889bd51 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -455,6 +455,7 @@ struct pci_dev { unsigned int no_command_memory:1; /* No PCI_COMMAND_MEMORY */ pci_dev_flags_t dev_flags; atomic_t enable_cnt; /* pci_enable_device has been called */ + struct mutex enable_mutex; u32 saved_config_space[16]; /* Config space saved at suspend time */ struct hlist_head saved_cap_space; From patchwork Fri Dec 18 17:39:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982631 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 B58FFC4361B for ; Fri, 18 Dec 2020 17:42:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 75DB423B75 for ; Fri, 18 Dec 2020 17:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728303AbgLRRlv (ORCPT ); Fri, 18 Dec 2020 12:41:51 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:37900 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728147AbgLRRlu (ORCPT ); Fri, 18 Dec 2020 12:41:50 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 6F806413CD; Fri, 18 Dec 2020 17:41:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313268; x=1610127669; bh=W7zcvbVJmLFtBKGNQFYRu7td+56m3Kd/9dF l39M0Org=; b=iLUSPGXzahlGftaQ5771vVhjXgoB4UwPfqCxggAclgyA7P17OZb lTfsYmNUvb9g9gBnf/BFLw1BJ1lWyP1ntYvOHmbq9XgV1sRopRlyZVGHbigYyvKu rDDYDKUftOANmaNIDwxyD9TP79bhDfmrRwXiaWOdsQLITRJNzV+HHgT0= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RBAXJFHrNrA4; Fri, 18 Dec 2020 20:41:08 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 73C7E412E1; Fri, 18 Dec 2020 20:41:07 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:05 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 02/26] PCI: Ensure a bridge has I/O and MEM access for hot-added devices Date: Fri, 18 Dec 2020 20:39:47 +0300 Message-ID: <20201218174011.340514-3-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org During hot-adding a device, its bridge may be already pci_is_enabled(), but without the I/O and/or MEM access bits, which may be required by this new device: these bits are set during first enabling the bridge, and they must be checked again. When hot-adding to the following bridge: +-[0020:00]---00.0-[01-0d]----00.0-[02-0d]----04.0-[03-0d]-- <- 00.0 this patch sets up the MEM bit in the downstream port 0020:02:04.0, needed for 0020:08:00.0: [ 1037.698206] pci 0020:00:00.0: PCI bridge to [bus 01-0d] [ 1037.698785] pci 0020:00:00.0: bridge window [mem 0x3fe800000000-0x3fe8017fffff] [ 1037.698874] pci 0020:00:00.0: bridge window [mem 0x240000000000-0x2400ffffffff 64bit pref] [ 1037.699002] pcieport 0020:02:04.0: enabling device (0545 -> 0547) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [ 1037.699114] pcieport 0020:03:00.0: enabling device (0540 -> 0542) [ 1037.699198] pciehp 0020:04:09.0:pcie204: Slot #41 AttnBtn+ PwrCtrl+ MRL- AttnInd+ PwrInd+ HotPlug+ Surprise- Interlock- NoCompl- LLActRep+ [ 1037.699285] pciehp 0020:04:09.0:pcie204: Slot(41): Card present [ 1037.699346] pciehp 0020:04:09.0:pcie204: Slot(41): Already enabled Signed-off-by: Sergei Miroshnichenko --- drivers/pci/pci.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 076b908127fe..b7bbc462a0b3 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1868,6 +1868,10 @@ static void pci_enable_bridge(struct pci_dev *dev) pci_enable_bridge(bridge); if (pci_is_enabled(dev)) { + retval = pci_reenable_device(dev); + if (retval) + pci_err(dev, "Error reenabling bridge, continuing\n"); + if (!dev->is_busmaster) pci_set_master(dev); mutex_unlock(&dev->enable_mutex); From patchwork Fri Dec 18 17:39:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982639 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 40884C3526C for ; Fri, 18 Dec 2020 17:42:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0D96523B5D for ; Fri, 18 Dec 2020 17:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729854AbgLRRlz (ORCPT ); Fri, 18 Dec 2020 12:41:55 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:37944 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730270AbgLRRlz (ORCPT ); Fri, 18 Dec 2020 12:41:55 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id ECFD9413E1; Fri, 18 Dec 2020 17:41:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313269; x=1610127670; bh=fxQXbFh6s+5sl+1t4OwYUApqBpUWKT5kxOJ MnkMS0sc=; b=DnEE3WLARohpee37q81YY7J2NgkBFXIhl2KqcukPMHtolbBr6jx wsc7XlSONsBHM43I2Z5zrzCaEqgjZPUvV6EB9GvQx2MmXgNGu8a3mUhnGL3qSrM7 PIcwkAQGD8cNCJk/odMUGSttueevN+gd0grEuquyBNuWGbD5ZmKkst8k= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id U1Z5X_iU9YOY; Fri, 18 Dec 2020 20:41:09 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 7B25C41396; Fri, 18 Dec 2020 20:41:07 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:05 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 03/26] PCI: hotplug: Initial support of the movable BARs feature Date: Fri, 18 Dec 2020 20:39:48 +0300 Message-ID: <20201218174011.340514-4-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org When hot-adding a device, the involved bridge may have windows not big enough (or fragmented too much) for newly requested BARs to fit in. But expanding these bridge windows may be impossible if they are wedged between existing neighboring BARs. Still, it may be possible to allocate a memory region for new BARs, if at least some working BARs can be moved, using the following procedure: 1) Notify all the drivers which support movable BARs to pause and release the BARs; the rest of the drivers are guaranteed that their devices will not get BARs moved; 2) Release all the bridge windows and movable BARs; 3) Try to recalculate new bridge windows that will fit all the BAR types: - fixed (those marked with PCI_FIXED or bound by not-updated drivers); - movable; - newly requested by hot-added devices; 4) If that failed, disable BARs for one of the hot-added devices and repeat the step 3; 5) Notify the drivers, so they remap BARs and resume. If bridge calculation and BAR assignment fail with hot-added devices, this patchset disables their BARs, falling back to the same amount and size of BARs as they were before the hotplug event. The kernel succeeded then, so the same BAR layout will be reproduced again. This makes the prior reservation of memory by BIOS/bootloader/firmware not required anymore for the PCI hotplug. Drivers indicate support of movable BARs by implementing a new .bar_fixed() hook and two optional ones: .rescan_prepare() and .rescan_done() in the struct pci_driver. All device's activity must be paused during a rescan, and iounmap()+ioremap() must be applied to every used BAR. If a device is not bound to a driver, its BARs are considered movable, except VGA devices, due to sometimes indirect usage of their framebuffers. For a higher probability of the successful BAR reassignment, all the BARs and bridge windows should be released during a rescan, not only those with higher addresses. One example when it is needed, BAR(I) is moved to free a gap for the new BAR(II): Before: ==================== parent bridge window =============== ---- hotplug bridge window ---- | BAR(I) | fixed BAR | fixed BAR | fixed BAR | ^^^^^^ ^ | new BAR(II) After: ==================== parent bridge window ========================= ----------- hotplug bridge window ----------- | new BAR(II) | fixed BAR | fixed BAR | fixed BAR | BAR(I) | ^^^^^^^^^^^ ^^^^^^ Another example is a fragmented bridge window jammed between fixed BARs: Before: ===================== parent bridge window ======================== ---------- hotplug bridge window ---------- | fixed BAR | | BAR(I) | | BAR(II) | | BAR(III) | fixed BAR | ^^^^^^ ^ ^^^^^^^ ^^^^^^^^ | new BAR(IV) After: ==================== parent bridge window ========================= ---------- hotplug bridge window ---------- | fixed BAR | BAR(I) | BAR(II) | BAR(III) | new BAR(IV) | fixed BAR | ^^^^^^ ^^^^^^^ ^^^^^^^^ ^^^^^^^^^^^ This patch is a preparation for future patches with actual implementation, and for now it just does the following: - declares the feature; - defines bool pci_can_move_bars and bool pci_dev_bar_fixed(dev, bar); - invokes the new .rescan_prepare() and .rescan_done() driver notifiers; - disables the feature for the powerpc (support will be added later, in another series). The feature is disabled in this first patch of the series, until the actual implementation if finalized by the following patches. It can be overridden per-arch using the pci_can_move_bars=false flag or by the following command line option: pci=no_movable_bars Current approach doesn't support calculating windows for subtractive decode bridges, so disable BAR movement if such bridge is present. Signed-off-by: Sergei Miroshnichenko --- Documentation/PCI/pci.rst | 63 +++++++++++ .../admin-guide/kernel-parameters.txt | 1 + arch/powerpc/platforms/powernv/pci.c | 2 + arch/powerpc/platforms/pseries/setup.c | 2 + drivers/pci/pci.c | 4 + drivers/pci/pci.h | 2 + drivers/pci/probe.c | 101 +++++++++++++++++- include/linux/pci.h | 8 ++ 8 files changed, 181 insertions(+), 2 deletions(-) diff --git a/Documentation/PCI/pci.rst b/Documentation/PCI/pci.rst index 814b40f8360b..48b729873ddb 100644 --- a/Documentation/PCI/pci.rst +++ b/Documentation/PCI/pci.rst @@ -575,3 +575,66 @@ handle the PCI master abort on all platforms if the PCI device is expected to not respond to a readl(). Most x86 platforms will allow MMIO reads to master abort (a.k.a. "Soft Fail") and return garbage (e.g. ~0). But many RISC platforms will crash (a.k.a."Hard Fail"). + + +Movable BARs +============ + +To increase the probability of finding a space for BARs of hot-added devices, +the kernel requests the drivers to release used BARs, so they can be moved +to free a gap for new BARs. + +This ability can be added to a driver by implementing the +:c:type:`rescan_prepare()`, :c:type:`bar_fixed()` and :c:type:`rescan_done()` +hooks from the :c:type:`struct pci_driver`. + +Before a PCI bus rescan the driver must pause its activity and unmap its +BARs, here is an example of how the NVMe driver can perform this:: + + static struct pci_driver nvme_driver = { + ... + .bar_fixed = nvme_bar_fixed, + .rescan_prepare = nvme_rescan_prepare, + .rescan_done = nvme_rescan_done, + }; + + static bool nvme_bar_fixed(struct pci_dev *pdev, int resno) + { + return false; + } + + static void nvme_rescan_prepare(struct pci_dev *pdev) + { + struct nvme_dev *dev = pci_get_drvdata(pdev); + + nvme_dev_disable(dev, true); + nvme_dev_unmap(dev); + dev->bar = NULL; + } + +The NVMe driver uses a single BAR, which is movable. After a PCI rescan, +the driver must re-read new addresses of BARs, remap them and resume:: + + static void nvme_rescan_done(struct pci_dev *pdev) + { + struct nvme_dev *dev = pci_get_drvdata(pdev); + + nvme_dev_map(dev); + nvme_reset_ctrl(&dev->ctrl); + } + +Currently there are no reliable way to determine if a driver uses BARs of +its devices or not (their :c:type:`struct resource` don't always have a child), +so if it doesn't explicitly support movable BARs, they are considered fixed. +To let the PCI subsystem move unused BARs, a driver have to implement one hook:: + + static bool pcie_portdrv_bar_fixed(struct pci_dev *pdev, int resno) + { + return false; + } + + static struct pci_driver pcie_portdriver = { + { + ... + .bar_fixed = pcie_portdrv_bar_fixed, + } diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index d24336109c2e..ee215b0e231c 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -3788,6 +3788,7 @@ nomio [S390] Do not use MIO instructions. norid [S390] ignore the RID field and force use of one PCI domain per PCI function + no_movable_bars Don't allow BARs to be moved during hotplug pcie_aspm= [PCIE] Forcibly enable or disable PCIe Active State Power Management. diff --git a/arch/powerpc/platforms/powernv/pci.c b/arch/powerpc/platforms/powernv/pci.c index 9b9bca169275..6a1c31a4e2ca 100644 --- a/arch/powerpc/platforms/powernv/pci.c +++ b/arch/powerpc/platforms/powernv/pci.c @@ -890,6 +890,8 @@ void __init pnv_pci_init(void) { struct device_node *np; + pci_can_move_bars = false; + pci_add_flags(PCI_CAN_SKIP_ISA_ALIGN); /* If we don't have OPAL, eg. in sim, just skip PCI probe */ diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c index 090c13f6c881..cf1804529b48 100644 --- a/arch/powerpc/platforms/pseries/setup.c +++ b/arch/powerpc/platforms/pseries/setup.c @@ -964,6 +964,8 @@ static void __init pseries_init(void) { pr_debug(" -> pseries_init()\n"); + pci_can_move_bars = false; + #ifdef CONFIG_HVC_CONSOLE if (firmware_has_feature(FW_FEATURE_LPAR)) hvc_vio_init_early(); diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index b7bbc462a0b3..f393f0bc8ec4 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -76,6 +76,8 @@ static void pci_dev_d3_sleep(struct pci_dev *dev) int pci_domains_supported = 1; #endif +bool pci_can_move_bars; + #define DEFAULT_CARDBUS_IO_SIZE (256) #define DEFAULT_CARDBUS_MEM_SIZE (64*1024*1024) /* pci=cbmemsize=nnM,cbiosize=nn can override this */ @@ -6602,6 +6604,8 @@ static int __init pci_setup(char *str) pci_add_flags(PCI_SCAN_ALL_PCIE_DEVS); } else if (!strncmp(str, "disable_acs_redir=", 18)) { disable_acs_redir_param = str + 18; + } else if (!strncmp(str, "no_movable_bars", 15)) { + pci_can_move_bars = false; } else { pr_err("PCI: Unknown option `%s'\n", str); } diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 5c59365092fa..c962d0375074 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -273,6 +273,8 @@ void pci_disable_bridge_window(struct pci_dev *dev); struct pci_bus *pci_bus_get(struct pci_bus *bus); void pci_bus_put(struct pci_bus *bus); +bool pci_dev_bar_fixed(struct pci_dev *dev, struct resource *res); + /* PCIe link information from Link Capabilities 2 */ #define PCIE_LNKCAP2_SLS2SPEED(lnkcap2) \ ((lnkcap2) & PCI_EXP_LNKCAP2_SLS_64_0GB ? PCIE_SPEED_64_0GT : \ diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 2f9631287719..17dd1fa4a05a 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2473,6 +2473,11 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) /* Fix up broken headers */ pci_fixup_device(pci_fixup_header, dev); + if (dev->transparent && pci_can_move_bars) { + pci_info(dev, "Disable movable BARs in presence of a transparent bridge\n"); + pci_can_move_bars = false; + } + pci_reassigndev_resource_alignment(dev); dev->state_saved = false; @@ -3007,6 +3012,7 @@ int pci_host_probe(struct pci_host_bridge *bridge) * or pci_bus_assign_resources(). */ if (pci_has_flag(PCI_PROBE_ONLY)) { + pci_can_move_bars = false; pci_bus_claim_resources(bus); } else { pci_bus_size_bridges(bus); @@ -3200,6 +3206,83 @@ unsigned int pci_rescan_bus_bridge_resize(struct pci_dev *bridge) return max; } +bool pci_dev_bar_fixed(struct pci_dev *dev, struct resource *res) +{ + int resno = res - dev->resource; + + /* Bridge windows are never fixed */ + if (resno >= PCI_BRIDGE_RESOURCES) + return false; + + if (res->flags & IORESOURCE_PCI_FIXED) + return true; + + if (res->flags & IORESOURCE_UNSET) + return false; + + if (!pci_can_move_bars) + return false; + + if (dev->driver && dev->driver->bar_fixed) + return dev->driver->bar_fixed(dev, resno); + + if (res->start && + !(res->flags & IORESOURCE_IO) && + (dev->class >> 8) == PCI_CLASS_DISPLAY_VGA) + return true; + + if (!dev->driver && !res->child) + return false; + + return true; +} + +static void pci_bus_rescan_prepare(struct pci_bus *bus) +{ + struct pci_dev *dev; + + if (bus->self) { + pci_config_pm_runtime_get(bus->self); + pm_runtime_get_sync(&bus->self->dev); + } + + list_for_each_entry(dev, &bus->devices, bus_list) { + struct pci_bus *child = dev->subordinate; + + if (child) + pci_bus_rescan_prepare(child); + + if (dev->driver && + dev->driver->rescan_prepare) + dev->driver->rescan_prepare(dev); + } +} + +static void pci_bus_rescan_done(struct pci_bus *bus) +{ + struct pci_dev *dev; + + if (bus->self && !pci_dev_is_added(bus->self)) + return; + + list_for_each_entry(dev, &bus->devices, bus_list) { + struct pci_bus *child = dev->subordinate; + + if (dev->driver && + dev->driver->rescan_done) + dev->driver->rescan_done(dev); + + if (child) + pci_bus_rescan_done(child); + } + + if (bus->self) { + pci_save_state(bus->self); + pm_runtime_put(&bus->self->dev); + pci_config_pm_runtime_put(bus->self); + } +} + /** * pci_rescan_bus - Scan a PCI bus for devices * @bus: PCI bus to scan @@ -3212,9 +3295,23 @@ unsigned int pci_rescan_bus_bridge_resize(struct pci_dev *bridge) unsigned int pci_rescan_bus(struct pci_bus *bus) { unsigned int max; + struct pci_bus *root = bus; + + while (!pci_is_root_bus(root)) + root = root->parent; + + if (pci_can_move_bars) { + pci_bus_rescan_prepare(root); + + max = pci_scan_child_bus(root); + pci_assign_unassigned_root_bus_resources(root); + + pci_bus_rescan_done(root); + } else { + max = pci_scan_child_bus(bus); + pci_assign_unassigned_bus_resources(bus); + } - max = pci_scan_child_bus(bus); - pci_assign_unassigned_bus_resources(bus); pci_bus_add_devices(bus); return max; diff --git a/include/linux/pci.h b/include/linux/pci.h index 81d54889bd51..8a7033b240f1 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -857,6 +857,9 @@ struct module; * e.g. drivers/net/e100.c. * @sriov_configure: Optional driver callback to allow configuration of * number of VFs to enable via sysfs "sriov_numvfs" file. + * @bar_fixed: Returns true if the driver doesn't allow to move this BAR. + * @rescan_prepare: Prepare to BAR movement - called before PCI rescan. + * @rescan_done: Remap BARs and restore after PCI rescan. * @err_handler: See Documentation/PCI/pci-error-recovery.rst * @groups: Sysfs attribute groups. * @driver: Driver model structure. @@ -872,6 +875,9 @@ struct pci_driver { int (*resume)(struct pci_dev *dev); /* Device woken up */ void (*shutdown)(struct pci_dev *dev); int (*sriov_configure)(struct pci_dev *dev, int num_vfs); /* On PF */ + bool (*bar_fixed)(struct pci_dev *dev, int resno); + void (*rescan_prepare)(struct pci_dev *dev); + void (*rescan_done)(struct pci_dev *dev); const struct pci_error_handlers *err_handler; const struct attribute_group **groups; struct device_driver driver; @@ -1426,6 +1432,8 @@ void pci_setup_bridge(struct pci_bus *bus); resource_size_t pcibios_window_alignment(struct pci_bus *bus, unsigned long type); +extern bool pci_can_move_bars; + #define PCI_VGA_STATE_CHANGE_BRIDGE (1 << 0) #define PCI_VGA_STATE_CHANGE_DECODES (1 << 1) From patchwork Fri Dec 18 17:39:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982635 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 25182C3526D for ; Fri, 18 Dec 2020 17:42:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D181523B85 for ; Fri, 18 Dec 2020 17:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732032AbgLRRlx (ORCPT ); Fri, 18 Dec 2020 12:41:53 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:37916 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725939AbgLRRlx (ORCPT ); Fri, 18 Dec 2020 12:41:53 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id A1E99413DA; Fri, 18 Dec 2020 17:41:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313269; x=1610127670; bh=6k4cKOs9PPwIpn1f3t+mizlaNU15OcNpPql ckDUhPrk=; b=YSzs3M2kTilvy9IyFC3ChVOZMK96vBgWQ21D5ssxU1QSEt/heLX AbHsu5flllJzoQKJ9EfNJhB7stndQ/DQqkTvnMS6hNkkuQ7psLHXPlS8mhh+pKqX acryMNNH/htA4N+QHRaWGkkjDTvWbC7RpZag0A/H7/0lvEecHxGEm1Io= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cJ3C7YPJcQ_g; Fri, 18 Dec 2020 20:41:09 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 8494F413A8; Fri, 18 Dec 2020 20:41:07 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:05 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 04/26] PCI: Add version of release_child_resources() aware of fixed BARs Date: Fri, 18 Dec 2020 20:39:49 +0300 Message-ID: <20201218174011.340514-5-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org When release_child_resources() is applied to a bridge window, it zeroes the .start field of children BARs, but the STARTALIGN flag remains set, leaving the resource in a state not valid for later re-assignment. So replace this flag with SIZEALIGN. Fixed BARs must preserve their offset and size: those marked with PCI_FIXED or bound by drivers without support of the movable BARs feature. Add the pci_release_child_resources() to replace release_child_resources() in handling the described PCI-specific cases. Signed-off-by: Sergei Miroshnichenko --- drivers/pci/setup-bus.c | 53 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 2ce636937c6e..bc342eaa98e8 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1520,6 +1520,56 @@ static void __pci_bridge_assign_resources(const struct pci_dev *bridge, (IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_PREFETCH |\ IORESOURCE_MEM_64) +/* + * Similar to generic release_child_resources(), but aware of fixed BARs and the + * STARTALIGN flag. + */ +static void pci_release_child_resources(struct pci_bus *bus, struct resource *r) +{ + struct pci_dev *dev; + + if (!pci_can_move_bars) + return release_child_resources(r); + + if (!bus || !r) + return; + + r->child = NULL; + + list_for_each_entry(dev, &bus->devices, bus_list) { + int i; + + for (i = 0; i < PCI_NUM_RESOURCES; i++) { + struct resource *tmp = &dev->resource[i]; + resource_size_t size = resource_size(tmp); + + if (!tmp->flags || !tmp->parent) + continue; + + tmp->parent = NULL; + tmp->sibling = NULL; + + pci_release_child_resources(dev->subordinate, tmp); + + tmp->flags &= ~IORESOURCE_STARTALIGN; + tmp->flags |= IORESOURCE_SIZEALIGN; + + if (pci_dev_bar_fixed(dev, tmp)) { + pci_dbg(dev, "release fixed BAR %d %pR (%s), keep its flags, base and size\n", + i, tmp, tmp->name); + continue; + } + + pci_dbg(dev, "release BAR %d %pR (%s)\n", i, tmp, tmp->name); + + if (i >= PCI_BRIDGE_RESOURCES) + tmp->flags = 0; + tmp->start = 0; + tmp->end = size - 1; + } + } +} + static void pci_bridge_release_resources(struct pci_bus *bus, unsigned long type) { @@ -1560,7 +1610,8 @@ static void pci_bridge_release_resources(struct pci_bus *bus, return; /* If there are children, release them all */ - release_child_resources(r); + pci_release_child_resources(bus, r); + if (!release_resource(r)) { type = old_flags = r->flags & PCI_RES_TYPE_MASK; pci_info(dev, "resource %d %pR released\n", From patchwork Fri Dec 18 17:39:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982643 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 EC38DC2D0E4 for ; Fri, 18 Dec 2020 17:42:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C151C23B5D for ; Fri, 18 Dec 2020 17:42:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732636AbgLRRmd (ORCPT ); Fri, 18 Dec 2020 12:42:33 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38566 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728091AbgLRRmc (ORCPT ); Fri, 18 Dec 2020 12:42:32 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id B41DA413E4; Fri, 18 Dec 2020 17:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313270; x=1610127671; bh=p5ojM85KzuWw1dn9l+gXPAqRVLagkNKnmBV ORTqlbZE=; b=OY31YfUjLhcfhtdd//+0ypfwU582Op4Er9rZs90hmLIFeUrB7WB y+t92Yu42Hf5ekeeoiEOXseaIC+FgsFXsCjnRGnRQsvel2QBZPxgkgD2hSz/MZLt iwxadU07nppfZjQ9/+GOoM0xAYRJJ4eM/pKZ1q4NyXShiMpwOQ9AiceQ= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xHt6f202nBdK; Fri, 18 Dec 2020 20:41:10 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 8B67A41395; Fri, 18 Dec 2020 20:41:07 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:06 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 05/26] PCI: hotplug: Fix reassigning the released BARs Date: Fri, 18 Dec 2020 20:39:50 +0300 Message-ID: <20201218174011.340514-6-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Bridge windows are temporarily released during a PCI rescan, and their old sizes are not relevant anymore as they will be recreated in pbus_size_*() from scratch. So don't keep it, but instead set to zero after release. If BAR assignment fails after a PCI hotplug event, the kernel will retry with a fall-back reduced configuration, so don't apply reset_resource() for non-window BARs to keep them valid for the next attempt. Signed-off-by: Sergei Miroshnichenko --- drivers/pci/setup-bus.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index bc342eaa98e8..a956f0179064 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -297,7 +297,9 @@ static void assign_requested_resources_sorted(struct list_head *head, 0 /* don't care */, 0 /* don't care */); } - reset_resource(res); + if (!pci_can_move_bars || + idx >= PCI_BRIDGE_RESOURCES) + reset_resource(res); } } } @@ -1616,8 +1618,8 @@ static void pci_bridge_release_resources(struct pci_bus *bus, type = old_flags = r->flags & PCI_RES_TYPE_MASK; pci_info(dev, "resource %d %pR released\n", PCI_BRIDGE_RESOURCES + idx, r); - /* Keep the old size */ - r->end = resource_size(r) - 1; + /* Don't keep the old size if the bridge will be recalculated */ + r->end = pci_can_move_bars ? 0 : (resource_size(r) - 1); r->start = 0; r->flags = 0; From patchwork Fri Dec 18 17:39:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982641 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 D2D76C4361B for ; Fri, 18 Dec 2020 17:42:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A9F1223B54 for ; Fri, 18 Dec 2020 17:42:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732521AbgLRRmc (ORCPT ); Fri, 18 Dec 2020 12:42:32 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38564 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728170AbgLRRmc (ORCPT ); Fri, 18 Dec 2020 12:42:32 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 2B60D413E5; Fri, 18 Dec 2020 17:41:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313270; x=1610127671; bh=Z9kVDFLlZ52UtEZ8/9sp4eIfSGUfuRMei10 Uu3B/fzM=; b=vDz/n3EBrSeO/fU48olYfx5lxY5tzL6UFG+SD5Gz1M6THaz59l1 F8hjoF776btQywW/RCfX571sDZstZxw1isekWC44WhWGAkUpdlTd/SQ8NbRenxgf bOcmw2L7RZRy9KZCkr8Tuu6B/WLIG5MStrlp2b4x9bPd0a47CpUj3ahA= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uFmdna4VGagu; Fri, 18 Dec 2020 20:41:10 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 91BDC413AB; Fri, 18 Dec 2020 20:41:07 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:06 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 06/26] PCI: hotplug: Recalculate every bridge window during rescan Date: Fri, 18 Dec 2020 20:39:51 +0300 Message-ID: <20201218174011.340514-7-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org When the movable BARs feature is enabled and a rescan has been requested, release all bridge windows and recalculate them from scratch, taking into account all kinds of BARs: fixed, movable, new. Comparing to simply trying to expand bridge windows, this also employs the PCI ability to shuffle BARs within a bridge, increasing the chances to find a memory space to fit BARs of newly hot-added devices, especially if no (or not enough) gaps were reserved. The last step of writing the recalculated windows to the bridges is done by the new pci_setup_bridges() function. Signed-off-by: Sergei Miroshnichenko --- drivers/pci/pci.h | 1 + drivers/pci/probe.c | 22 ++++++++++++++++++++++ drivers/pci/setup-bus.c | 9 +++++++++ 3 files changed, 32 insertions(+) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index c962d0375074..dc7f40b42fa7 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -267,6 +267,7 @@ void __pci_bus_assign_resources(const struct pci_bus *bus, struct list_head *realloc_head, struct list_head *fail_head); bool pci_bus_clip_resource(struct pci_dev *dev, int idx); +void pci_bus_release_root_bridge_resources(struct pci_bus *bus); void pci_reassigndev_resource_alignment(struct pci_dev *dev); void pci_disable_bridge_window(struct pci_dev *dev); diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 17dd1fa4a05a..47d28761339b 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -3283,6 +3283,25 @@ static void pci_bus_rescan_done(struct pci_bus *bus) } } +static void pci_setup_bridges(struct pci_bus *bus) +{ + struct pci_dev *dev; + + list_for_each_entry(dev, &bus->devices, bus_list) { + struct pci_bus *child; + + if (!pci_dev_is_added(dev)) + continue; + + child = dev->subordinate; + if (child) + pci_setup_bridges(child); + } + + if (bus->self) + pci_setup_bridge(bus); +} + /** * pci_rescan_bus - Scan a PCI bus for devices * @bus: PCI bus to scan @@ -3304,8 +3323,11 @@ unsigned int pci_rescan_bus(struct pci_bus *bus) pci_bus_rescan_prepare(root); max = pci_scan_child_bus(root); + + pci_bus_release_root_bridge_resources(root); pci_assign_unassigned_root_bus_resources(root); + pci_setup_bridges(root); pci_bus_rescan_done(root); } else { max = pci_scan_child_bus(bus); diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index a956f0179064..9eb982196422 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1673,6 +1673,15 @@ static void pci_bus_release_bridge_resources(struct pci_bus *bus, pci_bridge_release_resources(bus, type); } +void pci_bus_release_root_bridge_resources(struct pci_bus *root_bus) +{ + pci_bus_release_bridge_resources(root_bus, IORESOURCE_IO, whole_subtree); + pci_bus_release_bridge_resources(root_bus, IORESOURCE_MEM, whole_subtree); + pci_bus_release_bridge_resources(root_bus, + IORESOURCE_MEM_64 | IORESOURCE_PREFETCH, + whole_subtree); +} + static void pci_bus_dump_res(struct pci_bus *bus) { struct resource *res; From patchwork Fri Dec 18 17:39:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982657 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 9A35AC35270 for ; Fri, 18 Dec 2020 17:42:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 756E3239EE for ; Fri, 18 Dec 2020 17:42:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733005AbgLRRmh (ORCPT ); Fri, 18 Dec 2020 12:42:37 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38568 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728319AbgLRRmg (ORCPT ); Fri, 18 Dec 2020 12:42:36 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 609A6413EC; Fri, 18 Dec 2020 17:41:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313271; x=1610127672; bh=Ppyz9abS1N0rxJcKAQZnWhUyrLyQJ496Tfx 6bo3ozYg=; b=SFLQplKkV5DkFjK21QxPPGnlopinyqXdLd7B7ZjLAqq6Kw4pb6X ISv5biEpOSebG3CPQ4PVWvVE5saY/X+HvCXK3KVK8cd09tyvmewD7xApLE76+1Qu yYK1oRmE+gRp1hn8RCeJgZHXVxBpql4I05H99nCDl70YOvy8Er7yQ7ik= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oudUoMBm-mUD; Fri, 18 Dec 2020 20:41:11 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 97DA4413B0; Fri, 18 Dec 2020 20:41:07 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:06 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 07/26] PCI: hotplug: Don't allow hot-added devices to steal resources Date: Fri, 18 Dec 2020 20:39:52 +0300 Message-ID: <20201218174011.340514-8-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org When movable BARs are enabled, the PCI subsystem at first releases all the bridge windows and then attempts to assign resources both to previously working devices and to the newly hot-added ones, with the same priority. If a hot-added device gets its BARs first, this may lead to lack of space for already working devices, which is unacceptable. If that happens, mark one of the new devices with the newly introduced flag PCI_DEV_DISABLED_BARS (if it is not yet marked) and retry the BAR recalculation. The worst case would be no BARs for hot-added devices, while all the rest just continue working. The algorithm is simple and it doesn't retry different subsets of hot-added devices in case of a failure, e.g. if there are no space to allocate BARs for both hot-added devices A and B, but is enough for just A, the A will be marked with PCI_DEV_DISABLED_BARS first, then (after the next failure) - B. As a result, A will not get BARs while it could. This issue is only relevant when hot-adding two and more devices simultaneously. Add a new res_mask bitmask to the struct pci_dev for storing the indices of assigned BARs. When preparing to the next rescan, all PCI_DEV_DISABLED_BARS marks are unset, so the kernel can retry to assign previously failed BARs. Before a rescan, some working devices may have assigned only part of their BARs - for example, if BIOS didn't allocate them. With this patch, the kernel assigns BARs in three steps: - first try every BAR, even those that weren't assigned before; - if that fails, retry without those failed BARs; - if that fails, retry without one of hotplugged devices. Signed-off-by: Sergei Miroshnichenko --- drivers/pci/pci.h | 3 + drivers/pci/probe.c | 177 +++++++++++++++++++++++++++++++++++++++- drivers/pci/setup-bus.c | 6 +- drivers/pci/setup-res.c | 2 + include/linux/pci.h | 1 + 5 files changed, 186 insertions(+), 3 deletions(-) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index dc7f40b42fa7..1668b1f45133 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -275,6 +275,8 @@ struct pci_bus *pci_bus_get(struct pci_bus *bus); void pci_bus_put(struct pci_bus *bus); bool pci_dev_bar_fixed(struct pci_dev *dev, struct resource *res); +bool pci_dev_bar_enabled(const struct pci_dev *dev, int idx); +bool pci_bus_check_bars_assigned(struct pci_bus *bus, bool complete_set); /* PCIe link information from Link Capabilities 2 */ #define PCIE_LNKCAP2_SLS2SPEED(lnkcap2) \ @@ -395,6 +397,7 @@ static inline bool pci_dev_is_disconnected(const struct pci_dev *dev) /* pci_dev priv_flags */ #define PCI_DEV_ADDED 0 +#define PCI_DEV_DISABLED_BARS 1 static inline void pci_dev_assign_added(struct pci_dev *dev, bool added) { diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 47d28761339b..294e8f262c7f 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -35,6 +35,13 @@ static struct resource busn_resource = { LIST_HEAD(pci_root_buses); EXPORT_SYMBOL(pci_root_buses); +/* + * This flag is used during pci_rescan_bus(), protected by pci_rescan_remove_lock: + * it indicates which BARs should be reassigned: every one, or only those which + * were assigned before the rescan. + */ +static bool pci_try_failed_bars = true; + static LIST_HEAD(pci_domain_busn_res_list); struct pci_domain_busn_res { @@ -43,6 +50,41 @@ struct pci_domain_busn_res { int domain_nr; }; +static void pci_dev_disable_bars(struct pci_dev *dev) +{ + assign_bit(PCI_DEV_DISABLED_BARS, &dev->priv_flags, true); +} + +static void pci_dev_enable_bars(struct pci_dev *dev) +{ + assign_bit(PCI_DEV_DISABLED_BARS, &dev->priv_flags, false); +} + +static bool pci_dev_bars_enabled(const struct pci_dev *dev) +{ + if (pci_try_failed_bars) + return true; + + return !(test_bit(PCI_DEV_DISABLED_BARS, &dev->priv_flags)); +} + +bool pci_dev_bar_enabled(const struct pci_dev *dev, int idx) +{ + if (idx >= PCI_BRIDGE_RESOURCES) + return true; + + if (pci_try_failed_bars) + return true; + + if (test_bit(PCI_DEV_DISABLED_BARS, &dev->priv_flags)) + return false; + + if (!pci_dev_is_added(dev)) + return true; + + return dev->res_mask & (1 << idx); +} + static struct resource *get_pci_domain_busn_res(int domain_nr) { struct pci_domain_busn_res *r; @@ -3237,6 +3279,24 @@ bool pci_dev_bar_fixed(struct pci_dev *dev, struct resource *res) return true; } +static unsigned int pci_dev_count_res_mask(struct pci_dev *dev) +{ + unsigned int res_mask = 0; + int i; + + for (i = 0; i < PCI_BRIDGE_RESOURCES; i++) { + struct resource *r = &dev->resource[i]; + + if (!r->flags || !r->parent || + (r->flags & IORESOURCE_UNSET)) + continue; + + res_mask |= (1 << i); + } + + return res_mask; +} + static void pci_bus_rescan_prepare(struct pci_bus *bus) { struct pci_dev *dev; @@ -3249,6 +3309,9 @@ static void pci_bus_rescan_prepare(struct pci_bus *bus) list_for_each_entry(dev, &bus->devices, bus_list) { struct pci_bus *child = dev->subordinate; + dev->res_mask = pci_dev_count_res_mask(dev); + pci_dev_enable_bars(dev); + if (child) pci_bus_rescan_prepare(child); @@ -3302,6 +3365,118 @@ static void pci_setup_bridges(struct pci_bus *bus) pci_setup_bridge(bus); } +static struct pci_dev *pci_find_next_new_device(struct pci_bus *bus) +{ + struct pci_dev *dev; + + if (!bus) + return NULL; + + list_for_each_entry(dev, &bus->devices, bus_list) { + struct pci_bus *child_bus = dev->subordinate; + + if (child_bus) { + struct pci_dev *next_new_dev; + + next_new_dev = pci_find_next_new_device(child_bus); + if (next_new_dev) + return next_new_dev; + } + + if (!pci_dev_is_added(dev) && pci_dev_bars_enabled(dev)) + return dev; + } + + return NULL; +} + +/** + * pci_bus_check_bars_assigned - check BARs under the bridge + * @bus: Parent PCI bus + * @complete_set: check every BAR, otherwise only those assigned before + * + * Returns true if every BAR is assigned. + */ +bool pci_bus_check_bars_assigned(struct pci_bus *bus, bool complete_set) +{ + struct pci_dev *dev; + bool good = true; + + if (!bus) + return false; + + list_for_each_entry(dev, &bus->devices, bus_list) { + struct pci_bus *child = dev->subordinate; + + if (complete_set) { + int i; + + for (i = 0; i < PCI_BRIDGE_RESOURCES; ++i) { + struct resource *r = &dev->resource[i]; + + if (!(r->flags & IORESOURCE_UNSET)) + continue; + + pci_warn(dev, "BAR %d: requested but not assigned: %pR\n", + i, r); + good = false; + } + } else { + unsigned int res_mask; + + if (!pci_dev_bars_enabled(dev)) + continue; + + res_mask = pci_dev_count_res_mask(dev); + + if (dev->res_mask & ~res_mask) { + pci_err(dev, "Non-re-enabled resources found: 0x%x -> 0x%x\n", + dev->res_mask, res_mask); + good = false; + } + } + + if (child && !pci_bus_check_bars_assigned(child, complete_set)) + good = false; + } + + return good; +} + +static void pci_reassign_root_bus_resources(struct pci_bus *root) +{ + do { + struct pci_dev *next_new_dev; + + pci_assign_unassigned_root_bus_resources(root); + + if (pci_bus_check_bars_assigned(root, pci_try_failed_bars)) + break; + + if (pci_try_failed_bars) { + dev_warn(&root->dev, "failed to assign all BARs, retry without those failed before\n"); + + pci_bus_release_root_bridge_resources(root); + pci_try_failed_bars = false; + continue; + } + + next_new_dev = pci_find_next_new_device(root); + if (!next_new_dev) { + dev_err(&root->dev, "failed to reassign BARs even after ignoring all the hot-added devices, reload the kernel with pci=no_movable_bars\n"); + break; + } + + dev_warn(&root->dev, "failed to reassign BARs, disable the next hot-added device %s and retry\n", + dev_name(&next_new_dev->dev)); + + pci_dev_disable_bars(next_new_dev); + pci_bus_release_root_bridge_resources(root); + } while (true); + + pci_try_failed_bars = true; +} + /** * pci_rescan_bus - Scan a PCI bus for devices * @bus: PCI bus to scan @@ -3325,7 +3500,7 @@ unsigned int pci_rescan_bus(struct pci_bus *bus) max = pci_scan_child_bus(root); pci_bus_release_root_bridge_resources(root); - pci_assign_unassigned_root_bus_resources(root); + pci_reassign_root_bus_resources(root); pci_setup_bridges(root); pci_bus_rescan_done(root); diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 9eb982196422..e2e253815454 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -141,7 +141,7 @@ static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head) if (r->flags & IORESOURCE_PCI_FIXED) continue; - if (!(r->flags) || r->parent) + if (!(r->flags) || r->parent || !pci_dev_bar_enabled(dev, i)) continue; r_align = pci_resource_alignment(dev, r); @@ -903,7 +903,8 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size, struct resource *r = &dev->resource[i]; unsigned long r_size; - if (r->parent || !(r->flags & IORESOURCE_IO)) + if (r->parent || !(r->flags & IORESOURCE_IO) || + !pci_dev_bar_enabled(dev, i)) continue; r_size = resource_size(r); @@ -1023,6 +1024,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, resource_size_t r_size; if (r->parent || (r->flags & IORESOURCE_PCI_FIXED) || + !pci_dev_bar_enabled(dev, i) || ((r->flags & mask) != type && (r->flags & mask) != type2 && (r->flags & mask) != type3)) diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index 43eda101fcf4..432f3b084f94 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c @@ -474,6 +474,8 @@ int pci_enable_resources(struct pci_dev *dev, int mask) if ((i == PCI_ROM_RESOURCE) && (!(r->flags & IORESOURCE_ROM_ENABLE))) continue; + if (!pci_dev_bar_enabled(dev, i)) + continue; if (r->flags & IORESOURCE_UNSET) { pci_err(dev, "can't enable device: BAR %d %pR not assigned\n", diff --git a/include/linux/pci.h b/include/linux/pci.h index 8a7033b240f1..29310f026eb7 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -401,6 +401,7 @@ struct pci_dev { */ unsigned int irq; struct resource resource[DEVICE_COUNT_RESOURCE]; /* I/O and memory regions + expansion ROMs */ + unsigned int res_mask; /* Bitmask of assigned resources */ bool match_driver; /* Skip attaching driver */ From patchwork Fri Dec 18 17:39:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982645 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 18C35C3526B for ; Fri, 18 Dec 2020 17:42:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D7D5323B54 for ; Fri, 18 Dec 2020 17:42:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732915AbgLRRmd (ORCPT ); Fri, 18 Dec 2020 12:42:33 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38570 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728403AbgLRRmd (ORCPT ); Fri, 18 Dec 2020 12:42:33 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 5D93D413EB; Fri, 18 Dec 2020 17:41:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313272; x=1610127673; bh=dvl7cddgkL1y7EPOt3GbUC/MPhpqFWegKCz MyctzpO4=; b=aJvfarybsIUaD11NoPW0bAEGLfliM/shA6tNLL7O6eJCEGPBl4f hPD1ZnJWT8vKBzVbEMfIe9uBHcIiq3Siy7V2mOEBg85zeNOmjQuNDQRQdki8H1Pv hl5V99Gk1Vt1yJ0d+/zvZSlIoQuVR84jjJnSr0/HAEb+ZFIo9iWJO35U= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vaSdaceijxvY; Fri, 18 Dec 2020 20:41:12 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 9F94C41393; Fri, 18 Dec 2020 20:41:07 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:07 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 08/26] PCI: Reassign BARs if BIOS/bootloader had assigned not all of them Date: Fri, 18 Dec 2020 20:39:53 +0300 Message-ID: <20201218174011.340514-9-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Some BIOSes don't allocate all requested BARs, leaving some (for example, SR_IOV) unassigned, without gaps for bridge windows to extend. If that happens, let the kernel use its own methods of BAR allocating on an early init stage, when drivers aren't yet bound to their devices, and it is safe to shuffle BARs that are not yet used. If the reassignment fails, retry without BARs omitted by BIOS, they have the IORESOURCE_UNSET flag being set. To use this property, a new bool was introduced: pci_init_done. Signed-off-by: Sergei Miroshnichenko --- drivers/pci/pci.h | 2 ++ drivers/pci/probe.c | 3 ++- drivers/pci/setup-bus.c | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 1668b1f45133..62c3eb146348 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -278,6 +278,8 @@ bool pci_dev_bar_fixed(struct pci_dev *dev, struct resource *res); bool pci_dev_bar_enabled(const struct pci_dev *dev, int idx); bool pci_bus_check_bars_assigned(struct pci_bus *bus, bool complete_set); +extern bool pci_init_done; + /* PCIe link information from Link Capabilities 2 */ #define PCIE_LNKCAP2_SLS2SPEED(lnkcap2) \ ((lnkcap2) & PCI_EXP_LNKCAP2_SLS_64_0GB ? PCIE_SPEED_64_0GT : \ diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 294e8f262c7f..f6e2216ce996 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -41,6 +41,7 @@ EXPORT_SYMBOL(pci_root_buses); * were assigned before the rescan. */ static bool pci_try_failed_bars = true; +bool pci_init_done; static LIST_HEAD(pci_domain_busn_res_list); @@ -3288,7 +3289,7 @@ static unsigned int pci_dev_count_res_mask(struct pci_dev *dev) struct resource *r = &dev->resource[i]; if (!r->flags || !r->parent || - (r->flags & IORESOURCE_UNSET)) + (pci_init_done && (r->flags & IORESOURCE_UNSET))) continue; res_mask |= (1 << i); diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index e2e253815454..a69415348684 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1919,7 +1919,14 @@ void __init pci_assign_unassigned_resources(void) /* Make sure the root bridge has a companion ACPI device */ if (ACPI_HANDLE(root_bus->bridge)) acpi_ioapic_add(ACPI_HANDLE(root_bus->bridge)); + + if (pci_can_move_bars && !pci_bus_check_bars_assigned(root_bus, true)) { + dev_err(&root_bus->dev, "Not all requested BARs are assigned, triggering a rescan with movable BARs"); + pci_rescan_bus(root_bus); + } } + + pci_init_done = true; } static void adjust_bridge_window(struct pci_dev *bridge, struct resource *res, From patchwork Fri Dec 18 17:39:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982649 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 337D6C3526C for ; Fri, 18 Dec 2020 17:42:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 06BEB23B5D for ; Fri, 18 Dec 2020 17:42:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732918AbgLRRmd (ORCPT ); Fri, 18 Dec 2020 12:42:33 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38573 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731531AbgLRRmd (ORCPT ); Fri, 18 Dec 2020 12:42:33 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 73A33413B0; Fri, 18 Dec 2020 17:41:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313273; x=1610127674; bh=Kf9+in/lW6DwQRavoksG7+6o/Fg4g9RDKTl cP+A4a6I=; b=GXAk/qx/OFbZaRFV9iLcXJdueEJY1FUyUPfm2FlUxpmMAOUhRKa ws2THX0Z0MFr7ZXjQV0w0+PC7wL/7owexGfHtDFktEJjo2YP9Ns8OOC/Trh57UNT XXbYDkK0M3YdtSM5uGLXXTbWhRfoLYvA3JiFNc2qNC6l6sh9Xj1Akp2U= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uwZoVP6RtjHj; Fri, 18 Dec 2020 20:41:13 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id A6BA7413B1; Fri, 18 Dec 2020 20:41:07 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:07 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 09/26] PCI: Movable BARs: Make just a single attempt to assign bridge resources Date: Fri, 18 Dec 2020 20:39:54 +0300 Message-ID: <20201218174011.340514-10-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org With enabled BAR movement, all BARs and bridge windows are released at the beginning of a reassign procedure, not just part of them. In this case only one pass is enough, no need for several traverses. In case of failures the pci_reassign_root_bus_resources() disables BARs for one of the hot-added devices and retries the single-step assignment. Signed-off-by: Sergei Miroshnichenko --- drivers/pci/setup-bus.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index a69415348684..640090046ffd 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1826,6 +1826,13 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus) int pci_try_num = 1; enum enable_type enable_local; + if (pci_can_move_bars) { + __pci_bus_size_bridges(bus, NULL); + __pci_bus_assign_resources(bus, NULL, NULL); + + goto dump; + } + /* Don't realloc if asked to do so */ enable_local = pci_realloc_detect(bus, pci_realloc_enable); if (pci_realloc_enabled(enable_local)) { From patchwork Fri Dec 18 17:39:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982647 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 45FF4C2BBD5 for ; Fri, 18 Dec 2020 17:42:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2854623B54 for ; Fri, 18 Dec 2020 17:42:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732961AbgLRRme (ORCPT ); Fri, 18 Dec 2020 12:42:34 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38572 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728459AbgLRRme (ORCPT ); Fri, 18 Dec 2020 12:42:34 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id CD01A413B1; Fri, 18 Dec 2020 17:41:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313273; x=1610127674; bh=bDzqp0BBGc4/Y3MuPxfFMBMUcFW7A4gCY+x s8xtCoWY=; b=EqSfidL7KtFdpo8CZqIoUCSjglrzKquoKCO38dFtY66oW1oMmeo +eqsNBJtvtO2tio2GLdwwzJd808DV2qDeLWiarX2WrJb6uZHcvHE0TIzxzfLkMP2 yDvulq2GH2PC2qV7AxkYEU4jG+qlIEqL+x3aBV9rwhOKqSK1InYSlb3w= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OmMlo1ZNYM5l; Fri, 18 Dec 2020 20:41:13 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id BC0F0413B3; Fri, 18 Dec 2020 20:41:07 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:07 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 10/26] PCI: hotplug: Calculate fixed parts of bridge windows Date: Fri, 18 Dec 2020 20:39:55 +0300 Message-ID: <20201218174011.340514-11-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org When movable BARs are enabled, and if a bridge contains a device with fixed BARs, the corresponding windows can't be moved too far away from their original positions - they must still contain all the fixed BARs, like that: 1) Window position before a bus rescan: | <------ root bridge window ------> | | | | | <-- bridge window --> | | | | movable BARs | **fixed BAR** | | ^^^^^^^^^^^^ 2) A possible valid outcome after a rescan and being moved: | <------ root bridge window ------> | | | | | <-- bridge window --> | | | | **fixed BAR** | Movable BARs | | ^^^^^^^^^^^^ A fixed area of a bridge window is a range that covers all the fixed BARs of direct children, and all the fixed area of children bridges: | <------ root bridge window ------> | | | | | <------ bridge window level 1 ------> | | | | ********************** fixed area ******************** | | | | | | | | **fixed BAR** | <--- bridge window level 2 ---> | BARs | | | | | ************* fixed area ************* | | | | | | | | | | | | **fixed BAR** | BARs | **fixed BAR** | | | ^^^^ To store these areas, the .fixed_range field has been added to the struct pci_bus for every bridge window type: IO, MEM and PREFETCH. They are filled recursively from leaves to the root before a rescan. Signed-off-by: Sergei Miroshnichenko --- drivers/pci/pci.h | 23 ++++++++++++ drivers/pci/probe.c | 89 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 6 +++ 3 files changed, 118 insertions(+) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 62c3eb146348..f47f80b6a620 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -278,6 +278,17 @@ bool pci_dev_bar_fixed(struct pci_dev *dev, struct resource *res); bool pci_dev_bar_enabled(const struct pci_dev *dev, int idx); bool pci_bus_check_bars_assigned(struct pci_bus *bus, bool complete_set); +static inline void pci_set_fixed_range(struct resource *res) +{ + res->start = (resource_size_t)-1; + res->end = 0; +} + +static inline bool pci_fixed_range_valid(struct resource *res) +{ + return res->start <= res->end; +} + extern bool pci_init_done; /* PCIe link information from Link Capabilities 2 */ @@ -397,6 +408,18 @@ static inline bool pci_dev_is_disconnected(const struct pci_dev *dev) return dev->error_state == pci_channel_io_perm_failure; } +static inline int pci_get_bridge_resource_idx(struct resource *r) +{ + if (r->flags & IORESOURCE_IO) + return 0; + else if (!(r->flags & IORESOURCE_PREFETCH)) + return 1; + else if (r->flags & IORESOURCE_MEM_64) + return 2; + + return 1; +} + /* pci_dev priv_flags */ #define PCI_DEV_ADDED 0 #define PCI_DEV_DISABLED_BARS 1 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index f6e2216ce996..964dfa71af22 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -589,6 +589,7 @@ void pci_read_bridge_bases(struct pci_bus *child) static struct pci_bus *pci_alloc_bus(struct pci_bus *parent) { struct pci_bus *b; + int idx; b = kzalloc(sizeof(*b), GFP_KERNEL); if (!b) @@ -605,6 +606,13 @@ static struct pci_bus *pci_alloc_bus(struct pci_bus *parent) if (parent) b->domain_nr = parent->domain_nr; #endif + for (idx = 0; idx < PCI_BRIDGE_RESOURCE_NUM; ++idx) + pci_set_fixed_range(&b->fixed_range[idx]); + + b->fixed_range[0].flags = IORESOURCE_IO; + b->fixed_range[1].flags = IORESOURCE_MEM; + b->fixed_range[2].flags = IORESOURCE_MEM | IORESOURCE_PREFETCH; + return b; } @@ -3366,6 +3374,86 @@ static void pci_setup_bridges(struct pci_bus *bus) pci_setup_bridge(bus); } +static void pci_bus_update_fixed_range(struct pci_bus *bus) +{ + struct pci_dev *dev; + int idx; + resource_size_t start, end; + + for (idx = 0; idx < PCI_BRIDGE_RESOURCE_NUM; ++idx) + pci_set_fixed_range(&bus->fixed_range[idx]); + + list_for_each_entry(dev, &bus->devices, bus_list) + if (dev->subordinate) + pci_bus_update_fixed_range(dev->subordinate); + + list_for_each_entry(dev, &bus->devices, bus_list) { + int i; + struct pci_bus *child = dev->subordinate; + + for (i = 0; i < PCI_BRIDGE_RESOURCES; ++i) { + struct resource *r = &dev->resource[i]; + struct resource *fixed_range; + + if (!r->flags || (r->flags & IORESOURCE_UNSET) || + !r->parent || !pci_dev_bar_fixed(dev, r)) + continue; + + idx = pci_get_bridge_resource_idx(r); + fixed_range = &bus->fixed_range[idx]; + start = fixed_range->start; + end = fixed_range->end; + + if (!pci_fixed_range_valid(fixed_range) || + start > r->start) + start = r->start; + + if (end < r->end) + end = r->end; + + if (fixed_range->start != start || + fixed_range->end != end) { + fixed_range->start = start; + fixed_range->end = end; + dev_dbg(&bus->dev, "Found fixed BAR %d %pR in %s, expand the fixed bridge window %d to %pR\n", + i, r, dev_name(&dev->dev), idx, + fixed_range); + } + } + + if (child) { + for (idx = 0; idx < PCI_BRIDGE_RESOURCE_NUM; ++idx) { + struct resource *fixed_range = &bus->fixed_range[idx]; + struct resource *child_fixed_range = + &child->fixed_range[idx]; + + if (!pci_fixed_range_valid(child_fixed_range)) + continue; + + start = fixed_range->start; + end = fixed_range->end; + + if (!pci_fixed_range_valid(fixed_range) || + start > child_fixed_range->start) + start = child_fixed_range->start; + + if (end < child_fixed_range->end) + end = child_fixed_range->end; + + if (start < fixed_range->start || + end > fixed_range->end) { + dev_dbg(&bus->dev, "Expand the fixed bridge window %d from %s to 0x%llx-0x%llx\n", + idx, dev_name(&child->dev), + (unsigned long long)start, + (unsigned long long)end); + fixed_range->start = start; + fixed_range->end = end; + } + } + } + } +} + static struct pci_dev *pci_find_next_new_device(struct pci_bus *bus) { struct pci_dev *dev; @@ -3497,6 +3585,7 @@ unsigned int pci_rescan_bus(struct pci_bus *bus) if (pci_can_move_bars) { pci_bus_rescan_prepare(root); + pci_bus_update_fixed_range(root); max = pci_scan_child_bus(root); diff --git a/include/linux/pci.h b/include/linux/pci.h index 29310f026eb7..def6b275d5ad 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -622,6 +622,12 @@ struct pci_bus { struct list_head resources; /* Address space routed to this bus */ struct resource busn_res; /* Bus numbers routed to this bus */ + /* + * If there are fixed resources in the bridge window, this range contains + * the lowest start address and the highest end address of them. + */ + struct resource fixed_range[PCI_BRIDGE_RESOURCE_NUM]; + struct pci_ops *ops; /* Configuration access functions */ struct msi_controller *msi; /* MSI controller */ void *sysdata; /* Hook for sys-specific extension */ From patchwork Fri Dec 18 17:39:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982653 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 58561C3526E for ; Fri, 18 Dec 2020 17:42:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3F94E23B5D for ; Fri, 18 Dec 2020 17:42:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732994AbgLRRmg (ORCPT ); Fri, 18 Dec 2020 12:42:36 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38578 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731531AbgLRRmg (ORCPT ); Fri, 18 Dec 2020 12:42:36 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id B5B8F413ED; Fri, 18 Dec 2020 17:41:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313274; x=1610127675; bh=zjewFlS8iSFSK0HyEJh9bkkMelhEy1KUPYf eiAbNkMk=; b=KGD1sxQYogCuy/K1W0aeRv/FPret59Uzc0Qp6pPWcwpBv1YdJkB fqXQeb1eQ9c7sHrJeCRXW3owA4c7zztn5tmd4p9xWJr2Y/KsJ/x7ELOkfSKvQY2c e8hypSOG97SGr7b3xOqvJXEUqPxRt4fjYqSu4Wdo8tiUbYZ36cF2IdoY= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id j4e6qikAwRNc; Fri, 18 Dec 2020 20:41:14 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 0782B413B5; Fri, 18 Dec 2020 20:41:08 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:07 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 11/26] PCI: Include fixed BARs into the bus size calculating Date: Fri, 18 Dec 2020 20:39:56 +0300 Message-ID: <20201218174011.340514-12-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The only difference between fixed and movable BARs is a size and offset preservation after they are released (the corresponding struct resource* is detached from a bridge window for a while during a bus rescan). So fixed BARs should not be skipped in pbus_size_{mem,io}(). Bridge window size calculation uses pci_{,sriov_}resource_alignment(), that are applicable only to not yet assigned BARs and don't make sense for fixed ones. Original alignment of a fixed BAR is lost after assignment, so return 1 in this case as a neutral value. A window should be additionally extended if it has distant fixed BARs on its edges: | <-- bridge window --> | | **fixed BAR** | | **fixed BAR** | Signed-off-by: Sergei Miroshnichenko --- drivers/pci/iov.c | 2 ++ drivers/pci/pci.h | 2 ++ drivers/pci/setup-bus.c | 21 ++++++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 4afd4ee4f7f0..f4f7c2702579 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -872,6 +872,8 @@ resource_size_t __weak pcibios_iov_resource_alignment(struct pci_dev *dev, */ resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno) { + if (pci_dev_bar_fixed(dev, dev->resource + resno)) + return 1; return pcibios_iov_resource_alignment(dev, resno); } diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index f47f80b6a620..f7460ddd196a 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -576,6 +576,8 @@ static inline resource_size_t pci_resource_alignment(struct pci_dev *dev, if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END) return pci_sriov_resource_alignment(dev, resno); #endif + if (pci_dev_bar_fixed(dev, res)) + return 1; if (dev->class >> 8 == PCI_CLASS_BRIDGE_CARDBUS) return pci_cardbus_resource_alignment(res); return resource_alignment(res); diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 640090046ffd..3dadadea10d6 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -888,9 +888,15 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size, resource_size_t children_add_size = 0; resource_size_t min_align, align; + struct resource *fixed_range; + resource_size_t fixed_size; + if (!b_res) return; + fixed_range = &bus->fixed_range[0]; + fixed_size = pci_fixed_range_valid(fixed_range) ? resource_size(fixed_range) : 0; + /* If resource is already assigned, nothing more to do */ if (b_res->parent) return; @@ -923,6 +929,9 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size, } } + if (size1 < fixed_size) + size1 = fixed_size; + size0 = calculate_iosize(size, min_size, size1, 0, 0, resource_size(b_res), min_align); size1 = (!realloc_head || (realloc_head && !add_size && !children_add_size)) ? size0 : @@ -1004,6 +1013,9 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, resource_size_t children_add_size = 0; resource_size_t children_add_align = 0; resource_size_t add_align = 0; + int idx; + struct resource *fixed_range; + resource_size_t fixed_size; if (!b_res) return -ENOSPC; @@ -1012,6 +1024,13 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, if (b_res->parent) return 0; + idx = pci_get_bridge_resource_idx(b_res); + fixed_range = &bus->fixed_range[idx]; + fixed_size = pci_fixed_range_valid(fixed_range) ? resource_size(fixed_range) : 0; + + if (min_size < fixed_size) + min_size = fixed_size; + memset(aligns, 0, sizeof(aligns)); max_order = 0; size = 0; @@ -1023,7 +1042,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, struct resource *r = &dev->resource[i]; resource_size_t r_size; - if (r->parent || (r->flags & IORESOURCE_PCI_FIXED) || + if (r->parent || !pci_dev_bar_enabled(dev, i) || ((r->flags & mask) != type && (r->flags & mask) != type2 && From patchwork Fri Dec 18 17:39:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982651 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 91F7FC3526D for ; Fri, 18 Dec 2020 17:42:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 54AFD23B54 for ; Fri, 18 Dec 2020 17:42:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732996AbgLRRmg (ORCPT ); Fri, 18 Dec 2020 12:42:36 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38576 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732931AbgLRRmg (ORCPT ); Fri, 18 Dec 2020 12:42:36 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 0E862413F1; Fri, 18 Dec 2020 17:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313274; x=1610127675; bh=T5Fkk6oGORAh4WFOfOZ1YgE9y1Rvi4Uvq20 28GCRRg0=; b=o5hYLCXFf+ljRJ6t1316LkRkk6823PrjHubbKcn/haTl6GZFPSw aeTYXjRVuHgJ9+nWJ5gpDORz3W7YtoddnmUCY11EUGSG3WO0pCF/6EdI+Dsl+az2 iHVyZwlacObKwDnhtpRIs4d+U83LTOrJBi38B5mCgnPF216FBmEKpp/M= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id chjP6ZLZcpyY; Fri, 18 Dec 2020 20:41:14 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 33290413B8; Fri, 18 Dec 2020 20:41:08 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:08 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 12/26] PCI: Make sure bridge windows include their fixed BARs Date: Fri, 18 Dec 2020 20:39:57 +0300 Message-ID: <20201218174011.340514-13-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org With enabled movable BARs, bridge windows are recalculated during each PCI rescan. There may be fixed BARs below a bridge: these areas are represented by the .fixed_range field in struct pci_bus. When choosing a start address for a bridge window, it should be not just a lowest possible address: this window must cover every underlying fixed BAR. If a size of the bridge window is equal to its fixed range, it can only be assigned to the start of this range. But if a bridge window size is larger, its lowest possible address equals to (fixed_range.end - bus_size + 1). Signed-off-by: Sergei Miroshnichenko --- drivers/pci/bus.c | 2 +- drivers/pci/setup-res.c | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 3cef835b375f..c716210b62c5 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -192,7 +192,7 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res, * this is an already-configured bridge window, its start * overrides "min". */ - if (avail.start) + if (min_used < avail.start) min_used = avail.start; max = avail.end; diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index 432f3b084f94..ee192e731119 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c @@ -247,11 +247,27 @@ static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev, int resno, resource_size_t size, resource_size_t align) { struct resource *res = dev->resource + resno; + struct resource *fixed_range = NULL; resource_size_t min; int ret; min = (res->flags & IORESOURCE_IO) ? PCIBIOS_MIN_IO : PCIBIOS_MIN_MEM; + if (pci_can_move_bars && dev->subordinate && resno >= PCI_BRIDGE_RESOURCES) { + struct pci_bus *child_bus = dev->subordinate; + int win_no = resno - PCI_BRIDGE_RESOURCES; + + fixed_range = &child_bus->fixed_range[win_no]; + if (pci_fixed_range_valid(fixed_range)) { + if (size <= resource_size(fixed_range)) + min = fixed_range->start; + else + min = fixed_range->end - size + 1; + } else { + fixed_range = NULL; + } + } + /* * First, try exact prefetching match. Even if a 64-bit * prefetchable bridge window is below 4GB, we can't put a 32-bit @@ -263,7 +279,7 @@ static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev, IORESOURCE_PREFETCH | IORESOURCE_MEM_64, pcibios_align_resource, dev); if (ret == 0) - return 0; + goto check_fixed; /* * If the prefetchable window is only 32 bits wide, we can put @@ -275,7 +291,7 @@ static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev, IORESOURCE_PREFETCH, pcibios_align_resource, dev); if (ret == 0) - return 0; + goto check_fixed; } /* @@ -288,6 +304,16 @@ static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev, ret = pci_bus_alloc_resource(bus, res, size, align, min, 0, pcibios_align_resource, dev); +check_fixed: + if (ret == 0 && fixed_range && + (res->start > fixed_range->start || + res->end < fixed_range->end)) { + dev_err(&bus->dev, "fixed area %pR for %s doesn't fit in the allocated %pR", + fixed_range, dev_name(&dev->dev), res); + release_resource(res); + return -1; + } + return ret; } From patchwork Fri Dec 18 17:39:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982659 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 AAA04C3526F for ; Fri, 18 Dec 2020 17:42:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8E90223B79 for ; Fri, 18 Dec 2020 17:42:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733009AbgLRRmh (ORCPT ); Fri, 18 Dec 2020 12:42:37 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38580 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732985AbgLRRmh (ORCPT ); Fri, 18 Dec 2020 12:42:37 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 06245413F6; Fri, 18 Dec 2020 17:41:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313275; x=1610127676; bh=fyaAplP259bXMQg284z40tJLExuGU1ZfPpZ M2BWBDGw=; b=pVeDUE///2lfgHAFE31d2AK5U55CkLtziYACr4BVUx9t8UcLMF+ qwyjQnu+TxXMB5LH++XT52GKhkNzElUHVuXTL6Z1MozEY+uHt0lwatyMOpLrahDU Pje7HKWRW1XRNDNvgUMPn8dr8QfET8B8+Aw405jZFUXOPlUEVzENIuFo= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zt-7b6M5sz3i; Fri, 18 Dec 2020 20:41:15 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 6773441385; Fri, 18 Dec 2020 20:41:08 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:08 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 13/26] PCI: hotplug: Add support of fixed BARs to pci_assign_resource() Date: Fri, 18 Dec 2020 20:39:58 +0300 Message-ID: <20201218174011.340514-14-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Fixed BARs must be assigned within a bridge window first, before movable BARs and neighboring bridge windows. Currently they are assigned last by pdev_assign_fixed_resources(). Let the fixed BARs be handled by pci_assign_resource() in the same way as it does for movable ones, assigning them in correct order, unifying the code. Allow matching IORESOURCE_PCI_FIXED prefetchable BARs to non-prefetchable windows, so they follow the same rules as non-flagged fixed BARs. Signed-off-by: Sergei Miroshnichenko --- drivers/pci/setup-bus.c | 43 ----------------------------------------- drivers/pci/setup-res.c | 41 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 45 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 3dadadea10d6..6055f15e3ac3 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1358,47 +1358,6 @@ void pci_bus_size_bridges(struct pci_bus *bus) } EXPORT_SYMBOL(pci_bus_size_bridges); -static void assign_fixed_resource_on_bus(struct pci_bus *b, struct resource *r) -{ - int i; - struct resource *parent_r; - unsigned long mask = IORESOURCE_IO | IORESOURCE_MEM | - IORESOURCE_PREFETCH; - - pci_bus_for_each_resource(b, parent_r, i) { - if (!parent_r) - continue; - - if ((r->flags & mask) == (parent_r->flags & mask) && - resource_contains(parent_r, r)) - request_resource(parent_r, r); - } -} - -/* - * Try to assign any resources marked as IORESOURCE_PCI_FIXED, as they are - * skipped by pbus_assign_resources_sorted(). - */ -static void pdev_assign_fixed_resources(struct pci_dev *dev) -{ - int i; - - for (i = 0; i < PCI_NUM_RESOURCES; i++) { - struct pci_bus *b; - struct resource *r = &dev->resource[i]; - - if (r->parent || !(r->flags & IORESOURCE_PCI_FIXED) || - !(r->flags & (IORESOURCE_IO | IORESOURCE_MEM))) - continue; - - b = dev->bus; - while (b && !r->parent) { - assign_fixed_resource_on_bus(b, r); - b = b->parent; - } - } -} - void __pci_bus_assign_resources(const struct pci_bus *bus, struct list_head *realloc_head, struct list_head *fail_head) @@ -1409,8 +1368,6 @@ void __pci_bus_assign_resources(const struct pci_bus *bus, pbus_assign_resources_sorted(bus, realloc_head, fail_head); list_for_each_entry(dev, &bus->devices, bus_list) { - pdev_assign_fixed_resources(dev); - b = dev->subordinate; if (!b) continue; diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index ee192e731119..6ffda8b94c52 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c @@ -333,14 +333,51 @@ static int _pci_assign_resource(struct pci_dev *dev, int resno, return ret; } +static int assign_fixed_resource_on_bus(struct pci_dev *dev, int resno) +{ + int i; + struct resource *parent_r; + unsigned long mask = IORESOURCE_TYPE_BITS; + struct resource *r = dev->resource + resno; + + /* + * If we have a shadow copy in RAM, the PCI device doesn't respond + * to the shadow range + */ + if (r->flags & IORESOURCE_ROM_SHADOW) + return 0; + + pci_bus_for_each_resource(dev->bus, parent_r, i) { + if (!parent_r) + continue; + + if ((r->flags & mask) != (parent_r->flags & mask)) + continue; + + if (parent_r->flags & IORESOURCE_PREFETCH && + !(r->flags & IORESOURCE_PREFETCH)) + continue; + + if (resource_contains(parent_r, r)) { + if (!request_resource(parent_r, r)) { + pci_info(dev, "BAR %d: assigned fixed %pR\n", resno, r); + return 0; + } + } + } + + pci_err(dev, "BAR %d: failed to assign fixed %pR\n", resno, r); + return -ENOSPC; +} + int pci_assign_resource(struct pci_dev *dev, int resno) { struct resource *res = dev->resource + resno; resource_size_t align, size; int ret; - if (res->flags & IORESOURCE_PCI_FIXED) - return 0; + if (res->flags && pci_dev_bar_fixed(dev, res)) + return assign_fixed_resource_on_bus(dev, resno); res->flags |= IORESOURCE_UNSET; align = pci_resource_alignment(dev, res); From patchwork Fri Dec 18 17:39:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982655 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 CD0A8C35273 for ; Fri, 18 Dec 2020 17:42:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8788239EE for ; Fri, 18 Dec 2020 17:42:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732985AbgLRRmj (ORCPT ); Fri, 18 Dec 2020 12:42:39 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38582 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732968AbgLRRmj (ORCPT ); Fri, 18 Dec 2020 12:42:39 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 567F7413FA; Fri, 18 Dec 2020 17:41:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313277; x=1610127678; bh=i1x3aD9KmgbJd+mdjxpBFj6MqGk6AnCXHtJ fYymmAU0=; b=Tt1uO8stbZOvI3Ac6OKYuXUgL0T+BffkP7nEvYUnGRrFI1ilK1R IijaQzLerFbRWJT7FRrII10+Pa82wiRM1ZFX69QCfZ9CaebWsy9Ospf6QfPjdNwU +2eFhLXFA64BOTBwNmQtpvinA2UXhqTwaEAu0P50Nfjrsv3ZXOsvccBI= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OozqNllCgm_T; Fri, 18 Dec 2020 20:41:17 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id A1458413BD; Fri, 18 Dec 2020 20:41:08 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:08 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 14/26] PCI: hotplug: Sort fixed BARs before assignment Date: Fri, 18 Dec 2020 20:39:59 +0300 Message-ID: <20201218174011.340514-15-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Fixed BARs and bridge windows containing fixed BARs must be assigned before the movable ones. When assigning a fixed BAR/bridge window, its start address is chosen to be the lowest possible. To prevent conflicts, sort such resources based on the start address of their fixed areas. Add support of fixed BARs and bridge windows to pdev_sort_resources(). Signed-off-by: Sergei Miroshnichenko --- drivers/pci/setup-bus.c | 63 +++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 9 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 6055f15e3ac3..ab58b999ac6d 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -126,7 +126,8 @@ static resource_size_t get_res_add_align(struct list_head *head, /* Sort resources by alignment */ -static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head) +static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head, + struct list_head *head_fixed) { int i; @@ -135,17 +136,27 @@ static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head) struct pci_dev_resource *dev_res, *tmp; resource_size_t r_align; struct list_head *n; + struct resource *fixed_res = NULL; r = &dev->resource[i]; - if (r->flags & IORESOURCE_PCI_FIXED) - continue; - if (!(r->flags) || r->parent || !pci_dev_bar_enabled(dev, i)) continue; + if (i >= PCI_BRIDGE_RESOURCES && + dev->subordinate) { + int idx = i - PCI_BRIDGE_RESOURCES; + + fixed_res = &dev->subordinate->fixed_range[idx]; + } else if (pci_dev_bar_fixed(dev, r)) { + fixed_res = r; + } + + if (fixed_res && !pci_fixed_range_valid(fixed_res)) + fixed_res = NULL; + r_align = pci_resource_alignment(dev, r); - if (!r_align) { + if (!r_align && !fixed_res) { pci_warn(dev, "BAR %d: %pR has bogus alignment\n", i, r); continue; @@ -157,6 +168,30 @@ static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head) tmp->res = r; tmp->dev = dev; + if (fixed_res) { + n = head_fixed; + list_for_each_entry(dev_res, head_fixed, list) { + struct resource *c_fixed_res = NULL; + int c_resno = dev_res->res - dev_res->dev->resource; + int br_idx = c_resno - PCI_BRIDGE_RESOURCES; + struct pci_bus *cbus = dev_res->dev->subordinate; + + if (br_idx >= 0) + c_fixed_res = &cbus->fixed_range[br_idx]; + else + c_fixed_res = dev_res->res; + + if (fixed_res->start < c_fixed_res->start) { + n = &dev_res->list; + break; + } + } + /* Insert it just before n */ + list_add_tail(&tmp->list, n); + + continue; + } + /* Fallback is smallest one or list is empty */ n = head; list_for_each_entry(dev_res, head, list) { @@ -175,7 +210,8 @@ static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head) } } -static void __dev_sort_resources(struct pci_dev *dev, struct list_head *head) +static void __dev_sort_resources(struct pci_dev *dev, struct list_head *head, + struct list_head *head_fixed) { u16 class = dev->class >> 8; @@ -191,7 +227,7 @@ static void __dev_sort_resources(struct pci_dev *dev, struct list_head *head) return; } - pdev_sort_resources(dev, head); + pdev_sort_resources(dev, head, head_fixed); } static inline void reset_resource(struct resource *res) @@ -486,8 +522,13 @@ static void pdev_assign_resources_sorted(struct pci_dev *dev, struct list_head *fail_head) { LIST_HEAD(head); + LIST_HEAD(head_fixed); + + __dev_sort_resources(dev, &head, &head_fixed); + + if (!list_empty(&head_fixed)) + __assign_resources_sorted(&head_fixed, NULL, NULL); - __dev_sort_resources(dev, &head); __assign_resources_sorted(&head, add_head, fail_head); } @@ -498,9 +539,13 @@ static void pbus_assign_resources_sorted(const struct pci_bus *bus, { struct pci_dev *dev; LIST_HEAD(head); + LIST_HEAD(head_fixed); list_for_each_entry(dev, &bus->devices, bus_list) - __dev_sort_resources(dev, &head); + __dev_sort_resources(dev, &head, &head_fixed); + + if (!list_empty(&head_fixed)) + __assign_resources_sorted(&head_fixed, NULL, NULL); __assign_resources_sorted(&head, realloc_head, fail_head); } From patchwork Fri Dec 18 17:40:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982675 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 C32EAC2D0E4 for ; Fri, 18 Dec 2020 17:43:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9675C23B54 for ; Fri, 18 Dec 2020 17:43:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728528AbgLRRnP (ORCPT ); Fri, 18 Dec 2020 12:43:15 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38588 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727967AbgLRRnO (ORCPT ); Fri, 18 Dec 2020 12:43:14 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 3BB15413BA; Fri, 18 Dec 2020 17:41:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313280; x=1610127681; bh=/htqB/0rYGM6bOltjMUumNTM/7sIZv8Pvtx 4XF2+xgg=; b=FcK8cCIwE2jE6mt7pYenjiVrVnUdmweG5BDXsACp1AH1Y8IG8A/ muEFyrbnOdSkh0L1kPpWTaifm4K8xpegGOHj16Z0AseVXXnlW6RVxb+w0DMwzmXa K6MJ9jDoqZVpNlH2T2Kmjjn9gZ3C2H1lV4YbDKKdyxrnCt9FPxHiCV6k= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FspDviXVrF6B; Fri, 18 Dec 2020 20:41:20 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id C6CFB413C2; Fri, 18 Dec 2020 20:41:08 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:08 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko , Thomas Gleixner Subject: [PATCH v9 15/26] x86/PCI/ACPI: Fix up PCIBIOS_MIN_MEM if value computed from e820 is invalid Date: Fri, 18 Dec 2020 20:40:00 +0300 Message-ID: <20201218174011.340514-16-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The value of PCIBIOS_MIN_MEM reported by BIOS 1.3 on Supermicro H11SSL-i via e820__setup_pci_gap(): [mem 0xebff1000-0xfe9fffff] available for PCI devices is only suitable for a single root complex out of four (0000:00): pci_bus 0000:00: root bus resource [mem 0xec000000-0xefffffff window] pci_bus 0000:20: root bus resource [mem 0xeb800000-0xebefffff window] pci_bus 0000:40: root bus resource [mem 0xeb200000-0xeb5fffff window] pci_bus 0000:60: root bus resource [mem 0xe8b00000-0xeaffffff window] That makes the AMD EPYC 7251 unable to assign BARs of devices hot-added in those three unlucky RCs (0000:20, 0000:40 and 0000:60). If there are apertures that end below the current PCIBIOS_MIN_MEM (which is a variable pci_mem_start on x86), adjust it to the aperture's start. CC: Thomas Gleixner Signed-off-by: Sergei Miroshnichenko --- arch/x86/pci/acpi.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c index 948656069cdd..9eccb26d0bf3 100644 --- a/arch/x86/pci/acpi.c +++ b/arch/x86/pci/acpi.c @@ -299,6 +299,21 @@ static int pci_acpi_root_prepare_resources(struct acpi_pci_root_info *ci) int status; status = acpi_pci_probe_root_resources(ci); + + resource_list_for_each_entry(entry, &ci->resources) { + struct resource *res = entry->res; + + if (!(res->flags & IORESOURCE_MEM) || + res->end > pci_mem_start || + res->start == 0xa0000) + continue; + + dev_warn(&ci->root->device->dev, "Fix up PCI start address: %lx -> %llx\n", + pci_mem_start, res->start); + + pci_mem_start = res->start; + } + if (pci_use_crs) { resource_list_for_each_entry_safe(entry, tmp, &ci->resources) if (resource_is_pcicfg_ioport(entry->res)) From patchwork Fri Dec 18 17:40:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982663 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 59728C3527A for ; Fri, 18 Dec 2020 17:42:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3353D23B7D for ; Fri, 18 Dec 2020 17:42:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727375AbgLRRmt (ORCPT ); Fri, 18 Dec 2020 12:42:49 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38564 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726057AbgLRRms (ORCPT ); Fri, 18 Dec 2020 12:42:48 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 6EE98413BD; Fri, 18 Dec 2020 17:41:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313280; x=1610127681; bh=q35EItJkKAw72WYZwl9DiZGp7mbr5pR6nC2 ozTHlueA=; b=OifHQ06ekQ0Vs1fe/NglwdExKO45lWV0aJgW2VA9Q5E7SJts9jb IRaokmcQuo0Amey6SVvNh0So6h3cqJXXz+4fIbI/rfRfCZxbeNlX40dXEQ+MIxY8 FLWWc52k/eRsL/vd/GGKZlJmvAzDuywFYOgtPuJDwHlIj4A7DSFUfeUc= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DB9o65GrG6ER; Fri, 18 Dec 2020 20:41:20 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 102ED412EC; Fri, 18 Dec 2020 20:41:09 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:08 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 16/26] PCI: hotplug: Configure MPS after manual bus rescan Date: Fri, 18 Dec 2020 20:40:01 +0300 Message-ID: <20201218174011.340514-17-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Assure that MPS settings are set up for bridges which are discovered during manually triggered rescan via sysfs. This sequence of bridge init (using pci_rescan_bus()) later will be used for pciehp hot-add events when BAR movement is enabled. Signed-off-by: Sergei Miroshnichenko --- drivers/pci/probe.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 964dfa71af22..b8873ee82a4b 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -3578,7 +3578,7 @@ static void pci_reassign_root_bus_resources(struct pci_bus *root) unsigned int pci_rescan_bus(struct pci_bus *bus) { unsigned int max; - struct pci_bus *root = bus; + struct pci_bus *root = bus, *child; while (!pci_is_root_bus(root)) root = root->parent; @@ -3599,6 +3599,9 @@ unsigned int pci_rescan_bus(struct pci_bus *bus) pci_assign_unassigned_bus_resources(bus); } + list_for_each_entry(child, &root->children, node) + pcie_bus_configure_settings(child); + pci_bus_add_devices(bus); return max; From patchwork Fri Dec 18 17:40:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982677 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 3189EC3526B for ; Fri, 18 Dec 2020 17:43:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 065EB23B54 for ; Fri, 18 Dec 2020 17:43:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728579AbgLRRnP (ORCPT ); Fri, 18 Dec 2020 12:43:15 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38590 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727981AbgLRRnP (ORCPT ); Fri, 18 Dec 2020 12:43:15 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 5BDBD412EC; Fri, 18 Dec 2020 17:41:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313282; x=1610127683; bh=0bEjkx9ssfVEMvJrSYLU+CqcgBfmVLRsI4V 2h/RC0J0=; b=th44KhD3NR4x8+fNrTD8KtS6p5Hz9HNlZGeOhcPyJmllnuRDfEy 5BeZEYh932ch6LIeHNMDv/ce9riA8oJ4VCkGK40UkpCIprxIMVcox5sxN6KyuJC9 vTZGCxvAmVL+JyEla7ggeekv6+eGpF+6DkwteT8XAHCfPm+bB9qTqMlY= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1k_t8HD_hBOL; Fri, 18 Dec 2020 20:41:22 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 55341413CB; Fri, 18 Dec 2020 20:41:09 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:09 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 17/26] PCI: hotplug: Don't disable the released bridge windows immediately Date: Fri, 18 Dec 2020 20:40:02 +0300 Message-ID: <20201218174011.340514-18-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On a hotplug event with enabled BAR movement, calculating new BAR layout and bridge windows takes some time. During this procedure, the structures representing these windows are released: marked for a recalculation. When the new bridge window values are ready, they are written to the bridge registers via pci_setup_bridges(). Currently, bridge's registers are updated immediately after releasing a window to disable it. But if a driver doesn't yet support movable BARs, it doesn't stop MEM transactions during the hotplug, so disabled bridge windows will break them. Let the bridge windows remain operating after releasing, as they will be updated to the new values in the end of a hotplug event. Signed-off-by: Sergei Miroshnichenko --- drivers/pci/setup-bus.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index ab58b999ac6d..f98772474421 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1649,7 +1649,8 @@ static void pci_bridge_release_resources(struct pci_bus *bus, /* Avoiding touch the one without PREF */ if (type & IORESOURCE_PREFETCH) type = IORESOURCE_PREFETCH; - __pci_setup_bridge(bus, type); + if (!pci_can_move_bars) + __pci_setup_bridge(bus, type); /* For next child res under same bridge */ r->flags = old_flags; } From patchwork Fri Dec 18 17:40:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982661 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 95B24C4361B for ; Fri, 18 Dec 2020 17:42:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6FC3C23B54 for ; Fri, 18 Dec 2020 17:42:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728006AbgLRRmu (ORCPT ); Fri, 18 Dec 2020 12:42:50 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38566 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726220AbgLRRmt (ORCPT ); Fri, 18 Dec 2020 12:42:49 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 9DCE64120A; Fri, 18 Dec 2020 17:41:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313283; x=1610127684; bh=yUQ/qeNM7/P1CLLD+3cl1iPEn6wC6ShgeR8 iUomRcFU=; b=HtOZukoxQW96sAXc8+u1lwPp+bX7+KVJk4utowLFbFVMrONY169 QS6lIK8ht5RZ5NYghJrOkDMXNXpnsJCqqmVhu8/oZi7v/p/7Mpo8yx0nUDMJv4vI DtJZGfwOhk2hFt68uz+UA7eNiqf4kIjZcHOfB27r+pMVh1rGUaL9zbzc= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QAFJnZ6eNGvt; Fri, 18 Dec 2020 20:41:23 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 8A24A413CF; Fri, 18 Dec 2020 20:41:09 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:09 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 18/26] PCI: pciehp: Trigger a domain rescan on hp events when enabled movable BARs Date: Fri, 18 Dec 2020 20:40:03 +0300 Message-ID: <20201218174011.340514-19-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org With movable BARs, hot-adding a device is not a local event for its bridge, but it affects the whole RC: BARs and bridge windows can be substantially rearranged. So instead of trying to fit the new devices into pre-allocated reserved gaps, initiate a full domain rescan. The pci_rescan_bus() covers all the operations of the replaced functions: - assigning new bus numbers, as the pci_hp_add_bridge() does it; - allocating BARs -- pci_assign_unassigned_bridge_resources(); - configuring MPS settings -- pcie_bus_configure_settings(); - binding devices to their drivers -- pci_bus_add_devices(). Signed-off-by: Sergei Miroshnichenko --- drivers/pci/hotplug/pciehp_pci.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/pci/hotplug/pciehp_pci.c b/drivers/pci/hotplug/pciehp_pci.c index d17f3bf36f70..6d4c1ef38210 100644 --- a/drivers/pci/hotplug/pciehp_pci.c +++ b/drivers/pci/hotplug/pciehp_pci.c @@ -58,6 +58,11 @@ int pciehp_configure_device(struct controller *ctrl) goto out; } + if (pci_can_move_bars) { + pci_rescan_bus(parent); + goto out; + } + for_each_pci_bridge(dev, parent) pci_hp_add_bridge(dev); From patchwork Fri Dec 18 17:40:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982667 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 53046C2D0E4 for ; Fri, 18 Dec 2020 17:42:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1E57F23B54 for ; Fri, 18 Dec 2020 17:42:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728012AbgLRRmu (ORCPT ); Fri, 18 Dec 2020 12:42:50 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38570 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726224AbgLRRmu (ORCPT ); Fri, 18 Dec 2020 12:42:50 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 7E44C413BC; Fri, 18 Dec 2020 17:41:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313285; x=1610127686; bh=VeknS/sOEvEPit2cGhX+MTaf2Qht/qtdPSn sto6syzg=; b=E/qXRDdtmsZX0/7lEwIedH6k0KMCHpgbXWXGI5CuwTWZhJONyDj fbAL4EeFlyru6vyfFTtnoFLe1//ZeuQLCXeO4UBT/pRItwKd7lacdwwmveHywxCk ASjZAxtFnGAFE3+mZil3tosv4feUifOB7UVQ0S8L6y5ys868TpkTts20= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ds8ckpxxolCM; Fri, 18 Dec 2020 20:41:25 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id C7854413D5; Fri, 18 Dec 2020 20:41:09 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:09 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 19/26] PCI: Don't claim fixed BARs Date: Fri, 18 Dec 2020 20:40:04 +0300 Message-ID: <20201218174011.340514-20-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org A fixed BAR always has an address, but its parent bridge window can be not yet calculated (during boot) or temporarily released for re-calculation (during PCI rescan) when pci_claim_resource() is called. Apart from that, fixed BARs now have separate guaranteed mechanism of assigning comparing to usual BARs, so claiming them is not needed. Return immediately from pci_claim_resource() to prevent a misleading "can't claim BAR ... no compatible bridge window" error message. Signed-off-by: Sergei Miroshnichenko --- drivers/pci/setup-res.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index 6ffda8b94c52..28ec3d8c79c8 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c @@ -139,6 +139,9 @@ int pci_claim_resource(struct pci_dev *dev, int resource) return -EINVAL; } + if (pci_dev_bar_fixed(dev, res)) + return 0; + /* * If we have a shadow copy in RAM, the PCI device doesn't respond * to the shadow range, so we don't need to claim it, and upstream From patchwork Fri Dec 18 17:40:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982679 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 BA9C5C3526C for ; Fri, 18 Dec 2020 17:43:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 92C9923B54 for ; Fri, 18 Dec 2020 17:43:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729999AbgLRRnQ (ORCPT ); Fri, 18 Dec 2020 12:43:16 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38594 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728303AbgLRRnP (ORCPT ); Fri, 18 Dec 2020 12:43:15 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 1DEFF413C6; Fri, 18 Dec 2020 17:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313286; x=1610127687; bh=q1nRneZFbxTjerthzgu+a2DaENJ6zgP/ikt PPRLbAr0=; b=KrhnxaIu7jZR0kOoT0/LrAz+0SRbiDQhEqg0er38zt9JFtdQbi5 A5b+mwz90cQk/jgsAP6g/30x18zndsbYPIp13VzagmmIyWDZ6YyyjtBuY9pW2Iz+ VQLbeG0xx5KXeat2pwlB6m/d/PIahcKBKZJ/M1ZCHhyCvYf99OALr8pM= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iEx8a77-hEw5; Fri, 18 Dec 2020 20:41:26 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 016A7413D8; Fri, 18 Dec 2020 20:41:10 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:09 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 20/26] PCI: hotplug: Retry bus assignment without reserved space Date: Fri, 18 Dec 2020 20:40:05 +0300 Message-ID: <20201218174011.340514-21-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org A hot-added bridge with many hotplug-capable ports may request reserving more IO space than the machine has. This could be overridden with the "hpiosize=" kernel argument though. But when BARs are movable, no need to reserve space anymore: new BARs are allocated not from reserved gaps, but via rearranging the existing BARs. Requesting a precise amount of space for bridge windows increases the chances of adding the new bridge successfully. Still, fixed BARs may interfere with an allocation, preventing it from happening. So it makes sense to reserve some space when it is possible, so movable BARs can be moved a bit more effectively later. If a BAR allocation fails with additional bridge size, retry without them. Signed-off-by: Sergei Miroshnichenko --- drivers/pci/pci.h | 1 + drivers/pci/probe.c | 9 +++++++++ drivers/pci/setup-bus.c | 9 +++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index f7460ddd196a..685284c57a28 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -207,6 +207,7 @@ extern unsigned long pci_hotplug_io_size; extern unsigned long pci_hotplug_mmio_size; extern unsigned long pci_hotplug_mmio_pref_size; extern unsigned long pci_hotplug_bus_size; +extern bool pci_hotplug_expand; /** * pci_match_one_device - Tell if a PCI device structure has a matching diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index b8873ee82a4b..24793766b4b7 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -41,6 +41,7 @@ EXPORT_SYMBOL(pci_root_buses); * were assigned before the rescan. */ static bool pci_try_failed_bars = true; +bool pci_hotplug_expand = true; bool pci_init_done; static LIST_HEAD(pci_domain_busn_res_list); @@ -3542,6 +3543,13 @@ static void pci_reassign_root_bus_resources(struct pci_bus *root) if (pci_bus_check_bars_assigned(root, pci_try_failed_bars)) break; + if (pci_hotplug_expand) { + dev_warn(&root->dev, "failed to assign all BARs, retry without additional window size\n"); + + pci_hotplug_expand = false; + continue; + } + if (pci_try_failed_bars) { dev_warn(&root->dev, "failed to assign all BARs, retry without those failed before\n"); @@ -3564,6 +3572,7 @@ static void pci_reassign_root_bus_resources(struct pci_bus *root) } while (true); pci_try_failed_bars = true; + pci_hotplug_expand = true; } /** diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index f98772474421..4b37815a9fcf 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1058,6 +1058,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, resource_size_t children_add_size = 0; resource_size_t children_add_align = 0; resource_size_t add_align = 0; + bool size0_can_add = pci_can_move_bars && !realloc_head; int idx; struct resource *fixed_range; resource_size_t fixed_size; @@ -1141,7 +1142,11 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, min_align = calculate_mem_align(aligns, max_order); min_align = max(min_align, window_alignment(bus, b_res->flags)); - size0 = calculate_memsize(size, min_size, 0, 0, resource_size(b_res), min_align); + size0 = calculate_memsize(size, min_size, + size0_can_add ? add_size : 0, + size0_can_add ? children_add_size : 0, + resource_size(b_res), min_align); + add_align = max(min_align, add_align); size1 = (!realloc_head || (realloc_head && !add_size && !children_add_size)) ? size0 : calculate_memsize(size, min_size, add_size, children_add_size, @@ -1316,7 +1321,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) case PCI_HEADER_TYPE_BRIDGE: pci_bridge_check_ranges(bus); - if (bus->self->is_hotplug_bridge) { + if (bus->self->is_hotplug_bridge && pci_hotplug_expand) { additional_io_size = pci_hotplug_io_size; additional_mmio_size = pci_hotplug_mmio_size; additional_mmio_pref_size = pci_hotplug_mmio_pref_size; From patchwork Fri Dec 18 17:40:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982673 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 47F7BC4361B for ; Fri, 18 Dec 2020 17:43:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1DE2B23B54 for ; Fri, 18 Dec 2020 17:43:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728458AbgLRRnP (ORCPT ); Fri, 18 Dec 2020 12:43:15 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38592 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728115AbgLRRnO (ORCPT ); Fri, 18 Dec 2020 12:43:14 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id D46A9413C3; Fri, 18 Dec 2020 17:41:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313289; x=1610127690; bh=YT0S6jRZmFKntF1RfxOxE05+Oc1ixfUdEj+ FCmojLYA=; b=V6DapAPv9clT4CnH3nPC8xJ8wfUdTBCe1XQ9mwnv5b4NUsjOvT+ 8nzCazdquPMJEEWi9scXkVOYW6UCQwhiWrc4K0WNyxfZkoGGtIJUFpc+tH+VqeKL r/ts/n6DsKstuw5Gqqk/b581SOi5Bz8HOhcEP3wrBfaVMSFeWyhc/bY4= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mzM7ohzCnT47; Fri, 18 Dec 2020 20:41:29 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 3CD44413DD; Fri, 18 Dec 2020 20:41:10 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:10 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 21/26] PCI: Rescan the bus to resize a BAR Date: Fri, 18 Dec 2020 20:40:06 +0300 Message-ID: <20201218174011.340514-22-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org BAR resizing can be blocked by another BAR, so trigger a bus rescan to be able to move BARs, increasing the probability of finding a good layout. Signed-off-by: Sergei Miroshnichenko --- drivers/pci/setup-res.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index 28ec3d8c79c8..83a491f6a2c2 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c @@ -480,6 +480,9 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size) u32 sizes; u16 cmd; + if (pci_dev_bar_fixed(dev, res)) + return -EOPNOTSUPP; + /* Make sure the resource isn't assigned before resizing it. */ if (!(res->flags & IORESOURCE_UNSET)) return -EBUSY; @@ -506,7 +509,15 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size) res->end = res->start + pci_rebar_size_to_bytes(size) - 1; /* Check if the new config works by trying to assign everything. */ - if (dev->bus->self) { + if (pci_can_move_bars) { + pci_rescan_bus(dev->bus); + + if (!res->flags || (res->flags & IORESOURCE_UNSET) || !res->parent) { + pci_err(dev, "BAR %d resize failed\n", resno); + ret = -1; + goto error_resize; + } + } else if (dev->bus->self) { ret = pci_reassign_bridge_resources(dev->bus->self, res->flags); if (ret) goto error_resize; @@ -516,6 +527,8 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size) error_resize: pci_rebar_set_size(dev, resno, old); res->end = res->start + pci_rebar_size_to_bytes(old) - 1; + if (pci_can_move_bars) + pci_rescan_bus(dev->bus); return ret; } EXPORT_SYMBOL(pci_resize_resource); From patchwork Fri Dec 18 17:40:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982665 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 0E519C3527E for ; Fri, 18 Dec 2020 17:42:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D7B2C23B54 for ; Fri, 18 Dec 2020 17:42:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728062AbgLRRmu (ORCPT ); Fri, 18 Dec 2020 12:42:50 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38573 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726242AbgLRRmu (ORCPT ); Fri, 18 Dec 2020 12:42:50 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 2A660413CB; Fri, 18 Dec 2020 17:41:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313291; x=1610127692; bh=S2G+Li4cmUfMFhe99gYolFF3zExbhtUK11o tKS49VIs=; b=KeGKzJnsLIgoKDZapFqMdp/Qh7PR/jCFz4QWKMY1bDATr7ew8Vp ZaeY2EO2BgE2iWK3gvZFclBETH212Vm4CrKVr/nlaNafZgcd8xjec37fqsT36IYN xobaA7amZdQ3X/c5j9DYOXUGZepEaRbYcBBMi3s6qugnbNMYMkPQrYbs= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6ZksMcE-ZizT; Fri, 18 Dec 2020 20:41:31 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 7A15B413DE; Fri, 18 Dec 2020 20:41:10 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:10 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 22/26] PCI: hotplug: Enable the movable BARs feature by default Date: Fri, 18 Dec 2020 20:40:07 +0300 Message-ID: <20201218174011.340514-23-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org This is the last patch in the series which implements the essentials of the movable BARs feature, so it is turned on by default now. Tested on x86_64; and with extra patches applied, it also works on ppc64le (PowerNV). In case of problems it is still can be overridden by the following command line option: pcie_movable_bars=off Signed-off-by: Sergei Miroshnichenko --- 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 f393f0bc8ec4..98fabff81028 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -76,7 +76,7 @@ static void pci_dev_d3_sleep(struct pci_dev *dev) int pci_domains_supported = 1; #endif -bool pci_can_move_bars; +bool pci_can_move_bars = true; #define DEFAULT_CARDBUS_IO_SIZE (256) #define DEFAULT_CARDBUS_MEM_SIZE (64*1024*1024) From patchwork Fri Dec 18 17:40:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982669 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 D6A92C352A2 for ; Fri, 18 Dec 2020 17:42:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ABE8923B54 for ; Fri, 18 Dec 2020 17:42:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728280AbgLRRmv (ORCPT ); Fri, 18 Dec 2020 12:42:51 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38572 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727981AbgLRRmv (ORCPT ); Fri, 18 Dec 2020 12:42:51 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 063E3413D2; Fri, 18 Dec 2020 17:41:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313291; x=1610127692; bh=faXA1qHhZ+GvL5/hTU6Bm/jkEm46iZZ2A5G poLgSabg=; b=OSP40vJJ/x6Fe3nHZjvgjTanR/79u6CLTfpMEFLUg6QB3a1Ux8L Cwz8aaNfFmiGIze1gVaSfml8Na6SDQadtEFoKJmaQz8pTnXXu1IauKzRKWqYOq++ 3YXT0G9O7GJxlwxsgN6RhVOnBt3Z6+WR8TaTCpjFRhTUwOXXhyge5PO4= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UQ7DE-EDqd8z; Fri, 18 Dec 2020 20:41:31 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id B5FFD413CE; Fri, 18 Dec 2020 20:41:10 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:10 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 23/26] PCI/portdrv: Declare support of movable BARs Date: Fri, 18 Dec 2020 20:40:08 +0300 Message-ID: <20201218174011.340514-24-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Currently there are no reliable way to determine if a driver uses BARs of its devices (their struct resource don't always have a child), so if it doesn't explicitly support movable BARs, they are considered fixed. The portdrv driver for PCI switches don't use BARs, so add a new hook .bar_fixed() { return false; } to increase the chances to allocate new BARs for new devices. Signed-off-by: Sergei Miroshnichenko --- drivers/pci/pcie/portdrv_pci.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c index 0b250bc5f405..3043f7e4d3c1 100644 --- a/drivers/pci/pcie/portdrv_pci.c +++ b/drivers/pci/pcie/portdrv_pci.c @@ -212,6 +212,11 @@ static const struct pci_error_handlers pcie_portdrv_err_handler = { .resume = pcie_portdrv_err_resume, }; +static bool pcie_portdrv_bar_fixed(struct pci_dev *pdev, int resno) +{ + return false; +} + static struct pci_driver pcie_portdriver = { .name = "pcieport", .id_table = &port_pci_ids[0], @@ -222,6 +227,8 @@ static struct pci_driver pcie_portdriver = { .err_handler = &pcie_portdrv_err_handler, + .bar_fixed = pcie_portdrv_bar_fixed, + .driver.pm = PCIE_PORTDRV_PM_OPS, }; From patchwork Fri Dec 18 17:40:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982681 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 3C2D4C4361B for ; Fri, 18 Dec 2020 17:43:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1922723B54 for ; Fri, 18 Dec 2020 17:43:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730270AbgLRRnQ (ORCPT ); Fri, 18 Dec 2020 12:43:16 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38596 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727967AbgLRRnQ (ORCPT ); Fri, 18 Dec 2020 12:43:16 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 7409C413D5; Fri, 18 Dec 2020 17:41:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313292; x=1610127693; bh=cLgLn4rXA1xiaAB3ENuZEne5ERVt5u32Jus mMyXwWHM=; b=fWEezA475dRWxuKNqbIf1tW5G5lCL3v3YDTS0Qhv27i6xC9Me21 K/0cwxljMltO4inYY1SvxrENm+7iNii2kmawyz3zqOWMoAcNITOQ72okdt6rd1Ut k4jLEgONfLP/KoUk2SX4CGzXGdBf0xIDssIiJZ+08F8Gp/pip7u5gt/g= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7Rbb2F7mdMFZ; Fri, 18 Dec 2020 20:41:32 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id EB213413E0; Fri, 18 Dec 2020 20:41:10 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:10 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko , , Christoph Hellwig Subject: [PATCH v9 24/26] nvme-pci: Handle movable BARs Date: Fri, 18 Dec 2020 20:40:09 +0300 Message-ID: <20201218174011.340514-25-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Hot-added devices can affect the existing ones by moving their BARs. The PCI subsystem will inform the NVME driver about this by invoking the .rescan_prepare() and .rescan_done() hooks, so the BARs can by re-mapped. Tested under the "randrw" mode of the fio tool, and when using an NVME drive as a root filesystem storage. Before the hot-adding: % sudo cat /proc/iomem ... 3fe800000000-3fe8007fffff : PCI Bus 0020:0b 3fe800000000-3fe8007fffff : PCI Bus 0020:18 3fe800000000-3fe8000fffff : 0020:18:00.0 3fe800000000-3fe8000fffff : nvme ^^^^^^^^^^^^^^^^^^^^^^^^^ 3fe800100000-3fe80017ffff : 0020:18:00.0 ... Then another NVME drive was hot-added, so BARs of the 0020:18:00.0 are moved: % sudo cat /proc/iomem ... 3fe800000000-3fe800ffffff : PCI Bus 0020:0b 3fe800000000-3fe8007fffff : PCI Bus 0020:10 3fe800000000-3fe800003fff : 0020:10:00.0 3fe800000000-3fe800003fff : nvme 3fe800010000-3fe80001ffff : 0020:10:00.0 3fe800800000-3fe800ffffff : PCI Bus 0020:18 3fe800800000-3fe8008fffff : 0020:18:00.0 3fe800800000-3fe8008fffff : nvme ^^^^^^^^^^^^^^^^^^^^^^^^^ 3fe800900000-3fe80097ffff : 0020:18:00.0 ... During the rescanning, both READ and WRITE speeds drop to zero for a while due to driver's pause, then restore. Cc: linux-nvme@lists.infradead.org Cc: Christoph Hellwig Signed-off-by: Sergei Miroshnichenko --- drivers/nvme/host/pci.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index b4385cb0ff60..7993062b11b6 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -1656,7 +1656,7 @@ static int nvme_remap_bar(struct nvme_dev *dev, unsigned long size) { struct pci_dev *pdev = to_pci_dev(dev->dev); - if (size <= dev->bar_mapped_size) + if (dev->bar && size <= dev->bar_mapped_size) return 0; if (size > pci_resource_len(pdev, 0)) return -ENOMEM; @@ -3152,6 +3152,28 @@ static void nvme_error_resume(struct pci_dev *pdev) flush_work(&dev->ctrl.reset_work); } +static bool nvme_bar_fixed(struct pci_dev *pdev, int resno) +{ + return false; +} + +static void nvme_rescan_prepare(struct pci_dev *pdev) +{ + struct nvme_dev *dev = pci_get_drvdata(pdev); + + nvme_dev_disable(dev, true); + nvme_dev_unmap(dev); + dev->bar = NULL; +} + +static void nvme_rescan_done(struct pci_dev *pdev) +{ + struct nvme_dev *dev = pci_get_drvdata(pdev); + + nvme_dev_map(dev); + nvme_reset_ctrl(&dev->ctrl); +} + static const struct pci_error_handlers nvme_err_handler = { .error_detected = nvme_error_detected, .slot_reset = nvme_slot_reset, @@ -3238,6 +3260,9 @@ static struct pci_driver nvme_driver = { #endif .sriov_configure = pci_sriov_configure_simple, .err_handler = &nvme_err_handler, + .rescan_prepare = nvme_rescan_prepare, + .rescan_done = nvme_rescan_done, + .bar_fixed = nvme_bar_fixed, }; static int __init nvme_init(void) From patchwork Fri Dec 18 17:40:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982683 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 2B2C4C2BBD5 for ; Fri, 18 Dec 2020 17:43:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F32F323B54 for ; Fri, 18 Dec 2020 17:43:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731636AbgLRRnS (ORCPT ); Fri, 18 Dec 2020 12:43:18 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38598 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727967AbgLRRnS (ORCPT ); Fri, 18 Dec 2020 12:43:18 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 20805413D6; Fri, 18 Dec 2020 17:41:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313293; x=1610127694; bh=6+JB6ailJ7ODm11KjGiL514scFTPER5Q1H2 hndZUQfI=; b=iQlj6ZsUib11ooJwdmi6JN5wyEpC/wJR6tuFeZrHsAOU99eyz+4 c2bN9IuhhwM2zqu4DsZzKmit2U/h09oF8nGAQzJn5iw1sFCfmxqSRAeNJ1hoNlEc o+L4sVtGd7LKztZmIh85G58sYKvxuY0aLHl3O+XAsL4igc7cMR1foRgg= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id scIF4c0UVia7; Fri, 18 Dec 2020 20:41:33 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 3586741396; Fri, 18 Dec 2020 20:41:11 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:10 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 25/26] PCI: Add a message for updating BARs Date: Fri, 18 Dec 2020 20:40:10 +0300 Message-ID: <20201218174011.340514-26-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Add a new debug message for changing a BAR value of a device: [ 1.851161] pci 0003:0a:00.1: BAR 0 updated: 0x60200c2000000 -> 0x6020142000000 Signed-off-by: Sergei Miroshnichenko --- drivers/pci/setup-res.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index 83a491f6a2c2..5fed21aed9b8 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c @@ -27,7 +27,8 @@ static void pci_std_update_resource(struct pci_dev *dev, int resno) struct pci_bus_region region; bool disable; u16 cmd; - u32 new, check, mask; + u32 new, check, mask, old; + u64 old_start; int reg; struct resource *res = dev->resource + resno; @@ -96,6 +97,9 @@ static void pci_std_update_resource(struct pci_dev *dev, int resno) cmd & ~PCI_COMMAND_MEMORY); } + pci_read_config_dword(dev, reg, &old); + old_start = old & mask; + pci_write_config_dword(dev, reg, new); pci_read_config_dword(dev, reg, &check); @@ -105,6 +109,9 @@ static void pci_std_update_resource(struct pci_dev *dev, int resno) } if (res->flags & IORESOURCE_MEM_64) { + pci_read_config_dword(dev, reg + 4, &old); + old_start |= (u64)old << 32; + new = region.start >> 16 >> 16; pci_write_config_dword(dev, reg + 4, new); pci_read_config_dword(dev, reg + 4, &check); @@ -116,6 +123,11 @@ static void pci_std_update_resource(struct pci_dev *dev, int resno) if (disable) pci_write_config_word(dev, PCI_COMMAND, cmd); + + if (old_start != region.start) + pci_info(dev, "BAR %d updated: %#llx -> %#llx\n", resno, + (unsigned long long)old_start, + (unsigned long long)region.start); } void pci_update_resource(struct pci_dev *dev, int resno) From patchwork Fri Dec 18 17:40:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Miroshnichenko X-Patchwork-Id: 11982671 X-Patchwork-Delegate: bhelgaas@google.com 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 38B9CC2BBD5 for ; Fri, 18 Dec 2020 17:42:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0881B239EE for ; Fri, 18 Dec 2020 17:42:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728459AbgLRRmw (ORCPT ); Fri, 18 Dec 2020 12:42:52 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:38578 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728458AbgLRRmw (ORCPT ); Fri, 18 Dec 2020 12:42:52 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 8D6B4413D7; Fri, 18 Dec 2020 17:41:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1608313293; x=1610127694; bh=aP4ZVo64yVK8Q+GVWLOMVK/0Def8PayQyTT YTWOSXpA=; b=bCyhKa2FzY1E39EFp5JVHY0araB1Ws0FvxvGv2dIM7odXgJJpls LNGLWR4o0UPzhTUuxojwg/n/eVWrSlRBpXY+JbVSzquG9fHlKa3H0opyusgtisMt qmETrMxh2T8ZASwpxdje/BV9cHRQKGt1vQfzTA/68gFrluxZN6U9hoLk= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YkP0ST7r1jVl; Fri, 18 Dec 2020 20:41:33 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 70D3A413E2; Fri, 18 Dec 2020 20:41:11 +0300 (MSK) Received: from NB-148.yadro.com (172.17.15.136) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Fri, 18 Dec 2020 20:41:11 +0300 From: Sergei Miroshnichenko To: CC: Bjorn Helgaas , Lukas Wunner , Stefan Roese , Andy Lavr , =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , David Laight , Rajat Jain , , Sergei Miroshnichenko Subject: [PATCH v9 26/26] resource: increase max nesting level for /proc/iomem Date: Fri, 18 Dec 2020 20:40:11 +0300 Message-ID: <20201218174011.340514-27-s.miroshnichenko@yadro.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201218174011.340514-1-s.miroshnichenko@yadro.com> References: <20201218174011.340514-1-s.miroshnichenko@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.15.136] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Current value of maximum indentation for /proc/iomem and /proc/ioports is not enough for comfortable PCI resources debugging when several bridges are nested, so increase it from 5 to 15: % lspci -tv +-[0000:80]-+-00.0-[81]-- | +-01.0-[82]-- | +-03.0-[83-99]----00.0-[84-99]----04.0-[85-99]----00.0-[86-99]--+-00.0-[87]-- | | +-04.0-[88]-- | | +-08.0-[89]-- | | +-09.0-[8a]-- | | +-0c.0-[8b-95]----00.0-[8c-95]--+-00.0-[8d]-- | | | +-04.0-[8e]-- | | | +-08.0-[8f]-- | | | +-09.0-[90]-- | | | +-0c.0-[91]-- | | | +-10.0-[92]--+-00.0 | | | | \-00.1 % sudo cat /proc/iomem ... f9000000000-f907fffffff : PCI Bus 0000:80 f9000100000-f90010fffff : PCI Bus 0000:83 f9000100000-f90010fffff : PCI Bus 0000:84 f9000100000-f90010fffff : PCI Bus 0000:85 f9000100000-f90010fffff : PCI Bus 0000:86 f9000100000-f90009fffff : PCI Bus 0000:8b f9000100000-f90009fffff : PCI Bus 0000:8c f9000100000-f90003fffff : PCI Bus 0000:92 f9000100000-f90001fffff : 0000:92:00.0 f9000100000-f90001fffff : qla2xx f9000200000-f9002ffffff : 0000:92:00.1 f9000200000-f90002fffff : qla2xxx f9000300000-f9000301fff : 0000:92:00.0 f9000300000-f9000301fff : qla2xxx f9000302000-f9000303fff : 0000:92:00.1 f9000302000-f9000303fff : qla2xxx f9000304000-f9000304fff : 0000:92:00.0 f9000304000-f9000304fff : qla2xxx f9000305000-f9000305fff : 0000:92:00.1 f9000305000-f9000305fff : qla2xxx Signed-off-by: Sergei Miroshnichenko --- kernel/resource.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/resource.c b/kernel/resource.c index 833394f9c608..4b3b378fed19 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -83,7 +83,7 @@ static void *r_next(struct seq_file *m, void *v, loff_t *pos) #ifdef CONFIG_PROC_FS -enum { MAX_IORES_LEVEL = 5 }; +enum { MAX_IORES_LEVEL = 15 }; static void *r_start(struct seq_file *m, loff_t *pos) __acquires(resource_lock)