From patchwork Fri Sep 29 16:02:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Pieralisi X-Patchwork-Id: 9978309 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 4CD6560311 for ; Fri, 29 Sep 2017 16:00:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C76229838 for ; Fri, 29 Sep 2017 16:00:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 303FB29842; Fri, 29 Sep 2017 16:00:09 +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=unavailable 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 D1BC829838 for ; Fri, 29 Sep 2017 16:00:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752092AbdI2P7y (ORCPT ); Fri, 29 Sep 2017 11:59:54 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:45790 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751973AbdI2P7x (ORCPT ); Fri, 29 Sep 2017 11:59:53 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7D4D81529; Fri, 29 Sep 2017 08:59:53 -0700 (PDT) Received: from red-moon (red-moon.cambridge.arm.com [10.1.206.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8D03B3F58C; Fri, 29 Sep 2017 08:59:51 -0700 (PDT) Date: Fri, 29 Sep 2017 17:02:26 +0100 From: Lorenzo Pieralisi To: Bjorn Helgaas Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ide@vger.kernel.org, Ivan Kokshaysky , Guenter Roeck , Bjorn Helgaas , Matt Turner , "David S. Miller" , linux-arm-kernel@lists.infradead.org, Richard Henderson Subject: Re: [PATCH] PCI: Fix legacy IRQ assignment execution stage Message-ID: <20170929160226.GA17398@red-moon> References: <1506598627-8985-1-git-send-email-lorenzo.pieralisi@arm.com> <20170928223719.GY15970@bhelgaas-glaptop.roam.corp.google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170928223719.GY15970@bhelgaas-glaptop.roam.corp.google.com> 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-Virus-Scanned: ClamAV using ClamSMTP On Thu, Sep 28, 2017 at 05:37:19PM -0500, Bjorn Helgaas wrote: > On Thu, Sep 28, 2017 at 12:37:07PM +0100, Lorenzo Pieralisi wrote: > > Through struct pci_host_bridge->{map/swizzle}_irq() hooks is now > > possible to define IRQ mapping functions on a per PCI host bridge basis. > > > > Actual IRQ allocation is carried out by the pci_assign_irq() function in > > pci_device_probe() - to make sure a device is assigned an IRQ only if it > > is probed (ie match a driver); it retrieves a struct pci_host_bridge* > > for a given PCI device and through {map/swizzle}_irq() hooks it carries > > out the PCI IRQ allocation. > > > > As it turned out, some legacy drivers (eg IDE layer) require that a > > device allocates IRQ as soon as it is added so that its actual IRQ > > settings are available early in the boot process. With current code > > calling pci_assign_irq() in pci_device_probe() IDE IRQ probing fails > > for some drivers: > > I think the patch is fine, but I don't understand the changelog. I > want to know specifically what the dependency on dev->irq is. "Early > in the boot process" is pretty vague. > > I *thought* we were doing something like this: > > pci_device_probe(dev1) > pci_assign_irq(dev1) > ... > ide_pci_init_two(dev1, dev2, ...) > do_ide_setup_pci_device(dev1) > pciirq = dev1->irq # this one is fine > do_ide_setup_pci_device(dev2) > pciirq = dev2->irq # not fine > > where the problem is that we haven't called pci_assign_irq(dev2), so > dev2->irq hasn't been set. > > But that doesn't match the data because we should be coming through > cmd64x_init_one(), which calls ide_pci_init_one(), so we shouldn't > have a dev2 in this path. I *think* I understand what's going on here, the key is: ide_scan_pcibus() and CONFIG_IDEPCI_PCIBUS_ORDER I still have to replicate it but I suspect that do_ide_setup_pci_device() for dev1 finds an unallocated IRQ (ie dev->irq == 0) because the probing did NOT happen via pci_device_probe(), ie pci_device_probe() was not called for the dev1, the cmd64x probe routine is called straight from ide_scan_pcidev(). I am struggling to understand the logic behind: ide_pci_register_driver() and ide_scan_pcibus() and the sequence wrt PCI bus probing but I think that's the problem and that's why moving pci_assign_irq() to pci_device_add() will sort this out, adding pci_assign_irq() in ide_scan_pcidev() will solve the problem too (patch below). Needless to say, ide_scan_pcibus() relies on pre_init global variable to make sure ide_pci_register_driver() chooses the "right" way of registering a driver, see: __ide_pci_register_driver() Patch here to verify my assumption in case Guenter has a chance to run it if I do not beat him to it: -- >8 -- diff --git a/drivers/ide/ide-scan-pci.c b/drivers/ide/ide-scan-pci.c index 86aa88a..86b570a 100644 --- a/drivers/ide/ide-scan-pci.c +++ b/drivers/ide/ide-scan-pci.c @@ -56,6 +56,8 @@ static int __init ide_scan_pcidev(struct pci_dev *dev) { struct list_head *l; struct pci_driver *d; + int ret; + list_for_each(l, &ide_pci_drivers) { d = list_entry(l, struct pci_driver, node); @@ -63,10 +65,14 @@ static int __init ide_scan_pcidev(struct pci_dev *dev) const struct pci_device_id *id = pci_match_id(d->id_table, dev); - if (id != NULL && d->probe(dev, id) >= 0) { - dev->driver = d; - pci_dev_get(dev); - return 1; + if (id != NULL) { + pci_assign_irq(dev); + ret = d->probe(dev, id); + if (ret >= 0) { + dev->driver = d; + pci_dev_get(dev); + return 1; + } } } }