From patchwork Sat Aug 4 18:19:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 1273991 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id AFBDADF24C for ; Sat, 4 Aug 2012 18:20:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753823Ab2HDSTd (ORCPT ); Sat, 4 Aug 2012 14:19:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:2262 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753968Ab2HDSTc (ORCPT ); Sat, 4 Aug 2012 14:19:32 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q74IJUn7005853 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 4 Aug 2012 14:19:30 -0400 Received: from bling.home (ovpn-113-63.phx2.redhat.com [10.3.113.63]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q74IJTSg018018; Sat, 4 Aug 2012 14:19:30 -0400 From: Alex Williamson Subject: [PATCH] pci: Account for virtual buses in pci_acs_path_enabled To: bhelgaas@google.com Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, dsahern@gmail.com Date: Sat, 04 Aug 2012 12:19:29 -0600 Message-ID: <20120804181445.6598.6505.stgit@bling.home> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org It's possible to have buses without an associated bridge (bus->self == NULL). SR-IOV can generate such buses. When we find these, skip to the parent bus to look for the next ACS test. Signed-off-by: Alex Williamson Tested-by: David Ahern --- David Ahern reported an oops from iommu drivers passing NULL into this function for the same mistake. Harden this function against assuming bus->self is valid as well. David, please include this patch as well as the iommu patches in your testing. drivers/pci/pci.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 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 f3ea977..e11a49c 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2486,18 +2486,30 @@ bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags) bool pci_acs_path_enabled(struct pci_dev *start, struct pci_dev *end, u16 acs_flags) { - struct pci_dev *pdev, *parent = start; + struct pci_dev *pdev = start; + struct pci_bus *bus; do { - pdev = parent; - if (!pci_acs_enabled(pdev, acs_flags)) return false; - if (pci_is_root_bus(pdev->bus)) + bus = pdev->bus; + + if (pci_is_root_bus(bus)) return (end == NULL); - parent = pdev->bus->self; + /* + * Skip buses without an associated bridge. In this + * case move to the parent and continue. + */ + while (!bus->self) { + if (!pci_is_root_bus(bus)) + bus = bus->parent; + else + return (end == NULL); + } + + pdev = bus->self; } while (pdev != end); return true;