From patchwork Wed Dec 24 02:29:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 423840 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 02C551400B7 for ; Wed, 24 Dec 2014 13:29:23 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750953AbaLXC3W (ORCPT ); Tue, 23 Dec 2014 21:29:22 -0500 Received: from mail-ig0-f182.google.com ([209.85.213.182]:36874 "EHLO mail-ig0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750896AbaLXC3V (ORCPT ); Tue, 23 Dec 2014 21:29:21 -0500 Received: by mail-ig0-f182.google.com with SMTP id hn15so6419255igb.9 for ; Tue, 23 Dec 2014 18:29:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=ty2/VMuFjs9DsisPWPM9SdxRO0P6vCNAKTJCyc5t5i8=; b=AN4CoTHa5Fgu4kZmNgJnm34uCil2cKKKzPfIU5keFdaH/BBUyxDERa/+mgJLhm76Vf oy0obAeljjYr0lc+MzECdDMXyz9iMrigbSm3Yc6As4wsKPvktqxYQeMKVlmNhcTzb42O HbNwqOXWwKYwHskjdjKvMrQWmnFBFit2uvcagToFLSjzHtGjuEZha0fNmT/c332hz+Ay EpKSyQpdASjbhKebXff3WRrJpVIltJHVvuGfrPtE0EwdG7tz784I1GzNBRJppGsz0EiF 4MMq2MCf6fkJtDMIKw0J/uX2/CmQjHkwmO/xJ3XVJ90jws4Fj0HrfsW7/lMTK218C/El m/gQ== MIME-Version: 1.0 X-Received: by 10.107.17.38 with SMTP id z38mr28509693ioi.29.1419388161026; Tue, 23 Dec 2014 18:29:21 -0800 (PST) Received: by 10.64.123.166 with HTTP; Tue, 23 Dec 2014 18:29:20 -0800 (PST) In-Reply-To: <20141223214106.GA27291@google.com> References: <1418074683.13358.1.camel@kernel.crashing.org> <20141208233855.GA15713@shangw> <20141220002306.GB30834@google.com> <20141223214106.GA27291@google.com> Date: Tue, 23 Dec 2014 18:29:20 -0800 X-Google-Sender-Auth: VyqljY8mm5eWcGX17thmNCRKcrE Message-ID: Subject: Re: Regression: bug 85491: radeon 0000:01:00.0: Fatal error during GPU init From: Yinghai Lu To: Bjorn Helgaas Cc: =?UTF-8?Q?Marek_Kord=C3=ADk?= , Gavin Shan , Benjamin Herrenschmidt , "linux-pci@vger.kernel.org" , Alexey Voronkov , David Airlie , Alex Deucher , Richard Yang Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On Tue, Dec 23, 2014 at 1:41 PM, Bjorn Helgaas wrote: > > Can you do this so it clips to any upstream bridge, whether it's a host > bridge or a PCI-to-PCI bridge? It doesn't seem like this has to be > specific to host bridge windows -- any device below a PCI-to-PCI bridge has > to use address space forwarded by that upstream bridge. ok, please check attached v2. > > I wish this were in generic code. There's nothing architecture-specific > about the problem, but this patch only fixes things on x86. Can you make a > similar change in the corresponding code for other arches, as well? ok, later after x86. Thanks Yinghai Subject: [RFC PATCH -v2] PCI, x86: clip firmware assigned pci bridges under hostbridge Some bios put range that is not fully coverred by root bus resources. Try to clip them and update them in pci bridge bars. -v2: check with upstream bridge instead of host bridge only. also add debug print out. Link: https://bugzilla.kernel.org/show_bug.cgi?id=85491 Reported-by: Marek Kordik Fixes: 5b28541552ef ("PCI: Restrict 64-bit prefetchable bridge windows to 64-bit resources") Signed-off-by: Yinghai Lu --- arch/x86/pci/i386.c | 81 +++++++++++++++++++++++++++++++++++++--------------- drivers/pci/bus.c | 35 ++++++++++++++++++++++ include/linux/pci.h | 1 3 files changed, 95 insertions(+), 22 deletions(-) Index: linux-2.6/arch/x86/pci/i386.c =================================================================== --- linux-2.6.orig/arch/x86/pci/i386.c +++ linux-2.6/arch/x86/pci/i386.c @@ -205,28 +205,48 @@ EXPORT_SYMBOL(pcibios_align_resource); * as well. */ -static void pcibios_allocate_bridge_resources(struct pci_dev *dev) +static bool pcibios_allocate_bridge_resources(struct pci_dev *dev) { int idx; struct resource *r; + bool changed = false; for (idx = PCI_BRIDGE_RESOURCES; idx < PCI_NUM_RESOURCES; idx++) { + int ret; + r = &dev->resource[idx]; if (!r->flags) continue; if (r->parent) /* Already allocated */ continue; - if (!r->start || pci_claim_resource(dev, idx) < 0) { - /* - * Something is wrong with the region. - * Invalidate the resource to prevent - * child resource allocations in this - * range. - */ - r->start = r->end = 0; - r->flags = 0; + + if (!r->start) + goto clear; + + ret = pci_claim_resource(dev, idx); + if (ret >= 0) + continue; + + /* try again after clip for pci bridge*/ + if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI && + pci_bus_clip_resource(dev, r)) { + changed = true; + if (pci_claim_resource(dev, idx) >= 0) + continue; } + +clear: + /* + * Something is wrong with the region. + * Invalidate the resource to prevent + * child resource allocations in this + * range. + */ + r->start = r->end = 0; + r->flags = 0; } + + return changed; } static void pcibios_allocate_bus_resources(struct pci_bus *bus) @@ -234,8 +254,12 @@ static void pcibios_allocate_bus_resourc struct pci_bus *child; /* Depth-First Search on bus tree */ - if (bus->self) - pcibios_allocate_bridge_resources(bus->self); + if (bus->self) { + bool changed = pcibios_allocate_bridge_resources(bus->self); + + if (changed) + pci_setup_bridge(bus); + } list_for_each_entry(child, &bus->children, node) pcibios_allocate_bus_resources(child); } @@ -271,21 +295,34 @@ static void pcibios_allocate_dev_resourc else disabled = !(command & PCI_COMMAND_MEMORY); if (pass == disabled) { + int ret; + dev_dbg(&dev->dev, "BAR %d: reserving %pr (d=%d, p=%d)\n", idx, r, disabled, pass); - if (pci_claim_resource(dev, idx) < 0) { - if (r->flags & IORESOURCE_PCI_FIXED) { - dev_info(&dev->dev, "BAR %d %pR is immovable\n", + + ret = pci_claim_resource(dev, idx); + + if (ret >= 0) + continue; + + if (r->flags & IORESOURCE_PCI_FIXED) { + dev_info(&dev->dev, "BAR %d %pR is immovable\n", idx, r); - } else { - /* We'll assign a new address later */ - pcibios_save_fw_addr(dev, - idx, r->start); - r->end -= r->start; - r->start = 0; - } + continue; + } + + /* try again with clip */ + if (pci_bus_clip_resource(dev, r)) { + pci_update_resource(dev, idx); + if (pci_claim_resource(dev, idx) >= 0) + continue; } + + /* We'll assign a new address later */ + pcibios_save_fw_addr(dev, idx, r->start); + r->end -= r->start; + r->start = 0; } } if (!pass) { Index: linux-2.6/include/linux/pci.h =================================================================== --- linux-2.6.orig/include/linux/pci.h +++ linux-2.6/include/linux/pci.h @@ -1094,6 +1094,7 @@ void pci_free_resource_list(struct list_ void pci_bus_add_resource(struct pci_bus *bus, struct resource *res, unsigned int flags); struct resource *pci_bus_resource_n(const struct pci_bus *bus, int n); void pci_bus_remove_resources(struct pci_bus *bus); +bool pci_bus_clip_resource(struct pci_dev *dev, struct resource *res); #define pci_bus_for_each_resource(bus, res, i) \ for (i = 0; \ Index: linux-2.6/drivers/pci/bus.c =================================================================== --- linux-2.6.orig/drivers/pci/bus.c +++ linux-2.6/drivers/pci/bus.c @@ -228,6 +228,41 @@ int pci_bus_alloc_resource(struct pci_bu } EXPORT_SYMBOL(pci_bus_alloc_resource); +bool pci_bus_clip_resource(struct pci_dev *dev, struct resource *res) +{ + struct pci_bus *bus = dev->bus; + resource_size_t start, end; + struct resource orig_res = *res; + struct resource *r; + int i; + + pci_bus_for_each_resource(bus, r, i) { + + if (resource_type(res) != resource_type(r)) + continue; + + start = max(r->start, res->start); + end = min(r->end, res->end); + + /* no overlap ? */ + if (start > end) + continue; + + if (res->start == start && res->end == end) + return false; + + /* changed */ + res->start = start; + res->end = end; + dev_printk(KERN_DEBUG, &dev->dev, "%pR ==> %pR\n", + &orig_res, res); + + return true; + } + + return false; +} + void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { } /**