From patchwork Tue Oct 29 15:28:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 11218055 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 141EA112B for ; Tue, 29 Oct 2019 15:28:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D2A75208E3 for ; Tue, 29 Oct 2019 15:28:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389965AbfJ2P2d convert rfc822-to-8bit (ORCPT ); Tue, 29 Oct 2019 11:28:33 -0400 Received: from mail-oln040092253072.outbound.protection.outlook.com ([40.92.253.72]:47232 "EHLO APC01-SG2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2390034AbfJ2P2d (ORCPT ); Tue, 29 Oct 2019 11:28:33 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mb+LOOcu3q4XvftwOSkVd1vB8HM2jDHPi1Wv+4oIK+Hsk3p6DzM3WczuLeVuHpJAXfL5tugeQOqIDhtYOCaPTE6ZW0jnOXfpGl9tQAF5HhNuwcthVt4tVsiRo2UrZO4bRQK1noIsN+mPRAfC2DVAQty1AVKeFEHNV84Ytcp6tvnavWywf2SQUG6sd8GW4z7acI+Y3WEcqAlCVZm6AJprN7A0piPmX02H0l6yFxAstJDtbhCKoMOUdhFd1C16p9GKLK3urAma+A6uzjEE8lrft3fkdvg9daLrL10kMgH7Czqy+gjzJF9l9K+ACMcK6iOCJ89NN93SGJmRCO3YvhME9Q== 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=/xLHuSr6FqdEP5Mt3XmB0egJcPY2SZdnT54+XaXc4cU=; b=BCCnRY6AK2wCdzBoorx1eWvX8YZV+0/v2XK7ttUCKser5j4YNd+2lBXDajPWWjSn3MQ0mZFYmFYVbshx5AYdCMZaOdq9WpVF4NBb8NOShARO10Utww2HNqhKRiFM9ML4XzomVjGFde1mHi6gDC1+l8buE7oF9LsH/gbX4w8t9iQzMr3zgJMJSP6gTlVb2dB2uK0FDgOAuaR8p3+1DuQTWYDJ5gnvB4BmZ4dIULkbEwuNDGouPi7wT10sWrGNMIxycwNWWp745mXJCBU93Olj8okvyfT3PeZhLCLvbSA3yFqcS5u9HbC/5TwyxzAi4OHDVhyOtfeFNeOtjn0yWWOA/Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from PU1APC01FT018.eop-APC01.prod.protection.outlook.com (10.152.252.58) by PU1APC01HT019.eop-APC01.prod.protection.outlook.com (10.152.253.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2387.20; Tue, 29 Oct 2019 15:28:21 +0000 Received: from SL2P216MB0187.KORP216.PROD.OUTLOOK.COM (10.152.252.53) by PU1APC01FT018.mail.protection.outlook.com (10.152.253.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2387.20 via Frontend Transport; Tue, 29 Oct 2019 15:28:21 +0000 Received: from SL2P216MB0187.KORP216.PROD.OUTLOOK.COM ([fe80::ec26:6771:625e:71d]) by SL2P216MB0187.KORP216.PROD.OUTLOOK.COM ([fe80::ec26:6771:625e:71d%8]) with mapi id 15.20.2387.028; Tue, 29 Oct 2019 15:28:21 +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" Subject: [PATCH v9 1/4] PCI: Consider alignment of hot-added bridges when distributing available resources Thread-Topic: [PATCH v9 1/4] PCI: Consider alignment of hot-added bridges when distributing available resources Thread-Index: AQHVjm1/vZ/dokkVoUKpkBYfhzTu5A== Date: Tue, 29 Oct 2019 15:28:21 +0000 Message-ID: Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SYBPR01CA0110.ausprd01.prod.outlook.com (2603:10c6:10:1::26) To SL2P216MB0187.KORP216.PROD.OUTLOOK.COM (2603:1096:100:22::19) x-incomingtopheadermarker: OriginalChecksum:CFA11F12F5E42A4BE191B1FFA583585118F79F2E47C93067E258CEEB6E1DDA62;UpperCasedChecksum:BE278943FBEF3CBAFA13C85BAF63A809E299EEBB8F83E2A138BBE7BD68395679;SizeAsReceived:7558;Count:46 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [jBBJBs5BpJdERD+cSo9Nl0vUzgu51ayHG+2Us6PUM6Fcx8QDq9G4bx8E/xhkWvqGtoU52tQ/kxI=] x-microsoft-original-message-id: <20191029152813.GA1914@nicholas-dell-linux> x-ms-publictraffictype: Email x-incomingheadercount: 46 x-eopattributedmessage: 0 x-ms-traffictypediagnostic: PU1APC01HT019: x-ms-exchange-purlcount: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: evidtvGuMlMiI2MfAmEKyzz41l6WxFMoaQTJD26ZQSZxU1YwtEgMRcjfAcIEiPUKxofe0p5OPFPsUHlvVftqJQ9uqSWBrIw7zl1l9cHFlhcO4351c8hFe9Jnf85XxnFrgTr4rDW7ni83DX91IPC7G1jziM9W0eceDhgXByTG3tB8u2wupyhSCagTFYgsvJkbUuE7qR9Tkwfx2vUOiPWRCAyUgynVpVqKRCaqOR5ZzhE= x-ms-exchange-transport-forked: True Content-ID: <3D9EAC3E622891499EA1375C662F4A59@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: e015c361-1c92-4c4d-3742-08d75c84a152 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Oct 2019 15:28:21.2360 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PU1APC01HT019 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 e7dbe2170..bd8231560 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; + /* - * 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 Tue Oct 29 15:28:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 11218057 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 3EF87112B for ; Tue, 29 Oct 2019 15:28:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1AAB321479 for ; Tue, 29 Oct 2019 15:28:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389836AbfJ2P2r convert rfc822-to-8bit (ORCPT ); Tue, 29 Oct 2019 11:28:47 -0400 Received: from mail-oln040092253020.outbound.protection.outlook.com ([40.92.253.20]:43328 "EHLO APC01-SG2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389809AbfJ2P2r (ORCPT ); Tue, 29 Oct 2019 11:28:47 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KRISFhHDsgw9+M1LjpEf5S2vSIilPxm6vFnHQNUO8d3llKbhg9TAadaSkFAbVXyDqi1AxGe87nPGAn0oNZexJ5Qi5j5h4OQSJ5/ueroJ1OwolT8M4fWeWHkHRSYPbTUaMbi0eOZvaJbfnVHvO0neJluR+F6pfn9PDyxiRKnYpqMnZUCYHt5IEt4AEpfR+KkhiV7aO2Av2ePbJe/IUPa3cbWyTZSenayYyHw4MWJ6WHGj4LcVROE+TAXHSk8opMnsnXumqU6fzIFTU9+xk10PcV1jPtttlksAXVTnx1OyPeIpEIHqmg+Pz9lkP1pmIonB626vNqs6CjuARaXOt8ISyw== 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=Nf10+7z0G+EnfjLVUGDq0Q0zMOOydC/Nljww+JKhsqI=; b=UXkso3ANj7uc6OIoCU0WpFLN+JU0bm9AAozbCvfe2vQhKSr0O6Nj/EwVDxuPFNN+bR1H+8bjIi0TDUtnyXo4ym/Y3gujclRBFdzD+hozRi2a22ighGUQ/+VDgwYzXF27Q4CzqloNedendUbXytzhFlptlMUx0Etnf9MqwAjg4BUR7jDnva9G79sNqBG6ih91DZ7uQlKNvfho9Efu/oRxi7HYo9uwEw4HC549J1yH7qE+MKvYrJyA3YR1T5RvpAPRKlZ2nBfrO5zJQeAjQ1zUveLXi736DR08AHKKwtpHENMj7VPqYAHVht9nlPHa0UEhn88k4H8SwXhJQs3DwQ+nqA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from PU1APC01FT018.eop-APC01.prod.protection.outlook.com (10.152.252.56) by PU1APC01HT139.eop-APC01.prod.protection.outlook.com (10.152.253.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2387.20; Tue, 29 Oct 2019 15:28:41 +0000 Received: from SL2P216MB0187.KORP216.PROD.OUTLOOK.COM (10.152.252.53) by PU1APC01FT018.mail.protection.outlook.com (10.152.253.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2387.20 via Frontend Transport; Tue, 29 Oct 2019 15:28:41 +0000 Received: from SL2P216MB0187.KORP216.PROD.OUTLOOK.COM ([fe80::ec26:6771:625e:71d]) by SL2P216MB0187.KORP216.PROD.OUTLOOK.COM ([fe80::ec26:6771:625e:71d%8]) with mapi id 15.20.2387.028; Tue, 29 Oct 2019 15:28:41 +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" Subject: [PATCH v9 2/4] PCI: In extend_bridge_window() change available to new_size Thread-Topic: [PATCH v9 2/4] PCI: In extend_bridge_window() change available to new_size Thread-Index: AQHVjm2LLNn/YiZQJ0yULwfg3MhJEA== Date: Tue, 29 Oct 2019 15:28:41 +0000 Message-ID: Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SYXPR01CA0120.ausprd01.prod.outlook.com (2603:10c6:0:2d::29) To SL2P216MB0187.KORP216.PROD.OUTLOOK.COM (2603:1096:100:22::19) x-incomingtopheadermarker: OriginalChecksum:9F04E5A710E40A2C0A29EC981344C3B768A3B740FA9051DFBE5036CD06A64C67;UpperCasedChecksum:A0E0CADCC2DF24E05F8A5E625E39AF7AD7890A7468B53E031CD8C8714EF1926A;SizeAsReceived:7506;Count:46 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [RePGtR6Fv6GgIY6BT7CBoANithpt0zuMDa0BaBXJC4mtQCJpU9wJd1BsrAQCUAABrVeSZ6Qz7A8=] x-microsoft-original-message-id: <20191029152833.GA1916@nicholas-dell-linux> x-ms-publictraffictype: Email x-incomingheadercount: 46 x-eopattributedmessage: 0 x-ms-traffictypediagnostic: PU1APC01HT139: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: v3zy3rRiLFFdwnouoKMogu/gPf2COlpZXan8Lm1Ckp4QrLu5rEp7oIR0z/L014ncdQP1wqyu1nFDIA16uMYvuGeDVsSlpeVGkQc+i+ECn95o/6bAeeLA5cBX4iHmnVfiZgY2c02ndsnet62eloNv4p0GFoapdXJjTY9rWcDyW2SbI4JR/1TXEtM1KHVD8NT0 x-ms-exchange-transport-forked: True Content-ID: <6436F55E4AE2694DB1E142D4B1994B24@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: ec8f22cd-9271-4664-c0c8-08d75c84ad45 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Oct 2019 15:28:41.2970 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PU1APC01HT139 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 bd8231560..728bcea26 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 Tue Oct 29 15:29:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 11218059 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 B73BE913 for ; Tue, 29 Oct 2019 15:29:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 92F932087F for ; Tue, 29 Oct 2019 15:29:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390034AbfJ2P3H convert rfc822-to-8bit (ORCPT ); Tue, 29 Oct 2019 11:29:07 -0400 Received: from mail-oln040092253033.outbound.protection.outlook.com ([40.92.253.33]:34112 "EHLO APC01-SG2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389809AbfJ2P3G (ORCPT ); Tue, 29 Oct 2019 11:29:06 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c7XwUagxm2IFi8AE0zGcAaZar8ILvxrr6k2T64XHqS792oEcSpFexo5wOdky7D02af71nFB4qek+8AvBVu/nOV5UoCPT6oK2+poYIJ0QxzlABHa85Q0voo29cI9uzU4/4t28GbLveWcoWuqzhi9eKlXfnsB9lN3lmxBHV0W/IPjIil/YHQ3etYVsI2hUYZJeds/9MD1IHwrAIySGSswpt9mAEUYo5Vg5HpBeiOegxmQMVKgmSNTe96lPNsifCL1iG6IO4x3FVodSVm/nc2Sx2R75KQcG9lx9nSBr1cF+3rzranawUZmSuMF68cAaI+uF/yV2El37ArG0JGBm5k5C6A== 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=HYK4AJq2wVyOdrQ6YBlPBFYX/XCDfpNvP+ELcOZprcU=; b=nw2DA8wxmKB+M1+MhhYn4Qa3S5sRswkMZTeiYDfUKNeluJeKsy4JFr4zcNuBA0OYF489wyNXrYa9SZwV3TnPMxbL1WsuWpEREu4OjGum76HELRV32ui1fV2SinHZNEozQa6iO5g/KHiRrHPjcYbxWNAK7p/JjzM3m421QlPG44FnTGrhMm4kllHqBoxNeasNLGZRumPQBcNuBd0XwrJdI0pMO8GdntgI8ZAD5SIb03BzVXuQQ8HAMik58GtvG1jPVIvtKBQ9OKHF/vRqqKQW6nnVSd1hjbq7rDkcBZoIXWzUIntysybYM8f/FnWK0hQ6HuC1GhwSoxCAwmuEZQjUcw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from PU1APC01FT018.eop-APC01.prod.protection.outlook.com (10.152.252.56) by PU1APC01HT163.eop-APC01.prod.protection.outlook.com (10.152.252.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2387.20; Tue, 29 Oct 2019 15:29:01 +0000 Received: from SL2P216MB0187.KORP216.PROD.OUTLOOK.COM (10.152.252.53) by PU1APC01FT018.mail.protection.outlook.com (10.152.253.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2387.20 via Frontend Transport; Tue, 29 Oct 2019 15:29:01 +0000 Received: from SL2P216MB0187.KORP216.PROD.OUTLOOK.COM ([fe80::ec26:6771:625e:71d]) by SL2P216MB0187.KORP216.PROD.OUTLOOK.COM ([fe80::ec26:6771:625e:71d%8]) with mapi id 15.20.2387.028; Tue, 29 Oct 2019 15:29:01 +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" Subject: [PATCH v9 3/4] PCI: Change extend_bridge_window() to set resource size directly Thread-Topic: [PATCH v9 3/4] PCI: Change extend_bridge_window() to set resource size directly Thread-Index: AQHVjm2XQMTh9lRh7kOUfj+t3LIGAQ== Date: Tue, 29 Oct 2019 15:29:01 +0000 Message-ID: Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SY4P282CA0012.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:a0::22) To SL2P216MB0187.KORP216.PROD.OUTLOOK.COM (2603:1096:100:22::19) x-incomingtopheadermarker: OriginalChecksum:168D4ED821E4AFD6019CA119A412C19D0DF9A3D1BD3925465726D1F6110DDA19;UpperCasedChecksum:CAC918EDFE39E8DFFD298EB4FFD790C08656C21B6C041503731BD0E2AA186CB2;SizeAsReceived:7524;Count:46 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [jbXEeCwWIASggUrjbpQS6lY/YwzSNnIk6OcMWIwZWnBfBDQ9sS/54vb7cmoynhq285C92fEd2H4=] x-microsoft-original-message-id: <20191029152853.GA1918@nicholas-dell-linux> x-ms-publictraffictype: Email x-incomingheadercount: 46 x-eopattributedmessage: 0 x-ms-traffictypediagnostic: PU1APC01HT163: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: vSqDlUzpev1ui0gJR9EHsTOvV3Lt5HQ01jAnnCnRMW07yf3x8cxZvBkBpzAm4Bo60NvbkD2hDaQBCF6f/8XaLWoioUIjkTXENaJYSdtOZ/7iKO4uY9J7TFFv0WcvGUs4+D6wQUbbDUSAZhxd8cdY1sFxADE0bGxS1XnyQWUuhdQL0wGBH3yc37r6586VhhQZ x-ms-exchange-transport-forked: True Content-ID: <8698D41A617D1E468FBA8DC65A28BCB4@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: 29a54a10-1f72-411b-803e-08d75c84b982 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Oct 2019 15:29:01.8128 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PU1APC01HT163 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 728bcea26..fe8b2c715 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 Tue Oct 29 15:29:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 11218061 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 3E387913 for ; Tue, 29 Oct 2019 15:29:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1A9A72087F for ; Tue, 29 Oct 2019 15:29:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390091AbfJ2P32 convert rfc822-to-8bit (ORCPT ); Tue, 29 Oct 2019 11:29:28 -0400 Received: from mail-oln040092254072.outbound.protection.outlook.com ([40.92.254.72]:25713 "EHLO APC01-PU1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389663AbfJ2P32 (ORCPT ); Tue, 29 Oct 2019 11:29:28 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JUl6SJbTnZnOWhL/xN0I1P8CtC6Wj66HY2b9Q1b3hGEF1HtCpZe70COib5Eube1p4972wQRLcA9Js537bWCoQVdQAIN41RWAo+RLkTjAUu5Wxp8pGLkTocBKz7gB3go0+eUBKeHwEaNhqhUtE3emQD8YTGTOGY+3A48pyzQrwKhoKeC2Tdr8daGHfx48LdJ7ugh5TyOM+WACDpD1zhFe6NzBGnrK5dxXrL9J8J/CmD7VQlpUbPTVLD8MOWsuGy2aO/W/GpD320dfqpJ9s6expOsbAGLAExcQ1yUVl10DIRvEZTXum9VOdCYzvBbSFQXkI5O9LUAqwL65//rR2V6oDg== 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=O3AaL0KkuoiKt3XJ7H2UWQw11cz/34REwFpljoWpT24=; b=n9nZdyaGoJARKsJsTyla1+R3ukEecKRd6XK/uUZ2iR/knne1BZW6fx/uDUb2paRP4EHhwWxTuBzaeqL0hb3V2OZM9WdvYogjSySm4aDmYVCL72o/QoOOwOhFzV/Ja7bWFL4PydhREpH/pyUuG/x3qp+ZmeuGDzgb1d/Q9wOoW2a91G5MSd4EIPwiIIog3ns/hFCMWa9Oz09k6QPYMrv3VjyC9b7yEYSkbwnc4Kby2vwPu1frZN2b1e5d+bcKPkqeld02Iz8jD0eE0b8hFwwPvsIyLoXNDzCVdUlm29G66GCtuqM5rFhJXpJfO9xcxij+cYSSVYrwZrv9jXUnZiPhuA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from PU1APC01FT018.eop-APC01.prod.protection.outlook.com (10.152.252.53) by PU1APC01HT089.eop-APC01.prod.protection.outlook.com (10.152.253.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2387.20; Tue, 29 Oct 2019 15:29:22 +0000 Received: from SL2P216MB0187.KORP216.PROD.OUTLOOK.COM (10.152.252.53) by PU1APC01FT018.mail.protection.outlook.com (10.152.253.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2387.20 via Frontend Transport; Tue, 29 Oct 2019 15:29:22 +0000 Received: from SL2P216MB0187.KORP216.PROD.OUTLOOK.COM ([fe80::ec26:6771:625e:71d]) by SL2P216MB0187.KORP216.PROD.OUTLOOK.COM ([fe80::ec26:6771:625e:71d%8]) with mapi id 15.20.2387.028; Tue, 29 Oct 2019 15:29:21 +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" Subject: [PATCH v9 4/4] PCI: Allow extend_bridge_window() to shrink resource if necessary Thread-Topic: [PATCH v9 4/4] PCI: Allow extend_bridge_window() to shrink resource if necessary Thread-Index: AQHVjm2j6KwuziponkGop9V32ZF1Jw== Date: Tue, 29 Oct 2019 15:29:21 +0000 Message-ID: Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SYXPR01CA0109.ausprd01.prod.outlook.com (2603:10c6:0:2d::18) To SL2P216MB0187.KORP216.PROD.OUTLOOK.COM (2603:1096:100:22::19) x-incomingtopheadermarker: OriginalChecksum:680B16EC5A89E42EA5B8FC9AAF9CDDCE9F9F746DDB00B4538319C8B6514C4106;UpperCasedChecksum:E0B4CF29FCF481C1BB134B79A0494155F70CBC4751C4C8169DCC84DDE4E442D1;SizeAsReceived:7519;Count:46 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [UdqF048vL+lXdtlUKD+PNpTGaTGklpDYjM4nEMVaDZuXAJk8QmPmqHnnO3r+f7OeQxPTn9AlpWA=] x-microsoft-original-message-id: <20191029152914.GA1920@nicholas-dell-linux> x-ms-publictraffictype: Email x-incomingheadercount: 46 x-eopattributedmessage: 0 x-ms-traffictypediagnostic: PU1APC01HT089: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: SEJlXf20pqSuQ2xA3fZwj58hduW706oa4wy0RTAlu2wvO0j8nryn+ijKVUOlfFEqc6btPEHI+2MWSljlJIxXpkBAyU8CW8RTRaBqeSJtwtw06eybHzhy7ASMwBT06bdnVdprgAcK8adqXtWSXL/mRJT/tp85PQLjBCmEjDkOpklHw/djDkqCCMHD2AOM8yiP x-ms-exchange-transport-forked: True Content-ID: <1347E0D099E28F44AFCABF12729230CD@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: d642e975-124f-4432-65cb-08d75c84c570 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Oct 2019 15:29:21.7938 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PU1APC01HT089 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 | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index fe8b2c715..f8cd54584 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1814,7 +1814,7 @@ 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) { @@ -1823,13 +1823,20 @@ static void extend_bridge_window(struct pci_dev *bridge, struct resource *res, if (res->parent) return; - if (resource_size(res) >= new_size) - 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 if (new_size < resource_size(res)) { + add_size = resource_size(res) - 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)); /*