lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1268182859.2615.8.camel@mj>
Date:	Tue, 09 Mar 2010 20:00:59 -0500
From:	Pavel Roskin <proski@....org>
To:	linux-kernel@...r.kernel.org
Subject: [PATCH] locking: annotate inline spinlocks and rwlocks on SMP

When spinlock or rwlock functions are inlined on SMP, their definitions
are not annotated for sparse.

In particular, SMP kernels without CONFIG_PREEMPT and lock debugging
would inline spin_unlock(), but not spin_lock(), resulting in bogus
sparse warnings about locking.

Use __acquire() and __release() to annotate inline spinlocks in the same
way as their non-inline implementations are annotated.

Signed-off-by: Pavel Roskin <proski@....org>
---

The new code has been tested by forcing all spinlocks and rwlocks to be
inlined.  The _raw_*_irqsave() functions return long (the flags) on SMP,
so compound statements are used for them.  I ran sparse on the whole
kernel, and whenever sparse complains about locking, the code is
non-trivial.  I'm running the patched kernel now.

 include/linux/rwlock_api_smp.h   |   98 +++++++++++++++++++++++++++++++-------
 include/linux/spinlock_api_smp.h |   48 ++++++++++++++++---
 2 files changed, 120 insertions(+), 26 deletions(-)

diff --git a/include/linux/rwlock_api_smp.h b/include/linux/rwlock_api_smp.h
index 9c9f049..c16c3ee 100644
--- a/include/linux/rwlock_api_smp.h
+++ b/include/linux/rwlock_api_smp.h
@@ -41,35 +41,67 @@ _raw_write_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
 							__releases(lock);
 
 #ifdef CONFIG_INLINE_READ_LOCK
-#define _raw_read_lock(lock) __raw_read_lock(lock)
+#define _raw_read_lock(lock)			\
+	do {					\
+		__acquire(lock);		\
+		__raw_read_lock(lock);		\
+	} while (0)
 #endif
 
 #ifdef CONFIG_INLINE_WRITE_LOCK
-#define _raw_write_lock(lock) __raw_write_lock(lock)
+#define _raw_write_lock(lock)			\
+	do {					\
+		__acquire(lock);		\
+		__raw_write_lock(lock);		\
+	} while (0)
 #endif
 
 #ifdef CONFIG_INLINE_READ_LOCK_BH
-#define _raw_read_lock_bh(lock) __raw_read_lock_bh(lock)
+#define _raw_read_lock_bh(lock)			\
+	do {					\
+		__acquire(lock);		\
+		__raw_read_lock_bh(lock);	\
+	} while (0)
 #endif
 
 #ifdef CONFIG_INLINE_WRITE_LOCK_BH
-#define _raw_write_lock_bh(lock) __raw_write_lock_bh(lock)
+#define _raw_write_lock_bh(lock)		\
+	do {					\
+		__acquire(lock);		\
+		__raw_write_lock_bh(lock);	\
+	} while (0)
 #endif
 
 #ifdef CONFIG_INLINE_READ_LOCK_IRQ
-#define _raw_read_lock_irq(lock) __raw_read_lock_irq(lock)
+#define _raw_read_lock_irq(lock)		\
+	do {					\
+		__acquire(lock);		\
+		__raw_read_lock_irq(lock);	\
+	} while (0)
 #endif
 
 #ifdef CONFIG_INLINE_WRITE_LOCK_IRQ
-#define _raw_write_lock_irq(lock) __raw_write_lock_irq(lock)
+#define _raw_write_lock_irq(lock)		\
+	do {					\
+		__acquire(lock);		\
+		__raw_write_lock_irq(lock);	\
+	} while (0)
 #endif
 
 #ifdef CONFIG_INLINE_READ_LOCK_IRQSAVE
-#define _raw_read_lock_irqsave(lock) __raw_read_lock_irqsave(lock)
+#define _raw_read_lock_irqsave(lock)		\
+	({					\
+		__acquire(lock);		\
+		__raw_read_lock_irqsave(lock);	\
+	})
 #endif
 
 #ifdef CONFIG_INLINE_WRITE_LOCK_IRQSAVE
-#define _raw_write_lock_irqsave(lock) __raw_write_lock_irqsave(lock)
+#define _raw_write_lock_irqsave(lock)		\
+	({					\
+		__acquire(lock);		\
+		__raw_write_lock_irqsave(lock);	\
+	})
 #endif
 
 #ifdef CONFIG_INLINE_READ_TRYLOCK
@@ -81,37 +113,67 @@ _raw_write_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
 #endif
 
 #ifdef CONFIG_INLINE_READ_UNLOCK
-#define _raw_read_unlock(lock) __raw_read_unlock(lock)
+#define _raw_read_unlock(lock)			\
+	do {					\
+		__raw_read_unlock(lock);	\
+		__release(lock);		\
+	} while (0)
 #endif
 
 #ifdef CONFIG_INLINE_WRITE_UNLOCK
-#define _raw_write_unlock(lock) __raw_write_unlock(lock)
+#define _raw_write_unlock(lock)			\
+	do {					\
+		__raw_write_unlock(lock);	\
+		__release(lock);		\
+	} while (0)
 #endif
 
 #ifdef CONFIG_INLINE_READ_UNLOCK_BH
-#define _raw_read_unlock_bh(lock) __raw_read_unlock_bh(lock)
+#define _raw_read_unlock_bh(lock)		\
+	do {					\
+		__raw_read_unlock_bh(lock);	\
+		__release(lock);		\
+	} while (0)
 #endif
 
 #ifdef CONFIG_INLINE_WRITE_UNLOCK_BH
-#define _raw_write_unlock_bh(lock) __raw_write_unlock_bh(lock)
+#define _raw_write_unlock_bh(lock)		\
+	do {					\
+		__raw_write_unlock_bh(lock);	\
+		__release(lock);		\
+	} while (0)
 #endif
 
 #ifdef CONFIG_INLINE_READ_UNLOCK_IRQ
-#define _raw_read_unlock_irq(lock) __raw_read_unlock_irq(lock)
+#define _raw_read_unlock_irq(lock)		\
+	do {					\
+		__raw_read_unlock_irq(lock);	\
+		__release(lock);		\
+	} while (0)
 #endif
 
 #ifdef CONFIG_INLINE_WRITE_UNLOCK_IRQ
-#define _raw_write_unlock_irq(lock) __raw_write_unlock_irq(lock)
+#define _raw_write_unlock_irq(lock)		\
+	do {					\
+		__raw_write_unlock_irq(lock);	\
+		__release(lock);		\
+	} while (0)
 #endif
 
 #ifdef CONFIG_INLINE_READ_UNLOCK_IRQRESTORE
-#define _raw_read_unlock_irqrestore(lock, flags) \
-	__raw_read_unlock_irqrestore(lock, flags)
+#define _raw_read_unlock_irqrestore(lock, flags)		\
+	do {							\
+		__raw_read_unlock_irqrestore(lock, flags);	\
+		__release(lock);				\
+	} while (0)
 #endif
 
 #ifdef CONFIG_INLINE_WRITE_UNLOCK_IRQRESTORE
-#define _raw_write_unlock_irqrestore(lock, flags) \
-	__raw_write_unlock_irqrestore(lock, flags)
+#define _raw_write_unlock_irqrestore(lock, flags)		\
+	do {							\
+		__raw_write_unlock_irqrestore(lock, flags);	\
+		__release(lock);				\
+	} while (0)
 #endif
 
 static inline int __raw_read_trylock(rwlock_t *lock)
diff --git a/include/linux/spinlock_api_smp.h b/include/linux/spinlock_api_smp.h
index e253ccd..6fb9ecb 100644
--- a/include/linux/spinlock_api_smp.h
+++ b/include/linux/spinlock_api_smp.h
@@ -44,19 +44,35 @@ _raw_spin_unlock_irqrestore(raw_spinlock_t *lock, unsigned long flags)
 								__releases(lock);
 
 #ifdef CONFIG_INLINE_SPIN_LOCK
-#define _raw_spin_lock(lock) __raw_spin_lock(lock)
+#define _raw_spin_lock(lock)			\
+	do {					\
+		__acquire(lock);		\
+		__raw_spin_lock(lock);		\
+	} while (0)
 #endif
 
 #ifdef CONFIG_INLINE_SPIN_LOCK_BH
-#define _raw_spin_lock_bh(lock) __raw_spin_lock_bh(lock)
+#define _raw_spin_lock_bh(lock)			\
+	do {					\
+		__acquire(lock);		\
+		__raw_spin_lock_bh(lock);	\
+	} while (0)
 #endif
 
 #ifdef CONFIG_INLINE_SPIN_LOCK_IRQ
-#define _raw_spin_lock_irq(lock) __raw_spin_lock_irq(lock)
+#define _raw_spin_lock_irq(lock)		\
+	do {					\
+		__acquire(lock);		\
+		__raw_spin_lock_irq(lock);	\
+	} while (0)
 #endif
 
 #ifdef CONFIG_INLINE_SPIN_LOCK_IRQSAVE
-#define _raw_spin_lock_irqsave(lock) __raw_spin_lock_irqsave(lock)
+#define _raw_spin_lock_irqsave(lock)		\
+	({					\
+		__acquire(lock);		\
+		__raw_spin_lock_irqsave(lock);	\
+	})
 #endif
 
 #ifdef CONFIG_INLINE_SPIN_TRYLOCK
@@ -68,19 +84,35 @@ _raw_spin_unlock_irqrestore(raw_spinlock_t *lock, unsigned long flags)
 #endif
 
 #ifdef CONFIG_INLINE_SPIN_UNLOCK
-#define _raw_spin_unlock(lock) __raw_spin_unlock(lock)
+#define _raw_spin_unlock(lock)			\
+	do {					\
+		__raw_spin_unlock(lock);	\
+		__release(lock);		\
+	} while (0)
 #endif
 
 #ifdef CONFIG_INLINE_SPIN_UNLOCK_BH
-#define _raw_spin_unlock_bh(lock) __raw_spin_unlock_bh(lock)
+#define _raw_spin_unlock_bh(lock)		\
+	do {					\
+		__raw_spin_unlock_bh(lock);	\
+		__release(lock);		\
+	} while (0)
 #endif
 
 #ifdef CONFIG_INLINE_SPIN_UNLOCK_IRQ
-#define _raw_spin_unlock_irq(lock) __raw_spin_unlock_irq(lock)
+#define _raw_spin_unlock_irq(lock)		\
+	do {					\
+		__raw_spin_unlock_irq(lock);	\
+		__release(lock);		\
+	} while (0)
 #endif
 
 #ifdef CONFIG_INLINE_SPIN_UNLOCK_IRQRESTORE
-#define _raw_spin_unlock_irqrestore(lock, flags) __raw_spin_unlock_irqrestore(lock, flags)
+#define _raw_spin_unlock_irqrestore(lock, flags)		\
+	do {							\
+		__raw_spin_unlock_irqrestore(lock, flags);	\
+		__release(lock);				\
+	} while (0)
 #endif
 
 static inline int __raw_spin_trylock(raw_spinlock_t *lock)

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ