* [PATCH v2] ACPI: Fix resource_lock dead lock in acpi_power_on_device
@ 2012-09-12 9:07 Aaron Lu
2012-09-13 22:26 ` Rafael J. Wysocki
0 siblings, 1 reply; 5+ messages in thread
From: Aaron Lu @ 2012-09-12 9:07 UTC (permalink / raw)
To: Leb Brown; +Cc: linux-acpi, linux-pm, Aaron Lu, Aaron Lu
Commit 0090def("ACPI: Add interface to register/unregister device
to/from power resources") used resource_lock to protect the devices list
that relies on power resource. It caused a mutex dead lock, as below
acpi_power_on ---> lock resource_lock
__acpi_power_on
acpi_power_on_device
acpi_power_get_inferred_state
acpi_power_get_list_state ---> lock resource_lock
This patch adds a new mutex "devices_lock" to protect the devices list
and calls acpi_power_on_device in acpi_power_on, instead of
__acpi_power_on, after the resource_lock is released.
Signed-off-by: Lin Ming <ming.m.lin@intel.com>
Signed-off-by: Aaron Lu <aaron.lu@intel.com>
---
v2:
If power resource is already on, no need to check if device needs
to be resumed.
v1:
By Lin Ming.
drivers/acpi/power.c | 36 ++++++++++++++++++++++++------------
1 file changed, 24 insertions(+), 12 deletions(-)
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index 215ecd0..3582a26 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -105,6 +105,7 @@ struct acpi_power_resource {
/* List of devices relying on this power resource */
struct acpi_power_resource_device *devices;
+ struct mutex devices_lock;
};
static struct list_head acpi_power_resource_list;
@@ -223,7 +224,6 @@ static void acpi_power_on_device(struct acpi_power_managed_device *device)
static int __acpi_power_on(struct acpi_power_resource *resource)
{
- struct acpi_power_resource_device *device_list = resource->devices;
acpi_status status = AE_OK;
status = acpi_evaluate_object(resource->device->handle, "_ON", NULL, NULL);
@@ -236,19 +236,14 @@ static int __acpi_power_on(struct acpi_power_resource *resource)
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Power resource [%s] turned on\n",
resource->name));
- while (device_list) {
- acpi_power_on_device(device_list->device);
-
- device_list = device_list->next;
- }
-
return 0;
}
static int acpi_power_on(acpi_handle handle)
{
- int result = 0;
+ int result = 0, resume_device = 0;
struct acpi_power_resource *resource = NULL;
+ struct acpi_power_resource_device *device_list;
result = acpi_power_get_context(handle, &resource);
if (result)
@@ -264,10 +259,26 @@ static int acpi_power_on(acpi_handle handle)
result = __acpi_power_on(resource);
if (result)
resource->ref_count--;
+ else
+ resume_device = 1;
}
mutex_unlock(&resource->resource_lock);
+ if (!resume_device)
+ return result;
+
+ mutex_lock(&resource->devices_lock);
+
+ device_list = resource->devices;
+ while (device_list) {
+ acpi_power_on_device(device_list->device);
+
+ device_list = device_list->next;
+ }
+
+ mutex_unlock(&resource->devices_lock);
+
return result;
}
@@ -353,7 +364,7 @@ static void __acpi_power_resource_unregister_device(struct device *dev,
if (acpi_power_get_context(res_handle, &resource))
return;
- mutex_lock(&resource->resource_lock);
+ mutex_lock(&resource->devices_lock);
prev = NULL;
curr = resource->devices;
while (curr) {
@@ -370,7 +381,7 @@ static void __acpi_power_resource_unregister_device(struct device *dev,
prev = curr;
curr = curr->next;
}
- mutex_unlock(&resource->resource_lock);
+ mutex_unlock(&resource->devices_lock);
}
/* Unlink dev from all power resources in _PR0 */
@@ -412,10 +423,10 @@ static int __acpi_power_resource_register_device(
power_resource_device->device = powered_device;
- mutex_lock(&resource->resource_lock);
+ mutex_lock(&resource->devices_lock);
power_resource_device->next = resource->devices;
resource->devices = power_resource_device;
- mutex_unlock(&resource->resource_lock);
+ mutex_unlock(&resource->devices_lock);
return 0;
}
@@ -719,6 +730,7 @@ static int acpi_power_add(struct acpi_device *device)
resource->device = device;
mutex_init(&resource->resource_lock);
+ mutex_init(&resource->devices_lock);
strcpy(resource->name, device->pnp.bus_id);
strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
strcpy(acpi_device_class(device), ACPI_POWER_CLASS);
--
1.7.12.21.g871e293
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] ACPI: Fix resource_lock dead lock in acpi_power_on_device
2012-09-12 9:07 [PATCH v2] ACPI: Fix resource_lock dead lock in acpi_power_on_device Aaron Lu
@ 2012-09-13 22:26 ` Rafael J. Wysocki
2012-09-14 1:15 ` Aaron Lu
0 siblings, 1 reply; 5+ messages in thread
From: Rafael J. Wysocki @ 2012-09-13 22:26 UTC (permalink / raw)
To: Aaron Lu; +Cc: Leb Brown, linux-acpi, linux-pm, Aaron Lu
On Wednesday, September 12, 2012, Aaron Lu wrote:
> Commit 0090def("ACPI: Add interface to register/unregister device
> to/from power resources") used resource_lock to protect the devices list
> that relies on power resource. It caused a mutex dead lock, as below
>
> acpi_power_on ---> lock resource_lock
> __acpi_power_on
> acpi_power_on_device
> acpi_power_get_inferred_state
> acpi_power_get_list_state ---> lock resource_lock
>
> This patch adds a new mutex "devices_lock" to protect the devices list
> and calls acpi_power_on_device in acpi_power_on, instead of
> __acpi_power_on, after the resource_lock is released.
>
> Signed-off-by: Lin Ming <ming.m.lin@intel.com>
> Signed-off-by: Aaron Lu <aaron.lu@intel.com>
Good catch, thanks.
I hope Len won't mind if I take it for v3.6.
> ---
> v2:
> If power resource is already on, no need to check if device needs
> to be resumed.
> v1:
> By Lin Ming.
>
> drivers/acpi/power.c | 36 ++++++++++++++++++++++++------------
> 1 file changed, 24 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
> index 215ecd0..3582a26 100644
> --- a/drivers/acpi/power.c
> +++ b/drivers/acpi/power.c
> @@ -105,6 +105,7 @@ struct acpi_power_resource {
>
> /* List of devices relying on this power resource */
> struct acpi_power_resource_device *devices;
> + struct mutex devices_lock;
> };
>
> static struct list_head acpi_power_resource_list;
> @@ -223,7 +224,6 @@ static void acpi_power_on_device(struct acpi_power_managed_device *device)
>
> static int __acpi_power_on(struct acpi_power_resource *resource)
> {
> - struct acpi_power_resource_device *device_list = resource->devices;
> acpi_status status = AE_OK;
>
> status = acpi_evaluate_object(resource->device->handle, "_ON", NULL, NULL);
> @@ -236,19 +236,14 @@ static int __acpi_power_on(struct acpi_power_resource *resource)
> ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Power resource [%s] turned on\n",
> resource->name));
>
> - while (device_list) {
> - acpi_power_on_device(device_list->device);
> -
> - device_list = device_list->next;
> - }
> -
> return 0;
> }
>
> static int acpi_power_on(acpi_handle handle)
> {
> - int result = 0;
> + int result = 0, resume_device = 0;
I'll change the data type of resume_device to bool when applying the patch.
> struct acpi_power_resource *resource = NULL;
> + struct acpi_power_resource_device *device_list;
>
> result = acpi_power_get_context(handle, &resource);
> if (result)
> @@ -264,10 +259,26 @@ static int acpi_power_on(acpi_handle handle)
> result = __acpi_power_on(resource);
> if (result)
> resource->ref_count--;
> + else
> + resume_device = 1;
> }
>
> mutex_unlock(&resource->resource_lock);
>
> + if (!resume_device)
> + return result;
> +
> + mutex_lock(&resource->devices_lock);
> +
> + device_list = resource->devices;
> + while (device_list) {
> + acpi_power_on_device(device_list->device);
> +
> + device_list = device_list->next;
> + }
> +
> + mutex_unlock(&resource->devices_lock);
> +
> return result;
> }
>
> @@ -353,7 +364,7 @@ static void __acpi_power_resource_unregister_device(struct device *dev,
> if (acpi_power_get_context(res_handle, &resource))
> return;
>
> - mutex_lock(&resource->resource_lock);
> + mutex_lock(&resource->devices_lock);
> prev = NULL;
> curr = resource->devices;
> while (curr) {
> @@ -370,7 +381,7 @@ static void __acpi_power_resource_unregister_device(struct device *dev,
> prev = curr;
> curr = curr->next;
> }
> - mutex_unlock(&resource->resource_lock);
> + mutex_unlock(&resource->devices_lock);
> }
>
> /* Unlink dev from all power resources in _PR0 */
> @@ -412,10 +423,10 @@ static int __acpi_power_resource_register_device(
>
> power_resource_device->device = powered_device;
>
> - mutex_lock(&resource->resource_lock);
> + mutex_lock(&resource->devices_lock);
> power_resource_device->next = resource->devices;
> resource->devices = power_resource_device;
> - mutex_unlock(&resource->resource_lock);
> + mutex_unlock(&resource->devices_lock);
>
> return 0;
> }
> @@ -719,6 +730,7 @@ static int acpi_power_add(struct acpi_device *device)
>
> resource->device = device;
> mutex_init(&resource->resource_lock);
> + mutex_init(&resource->devices_lock);
> strcpy(resource->name, device->pnp.bus_id);
> strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
> strcpy(acpi_device_class(device), ACPI_POWER_CLASS);
>
Thanks,
Rafael
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] ACPI: Fix resource_lock dead lock in acpi_power_on_device
2012-09-13 22:26 ` Rafael J. Wysocki
@ 2012-09-14 1:15 ` Aaron Lu
2012-09-14 1:21 ` Aaron Lu
0 siblings, 1 reply; 5+ messages in thread
From: Aaron Lu @ 2012-09-14 1:15 UTC (permalink / raw)
To: Rafael J. Wysocki; +Cc: Leb Brown, linux-acpi, linux-pm, Aaron Lu
On 09/14/2012 06:26 AM, Rafael J. Wysocki wrote:
> On Wednesday, September 12, 2012, Aaron Lu wrote:
>> Commit 0090def("ACPI: Add interface to register/unregister device
>> to/from power resources") used resource_lock to protect the devices list
>> that relies on power resource. It caused a mutex dead lock, as below
>>
>> acpi_power_on ---> lock resource_lock
>> __acpi_power_on
>> acpi_power_on_device
>> acpi_power_get_inferred_state
>> acpi_power_get_list_state ---> lock resource_lock
>>
>> This patch adds a new mutex "devices_lock" to protect the devices list
>> and calls acpi_power_on_device in acpi_power_on, instead of
>> __acpi_power_on, after the resource_lock is released.
>>
>> Signed-off-by: Lin Ming <ming.m.lin@intel.com>
>> Signed-off-by: Aaron Lu <aaron.lu@intel.com>
>
> Good catch, thanks.
>
> I hope Len won't mind if I take it for v3.6.
>
Yes, that would be good.
And the commit enters v3.4, so a stable tag may need be added.
>> ---
>> v2:
>> If power resource is already on, no need to check if device needs
>> to be resumed.
>> v1:
>> By Lin Ming.
>>
>> drivers/acpi/power.c | 36 ++++++++++++++++++++++++------------
>> 1 file changed, 24 insertions(+), 12 deletions(-)
>>
>> diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
>> index 215ecd0..3582a26 100644
>> --- a/drivers/acpi/power.c
>> +++ b/drivers/acpi/power.c
>> @@ -105,6 +105,7 @@ struct acpi_power_resource {
>>
>> /* List of devices relying on this power resource */
>> struct acpi_power_resource_device *devices;
>> + struct mutex devices_lock;
>> };
>>
>> static struct list_head acpi_power_resource_list;
>> @@ -223,7 +224,6 @@ static void acpi_power_on_device(struct acpi_power_managed_device *device)
>>
>> static int __acpi_power_on(struct acpi_power_resource *resource)
>> {
>> - struct acpi_power_resource_device *device_list = resource->devices;
>> acpi_status status = AE_OK;
>>
>> status = acpi_evaluate_object(resource->device->handle, "_ON", NULL, NULL);
>> @@ -236,19 +236,14 @@ static int __acpi_power_on(struct acpi_power_resource *resource)
>> ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Power resource [%s] turned on\n",
>> resource->name));
>>
>> - while (device_list) {
>> - acpi_power_on_device(device_list->device);
>> -
>> - device_list = device_list->next;
>> - }
>> -
>> return 0;
>> }
>>
>> static int acpi_power_on(acpi_handle handle)
>> {
>> - int result = 0;
>> + int result = 0, resume_device = 0;
>
> I'll change the data type of resume_device to bool when applying the patch.
>
Sure, thanks.
-Aaron
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] ACPI: Fix resource_lock dead lock in acpi_power_on_device
2012-09-14 1:15 ` Aaron Lu
@ 2012-09-14 1:21 ` Aaron Lu
2012-09-14 19:02 ` Rafael J. Wysocki
0 siblings, 1 reply; 5+ messages in thread
From: Aaron Lu @ 2012-09-14 1:21 UTC (permalink / raw)
To: Rafael J. Wysocki; +Cc: Leb Brown, linux-acpi, linux-pm, Aaron Lu
On 09/14/2012 09:15 AM, Aaron Lu wrote:
>>
>> Good catch, thanks.
>>
>> I hope Len won't mind if I take it for v3.6.
>>
>
> Yes, that would be good.
> And the commit enters v3.4, so a stable tag may need be added.
>
On another thought, it may not be needed for pre v3.6 kernel as the only
code that uses this interface appeared in v3.6-rc1.
Thanks,
Aaron
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] ACPI: Fix resource_lock dead lock in acpi_power_on_device
2012-09-14 1:21 ` Aaron Lu
@ 2012-09-14 19:02 ` Rafael J. Wysocki
0 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2012-09-14 19:02 UTC (permalink / raw)
To: Aaron Lu; +Cc: Leb Brown, linux-acpi, linux-pm, Aaron Lu
On Friday, September 14, 2012, Aaron Lu wrote:
> On 09/14/2012 09:15 AM, Aaron Lu wrote:
> >>
> >> Good catch, thanks.
> >>
> >> I hope Len won't mind if I take it for v3.6.
> >>
> >
> > Yes, that would be good.
> > And the commit enters v3.4, so a stable tag may need be added.
> >
>
> On another thought, it may not be needed for pre v3.6 kernel as the only
> code that uses this interface appeared in v3.6-rc1.
I've added the -stable tag already. It may be useful for backports and the
bug is real.
Thanks,
Rafael
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-09-14 18:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-12 9:07 [PATCH v2] ACPI: Fix resource_lock dead lock in acpi_power_on_device Aaron Lu
2012-09-13 22:26 ` Rafael J. Wysocki
2012-09-14 1:15 ` Aaron Lu
2012-09-14 1:21 ` Aaron Lu
2012-09-14 19:02 ` Rafael J. Wysocki
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).