linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiang Liu <jiang.liu@huawei.com>
To: "Rafael J . Wysocki" <rjw@sisk.pl>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Yinghai Lu <yinghai@kernel.org>,
	"Alexander E . Patrakov" <patrakov@gmail.com>
Cc: Jiang Liu <jiang.liu@huawei.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Yijing Wang <wangyijing@huawei.com>,
	linux-acpi@vger.kernel.org, Jiang Liu <liuj97@gmail.com>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Subject: [BUGFIX v2 3/4] PCI, ACPI: fix device destroying order issue when handling dock notification
Date: Sat, 15 Jun 2013 03:28:00 +0800	[thread overview]
Message-ID: <1371238081-32260-4-git-send-email-jiang.liu@huawei.com> (raw)
In-Reply-To: <1371238081-32260-1-git-send-email-jiang.liu@huawei.com>

Current ACPI glue logic expects that physical devices are destroyed
before destroying companion ACPI devices, otherwise it will break the
ACPI unbind logic and cause following warning messages:
[  185.026073] usb usb5: Oops, 'acpi_handle' corrupt
[  185.035150] pci 0000:1b:00.0: Oops, 'acpi_handle' corrupt
[  185.035515] pci 0000:18:02.0: Oops, 'acpi_handle' corrupt
[  180.013656]  port1: Oops, 'acpi_handle' corrupt
Please refer to https://bugzilla.kernel.org/attachment.cgi?id=104321
for full log message.

Above warning messages are caused by following scenario:
1) acpi_dock_notifier_call() queues a task (T1) onto kacpi_hotplug_wq
2) kacpi_hotplug_wq handles T1, which invokes acpi_dock_deferred_cb()
   ->dock_notify()-> handle_eject_request()->hotplug_dock_devices()
3) hotplug_dock_devices() first invokes registered hotplug callbacks to
   destroy physical devices, then destroys all affected ACPI devices.
   Everything seems perfect until now. But the acpiphp dock notification
   handler will queue another task (T2) onto kacpi_hotplug_wq to really
   destroy affected physical devices.
4) kacpi_hotplug_wq finishes T1, and all affected ACPI devices have
   been destroyed.
5) kacpi_hotplug_wq handles T2, which destroys all affected physical
   devices.

So it breaks ACPI glue logic's expection because ACPI devices are destroyed
in step 3 and physical devices are destroyed in step 5.

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Reported-by: Alexander E. Patrakov <patrakov@gmail.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: linux-pci@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org # 3.8+
---
 drivers/pci/hotplug/acpiphp_glue.c | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 5d696f5..a65203b 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -61,6 +61,8 @@ static DEFINE_MUTEX(bridge_mutex);
 static void handle_hotplug_event_bridge (acpi_handle, u32, void *);
 static void acpiphp_sanitize_bus(struct pci_bus *bus);
 static void acpiphp_set_hpp_values(struct pci_bus *bus);
+static void _handle_hotplug_event_func(acpi_handle handle, u32 type,
+				       void *context);
 static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context);
 static void free_bridge(struct kref *kref);
 
@@ -160,7 +162,7 @@ static void acpiphp_dock_put(void *data)
 }
 
 static const struct acpi_dock_ops acpiphp_dock_ops = {
-	.handler = handle_hotplug_event_func,
+	.handler = _handle_hotplug_event_func,
 	.get = acpiphp_dock_get,
 	.put = acpiphp_dock_put,
 };
@@ -1080,22 +1082,13 @@ static void handle_hotplug_event_bridge(acpi_handle handle, u32 type,
 	alloc_acpi_hp_work(handle, type, context, _handle_hotplug_event_bridge);
 }
 
-static void _handle_hotplug_event_func(struct work_struct *work)
+static void _handle_hotplug_event_func(acpi_handle handle, u32 type,
+				       void *context)
 {
-	struct acpiphp_func *func;
+	struct acpiphp_func *func = context;
 	char objname[64];
 	struct acpi_buffer buffer = { .length = sizeof(objname),
 				      .pointer = objname };
-	struct acpi_hp_work *hp_work;
-	acpi_handle handle;
-	u32 type;
-
-	hp_work = container_of(work, struct acpi_hp_work, work);
-	handle = hp_work->handle;
-	type = hp_work->type;
-	func = (struct acpiphp_func *)hp_work->context;
-
-	acpi_scan_lock_acquire();
 
 	acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
 
@@ -1128,7 +1121,18 @@ static void _handle_hotplug_event_func(struct work_struct *work)
 		warn("notify_handler: unknown event type 0x%x for %s\n", type, objname);
 		break;
 	}
+}
+
+static void _handle_hotplug_event_cb(struct work_struct *work)
+{
+	struct acpiphp_func *func;
+	struct acpi_hp_work *hp_work;
 
+	hp_work = container_of(work, struct acpi_hp_work, work);
+	func = (struct acpiphp_func *)hp_work->context;
+	acpi_scan_lock_acquire();
+	_handle_hotplug_event_func(hp_work->handle, hp_work->type,
+				    hp_work->context);
 	acpi_scan_lock_release();
 	kfree(hp_work); /* allocated in handle_hotplug_event_func */
 	put_bridge(func->slot->bridge);
@@ -1156,7 +1160,7 @@ static void handle_hotplug_event_func(acpi_handle handle, u32 type,
 	 * don't deadlock on hotplug actions.
 	 */
 	get_bridge(func->slot->bridge);
-	alloc_acpi_hp_work(handle, type, context, _handle_hotplug_event_func);
+	alloc_acpi_hp_work(handle, type, context, _handle_hotplug_event_cb);
 }
 
 /*
-- 
1.8.1.2


  parent reply	other threads:[~2013-06-14 19:28 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-14 19:27 [BUGFIX v2 0/4] fix bug 56531, 59501 and 59581 Jiang Liu
2013-06-14 19:27 ` [BUGFIX v2 1/4] ACPI, DOCK: initialize dock subsystem before scanning PCI root buses Jiang Liu
2013-06-15  6:51   ` Yinghai Lu
2013-06-15 10:05     ` Jiang Liu
2013-06-15 20:03       ` Rafael J. Wysocki
2013-06-14 19:27 ` [BUGFIX v2 2/4] ACPI, DOCK: resolve possible deadlock scenarios Jiang Liu
2013-06-14 22:21   ` Rafael J. Wysocki
2013-06-15  1:44     ` Jiang Liu
2013-06-15 20:17       ` Rafael J. Wysocki
2013-06-15 21:20         ` Rafael J. Wysocki
2013-06-15 22:54           ` Rafael J. Wysocki
2013-06-16 17:12             ` Jiang Liu
2013-06-17 11:40               ` Rafael J. Wysocki
2013-06-18 16:03                 ` Jiang Liu
2013-06-18 21:25                   ` Rafael J. Wysocki
2013-06-16 17:01           ` Jiang Liu
2013-06-17 11:39             ` Rafael J. Wysocki
2013-06-17 12:54               ` Rafael J. Wysocki
2013-06-18 15:36               ` Jiang Liu
2013-06-18 21:12                 ` Rafael J. Wysocki
2013-06-16 16:27         ` Jiang Liu
2013-06-14 19:28 ` Jiang Liu [this message]
2013-06-15  6:50   ` [BUGFIX v2 3/4] PCI, ACPI: fix device destroying order issue when handling dock notification Yinghai Lu
2013-06-14 19:28 ` [BUGFIX v2 4/4] ACPIPHP: fix bug 56531 Sony VAIO VPCZ23A4R: can't assign mem/io after docking Jiang Liu
2013-06-14 21:03   ` Yinghai Lu
2013-06-17 11:57   ` Rafael J. Wysocki
2013-06-15  6:42 ` [BUGFIX v2 0/4] fix bug 56531, 59501 and 59581 Alexander E. Patrakov
2013-06-15  7:25   ` Alexander E. Patrakov
2013-06-18 21:35     ` Rafael J. Wysocki
2013-06-19  5:18       ` Alexander E. Patrakov
2013-06-20 19:06         ` Rafael J. Wysocki
2013-06-21  4:36           ` Alexander E. Patrakov
2013-06-21  4:37             ` Alexander E. Patrakov
2013-06-21 13:06               ` Rafael J. Wysocki
2013-06-21 12:47             ` Rafael J. Wysocki
2013-06-21 13:02               ` Alexander E. Patrakov
2013-06-21 16:54           ` Jiang Liu
2013-06-22  0:13             ` Rafael J. Wysocki
2013-06-22  2:47               ` Jiang Liu
2013-06-22 19:59                 ` Rafael J. Wysocki
2013-06-23 15:57                   ` Jiang Liu
2013-06-23 21:51                     ` Rafael J. Wysocki
2013-06-23 21:52                     ` Rafael J. Wysocki
2013-06-16 17:33   ` Jiang Liu
2013-06-17  3:27     ` Alexander E. Patrakov
2013-06-17 17:07       ` Alexander E. Patrakov
2013-06-18 15:13         ` 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=1371238081-32260-4-git-send-email-jiang.liu@huawei.com \
    --to=jiang.liu@huawei.com \
    --cc=bhelgaas@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=liuj97@gmail.com \
    --cc=patrakov@gmail.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rjw@sisk.pl \
    --cc=wangyijing@huawei.com \
    --cc=yinghai@kernel.org \
    /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).