From patchwork Tue May 26 14:32:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Ostrovsky X-Patchwork-Id: 6482251 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A98139F399 for ; Tue, 26 May 2015 14:32:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A1FA020166 for ; Tue, 26 May 2015 14:32:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 639ED2012B for ; Tue, 26 May 2015 14:32:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752096AbbEZOch (ORCPT ); Tue, 26 May 2015 10:32:37 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:30791 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751275AbbEZOcg (ORCPT ); Tue, 26 May 2015 10:32:36 -0400 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t4QEW6Fm031353 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 26 May 2015 14:32:06 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.13.8/8.13.8) with ESMTP id t4QEW5jn005172 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 26 May 2015 14:32:06 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.13.8/8.13.8) with ESMTP id t4QEW5Uv006502; Tue, 26 May 2015 14:32:05 GMT Received: from dhcp-burlington7-2nd-B-east-10-152-55-162.usdhcp.oraclecorp.com (/10.152.55.112) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 26 May 2015 07:32:04 -0700 Message-ID: <556483E3.4010202@oracle.com> Date: Tue, 26 May 2015 10:32:03 -0400 From: Boris Ostrovsky User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: "Rafael J. Wysocki" , Sander Eikelenboom CC: david.vrabel@citrix.com, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, Bjorn Helgaas , ACPI Devel Maling List , Linux PCI Subject: Re: [PATCH] PCI / ACPI: Do not set ACPI companions for host bridges with parents References: <555FDDA1.8030806@oracle.com> <2059136.yfbqz351P1@vostro.rjw.lan> <1901357.YAorP09rCo@vostro.rjw.lan> <2625308.mOex6suvmm@vostro.rjw.lan> In-Reply-To: <2625308.mOex6suvmm@vostro.rjw.lan> X-Source-IP: userv0022.oracle.com [156.151.31.74] Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, 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 05/25/2015 10:17 PM, Rafael J. Wysocki wrote: > On Tuesday, May 26, 2015 03:08:17 AM Rafael J. Wysocki wrote: >> On Tuesday, May 26, 2015 01:42:16 AM Rafael J. Wysocki wrote: >>> On Tuesday, May 26, 2015 01:22:12 AM Rafael J. Wysocki wrote: >>>> On Friday, May 22, 2015 09:53:37 PM Boris Ostrovsky wrote: >>>>> On 05/22/2015 04:11 AM, Sander Eikelenboom wrote: >>>>>> Hello Sander, >>>>>> >>> >>> [cut] >>> >>>>> (+Rafael again) >>>>> >>>>> So the immediate cause of those errors is that pdev->evtchn is 0. >>>>> Backend is not notified and things not go well then. >>>>> >>>>> And it is indeed caused by 97badf873ab60e841243b66133ff9eff2a46ef29: >>>>> >>>>> We allocate pcifront_sd in pcifront_scan_root() and then pass it to >>>>> pci_scan_bus_parented() as sysdata. Eventually this sysdata is used in >>>>> pcibios_root_bridge_prepare() as pci_sysdata. It is dereferenced as >>>>> pci_sysdata->companion (which I believe is aliased to pcifront_sd->pdev) >>> >>> Well, there is an int node field between them, so I'm not sure. >>> >>>>> and then set_primary_fwnode() writes it, thus corrupting >>>>> pcifront_sd->pdev (and I think this is what sets evtchn to zero). >>> >>> So the corruption happens when set_primary_fwnode() writes NULL to the >>> 'secondary' field of object pointed to by 'fwnode'. >>> >>> This isn't strictly necessary and we might avoid the crash by only >>> writing to fwnode->secondary if fn is not NULL. >>> >>> So, Sander please test the patch below too if possible. >>> >>> Of course, that doesn't solve a problem of passing an incorrect pointer >>> to ACPI_COMPANION_SET() in pcibios_root_bridge_prepare(). >> >> And here's one more thing to test. > > And the below is how I'd fix it, so you can simply test this patch and skip the > previous ones. > > --- > From: Rafael J. Wysocki > Subject: PCI / ACPI: Do not set ACPI companions for host bridges with parents > > Commit 97badf873ab6 (device property: Make it possible to use > secondary firmware nodes) uncovered a bug in the x86 (and ia64) PCI > host bridge initialization code that assumes bridge->bus->sysdata > to always point to a struct pci_sysdata object which need not be > the case (in particular, the Xen PCI frontend driver sets it to point > to a different data type). If it is not the case, an incorrect > pointer (or a piece of data that is not a pointer at all) will be > passed to ACPI_COMPANION_SET() and that may cause interesting > breakage to happen going forward. > > To work around this problem use the observation that the ACPI > host bridge initialization always passes NULL as parent to > pci_create_root_bus(), so if pcibios_root_bridge_prepare() sees > a non-NULL parent of the bridge, it should not attempt to set > an ACPI companion for it, because that means that > pci_create_root_bus() has been called by someone else. I am wondering whether at some point we might want to use companion information in Xen as well. Another option might be to require that whoever creates their own sysdata structure to have pci_sysdata as its first element, e.g. -boris > > Reported-by: Sander Eikelenboom > Signed-off-by: Rafael J. Wysocki > --- > arch/ia64/pci/pci.c | 13 ++++++++++--- > arch/x86/pci/acpi.c | 13 ++++++++++--- > 2 files changed, 20 insertions(+), 6 deletions(-) > > Index: linux-pm/arch/x86/pci/acpi.c > =================================================================== > --- linux-pm.orig/arch/x86/pci/acpi.c > +++ linux-pm/arch/x86/pci/acpi.c > @@ -482,9 +482,16 @@ struct pci_bus *pci_acpi_scan_root(struc > > int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge) > { > - struct pci_sysdata *sd = bridge->bus->sysdata; > - > - ACPI_COMPANION_SET(&bridge->dev, sd->companion); > + /* > + * We pass NULL as parent to pci_create_root_bus(), so if it is not NULL > + * here, pci_create_root_bus() has been called by someone else and > + * sysdata is likely to be different from what we expect. Let it go in > + * that case. > + */ > + if (!bridge->dev.parent) { > + struct pci_sysdata *sd = bridge->bus->sysdata; > + ACPI_COMPANION_SET(&bridge->dev, sd->companion); > + } > return 0; > } > > Index: linux-pm/arch/ia64/pci/pci.c > =================================================================== > --- linux-pm.orig/arch/ia64/pci/pci.c > +++ linux-pm/arch/ia64/pci/pci.c > @@ -478,9 +478,16 @@ struct pci_bus *pci_acpi_scan_root(struc > > int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge) > { > - struct pci_controller *controller = bridge->bus->sysdata; > - > - ACPI_COMPANION_SET(&bridge->dev, controller->companion); > + /* > + * We pass NULL as parent to pci_create_root_bus(), so if it is not NULL > + * here, pci_create_root_bus() has been called by someone else and > + * sysdata is likely to be different from what we expect. Let it go in > + * that case. > + */ > + if (!bridge->dev.parent) { > + struct pci_controller *controller = bridge->bus->sysdata; > + ACPI_COMPANION_SET(&bridge->dev, controller->companion); > + } > return 0; > } > > --- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/drivers/pci/xen-pcifront.c +++ b/drivers/pci/xen-pcifront.c @@ -52,7 +52,12 @@ struct pcifront_device { }; struct pcifront_sd { + /* + * Must be the first element of this structure since pcifront_sd + * is assigned to bus' sysdata and may later be dereferenced as + * pci_sysdata. + */ + struct pci_sysdata sd; struct pcifront_device *pdev; };