Skip to content

Commit

Permalink
Revert "ACPICA: fix AML mutex re-entrancy"
Browse files Browse the repository at this point in the history
This reverts commit c0d127b.

These changes to AML locking were made to allow
Notify handlers to be called on the stack
and not deadlock.  However, that scheme turns
out to be flawed and was reverted by the previous commit,
so this commit restores the locking to it previous design.

Signed-off-by: Len Brown <len.brown@intel.com>
  • Loading branch information
Len Brown committed May 10, 2007
1 parent 40d0708 commit 262a7a2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
12 changes: 7 additions & 5 deletions drivers/acpi/dispatcher/dsmethod.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,10 @@ acpi_ds_begin_method_execution(struct acpi_namespace_node *method_node,
* Obtain the method mutex if necessary. Do not acquire mutex for a
* recursive call.
*/
if (acpi_os_get_thread_id() !=
obj_desc->method.mutex->mutex.owner_thread_id) {
if (!walk_state ||
!obj_desc->method.mutex->mutex.owner_thread ||
(walk_state->thread !=
obj_desc->method.mutex->mutex.owner_thread)) {
/*
* Acquire the method mutex. This releases the interpreter if we
* block (and reacquires it before it returns)
Expand All @@ -246,14 +248,14 @@ acpi_ds_begin_method_execution(struct acpi_namespace_node *method_node,
}

/* Update the mutex and walk info and save the original sync_level */
obj_desc->method.mutex->mutex.owner_thread_id =
acpi_os_get_thread_id();

if (walk_state) {
obj_desc->method.mutex->mutex.
original_sync_level =
walk_state->thread->current_sync_level;

obj_desc->method.mutex->mutex.owner_thread =
walk_state->thread;
walk_state->thread->current_sync_level =
obj_desc->method.sync_level;
} else {
Expand Down Expand Up @@ -567,7 +569,7 @@ acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,

acpi_os_release_mutex(method_desc->method.mutex->mutex.
os_mutex);
method_desc->method.mutex->mutex.owner_thread_id = ACPI_MUTEX_NOT_ACQUIRED;
method_desc->method.mutex->mutex.owner_thread = NULL;
}
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/acpi/executer/exdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static struct acpi_exdump_info acpi_ex_dump_method[8] = {
static struct acpi_exdump_info acpi_ex_dump_mutex[5] = {
{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_mutex), NULL},
{ACPI_EXD_UINT8, ACPI_EXD_OFFSET(mutex.sync_level), "Sync Level"},
{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.owner_thread_id), "Owner Thread"},
{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.owner_thread), "Owner Thread"},
{ACPI_EXD_UINT16, ACPI_EXD_OFFSET(mutex.acquisition_depth),
"Acquire Depth"},
{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.os_mutex), "OsMutex"}
Expand Down
36 changes: 20 additions & 16 deletions drivers/acpi/executer/exmutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ acpi_ex_link_mutex(union acpi_operand_object *obj_desc,
*
******************************************************************************/

void acpi_ex_unlink_mutex(union acpi_operand_object *obj_desc,
struct acpi_thread_state *thread)
void acpi_ex_unlink_mutex(union acpi_operand_object *obj_desc)
{
struct acpi_thread_state *thread = obj_desc->mutex.owner_thread;

if (!thread) {
return;
}
Expand Down Expand Up @@ -173,13 +174,16 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,

/* Support for multiple acquires by the owning thread */

if (obj_desc->mutex.owner_thread_id == acpi_os_get_thread_id()) {
/*
* The mutex is already owned by this thread, just increment the
* acquisition depth
*/
obj_desc->mutex.acquisition_depth++;
return_ACPI_STATUS(AE_OK);
if (obj_desc->mutex.owner_thread) {
if (obj_desc->mutex.owner_thread->thread_id ==
walk_state->thread->thread_id) {
/*
* The mutex is already owned by this thread, just increment the
* acquisition depth
*/
obj_desc->mutex.acquisition_depth++;
return_ACPI_STATUS(AE_OK);
}
}

/* Acquire the mutex, wait if necessary. Special case for Global Lock */
Expand All @@ -202,7 +206,7 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,

/* Have the mutex: update mutex and walk info and save the sync_level */

obj_desc->mutex.owner_thread_id = acpi_os_get_thread_id();
obj_desc->mutex.owner_thread = walk_state->thread;
obj_desc->mutex.acquisition_depth = 1;
obj_desc->mutex.original_sync_level =
walk_state->thread->current_sync_level;
Expand Down Expand Up @@ -242,7 +246,7 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,

/* The mutex must have been previously acquired in order to release it */

if (!obj_desc->mutex.owner_thread_id) {
if (!obj_desc->mutex.owner_thread) {
ACPI_ERROR((AE_INFO,
"Cannot release Mutex [%4.4s], not acquired",
acpi_ut_get_node_name(obj_desc->mutex.node)));
Expand All @@ -262,14 +266,14 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
* The Mutex is owned, but this thread must be the owner.
* Special case for Global Lock, any thread can release
*/
if ((obj_desc->mutex.owner_thread_id !=
if ((obj_desc->mutex.owner_thread->thread_id !=
walk_state->thread->thread_id)
&& (obj_desc->mutex.os_mutex != acpi_gbl_global_lock_mutex)) {
ACPI_ERROR((AE_INFO,
"Thread %lX cannot release Mutex [%4.4s] acquired by thread %lX",
(unsigned long)walk_state->thread->thread_id,
acpi_ut_get_node_name(obj_desc->mutex.node),
(unsigned long)obj_desc->mutex.owner_thread_id));
(unsigned long)obj_desc->mutex.owner_thread->thread_id));
return_ACPI_STATUS(AE_AML_NOT_OWNER);
}

Expand All @@ -296,7 +300,7 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,

/* Unlink the mutex from the owner's list */

acpi_ex_unlink_mutex(obj_desc, walk_state->thread);
acpi_ex_unlink_mutex(obj_desc);

/* Release the mutex, special case for Global Lock */

Expand All @@ -308,7 +312,7 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,

/* Update the mutex and restore sync_level */

obj_desc->mutex.owner_thread_id = ACPI_MUTEX_NOT_ACQUIRED;
obj_desc->mutex.owner_thread = NULL;
walk_state->thread->current_sync_level =
obj_desc->mutex.original_sync_level;

Expand Down Expand Up @@ -363,7 +367,7 @@ void acpi_ex_release_all_mutexes(struct acpi_thread_state *thread)

/* Mark mutex unowned */

obj_desc->mutex.owner_thread_id = ACPI_MUTEX_NOT_ACQUIRED;
obj_desc->mutex.owner_thread = NULL;

/* Update Thread sync_level (Last mutex is the important one) */

Expand Down
1 change: 1 addition & 0 deletions drivers/acpi/utilities/utdelete.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ static void acpi_ut_delete_internal_obj(union acpi_operand_object *object)
acpi_os_delete_mutex(object->mutex.os_mutex);
acpi_gbl_global_lock_mutex = NULL;
} else {
acpi_ex_unlink_mutex(object);
acpi_os_delete_mutex(object->mutex.os_mutex);
}
break;
Expand Down
3 changes: 1 addition & 2 deletions include/acpi/acinterp.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,

void acpi_ex_release_all_mutexes(struct acpi_thread_state *thread);

void acpi_ex_unlink_mutex(union acpi_operand_object *obj_desc,
struct acpi_thread_state *thread);
void acpi_ex_unlink_mutex(union acpi_operand_object *obj_desc);

/*
* exprep - ACPI AML execution - prep utilities
Expand Down
2 changes: 1 addition & 1 deletion include/acpi/acobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ struct acpi_object_event {
struct acpi_object_mutex {
ACPI_OBJECT_COMMON_HEADER u8 sync_level; /* 0-15, specified in Mutex() call */
u16 acquisition_depth; /* Allow multiple Acquires, same thread */
acpi_thread_id owner_thread_id; /* Current owner of the mutex */
struct acpi_thread_state *owner_thread; /* Current owner of the mutex */
acpi_mutex os_mutex; /* Actual OS synchronization object */
union acpi_operand_object *prev; /* Link for list of acquired mutexes */
union acpi_operand_object *next; /* Link for list of acquired mutexes */
Expand Down

0 comments on commit 262a7a2

Please sign in to comment.