[PATCH v3 26/30] locking/lockdep: Add lock exclusiveness table

From: Yuyang Du
Date: Fri Jun 28 2019 - 05:17:42 EST


Lock exclusiveness table gathers the information about whether two lock
acquisitions for the same lock instance can be granted concurrently.

Signed-off-by: Yuyang Du <duyuyang@xxxxxxxxx>
---
kernel/locking/lockdep.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index cb3a1d3..e11ffab 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -894,6 +894,36 @@ static bool class_lock_list_valid(struct lock_class *c, int forward)
#ifdef CONFIG_PROVE_LOCKING
static u16 chain_hlocks[MAX_LOCKDEP_CHAIN_HLOCKS];
static u16 chain_hlocks_type[MAX_LOCKDEP_CHAIN_HLOCKS];
+
+/*
+ * Lock exclusiveness table.
+ *
+ * With lock X.A and X.B (X.A is on top and X.B is on bottom):
+ *
+ * T1 TB T1 TB
+ * -- -- -- --
+ *
+ * X.A or X.A
+ * X.B X.B
+ *
+ * in the table Yes means the two locks are exclusive and No otherwise.
+ *
+ * +---------------------+------------+-----------+---------------------+
+ * | X.A vs. X.B | Write lock | Read lock | Recursive-read lock |
+ * +---------------------+------------+-----------+---------------------+
+ * | Write lock | Yes | Yes | Yes |
+ * +---------------------+------------+-----------+---------------------+
+ * | Read lock | Yes | Yes | No |
+ * +---------------------+------------+-----------+---------------------+
+ * | Recursive-read lock | Yes | Yes | No |
+ * +---------------------+------------+-----------+---------------------+
+ *
+ */
+static int lock_excl_table[3][3] = {
+ {1, 1, 1}, /* Write lock vs. X.B */
+ {1, 1, 0}, /* Read lock vs. X.B */
+ {1, 1, 0}, /* Recursive-read lock vs. X.B */
+};
#endif

static bool check_lock_chain_key(struct lock_chain *chain)
--
1.8.3.1