Skip to contentSkip to conversation

ACPI: fix acpi_power_off lockdep splat

PATCH In review Andrea Righi 5 participants 10 messages Jul 3, 2011 – Jul 13, 2011

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

PATCH v2 1/1 ACPI: fix acpi_power_off lockdep splat

Implement acpi_os_create_lock() as a C-preprocessor macro to suppress lockdep false positive.

When lockdep is enabled the spin_lock_init macro stringifies it's argument and uses that as a name for the lock in the debugging.

By executing spin_lock_init in a macro the key changes from "lock" for all locks to the actual argument of acpi_os_create_lock() ("&acpi_gbl_global_lock_pending_lock", "&acpi_gbl_gpe_lock" or "&acpi_gbl_hardware_lock" for now).

This fixes:
https://bugzilla.kernel.org/show_bug.cgi?id=38152

ChangeLog (v1 -> v2):
- avoid to call spin_lock_init multiple times on the same lock
- rewrite patch description (thanks to Florian for providing a better description of the patch)

---
 drivers/acpi/osl.c      |    3 +--
 include/acpi/acpiosxf.h |   12 +++++++++++-
 2 files changed, 12 insertions(+), 3 deletions(-)
drivers/acpi/osl.c +1 -2
index 52ca964..4c985d3 100644
@@ -1336,14 +1336,13 @@ EXPORT_SYMBOL(acpi_resources_are_enforced);
  * Create and initialize a spinlock.
  */
 acpi_status
-acpi_os_create_lock(acpi_spinlock *out_handle)
+__acpi_os_create_lock(acpi_spinlock *out_handle)
 {
 	spinlock_t *lock;
 
 	lock = ACPI_ALLOCATE(sizeof(spinlock_t));
 	if (!lock)
 		return AE_NO_MEMORY;
-	spin_lock_init(lock);
 	*out_handle = lock;
 
 	return AE_OK;
include/acpi/acpiosxf.h +11 -1
index a756bc8..4a0385d 100644
@@ -99,7 +99,17 @@ acpi_os_table_override(struct acpi_table_header *existing_table,
  * Spinlock primitives
  */
 acpi_status
-acpi_os_create_lock(acpi_spinlock *out_handle);
+__acpi_os_create_lock(acpi_spinlock *out_handle);
+
+#define acpi_os_create_lock(__handle)			\
+({							\
+	acpi_status ret;				\
+							\
+	ret = __acpi_os_create_lock(__handle);		\
+	if (ret == AE_OK)				\
+		spin_lock_init(*(__handle));		\
+	ret;						\
+})
 
 void acpi_os_delete_lock(acpi_spinlock handle);
 
Signature · 1 line
1.7.4.1
#1 lore raw
Quoted 32 lines · Andrea Righi

Implement acpi_os_create_lock() as a C-preprocessor macro to suppress lockdep false positive.

When lockdep is enabled the spin_lock_init macro stringifies it's argument and uses that as a name for the lock in the debugging.

By executing spin_lock_init in a macro the key changes from "lock" for all locks to the actual argument of acpi_os_create_lock() ("&acpi_gbl_global_lock_pending_lock", "&acpi_gbl_gpe_lock" or "&acpi_gbl_hardware_lock" for now).

This fixes:
https://bugzilla.kernel.org/show_bug.cgi?id=38152

ChangeLog (v1 -> v2):
- avoid to call spin_lock_init multiple times on the same lock
- rewrite patch description (thanks to Florian for providing a better description of the patch)

---
 drivers/acpi/osl.c      |    3 +--
 include/acpi/acpiosxf.h |   12 +++++++++++-
 2 files changed, 12 insertions(+), 3 deletions(-)
drivers/acpi/osl.c +0 -0
index 52ca964..4c985d3 100644

drivers/acpi/osl.c EXPORT_SYMBOL(acpi_resources_are_enforced); · line 1340

Quoted 6 lines
drivers/acpi/osl.c +1 -1
@@ -1336,14 +1336,13 @@ EXPORT_SYMBOL(acpi_resources_are_enforced);
  * Create and initialize a spinlock.
  */
 acpi_status
-acpi_os_create_lock(acpi_spinlock *out_handle)
+__acpi_os_create_lock(acpi_spinlock *out_handle)
 {

I would rename this to acpi_os_allocate_lock() or acpi_os_alloc_lock(), so that it doesn't suggest the lock is initialized by this function.

Hmm. There's one more thing we need to take into account here. Namely, include/acpi/acpiosxf.h is used by other OSes, so we shouldn't put Linux-specific stuff into it.

I'm not sure how to work around that at the moment.

Thanks,
Rafael

Quoted 33 lines
drivers/acpi/osl.c +0 -1
 	spinlock_t *lock;
 
 	lock = ACPI_ALLOCATE(sizeof(spinlock_t));
 	if (!lock)
 		return AE_NO_MEMORY;
-	spin_lock_init(lock);
 	*out_handle = lock;
 
 	return AE_OK;
include/acpi/acpiosxf.h +11 -1
index a756bc8..4a0385d 100644
@@ -99,7 +99,17 @@ acpi_os_table_override(struct acpi_table_header *existing_table,
  * Spinlock primitives
  */
 acpi_status
-acpi_os_create_lock(acpi_spinlock *out_handle);
+__acpi_os_create_lock(acpi_spinlock *out_handle);
+
+#define acpi_os_create_lock(__handle)			\
+({							\
+	acpi_status ret;				\
+							\
+	ret = __acpi_os_create_lock(__handle);		\
+	if (ret == AE_OK)				\
+		spin_lock_init(*(__handle));		\
+	ret;						\
+})
 
 void acpi_os_delete_lock(acpi_spinlock handle);
 
#2 lore raw
Quoted 43 lines · Rafael J. Wysocki
Quoted 32 lines · Andrea Righi

Implement acpi_os_create_lock() as a C-preprocessor macro to suppress lockdep false positive.

When lockdep is enabled the spin_lock_init macro stringifies it's argument and uses that as a name for the lock in the debugging.

By executing spin_lock_init in a macro the key changes from "lock" for all locks to the actual argument of acpi_os_create_lock() ("&acpi_gbl_global_lock_pending_lock", "&acpi_gbl_gpe_lock" or "&acpi_gbl_hardware_lock" for now).

This fixes:
https://bugzilla.kernel.org/show_bug.cgi?id=38152

ChangeLog (v1 -> v2):
- avoid to call spin_lock_init multiple times on the same lock
- rewrite patch description (thanks to Florian for providing a better description of the patch)

---
 drivers/acpi/osl.c      |    3 +--
 include/acpi/acpiosxf.h |   12 +++++++++++-
 2 files changed, 12 insertions(+), 3 deletions(-)
drivers/acpi/osl.c +0 -0
index 52ca964..4c985d3 100644

drivers/acpi/osl.c EXPORT_SYMBOL(acpi_resources_are_enforced); · line 1340

Quoted 6 lines
drivers/acpi/osl.c +1 -1
@@ -1336,14 +1336,13 @@ EXPORT_SYMBOL(acpi_resources_are_enforced);
  * Create and initialize a spinlock.
  */
 acpi_status
-acpi_os_create_lock(acpi_spinlock *out_handle)
+__acpi_os_create_lock(acpi_spinlock *out_handle)
 {

I would rename this to acpi_os_allocate_lock() or acpi_os_alloc_lock(), so that it doesn't suggest the lock is initialized by this function.

Quoted 5 lines

Hmm. There's one more thing we need to take into account here. Namely, include/acpi/acpiosxf.h is used by other OSes, so we shouldn't put Linux-specific stuff into it.

I'm not sure how to work around that at the moment.

OK, the patch below builds for me and seems to work even, although I haven't tested it with lockdep on.

Thanks,
Rafael

---
 drivers/acpi/osl.c              |   25 -------------------------
 include/acpi/acpiosxf.h         |    8 --------
 include/acpi/platform/aclinux.h |   20 ++++++++++++++++++++
 3 files changed, 20 insertions(+), 33 deletions(-)
drivers/acpi/osl.c +0 -25
Index: linux-2.6/drivers/acpi/osl.c
===================================================================
@@ -1333,31 +1333,6 @@ int acpi_resources_are_enforced(void)
 EXPORT_SYMBOL(acpi_resources_are_enforced);
 
 /*
- * Create and initialize a spinlock.
- */
-acpi_status
-acpi_os_create_lock(acpi_spinlock *out_handle)
-{
-	spinlock_t *lock;
-
-	lock = ACPI_ALLOCATE(sizeof(spinlock_t));
-	if (!lock)
-		return AE_NO_MEMORY;
-	spin_lock_init(lock);
-	*out_handle = lock;
-
-	return AE_OK;
-}
-
-/*
- * Deallocate the memory for a spinlock.
- */
-void acpi_os_delete_lock(acpi_spinlock handle)
-{
-	ACPI_FREE(handle);
-}
-
-/*
  * Acquire a spinlock.
  *
  * handle is a pointer to the spinlock_t.
include/acpi/acpiosxf.h +0 -8
Index: linux-2.6/include/acpi/acpiosxf.h
===================================================================
@@ -95,14 +95,6 @@ acpi_status
 acpi_os_table_override(struct acpi_table_header *existing_table,
 		       struct acpi_table_header **new_table);
 
-/*
- * Spinlock primitives
- */
-acpi_status
-acpi_os_create_lock(acpi_spinlock *out_handle);
-
-void acpi_os_delete_lock(acpi_spinlock handle);
-
 acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock handle);
 
 void acpi_os_release_lock(acpi_spinlock handle, acpi_cpu_flags flags);
include/acpi/platform/aclinux.h +20 -0
Index: linux-2.6/include/acpi/platform/aclinux.h
===================================================================
@@ -159,6 +159,26 @@ static inline void *acpi_os_acquire_obje
 	} while (0)
 #endif
 
+/*
+ * Spinlock primitives
+ */
+
+#define acpi_os_create_lock(__handle)				\
+({								\
+	spinlock_t *lock = ACPI_ALLOCATE(sizeof(*lock));	\
+								\
+	if (lock) {						\
+		*(__handle) = lock;				\
+		spin_lock_init(*(__handle));			\
+	}							\
+	lock ? AE_OK : AE_NO_MEMORY;				\
+})
+
+#define acpi_os_delete_lock(__handle)	\
+	do {				\
+		ACPI_FREE(__handle);	\
+	} while (0)
+
 #endif /* __KERNEL__ */
 
 #endif /* __ACLINUX_H__ */
#3 lore raw
Quoted 44 lines · Rafael J. Wysocki
Quoted 43 lines · Rafael J. Wysocki
Quoted 32 lines · Andrea Righi

Implement acpi_os_create_lock() as a C-preprocessor macro to suppress lockdep false positive.

When lockdep is enabled the spin_lock_init macro stringifies it's argument and uses that as a name for the lock in the debugging.

By executing spin_lock_init in a macro the key changes from "lock" for all locks to the actual argument of acpi_os_create_lock() ("&acpi_gbl_global_lock_pending_lock", "&acpi_gbl_gpe_lock" or "&acpi_gbl_hardware_lock" for now).

This fixes:
https://bugzilla.kernel.org/show_bug.cgi?id=38152

ChangeLog (v1 -> v2):
- avoid to call spin_lock_init multiple times on the same lock
- rewrite patch description (thanks to Florian for providing a better description of the patch)

---
 drivers/acpi/osl.c      |    3 +--
 include/acpi/acpiosxf.h |   12 +++++++++++-
 2 files changed, 12 insertions(+), 3 deletions(-)
drivers/acpi/osl.c +0 -0
index 52ca964..4c985d3 100644

drivers/acpi/osl.c EXPORT_SYMBOL(acpi_resources_are_enforced); · line 1340

Quoted 6 lines
drivers/acpi/osl.c +1 -1
@@ -1336,14 +1336,13 @@ EXPORT_SYMBOL(acpi_resources_are_enforced);
  * Create and initialize a spinlock.
  */
 acpi_status
-acpi_os_create_lock(acpi_spinlock *out_handle)
+__acpi_os_create_lock(acpi_spinlock *out_handle)
 {

I would rename this to acpi_os_allocate_lock() or acpi_os_alloc_lock(), so that it doesn't suggest the lock is initialized by this function.

Quoted 8 lines
Quoted 5 lines

Hmm. There's one more thing we need to take into account here. Namely, include/acpi/acpiosxf.h is used by other OSes, so we shouldn't put Linux-specific stuff into it.

I'm not sure how to work around that at the moment.

OK, the patch below builds for me and seems to work even, although I haven't tested it with lockdep on.

Below is a cleaned-up version, still untested with lockdep on.

Thanks,
Rafael

---
 drivers/acpi/osl.c              |   17 -----------------
 include/acpi/acpiosxf.h         |    3 +++
 include/acpi/platform/aclinux.h |   18 ++++++++++++++++++
 3 files changed, 21 insertions(+), 17 deletions(-)
drivers/acpi/osl.c +0 -17
Index: linux-2.6/drivers/acpi/osl.c
===================================================================
@@ -1333,23 +1333,6 @@ int acpi_resources_are_enforced(void)
 EXPORT_SYMBOL(acpi_resources_are_enforced);
 
 /*
- * Create and initialize a spinlock.
- */
-acpi_status
-acpi_os_create_lock(acpi_spinlock *out_handle)
-{
-	spinlock_t *lock;
-
-	lock = ACPI_ALLOCATE(sizeof(spinlock_t));
-	if (!lock)
-		return AE_NO_MEMORY;
-	spin_lock_init(lock);
-	*out_handle = lock;
-
-	return AE_OK;
-}
-
-/*
  * Deallocate the memory for a spinlock.
  */
 void acpi_os_delete_lock(acpi_spinlock handle)
include/acpi/acpiosxf.h +3 -0
Index: linux-2.6/include/acpi/acpiosxf.h
===================================================================
@@ -98,8 +98,11 @@ acpi_os_table_override(struct acpi_table
 /*
  * Spinlock primitives
  */
+
+#ifndef acpi_os_create_lock
 acpi_status
 acpi_os_create_lock(acpi_spinlock *out_handle);
+#endif
 
 void acpi_os_delete_lock(acpi_spinlock handle);
 
include/acpi/platform/aclinux.h +18 -0
Index: linux-2.6/include/acpi/platform/aclinux.h
===================================================================
@@ -159,6 +159,24 @@ static inline void *acpi_os_acquire_obje
 	} while (0)
 #endif
 
+/*
+ * When lockdep is enabled, the spin_lock_init() macro stringifies it's
+ * argument and uses that as a name for the lock in debugging.
+ * By executing spin_lock_init() in a macro the key changes from "lock" for
+ * all locks to the name of the argument of acpi_os_create_lock(), which
+ * prevents lockdep from reporting false positives for ACPICA locks.
+ */
+#define acpi_os_create_lock(__handle)				\
+({								\
+	spinlock_t *lock = ACPI_ALLOCATE(sizeof(*lock));	\
+								\
+	if (lock) {						\
+		*(__handle) = lock;				\
+		spin_lock_init(*(__handle));			\
+	}							\
+	lock ? AE_OK : AE_NO_MEMORY;				\
+})
+
 #endif /* __KERNEL__ */
 
 #endif /* __ACLINUX_H__ */
#4 lore raw
Quoted 49 lines · Rafael J. Wysocki
Quoted 48 lines · Rafael J. Wysocki
Quoted 47 lines · Rafael J. Wysocki
Quoted 32 lines · Andrea Righi

Implement acpi_os_create_lock() as a C-preprocessor macro to suppress lockdep false positive.

When lockdep is enabled the spin_lock_init macro stringifies it's argument and uses that as a name for the lock in the debugging.

By executing spin_lock_init in a macro the key changes from "lock" for all locks to the actual argument of acpi_os_create_lock() ("&acpi_gbl_global_lock_pending_lock", "&acpi_gbl_gpe_lock" or "&acpi_gbl_hardware_lock" for now).

This fixes:
https://bugzilla.kernel.org/show_bug.cgi?id=38152

ChangeLog (v1 -> v2):
- avoid to call spin_lock_init multiple times on the same lock
- rewrite patch description (thanks to Florian for providing a better description of the patch)

---
 drivers/acpi/osl.c      |    3 +--
 include/acpi/acpiosxf.h |   12 +++++++++++-
 2 files changed, 12 insertions(+), 3 deletions(-)
drivers/acpi/osl.c +0 -0
index 52ca964..4c985d3 100644

drivers/acpi/osl.c EXPORT_SYMBOL(acpi_resources_are_enforced); · line 1340

Quoted 6 lines
drivers/acpi/osl.c +1 -1
@@ -1336,14 +1336,13 @@ EXPORT_SYMBOL(acpi_resources_are_enforced);
  * Create and initialize a spinlock.
  */
 acpi_status
-acpi_os_create_lock(acpi_spinlock *out_handle)
+__acpi_os_create_lock(acpi_spinlock *out_handle)
 {

I would rename this to acpi_os_allocate_lock() or acpi_os_alloc_lock(), so that it doesn't suggest the lock is initialized by this function.

Hmm. There's one more thing we need to take into account here. Namely, include/acpi/acpiosxf.h is used by other OSes, so we shouldn't put Linux-specific stuff into it.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

I'm not sure how to work around that at the moment.

OK, the patch below builds for me and seems to work even, although I haven't tested it with lockdep on.

Below is a cleaned-up version, still untested with lockdep on.

Tested. Works fine for me.

Thanks!
-Andrea

#5 lore raw

PATCH 1/1 ACPI: Fix lockdep false positives in acpi_power_off()

Quoted 50 lines · Andrea Righi
Quoted 49 lines · Rafael J. Wysocki
Quoted 48 lines · Rafael J. Wysocki
Quoted 47 lines · Rafael J. Wysocki
Quoted 32 lines · Andrea Righi

Implement acpi_os_create_lock() as a C-preprocessor macro to suppress lockdep false positive.

When lockdep is enabled the spin_lock_init macro stringifies it's argument and uses that as a name for the lock in the debugging.

By executing spin_lock_init in a macro the key changes from "lock" for all locks to the actual argument of acpi_os_create_lock() ("&acpi_gbl_global_lock_pending_lock", "&acpi_gbl_gpe_lock" or "&acpi_gbl_hardware_lock" for now).

This fixes:
https://bugzilla.kernel.org/show_bug.cgi?id=38152

ChangeLog (v1 -> v2):
- avoid to call spin_lock_init multiple times on the same lock
- rewrite patch description (thanks to Florian for providing a better description of the patch)

---
 drivers/acpi/osl.c      |    3 +--
 include/acpi/acpiosxf.h |   12 +++++++++++-
 2 files changed, 12 insertions(+), 3 deletions(-)
drivers/acpi/osl.c +0 -0
index 52ca964..4c985d3 100644

drivers/acpi/osl.c EXPORT_SYMBOL(acpi_resources_are_enforced); · line 1340

Quoted 6 lines
drivers/acpi/osl.c +1 -1
@@ -1336,14 +1336,13 @@ EXPORT_SYMBOL(acpi_resources_are_enforced);
  * Create and initialize a spinlock.
  */
 acpi_status
-acpi_os_create_lock(acpi_spinlock *out_handle)
+__acpi_os_create_lock(acpi_spinlock *out_handle)
 {

I would rename this to acpi_os_allocate_lock() or acpi_os_alloc_lock(), so that it doesn't suggest the lock is initialized by this function.

Hmm. There's one more thing we need to take into account here. Namely, include/acpi/acpiosxf.h is used by other OSes, so we shouldn't put Linux-specific stuff into it.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

I'm not sure how to work around that at the moment.

OK, the patch below builds for me and seems to work even, although I haven't tested it with lockdep on.

Below is a cleaned-up version, still untested with lockdep on.

Tested. Works fine for me.

OK, below is an official version.

Thanks,
Rafael

---
From: Rafael J. Wysocki <[email protected]>
Subject: ACPI: Fix lockdep false positives in acpi_power_off()

All ACPICA locks are allocated and initialized by the same function, acpi_os_create_lock(), with the help of a local variable called "lock". Thus, when lockdep is enabled, it uses "lock" as the name of all those locks and regards them as instances of the same lock, which causes it to report possible locking problems with them when there aren't any.

To work around this problem, define acpi_os_create_lock() as a macro and make it pass its argument to spin_lock_init(), so that lockdep uses it as the name of the new lock. Define this macron in a Linux-specific file to minimize the resulting modifications of the OS-independent ACPICA parts.

This change is based on an earlier patch from Andrea Righi and it addresses a regression from 2.6.39 tracked as
https://bugzilla.kernel.org/show_bug.cgi?id=38152

---
 drivers/acpi/osl.c              |   17 -----------------
 include/acpi/acpiosxf.h         |    3 +++
 include/acpi/platform/aclinux.h |   18 ++++++++++++++++++
 3 files changed, 21 insertions(+), 17 deletions(-)
drivers/acpi/osl.c +0 -17
Index: linux-2.6/drivers/acpi/osl.c
===================================================================
@@ -1333,23 +1333,6 @@ int acpi_resources_are_enforced(void)
 EXPORT_SYMBOL(acpi_resources_are_enforced);
 
 /*
- * Create and initialize a spinlock.
- */
-acpi_status
-acpi_os_create_lock(acpi_spinlock *out_handle)
-{
-	spinlock_t *lock;
-
-	lock = ACPI_ALLOCATE(sizeof(spinlock_t));
-	if (!lock)
-		return AE_NO_MEMORY;
-	spin_lock_init(lock);
-	*out_handle = lock;
-
-	return AE_OK;
-}
-
-/*
  * Deallocate the memory for a spinlock.
  */
 void acpi_os_delete_lock(acpi_spinlock handle)
include/acpi/acpiosxf.h +3 -0
Index: linux-2.6/include/acpi/acpiosxf.h
===================================================================
@@ -98,8 +98,11 @@ acpi_os_table_override(struct acpi_table
 /*
  * Spinlock primitives
  */
+
+#ifndef acpi_os_create_lock
 acpi_status
 acpi_os_create_lock(acpi_spinlock *out_handle);
+#endif
 
 void acpi_os_delete_lock(acpi_spinlock handle);
 
include/acpi/platform/aclinux.h +18 -0
Index: linux-2.6/include/acpi/platform/aclinux.h
===================================================================
@@ -159,6 +159,24 @@ static inline void *acpi_os_acquire_obje
 	} while (0)
 #endif
 
+/*
+ * When lockdep is enabled, the spin_lock_init() macro stringifies it's
+ * argument and uses that as a name for the lock in debugging.
+ * By executing spin_lock_init() in a macro the key changes from "lock" for
+ * all locks to the name of the argument of acpi_os_create_lock(), which
+ * prevents lockdep from reporting false positives for ACPICA locks.
+ */
+#define acpi_os_create_lock(__handle)				\
+({								\
+	spinlock_t *lock = ACPI_ALLOCATE(sizeof(*lock));	\
+								\
+	if (lock) {						\
+		*(__handle) = lock;				\
+		spin_lock_init(*(__handle));			\
+	}							\
+	lock ? AE_OK : AE_NO_MEMORY;				\
+})
+
 #endif /* __KERNEL__ */
 
 #endif /* __ACLINUX_H__ */
Tested-by on v1 1/1
#6 lore raw

Re: [PATCH] ACPI: Fix lockdep false positives in acpi_power_off()

Quoted 16 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>
Subject: ACPI: Fix lockdep false positives in acpi_power_off()

All ACPICA locks are allocated and initialized by the same function, acpi_os_create_lock(), with the help of a local variable called "lock". Thus, when lockdep is enabled, it uses "lock" as the name of all those locks and regards them as instances of the same lock, which causes it to report possible locking problems with them when there aren't any.

To work around this problem, define acpi_os_create_lock() as a macro and make it pass its argument to spin_lock_init(), so that lockdep uses it as the name of the new lock. Define this macron in a Linux-specific file to minimize the resulting modifications of the OS-independent ACPICA parts.

Quoted 7 lines

This change is based on an earlier patch from Andrea Righi and it addresses a regression from 2.6.39 tracked as
https://bugzilla.kernel.org/show_bug.cgi?id=38152

Signature · 2 lines
Regards/Gruss,
    Boris.
Reviewed-by on v1 1/1
#7 lore raw

Re: [PATCH] ACPI: Fix lockdep false positives in acpi_power_off()

In reply to Rafael J. Wysocki
Quoted 99 lines · On Tue, 5 Jul 2011 01:32:11 +0200 "Rafael J. Wysocki" <[email protected]> wrote:

OK, below is an official version.

Thanks,
Rafael

---
From: Rafael J. Wysocki <[email protected]>
Subject: ACPI: Fix lockdep false positives in acpi_power_off()

All ACPICA locks are allocated and initialized by the same function, acpi_os_create_lock(), with the help of a local variable called "lock". Thus, when lockdep is enabled, it uses "lock" as the name of all those locks and regards them as instances of the same lock, which causes it to report possible locking problems with them when there aren't any.

To work around this problem, define acpi_os_create_lock() as a macro and make it pass its argument to spin_lock_init(), so that lockdep uses it as the name of the new lock. Define this macron in a Linux-specific file to minimize the resulting modifications of the OS-independent ACPICA parts.

This change is based on an earlier patch from Andrea Righi and it addresses a regression from 2.6.39 tracked as
https://bugzilla.kernel.org/show_bug.cgi?id=38152

---
 drivers/acpi/osl.c              |   17 -----------------
 include/acpi/acpiosxf.h         |    3 +++
 include/acpi/platform/aclinux.h |   18 ++++++++++++++++++
 3 files changed, 21 insertions(+), 17 deletions(-)

Index: linux-2.6/drivers/acpi/osl.c
===================================================================

drivers/acpi/osl.c +0 -17
@@ -1333,23 +1333,6 @@ int acpi_resources_are_enforced(void)
 EXPORT_SYMBOL(acpi_resources_are_enforced);
 
 /*
- * Create and initialize a spinlock.
- */
-acpi_status
-acpi_os_create_lock(acpi_spinlock *out_handle)
-{
-	spinlock_t *lock;
-
-	lock = ACPI_ALLOCATE(sizeof(spinlock_t));
-	if (!lock)
-		return AE_NO_MEMORY;
-	spin_lock_init(lock);
-	*out_handle = lock;
-
-	return AE_OK;
-}
-
-/*
  * Deallocate the memory for a spinlock.
  */
 void acpi_os_delete_lock(acpi_spinlock handle)

Index: linux-2.6/include/acpi/acpiosxf.h
===================================================================

include/acpi/acpiosxf.h +3 -0
@@ -98,8 +98,11 @@ acpi_os_table_override(struct acpi_table
 /*
  * Spinlock primitives
  */
+
+#ifndef acpi_os_create_lock
 acpi_status
 acpi_os_create_lock(acpi_spinlock *out_handle);
+#endif
 
 void acpi_os_delete_lock(acpi_spinlock handle);
 

Index: linux-2.6/include/acpi/platform/aclinux.h
===================================================================

include/acpi/platform/aclinux.h +11 -0
@@ -159,6 +159,24 @@ static inline void *acpi_os_acquire_obje
 	} while (0)
 #endif
 
+/*
+ * When lockdep is enabled, the spin_lock_init() macro stringifies it's
+ * argument and uses that as a name for the lock in debugging.
+ * By executing spin_lock_init() in a macro the key changes from "lock" for
+ * all locks to the name of the argument of acpi_os_create_lock(), which
+ * prevents lockdep from reporting false positives for ACPICA locks.
+ */
+#define acpi_os_create_lock(__handle)				\
+({								\
+	spinlock_t *lock = ACPI_ALLOCATE(sizeof(*lock));	\
+								\

include/acpi/platform/aclinux.h static inline void *acpi_os_acquire_obje · line 182

Quoted 10 lines
include/acpi/platform/aclinux.h +7 -0
+	if (lock) {						\
+		*(__handle) = lock;				\
+		spin_lock_init(*(__handle));			\
+	}							\
+	lock ? AE_OK : AE_NO_MEMORY;				\
+})
+
 #endif /* __KERNEL__ */
 
 #endif /* __ACLINUX_H__ */

Since I made the effort of digging into the lockdep code, you can actually add my

Regards,
Flo

#8 lore raw

PATCH 1/1 ACPI: Fix lockdep false positives in acpi_power_off()

From: Rafael J. Wysocki <[email protected]>
Subject: ACPI: Fix lockdep false positives in acpi_power_off()

All ACPICA locks are allocated by the same function, acpi_os_create_lock(), with the help of a local variable called "lock". Thus, when lockdep is enabled, it uses "lock" as the name of all those locks and regards them as instances of the same lock, which causes it to report possible locking problems with them when there aren't any.

To work around this problem, define acpi_os_create_lock() as a macro and make it pass its argument to spin_lock_init(), so that lockdep uses it as the name of the new lock. Define this macron in a Linux-specific file, to minimize the resulting modifications of the OS-independent ACPICA parts.

This change is based on an earlier patch from Andrea Righi and it addresses a regression from 2.6.39 tracked as
https://bugzilla.kernel.org/show_bug.cgi?id=38152

---
 drivers/acpi/osl.c              |   17 -----------------
 include/acpi/acpiosxf.h         |    3 +++
 include/acpi/platform/aclinux.h |   18 ++++++++++++++++++
 3 files changed, 21 insertions(+), 17 deletions(-)
drivers/acpi/osl.c +0 -17
Index: linux-2.6/drivers/acpi/osl.c
===================================================================
@@ -1333,23 +1333,6 @@ int acpi_resources_are_enforced(void)
 EXPORT_SYMBOL(acpi_resources_are_enforced);
 
 /*
- * Create and initialize a spinlock.
- */
-acpi_status
-acpi_os_create_lock(acpi_spinlock *out_handle)
-{
-	spinlock_t *lock;
-
-	lock = ACPI_ALLOCATE(sizeof(spinlock_t));
-	if (!lock)
-		return AE_NO_MEMORY;
-	spin_lock_init(lock);
-	*out_handle = lock;
-
-	return AE_OK;
-}
-
-/*
  * Deallocate the memory for a spinlock.
  */
 void acpi_os_delete_lock(acpi_spinlock handle)
include/acpi/acpiosxf.h +3 -0
Index: linux-2.6/include/acpi/acpiosxf.h
===================================================================
@@ -98,8 +98,11 @@ acpi_os_table_override(struct acpi_table
 /*
  * Spinlock primitives
  */
+
+#ifndef acpi_os_create_lock
 acpi_status
 acpi_os_create_lock(acpi_spinlock *out_handle);
+#endif
 
 void acpi_os_delete_lock(acpi_spinlock handle);
 
include/acpi/platform/aclinux.h +18 -0
Index: linux-2.6/include/acpi/platform/aclinux.h
===================================================================
@@ -159,6 +159,24 @@ static inline void *acpi_os_acquire_obje
 	} while (0)
 #endif
 
+/*
+ * When lockdep is enabled, the spin_lock_init() macro stringifies it's
+ * argument and uses that as a name for the lock in debugging.
+ * By executing spin_lock_init() in a macro the key changes from "lock" for
+ * all locks to the name of the argument of acpi_os_create_lock(), which
+ * prevents lockdep from reporting false positives for ACPICA locks.
+ */
+#define acpi_os_create_lock(__handle)				\
+({								\
+	spinlock_t *lock = ACPI_ALLOCATE(sizeof(*lock));	\
+								\
+	if (lock) {						\
+		*(__handle) = lock;				\
+		spin_lock_init(*(__handle));			\
+	}							\
+	lock ? AE_OK : AE_NO_MEMORY;				\
+})
+
 #endif /* __KERNEL__ */
 
 #endif /* __ACLINUX_H__ */
reviewer Applied
#9 lore raw

Re: [Resend/Update][PATCH] ACPI: Fix lockdep false positives in acpi_power_off()

applied

thanks,
Len Brown, Intel Open Source Technology Center