fix a deadlock issue when poking "eject" file

"/sys/devices/LNXSYSTM:00/.../eject" is used to evaluate _EJx method
and eject a device in user space.
But system hangs when poking the "eject" file because that
the device hot-removal code invoke the driver .remove method which will
try to remove the "eject" file as a result.

Queues the hot-removal function for deferred execution in this patch.
http://bugzilla.kernel.org/show_bug.cgi?id=9772

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
This commit is contained in:
Zhang Rui 2008-04-29 02:35:48 -04:00 committed by Andi Kleen
parent a3cf859321
commit 26d46867b7

View file

@ -6,6 +6,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/acpi.h> #include <linux/acpi.h>
#include <asm/signal.h>
#include <acpi/acpi_drivers.h> #include <acpi/acpi_drivers.h>
#include <acpi/acinterp.h> /* for acpi_ex_eisa_id_to_string() */ #include <acpi/acinterp.h> /* for acpi_ex_eisa_id_to_string() */
@ -92,17 +93,37 @@ acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, cha
} }
static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL); static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL);
static int acpi_eject_operation(acpi_handle handle, int lockable) static int acpi_bus_hot_remove_device(void *context)
{ {
struct acpi_device *device;
acpi_handle handle = context;
struct acpi_object_list arg_list; struct acpi_object_list arg_list;
union acpi_object arg; union acpi_object arg;
acpi_status status = AE_OK; acpi_status status = AE_OK;
/* if (acpi_bus_get_device(handle, &device))
* TBD: evaluate _PS3? return 0;
*/
if (lockable) { if (!device)
return 0;
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
"Hot-removing device %s...\n", device->dev.bus_id));
if (acpi_bus_trim(device, 1)) {
ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
"Removing device failed\n"));
return -1;
}
/* power off device */
status = acpi_evaluate_object(handle, "_PS3", NULL, NULL);
if (ACPI_FAILURE(status) && status != AE_NOT_FOUND)
ACPI_DEBUG_PRINT((ACPI_DB_WARN,
"Power-off device failed\n"));
if (device->flags.lockable) {
arg_list.count = 1; arg_list.count = 1;
arg_list.pointer = &arg; arg_list.pointer = &arg;
arg.type = ACPI_TYPE_INTEGER; arg.type = ACPI_TYPE_INTEGER;
@ -118,24 +139,19 @@ static int acpi_eject_operation(acpi_handle handle, int lockable)
/* /*
* TBD: _EJD support. * TBD: _EJD support.
*/ */
status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL); status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL);
if (ACPI_FAILURE(status)) { if (ACPI_FAILURE(status))
return (-ENODEV); return -ENODEV;
}
return (0); return 0;
} }
static ssize_t static ssize_t
acpi_eject_store(struct device *d, struct device_attribute *attr, acpi_eject_store(struct device *d, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
int result;
int ret = count; int ret = count;
int islockable;
acpi_status status; acpi_status status;
acpi_handle handle;
acpi_object_type type = 0; acpi_object_type type = 0;
struct acpi_device *acpi_device = to_acpi_device(d); struct acpi_device *acpi_device = to_acpi_device(d);
@ -154,17 +170,9 @@ acpi_eject_store(struct device *d, struct device_attribute *attr,
goto err; goto err;
} }
islockable = acpi_device->flags.lockable; /* remove the device in another thread to fix the deadlock issue */
handle = acpi_device->handle; ret = kernel_thread(acpi_bus_hot_remove_device,
acpi_device->handle, SIGCHLD);
result = acpi_bus_trim(acpi_device, 1);
if (!result)
result = acpi_eject_operation(handle, islockable);
if (result) {
ret = -EBUSY;
}
err: err:
return ret; return ret;
} }