From patchwork Mon Dec 9 12:59: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: 11279335 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 16A75139A for ; Mon, 9 Dec 2019 13:00:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DD9C42077B for ; Mon, 9 Dec 2019 13:00:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727590AbfLINAC convert rfc822-to-8bit (ORCPT ); Mon, 9 Dec 2019 08:00:02 -0500 Received: from mail-oln040092255087.outbound.protection.outlook.com ([40.92.255.87]:6247 "EHLO APC01-HK2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727268AbfLINAC (ORCPT ); Mon, 9 Dec 2019 08:00:02 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Sly9mk8GGp6Zq2Rtbc37z+xUlKpcaQ5J4XEAFMVn/0ItWtzBi3ptAMWCemmvQAWF8Aq7N9bE+++DokeeCDBD5ocYqKi80mx9mi5WI3p0Y6r5UYyjX2F+H8+BCsyFKv2vl4EavFjoKqD5Ppvd4bOiBeL+Tk21ikc/Hk28lcM5NwgyQBl7mis0zjximZH//d3nGnMTK5UMblS2QkqYRNPx9YpnSFIuGb/O+HjsXWQGdXoJagHhFxQM4pU2yg7TmXLSPsQwHedavhuizv8x3ZUbk/00Aq3/c0E2jhtlcbE5tjHaO30M5kNvyxiTnIyX/0jp33GeRnmgqFQsXXZgFCcCVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=J33yRl9Y2sqr6U3Uqe7kpzMmVIwCHSxyWSJOLz/W43k=; b=NTLyY4/zSM1Ur7+wyq4Tjx10Xh23QXBuhIGweTioUsx7um1fYRd8o4ZJTAq+7sltSS/TMrLB0s0Cnh5EchvvvrrG/koiUvtGa2yOjXFpPgvhiZbrc/EcPIhexZAZzBSCAWKkODbYXcA12DvoBuokaz5VvKkBVZD9aGak6zCkcqMzk9THcPFUBmPPWx8LdrEGQmloJmnv/t7DVCJvYkuQrVj7k1IdtCFC31RzHz5sZaGn2zR7hosNjjWb92EfPX0qA1X//Y/oj7u4Zk4LaP3xb9nYyecZCALXDXzDmYPAolX1iQnFeKfjbWWf7tbLj+1LzVikch6Db3UX6SqqMcnR9g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from HK2APC01FT003.eop-APC01.prod.protection.outlook.com (10.152.248.51) by HK2APC01HT145.eop-APC01.prod.protection.outlook.com (10.152.249.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2495.25; Mon, 9 Dec 2019 12:59:51 +0000 Received: from PSXP216MB0438.KORP216.PROD.OUTLOOK.COM (10.152.248.51) by HK2APC01FT003.mail.protection.outlook.com (10.152.248.173) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2495.25 via Frontend Transport; Mon, 9 Dec 2019 12:59:50 +0000 Received: from PSXP216MB0438.KORP216.PROD.OUTLOOK.COM ([fe80::20ad:6646:5bcd:63c9]) by PSXP216MB0438.KORP216.PROD.OUTLOOK.COM ([fe80::20ad:6646:5bcd:63c9%11]) with mapi id 15.20.2516.018; Mon, 9 Dec 2019 12:59:50 +0000 From: Nicholas Johnson To: "linux-kernel@vger.kernel.org" CC: "linux-pci@vger.kernel.org" , Bjorn Helgaas , Mika Westerberg , Benjamin Herrenschmidt , Logan Gunthorpe , Nicholas Johnson Subject: [PATCH v12 1/4] PCI: Consider alignment of hot-added bridges when distributing available resources Thread-Topic: [PATCH v12 1/4] PCI: Consider alignment of hot-added bridges when distributing available resources Thread-Index: AQHVrpCKw/jSqscLuUygM8Wo72oCqQ== Date: Mon, 9 Dec 2019 12:59:50 +0000 Message-ID: Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SY2PR01CA0020.ausprd01.prod.outlook.com (2603:10c6:1:14::32) To PSXP216MB0438.KORP216.PROD.OUTLOOK.COM (2603:1096:300:d::20) x-incomingtopheadermarker: OriginalChecksum:305BD8B41944432731A3F8CCD31A1C90C27119A7FDAEB7EE77D0B6FEF2D73A3B;UpperCasedChecksum:DD3A3D451854E4D28EBC50871CABC14836D8008F2BCE265041A2DF63255EB781;SizeAsReceived:7644;Count:47 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [IRjDK5xfcaUPOUNXREy3l5piBIWNb7ZnkiTYyLGsG5Oe6kJl1I4ZWUpqXu6+J3oOvLFmF5rD3Do=] x-microsoft-original-message-id: <20191209125941.GA3009@nicholas-dell-linux> x-ms-publictraffictype: Email x-incomingheadercount: 47 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: c9f8bc59-a69b-412f-aacb-08d77ca7ad30 x-ms-exchange-slblob-mailprops: inBjZRGSCZnDtjlsTQkDSW/U0MH078bZbYz0PV88+XbGdkPGzfBitNHm6hoVltFJK9p6L2o+hVKLWOHoOBapf7/gTkuJ64vN9/Wmi4ncDg9XgU6Yu6otUeviLDqRZd/49h0bqI22wVAn+qrapGzULXNo7WxhKA61e8Pxl9lqYg7Vk7l51n2UhW+3hHzFKPyBus6Itj1l4EvdMVg0/7bJEWnj96YE7PFUpoMqv8plgILLeMC6uVXyJ8ec2kDbtfiuGsF1qwugTkH1Z07drZdaviXdRVC6SOCfaN0p6LwcU0PT9SXthMQFNw0PbQQNYqDQL2NNjfSBclntaLcF7CpeQinoR/w22vED/Ip7x+Gcy3NR/55XjmYo0VNof5ByVACVkqsX5r8UyPH19cD52HFcsiwtcP9YtJVMAoRVnZQ2xQwHVyiN3hl5G8jyOsdYpD65EkJU0C89TMAHV7XdfAo+m5A3ZjYezBdRp7KgFpP0thB5dyBd4afefUMGZqFI6JN8va8N5HzeSVhBYDBtLhTtl/X/kMmR1vU6dD43AsSNstFWL6OtIRgJrvGlebD+zt0CtuSr/NWZTCuvQZ8dLu5vUQDj6nblJwmFdWgbAIP6Tvq8B84Dd2LegH0Eg17QfrwSdzw6wXC5DZRPnlHT1svjBaghl3P/KV8+9NbbVtTsJ+/piHmgX0rjuBl3cDBPzbCK3Lc+KBWh8j9z99H7QBrmtuJKUETjhyTEgWPDUZPzzrEGzpzIO6rwUha5wsZwHLsXthbc+thXW6l1o0iUdIop51iOhydDkpvtixUheg4ubG+o8oUlGenqFyQlM1uQd4N3IsY70McOCxbF0EPBD3kOtsUHxGm6GRiGqdutvb8MFxv/b14nG4Qj6q2YlmDrJmzoapTxs147u/bvi/JHIdhZ8YDzScTx13LmK+An1kgbGbxVSPdc/yXCsLPecIOIh0cYoA7C2k8bYUXbjY2IvMjh2Q== x-ms-traffictypediagnostic: HK2APC01HT145: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Ds1LkNy06jo/vzNSk3GfAuNZRLLYxxjaZRfKcIGsf8OfjJnI4CANoTNQ0YC18YXB2fepyorll2pdqczer7XcBlNOJzn0Ko5bSH/hjqJPLgUEcIrNZLxcUOK6TUNIo8ljco05I4JCaCVa6S1RYihyv2wBNtQJoZvRJHVOEcFQF9iXqHjelJYRgKi1SHDQPGqyvpzPx+XiY2GS4J0jbvZ+Fkvzyqyrp6OZ5ceb96Io8mM= x-ms-exchange-transport-forked: True Content-ID: <926ECF76B8852B4CA2663EE1D4AE59C9@KORP216.PROD.OUTLOOK.COM> 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: c9f8bc59-a69b-412f-aacb-08d77ca7ad30 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Dec 2019 12:59:50.6953 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK2APC01HT145 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Rewrite pci_bus_distribute_available_resources to better handle bridges with different resource alignment requirements. Pass more details arguments recursively to track the resource start and end addresses relative to the initial hotplug bridge. This is especially useful for Thunderbolt with native PCI enumeration, enabling external graphics cards and other devices with bridge alignment higher than 1MB. Link: https://bugzilla.kernel.org/show_bug.cgi?id=199581 Reported-by: Mika Westerberg Tested-by: Mika Westerberg Signed-off-by: Nicholas Johnson Reviewed-by: Mika Westerberg --- drivers/pci/setup-bus.c | 148 +++++++++++++++++++--------------------- 1 file changed, 71 insertions(+), 77 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index f27982620..8c990f981 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1858,12 +1858,10 @@ static void extend_bridge_window(struct pci_dev *bridge, struct resource *res, } static void pci_bus_distribute_available_resources(struct pci_bus *bus, - struct list_head *add_list, - resource_size_t available_io, - resource_size_t available_mmio, - resource_size_t available_mmio_pref) + struct list_head *add_list, struct resource io, + struct resource mmio, struct resource mmio_pref) { - resource_size_t remaining_io, remaining_mmio, remaining_mmio_pref; + resource_size_t io_per_hp, mmio_per_hp, mmio_pref_per_hp, align; unsigned int normal_bridges = 0, hotplug_bridges = 0; struct resource *io_res, *mmio_res, *mmio_pref_res; struct pci_dev *dev, *bridge = bus->self; @@ -1873,15 +1871,29 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, mmio_pref_res = &bridge->resource[PCI_BRIDGE_RESOURCES + 2]; /* - * Update additional resource list (add_list) to fill all the - * extra resource space available for this port except the space - * calculated in __pci_bus_size_bridges() which covers all the - * devices currently connected to the port and below. + * The alignment of this bridge is yet to be considered, hence it must + * be done now before extending its bridge window. */ - extend_bridge_window(bridge, io_res, add_list, available_io); - extend_bridge_window(bridge, mmio_res, add_list, available_mmio); + align = pci_resource_alignment(bridge, io_res); + if (!io_res->parent && align) + io.start = ALIGN(io.start, align); + + align = pci_resource_alignment(bridge, mmio_res); + if (!mmio_res->parent && align) + mmio.start = ALIGN(mmio.start, align); + + align = pci_resource_alignment(bridge, mmio_pref_res); + if (!mmio_pref_res->parent && align) + mmio_pref.start = ALIGN(mmio_pref.start, align); + + /* + * Update the resources to fill as much remaining resource space in the + * parent bridge as possible, whilst considering alignment. + */ + extend_bridge_window(bridge, io_res, add_list, resource_size(&io)); + extend_bridge_window(bridge, mmio_res, add_list, resource_size(&mmio)); extend_bridge_window(bridge, mmio_pref_res, add_list, - available_mmio_pref); + resource_size(&mmio_pref)); /* * Calculate how many hotplug bridges and normal bridges there @@ -1902,108 +1914,90 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, */ if (hotplug_bridges + normal_bridges == 1) { dev = list_first_entry(&bus->devices, struct pci_dev, bus_list); - if (dev->subordinate) { + if (dev->subordinate) pci_bus_distribute_available_resources(dev->subordinate, - add_list, available_io, available_mmio, - available_mmio_pref); - } + add_list, io, mmio, mmio_pref); return; } - if (hotplug_bridges == 0) - return; - /* - * Calculate the total amount of extra resource space we can - * pass to bridges below this one. This is basically the - * extra space reduced by the minimal required space for the - * non-hotplug bridges. + * Reduce the available resource space by what the bridge and devices + * below it occupy. */ - remaining_io = available_io; - remaining_mmio = available_mmio; - remaining_mmio_pref = available_mmio_pref; - for_each_pci_bridge(dev, bus) { - const struct resource *res; + resource_size_t used_size; + struct resource *res; if (dev->is_hotplug_bridge) continue; - /* - * Reduce the available resource space by what the - * bridge and devices below it occupy. - */ res = &dev->resource[PCI_BRIDGE_RESOURCES + 0]; - if (!res->parent && available_io > resource_size(res)) - remaining_io -= resource_size(res); + align = pci_resource_alignment(dev, res); + align = align ? ALIGN(io.start, align) - io.start : 0; + used_size = align + resource_size(res); + if (!res->parent && used_size <= resource_size(&io)) + io.start += used_size; res = &dev->resource[PCI_BRIDGE_RESOURCES + 1]; - if (!res->parent && available_mmio > resource_size(res)) - remaining_mmio -= resource_size(res); + align = pci_resource_alignment(dev, res); + align = align ? ALIGN(mmio.start, align) - mmio.start : 0; + used_size = align + resource_size(res); + if (!res->parent && used_size <= resource_size(&mmio)) + mmio.start += used_size; res = &dev->resource[PCI_BRIDGE_RESOURCES + 2]; - if (!res->parent && available_mmio_pref > resource_size(res)) - remaining_mmio_pref -= resource_size(res); + align = pci_resource_alignment(dev, res); + align = align ? ALIGN(mmio_pref.start, align) - + mmio_pref.start : 0; + used_size = align + resource_size(res); + if (!res->parent && used_size <= resource_size(&mmio_pref)) + mmio_pref.start += used_size; } + if (!hotplug_bridges) + return; + /* - * Go over devices on this bus and distribute the remaining - * resource space between hotplug bridges. + * Distribute any remaining resources equally between + * the hotplug-capable downstream ports. */ - for_each_pci_bridge(dev, bus) { - resource_size_t align, io, mmio, mmio_pref; - struct pci_bus *b; + io_per_hp = div64_ul(resource_size(&io), hotplug_bridges); + mmio_per_hp = div64_ul(resource_size(&mmio), hotplug_bridges); + mmio_pref_per_hp = div64_ul(resource_size(&mmio_pref), + hotplug_bridges); - b = dev->subordinate; - if (!b || !dev->is_hotplug_bridge) + for_each_pci_bridge(dev, bus) { + if (!dev->subordinate || !dev->is_hotplug_bridge) continue; - /* - * Distribute available extra resources equally between - * hotplug-capable downstream ports taking alignment into - * account. - */ - align = pci_resource_alignment(bridge, io_res); - io = div64_ul(available_io, hotplug_bridges); - io = min(ALIGN(io, align), remaining_io); - remaining_io -= io; - - align = pci_resource_alignment(bridge, mmio_res); - mmio = div64_ul(available_mmio, hotplug_bridges); - mmio = min(ALIGN(mmio, align), remaining_mmio); - remaining_mmio -= mmio; + io.end = io.start + io_per_hp - 1; + mmio.end = mmio.start + mmio_per_hp - 1; + mmio_pref.end = mmio_pref.start + mmio_pref_per_hp - 1; - align = pci_resource_alignment(bridge, mmio_pref_res); - mmio_pref = div64_ul(available_mmio_pref, hotplug_bridges); - mmio_pref = min(ALIGN(mmio_pref, align), remaining_mmio_pref); - remaining_mmio_pref -= mmio_pref; + pci_bus_distribute_available_resources(dev->subordinate, + add_list, io, mmio, mmio_pref); - pci_bus_distribute_available_resources(b, add_list, io, mmio, - mmio_pref); + io.start += io_per_hp; + mmio.start += mmio_per_hp; + mmio_pref.start += mmio_pref_per_hp; } } static void pci_bridge_distribute_available_resources(struct pci_dev *bridge, struct list_head *add_list) { - resource_size_t available_io, available_mmio, available_mmio_pref; - const struct resource *res; + struct resource io, mmio, mmio_pref; if (!bridge->is_hotplug_bridge) return; /* Take the initial extra resources from the hotplug port */ - res = &bridge->resource[PCI_BRIDGE_RESOURCES + 0]; - available_io = resource_size(res); - res = &bridge->resource[PCI_BRIDGE_RESOURCES + 1]; - available_mmio = resource_size(res); - res = &bridge->resource[PCI_BRIDGE_RESOURCES + 2]; - available_mmio_pref = resource_size(res); + io = bridge->resource[PCI_BRIDGE_RESOURCES + 0]; + mmio = bridge->resource[PCI_BRIDGE_RESOURCES + 1]; + mmio_pref = bridge->resource[PCI_BRIDGE_RESOURCES + 2]; - pci_bus_distribute_available_resources(bridge->subordinate, - add_list, available_io, - available_mmio, - available_mmio_pref); + pci_bus_distribute_available_resources(bridge->subordinate, add_list, + io, mmio, mmio_pref); } void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge) From patchwork Mon Dec 9 13:00:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 11279337 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CB667139A for ; Mon, 9 Dec 2019 13:00:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AB9812077B for ; Mon, 9 Dec 2019 13:00:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727527AbfLINAR convert rfc822-to-8bit (ORCPT ); Mon, 9 Dec 2019 08:00:17 -0500 Received: from mail-oln040092253049.outbound.protection.outlook.com ([40.92.253.49]:30694 "EHLO APC01-SG2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727268AbfLINAR (ORCPT ); Mon, 9 Dec 2019 08:00:17 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Up+ht78xis5Co+579LnR55e+j3LvjM1bP1AkUK8hs+4ziUf0+raS/Cu1mAyBjPXxM8fHn50MOKTie8TvZ8347OrBXmeoBI8bE8cqzkKM4gx9bTN+UK7oV4ThbgYyBxZLDo9JEqg7Y8fyzlTHL/KwNs8VPngwveHFLi0uaM28iDzQg8xGmX6SslTDHC9zGWBoO7tu4zEKSVTTMLDY+WcLz4rRuMoMWfs9vyCLlDzXOuJK03kykK71uqe79Ha+ZXBMI3Ka/5VhL01vGT3cEyCzQFXmV0jlyiWRIINyR65Hhlp4m1+qMKphKcvAg3LpcP75BDBaFfPjssrXONEN+gtYSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=D/OELDpQxPcZGJ+sYL7LWncgmwYxkHmP76LLvMuNy0E=; b=UoCQlt43hFrGavEjVO4ek35j+BLI2mo1iqmQM0dA4O3izfy/BjGnhriPm32ByXL8o5HH8v9TXB8jXrJMRTkUuqTpB5fuESh0d+EoLTjHvw9Mk2ggwQB8T24JV6goU7XjV2O8NEHnsi0GhzFG3aRIp/Y7rzp13SPMbYo419Fe47xgsFGdgmeRB1XRCkifYc2n+DKwSJxOIOtLnfZTAB7HKxbnW3xikDL1nXH4UjbD+MqwWFB2v2LY7EpGEFrEBmwZgETDIe2z75NFd4F+GbTBSVeTOvB592Ly9+NBDvn4vhuO7zODjlw/O603+MmHQIsTDUm6p6PpPOCr0SCm7401sw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from HK2APC01FT003.eop-APC01.prod.protection.outlook.com (10.152.248.60) by HK2APC01HT090.eop-APC01.prod.protection.outlook.com (10.152.249.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2495.25; Mon, 9 Dec 2019 13:00:11 +0000 Received: from PSXP216MB0438.KORP216.PROD.OUTLOOK.COM (10.152.248.51) by HK2APC01FT003.mail.protection.outlook.com (10.152.248.173) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2495.25 via Frontend Transport; Mon, 9 Dec 2019 13:00:11 +0000 Received: from PSXP216MB0438.KORP216.PROD.OUTLOOK.COM ([fe80::20ad:6646:5bcd:63c9]) by PSXP216MB0438.KORP216.PROD.OUTLOOK.COM ([fe80::20ad:6646:5bcd:63c9%11]) with mapi id 15.20.2516.018; Mon, 9 Dec 2019 13:00:10 +0000 From: Nicholas Johnson To: "linux-kernel@vger.kernel.org" CC: "linux-pci@vger.kernel.org" , Bjorn Helgaas , Mika Westerberg , Benjamin Herrenschmidt , Logan Gunthorpe , Nicholas Johnson Subject: [PATCH v12 2/4] PCI: In extend_bridge_window() change available to new_size Thread-Topic: [PATCH v12 2/4] PCI: In extend_bridge_window() change available to new_size Thread-Index: AQHVrpCWg3aFUt9ZDEGlAJkcxWcZHQ== Date: Mon, 9 Dec 2019 13:00:10 +0000 Message-ID: Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SYCPR01CA0030.ausprd01.prod.outlook.com (2603:10c6:10:e::18) To PSXP216MB0438.KORP216.PROD.OUTLOOK.COM (2603:1096:300:d::20) x-incomingtopheadermarker: OriginalChecksum:B8E8E4D305F5CA5F9FBFADDB8085BC9A52C3273AC35A60005421D1D3BF7F7E24;UpperCasedChecksum:63C8097933FAA77927E3901A5A37076C332924CB1592398B963EF552A1195128;SizeAsReceived:7614;Count:47 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [85xwPnOG6tmid0HD9eiGeyjyPwoSAti/w1kfwH9WuYL0cE8u4qm2Pkwtw4f2VZcC6vgYUI6wuXo=] x-microsoft-original-message-id: <20191209130002.GA3011@nicholas-dell-linux> x-ms-publictraffictype: Email x-incomingheadercount: 47 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 387a718d-39bf-47df-2060-08d77ca7b940 x-ms-exchange-slblob-mailprops: kw4jv30d2yRo2VVZljeoS8aHjULAHTRDe5X9jSqjsfHoA0Kj3RdYWEHFOtFIgunR3BPRk9g8fRZF/PjhFn9NY7ropYRD2qAWustIQffx1gvUVh97/PkCUFul/IW3LrJUXtewsw1treiG3E74kW7MdqeFMGuwDszC/HqeQ4hKe/MbTVtxZAvtPQ5qXgpmDPwZGdYELqqCN7t1i2wCQwWjAcbgG3gT3MoiEaOLRrBUNKudNC6qE2spi4+urOub5g5asVbnArmhO8x5YQljSX+gnokLbnEn+y/U2euO76kjqM8xXi7oSYnu+qTscTzNlFw1fCjeba90vAtmkhYKLv5r6KGCF5a/HsqzG2aLDIn/ui4vZoQbXtFmdXtyS2qp6HpCsY4smMQc8p1lNJN71vVlohfT2H/aUb0SFraIb7ZnIFVligKA7WIxwavKWT1D01fPumB6lFgNf8RKkO+Wmp07ZoaJFQFGrkn1ezRB41nFv8u+pznrdnle8wpgXVRNtyiHXGSKeRymRrW0/TjYaBIHWtceRZDlwafXPaHXi7+VJSoO/pHuknVZhGrcuurdfggfZCZ0KwYuGNUtwTTYzsBQ5WtldyrVhASgP56vNDfjXlAwAJTQeqSk6Vz5wrQs0TYnRscSYbqiYoTfrM3IrzmLizzIdXHsKY+94LSVvDw2AQ8= x-ms-traffictypediagnostic: HK2APC01HT090: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: tn/XwKzuzr8/8OzC9Uvo1Na4KyStxY21itj7N9gLiJiEQuIDh7ruC9k9Yt3qTeQDlmyYHp12ITsHsiH9hYsjadEdYKKw/7IDBT07HfcCQPQZv0BuG4EQRdyhOSg2rTWYaj7ph8nJij+IY+a7NB7dgKnzysOOy+jVcZrywfzPAuJfnp/PkRJSWbX0Ijh+ChwE x-ms-exchange-transport-forked: True Content-ID: <7063E438C3EC3340A0466CC948A02314@KORP216.PROD.OUTLOOK.COM> 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: 387a718d-39bf-47df-2060-08d77ca7b940 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Dec 2019 13:00:10.8443 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK2APC01HT090 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org In extend_bridge_window() change "available" parameter name to new_size. This makes more sense as this parameter represents the new size for the window. Signed-off-by: Nicholas Johnson Reviewed-by: Mika Westerberg --- drivers/pci/setup-bus.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 8c990f981..165a62a79 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1834,14 +1834,14 @@ 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) + resource_size_t new_size) { struct pci_dev_resource *dev_res; if (res->parent) return; - if (resource_size(res) >= available) + if (resource_size(res) >= new_size) return; dev_res = res_to_dev_res(add_list, res); @@ -1849,10 +1849,10 @@ static void extend_bridge_window(struct pci_dev *bridge, struct resource *res, return; /* Is there room to extend the window? */ - if (available - resource_size(res) <= dev_res->add_size) + if (new_size - resource_size(res) <= dev_res->add_size) return; - dev_res->add_size = available - resource_size(res); + dev_res->add_size = new_size - resource_size(res); pci_dbg(bridge, "bridge window %pR extended by %pa\n", res, &dev_res->add_size); } From patchwork Mon Dec 9 13:00:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 11279339 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 687A2139A for ; Mon, 9 Dec 2019 13:00:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 46CD5214AF for ; Mon, 9 Dec 2019 13:00:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727300AbfLINAg convert rfc822-to-8bit (ORCPT ); Mon, 9 Dec 2019 08:00:36 -0500 Received: from mail-oln040092255094.outbound.protection.outlook.com ([40.92.255.94]:27680 "EHLO APC01-HK2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727496AbfLINAg (ORCPT ); Mon, 9 Dec 2019 08:00:36 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dOjM2v/IVv8L6G2rs6VN/WDIlwUEZjPci1p7LHafS+f0XNsM0ipvqIDH5jjVCYih9oknkHTW+RbeEm6jCPpAFuJ6CRzEmjAQSzKXxER6uzUerNxP4w0PD9faXFQWvB8DA530MpQJM6+DfJppq1PnwoYUJZmSBqsCstpaErJU8PfvW+j294nWeu1iKNGg7Bpfvs6iYlVllOGpDoauENVFW7ygnjxEH4SrfHH3dLquTp5CmPXqTgrjgK3WOfM3SFcM996mHfOFWEbG/f2oDWIpWirIZpjjINEVjWxIqDyGOb2bYzdnFQ4BjSajqrILzKaFqmotVj9k33g9Y7jTQo974w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uyt+eS3rEXrUvomE+zlLjW5+zb4U5Tjm1OM05kjNPc4=; b=d5QXl73oqbbmnmS72jF+iqO9CfZlLxsRGD7Ikxp93BEhIJyH0+lTsibm60FT2KZpg4ZzDLhN2TmvRx/m/xo/Z7fRzm22afqBUofGML+Av3MKSyK1DBeLuC56+ZLbUSIS6v95RKxQQZcixztHwMns8IgZrEB9UdfgUSYa/XaxcKNRqfqhFJZY0h8q89JPafBtHH4pohh+fcVXR4uUvonkecEcD5ZEXin2ouLH9XLSVxOhUh35sBlwBfbgNfV4YpX26GkP5AkRGPi2FSEXPGVn/f3G9t8277tuFxg+QclxRG04WNeSeMKUZnoywLr7gDb21yYdTs5q5VwQ2bPpuAqH4g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from HK2APC01FT003.eop-APC01.prod.protection.outlook.com (10.152.248.53) by HK2APC01HT050.eop-APC01.prod.protection.outlook.com (10.152.249.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2495.25; Mon, 9 Dec 2019 13:00:31 +0000 Received: from PSXP216MB0438.KORP216.PROD.OUTLOOK.COM (10.152.248.51) by HK2APC01FT003.mail.protection.outlook.com (10.152.248.173) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2495.25 via Frontend Transport; Mon, 9 Dec 2019 13:00:31 +0000 Received: from PSXP216MB0438.KORP216.PROD.OUTLOOK.COM ([fe80::20ad:6646:5bcd:63c9]) by PSXP216MB0438.KORP216.PROD.OUTLOOK.COM ([fe80::20ad:6646:5bcd:63c9%11]) with mapi id 15.20.2516.018; Mon, 9 Dec 2019 13:00:31 +0000 From: Nicholas Johnson To: "linux-kernel@vger.kernel.org" CC: "linux-pci@vger.kernel.org" , Bjorn Helgaas , Mika Westerberg , Benjamin Herrenschmidt , Logan Gunthorpe , Nicholas Johnson Subject: [PATCH v12 3/4] PCI: Change extend_bridge_window() to set resource size directly Thread-Topic: [PATCH v12 3/4] PCI: Change extend_bridge_window() to set resource size directly Thread-Index: AQHVrpCjhCjAA/xwlE6P73k2zd/lCg== Date: Mon, 9 Dec 2019 13:00:31 +0000 Message-ID: Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SYCP282CA0004.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:80::16) To PSXP216MB0438.KORP216.PROD.OUTLOOK.COM (2603:1096:300:d::20) x-incomingtopheadermarker: OriginalChecksum:21A0B1BDED5DBF529341CBFA621B7AD740CE53C748A8F0F349AAF7E791CC9D6B;UpperCasedChecksum:27AE4DD4FD3EC513D4AE0D8E26601F16A04D54D121314D66BD7CAA36127A8992;SizeAsReceived:7609;Count:47 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [UTLs0FqE+KsUCBIt6eNaraNujQiCj7BdKio3RaODShE2a67NS0T5AtatK7Tgh9gRx23J1TJLhkw=] x-microsoft-original-message-id: <20191209130022.GA3014@nicholas-dell-linux> x-ms-publictraffictype: Email x-incomingheadercount: 47 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 86a71aca-d33a-4325-a636-08d77ca7c56b x-ms-exchange-slblob-mailprops: FNsJQuRXwPqc5X5QZ6YF1p9pz8sDL8bcDHnxvHwZx/PjB1vs5ZdyFBFekSWm+KWydMSeinxmI1fia9mUyxKBsenmKK2P48Bn7PAomLPEDX/BFMkl8dP3EV4lNXEPuVaiolumN6os+yWskyxFIbVmnFuqXnkfUuYfKybaZ2fwE5ohT6T7Wn1xQ2h9r+77O6aV2arn2U/OygUYf7SjgoXiG+hWxxcmX6R8zmuqA8jpiz+q2ZzjBuaPI3MMyI7UG+R/RbnFJJT9pktno2YUvpva0XZGXNrh+4rfaOBaZlVrlhw+ztFOPEztlAldKz57uFFkbpQEWzINT8kIBX7FhPZ4ut1LSE87gNcdvkjToIZTVg8M22ttdCQa16/mQjeqt86MUkb9sRvNKxDrsj2EZk9/qLMPgqBSC1Q55UMdLpLeDyu4BY+WLrJqJFtHeq9Htw6jxG5cTlOBE2hm2bqWG7Idy4Orl/6jxYQWZC0b2gGjowjlrn8rkEEomhZC+5QPzdqMziwmj9ylSFn2fKZOgVxPPdRwNMF3GyppHcU1PMES8K+L4JsoCwrAJI7v8A8gxY71LCgIPja6jJykxKvDrdqTXXC3o5PpkoyDHNTP9Urtc+IaVcUVHRkEjg== x-ms-traffictypediagnostic: HK2APC01HT050: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: fHf651mqi+ejkzSxaWFSkKuaUx71cQZPKEojcvMAQwAwzC05BsBDDoZDQLrFAecTKSTxMn8oTu9LJo7/wAgYoDW2/W8EdiGeVoh8WeLaYVkUWVxvEI6+UPrNyoRS3/PWsf5Wswyf6ccQOEQt8RABJWDfdYcAttQ9GMFO9+zMnTRaAiDyxR5MI3qyWXPy99pv x-ms-exchange-transport-forked: True Content-ID: <038612782B34D24C9E159BA6FD4286C8@KORP216.PROD.OUTLOOK.COM> 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: 86a71aca-d33a-4325-a636-08d77ca7c56b X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Dec 2019 13:00:31.4191 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK2APC01HT050 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Change extend_bridge_window() to set resource size directly instead of using additional resource lists. Because additional resource lists are optional resources, any algorithm that requires guaranteed allocation that uses them cannot be guaranteed to work. Remove the resource from add_list, as a zero-sized additional resource is redundant. Signed-off-by: Nicholas Johnson Reviewed-by: Mika Westerberg --- drivers/pci/setup-bus.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 165a62a79..0e0c8b677 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1836,7 +1836,7 @@ static void extend_bridge_window(struct pci_dev *bridge, struct resource *res, 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; @@ -1844,17 +1844,10 @@ static void extend_bridge_window(struct pci_dev *bridge, struct resource *res, if (resource_size(res) >= new_size) return; - dev_res = res_to_dev_res(add_list, res); - if (!dev_res) - return; - - /* Is there room to extend the window? */ - if (new_size - resource_size(res) <= dev_res->add_size) - return; - - dev_res->add_size = new_size - resource_size(res); - pci_dbg(bridge, "bridge window %pR extended by %pa\n", res, - &dev_res->add_size); + add_size = new_size - resource_size(res); + pci_dbg(bridge, "bridge window %pR extended by %pa\n", res, &add_size); + res->end = res->start + new_size - 1; + remove_from_list(add_list, res); } static void pci_bus_distribute_available_resources(struct pci_bus *bus, From patchwork Mon Dec 9 13:00:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 11279341 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5152D14B7 for ; Mon, 9 Dec 2019 13:00:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2F7502077B for ; Mon, 9 Dec 2019 13:00:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727307AbfLINA5 convert rfc822-to-8bit (ORCPT ); Mon, 9 Dec 2019 08:00:57 -0500 Received: from mail-oln040092254048.outbound.protection.outlook.com ([40.92.254.48]:44146 "EHLO APC01-PU1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727038AbfLINA5 (ORCPT ); Mon, 9 Dec 2019 08:00:57 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ghPnSiS2bR3slrAQz625jnpVwX7oyzb4sIMrn2qCcIrFF58h/ZjUAwgdostbOzQ8Wd2sPVipDrRGh/J9qkUwp+Xdfp5c5jCdFB3+Y+9eBq15ZOlzERuj4qoxV5RgjfBnWVKD0Pg5Kcgf17hBDf9xTPTUpSyoyQgvGaXrp1oWsEXvlAA3tgmzZFrzl4d5tus85jRU/YIS+45hf0tBWCipyXBW39DJV7KpXn6EaNnXxD+sKE6NLP5Yilu7BADMNakWVMqKHeZDmVaRmaGz/LJLqccISQzLnVTri4HvMHbTPy5bG/Gnau5x5UFcgPi+ogHHSHCYY1l0biP788FzHpForw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yfiqzN34SYKlgEbvFx+4dvp3h00h3Xf+NeQ/xHHE9uM=; b=SFGm/scm/vV+dpopVyd+0P0cLXmROs10hYcqDaSJONPFLZv/z2fm/cbjy3PGtQHxeFUC4O8zN8j51NKb9hnWubpfsVWDHKOZKENGNdtSFiknaPRbcN66o8Z50iOUbPqbKO6NMI2XQN8JJ0eLJxGPmo/fc5Y2if4ifBpCNSKHPXCxbvojXt43xG1lEN1xUMrVZyh7XKJY5NF75bVLNGmq3jAD8eRpKq3YQYS+0ADZjukHJ34vC/fSCl4I6JRmhPnjPw9/q1r7AdvLHKD/1OZZzoHsbhss07lVkemptt45YeWhzTEsrTM03cqGLJQ98ZYGsmr5aWXmWjmWYzmFVspWpw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from HK2APC01FT003.eop-APC01.prod.protection.outlook.com (10.152.248.55) by HK2APC01HT194.eop-APC01.prod.protection.outlook.com (10.152.249.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2495.25; Mon, 9 Dec 2019 13:00:51 +0000 Received: from PSXP216MB0438.KORP216.PROD.OUTLOOK.COM (10.152.248.51) by HK2APC01FT003.mail.protection.outlook.com (10.152.248.173) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2495.25 via Frontend Transport; Mon, 9 Dec 2019 13:00:51 +0000 Received: from PSXP216MB0438.KORP216.PROD.OUTLOOK.COM ([fe80::20ad:6646:5bcd:63c9]) by PSXP216MB0438.KORP216.PROD.OUTLOOK.COM ([fe80::20ad:6646:5bcd:63c9%11]) with mapi id 15.20.2516.018; Mon, 9 Dec 2019 13:00:51 +0000 From: Nicholas Johnson To: "linux-kernel@vger.kernel.org" CC: "linux-pci@vger.kernel.org" , Bjorn Helgaas , Mika Westerberg , Benjamin Herrenschmidt , Logan Gunthorpe , Nicholas Johnson Subject: [PATCH v12 4/4] PCI: Allow extend_bridge_window() to shrink resource if necessary Thread-Topic: [PATCH v12 4/4] PCI: Allow extend_bridge_window() to shrink resource if necessary Thread-Index: AQHVrpCvPIyPLGgIT0aVKrLx85Jowg== Date: Mon, 9 Dec 2019 13:00:51 +0000 Message-ID: Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SYYP282CA0016.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:b4::26) To PSXP216MB0438.KORP216.PROD.OUTLOOK.COM (2603:1096:300:d::20) x-incomingtopheadermarker: OriginalChecksum:80C3EB2F81A8A468B085D06868FAF549D412D6C83B2D184D939604642F70FED3;UpperCasedChecksum:B054872A94759315DC83A89DBF2A2B9094D459A0DE929939226AAA364F3471BD;SizeAsReceived:7612;Count:47 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [dZOOw6rEfqlkSrUq9vgwc/up2qRoE85kXEKEMPfX2be8l5KRbuIu2JBqqxWmaaOJel9LMrlLFD4=] x-microsoft-original-message-id: <20191209130042.GA3017@nicholas-dell-linux> x-ms-publictraffictype: Email x-incomingheadercount: 47 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: dffdd2b2-3743-4042-8d71-08d77ca7d162 x-ms-exchange-slblob-mailprops: Zv/SX2iM+5WBO+Hzd/SDavkKHBOvnksd01hJFr3iXCJtXVv218tmSHREHPLp5PjzMFrUVa9edh5xVOtuh1IlKnrhyx/eqMfwjLS45pH+hQA/H+lSCBDm67k1PVziUdpQat3HZ+VKpUgdLP32raZf6L9cYpfy52l4Lw7oie0Garzi5vuSPyj3/2JicpUM8lg2kk/UpY4q8p6py2MGjNT67Ydt/JhjqYcHA92bDSpwPFjC69Qvclf0AYzMz8xTDadV/7i7RhPOa2BzGayTr0gA9YDL18S3pIYwwIC5hReEMO1bQdzmYV4jfnN+6icvmglqlOotTtJkPpmGOgrK/qNuLqTrWTmRnfJPMF+3HrhVT3BGPRV8fT2L2LJZSwgkXvLIPXcBUQvUb64JsNiWtIVsXfS/0+vgNzx6yMLZl0ysaq8HrtZNKhx9iULSposG9PDZrxrn7OP57Kj3PqdaLBn+kVnPA9ExlHM2Jd1j5mj8Dd67xOXY4swkV2yyZmD113Yck7yHFQGGhAIKf4voiHILDFLyik9yaTmKetIYaX1gbjEJ7EgGt7Tx1pwkoDAqg3zpphFrMrMkIgBKLbvOxaJj1BIycQGdGZ+d9vIbQO4lDJM2gx9qV6HqSEabEef9wE7T+3SZQhCf3rT4Vg9yBAQEIzdWA2xoxN+4kkLzWBXdLQUIFmYgi2Ut/udTgXuBwftauC6a8Onr9Yc= x-ms-traffictypediagnostic: HK2APC01HT194: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: GElS8eutZGp8lfwKE1ZwpGLLCi+dKHJhFycZD6CAm0QImSIANV87AbtVWRaK5llTTxngFB2wQmrRfMZWMlUOv3If4fG0sF8eeErugvdKfqgcHgs9Gmp0tptDEmTVHYq5t491UjUCWKYI0+zszDS491Q08ohIvsfmPPADTzsOMi32RB5cME/Wn3Grio4OOCHS x-ms-exchange-transport-forked: True Content-ID: 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: dffdd2b2-3743-4042-8d71-08d77ca7d162 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Dec 2019 13:00:51.5042 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK2APC01HT194 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Remove checks for resource size in extend_bridge_window(). This is necessary to allow the pci_bus_distribute_available_resources() to function when the kernel parameter pci=hpmemsize=nn[KMG] is used to allocate resources. Because the kernel parameter sets the size of all hotplug bridges to be the same, there are problems when nested hotplug bridges are encountered. Fitting a downstream hotplug bridge with size X and normal bridges with non-zero size Y into parent hotplug bridge with size X is impossible, and hence the downstream hotplug bridge needs to shrink to fit into its parent. Add check for if bridge is extended or shrunken and adjust pci_dbg to reflect this. Reset the resource if its new size is zero (if we have run out of a bridge window resource) to prevent the PCI resource assignment code from attempting to assign a zero-sized resource. Rename extend_bridge_window() to adjust_bridge_window() to reflect the fact that the window can now shrink. Signed-off-by: Nicholas Johnson Reviewed-by: Mika Westerberg --- drivers/pci/setup-bus.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 0e0c8b677..22aed6cdb 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1832,22 +1832,29 @@ void __init pci_assign_unassigned_resources(void) } } -static void extend_bridge_window(struct pci_dev *bridge, struct resource *res, +static void adjust_bridge_window(struct pci_dev *bridge, struct resource *res, struct list_head *add_list, resource_size_t new_size) { - resource_size_t add_size; + resource_size_t add_size, size = resource_size(res); if (res->parent) return; - if (resource_size(res) >= new_size) - return; + if (new_size > size) { + add_size = new_size - size; + pci_dbg(bridge, "bridge window %pR extended by %pa\n", res, + &add_size); + } else if (new_size < size) { + add_size = size - new_size; + pci_dbg(bridge, "bridge window %pR shrunken by %pa\n", res, + &add_size); + } - add_size = new_size - resource_size(res); - pci_dbg(bridge, "bridge window %pR extended by %pa\n", res, &add_size); res->end = res->start + new_size - 1; remove_from_list(add_list, res); + if (!new_size) + reset_resource(res); } static void pci_bus_distribute_available_resources(struct pci_bus *bus, @@ -1883,9 +1890,9 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, * Update the resources to fill as much remaining resource space in the * parent bridge as possible, whilst considering alignment. */ - extend_bridge_window(bridge, io_res, add_list, resource_size(&io)); - extend_bridge_window(bridge, mmio_res, add_list, resource_size(&mmio)); - extend_bridge_window(bridge, mmio_pref_res, add_list, + adjust_bridge_window(bridge, io_res, add_list, resource_size(&io)); + adjust_bridge_window(bridge, mmio_res, add_list, resource_size(&mmio)); + adjust_bridge_window(bridge, mmio_pref_res, add_list, resource_size(&mmio_pref)); /*