From patchwork Thu May 3 12:39:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 10378111 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3CD8A60541 for ; Thu, 3 May 2018 12:39:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EC4128E22 for ; Thu, 3 May 2018 12:39:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22C0828E49; Thu, 3 May 2018 12:39:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C154428E22 for ; Thu, 3 May 2018 12:39:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751622AbeECMju (ORCPT ); Thu, 3 May 2018 08:39:50 -0400 Received: from mga12.intel.com ([192.55.52.136]:24203 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751195AbeECMjt (ORCPT ); Thu, 3 May 2018 08:39:49 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 May 2018 05:39:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,358,1520924400"; d="scan'208";a="196430281" Received: from lahna.fi.intel.com (HELO lahna) ([10.237.72.157]) by orsmga004.jf.intel.com with SMTP; 03 May 2018 05:39:42 -0700 Received: by lahna (sSMTP sendmail emulation); Thu, 03 May 2018 15:39:41 +0300 Date: Thu, 3 May 2018 15:39:41 +0300 From: Mika Westerberg To: Bjorn Helgaas Cc: Bjorn Helgaas , "Rafael J. Wysocki" , Len Brown , Mario.Limonciello@dell.com, Michael Jamet , Yehezkel Bernat , Andy Shevchenko , Lukas Wunner , linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org Subject: Re: [PATCH v5 2/9] PCI: Take bridge window alignment into account when distributing resources Message-ID: <20180503123941.GP2355@lahna.fi.intel.com> References: <20180416103453.46232-1-mika.westerberg@linux.intel.com> <20180416103453.46232-3-mika.westerberg@linux.intel.com> <20180425223853.GA225403@bhelgaas-glaptop.roam.corp.google.com> <20180426122333.GE2173@lahna.fi.intel.com> <20180501201546.GC11698@bhelgaas-glaptop.roam.corp.google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180501201546.GC11698@bhelgaas-glaptop.roam.corp.google.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Tue, May 01, 2018 at 03:32:46PM -0500, Bjorn Helgaas wrote: > This is where it gets hard for me -- I'm not really comfortable if we > have to convince ourselves that code is correct by testing every > scenario. It's a lot better if we can convince ourselves by reasoning > about what the code does. That's not very reliable either, but if we > understand the code, we at least have a hope of being able to fix the > bugs we missed in our reasoning. I took another look at the code and we can calculate everything upfront before resources get distributed to hotplug bridges. I also tried and it still works on my test systems. Does the below patch look more acceptable to you? diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 072784f55ea5..cbc80dd5e8d8 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1881,6 +1881,7 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, unsigned int normal_bridges = 0, hotplug_bridges = 0; struct resource *io_res, *mmio_res, *mmio_pref_res; struct pci_dev *dev, *bridge = bus->self; + resource_size_t align, io_align, mem_align; io_res = &bridge->resource[PCI_BRIDGE_RESOURCES + 0]; mmio_res = &bridge->resource[PCI_BRIDGE_RESOURCES + 1]; @@ -1919,27 +1920,43 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, normal_bridges++; } + io_align = window_alignment(bus, IORESOURCE_IO); + mem_align = window_alignment(bus, IORESOURCE_MEM); + for_each_pci_bridge(dev, bus) { - const struct resource *res; + struct resource *res; if (dev->is_hotplug_bridge) continue; /* * Reduce the available resource space by what the - * bridge and devices below it occupy. + * bridge and devices below it occupy taking into + * account alignment if it differs from the default. */ res = &dev->resource[PCI_BRIDGE_RESOURCES + 0]; - if (!res->parent && available_io > resource_size(res)) + if (!res->parent && available_io > resource_size(res)) { remaining_io -= resource_size(res); + align = pci_resource_alignment(dev, res); + if (align > io_align) + remaining_io -= align - io_align; + } res = &dev->resource[PCI_BRIDGE_RESOURCES + 1]; - if (!res->parent && available_mmio > resource_size(res)) + if (!res->parent && available_mmio > resource_size(res)) { remaining_mmio -= resource_size(res); + align = pci_resource_alignment(dev, res); + if (align > mem_align) + remaining_mmio -= align - mem_align; + } res = &dev->resource[PCI_BRIDGE_RESOURCES + 2]; - if (!res->parent && available_mmio_pref > resource_size(res)) + if (!res->parent && available_mmio_pref > resource_size(res)) { remaining_mmio_pref -= resource_size(res); + align = pci_resource_alignment(dev, res); + if (align > mem_align) + remaining_mmio_pref -= align - mem_align; + } } /* @@ -1964,7 +1981,7 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, available_io, available_mmio, available_mmio_pref); } else if (dev->is_hotplug_bridge) { - resource_size_t align, io, mmio, mmio_pref; + resource_size_t io, mmio, mmio_pref; /* * Distribute available extra resources equally