From patchwork Wed Feb 26 19:37:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 3728231 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E5252BF13A for ; Wed, 26 Feb 2014 19:42:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 15E6B201F9 for ; Wed, 26 Feb 2014 19:42:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1F370201CD for ; Wed, 26 Feb 2014 19:42:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754051AbaBZTh3 (ORCPT ); Wed, 26 Feb 2014 14:37:29 -0500 Received: from mail-ig0-f174.google.com ([209.85.213.174]:42636 "EHLO mail-ig0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753789AbaBZThZ (ORCPT ); Wed, 26 Feb 2014 14:37:25 -0500 Received: by mail-ig0-f174.google.com with SMTP id h18so1516171igc.1 for ; Wed, 26 Feb 2014 11:37:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=subject:to:from:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-type:content-transfer-encoding; bh=MO7EWaFzZ82zQLZFyWyJS2endAJMtMvdeGnVzchpQSg=; b=CoTAtGSAK4uF3sm8JfD3LWGglipH8S1gvKvMAxsResEKrnE6i/Fc4vJqTp1Ja63JAX Tgj7QN2E86MGtmN2RWbjNt3SNHpHRMQLcVEdfb3LHp/XalrWyXQ7RhkTmKBVdV5cRbWS koQV2aDnzEaWxDJ6XOTk64njmhSo5Byieb40+5yHDSnyTxOuTpvnxxjyvFVMnajrgfKA PhOVrS1zVGB+mTXYsBTUS4fNYAI3LXyZ8flSRsKG2Iu2WlBJf81e4uzyhGTCQwp2lO0j lGN8PVh2PTGvZBFoKBskRz099NKuVMBYL24dwswbLoXujD+mDTS+cSdInzUthiQ4bfUp B7Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:from:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-type :content-transfer-encoding; bh=MO7EWaFzZ82zQLZFyWyJS2endAJMtMvdeGnVzchpQSg=; b=NZgzFXDMSsX8yKD9k5N6L732bciQRYVobKD+cW+Z4haU0h1RcK3b5E89eabP90wLGV 4AIMfwo+dlOwVWQ99IcIvWmd0dFb3TyfPjMiLH6caC9zWlksI3PfrDHdVezNFS11ZGzt IGOzHZbYwfeRW3hcHFqGYI+hL9eV3DYtBu6H6/lZyXfqR10ScWafK22VmE7NaFtc0Ln2 mqLV1Wa5JkzWKqeKTiEkdxRGJNu8GLZYvnpp/e/Mth61NawsM03h30G4kPlSS41M1ymE hIrm87+AiwPNWlpgmgeB+nVx1PtF0VUa8rkvGg3C4xW5dfimGovl39Wrua3lZQqT0215 2IGA== X-Gm-Message-State: ALoCoQlW1xG9sMTkVJwk5OL3prYOi9WApVqBhMC1CRXyV4oj9tZOYER02XcfgyHBmIWS5MQMmY80gkfKu5MtswoPXzc/FTZIeyKfu8O6xEcSheBBXB7hexdJb7ZdRujfDT38E2/26pD28mfHAIEMq1LYBRQb1O5gpybICVYIOpJlr/zH8J8lh3Psgj5SJZPgMpcWa2/e0SDapvi/g46XQ9PbUlKmQXM29g9OW7f1dlj7Zn1TkcejtI8= X-Received: by 10.50.66.180 with SMTP id g20mr27869839igt.44.1393443444989; Wed, 26 Feb 2014 11:37:24 -0800 (PST) Received: from localhost ([172.16.49.60]) by mx.google.com with ESMTPSA id c17sm51446514igo.4.2014.02.26.11.37.24 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 26 Feb 2014 11:37:24 -0800 (PST) Subject: [PATCH 3/9] PCI: Remove pci_find_parent_resource() use for allocation To: linux-pci@vger.kernel.org From: Bjorn Helgaas Cc: linux-kernel@vger.kernel.org Date: Wed, 26 Feb 2014 12:37:23 -0700 Message-ID: <20140226193723.10125.15799.stgit@bhelgaas-glaptop.roam.corp.google.com> In-Reply-To: <20140226192614.10125.68711.stgit@bhelgaas-glaptop.roam.corp.google.com> References: <20140226192614.10125.68711.stgit@bhelgaas-glaptop.roam.corp.google.com> User-Agent: StGit/0.16 MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If the resource hasn't been allocated yet, pci_find_parent_resource() is documented as returning the region "where it should be allocated from." This is impossible in general because there may be several candidates: a prefetchable BAR can be put in either a prefetchable or non-prefetchable window, a transparent bridge may have overlapping positively- and subtractively-decoded windows, and a root bus may have several windows of the same type. Allocation should be done by pci_bus_alloc_resource(), which iterates through all bus resources and looks for the best match, e.g., one with the desired prefetchability attributes, and falls back to less-desired possibilities. The only valid use of pci_find_parent_resource() is to find the parent of an already-allocated resource so we can claim it via request_resource(), and all we need for that is a bus region of the correct type that contains the resource. Note that like 8c8def26bfaa ("PCI: allow matching of prefetchable resources to non-prefetchable windows"), this depends on pci_bus_for_each_resource() iterating through positively-decoded regions before subtractively-decoded ones. We prefer not to return a subtractively-decoded region because requesting from it will likely conflict with the overlapping positively- decoded window (see Launchpad report below). Link: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/424142 Signed-off-by: Bjorn Helgaas CC: Linus Torvalds --- drivers/pci/pci.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 1febe90831b4..99293fa40db9 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -401,33 +401,40 @@ EXPORT_SYMBOL_GPL(pci_find_ht_capability); * @res: child resource record for which parent is sought * * For given resource region of given device, return the resource - * region of parent bus the given region is contained in or where - * it should be allocated from. + * region of parent bus the given region is contained in. */ struct resource * pci_find_parent_resource(const struct pci_dev *dev, struct resource *res) { const struct pci_bus *bus = dev->bus; + struct resource *r; int i; - struct resource *best = NULL, *r; pci_bus_for_each_resource(bus, r, i) { if (!r) continue; - if (res->start && !(res->start >= r->start && res->end <= r->end)) - continue; /* Not contained */ - if ((res->flags ^ r->flags) & (IORESOURCE_IO | IORESOURCE_MEM)) - continue; /* Wrong type */ - if (!((res->flags ^ r->flags) & IORESOURCE_PREFETCH)) - return r; /* Exact match */ - /* We can't insert a non-prefetch resource inside a prefetchable parent .. */ - if (r->flags & IORESOURCE_PREFETCH) - continue; - /* .. but we can put a prefetchable resource inside a non-prefetchable one */ - if (!best) - best = r; + if (res->start && resource_contains(r, res)) { + + /* + * If the window is prefetchable but the BAR is + * not, the allocator made a mistake. + */ + if (r->flags & IORESOURCE_PREFETCH && + !(res->flags & IORESOURCE_PREFETCH)) + return NULL; + + /* + * If we're below a transparent bridge, there may + * be both a positively-decoded aperture and a + * subtractively-decoded region that contain the BAR. + * We want the positively-decoded one, so this depends + * on pci_bus_for_each_resource() giving us those + * first. + */ + return r; + } } - return best; + return NULL; } /**