Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp46345imm; Thu, 30 Aug 2018 15:18:59 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY+0tKJugLJNtMcoweU6RNqBQpkYK4TfMQxqYov0rLRf8QcUq00+R7RTsPqxPAgrqzFu5oj X-Received: by 2002:a17:902:6a83:: with SMTP id n3-v6mr12011653plk.246.1535667539418; Thu, 30 Aug 2018 15:18:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535667539; cv=none; d=google.com; s=arc-20160816; b=zc6GKgjE8ARCbSeeLtXvzMbe4hRdSi1WlI8bxhkoNlGyLHqrZtCmI8RAGYm3/b3Nbx PwS2q3dCNqe+fOkwTU/ut3TuEuticT0qeLoSVyXp73Ny1XcnaG3sv4NnsTWUGADT4wno KAonLRP5jVa7hjp6mwaT73ikBbCAZ10I6dNm3i41NIcSDJqLHm1GSQYEqUt+j1AW1YEp px+2Nr3eDv79ogAxL+v47CkPqbxnSHW6Lm9QFD6RHClK/ztc8Lhci0T8IXFgBQxzmS8D xIUwvxQx5rydHMq356Xh/57OL+Rj7+90fRbvj5h7VTXBZpg7YL5rIXipwxI+w3bnn73+ 2O3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=6whGCIMNrLEtediuVuQgB1bRfz4ucgAhoZJsCz5G+Rs=; b=Gh4zFmlz6F6xGJ8GX4UQC5LLfYIbPvHxfJYZwJMHNf9i8kUuR2LWXos/09r4CwOzJw EfPbv2kLyuWmC/kCofFnJUgmOzXkhlLTgcHA+SK31PBA8VHN2mbmFmr+si55gYcKAAL2 MkZCh2hCoYQg6NlOfyZWEeBGH9LqQ/tAxpShY3QP8CNOpQ6Tny3zzT8ASTp+lK2WC8TK dF1ip3G/TbDOtZtbQ2qAkvbfgoPkM+Sy5mYZw5YTJv0wuiGHVxP7qgZfsGsxUoC3x8uG oYpkOBzcQsoGgdyzJYhQyTXaFA13mm/WhvRNm95hLdSKPk/1URD19FxalkkmbOBsUQyz KVAg== 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 7-v6si7270397pgq.637.2018.08.30.15.18.43; Thu, 30 Aug 2018 15:18:59 -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 S1727294AbeHaCV4 (ORCPT + 99 others); Thu, 30 Aug 2018 22:21:56 -0400 Received: from mga06.intel.com ([134.134.136.31]:7445 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726674AbeHaCVz (ORCPT ); Thu, 30 Aug 2018 22:21:55 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Aug 2018 15:17:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,308,1531810800"; d="scan'208";a="85928798" Received: from unknown (HELO localhost.localdomain.localdomain) ([10.232.117.194]) by fmsmga001.fm.intel.com with ESMTP; 30 Aug 2018 15:17:34 -0700 From: Jon Derrick To: Bjorn Helgaas Cc: , , Lorenzo Pieralisi , Keith Busch , Greg Kroah-Hartman , Mika Westerberg , Sinan Kaya , Christoph Hellwig , Matthew Wilcox , Logan Gunthorpe , Stephen Bates , Jon Derrick Subject: [PATCH v2] PCI: Equalize hotplug memory for non/occupied slots Date: Thu, 30 Aug 2018 16:12:00 -0600 Message-Id: <1535667120-3002-2-git-send-email-jonathan.derrick@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1535667120-3002-1-git-send-email-jonathan.derrick@intel.com> References: <1535667120-3002-1-git-send-email-jonathan.derrick@intel.com> 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 if available, in order to satisfy any future hotplug allocation requirements. These calculations don't consider the current memory size of the hotplug bridge/slot, so hotplug bridges/slots which have downstream devices will get 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 parameter 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] The calculation for IO (hpiosize) should be similar, but platform firmwares I've encountered (including QEMU) provide strict allocations for IO and would not provide free IO resources for hotplug buses in order to prove this calculation. Signed-off-by: Jon Derrick --- drivers/pci/setup-bus.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 79b1824..70d0aba 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -831,7 +831,8 @@ static resource_size_t calculate_iosize(resource_size_t 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 +842,15 @@ 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); + + /* + * Consider the current allocation size when adding size for extra + * hotplug memory. This ensures that occupied slots don't receive + * unneccessary memory allocations in addition to their current size. + * The calculation should be similar for calculate_iosize, but was + * unable to be tested. + */ + size = ALIGN(max(size, add_size) + children_add_size, align); return size; } @@ -1079,12 +1088,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