From patchwork Wed Nov 13 14:07:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 1194283 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=outlook.com.au Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47CmfJ43PLz9sPJ for ; Thu, 14 Nov 2019 01:07:52 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726434AbfKMOHv convert rfc822-to-8bit (ORCPT ); Wed, 13 Nov 2019 09:07:51 -0500 Received: from mail-oln040092254081.outbound.protection.outlook.com ([40.92.254.81]:15767 "EHLO APC01-PU1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726190AbfKMOHv (ORCPT ); Wed, 13 Nov 2019 09:07:51 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mkKBHngWGAS45VAQpG0GtO5Sxap1/DgJY/ZNyQ1SGoSaNvCBve70n6gPdi0aiCxlY2Y/ImghJc2c2CzH8ts4wlWctUvn/jY0KPJBgP5v/OOEY50UVvn/xeOekNanVB4H7yv9TVq9tqNB4Ae2LRLvOjX/C/8Nn3Ij1I/5MmAQlt2BCxEvPctH5HoixXNXtJ6a9Ix3FsbQsTdWYtE1bR70Rwxjk9C7NXaFfPDybCw2qA3rnZvkJOuH4HBP3CdHzKyojQZpdgynH4Icf6l0N8w9T2pqUY0fvWdDNC/L7yWWBZXOS8Fg33dbkvkTRrz7/ppMCIjUKNp0EVKar7/D37e96Q== 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=FXP2TzRbbeY+fqr5HfDW7prpUb9MuvQ4LU6v6T20PaI=; b=m6qTZSv/OR/uFdCtCVqyH9CCpXgf0c/gXh82USG68dQxU4JcKDTDyDg393B7m3NedrEr0ILI1jPjzNxnAvKOiHnUk2jKzOtg5SiuB7pOoNCFWzI9PdiplTUrVjVm6vDKoQMj8S3SFN5UZs6JJMpkSqvlNQQdLlpM/MEx/tF7uv9lRF9QqXUn5GlFgHAeZkMAuVZ9h1UJncFFx6j/d1FhkZXpx+CJ+duTyfkA1FHTFatbGjFM/gFt/eKOxp7yYaDybYctP8MnTOr4rEebucXRiXav9tkxb6Ojh8IOBeMFaLm7U2sfmLZGO84+jILBaKDS+56WPSNIUCEqMaPtlmIqfA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from SG2APC01FT025.eop-APC01.prod.protection.outlook.com (10.152.250.59) by SG2APC01HT082.eop-APC01.prod.protection.outlook.com (10.152.251.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2430.22; Wed, 13 Nov 2019 14:07:43 +0000 Received: from PS2P216MB0755.KORP216.PROD.OUTLOOK.COM (10.152.250.51) by SG2APC01FT025.mail.protection.outlook.com (10.152.250.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2430.22 via Frontend Transport; Wed, 13 Nov 2019 14:07:43 +0000 Received: from PS2P216MB0755.KORP216.PROD.OUTLOOK.COM ([fe80::44f5:f4bb:1601:2602]) by PS2P216MB0755.KORP216.PROD.OUTLOOK.COM ([fe80::44f5:f4bb:1601:2602%9]) with mapi id 15.20.2451.023; Wed, 13 Nov 2019 14:07:42 +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" , "benh@kernel.crashing.org" , "logang@deltatee.com" , Nicholas Johnson Subject: [PATCH v11 1/4] PCI: Consider alignment of hot-added bridges when distributing available resources Thread-Topic: [PATCH v11 1/4] PCI: Consider alignment of hot-added bridges when distributing available resources Thread-Index: AQHVmiu3OgcTMRwsvk20eJUwCNMwtQ== Date: Wed, 13 Nov 2019 14:07:42 +0000 Message-ID: Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SYXPR01CA0088.ausprd01.prod.outlook.com (2603:10c6:0:2e::21) To PS2P216MB0755.KORP216.PROD.OUTLOOK.COM (2603:1096:300:1c::13) x-incomingtopheadermarker: OriginalChecksum:406BB8736E2F2A4D18C5266BA993946C81F754A4B45B9748BFFA1AACE892985D; UpperCasedChecksum:2BBE68D2C820641AD0C51855A180CE8D47CC5761DC610BDB311CFAE6CEB795F4; SizeAsReceived:7726; Count:47 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [/qCbzFqPs0HmALH2/FMs9swGrG7c7t2EMilXNDzp5j0bdk8l+kVsmeLNHiSUOuM7OMVabippH+c=] x-microsoft-original-message-id: <20191113140734.GA3819@nicholas-dell-linux> x-ms-publictraffictype: Email x-incomingheadercount: 47 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 4e04ab76-c87f-4fb2-4d0e-08d76842d9a8 x-ms-exchange-slblob-mailprops: KE5ywuOaN5jF7dXX3ZDU2SplAw6YV8u2U37Af1nkGT6pnkkJjrOMMFLpBdmzOGiJH7ju0TdrMpzRLZbHXMKdScg/D10OAROT3XpteQc5XcseKe8SYeXObfii/8gi8+5x0KZcVCe6g3igqfEHMaOUQoVRcq59BE1wIi4rXnlaNSqS5ok/c3xWhCCuJ2zdIzEyAi50hzmnZ/Y4uDjd4Fg7gjIapnoJCAMQ9gLjFGl54i8DgtO83Z13Kr7BeGMnCyrAswfOf0VZUekRaFJnxI0QcTgmQ+nqt0q7qJrCX1kcHDczuVa107pIZa7Vcuaah4T129+9ZgSvCdX02DTVcX/od2sfGWSKZLsUPuSBWcvyyr1mEvWngFAy9eB55ypKRfKb+YqAd1Hpd0riaUc5IT0VSdO7mrhYWkyno3B6qjP7SGNep+bNoIi92HZbEGEYSp1sWZbJbaRSyo5QFXntXzPrr2Z2zq+2M7svnwXISgYG6eazTh05ugt1C/Ezr4d2B3uaTVzRgBuDsrHJG/yXkXC2UpCwgpcP4xllFlyh663k+tdx+mNv1jYx+AFMUA8xY8d5Ufzpvgkuk76e/O15Dr5PoC9TPrKmScQMXWUZHpc/l5/cswOw/0p0Q9VWNjeGCUjW7fUw2/i5n0kf/xEQBncHbx09mB+H1DqsI+CED8Hj8b0B1IDz3+rAIncNRIc5gDSOIeuYxW6OKDav/rK2ncl/3qn/Cz0GMA9+K3LamkDzxbvZn88AhYoR3Im236Dpcj2AvwwmBw4B4hxooRNy9zwQKH0WEtqZqIZlf2ePT/2Filv7j6R6TCZ5uHRRRS1oxeKdsnij8Gtaw3rJnvtldQnfEnH8zomgsLb6rO4B5YpswPztr82a2K6gI3VHUeInWaRFRWw80DHj7yOW58rh5g0SnLHXMu4Q124Pi4F7Q1BCVAm4UUHE2YRrR6ckUyoiyg68NPiHrR5ov2uVuuhbLFSwUAutUlakxNG0 x-ms-traffictypediagnostic: SG2APC01HT082: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 6VW6JCOPmTVl6aDNQISN+8zTelPV8aRGM95ywG3bimMYmYQnMQdOyrt/KTar4yFc+hXjJDgS7UrY/liIw7dzwbQQl+lh7wmGZzS8yDmiaUyCjGodFCsm+OIRYvCXdOnl2uwyVE5biMHwX4gcEtKVBLohZj85+0WFwVxI6eKYC0ab8UpCTcUh2LVxTziImcf7 x-ms-exchange-transport-forked: True Content-ID: <909C5A9FBC52DC45954B253AC8EC6BE9@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: 4e04ab76-c87f-4fb2-4d0e-08d76842d9a8 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Nov 2019 14:07:42.9068 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2APC01HT082 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 Signed-off-by: Nicholas Johnson Reported-by: Mika Westerberg Tested-by: Mika Westerberg --- drivers/pci/setup-bus.c | 144 +++++++++++++++++++--------------------- 1 file changed, 69 insertions(+), 75 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index e7dbe2170..2e71efccc 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1840,12 +1840,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; @@ -1855,15 +1853,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, while 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 @@ -1884,108 +1896,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; + struct resource *res; + resource_size_t used_size; 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; + + 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); + /* * Go over devices on this bus and distribute the remaining * resource space between hotplug bridges. */ for_each_pci_bridge(dev, bus) { - resource_size_t align, io, mmio, mmio_pref; - struct pci_bus *b; - - b = dev->subordinate; - if (!b || !dev->is_hotplug_bridge) + 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 Wed Nov 13 14:08:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 1194284 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=outlook.com.au Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47Cmfd4CBDz9sQp for ; Thu, 14 Nov 2019 01:08:09 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727392AbfKMOII convert rfc822-to-8bit (ORCPT ); Wed, 13 Nov 2019 09:08:08 -0500 Received: from mail-oln040092255066.outbound.protection.outlook.com ([40.92.255.66]:1472 "EHLO APC01-HK2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726190AbfKMOII (ORCPT ); Wed, 13 Nov 2019 09:08:08 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jlfdVQL+9kdNPxiy11iF9LvoITCKayRilIDEYGJcaeOrplJ8vaAb9bmi/kIQLaijzQ01IPiXjNsMdVFfvXGQRWmhRw8xnilfkDiVdeGzvWvvAIKRwOJbFOXwR+rmGAg4OpydZj6KTXW8GpJFmiWZ5Z4O1Xm1C+kQn0PoTPxgq20rR2aDu8RBIBqSSJguujJVbv0YxDL8JGifwTVbNUrkGGwvT8KtOiSPLx9+SIiXbCokP9xx/WPZNNHYojel3+5EsO8UbxgwSWXVI8Y2A/74dKISnL3tV79BJHqkV8m5yKEYDlYI9R7wXacHqnyLvuLnTTmjXNkh1RhUVgqkI1IrgA== 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=016AO4EuJoE4zJCm1DfO5/6UliGdpqvionRCS7AOw/c=; b=bwGOdMqVyKLqcGMPhOrd8bS9aZ0i+qVPXnKblYeZ/z+yctqGCP1j/LPF9RyyGtqa/uPeZjeAwDIZEpU8c1Ig6txhPTWcpaDE9J9NOQHHYYumKXzTecTmR6G8uK2SxP5UTihVUrPF3Qh6ifJeIKImZhDKczyymJc8LyCfFC9jE/81I49MGvI/xAfNmJY38d4sTHlfKKvB5hNXtuLkk1xcncv/GKPMRd3ZQGkYrtBgIpMdgeasRE4oyqYoYoTlIMwFe2i3DMoKqc+iXBjSxXgLqsTEiQ181ml1h+yaBV2LFhergrhFWUQ5aHeHja6tdDsgpH8XnndKfOUiUTqJIZW5+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from SG2APC01FT025.eop-APC01.prod.protection.outlook.com (10.152.250.58) by SG2APC01HT007.eop-APC01.prod.protection.outlook.com (10.152.250.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2430.22; Wed, 13 Nov 2019 14:08:02 +0000 Received: from PS2P216MB0755.KORP216.PROD.OUTLOOK.COM (10.152.250.51) by SG2APC01FT025.mail.protection.outlook.com (10.152.250.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2430.22 via Frontend Transport; Wed, 13 Nov 2019 14:08:02 +0000 Received: from PS2P216MB0755.KORP216.PROD.OUTLOOK.COM ([fe80::44f5:f4bb:1601:2602]) by PS2P216MB0755.KORP216.PROD.OUTLOOK.COM ([fe80::44f5:f4bb:1601:2602%9]) with mapi id 15.20.2451.023; Wed, 13 Nov 2019 14:08:02 +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" , "benh@kernel.crashing.org" , "logang@deltatee.com" , Nicholas Johnson Subject: [PATCH v11 2/4] PCI: In extend_bridge_window() change available to new_size Thread-Topic: [PATCH v11 2/4] PCI: In extend_bridge_window() change available to new_size Thread-Index: AQHVmivDZMzVZlyS60a00vuWxO1dbQ== Date: Wed, 13 Nov 2019 14:08:02 +0000 Message-ID: Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SYBPR01CA0157.ausprd01.prod.outlook.com (2603:10c6:10:d::25) To PS2P216MB0755.KORP216.PROD.OUTLOOK.COM (2603:1096:300:1c::13) x-incomingtopheadermarker: OriginalChecksum:3E69BFB4D77E8FFD48B2E4B62E5755CAFB473E8D85D7DA810F879EA8A0DA7F29; UpperCasedChecksum:932E01EB8ADC9D641D1ABCE0D1E3FD2C8A4FD2FBB4F18AD4E90D4ABFE6E406B0; SizeAsReceived:7666; Count:47 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [XklBoeGfCqSFwNJvWCGiFOxWIEYpjrifOTzwh8SWvnxpzpvpr/5boIWFaoz0bBuiddeVhMrUPN8=] x-microsoft-original-message-id: <20191113140753.GA3828@nicholas-dell-linux> x-ms-publictraffictype: Email x-incomingheadercount: 47 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: e20bf969-db4f-471e-fd10-08d76842e550 x-ms-exchange-slblob-mailprops: dEG5jEBie8mlFL0Oe7sWpdK/rFF0vM+sqBFUTfSN3SgvpNJ620J+upS+ZENs3ZH3LtMrPWrWmJhE7HrQ2Poghh4acENQbI8mL8RUgppNfHomZrxr4PEAnsllDR5TjjJNpYFF0RxOPoQaDKHheQMARxWVrjryz2JIkHwVH4jOsJVLKPWZu5JJnHb+jabuUj4jxUKyFd9g4JBb9nX9Lr+CO4+MJhMUlAUtp3D6OaFR7mzuHgGZZX1fJS4Ilt0YNh6KGtKvxzhPCQNX67N9vYB+yerPiVxJ27imj3ODab2F4QRQHOz76RfLHlJYoFq4dEZAVdGbIbXqUHqwbnAGXefr05rGSAL/goObDe/k0LXTNMMKB/9P1Lyy03F3dGqjfmOqXj9NftxETitwUWel0PyqxP2DuErD0NaWHaMQ62j1H7NKM3t0AS9Udttpatu/wDGzjeM7JfPt/1ubrXy4MB9Uac0HWcAblDBrYGqJ/brT8lLwSQE5DTmNu8SL8D5QjfUWfbey5if6aJgJ3DepNcN0GHdheMIgz2YX9pS64dlbqUefo/Vwjpvi/mwcE8ytC/6EtXWFJNcn1TUGV+HxdHt0mtPlVPH/EZQrKWrJQVw4CXbQWCQ8CJsE8RMHkic3f/Xta6mtuGjhNsO9J63pIySI05vm2D4OAH0sLoATBZ1xTedxZVM2uhdHiQ== x-ms-traffictypediagnostic: SG2APC01HT007: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 1vfORs9sjOMT+wNWmBP4AtQBKJBAfpOq1KdZftJ636TqCJh0mraGe+2/Pio3g+xyjbAeKoXxF3zLL2/+TeCrFzsvRMloheVMdzmTO2HVWDbtixWLhM2KzcTDlTb3BsKw7AEYeZnB3YlFj1Ob2pIPjl/8a6lebHxUzb6FX4UxY95ERUiYLCc648ufEYRqxuat x-ms-exchange-transport-forked: True Content-ID: <765D4060D2797C43AA3B54A7C9195922@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: e20bf969-db4f-471e-fd10-08d76842e550 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Nov 2019 14:08:02.3873 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2APC01HT007 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 2e71efccc..3f5021f75 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1816,14 +1816,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); @@ -1831,10 +1831,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 Wed Nov 13 14:08:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 1194285 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=outlook.com.au Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47Cmg24lVwz9sQp for ; Thu, 14 Nov 2019 01:08:30 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727386AbfKMOIa convert rfc822-to-8bit (ORCPT ); Wed, 13 Nov 2019 09:08:30 -0500 Received: from mail-oln040092253083.outbound.protection.outlook.com ([40.92.253.83]:36672 "EHLO APC01-SG2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727442AbfKMOI3 (ORCPT ); Wed, 13 Nov 2019 09:08:29 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GizK5QadgCSGa2Tdi9zODWCgs2D8JwvOBPzYYJJNbAdzD40OuPdp/ocuuGOnSx6b2f9VQjUicloMAdgl7z5C1pyL2DUZ0msXavr4D01N1lzZNk8TCWYYNnhJmnbBh/Lct3R1eR11Hdbtxu8AlKW/kqH5B3CKaLbHlWZ5uua/qxh+6P+B+JhOsUmjtnWrqpl56JVb9QMVelk8zJ8j4e4nMBVvmFDt1YQp61KHJdXM6BVnG1ff8ijzaKIOW2kxVEMK6Gu5mjC7FO+vf8C/4TnDu2apxsHUYVl1h8SONodcHWET7jBmQfymJYMCiF+k7TiGexEKjAhgsFULNm7DPa8mjA== 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=581ZR/gUczRXx47GZHadEmMQl+GyaR1Q7Eagms+qo5s=; b=FYX2wM+GtlIxpZbi5r6eVsOyr+2xb3Adbg2E/drxbVfHajXhaho8u9AYc/D6fbSU7jnOTbgW23ifkcPxX+4gNXjHf8Q7EtEw2PFTNMEvWfAkavY6Xhbq0uY+pNnC+d5DDNIKGcy4HpunF/w94dq515YDNdfe+Oof7GHi+DNBKId2O+uRF1CwkZYjTVcEryXkH6gAHoEw2veUGBI6SXVFOYdAZfmf3X432sIWgYHhc3Ka8ATmFJS+bmnStQCB4CKaUoZTvkD4w4JndG88nGlTFCJYqNO5XdlipCAyO/WsYlSZxBb239HzJ/GZK+fQ5b5At96PIXzyI8W0nS3nvS3gQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from SG2APC01FT025.eop-APC01.prod.protection.outlook.com (10.152.250.59) by SG2APC01HT137.eop-APC01.prod.protection.outlook.com (10.152.251.125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2430.22; Wed, 13 Nov 2019 14:08:23 +0000 Received: from PS2P216MB0755.KORP216.PROD.OUTLOOK.COM (10.152.250.51) by SG2APC01FT025.mail.protection.outlook.com (10.152.250.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2430.22 via Frontend Transport; Wed, 13 Nov 2019 14:08:23 +0000 Received: from PS2P216MB0755.KORP216.PROD.OUTLOOK.COM ([fe80::44f5:f4bb:1601:2602]) by PS2P216MB0755.KORP216.PROD.OUTLOOK.COM ([fe80::44f5:f4bb:1601:2602%9]) with mapi id 15.20.2451.023; Wed, 13 Nov 2019 14:08:23 +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" , "benh@kernel.crashing.org" , "logang@deltatee.com" , Nicholas Johnson Subject: [PATCH v11 3/4] PCI: Change extend_bridge_window() to set resource size directly Thread-Topic: [PATCH v11 3/4] PCI: Change extend_bridge_window() to set resource size directly Thread-Index: AQHVmivPNCxNZhdzqEmSlCezLTSMmA== Date: Wed, 13 Nov 2019 14:08:23 +0000 Message-ID: Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SYAPR01CA0033.ausprd01.prod.outlook.com (2603:10c6:1:1::21) To PS2P216MB0755.KORP216.PROD.OUTLOOK.COM (2603:1096:300:1c::13) x-incomingtopheadermarker: OriginalChecksum:C1C5CA3FA17520761497B5B98963D446A905487B2417488C6E3393F1A12D0221; UpperCasedChecksum:673FF22E00789FA487B390623740803CBE215B176D9437C5850D224BD0CE24D1; SizeAsReceived:7672; Count:47 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [PSCYgzLE06U77IVDBCL9JMR6kEDOMmX3WP3pHhVKcUmuLcOIYqBdnuf07weIgynEuTTNVHtT6d8=] x-microsoft-original-message-id: <20191113140814.GA3837@nicholas-dell-linux> x-ms-publictraffictype: Email x-incomingheadercount: 47 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 230cbc23-2dd1-4ecf-4a76-08d76842f1c5 x-ms-exchange-slblob-mailprops: dEG5jEBie8mlFL0Oe7sWpdK/rFF0vM+sWL1qRZrZy241AD5Ig2bURN2uyIBSztpQysq+FzFoRebSSHNY8IWmsqRv6xB7HaBxVN5B+DIdg/aJFlYX/uVRHyZ7PDoCftEShY5+JmNTm3eTOLR4VgR7jn//wXX4vH0rw1oyFVdRWfyrURSjn/9LVMREKWktku/TsovRavMFrmEcidvjyfLZLPG10ZIayo0uKtfZNIIY6wZYEu7bDIruDbYcSj5V+eJD4GAs4VX7fibywsAK03QpPZLBZuSajC8amzD8pzfnEKx9hm0JS/HG+nlh+qnuu3I+HSMDbPy/INuxVkAn89wlWwr8khfa48up0JpU/FmdgKvY06NWUSAdUf0NuPzAWRN4txyG11hqPlhHEv7oo3BUUpd2P1rukRk9/D/SQhDZVY3eMwxr9G9t1stbZOp8oxtlFtuGSiDoarettnh6MDzkcBfArzFN+24gcKbjByQIVnoPWL8Vza6KSUolHnVEhSv60+v6+3cx69YrM42MQyt1/I2GN/qnt2a2TsvrVnkBZsWdB2yMP6VrFR//XrF2gmIwfQ+Hqo959tsRBEsVQccDfxHetzkr2migZahI0pFP2mLj3g4lARtn2oQbQKmN/6BtlxlQ5eRe2b4A95wGQl27H7DOqyaf02qOpFcGuSC5BOwU5gKuwuikhw== x-ms-traffictypediagnostic: SG2APC01HT137: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: XkQm43++lx80niKAloJ27EoGpLjnXkoL4AJ5dL4PlfYKQf6qnxgix9FVBbSgyLt4POWuHU0ICPjPA50LgBBR/HwBpJHsY3oiWgNz33FBI/I9yW6/cln789Nv1lEbm9tD955nzMJeKQWkEYlW9ZwsdeW3aA1BMn1lxby+QeW2hQ1zujwvJ7Zx+rXM5DvMVht4 x-ms-exchange-transport-forked: True Content-ID: <1E4FDC9A2842C2468D24313E8C943E4E@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: 230cbc23-2dd1-4ecf-4a76-08d76842f1c5 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Nov 2019 14:08:23.2422 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2APC01HT137 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 3f5021f75..d83c55169 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1818,7 +1818,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; @@ -1826,17 +1826,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 Wed Nov 13 14:08:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 1194286 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=outlook.com.au Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47CmgR6yqgz9sPJ for ; Thu, 14 Nov 2019 01:08:51 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727472AbfKMOIu convert rfc822-to-8bit (ORCPT ); Wed, 13 Nov 2019 09:08:50 -0500 Received: from mail-oln040092255028.outbound.protection.outlook.com ([40.92.255.28]:20457 "EHLO APC01-HK2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727442AbfKMOIu (ORCPT ); Wed, 13 Nov 2019 09:08:50 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W6sJIi21/M5OWKigPbNQbtf5SDl+tNTFeHr2gfJvnnbTeOeV98n3hlZSzTyExhto4rnorBN4Gd4w3zgXft+uEIlrxhCI4N/6SdtP51DxJJhVaxSW8owVHT5AyiLiLAH3AQGIb9WoylanlAklpYEGTYL5ZoHXf9XYSAOepin34OFQjl3RR8ekEwk7YvGc9xoGN4Glb42AnPmOf6mmd2QEOxZubj5e8O1xWaq5RjGNgZXK+dUE2FD7L1JeW5mdN/TBi8iVGStq3MF+C1RRWmpAB3n8WYXmXNrAlZ6sCipVibm8O/PNjC6ub54uVHfQ70C+q3L3KHzezlWtufcTcumnBw== 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=tX8MrlsAW211GJ4ivkEQ9JbDwZyKaG4Plp2HCKvsMkk=; b=W2mMbCRm9lgJfZK6cToY5GZgQ0eqrcILmWBWtQ6hQwNXEfMwkvhFOhIKi/SY14mt8hl3PFSAiELsnFrH7PC6NOKMnT0+/nCJ5Jzme8UEkk+He72nqbuQ5OAWEFyjc//aORMZkSo+JBzRvffhoJvnytJN+rlOIi21aOiL1UfMqVScHNW1Cmp4Jfzdl/xgHo4BkNhzKY1rIQ+jyudkWk9rEOoMctuVcEqRmstmYSaxtjwUs0ho4BDoybm1ZzvCYRSm3oN8KLS42lGsSTMzFe9CmfRRvYaIGgwdZCukA5rx2OV93gFGFb6NoP/V+wyjRw213cRxuQVhP/HZXtVLQMLQeQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from SG2APC01FT025.eop-APC01.prod.protection.outlook.com (10.152.250.51) by SG2APC01HT113.eop-APC01.prod.protection.outlook.com (10.152.251.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2430.22; Wed, 13 Nov 2019 14:08:43 +0000 Received: from PS2P216MB0755.KORP216.PROD.OUTLOOK.COM (10.152.250.51) by SG2APC01FT025.mail.protection.outlook.com (10.152.250.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2430.22 via Frontend Transport; Wed, 13 Nov 2019 14:08:42 +0000 Received: from PS2P216MB0755.KORP216.PROD.OUTLOOK.COM ([fe80::44f5:f4bb:1601:2602]) by PS2P216MB0755.KORP216.PROD.OUTLOOK.COM ([fe80::44f5:f4bb:1601:2602%9]) with mapi id 15.20.2451.023; Wed, 13 Nov 2019 14:08:42 +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" , "benh@kernel.crashing.org" , "logang@deltatee.com" , Nicholas Johnson Subject: [PATCH v11 4/4] PCI: Allow extend_bridge_window() to shrink resource if necessary Thread-Topic: [PATCH v11 4/4] PCI: Allow extend_bridge_window() to shrink resource if necessary Thread-Index: AQHVmivb8eHIBfYgFkKFMiybT5ykOw== Date: Wed, 13 Nov 2019 14:08:42 +0000 Message-ID: Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SY3PR01CA0127.ausprd01.prod.outlook.com (2603:10c6:0:1b::12) To PS2P216MB0755.KORP216.PROD.OUTLOOK.COM (2603:1096:300:1c::13) x-incomingtopheadermarker: OriginalChecksum:2E3B80BABE0A296F66C43DD06051DBB4EA614DFCB400E69D8FF9531BFAC7BE52; UpperCasedChecksum:A71F6DEA6144EFE3CD520F431EDC9DA5D4188E28148EFC91004CB2C01E06A169; SizeAsReceived:7666; Count:47 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [0MkXgU1rqzU+5cxo0tZN0533TrLEGtIY8UrLf00/ZoIHMV2ndCKnaNKS2/Gv9Ckw] x-microsoft-original-message-id: <20191113140834.GA3839@nicholas-dell-linux> x-ms-publictraffictype: Email x-incomingheadercount: 47 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 7674df3f-79d0-4992-138a-08d76842fd7d x-ms-exchange-slblob-mailprops: gjx25WM8ZNUUcF99Xf9jcIZVmoSE4UEuKZKzQN6lc/wY3oOtgrBiHfY4H1N9QwewqAbH4TH6l7xhSa2uQHfyiIbeEj4hFdPDZNiRZri9MLvzeFDsu/lEfGb3jUd4Miid99VVxAqm8p8UhB+XvNw/0stZzi2WyLEYcPXpWwIeAep9O27r3efTSlwXJTgyyiPhxFz/RLIU1C3O9+rTwTaDuGm6KgJPftXn0SK/bSd5h7iPONaSHKGC82uPBHd4qRVCzl7V+7LQbyrmfVV5ZrF4QKFXwrW231+xTZROMJnYAF2guJaw167sxkRWiGDOmKEpUIQuhxfo1je5ChtOBMx6ATRocuO12XC7QY7wYrLvthvp6mJQq1SVOX4H2w0A1eUYhz7TH3yCpTbj2iudSBbUjmNn11WzeCCOK/I2wwZ6kIGurglKAGMqgwwlUOUY0eEjFeZfU6ewcxsH5ih7pkkKSP7ldL4g5Af8Xpyc+NZ62l68BGFQyb4+zEmmUJE2HbRM6c4cXczhLeJgre7vo2c9o0EcktdGE8F8ssBat35G2bvkJKHWPLpevt/8xMbJjpKN9LyrPUKi7Yd0tCYW0EjQ3vr58HPBO/EkVB+XiwAWhFRHPopOX4IN036NjGF9C1m1BJGpGltsdmVPV8INmys/7Z0UqWGVspGYPW6ajZR2erkztDcpaWmixx/+ylBCRto7bREEyXXhYEg1X3R36jGhl0R3WKKWP02oYMrQr7/3x0U= x-ms-traffictypediagnostic: SG2APC01HT113: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: tlrGXHvttR3aauJAVXDavpAsxmzaVhIrgWmHzmX9BOLWQr/kWgl5vm4QrLhPO1GtkJatz/4BLvnZlH2HT2dCTn4kbS40NygrNSmyro4C9bYBTKL51fE28xghjZBxNT/3dPKr2xrtmX/8+VxSjD7Yk/LfRBVjJFCqW4Lrt3RAJ18wgnyOwF/qnlM5o4I7BRDR x-ms-exchange-transport-forked: True Content-ID: <169E2867B99A974AA67E4A50C2E112D9@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: 7674df3f-79d0-4992-138a-08d76842fd7d X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Nov 2019 14:08:42.9296 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2APC01HT113 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 --- 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 d83c55169..6b64bf909 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1814,22 +1814,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, @@ -1865,9 +1872,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, while 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)); /*