From patchwork Fri Jul 8 11:49:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Edworthy X-Patchwork-Id: 9220653 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 1B25D60467 for ; Fri, 8 Jul 2016 11:50:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C5112870C for ; Fri, 8 Jul 2016 11:50:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00CFD28711; Fri, 8 Jul 2016 11:50:31 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham 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 82DBB2870C for ; Fri, 8 Jul 2016 11:50:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754948AbcGHLu3 (ORCPT ); Fri, 8 Jul 2016 07:50:29 -0400 Received: from relmlor3.renesas.com ([210.160.252.173]:23967 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755005AbcGHLuE (ORCPT ); Fri, 8 Jul 2016 07:50:04 -0400 Received: from unknown (HELO relmlir4.idc.renesas.com) ([10.200.68.154]) by relmlie2.idc.renesas.com with ESMTP; 08 Jul 2016 20:49:59 +0900 Received: from relmlac2.idc.renesas.com (relmlac2.idc.renesas.com [10.200.69.22]) by relmlir4.idc.renesas.com (Postfix) with ESMTP id 845154F7BE; Fri, 8 Jul 2016 20:49:59 +0900 (JST) Received: by relmlac2.idc.renesas.com (Postfix, from userid 0) id 698792806E; Fri, 8 Jul 2016 20:49:59 +0900 (JST) Received: from relmlac2.idc.renesas.com (localhost [127.0.0.1]) by relmlac2.idc.renesas.com (Postfix) with ESMTP id 650932806D; Fri, 8 Jul 2016 20:49:59 +0900 (JST) Received: from relmlii1.idc.renesas.com [10.200.68.65] by relmlac2.idc.renesas.com with ESMTP id WAF27600; Fri, 8 Jul 2016 20:49:59 +0900 X-IronPort-AV: E=Sophos;i="5.22,559,1449500400"; d="scan'208";a="214689803" Received: from unknown (HELO localhost.localdomain) ([172.29.43.47]) by relmlii1.idc.renesas.com with ESMTP; 08 Jul 2016 20:49:57 +0900 From: Phil Edworthy To: Bjorn Helgaas Cc: , , Phil Edworthy Subject: [RFC] pci: Provide a domain limited version of pdev_fixup_irq Date: Fri, 8 Jul 2016 12:49:55 +0100 Message-Id: <1467978595-25386-1-git-send-email-phil.edworthy@renesas.com> X-Mailer: git-send-email 2.5.0 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 Hi Bjorn, I've marked this as RFC as I guess there might be a better way to do this, but I'm not sure how. I would appreciate your thoughts on this. Thanks Phil --- pdev_fixup_irq() performs interrupt swizzling on all PCI devices, no matter that the device may be on a completely unrelated PCI Host controller. When you have multiple PCI Host controllers, pdev_fixup_irq() can clobber the dev->irq of devices it should not be changing. This has been seen when performing suspend/resume on boards with two R-Car PCIe Host controllers, resulting in a NULL ptr access in __pci_restore_msi_state. This happens because dev->irq has been overwritten with 0, and irq_get_msi_desc(dev->irq) returns NULL. This patch introduces a new function, pci_fixup_irqs_local(), that performs the same operation as pdev_fixup_irq(), but only changes the dev->irq of device on the same domain. Signed-off-by: Phil Edworthy --- drivers/pci/setup-irq.c | 25 ++++++++++++++++++++++--- include/linux/pci.h | 3 +++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/drivers/pci/setup-irq.c b/drivers/pci/setup-irq.c index 95c225b..90ea8fa 100644 --- a/drivers/pci/setup-irq.c +++ b/drivers/pci/setup-irq.c @@ -22,7 +22,8 @@ void __weak pcibios_update_irq(struct pci_dev *dev, int irq) pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq); } -static void pdev_fixup_irq(struct pci_dev *dev, +static void pdev_fixup_irq(int domain_nr, + struct pci_dev *dev, u8 (*swizzle)(struct pci_dev *, u8 *), int (*map_irq)(const struct pci_dev *, u8, u8)) { @@ -48,8 +49,15 @@ static void pdev_fixup_irq(struct pci_dev *dev, if (irq == -1) irq = 0; } - dev->irq = irq; + /* Since pci_fixup_irqs() can be called more than once due to multiple + * host controllers, and we scan all PCI devices, not just those + * attached to this controller, make sure we don't clobber dev->irq + * that has nothing to do with this domain. + */ + if (domain_nr >= 0 && dev->bus->domain_nr != domain_nr) + return; + dev->irq = irq; dev_dbg(&dev->dev, "fixup irq: got %d\n", dev->irq); /* Always tell the device, so the driver knows what is @@ -63,6 +71,17 @@ void pci_fixup_irqs(u8 (*swizzle)(struct pci_dev *, u8 *), struct pci_dev *dev = NULL; for_each_pci_dev(dev) - pdev_fixup_irq(dev, swizzle, map_irq); + pdev_fixup_irq(-1, dev, swizzle, map_irq); } EXPORT_SYMBOL_GPL(pci_fixup_irqs); + +void pci_fixup_irqs_local(struct pci_bus *bus, + u8 (*swizzle)(struct pci_dev *, u8 *), + int (*map_irq)(const struct pci_dev *, u8, u8)) +{ + struct pci_dev *dev = NULL; + + for_each_pci_dev(dev) + pdev_fixup_irq(bus->domain_nr, dev, swizzle, map_irq); +} +EXPORT_SYMBOL_GPL(pci_fixup_irqs_local); diff --git a/include/linux/pci.h b/include/linux/pci.h index 8badb66..37a97df 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1134,6 +1134,9 @@ void pdev_enable_device(struct pci_dev *); int pci_enable_resources(struct pci_dev *, int mask); void pci_fixup_irqs(u8 (*)(struct pci_dev *, u8 *), int (*)(const struct pci_dev *, u8, u8)); +void pci_fixup_irqs_local(struct pci_bus *, + u8 (*)(struct pci_dev *, u8 *), + int (*)(const struct pci_dev *, u8, u8)); #define HAVE_PCI_REQ_REGIONS 2 int __must_check pci_request_regions(struct pci_dev *, const char *); int __must_check pci_request_regions_exclusive(struct pci_dev *, const char *);