linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yinghai Lu <yinghai@kernel.org>
To: Jiang Liu <liuj97@gmail.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	Tony Luck <tony.luck@intel.com>, Jiang Liu <jiang.liu@huawei.com>,
	Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>,
	Yijing Wang <wangyijing@huawei.com>,
	linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v2 2/9] PCI: split registration of PCI bus devices into two stages
Date: Sat, 15 Sep 2012 11:47:43 -0700	[thread overview]
Message-ID: <CAE9FiQX=NoSBY1vJSqEpRASY92A1C0x2rZONx1Xor_Zm4zCweQ@mail.gmail.com> (raw)
In-Reply-To: <CAE9FiQVyEskBfBxM90fD2BFVNGTYa75QCtkZp+5n8cLh3y395Q@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 347 bytes --]

On Sat, Sep 15, 2012 at 1:03 AM, Yinghai Lu <yinghai@kernel.org> wrote:
> On Fri, Sep 14, 2012 at 8:05 PM, Jiang Liu <liuj97@gmail.com> wrote:
>
> failing path in pci_create_root_bus is not handled.
>
> you could try to move
>
>      device_initialize(&b->dev);
>
> to
>      pci_add_new_bus and pci_create_root_bus instead.

sth like attached...

[-- Attachment #2: jiang_hotplug_rework_2.patch --]
[-- Type: application/octet-stream, Size: 6513 bytes --]

                                                                                                                                                                                                                                                               
Delivered-To: yhlu.kernel@gmail.com
Received: by 10.205.37.138 with SMTP id te10csp185645bkb;
        Fri, 14 Sep 2012 20:13:03 -0700 (PDT)
Received: by 10.68.203.230 with SMTP id kt6mr7970238pbc.163.1347678782659;
        Fri, 14 Sep 2012 20:13:02 -0700 (PDT)
Return-Path: <liuj97@gmail.com>
Received: from mail.kernel.org (mail.kernel.org. [198.145.19.201])
        by mx.google.com with ESMTP id vn9si5410909pbc.317.2012.09.14.20.13.01;
        Fri, 14 Sep 2012 20:13:02 -0700 (PDT)
Received-SPF: neutral (google.com: 198.145.19.201 is neither permitted nor denied by domain of liuj97@gmail.com) client-ip=198.145.19.201;
Authentication-Results: mx.google.com; spf=neutral (google.com: 198.145.19.201 is neither permitted nor denied by domain of liuj97@gmail.com) smtp.mail=liuj97@gmail.com; dkim=pass header.i=@gmail.com
Received: by mail.kernel.org (Postfix)
	id C785B20172; Sat, 15 Sep 2012 03:13:01 +0000 (UTC)
Delivered-To: yinghai@kernel.org
Received: from mail.kernel.org (localhost [127.0.0.1])
	by mail.kernel.org (Postfix) with ESMTP id 24CED2017B
	for <yinghai@kernel.org>; Sat, 15 Sep 2012 03:13:01 +0000 (UTC)
Received: from mail-pb0-f44.google.com (mail-pb0-f44.google.com [209.85.160.44])
	by mail.kernel.org (Postfix) with ESMTP id A7ACE20172
	for <yinghai@kernel.org>; Sat, 15 Sep 2012 03:12:56 +0000 (UTC)
Received: by mail-pb0-f44.google.com with SMTP id rr4so6641777pbb.3
        for <yinghai@kernel.org>; Fri, 14 Sep 2012 20:12:56 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;
        bh=7rI/5ErxmvnHqd6Af99njMHdZQSxcg1oSVXxgmJquvs=;
        b=Wle4FFXnXo4hq0F3+7hDY+JVZQKwYc0/TW1xcAOF7doqwbf6rGkLcoYUzPQF+oJU1u
         dDORpq5BCeVhi/LWROGltmJUZ4FAzjRJzc/3s/YFIb01K5PtXqchf1GgHUgnlLvywL0Z
         yarvhCwUWL9WTqd4h4ahVB4dOp00E9ygJDuYkmqe0R7oQuw8YmUxMVqeSLQLzIC3t2/U
         6L97tQ6GauyqrChnzyrmXNLcC9Hij4GaquWUXWzz71KxCejEWRPrvzFEjeAAOZ+TIeU8
         b+QI4m1eC2OV3zODrNtZK7B/0W3SswGvXN6bVZ147VYv74nrzXP4WgRH6MN3XbaBlj/p
         Q+mA==
Received: by 10.66.90.38 with SMTP id bt6mr6924001pab.53.1347678776513;
        Fri, 14 Sep 2012 20:12:56 -0700 (PDT)
Received: from localhost.localdomain ([221.221.18.122])
        by mx.google.com with ESMTPS id jz10sm2092777pbc.8.2012.09.14.20.12.43
        (version=TLSv1/SSLv3 cipher=OTHER);
        Fri, 14 Sep 2012 20:12:49 -0700 (PDT)
From: Jiang Liu <liuj97@gmail.com>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: Tony Luck <tony.luck@intel.com>,
	Jiang Liu <jiang.liu@huawei.com>,
	Yinghai Lu <yinghai@kernel.org>,
	Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>,
	Yijing Wang <wangyijing@huawei.com>,
	Jiang Liu <liuj97@gmail.com>,
	linux-kernel@vger.kernel.org,
	linux-pci@vger.kernel.org
Subject: [PATCH v2 2/9] PCI: split registration of PCI bus devices into two stages
Date: Sat, 15 Sep 2012 11:05:05 +0800
Message-Id: <1347678312-11124-3-git-send-email-jiang.liu@huawei.com>
X-Mailer: git-send-email 1.7.9.5
In-Reply-To: <1347678312-11124-1-git-send-email-jiang.liu@huawei.com>
References: <1347678312-11124-1-git-send-email-jiang.liu@huawei.com>
X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,
	RCVD_IN_DNSWL_LOW,UNPARSEABLE_RELAY autolearn=ham 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

When handling BUS_NOTIFY_ADD_DEVICE event for a PCI bridge device,
the notification handler can't hold reference count to the new PCI bus
because the device object for the new bus (pci_dev->subordinate->dev)
hasn't been initialized yet.

Split the registration of PCI bus device into two stages as below,
so that the event handler could hold reference count to the new PCI bus
when handling BUS_NOTIFY_ADD_DEVICE event.

1) device_initialize(&pci_dev->dev)
2) device_initialize(&pci_dev->subordinate->dev)
3) notify BUS_NOTIFY_ADD_DEVICE event for pci_dev
4) device_add(&pci_dev->dev)
5) device_add(&pci_dev->subordinate->dev)

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
---
 drivers/pci/bus.c    |    2 +-
 drivers/pci/probe.c  |    4 +++-
 drivers/pci/remove.c |   10 +++++-----
 3 files changed, 9 insertions(+), 7 deletions(-)

Index: linux-2.6/drivers/pci/bus.c
===================================================================
--- linux-2.6.orig/drivers/pci/bus.c
+++ linux-2.6/drivers/pci/bus.c
@@ -193,7 +193,7 @@ int pci_bus_add_child(struct pci_bus *bu
 	if (bus->bridge)
 		bus->dev.parent = bus->bridge;
 
-	retval = device_register(&bus->dev);
+	retval = device_add(&bus->dev);
 	if (retval)
 		return retval;
 
Index: linux-2.6/drivers/pci/probe.c
===================================================================
--- linux-2.6.orig/drivers/pci/probe.c
+++ linux-2.6/drivers/pci/probe.c
@@ -637,6 +637,7 @@ static struct pci_bus *pci_alloc_child_b
 	 * now as the parent is not properly set up yet.  This device will get
 	 * registered later in pci_bus_add_devices()
 	 */
+	device_initialize(&child->dev);
 	child->dev.class = &pcibus_class;
 	dev_set_name(&child->dev, "%04x:%02x", pci_domain_nr(child), busnr);
 
@@ -1669,10 +1670,11 @@ struct pci_bus *pci_create_root_bus(stru
 	if (!parent)
 		set_dev_node(b->bridge, pcibus_to_node(b));
 
+	device_initialize(&b->dev);
 	b->dev.class = &pcibus_class;
 	b->dev.parent = b->bridge;
 	dev_set_name(&b->dev, "%04x:%02x", pci_domain_nr(b), bus);
-	error = device_register(&b->dev);
+	error = device_add(&b->dev);
 	if (error)
 		goto class_dev_reg_err;
 
Index: linux-2.6/drivers/pci/remove.c
===================================================================
--- linux-2.6.orig/drivers/pci/remove.c
+++ linux-2.6/drivers/pci/remove.c
@@ -48,11 +48,11 @@ void pci_remove_bus(struct pci_bus *bus)
 	list_del(&bus->node);
 	pci_bus_release_busn_res(bus);
 	up_write(&pci_bus_sem);
-	if (!bus->is_added)
-		return;
-
-	pci_remove_legacy_files(bus);
-	device_unregister(&bus->dev);
+	if (bus->is_added) {
+		pci_remove_legacy_files(bus);
+		device_del(&bus->dev);
+	}
+	put_device(&bus->dev);
 }
 EXPORT_SYMBOL(pci_remove_bus);
 

  reply	other threads:[~2012-09-15 18:47 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-15  3:05 [PATCH v2 0/9] enhance PCI related drivers to handle hotplug events Jiang Liu
2012-09-15  3:05 ` [PATCH v2 1/9] PCI: make PCI device create/destroy logic symmetric Jiang Liu
2012-09-15  3:05 ` [PATCH v2 2/9] PCI: split registration of PCI bus devices into two stages Jiang Liu
2012-09-15  8:03   ` Yinghai Lu
2012-09-15 18:47     ` Yinghai Lu [this message]
2012-09-16 13:16       ` [PATCH v3] " Jiang Liu
2012-09-15  3:05 ` [PATCH v2 3/9] PCI: preserve dev->subordinate until pci_stop_dev() has been called Jiang Liu
2012-09-15  5:09   ` Yinghai Lu
2012-09-15  7:02     ` Jiang Liu
2012-09-15  3:05 ` [PATCH v2 4/9] ACPI/pci_bind: correctly update binding relationship for PCI hotplug Jiang Liu
2012-09-15  3:05 ` [PATCH v2 5/9] ACPI/pci-bind: remove bind/unbind callbacks from acpi_device_ops Jiang Liu
2012-09-15 18:53   ` Yinghai Lu
2012-09-16 14:09     ` [PATCH v3] " Jiang Liu
2012-09-16 16:49       ` Yinghai Lu
2012-09-16 18:02         ` Yinghai Lu
2012-09-17  3:06           ` Yinghai Lu
2012-09-17 15:26           ` Jiang Liu
2012-09-15 23:27   ` [PATCH v2 5/9] " Yinghai Lu
2012-09-17  3:03     ` Yinghai Lu
2012-09-17 14:22       ` Jiang Liu
2012-09-17 14:31     ` Jiang Liu
2012-09-17 15:41       ` Yinghai Lu
2012-09-15  3:05 ` [PATCH v2 6/9] ACPI/pci_slot: update PCI slot information when PCI hotplug event happens Jiang Liu
2012-09-15  3:05 ` [PATCH v2 7/9] PCI/acpiphp: update ACPI hotplug slot information when PCI hotplug happens Jiang Liu
2012-09-15  3:05 ` [PATCH v2 8/9] PCI/acpiphp: serialize access to the bridge_list list Jiang Liu
2012-09-15  3:05 ` [PATCH v2 9/9] PCI/AER: update AER configuration when PCI hotplug event happens Jiang Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAE9FiQX=NoSBY1vJSqEpRASY92A1C0x2rZONx1Xor_Zm4zCweQ@mail.gmail.com' \
    --to=yinghai@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=jiang.liu@huawei.com \
    --cc=kaneshige.kenji@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=liuj97@gmail.com \
    --cc=tony.luck@intel.com \
    --cc=wangyijing@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).