[PATCH 02/17] locking: Add split_lock

From: Matthew Wilcox (Oracle)
Date: Thu Apr 08 2021 - 22:54:17 EST


Bitlocks do not currently participate in lockdep. Conceptually, a
bit_spinlock is a split lock, eg across each bucket in a hash table.
The struct split_lock gives us somewhere to record the lockdep_map.

Signed-off-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx>
---
include/linux/split_lock.h | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
create mode 100644 include/linux/split_lock.h

diff --git a/include/linux/split_lock.h b/include/linux/split_lock.h
new file mode 100644
index 000000000000..8d64cfa0bbad
--- /dev/null
+++ b/include/linux/split_lock.h
@@ -0,0 +1,37 @@
+#ifndef _LINUX_SPLIT_LOCK_H
+#define _LINUX_SPLIT_LOCK_H
+
+#include <linux/lockdep_types.h>
+
+struct split_lock {
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+ struct lockdep_map dep_map;
+#endif
+};
+
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+#define SPLIT_DEP_MAP_INIT(lockname) \
+ .dep_map = { \
+ .name = #lockname, \
+ .wait_type_inner = LD_WAIT_SPIN, \
+ }
+#else
+#define SPLIT_DEP_MAP_INIT(lockname)
+#endif
+
+#define DEFINE_SPLIT_LOCK(name) \
+struct split_lock name = { \
+ SPLIT_DEP_MAP_INIT(name) \
+};
+
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+#define split_lock_init(_lock) do { \
+ static struct lock_class_key __key; \
+ lockdep_init_map_wait(&(_lock)->dep_map, #_lock, &__key, 0, \
+ LD_WAIT_SPIN); \
+} while (0)
+#else
+static inline void split_lock_init(struct split_lock *sl) { }
+#endif
+
+#endif /* _LINUX_SPLIT_LOCK_H */
--
2.30.2