From patchwork Tue Jul 14 22:46:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 495334 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id ACE03140788 for ; Wed, 15 Jul 2015 09:01:36 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754475AbbGNW7q (ORCPT ); Tue, 14 Jul 2015 18:59:46 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:44872 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752919AbbGNWrx (ORCPT ); Tue, 14 Jul 2015 18:47:53 -0400 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t6EMlVsf020078 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 14 Jul 2015 22:47:31 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id t6EMlVU7032123 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 14 Jul 2015 22:47:31 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by userv0122.oracle.com (8.13.8/8.13.8) with ESMTP id t6EMlUTa004368; Tue, 14 Jul 2015 22:47:30 GMT Received: from linux-siqj.site.us.oracle.com (/10.132.127.48) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 14 Jul 2015 15:47:30 -0700 From: Yinghai Lu To: Bjorn Helgaas , David Miller , Benjamin Herrenschmidt , Wei Yang , TJ , Yijing Wang Cc: Andrew Morton , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Yinghai Lu Subject: [PATCH v2 06/49] PCI: Don't add too much optional size for hotplug bridge mmio Date: Tue, 14 Jul 2015 15:46:37 -0700 Message-Id: <1436914040-13206-7-git-send-email-yinghai@kernel.org> X-Mailer: git-send-email 1.8.4.5 In-Reply-To: <1436914040-13206-1-git-send-email-yinghai@kernel.org> References: <1436914040-13206-1-git-send-email-yinghai@kernel.org> X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Current code will always add 2M for hotplug bridge mmio even there is child device under it. For example: 40:03.0 --- 43:00.0 --- 44:02.0 -+- 45:00.0 \- 45:00.1 44:02.0 will need 1M as must for 45:00.0 and 45:00.1 When we calculate add_size for 44:02.0, we pass 2M as additional size for hotplug bridge, total will be 3M. That is different from code before changes for optional support, or even current code that treat optional as must directly by not passing realloc head. We only need 2M as total. The optional size should be 1M, and total size should be 2M. This patch change to comparing must+optional with min_sum_size to get smaller optional size. Signed-off-by: Yinghai Lu --- drivers/pci/setup-bus.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 4c7f25f..7346bbf 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1156,7 +1156,6 @@ out: * @type2: second match type * @type3: third match type * @min_size : the minimum memory window that must to be allocated - * @add_size : additional optional memory window * @realloc_head : track the additional memory window on this list * * Calculate the size of the bus and minimal alignment which @@ -1169,10 +1168,11 @@ out: static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, unsigned long type, unsigned long type2, unsigned long type3, - resource_size_t min_size, resource_size_t add_size, + resource_size_t min_size, struct list_head *realloc_head) { struct pci_dev *dev; + resource_size_t min_sum_size = 0; resource_size_t min_align = 0, min_add_align = 0; resource_size_t max_align = 0, max_add_align = 0; resource_size_t size = 0, size0 = 0, size1 = 0, sum_add_size = 0; @@ -1184,6 +1184,11 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, if (!b_res) return -ENOSPC; + if (realloc_head) { + min_sum_size = min_size; + min_size = 0; + } + list_for_each_entry(dev, &bus->devices, bus_list) { int i; @@ -1254,8 +1259,8 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, } free_align_test_list(&align_test_list); - if ((sum_add_size - size) < add_size) - sum_add_size = size + add_size; + if (sum_add_size < min_sum_size) + sum_add_size = min_sum_size; if (sum_add_size > size && realloc_head) { min_add_align = calculate_mem_align(&align_test_add_list, max_add_align, sum_add_size, @@ -1392,7 +1397,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) { struct pci_dev *dev; unsigned long mask, prefmask, type2 = 0, type3 = 0; - resource_size_t additional_mem_size = 0, additional_io_size = 0; + resource_size_t min_mem_size = 0, additional_io_size = 0; struct resource *b_res; int ret; @@ -1426,7 +1431,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) pci_bridge_check_ranges(bus); if (bus->self->is_hotplug_bridge) { additional_io_size = pci_hotplug_io_size; - additional_mem_size = pci_hotplug_mem_size; + min_mem_size = pci_hotplug_mem_size; } /* Fall through */ default: @@ -1445,8 +1450,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) prefmask |= IORESOURCE_MEM_64; ret = pbus_size_mem(bus, prefmask, prefmask, prefmask, prefmask, - realloc_head ? 0 : additional_mem_size, - additional_mem_size, realloc_head); + min_mem_size, realloc_head); /* * If successful, all non-prefetchable resources @@ -1469,8 +1473,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) prefmask &= ~IORESOURCE_MEM_64; ret = pbus_size_mem(bus, prefmask, prefmask, prefmask, prefmask, - realloc_head ? 0 : additional_mem_size, - additional_mem_size, realloc_head); + min_mem_size, realloc_head); /* * If successful, only non-prefetchable resources @@ -1479,7 +1482,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) if (ret == 0) mask = prefmask; else - additional_mem_size += additional_mem_size; + min_mem_size += min_mem_size; type2 = type3 = IORESOURCE_MEM; } @@ -1500,8 +1503,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) * window. */ pbus_size_mem(bus, mask, IORESOURCE_MEM, type2, type3, - realloc_head ? 0 : additional_mem_size, - additional_mem_size, realloc_head); + min_mem_size, realloc_head); break; } }