Skip to contentSkip to conversation

acpi: Fix possible recursive locking in hwregs.c

PATCH In review Rakib Mullick 3 participants 7 messages Nov 3, 2011 – Nov 5, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 acpi: Fix possible recursive locking in hwregs.c

Calling pm-suspend might trigger a recursive lock in it's code path. In function acpi_hw_clear_acpi_status, acpi_os_acquire_lock holds the lock acpi_gbl_hardware_lock before calling acpi_hw_register_write(), then without releasing acpi_gbl_hardware_lock, this function calls acpi_ev_walk_gpe_list, which tries to hold acpi_gbl_gpe_lock and thus might causes possible recursive lock.

Following patch fixes this scenario by just releasing acpi_gbl_hardware_lock before calling acpi_ev_walk_gpe_list.

Changes since v0(https://lkml.org/lkml/2011/9/21/355):
- Fix changelog, thanks to Lin Ming.

Cc Lin Ming <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Len Brown <[email protected]>

---

drivers/acpi/acpica/hwregs.c +3 -1
index 55accb7..e3110ac 100644
@@ -269,6 +269,9 @@ acpi_status acpi_hw_clear_acpi_status(void)
 
 	status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
 					ACPI_BITMASK_ALL_FIXED_STATUS);
+
+	acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
+
 	if (ACPI_FAILURE(status)) {
 		goto unlock_and_exit;
 	}
@@ -278,7 +281,6 @@ acpi_status acpi_hw_clear_acpi_status(void)
 	status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
 
       unlock_and_exit:
-	acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
 	return_ACPI_STATUS(status);
 }
 
#1 lore raw
Quoted 1 line · Rakib Mullick

Calling pm-suspend might trigger a recursive lock in it's code path. In function acpi_hw_clear_acpi_status,

As I replied at https://lkml.org/lkml/2011/9/22/6, I still don't think there is a recursive lock.

Or do you have a real test case to trigger the recursive lock you mentioned?

Lin Ming

Quoted 39 lines

acpi_os_acquire_lock holds the lock acpi_gbl_hardware_lock before calling acpi_hw_register_write(), then without releasing acpi_gbl_hardware_lock, this function calls acpi_ev_walk_gpe_list, which tries to hold acpi_gbl_gpe_lock and thus might causes possible recursive lock.

Following patch fixes this scenario by just releasing acpi_gbl_hardware_lock before calling acpi_ev_walk_gpe_list.

Changes since v0(https://lkml.org/lkml/2011/9/21/355):
- Fix changelog, thanks to Lin Ming.

Cc Lin Ming <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Len Brown <[email protected]>

---

drivers/acpi/acpica/hwregs.c +3 -1
index 55accb7..e3110ac 100644
@@ -269,6 +269,9 @@ acpi_status acpi_hw_clear_acpi_status(void)
 
 	status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
 					ACPI_BITMASK_ALL_FIXED_STATUS);
+
+	acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
+
 	if (ACPI_FAILURE(status)) {
 		goto unlock_and_exit;
 	}
@@ -278,7 +281,6 @@ acpi_status acpi_hw_clear_acpi_status(void)
 	status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
 
       unlock_and_exit:
-	acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
 	return_ACPI_STATUS(status);
 }
 
#2 lore raw
Quoted 10 lines · Lin Ming
Quoted 2 lines · Rakib Mullick

Calling pm-suspend might trigger a recursive lock in it's code path. In function acpi_hw_clear_acpi_status,

As I replied at https://lkml.org/lkml/2011/9/22/6, I still don't think there is a recursive lock.

Or do you have a real test case to trigger the recursive lock you mentioned?

As I said before, recursive lock trigger's on a modified kernel (when calling pm-suspend), not with the mainline kernel. If you think that, since it's not happening with original kernel, so we shouldn't go for fix - that's a different thing, I don't have any argue. But, the issue is on.

Thanks,
Rakib

#3 lore raw
In reply to Lin Ming

Hi,

Quoted 6 lines · Lin Ming
Quoted 1 line · Rakib Mullick

Calling pm-suspend might trigger a recursive lock in it's code path. In function acpi_hw_clear_acpi_status,

As I replied at https://lkml.org/lkml/2011/9/22/6, I still don't think there is a recursive lock.

At first look, it definitely doesn't look like a recursive lock, as Lin said. But, quoting Documentation/lockdep-design.txt:

"Multi-lock dependency rules:
----------------------------

The same lock-class must not be acquired twice, because this could lead to lock recursion deadlocks."

So, Rakib, do the 2 locks belong to the same lock-class? If yes, then I think that is the reason for the lockdep splat. Could you show the lockdep warning?

By the way, another way to look at this patch is as an optimization.. i.e., if acpi_gbl_hardware_lock doesn't need to be held to call acpi_ev_walk_gpe_list(), then we can move from the coarse-grained locking to finer-grained locking by releasing it earlier, as you did in your patch. [Note that you will have to update the goto label also, i.e., rename it as 'exit' or something like that]

Quoted 38 lines
Quoted 38 lines

acpi_os_acquire_lock holds the lock acpi_gbl_hardware_lock before calling acpi_hw_register_write(), then without releasing acpi_gbl_hardware_lock, this function calls acpi_ev_walk_gpe_list, which tries to hold acpi_gbl_gpe_lock and thus might causes possible recursive lock.

Following patch fixes this scenario by just releasing acpi_gbl_hardware_lock before calling acpi_ev_walk_gpe_list.

Changes since v0(https://lkml.org/lkml/2011/9/21/355):
- Fix changelog, thanks to Lin Ming.

Cc Lin Ming <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Len Brown <[email protected]>

---

drivers/acpi/acpica/hwregs.c +3 -1
index 55accb7..e3110ac 100644
@@ -269,6 +269,9 @@ acpi_status acpi_hw_clear_acpi_status(void)
 
 	status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
 					ACPI_BITMASK_ALL_FIXED_STATUS);
+
+	acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
+
 	if (ACPI_FAILURE(status)) {
 		goto unlock_and_exit;
 	}
@@ -278,7 +281,6 @@ acpi_status acpi_hw_clear_acpi_status(void)
 	status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
 
       unlock_and_exit:
-	acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
 	return_ACPI_STATUS(status);
 }
 
Signature · 4 lines
Regards,
Srivatsa S. Bhat  <[email protected]>
Linux Technology Center,
IBM India Systems and Technology Lab
#4 lore raw
Quoted 13 lines · Srivatsa S. Bhat

Hi,

Quoted 6 lines · Lin Ming
Quoted 1 line · Rakib Mullick

Calling pm-suspend might trigger a recursive lock in it's code path. In function acpi_hw_clear_acpi_status,

As I replied at https://lkml.org/lkml/2011/9/22/6, I still don't think there is a recursive lock.

At first look, it definitely doesn't look like a recursive lock, as Lin said. But, quoting Documentation/lockdep-design.txt:

Quoted 9 lines

"Multi-lock dependency rules:
----------------------------

The same lock-class must not be acquired twice, because this could lead to lock recursion deadlocks."

So, Rakib, do the 2 locks belong to the same lock-class? If yes, then I think that is the reason for the lockdep splat. Could you show the lockdep warning?

Yes, same lock-class. And as per "Multi-lock dependency rules:", it leads to lock recursion deadlocks.
Lockdep warning attached.

Quoted 7 lines

By the way, another way to look at this patch is as an optimization.. i.e., if acpi_gbl_hardware_lock doesn't need to be held to call acpi_ev_walk_gpe_list(), then we can move from the coarse-grained locking to finer-grained locking by releasing it earlier, as you did in your patch. [Note that you will have to update the goto label also, i.e., rename it as 'exit' or something like that]

I can do it, thanks for suggestions. But, what does Lin thinks? Lin are you okay?

Thanks,
Rakib

#5 lore raw
Quoted 35 lines · Rakib Mullick
Quoted 13 lines · Srivatsa S. Bhat

Hi,

Quoted 6 lines · Lin Ming
Quoted 1 line · Rakib Mullick

Calling pm-suspend might trigger a recursive lock in it's code path. In function acpi_hw_clear_acpi_status,

As I replied at https://lkml.org/lkml/2011/9/22/6, I still don't think there is a recursive lock.

At first look, it definitely doesn't look like a recursive lock, as Lin said. But, quoting Documentation/lockdep-design.txt:

Quoted 9 lines

"Multi-lock dependency rules:
----------------------------

The same lock-class must not be acquired twice, because this could lead to lock recursion deadlocks."

So, Rakib, do the 2 locks belong to the same lock-class? If yes, then I think that is the reason for the lockdep splat. Could you show the lockdep warning?

Yes, same lock-class. And as per "Multi-lock dependency rules:", it leads to lock recursion deadlocks.
Lockdep warning attached.

Quoted 7 lines

By the way, another way to look at this patch is as an optimization.. i.e., if acpi_gbl_hardware_lock doesn't need to be held to call acpi_ev_walk_gpe_list(), then we can move from the coarse-grained locking to finer-grained locking by releasing it earlier, as you did in your patch. [Note that you will have to update the goto label also, i.e., rename it as 'exit' or something like that]

Quoted 2 lines

I can do it, thanks for suggestions. But, what does Lin thinks? Lin are you okay?

I'm OK.

We need to figure out why the dead lock happens. Could you also paste the patch which trigger this dead lock?

Thanks,
Lin Ming

Quoted 3 lines

Thanks,
Rakib

#6 lore raw
Quoted 36 lines · Lin Ming
Quoted 35 lines · Rakib Mullick
Quoted 13 lines · Srivatsa S. Bhat

Hi,

Quoted 6 lines · Lin Ming
Quoted 1 line · Rakib Mullick

Calling pm-suspend might trigger a recursive lock in it's code path. In function acpi_hw_clear_acpi_status,

As I replied at https://lkml.org/lkml/2011/9/22/6, I still don't think there is a recursive lock.

At first look, it definitely doesn't look like a recursive lock, as Lin said. But, quoting Documentation/lockdep-design.txt:

Quoted 9 lines

"Multi-lock dependency rules:
----------------------------

The same lock-class must not be acquired twice, because this could lead to lock recursion deadlocks."

So, Rakib, do the 2 locks belong to the same lock-class? If yes, then I think that is the reason for the lockdep splat. Could you show the lockdep warning?

Yes, same lock-class. And as per "Multi-lock dependency rules:", it leads to lock recursion deadlocks.
Lockdep warning attached.

Quoted 7 lines

By the way, another way to look at this patch is as an optimization.. i.e., if acpi_gbl_hardware_lock doesn't need to be held to call acpi_ev_walk_gpe_list(), then we can move from the coarse-grained locking to finer-grained locking by releasing it earlier, as you did in your patch. [Note that you will have to update the goto label also, i.e., rename it as 'exit' or something like that]

Quoted 5 lines
Quoted 2 lines

I can do it, thanks for suggestions. But, what does Lin thinks? Lin are you okay?

I'm OK.

Thanks. Then, I'll come up with a follow up patch includes the suggestion from Srivatsa.

Quoted 1 line

We need to figure out why the dead lock happens.

I think its pretty clear from the lockdep warning, the reason of the possible (since not happened with mainline kernel) dead lock.

Quoted 2 lines

Could you also paste the patch which trigger this dead lock?

It's basically a modification of kernel scheduler, it does load distribution differently. Since it's different approach and needs to introduce properly. I wish I'll show it some day, if I can make some fair improvement. Hope you understand.

Thanks,
Rakib