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: 9978311 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 681FE60311 for ; Fri, 29 Sep 2017 16:00:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57BD429838 for ; Fri, 29 Sep 2017 16:00:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B4D529842; Fri, 29 Sep 2017 16:00:24 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A5C1629838 for ; Fri, 29 Sep 2017 16:00:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=konwxW1V7dw/q/XJLZdVmuS4M21CHRchcIwMjWU4Nk0=; b=strUXsw/uAl/P/ I5ozaa6tVyWXW9s1Sj/19KwGQv5kl2kWKK4lrODt3meQ13eyIygFoffRufrHf+vLHyQCZ83PLTRR/ bWKjzBtjUX+NoSzbui1Gzu5ScZl12vZtiucpW5SIu07FKVyVGkmgHBN4fA5C3IA6LuV2lDjNTKWqQ 9VhrN8AaFNS4CQAm8WJJ2be1hQ9ofKAALP0Id//YBLOhztwvU1UJ/HRy9zKEU/7djZ9K8YXcxmn8i +eypgE1S7HU0I/MIB9Q6LkrrzvaG2GN2yMKEa3COfvVJ2JLm9mGBJNSvlOolwjH1AmW8cw2oKW0Ho 1R/duxtVLpmp6HUmah4A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dxxi5-0005zw-Ja; Fri, 29 Sep 2017 16:00:17 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dxxi1-0004h7-OL for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2017 16:00:15 +0000 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 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) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170929_090013_815852_6C3E9326 X-CRM114-Status: GOOD ( 26.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ide@vger.kernel.org, Ivan Kokshaysky , linux-arm-kernel@lists.infradead.org, Bjorn Helgaas , Matt Turner , "David S. Miller" , Guenter Roeck , Richard Henderson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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; + } } } }