[RFC tip/locking/lockdep v5 13/17] lockdep/selftest: Add more recursive read related test cases

2018-02-21 Thread Boqun Feng
Add those four test cases:

1.  X --(NR)--> Y --(NR)--> Z --(NR)--> X is deadlock.

2.  X --(NN)--> Y --(RR)--> Z --(NR)--> X is deadlock.

3.  X --(NN)--> Y --(RR)--> Z --(RN)--> X is not deadlock.

4.  X --(NR)--> Y --(RR)--> Z --(NN)--> X is not deadlock.

Those self testcases are valuable for the development of supporting
recursive read related deadlock detection.

Signed-off-by: Boqun Feng 
---
 lib/locking-selftest.c | 161 +
 1 file changed, 161 insertions(+)

diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c
index c2f06b423da8..6b7a28d84fc4 100644
--- a/lib/locking-selftest.c
+++ b/lib/locking-selftest.c
@@ -1033,6 +1033,133 @@ GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_soft_wlock)
 #undef E2
 #undef E3
 
+/*
+ * write-read / write-read / write-read deadlock even if read is recursive
+ */
+
+#define E1()   \
+   \
+   WL(X1); \
+   RL(Y1); \
+   RU(Y1); \
+   WU(X1);
+
+#define E2()   \
+   \
+   WL(Y1); \
+   RL(Z1); \
+   RU(Z1); \
+   WU(Y1);
+
+#define E3()   \
+   \
+   WL(Z1); \
+   RL(X1); \
+   RU(X1); \
+   WU(Z1);
+
+#include "locking-selftest-rlock.h"
+GENERATE_PERMUTATIONS_3_EVENTS(W1R2_W2R3_W3R1)
+
+#undef E1
+#undef E2
+#undef E3
+
+/*
+ * write-write / read-read / write-read deadlock even if read is recursive
+ */
+
+#define E1()   \
+   \
+   WL(X1); \
+   WL(Y1); \
+   WU(Y1); \
+   WU(X1);
+
+#define E2()   \
+   \
+   RL(Y1); \
+   RL(Z1); \
+   RU(Z1); \
+   RU(Y1);
+
+#define E3()   \
+   \
+   WL(Z1); \
+   RL(X1); \
+   RU(X1); \
+   WU(Z1);
+
+#include "locking-selftest-rlock.h"
+GENERATE_PERMUTATIONS_3_EVENTS(W1W2_R2R3_W3R1)
+
+#undef E1
+#undef E2
+#undef E3
+
+/*
+ * write-write / read-read / read-write is not deadlock when read is recursive
+ */
+
+#define E1()   \
+   \
+   WL(X1); \
+   WL(Y1); \
+   WU(Y1); \
+   WU(X1);
+
+#define E2()   \
+   \
+   RL(Y1); \
+   RL(Z1); \
+   RU(Z1); \
+   RU(Y1);
+
+#define E3()   \
+   \
+   RL(Z1); \
+   WL(X1); \
+   WU(X1); \
+   RU(Z1);
+
+#include "locking-selftest-rlock.h"
+GENERATE_PERMUTATIONS_3_EVENTS(W1R2_R2R3_W3W1)
+
+#undef E1
+#undef E2
+#undef E3
+
+/*
+ * write-read / read-read / write-write is not deadlock when read is recursive
+ */
+
+#define E1()   \
+   \
+   WL(X1); \
+   RL(Y1); \
+   RU(Y1); \
+   WU(X1);
+
+#define E2()   \
+   \
+   RL(Y1); \
+   RL(Z1); \
+   RU(Z1); \
+   RU(Y1);
+
+#define E3()   \
+   \
+   WL(Z1); \
+   WL(X1); \
+   WU(X1); \
+   WU(Z1);
+
+#include "locking-selftest-rlock.h"
+GENERATE_PERMUTATIONS_3_EVENTS(W1W2_R2R3_R3W1)
+
+#undef E1
+#undef E2
+#undef E3
 /*
  * read-lock / write-lock recursion that is actually safe.
  */
@@ -1258,6 +1385,19 @@ static inline void print_testname(const char *testname)
dotest(name##_##nr, FAILURE, LOCKTYPE_RWLOCK);  \
pr_cont("\n");
 
+#define DO_TESTCASE_1RR(desc, name, nr)\
+   print_testname(desc"/"#nr); \
+   pr_cont(" |");  \
+   dotest(name##_##nr, SUCCESS, LOCKTYPE_RWLOCK);  \
+   pr_cont("\n");
+
+#define DO_TESTCASE_1RRB(desc, name, nr)   

[RFC tip/locking/lockdep v5 13/17] lockdep/selftest: Add more recursive read related test cases

2018-02-21 Thread Boqun Feng
Add those four test cases:

1.  X --(NR)--> Y --(NR)--> Z --(NR)--> X is deadlock.

2.  X --(NN)--> Y --(RR)--> Z --(NR)--> X is deadlock.

3.  X --(NN)--> Y --(RR)--> Z --(RN)--> X is not deadlock.

4.  X --(NR)--> Y --(RR)--> Z --(NN)--> X is not deadlock.

Those self testcases are valuable for the development of supporting
recursive read related deadlock detection.

Signed-off-by: Boqun Feng 
---
 lib/locking-selftest.c | 161 +
 1 file changed, 161 insertions(+)

diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c
index c2f06b423da8..6b7a28d84fc4 100644
--- a/lib/locking-selftest.c
+++ b/lib/locking-selftest.c
@@ -1033,6 +1033,133 @@ GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_soft_wlock)
 #undef E2
 #undef E3
 
+/*
+ * write-read / write-read / write-read deadlock even if read is recursive
+ */
+
+#define E1()   \
+   \
+   WL(X1); \
+   RL(Y1); \
+   RU(Y1); \
+   WU(X1);
+
+#define E2()   \
+   \
+   WL(Y1); \
+   RL(Z1); \
+   RU(Z1); \
+   WU(Y1);
+
+#define E3()   \
+   \
+   WL(Z1); \
+   RL(X1); \
+   RU(X1); \
+   WU(Z1);
+
+#include "locking-selftest-rlock.h"
+GENERATE_PERMUTATIONS_3_EVENTS(W1R2_W2R3_W3R1)
+
+#undef E1
+#undef E2
+#undef E3
+
+/*
+ * write-write / read-read / write-read deadlock even if read is recursive
+ */
+
+#define E1()   \
+   \
+   WL(X1); \
+   WL(Y1); \
+   WU(Y1); \
+   WU(X1);
+
+#define E2()   \
+   \
+   RL(Y1); \
+   RL(Z1); \
+   RU(Z1); \
+   RU(Y1);
+
+#define E3()   \
+   \
+   WL(Z1); \
+   RL(X1); \
+   RU(X1); \
+   WU(Z1);
+
+#include "locking-selftest-rlock.h"
+GENERATE_PERMUTATIONS_3_EVENTS(W1W2_R2R3_W3R1)
+
+#undef E1
+#undef E2
+#undef E3
+
+/*
+ * write-write / read-read / read-write is not deadlock when read is recursive
+ */
+
+#define E1()   \
+   \
+   WL(X1); \
+   WL(Y1); \
+   WU(Y1); \
+   WU(X1);
+
+#define E2()   \
+   \
+   RL(Y1); \
+   RL(Z1); \
+   RU(Z1); \
+   RU(Y1);
+
+#define E3()   \
+   \
+   RL(Z1); \
+   WL(X1); \
+   WU(X1); \
+   RU(Z1);
+
+#include "locking-selftest-rlock.h"
+GENERATE_PERMUTATIONS_3_EVENTS(W1R2_R2R3_W3W1)
+
+#undef E1
+#undef E2
+#undef E3
+
+/*
+ * write-read / read-read / write-write is not deadlock when read is recursive
+ */
+
+#define E1()   \
+   \
+   WL(X1); \
+   RL(Y1); \
+   RU(Y1); \
+   WU(X1);
+
+#define E2()   \
+   \
+   RL(Y1); \
+   RL(Z1); \
+   RU(Z1); \
+   RU(Y1);
+
+#define E3()   \
+   \
+   WL(Z1); \
+   WL(X1); \
+   WU(X1); \
+   WU(Z1);
+
+#include "locking-selftest-rlock.h"
+GENERATE_PERMUTATIONS_3_EVENTS(W1W2_R2R3_R3W1)
+
+#undef E1
+#undef E2
+#undef E3
 /*
  * read-lock / write-lock recursion that is actually safe.
  */
@@ -1258,6 +1385,19 @@ static inline void print_testname(const char *testname)
dotest(name##_##nr, FAILURE, LOCKTYPE_RWLOCK);  \
pr_cont("\n");
 
+#define DO_TESTCASE_1RR(desc, name, nr)\
+   print_testname(desc"/"#nr); \
+   pr_cont(" |");  \
+   dotest(name##_##nr, SUCCESS, LOCKTYPE_RWLOCK);  \
+   pr_cont("\n");
+
+#define DO_TESTCASE_1RRB(desc, name, nr)   \
+