From patchwork Sun May 5 14:40:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 10930241 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 0F0F61398 for ; Sun, 5 May 2019 14:41:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE339285FB for ; Sun, 5 May 2019 14:41:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFEEC28619; Sun, 5 May 2019 14:41:00 +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 7B305285FB for ; Sun, 5 May 2019 14:40:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727343AbfEEOk5 (ORCPT ); Sun, 5 May 2019 10:40:57 -0400 Received: from mail-oln040092254060.outbound.protection.outlook.com ([40.92.254.60]:44064 "EHLO APC01-PU1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727325AbfEEOk4 (ORCPT ); Sun, 5 May 2019 10:40:56 -0400 Received: from HK2APC01FT045.eop-APC01.prod.protection.outlook.com (10.152.248.58) by HK2APC01HT130.eop-APC01.prod.protection.outlook.com (10.152.249.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1856.11; Sun, 5 May 2019 14:40:50 +0000 Received: from PS2P216MB0642.KORP216.PROD.OUTLOOK.COM (10.152.248.52) by HK2APC01FT045.mail.protection.outlook.com (10.152.249.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1856.11 via Frontend Transport; Sun, 5 May 2019 14:40:50 +0000 Received: from PS2P216MB0642.KORP216.PROD.OUTLOOK.COM ([fe80::adb3:4c16:60fd:65]) by PS2P216MB0642.KORP216.PROD.OUTLOOK.COM ([fe80::adb3:4c16:60fd:65%5]) with mapi id 15.20.1856.012; Sun, 5 May 2019 14:40:50 +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 v5 2/5] PCI: Modify extend_bridge_window() to set resource size directly Thread-Topic: [PATCH v5 2/5] PCI: Modify extend_bridge_window() to set resource size directly Thread-Index: AQHVA1CI9jNol7iUzES0UZf8wu0+NA== Date: Sun, 5 May 2019 14:40:50 +0000 Message-ID: References: <20190505144001.8106-1-nicholas.johnson-opensource@outlook.com.au> In-Reply-To: <20190505144001.8106-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: SG2PR03CA0128.apcprd03.prod.outlook.com (2603:1096:4:91::32) To PS2P216MB0642.KORP216.PROD.OUTLOOK.COM (2603:1096:300:1c::16) x-incomingtopheadermarker: OriginalChecksum:4434BF53E77976FBA866F5E1AA7F2BCECC47564EFADDACB1DEA614C0163F70B9;UpperCasedChecksum:B798127DA7FEEAD382AF9CDCC9955D0A58596E9E9DAA2C3C74538BDFCB0A458C;SizeAsReceived:7897;Count:50 x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.19.1 x-tmn: [Fe59OQfkaps0sjCmyQD8VEvn1TR7jiaJwDlfSWbKVuEgHGVlH8md+4wCahq/fVpdBUcFU1Gib5g=] x-microsoft-original-message-id: <20190505144001.8106-3-nicholas.johnson-opensource@outlook.com.au> x-ms-publictraffictype: Email x-incomingheadercount: 50 x-eopattributedmessage: 0 x-ms-exchange-slblob-mailprops: mBy7Mai7yE4yhl4FRICA9NYl3Rc5hrDw8nZxa3nbUQ6gdN6BZ2hbWE8C89NMjQ2tyIypK6YTu0B4KvWxnCLRr4b/SjqpqRfnLf0wg92qkS/9+H9UR9th/XRkmB6/acST+FaSarbRRHyRkyVHYjOsyqQMCWN35ofQoq6DfSzsdqt6DWJXpmfkja/D1fJ2c5pqdCUGjanO8K5TNO/7uPg0mD11Itws+fMNNn2pZKcVItimGc827EpKBT2ZSgiRR7jV+iS/P61PyLydtssdlv6M61m6ZJqarQUn0+WY1SrWVKc4BBnhYom+1yy/T6ZjHtZcDSQEoThZ0raGJYke0wEquKo/aatMrTS6QapJq8z2iNpaS2FGhL/Sbfkt4dHZUb2wQWQRNC/mVBrOnAs1YpgXdbQZM+8NNS9KOsXy0LP0x6ngYKONxvyjzfcIOOqR7zds4PMpwr4DlVzzZhF6ExvOdPPqTg3omwoKqlVlWm6I2ZP/0gztNrJYsM8phcSfUhTCyIG1i3lgtY4dspzgKEp+VI458vgCVWNW8FE22hfD97+t19/khQ1ZQWMRgJwDi0pda6GssF3lkJB5MNdkWAu7Gz0fGUalpDg/N52xvFvUduUThBUnUnbcIvgkmgkS7Txgh2LS8vdQjR5raKMAi39dvg0n6kIGXFRR7R7Yq3RJk9hNqF1a8350MB5kyE5r4Sa7noTBk1te453ZCx179NS9lD9uhUfgIzMJ 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:HK2APC01HT130; x-ms-traffictypediagnostic: HK2APC01HT130: x-microsoft-antispam-message-info: iQ2sfmBZ8yIhi/wekERmc3XMgInArylgo3o60tFSDzn2t/pOAUoYLv95+mo/gyEYl8qgcj3NHceJkDBPCBpfpJLDnPTqGsG148trKvR+ikTOSsBvkmNg6lFjvsgl27bgxBJF3njQQVOf0xsv9ye5lRKzwygNOnGS8z1nm8VPmppxMmX8k/rLmmoYhkevHaGP 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: 622028f6-4ec8-4ee5-120b-08d6d167aacb X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 May 2019 14:40:50.0218 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK2APC01HT130 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 | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index dae4bae12..5214815c7 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1815,27 +1815,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,