From patchwork Wed Nov 6 20:46:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 3149071 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 0C3CFBEEB2 for ; Wed, 6 Nov 2013 20:46:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C61A7205E6 for ; Wed, 6 Nov 2013 20:46:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 72926205BB for ; Wed, 6 Nov 2013 20:46:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755973Ab3KFUqI (ORCPT ); Wed, 6 Nov 2013 15:46:08 -0500 Received: from mail-ie0-f172.google.com ([209.85.223.172]:44166 "EHLO mail-ie0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755710Ab3KFUqG (ORCPT ); Wed, 6 Nov 2013 15:46:06 -0500 Received: by mail-ie0-f172.google.com with SMTP id tp5so82824ieb.17 for ; Wed, 06 Nov 2013 12:46:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=Er8lojwHX2BcRWmXQTNClT15V1hRH4x/iZP1kGDODBc=; b=cb52nqRRKbUSKBXa4wYmvrKT1ipGKz7wcFsQVjuztF4e/Or5WD+/Id0Apkq/O3bEBa kDHdPJlpU98FlQrk79OkZEjgQRciKXV0w4ybojHbAyOSujkJWVXnwvopwbwjfJxmQK94 Nppd2E/DIuuqEeSaGDoMN0M8U7XH7yrJ+W8XWLTXXFqBk10RwxYeUGYvRjAJMGy/OSUQ 0jl8kVt6GbWBpUYM+/u6hRjp9Yt1OzlCJjuSAtFO1usIS3ILv2YpeFRG3VkZ+hwnURub CvmRiEf/PNSkz7NRzF4R2f0wLtFLPr927/gWDK6psZKrd/a8+bYXgPHfrhCIx3AuPCVP AD3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=Er8lojwHX2BcRWmXQTNClT15V1hRH4x/iZP1kGDODBc=; b=EjSJtORM6qJroWd38hwN7anrdjjkrMmoE8DrywnTty4NOoStvQwaGMTs3N51H1OWrn cWbwF/T0Dps4vEtwFDduHkbt9rRqBvIjo8RA2WpJlSLLVhqF1bPITaywX2y9YqJfrh0P NuwhDNHnhFBYG4Ds4qaBtBQtkOJaOT8q7qORvnNqnIIe8B7STVPDvohiD1hTiZlC23A2 5THBuXAWHxkWcEgKXf/XIoPKPY3rAQ1EQEwVDzPYYIkQa/TAAcdrb9rX5/Tg2y6Rj2Ut UOLO4wDllc/y2xbrbJTY5TxaedAWN04boU50vd9jCF85cTI72C2SbgJ/kQWFKtZR06OU ftHA== X-Gm-Message-State: ALoCoQliKmtd+btYb82c8gnHcnxFcLqF77VCHptYa0sPzZIlgN7aJ9AHPLWQv9Iw7HZf0l+LrPzFNUTV4cZ7UmnU29TKpgvp9OD4GvEt7S2yQSntpMTkoSUqAdzVtqfVEPicY9QiM3hPV564AqiU0aiT6mOthQSAwHeFSa6SbCJgek/5jLuZUxw4Zwx6OJ4TKmxbm9CmeJReLtXX0dF+dTdTC2xUnuwYMw== X-Received: by 10.50.30.9 with SMTP id o9mr4047735igh.0.1383770766386; Wed, 06 Nov 2013 12:46:06 -0800 (PST) Received: from google.com ([172.29.124.25]) by mx.google.com with ESMTPSA id m1sm15929820igj.10.2013.11.06.12.46.05 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 06 Nov 2013 12:46:05 -0800 (PST) Date: Wed, 6 Nov 2013 13:46:03 -0700 From: Bjorn Helgaas To: Yinghai Lu Cc: "linux-pci@vger.kernel.org" , Wei Yang , Nishank Trivedi Subject: Re: [PATCH] PCI: Use pci_is_root_bus() to check for root bus Message-ID: <20131106204603.GA17046@google.com> References: <20131105232903.3790.8738.stgit@bhelgaas-glaptop.roam.corp.google.com> <20131106181558.GA14444@google.com> <20131106201239.GA8971@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FSL_HELO_FAKE, 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 On Wed, Nov 06, 2013 at 12:33:31PM -0800, Yinghai Lu wrote: > >> > commit 4e5415f02e32c85e902cd9692eab18200e14b347 > >> > Author: Bjorn Helgaas > >> > Date: Wed Nov 6 10:00:51 2013 -0700 > >> > > >> > PCI: Enable upstream bridges even for VFs on virtual buses > >> > > >> > Previously we enabled the upstream PCI-to-PCI bridge only when > >> > "dev->bus->self != NULL". In the case of a VF on a virtual bus, where > >> > "bus->self == NULL", we didn't enable the upstream bridge. > >> > > >> > This fixes that by enabling the upstream bridge of the PF corresponding to > >> > the VF. > >> > > >> > Signed-off-by: Bjorn Helgaas > >> > > >> > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > >> > index ac40f90..744dc26 100644 > >> > --- a/drivers/pci/pci.c > >> > +++ b/drivers/pci/pci.c > >> > @@ -1150,10 +1150,8 @@ static void pci_enable_bridge(struct pci_dev *dev) > >> > { > >> > int retval; > >> > > >> > - if (!dev) > >> > - return; > >> > - > >> > - pci_enable_bridge(dev->bus->self); > >> > + if (!pci_is_root_bus(dev->bus)) > >> > + pci_enable_bridge(pci_upstream_bridge(dev)); > >> > > >> > if (pci_is_enabled(dev)) { > >> > if (!dev->is_busmaster) > >> > @@ -1188,7 +1186,8 @@ static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags) > >> > if (atomic_inc_return(&dev->enable_cnt) > 1) > >> > return 0; /* already enabled */ > >> > > >> > - pci_enable_bridge(dev->bus->self); > >> > + if (!pci_is_root_bus(dev->bus)) > >> > + pci_enable_bridge(pci_upstream_bridge(dev)); > >> > > >> > /* only skip sriov related */ > >> > for (i = 0; i <= PCI_ROM_RESOURCE; i++) > >> > >> still have problem. > >> > >> pci_upstream_bridge() could return NULL. so later pci_enable_bridge() > >> referring dev->bus could panic, as you remove !dev checking. > > > > pci_upstream_bridge(dev) can only return NULL if dev is on a root bus, > > and we never call pci_enable_bridge() in that case. So I don't see > > the problem. > > how about it is VF and it is on it's own virtual bus ? > and it will pass !pci_is_root_bus(dev->bus) checking and get into > pci_enable_bridge(pci_upstream_bridge(dev)); Oh, I see. The problem is when VF is on a virtual bus and the corresponding PF is on a root bus. Then we have: pci_is_root_bus(VF) == false pci_upstream_bridge(VF) == pci_upstream_bridge(PF) pci_uptream_bridge(PF) == NULL I guess that's what your suggestion about "caching the return from pci_upstream_bridge()" was about. Like this: commit 21ea57bf1311f7a8d1b755d355322a1f077fccb7 Author: Bjorn Helgaas Date: Wed Nov 6 10:11:48 2013 -0700 PCI: Add pci_upstream_bridge() This adds a pci_upstream_bridge() interface to find the PCI-to-PCI bridge upstream from a device. This is typically just "dev->bus->self", but in the case of a VF on a virtual bus, we have to start from the corresponding PF. Returns NULL if there is no upstream PCI bridge, i.e., if the device is on a root bus. Signed-off-by: Bjorn Helgaas Acked-by: Yinghai Lu --- 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/include/linux/pci.h b/include/linux/pci.h index d3a888a..835ec7b 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -480,6 +480,15 @@ static inline bool pci_is_root_bus(struct pci_bus *pbus) return !(pbus->parent); } +static inline struct pci_dev *pci_upstream_bridge(struct pci_dev *dev) +{ + dev = pci_physfn(dev); + if (pci_is_root_bus(dev->bus)) + return NULL; + + return dev->bus->self; +} + #ifdef CONFIG_PCI_MSI static inline bool pci_dev_msi_enabled(struct pci_dev *pci_dev) { commit bca690ab580d5c0c4a0c7201f3c42057288add8b Author: Bjorn Helgaas Date: Wed Nov 6 10:00:51 2013 -0700 PCI: Enable upstream bridges even for VFs on virtual buses Previously we enabled the upstream PCI-to-PCI bridge only when "dev->bus->self != NULL". In the case of a VF on a virtual bus, where "bus->self == NULL", we didn't enable the upstream bridge. This fixes that by enabling the upstream bridge of the PF corresponding to the VF. Signed-off-by: Bjorn Helgaas diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index ac40f90..d3ed931 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1148,12 +1148,12 @@ int pci_reenable_device(struct pci_dev *dev) static void pci_enable_bridge(struct pci_dev *dev) { + struct pci_dev *bridge; int retval; - if (!dev) - return; - - pci_enable_bridge(dev->bus->self); + bridge = pci_upstream_bridge(dev); + if (bridge) + pci_enable_bridge(bridge); if (pci_is_enabled(dev)) { if (!dev->is_busmaster) @@ -1170,6 +1170,7 @@ static void pci_enable_bridge(struct pci_dev *dev) static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags) { + struct pci_dev *bridge; int err; int i, bars = 0; @@ -1188,7 +1189,9 @@ static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags) if (atomic_inc_return(&dev->enable_cnt) > 1) return 0; /* already enabled */ - pci_enable_bridge(dev->bus->self); + bridge = pci_upstream_bridge(dev); + if (bridge) + pci_enable_bridge(bridge); /* only skip sriov related */ for (i = 0; i <= PCI_ROM_RESOURCE; i++)