Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4124940imm; Tue, 25 Sep 2018 11:46:14 -0700 (PDT) X-Google-Smtp-Source: ACcGV62z3dmNZXoeyFJ4JMDIxHgJyogVnGNyAcI+//TEgGzUiClbg5c/YXYdvHOG1zdfSNAexVD/ X-Received: by 2002:a63:1752:: with SMTP id 18-v6mr2220997pgx.131.1537901174662; Tue, 25 Sep 2018 11:46:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537901174; cv=none; d=google.com; s=arc-20160816; b=ZP1JCsObCCxI+oij5NurMOHbHExkjNPBYTKhZCEB+ZpyAeQntmCEAczOZfnr+NWA71 SKYCp16+0PFrQyiOn3wDJZ94YJB0lc29ZNLO4sQ3b+fgsyMdIcJ0le4Fl3LL/wIco/Ug ovt85Tn7wdmwzcFpG8ynO8B/MiQlZUjqYT6lLtZrAuGJRNyMeepGq0H192NwjfEr9j6r /xWq8eXqpmmMZgisCkeTojuQm0aHfRg/Yh+9GHPW4a9buGJ+Bioi/6KITehwc0/ovqkE o8Uy/tuDWs/P/FNwrVZx8OqYpDffALTaeRmeY932PMrvUAVGuIW8uaQSnj1SvhMWVsut gjgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=rXvXRkGGwTKjk5/0ladrN/GlJLxSN+wdUkPaP47MX+M=; b=dOemfFwdfVYLuymbSvkKT1ULhrzvDUvKABt63wrW52wTPJbB7YfcC+801vJGJKjCK9 zABKABGkFlJjVDWW4tZ/6AuIdcRiYUuyqju0+YmO8hxd4nAs42MWSh0cQsiSg4pZmnyM P92cOzAqvwDw0BYB1F3FvXB8QBphdnf8btPXOJ184GuyaUK5C0WlBpPAfHRZ74P6o8OY Op/Ke61hlQiqsiFN/Oq7fxnnkf4Fx32Fg6WOPWJqJeDykN8GWUEMBD32yV/8oSdhJyzO UrNX+HT0YS75es+lzuATOoaFdnDbBrel3eOnPtnWXKGWgKfDg1wB9R98xXH+91O07Nu+ erkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 63-v6si2658161pfg.67.2018.09.25.11.45.58; Tue, 25 Sep 2018 11:46:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727575AbeIZAyZ (ORCPT + 99 others); Tue, 25 Sep 2018 20:54:25 -0400 Received: from mga11.intel.com ([192.55.52.93]:5506 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726944AbeIZAyZ (ORCPT ); Tue, 25 Sep 2018 20:54:25 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Sep 2018 11:45:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,303,1534834800"; d="scan'208";a="73635613" Received: from unknown (HELO localhost.localdomain.localdomain) ([10.232.117.194]) by fmsmga008.fm.intel.com with ESMTP; 25 Sep 2018 11:45:32 -0700 From: Jon Derrick To: Bjorn Helgaas Cc: , , Lorenzo Pieralisi , Sinan Kaya , Christoph Hellwig , Keith Busch , Matthew Wilcox , Logan Gunthorpe , Mika Westerberg , Jon Derrick Subject: [PATCH v3] PCI: Equalize hotplug memory and io for non/occupied slots Date: Tue, 25 Sep 2018 12:39:06 -0600 Message-Id: <1537900746-3043-1-git-send-email-jonathan.derrick@intel.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, a hotplug bridge will be given hpmemsize additional memory and hpiosize additional io if available, in order to satisfy any future hotplug allocation requirements. These calculations don't consider the current memory/io size of the hotplug bridge/slot, so hotplug bridges/slots which have downstream devices will be allocated their current allocation in addition to the hpmemsize value. This makes for possibly undesirable results with a mix of unoccupied and occupied slots (ex, with hpmemsize=2M): 02:03.0 PCI bridge: <-- Occupied Memory behind bridge: d6200000-d64fffff [size=3M] 02:04.0 PCI bridge: <-- Unoccupied Memory behind bridge: d6500000-d66fffff [size=2M] This change considers the current allocation size when using the hpmemsize/hpiosize parameters to make the reservations predictable for the mix of unoccupied and occupied slots: 02:03.0 PCI bridge: <-- Occupied Memory behind bridge: d6200000-d63fffff [size=2M] 02:04.0 PCI bridge: <-- Unoccupied Memory behind bridge: d6400000-d65fffff [size=2M] Signed-off-by: Jon Derrick --- v2->v3: Made the IO and mem size calculations nearly equivalent 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 79b1824..ed96043 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -811,6 +811,8 @@ static struct resource *find_free_bus_resource(struct pci_bus *bus, static resource_size_t calculate_iosize(resource_size_t size, resource_size_t min_size, resource_size_t size1, + resource_size_t add_size, + resource_size_t children_add_size, resource_size_t old_size, resource_size_t align) { @@ -823,15 +825,18 @@ static resource_size_t calculate_iosize(resource_size_t size, #if defined(CONFIG_ISA) || defined(CONFIG_EISA) size = (size & 0xff) + ((size & ~0xffUL) << 2); #endif - size = ALIGN(size + size1, align); + size = size + size1; if (size < old_size) size = old_size; + + size = ALIGN(max(size, add_size) + children_add_size, align); return size; } static resource_size_t calculate_memsize(resource_size_t size, resource_size_t min_size, - resource_size_t size1, + resource_size_t add_size, + resource_size_t children_add_size, resource_size_t old_size, resource_size_t align) { @@ -841,7 +846,8 @@ static resource_size_t calculate_memsize(resource_size_t size, old_size = 0; if (size < old_size) size = old_size; - size = ALIGN(size + size1, align); + + size = ALIGN(max(size, add_size) + children_add_size, align); return size; } @@ -930,12 +936,10 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size, } } - size0 = calculate_iosize(size, min_size, size1, + size0 = calculate_iosize(size, min_size, size1, 0, 0, resource_size(b_res), min_align); - if (children_add_size > add_size) - add_size = children_add_size; - size1 = (!realloc_head || (realloc_head && !add_size)) ? size0 : - calculate_iosize(size, min_size, add_size + size1, + size1 = (!realloc_head || (realloc_head && !add_size && !children_add_size)) ? size0 : + calculate_iosize(size, min_size, size1, add_size, children_add_size, resource_size(b_res), min_align); if (!size0 && !size1) { if (b_res->start || b_res->end) @@ -1079,12 +1083,10 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, min_align = calculate_mem_align(aligns, max_order); min_align = max(min_align, window_alignment(bus, b_res->flags)); - size0 = calculate_memsize(size, min_size, 0, resource_size(b_res), min_align); + size0 = calculate_memsize(size, min_size, 0, 0, resource_size(b_res), min_align); add_align = max(min_align, add_align); - if (children_add_size > add_size) - add_size = children_add_size; - size1 = (!realloc_head || (realloc_head && !add_size)) ? size0 : - calculate_memsize(size, min_size, add_size, + size1 = (!realloc_head || (realloc_head && !add_size && !children_add_size)) ? size0 : + calculate_memsize(size, min_size, add_size, children_add_size, resource_size(b_res), add_align); if (!size0 && !size1) { if (b_res->start || b_res->end) -- 1.8.3.1