Received: by 10.223.185.116 with SMTP id b49csp4877463wrg; Wed, 7 Mar 2018 02:34:27 -0800 (PST) X-Google-Smtp-Source: AG47ELvhJwdq2p+KuQLxR4Tae1OhyVQpnxYg4PYmR8cyWhALN7v3F51WH8+/weO3H2pFgHnURbqw X-Received: by 10.99.100.67 with SMTP id y64mr18034915pgb.145.1520418867496; Wed, 07 Mar 2018 02:34:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520418867; cv=none; d=google.com; s=arc-20160816; b=Bz4OXCM2HV33NE/lwD4S3lttJcKAEH8eQDqEzF1D1njKfOCX4TQErQG6e6tcUSTSWY gapiVky3321hsvukximP/QFNfSsS+zjfWLvyUZHCqUgR/Ir7gUAYgW6CuOCdKGMojgWd hMrfxSbq5mwnsy2JB3Q1DPzTAZTdODanJKf/LMSgmAret4do9gwqb8b21UW2P7V9TMjg v0kWhaAEGZwcs5rWzRO7qcnrKLVUu+nOAMwIPfr2k3uIX8uo61U1WwdjqOf1Dx38lXvc Wt677Am8ea2Td640CPysS/csW++7wlaUZtbmHbaM1AiEgHpSbLM8hX7gR7ihXxf0Af6o 7XOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=VrqHNb3nOmwcuEU4jnkXC7ZfZOAlwFOs0Bwc3SlYKpk=; b=O3/lLFAcdL+Cd2cL0SXDU5IbxYyphplzocAmywEEtL4AAG97Fp43SKs+QCITdPgWIn zhVZ08l/1grrrxniKBOQ2G0wNfSjEMDSIOd3BlCFwtfrSQSiRwio3jPUCEJqmHxKiBqs iNKulH+TdFUSCu3lgsh+9suV2l7Gz2TwQhPI/Xy3aOF9B4WaB8/G7govoMhm/sFpbRD6 CtOuJkpXVEz5viYQWHqCEcenIKg1+jyhbk/OAcOY8qEGmjYcXsgnC6hb+eMsUNBLbGnU 4uB45/V+Y8ysb47/JHUu1J0VdbVAewFHRapcV2GQMOHOCQW902lVCHh0vSIhve1Si9ES 7ibg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g5-v6si12724341pll.488.2018.03.07.02.34.13; Wed, 07 Mar 2018 02:34:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754210AbeCGKdI (ORCPT + 99 others); Wed, 7 Mar 2018 05:33:08 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:57606 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754153AbeCGKdH (ORCPT ); Wed, 7 Mar 2018 05:33:07 -0500 Received: from 79.184.254.228.ipv4.supernova.orange.pl (79.184.254.228) (HELO aspire.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83) id 34cebeb89bf0d5bc; Wed, 7 Mar 2018 11:33:05 +0100 From: "Rafael J. Wysocki" To: Bjorn Helgaas Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Keith Busch , Sinan Kaya , Lukas Wunner Subject: Re: [PATCH v1 5/9] PCI/portdrv: Remove pcie_port_bus_type link order dependency Date: Wed, 07 Mar 2018 11:33:48 +0100 Message-ID: <7571217.yaDH5TzqWC@aspire.rjw.lan> In-Reply-To: <152040323121.240786.5383276983544773869.stgit@bhelgaas-glaptop.roam.corp.google.com> References: <152040297576.240786.1532465558381209070.stgit@bhelgaas-glaptop.roam.corp.google.com> <152040323121.240786.5383276983544773869.stgit@bhelgaas-glaptop.roam.corp.google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wednesday, March 7, 2018 7:13:51 AM CET Bjorn Helgaas wrote: > From: Bjorn Helgaas > > The pcie_port_bus_type must be registered before drivers that depend on it > can be registered. Those drivers include: > > pcied_init() # PCIe native hotplug driver > aer_service_init() # AER driver > dpc_service_init() # DPC driver > pcie_pme_service_init() # PME driver > > Previously we registered pcie_port_bus_type from pcie_portdrv_init(), a > device_initcall. The callers of pcie_port_service_register() (above) are > also device_initcalls. This is fragile because the device_initcall > ordering depends on link order, which is not explicit. > > Register pcie_port_bus_type from pci_driver_init() along with pci_bus_type. > This removes the link order dependency between portdrv and the pciehp, AER, > DPC, and PCIe PME drivers. > > Signed-off-by: Bjorn Helgaas > --- > drivers/pci/pci-driver.c | 45 +++++++++++++++++++++++++++++++- > drivers/pci/pcie/Makefile | 2 + > drivers/pci/pcie/portdrv_bus.c | 56 ---------------------------------------- > drivers/pci/pcie/portdrv_pci.c | 13 +-------- > 4 files changed, 46 insertions(+), 70 deletions(-) > delete mode 100644 drivers/pci/pcie/portdrv_bus.c > > diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c > index 38ee7c8b4d1a..4db85a0faf34 100644 > --- a/drivers/pci/pci-driver.c > +++ b/drivers/pci/pci-driver.c > @@ -7,6 +7,7 @@ > */ > > #include > +#include > #include > #include > #include > @@ -19,6 +20,7 @@ > #include > #include > #include "pci.h" > +#include "pcie/portdrv.h" > > struct pci_dynid { > struct list_head node; > @@ -1553,8 +1555,49 @@ struct bus_type pci_bus_type = { > }; > EXPORT_SYMBOL(pci_bus_type); > > +#ifdef CONFIG_PCIEPORTBUS > +static int pcie_port_bus_match(struct device *dev, struct device_driver *drv) > +{ > + struct pcie_device *pciedev; > + struct pcie_port_service_driver *driver; > + > + if (drv->bus != &pcie_port_bus_type || dev->bus != &pcie_port_bus_type) > + return 0; > + > + pciedev = to_pcie_device(dev); > + driver = to_service_driver(drv); > + > + if (driver->service != pciedev->service) > + return 0; > + > + if ((driver->port_type != PCIE_ANY_PORT) && > + (driver->port_type != pci_pcie_type(pciedev->port))) > + return 0; > + > + return 1; > +} > + > +struct bus_type pcie_port_bus_type = { > + .name = "pci_express", > + .match = pcie_port_bus_match, > +}; > +EXPORT_SYMBOL_GPL(pcie_port_bus_type); > +#endif > + > static int __init pci_driver_init(void) > { > - return bus_register(&pci_bus_type); > + int ret; > + > + ret = bus_register(&pci_bus_type); > + if (ret) > + return ret; > + > +#ifdef CONFIG_PCIEPORTBUS > + ret = bus_register(&pcie_port_bus_type); > + if (ret) > + return ret; > +#endif > + > + return 0; > } > postcore_initcall(pci_driver_init); > diff --git a/drivers/pci/pcie/Makefile b/drivers/pci/pcie/Makefile > index 223e4c34c29a..e01c10c97b95 100644 > --- a/drivers/pci/pcie/Makefile > +++ b/drivers/pci/pcie/Makefile > @@ -6,7 +6,7 @@ > # Build PCI Express ASPM if needed > obj-$(CONFIG_PCIEASPM) += aspm.o > > -pcieportdrv-y := portdrv_core.o portdrv_pci.o portdrv_bus.o > +pcieportdrv-y := portdrv_core.o portdrv_pci.o > pcieportdrv-$(CONFIG_ACPI) += portdrv_acpi.o > > obj-$(CONFIG_PCIEPORTBUS) += pcieportdrv.o > diff --git a/drivers/pci/pcie/portdrv_bus.c b/drivers/pci/pcie/portdrv_bus.c > deleted file mode 100644 > index f0fba552a0e2..000000000000 > --- a/drivers/pci/pcie/portdrv_bus.c > +++ /dev/null > @@ -1,56 +0,0 @@ > -// SPDX-License-Identifier: GPL-2.0 > -/* > - * File: portdrv_bus.c > - * Purpose: PCI Express Port Bus Driver's Bus Overloading Functions > - * > - * Copyright (C) 2004 Intel > - * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com) > - */ > - > -#include > -#include > -#include > -#include > -#include > - > -#include > -#include "portdrv.h" > - > -static int pcie_port_bus_match(struct device *dev, struct device_driver *drv); > - > -struct bus_type pcie_port_bus_type = { > - .name = "pci_express", > - .match = pcie_port_bus_match, > -}; > -EXPORT_SYMBOL_GPL(pcie_port_bus_type); > - > -static int pcie_port_bus_match(struct device *dev, struct device_driver *drv) > -{ > - struct pcie_device *pciedev; > - struct pcie_port_service_driver *driver; > - > - if (drv->bus != &pcie_port_bus_type || dev->bus != &pcie_port_bus_type) > - return 0; > - > - pciedev = to_pcie_device(dev); > - driver = to_service_driver(drv); > - > - if (driver->service != pciedev->service) > - return 0; > - > - if ((driver->port_type != PCIE_ANY_PORT) && > - (driver->port_type != pci_pcie_type(pciedev->port))) > - return 0; > - > - return 1; > -} > - > -int pcie_port_bus_register(void) > -{ > - return bus_register(&pcie_port_bus_type); > -} > - > -void pcie_port_bus_unregister(void) > -{ > - bus_unregister(&pcie_port_bus_type); > -} > diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c > index c08ebd237242..9475886eeb62 100644 > --- a/drivers/pci/pcie/portdrv_pci.c > +++ b/drivers/pci/pcie/portdrv_pci.c > @@ -259,22 +259,11 @@ static const struct dmi_system_id pcie_portdrv_dmi_table[] __initconst = { > > static int __init pcie_portdrv_init(void) > { > - int retval; > - > if (pcie_ports_disabled) > return -EACCES; > > dmi_check_system(pcie_portdrv_dmi_table); > > - retval = pcie_port_bus_register(); > - if (retval) { > - printk(KERN_WARNING "PCIE: bus_register error: %d\n", retval); > - goto out; > - } > - retval = pci_register_driver(&pcie_portdriver); > - if (retval) > - pcie_port_bus_unregister(); > - out: > - return retval; > + return pci_register_driver(&pcie_portdriver); > } > device_initcall(pcie_portdrv_init); > > Reviewed-by: Rafael J. Wysocki