From patchwork Wed May 22 14:30:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 10955943 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A70D14B6 for ; Wed, 22 May 2019 14:31:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B36C28BEC for ; Wed, 22 May 2019 14:31:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F5F827F3E; Wed, 22 May 2019 14:31:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C83A128BCC for ; Wed, 22 May 2019 14:31:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729081AbfEVObC (ORCPT ); Wed, 22 May 2019 10:31:02 -0400 Received: from mail-oln040092255053.outbound.protection.outlook.com ([40.92.255.53]:55074 "EHLO APC01-HK2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729496AbfEVObC (ORCPT ); Wed, 22 May 2019 10:31:02 -0400 Received: from HK2APC01FT049.eop-APC01.prod.protection.outlook.com (10.152.248.56) by HK2APC01HT057.eop-APC01.prod.protection.outlook.com (10.152.248.228) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1922.16; Wed, 22 May 2019 14:30:57 +0000 Received: from PS2P216MB0642.KORP216.PROD.OUTLOOK.COM (10.152.248.53) by HK2APC01FT049.mail.protection.outlook.com (10.152.249.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1922.16 via Frontend Transport; Wed, 22 May 2019 14:30:57 +0000 Received: from PS2P216MB0642.KORP216.PROD.OUTLOOK.COM ([fe80::1c5e:7ea0:b90c:65c9]) by PS2P216MB0642.KORP216.PROD.OUTLOOK.COM ([fe80::1c5e:7ea0:b90c:65c9%10]) with mapi id 15.20.1922.016; Wed, 22 May 2019 14:30:57 +0000 From: Nicholas Johnson To: "linux-kernel@vger.kernel.org" CC: "linux-pci@vger.kernel.org" , "bhelgaas@google.com" , "mika.westerberg@linux.intel.com" , "corbet@lwn.net" , Nicholas Johnson Subject: [PATCH v6 2/4] PCI: Modify extend_bridge_window() to set resource size directly Thread-Topic: [PATCH v6 2/4] PCI: Modify extend_bridge_window() to set resource size directly Thread-Index: AQHVEKr4LXCXpei2wUm8E5PLOp+BQg== Date: Wed, 22 May 2019 14:30:57 +0000 Message-ID: References: <20190522222928.2964-1-nicholas.johnson-opensource@outlook.com.au> In-Reply-To: <20190522222928.2964-1-nicholas.johnson-opensource@outlook.com.au> Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SYBPR01CA0182.ausprd01.prod.outlook.com (2603:10c6:10:52::26) To PS2P216MB0642.KORP216.PROD.OUTLOOK.COM (2603:1096:300:1c::16) x-incomingtopheadermarker: OriginalChecksum:740C92D4E1CF1E0C4DEDBDBFF7858B92FBD3E9145DC2DACD8163D6601E0B33EA;UpperCasedChecksum:D36088524FF24528BD8DE8C08F7B6416E2C19F590AEAF0DA82CBD58707660FD5;SizeAsReceived:7908;Count:50 x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.19.1 x-tmn: [cdS8nkYCPMEd0lOhgZUxGLkqD5fehTd5n2/Q+P+bgZhG18io+iR27BzXoljUlhnzI4P8RrUbdv8=] x-microsoft-original-message-id: <20190522222928.2964-3-nicholas.johnson-opensource@outlook.com.au> x-ms-publictraffictype: Email x-incomingheadercount: 50 x-eopattributedmessage: 0 x-ms-exchange-slblob-mailprops: zswcL9HXbeUiX0zZ7ySjSUyGp5OFWI2c3bi5ld70R/pNUM8L97IpnYUf5kDn3ez/RvkCwo820rd9CSSxvaw/2IfyUhAtqWcupnYNJgzDhpLuYHy7FBROcPNKlYf2wOWc4E65bTdbgpXtqBhwa0+LLSoH1g2f546gRyfrkbjQzjcnjap73/B5dOZF3Rn2xSN1rD6mtBlqNZHRk5K1hLBB6lyKorGfySobyIylhp83scM6ZBQPwsFrcocHPE7u88Qj+e/+NBTVXRCMP75xjhUpdA3PsmUrCa3trhAnZTu0oIH8RG16nVO9C24Z0dFqLgwU0FimzdxrXeZpmLMGL2ZA531/JrBoaLuHL0IO5WbG4zaEhINsa6q8Qfm67tOPNUjzEGMQk5uU9R3Yi+ei6sQMTBCgDjSlc4v+kLebwIEk44KC5dxxWUrcct7jvyQDU7ij7VY1EyzEPfGg4n+Fc3IWC86kHhgWmp7NLQ3IpC0QmYafJYak0sUfymg741bRSl+NDJZHGedunf0uMJgDO1O0lvH9lret1ZqaG1DfXURvb+1h7wz07VAfKW5y9s/g8HuIENLRY/CCjnDz4v9UB9MFLRE9WifRVZrTJ75y17eJMCW0eh8jkON8xLm5goDUnZWLcL4DN3lMAgJ+IVXifK8gByMC/yXAWKOS9IWv5C0LPDxxQWj21YiTIqbo2Dk8MXrNhG5VEO09I4CEnpJbBUcT5hS1u0VDNgBxDBAqXme1grxscqpmF2c3MVFbJh9syLKl x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(5050001)(7020095)(20181119110)(201702061078)(5061506573)(5061507331)(1603103135)(2017031320274)(201702181274)(2017031323274)(2017031324274)(2017031322404)(1601125500)(1603101475)(1701031045);SRVR:HK2APC01HT057; x-ms-traffictypediagnostic: HK2APC01HT057: x-microsoft-antispam-message-info: tDxHz0ZyQ4RFuQPtmI7Q+FPK/Fm5RZxUhK5/JpKRHzT4sOouv3pjWTIgRqKNPy87hr9aG9R3k7f0kmtHOiXZOz0CH2vREkIDjq9VrQm6xkMUGVU4KES08EJ9bf1no+ONUYCe1yZvnBWzLS3ph+OBV2poB1sl0PrHHtwnIvLsnxgEcxfz7cUnv2TKKyxmyJZY MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: acaf4792-230d-4b4a-3dd2-08d6dec21a8a X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 May 2019 14:30:57.4146 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK2APC01HT057 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Background ========================================================================== In the current state, the PCI allocation could fail with Thunderbolt under certain unusual circumstances, because add_list resources are "optional". Guaranteed allocation requires guaranteed resource sizes. It is difficult to give examples of these failures - because without the previous patch in the series, the symptoms of the problem are hidden by larger problems. This patch has been split from the previous patch and makes little sense on its own - as it is almost impossible to see the effect of this patch without first fixing the problems addressed by the previous patch. So the evidence I put forward for making this change is that because add_list resources are "optional", there could be any number of unforeseen bugs that are yet to be encountered if the kernel decides not to assign all of the optional size. In kernel development, we should not play around with chance. Moving away from add_size also allows for use of pci=hpmemsize to assign resources. Previously, when using add_size and not allowing the add_size to shrink, it made it impossible to distribute resources. If a hotplug bridge has size X, and below it is some devices with non-zero size Y and a nested hotplug bridge of same size X, fitting X+Y into size X is mathematically impossible. This patch solves this by dropping add_size and giving each bridge the maximum size possible without failing resource assignment. Using pci=hpmemsize still works as pci_assign_unassigned_root_bus_resources() does not call pci_bus_distribute_available_resources(). At boot, pci_assign_unassigned_root_bus_resources() is used, instead of pci_bridge_distribute_available_resources(). By allowing to use pci=hpmemsize, it removes the reliance on the firmware to declare the window resources under the root port, and could pay off in the future with USB4 (which is backward-compatible to Thunderbolt devices, and not specific to Intel systems). Users of Thunderbolt hardware on unsupported systems will be able to specify the resources in the kernel parameters. Users of official systems will be able to override the default firmware window sizes to allocate much larger resource sizes, potentially enabling Thunderbolt support for devices with massive BARs (with a few other problems solved by later patches in this series). Patch notes ========================================================================== Modify extend_bridge_window() to remove the resource from add_list and change the resource size directly. Modify extend_bridge_window() to reset resources that are being assigned zero size. This is required to prevent the bridge not being enabled due to resources with zero size. This is a direct requirement to prevent the change away from using add_list from introducing a regression - because before, it was not possible to end up with zero size. Signed-off-by: Nicholas Johnson --- drivers/pci/setup-bus.c | 42 ++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 1b5b851ca..5675254fa 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1810,28 +1810,40 @@ void __init pci_assign_unassigned_resources(void) } static void extend_bridge_window(struct pci_dev *bridge, struct resource *res, - struct list_head *add_list, - resource_size_t available) + struct list_head *add_list, resource_size_t new_size) { - struct pci_dev_resource *dev_res; + resource_size_t add_size; if (res->parent) return; - if (resource_size(res) >= available) - return; - - dev_res = res_to_dev_res(add_list, res); - if (!dev_res) - return; + if (new_size >= resource_size(res)) { + add_size = new_size - resource_size(res); + pci_dbg(bridge, "bridge window %pR extended by %pa\n", res, + &add_size); + } else { + add_size = resource_size(res) - new_size; + pci_dbg(bridge, "bridge window %pR shrunken by %pa\n", res, + &add_size); + } - /* Is there room to extend the window? */ - if (available - resource_size(res) <= dev_res->add_size) - return; + /* + * Resources requested using add_size in additional resource lists are + * considered optional when allocated. Guaranteed size of allocation + * is required to guarantee successful resource distribution. Hence, + * the size of the actual resource must be adjusted, and the resource + * removed from add_list to prevent any additional size interfering. + */ + res->end = res->start + new_size - 1; + remove_from_list(add_list, res); - dev_res->add_size = available - resource_size(res); - pci_dbg(bridge, "bridge window %pR extended by %pa\n", res, - &dev_res->add_size); + /* + * If we have run out of bridge resources, we may end up with a + * zero-sized resource which may cause its bridge to not be enabled. + * Disabling the resource prevents any such issues. + */ + if (!new_size) + reset_resource(res); } static void pci_bus_distribute_available_resources(struct pci_bus *bus,