From patchwork Wed Nov 13 13:56: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: 11241955 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 16E3016B1 for ; Wed, 13 Nov 2019 13:56:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E2D31206A3 for ; Wed, 13 Nov 2019 13:56:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727452AbfKMN4k convert rfc822-to-8bit (ORCPT ); Wed, 13 Nov 2019 08:56:40 -0500 Received: from mail-oln040092255031.outbound.protection.outlook.com ([40.92.255.31]:45946 "EHLO APC01-HK2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726190AbfKMN4k (ORCPT ); Wed, 13 Nov 2019 08:56:40 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kK7zB3i9SSZjH8PTJZ0DZldFATDT0Ni2rkVFanBEABHOxRHS6cPcWMGV/Xi6QTYqT5crVHQVcBBLSy8jkUITgHQxs+iHEWwYXG0MH7R9UsMXG+87s5Cso75WHQBRnYhD8+BMAExnbHsHj/O+auY3CnH8K0WHQP+PSgUXJ7IZI26IR/j7+1jy0OxtnHpZHjvUR3GXw+HyOCn5ZggpxioAewbvzkBRw+SSYIjmefOCQrtSQhsn26WeLHB9CskRL4Eum9dQaVb+ixdtTm0yksMV/W6AbYgXtygIpEP2ENnUJNF2p2jmp8OZbO3cSw1Nn7eupgjTzBiO/W9HQm5ZQ9pVNg== 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=1Lo8wVNBWQGgp23tAlbWJA3vZbvn8qDfNIMCGXf1DME=; b=IG6w5pZpM+mUpAppjiJdVBjP2/C+bFr3xMw7+O2fIz1CcrnJp1SlDzatHrw19MM4skBfeVqChspKQfSxmkxTufXSRhqVgpN/3AoT5Um7sZ9yKnmeOCCjEzN8uDmH6/lFHzpeM8l5RKYkVpE3oN81XduRuRiDmb5yXfWcZq3rkb2y7t7Zzpu6xoNIaQE5TbpVuOibJ6cN8CYp+kkzgbOHKvD7Zc0WKDPXGA7KrgBgGectZ0xA6I0R7qKXY6oQG6/ySzyw40Gn7uQSX/osVmb0VR9KMxhpJmbR2la2kUnn/QXlaWZUNopyHm/yQGLDrAG/a0DnfvXNLNp3WJeeLmkBTA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from PU1APC01FT035.eop-APC01.prod.protection.outlook.com (10.152.252.57) by PU1APC01HT043.eop-APC01.prod.protection.outlook.com (10.152.253.144) 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 13:56:31 +0000 Received: from PS2P216MB0755.KORP216.PROD.OUTLOOK.COM (10.152.252.57) by PU1APC01FT035.mail.protection.outlook.com (10.152.252.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2451.23 via Frontend Transport; Wed, 13 Nov 2019 13:56:31 +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 13:56:31 +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 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: AQHVmionW5Vccx4lI06a8AnSKZg2ew== Date: Wed, 13 Nov 2019 13:56:31 +0000 Message-ID: Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SY3PR01CA0096.ausprd01.prod.outlook.com (2603:10c6:0:19::29) To PS2P216MB0755.KORP216.PROD.OUTLOOK.COM (2603:1096:300:1c::13) x-incomingtopheadermarker: OriginalChecksum:2E1463CB15FA671BCCBA58F049DA5247C041178DDC41974C57C97904CE0A0897;UpperCasedChecksum:B122233A00DB3CC652348A5B1F2ED1215487554FE11CB996B00DA2509237E1AC;SizeAsReceived:7717;Count:47 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [yrz4/Z7Yxgydo6tMoyjJr2ksk5OApWB5XrYJTY1oGCICWHUBFBnvEGA+Wq2aX10Gn4q2rcbtTTE=] x-microsoft-original-message-id: <20191113135622.GA3216@nicholas-dell-linux> x-ms-publictraffictype: Email x-incomingheadercount: 47 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: ab963db1-a6ab-49b1-0c66-08d7684149a2 x-ms-exchange-slblob-mailprops: KE5ywuOaN5jF7dXX3ZDU2SplAw6YV8u2U37Af1nkGT6pnkkJjrOMMFLpBdmzOGiJH7ju0TdrMpzRLZbHXMKdScg/D10OAROT3XpteQc5XcseKe8SYeXObfii/8gi8+5x0KZcVCe6g3igqfEHMaOUQoVRcq59BE1wIi4rXnlaNSqS5ok/c3xWhCCuJ2zdIzEyAi50hzmnZ/Y4uDjd4Fg7gjIapnoJCAMQ9gLjFGl54i8DgtO83Z13Kr7BeGMnCyrAswfOf0VZUekRaFJnxI0QcTgmQ+nqt0q7qJrCX1kcHDczuVa107pIZa7Vcuaah4T1PXGTx6KO7LX8mujz4XkOmYb8JDm7pBVW7rHlPBlvVC1q4z62gf59Gsodu/kRNPFsSVH6DISSJFbuWDXgEb7cliahllNA/YnX5IuCkXMmcXFvoypD5HsWwPGBn8TKO1ENvUFkZijf08RZj0+J6v8LcX4WIZ30ecVo3+Vs9Zo7DZ3BhgoxcZGqIMZZd4WYP8Rx9PtygQE5oOYAhVMpptXqQGOwq8uSwS+MEdopYUImW2MU4hfNWq4ZnBMtQSNnfaOyZpTZ7yUojZuLJ3QCN2Kr6PPG95p7XacmKu7ITaPIsOuAOgZiSYwy8HqDYIjQxS66li//m9ewqY5Gd1I0m8zqqfFwVbCkbVmRMZqstaBKtrvkl28ivnxm04s1qrwN8sgjgnjeY49x6FdHC8zoCHc4xNOr3Li/bEo04MvIhydTXTZP/mTr/wvxfTJIO89hOCqvOwnoYJq4ZeHxBFHUWOCNUSZNfkk58lc77UlwRAJIVVK1xQKuV+fJyUCcg3bqaOdXauksqrlUxAgHWI5MuQSuZ3iRz+Q3rrQ928lLWPRLG/8jR0y7vfZB/bDouGaOUWKL+KRBzZwWfJpdbceb4HlWwfQzRZFneoLlCALmPg7kK6iquAgFGsPR3eTdAMAOAir/yS0594KcuKhyMSMNyMwHsRGUyaVTofzC x-ms-traffictypediagnostic: PU1APC01HT043: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: jDnIC3B+utzr4jT5UXC+HaQ9I5fou5EGr45YO/0VRrvUmlqCTNMt6BBGX9zLlMwlww9nhGfI0pEr9YdjA8VnAUKFJDT1zsN0JDh25lXGuFCzGtcbzf0WtUxLZhr3DWrnkljZB/3TMchduvk6qG7etqKKzg2KtfvfsTQWK1xKFgl1sve6A+4F0QidfMWbvCwH 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: ab963db1-a6ab-49b1-0c66-08d7684149a2 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Nov 2019 13:56:31.7962 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PU1APC01HT043 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 Wed Nov 13 13:56:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 11241957 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 360D81747 for ; Wed, 13 Nov 2019 13:57:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1DDCF207FC for ; Wed, 13 Nov 2019 13:57:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727507AbfKMN47 convert rfc822-to-8bit (ORCPT ); Wed, 13 Nov 2019 08:56:59 -0500 Received: from mail-oln040092255071.outbound.protection.outlook.com ([40.92.255.71]:50214 "EHLO APC01-HK2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726190AbfKMN47 (ORCPT ); Wed, 13 Nov 2019 08:56:59 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UN5PV8EKe0imzQcsjsBHQ4sN0Gw1Vf9180yJPal24tKfW1qMsyIaKqC1EvdiohFw6ZVAc5TxcIecMCNjCGX3f2OmZFNAg7ENhk/bXFzLU6W/oYH+nJHGI/ccV3dKtFK8k1kDLnJQMK0FkI0GbpbTB3rUI8v9ldtIJRySa4k2+wclrHVTm6p+1sr8UYB4yG/dlxbiMl6gRa7lchOlySM8PmIdagVTSdLQ53WmPOiIXCvo47Zy7f7oKUw7WjPsuP9a135CI8lNzmHcvG20py6Dg1opudhve0cSuhA8cG8RBue42plFloGspsEqO8fjExRg8Um5rlKjEKOjPk2WTFjGfw== 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=e7/ArhO40rvuslFVXUMzrP4XfK2y/TQOyjIRFEKuXKQFqBT3t3PbTMWc+B4Z7z9aUN92dZ3s4WujA9ofE8uQ2yX5BM/DL8IKhWqU63QIzbH/1o9msGhx+FLWavMprWS19GSqZPc64up8lldwJ2tKmdywnf8ZR4thn9P8EgJRZoJOUm3TCTiSWCj++S6M9tiVG63bMRd+fts70gNTSNAWCSTPgmGCvi4XNppzTAYLZdqkxhUcmZ7qsTOMhboVFIUPWUQNr0CGh06DVNTK/M0ki23wuplRwtGRG0kNNmuYXF2jjrbECzFu014bLg2k2Ko4gQ/kU1+yvqS0UIBlF/sZoQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from PU1APC01FT035.eop-APC01.prod.protection.outlook.com (10.152.252.55) by PU1APC01HT056.eop-APC01.prod.protection.outlook.com (10.152.253.82) 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 13:56:54 +0000 Received: from PS2P216MB0755.KORP216.PROD.OUTLOOK.COM (10.152.252.57) by PU1APC01FT035.mail.protection.outlook.com (10.152.252.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2451.23 via Frontend Transport; Wed, 13 Nov 2019 13:56:54 +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 13:56:54 +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 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: AQHVmio1UPHQ91Txq0ecwsk7Nnr1Dw== Date: Wed, 13 Nov 2019 13:56:54 +0000 Message-ID: Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SYBPR01CA0197.ausprd01.prod.outlook.com (2603:10c6:10:16::17) To PS2P216MB0755.KORP216.PROD.OUTLOOK.COM (2603:1096:300:1c::13) x-incomingtopheadermarker: OriginalChecksum:6ABFF8C6CB5C374E84EC9406E25A2B1D2CE7CE3FF859D33EF23710A2D99CD1E0;UpperCasedChecksum:EE51FB1531CB3BFF653E4977D9466CA2720D047675117CF78749BB980BE2349A;SizeAsReceived:7684;Count:47 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [d6FG126QYELAKeKCY69GPDkm0PL3rfYSwjItcb0JdGmzxsfgNcu6fp0Ju1LBClc3CYlFZPZX8W8=] x-microsoft-original-message-id: <20191113135645.GA3220@nicholas-dell-linux> x-ms-publictraffictype: Email x-incomingheadercount: 47 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 5221be0a-eed8-417d-31af-08d768415754 x-ms-exchange-slblob-mailprops: Eluf6BVNkXnWHxa7ZbiJC49Lj0H6xSaHWsHmds2yMHv17Tb5BrhIRnbD/a0tWCu1gSLWreanXa5G/VFuybTyPdE55IEJw9Dllbu6VOLc1M99D5pNpgMvBrEvGJd7Z0AZFFmRFAWuGesloQzPYcqF79+t1BQJxuIFNt8aS9XkcRen8vr9A+bvxGW6DBEOckZMrgnJyBj1cFaGt7WLqWhfMMl/Gs5THGUu3M11B8VuuU5tcudaMog0y3WPyheMGPd+QzIj3E6j8rFQOFKrj77l9FE4xqKsImrKFpwmKzuSfQ8BbRczqZDys3JqxhqNT1FhtO8XAPTqGvh+weQbWVrQCfebSZeW05CaVZTtIDNe/6ekU2NDb9olIZcky5kKn+FZXRvpKBYDt2rteVOEewWU7zYZfuB2MbU9TTXMUUxf29o4S8m1wLT28sjr6KSwyi8aUWkdU7hNb3zTQ6uMPVhi2PCb4h7lUjSfVcm4ugPCocPwTJ+cDDx0m+I1t3KSOFmu6Vt7CoLVdwi5mU2/TXwL9emFabGJLLSCg0nTvrKMj1kDMboFjLFOojvKWIv+/bgHaocD6PA/PgukqjPH/T5BxvkCbrzhf1N342rUMpqc0WZSEvs57XyP3AiDQVpGbpwvHRJ2leQmdTeN3jcH/BTJDq7jj1H7W/+V x-ms-traffictypediagnostic: PU1APC01HT056: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: AN5wHYwLHym0P13WhMO/PgwEnvI1l/OGhCazB/81hf4rrc7pZbEitWyzpjs6UQXybBO1ABTNpwpIx8LVz12tYzOliAN5zQQ27ndj3I7gtgHVGiU5AQuqKBo/34P4cdBrGEa9mHTujxQdr3yepWYEa8wiw/dOCELrFLLHz+q0AiWU7XnONRK7ECUNUSfSCGwK 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: 5221be0a-eed8-417d-31af-08d768415754 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Nov 2019 13:56:54.7631 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PU1APC01HT056 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 Wed Nov 13 13:57:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 11241959 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 669BA16B1 for ; Wed, 13 Nov 2019 13:57:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 47D7B222D0 for ; Wed, 13 Nov 2019 13:57:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727504AbfKMN5X convert rfc822-to-8bit (ORCPT ); Wed, 13 Nov 2019 08:57:23 -0500 Received: from mail-oln040092254097.outbound.protection.outlook.com ([40.92.254.97]:60976 "EHLO APC01-PU1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726190AbfKMN5X (ORCPT ); Wed, 13 Nov 2019 08:57:23 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TiCL7JRsur7zoTMTRS/BL2Fg6ysmTn2F2mJxUiQK1RyAEYgBP7fGcs8RYfff6aYMiWSmQNRCWhx6XyTWh8G9ks1PkYTLjVGswL3hTRiSlSlnHDuMniv6+y4bby+yzO2dTXywP6vGkqMlTE43IUPNoi1TBKMghPQXPT9iDKyehnj1334MarTFPNhQZMRnKUJGDIHZXbPorfglwJPcC8JGbmEdoAEUXki4QX26UV/EKjabyGLpUB5lRuu5HSj90wF1uang5bxSsOw1oXcphFIaYn0O1xG9LZYDYz/eDCtL66dke6zHDh3v0NJ8hHFGw95p6kHxltVEmFUG83BdYqkngw== 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=b1yUZPSQk/b6PHFqQtcuUl/v8n5bbU4oOm+k+2zQsgVB8bxpyRUeBsg5sn6PSvEnPZqgY7e24tbz4zjxPVxxXcb1xUIYHD8ftFD7uKI4mSHQtgMgR2YgKTVcMPvnotayPM60oiyteVr8402kVyNXnqCKIisUo/ZhrfFdF07ozzqtNRFLp5XUTgGwDkGtzHQAJy7OCYipEfn2K9UxT5dGQv4NrMBzJpzjHZ/sNYoq2F4Ts2dNY/+wdd36wLWwu7VeZmZE1Fa8IJW3wMGaAraqtQlywx95CNSDOFgTvcme6vrUndRcj4z7TZ0Vd5JPkbFiRPtUyp3MnIGLabR9zBTB8A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from PU1APC01FT035.eop-APC01.prod.protection.outlook.com (10.152.252.54) by PU1APC01HT222.eop-APC01.prod.protection.outlook.com (10.152.252.163) 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 13:57:18 +0000 Received: from PS2P216MB0755.KORP216.PROD.OUTLOOK.COM (10.152.252.57) by PU1APC01FT035.mail.protection.outlook.com (10.152.252.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2451.23 via Frontend Transport; Wed, 13 Nov 2019 13:57:18 +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 13:57:18 +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 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: AQHVmipDV6eC7pwnA0uzrURncVQLew== Date: Wed, 13 Nov 2019 13:57:18 +0000 Message-ID: Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SYBPR01CA0198.ausprd01.prod.outlook.com (2603:10c6:10:16::18) To PS2P216MB0755.KORP216.PROD.OUTLOOK.COM (2603:1096:300:1c::13) x-incomingtopheadermarker: OriginalChecksum:418D55EF9DA2B97880F9FD6EF04FA1104D40CFE7061EC3F8BE00EC5B240CAB75;UpperCasedChecksum:0DB9C8F9DD6CFCB9133B6CED923B620A936ACCF4BA8BE2854E2B18E235801871;SizeAsReceived:7679;Count:47 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [NlEcxp3pOd9B9pAVgewh+JpuDmWmXugCbhvRkVF0pPRnLH9LUMuW9n9zGAWDlkF+lIQwdyWG0wk=] x-microsoft-original-message-id: <20191113135710.GA3224@nicholas-dell-linux> x-ms-publictraffictype: Email x-incomingheadercount: 47 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 724d73c3-f127-449a-b1c8-08d768416585 x-ms-exchange-slblob-mailprops: dEG5jEBie8mlFL0Oe7sWpdK/rFF0vM+sWL1qRZrZy26tb4PZdKegNw3NbXdJZ2dVjtIDyV3R1DNVPVDikMwFk/AMW1AsVzYEK/kugPDzdBtEKHCQ0vraFuc6Ppo6MWt58XiygU5cV3OGnNFx9XGNc2AXqgeRikjG9WqBndni2PCVQLbLHzzeg0pgixRaB7O+D2Sx12e8hYsxoR2zJbwvRojA0W44TRfXMXRIVDfj6aoZ5zNY7MfEmSt/mZADXYZ4NP+60GeU8COZoQ9PfwHC7QnPR2uCMVDb+N3E6ykhBipl5viiavzcN7g3032gh7bp0MTNUNwgL8CktbojfBXioFWTcySI4E5zekrWIIsxhPH+bh1XgAvDgJrzHSpEVBEoz0x8yniT6IT3EsGyhL9q76mtK0BfqdmhpE4vSFx3OPlQhc1FlPAdSC1PQJaUqo8bvzjNZbtli6jGamwWBplluPDJCadHv16Z5/TGjojk4Gr9plrCxCGS1JOH0ggAk+VoC+z7Jwvsgtpz7f1MU5jhi+QlRcnKNymuiy+JOU2eZoERyX/bS4SbRv09l3UXqr253fLyCONLgChQqD5Me6pEpcDFvKpFhdqmKTN4CqsROGvpSlVAF9F4TjTk8Hovx3YmirbPtghLBcvrsWKTjamOTVUyKydKxcxbCRyNPTPdH8k0u1r2mnHk5Q== x-ms-traffictypediagnostic: PU1APC01HT222: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: I/RgUYNfOJnVA98S8qgaT5v7R/WNtEiJRAotre8adDG/LgA6paGBrl6O2Z9Mt44HqbKn+h4P2xdbrn4mrY03bgm4pOpoGW3En5BRmSe1LrHBtPqofZKQxVOBWTEzP4SKK50YV40mIpD8mEZC0sMbVo1lHEP4yBbRgmls/0gPcmf7halFfVFYKnABx9ALHqzp 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: 724d73c3-f127-449a-b1c8-08d768416585 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Nov 2019 13:57:18.4396 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PU1APC01HT222 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,