#define LOCKTYPE_RTMUTEX 0x20
#define LOCKTYPE_LL 0x40
#define LOCKTYPE_SPECIAL 0x80
+#define LOCKTYPE_SRCU 0x100
static struct ww_acquire_ctx t, t2;
static struct ww_mutex o, o2, o3;
#endif
+#ifdef CONFIG_SRCU
+static struct lock_class_key srcu_A_key;
+static struct lock_class_key srcu_B_key;
+static struct srcu_struct srcu_A;
+static struct srcu_struct srcu_B;
+#endif
+
/*
* Locks that we initialize dynamically as well so that
* e.g. X1 and X2 becomes two instances of the same class,
memset(&ww_lockdep.acquire_key, 0, sizeof(ww_lockdep.acquire_key));
memset(&ww_lockdep.mutex_key, 0, sizeof(ww_lockdep.mutex_key));
local_irq_enable();
+
+#ifdef CONFIG_SRCU
+ __init_srcu_struct(&srcu_A, "srcuA", &srcu_A_key);
+ __init_srcu_struct(&srcu_B, "srcuB", &srcu_B_key);
+#endif
+
}
#undef I
pr_cont("\n");
}
+static void srcu_ABBA(void)
+{
+ int ia, ib;
+
+ ia = srcu_read_lock(&srcu_A);
+ synchronize_srcu(&srcu_B);
+ srcu_read_unlock(&srcu_A, ia);
+
+ ib = srcu_read_lock(&srcu_B);
+ synchronize_srcu(&srcu_A);
+ srcu_read_unlock(&srcu_B, ib); // should fail
+}
+
+static void srcu_mutex_ABBA(void)
+{
+ int ia;
+
+ mutex_lock(&mutex_A);
+ synchronize_srcu(&srcu_A);
+ mutex_unlock(&mutex_A);
+
+ ia = srcu_read_lock(&srcu_A);
+ mutex_lock(&mutex_A);
+ mutex_unlock(&mutex_A);
+ srcu_read_unlock(&srcu_A, ia); // should fail
+}
+
+static void srcu_irqsafe(void)
+{
+ int ia;
+
+ HARDIRQ_ENTER();
+ ia = srcu_read_lock(&srcu_A);
+ srcu_read_unlock(&srcu_A, ia);
+ HARDIRQ_EXIT();
+
+ synchronize_srcu(&srcu_A); // should NOT fail
+}
+
+static void srcu_tests(void)
+{
+ printk(" --------------------------------------------------------------------------\n");
+ printk(" | SRCU tests |\n");
+ printk(" ---------------\n");
+ print_testname("ABBA read-sync/read-sync");
+ dotest(srcu_ABBA, FAILURE, LOCKTYPE_SRCU);
+ print_testname("ABBA mutex-sync/read-mutex");
+ dotest(srcu_mutex_ABBA, FAILURE, LOCKTYPE_SRCU);
+ print_testname("Irqsafe synchronize_srcu");
+ dotest(srcu_irqsafe, SUCCESS, LOCKTYPE_SRCU);
+ pr_cont("\n");
+}
/*
* <in hardirq handler>
printk(" --------------------------------------------------------------------------\n");
init_shared_classes();
+#ifdef CONFIG_SRCU
+ __init_srcu_struct(&srcu_A, "srcuA", &srcu_A_key);
+ __init_srcu_struct(&srcu_B, "srcuB", &srcu_B_key);
+#endif
lockdep_set_selftest_task(current);
DO_TESTCASE_6R("A-A deadlock", AA);
DO_TESTCASE_6x2x2RW("irq read-recursion #3", irq_read_recursion3);
ww_tests();
+ srcu_tests();
force_read_lock_recursive = 0;
/*