Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1331186imm; Wed, 25 Jul 2018 16:15:03 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf7srGzZdJKgMCgDYnwnOkZXi8UETN59iZ5QHesOsoQDqI+iNlG/dPt1gx4/N36jdpW6jm5 X-Received: by 2002:a65:5641:: with SMTP id m1-v6mr22894053pgs.246.1532560503865; Wed, 25 Jul 2018 16:15:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532560503; cv=none; d=google.com; s=arc-20160816; b=AX44n8GKWhmsnl1qWBsROTBnTb06gpjOxZXWZ/tUyRXPPXngXevdhNL5wld7+WoJow Te8oYMCHDLF7ZcEH4LZOyIlhlQb7LE5ezew/bveRlnujb6fkwaOqE9KQOz5oLaOMm8SU qHHAFbi5b+bH1mPH1N0zK/Q9GqlLyRo0Eno5BbnnL2SmOJmBTDaCrX/VUJk9sHx4lR2N 9CQFwdORo2wy5lwM/2BS4Ec1jxf746zD6RJK9CSZ2IBg58H5o9RmonnOEWADYU1F1Uwr PgPe6KBgQMUdZrDrXdqVqgSZNlUZpwFdSsTWUWU2aIyLceuoKe3ixWbRswqA0AX6b//Y CIig== 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 :arc-authentication-results; bh=ciLxGjE4LB8kWkSFdwc83yZJGp07lXfy73dz3+uje4s=; b=mV9pWdoRMCHLYQTb4j0b2zyeR9HuY6BqsnghQGLgO7bqbTfjpWcatAznZFcnes20MX XD2iCVazdf7y/36rhL2ynHfED3wn/9jVGRdMSsUvzv738K0oFGVifjLhGcQLIbt23LC2 7ekKRzAS/3o7dcqob2qasI9rWqVMdudyubqzuYy//YaQAKtuThhlNL/l5pqsCxcY4quG 9OzunKZ9fsAAl/zb80M6m+QmeLQP31Xv3250leAHIsQspKAwSQyWi+JV7C966b1IPwQh 90SRLCQW9+gHtia/dub+PZB8C+lRaBpoBLtINsqH8+zxHnIU53AiimzXerbDKZyyyXq8 q+9A== 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 a90-v6si12829124plc.285.2018.07.25.16.14.45; Wed, 25 Jul 2018 16:15:03 -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 S1731737AbeGZATg (ORCPT + 99 others); Wed, 25 Jul 2018 20:19:36 -0400 Received: from mga05.intel.com ([192.55.52.43]:9640 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731437AbeGZATg (ORCPT ); Wed, 25 Jul 2018 20:19:36 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jul 2018 16:05:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,402,1526367600"; d="scan'208";a="59829809" Received: from unknown (HELO localhost.lm.intel.com) ([10.232.117.43]) by orsmga008.jf.intel.com with ESMTP; 25 Jul 2018 16:05:42 -0700 From: Jon Derrick To: Bjorn Helgaas Cc: , , Lorenzo Pieralisi , Keith Busch , Greg Kroah-Hartman , Mika Westerberg , Sinan Kaya , Logan Gunthorpe , Stephen Bates , Jon Derrick Subject: [PATCH] PCI: Equalize hotplug memory for non/occupied slots Date: Wed, 25 Jul 2018 17:02:59 -0600 Message-Id: <1532559779-3542-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 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] Signed-off-by: Jon Derrick --- Original RFC here: https://patchwork.ozlabs.org/patch/945374/ I split this bit out from the RFC while awaiting the pci string handling enhancements to handle per-device settings Changed from RFC is a simpler algo drivers/pci/setup-bus.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 79b1824..5ae39e6 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,7 @@ 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; } @@ -1079,12 +1080,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