locking-selftest.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902
  1. /*
  2. * lib/locking-selftest.c
  3. *
  4. * Testsuite for various locking APIs: spinlocks, rwlocks,
  5. * mutexes and rw-semaphores.
  6. *
  7. * It is checking both false positives and false negatives.
  8. *
  9. * Started by Ingo Molnar:
  10. *
  11. * Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
  12. */
  13. #include <linux/rwsem.h>
  14. #include <linux/mutex.h>
  15. #include <linux/ww_mutex.h>
  16. #include <linux/sched.h>
  17. #include <linux/delay.h>
  18. #include <linux/lockdep.h>
  19. #include <linux/spinlock.h>
  20. #include <linux/kallsyms.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/debug_locks.h>
  23. #include <linux/irqflags.h>
  24. /*
  25. * Change this to 1 if you want to see the failure printouts:
  26. */
  27. static unsigned int debug_locks_verbose;
  28. static DEFINE_WW_CLASS(ww_lockdep);
  29. static int __init setup_debug_locks_verbose(char *str)
  30. {
  31. get_option(&str, &debug_locks_verbose);
  32. return 1;
  33. }
  34. __setup("debug_locks_verbose=", setup_debug_locks_verbose);
  35. #define FAILURE 0
  36. #define SUCCESS 1
  37. #define LOCKTYPE_SPIN 0x1
  38. #define LOCKTYPE_RWLOCK 0x2
  39. #define LOCKTYPE_MUTEX 0x4
  40. #define LOCKTYPE_RWSEM 0x8
  41. #define LOCKTYPE_WW 0x10
  42. static struct ww_acquire_ctx t, t2;
  43. static struct ww_mutex o, o2, o3;
  44. /*
  45. * Normal standalone locks, for the circular and irq-context
  46. * dependency tests:
  47. */
  48. static DEFINE_RAW_SPINLOCK(lock_A);
  49. static DEFINE_RAW_SPINLOCK(lock_B);
  50. static DEFINE_RAW_SPINLOCK(lock_C);
  51. static DEFINE_RAW_SPINLOCK(lock_D);
  52. static DEFINE_RWLOCK(rwlock_A);
  53. static DEFINE_RWLOCK(rwlock_B);
  54. static DEFINE_RWLOCK(rwlock_C);
  55. static DEFINE_RWLOCK(rwlock_D);
  56. static DEFINE_MUTEX(mutex_A);
  57. static DEFINE_MUTEX(mutex_B);
  58. static DEFINE_MUTEX(mutex_C);
  59. static DEFINE_MUTEX(mutex_D);
  60. static DECLARE_RWSEM(rwsem_A);
  61. static DECLARE_RWSEM(rwsem_B);
  62. static DECLARE_RWSEM(rwsem_C);
  63. static DECLARE_RWSEM(rwsem_D);
  64. /*
  65. * Locks that we initialize dynamically as well so that
  66. * e.g. X1 and X2 becomes two instances of the same class,
  67. * but X* and Y* are different classes. We do this so that
  68. * we do not trigger a real lockup:
  69. */
  70. static DEFINE_RAW_SPINLOCK(lock_X1);
  71. static DEFINE_RAW_SPINLOCK(lock_X2);
  72. static DEFINE_RAW_SPINLOCK(lock_Y1);
  73. static DEFINE_RAW_SPINLOCK(lock_Y2);
  74. static DEFINE_RAW_SPINLOCK(lock_Z1);
  75. static DEFINE_RAW_SPINLOCK(lock_Z2);
  76. static DEFINE_RWLOCK(rwlock_X1);
  77. static DEFINE_RWLOCK(rwlock_X2);
  78. static DEFINE_RWLOCK(rwlock_Y1);
  79. static DEFINE_RWLOCK(rwlock_Y2);
  80. static DEFINE_RWLOCK(rwlock_Z1);
  81. static DEFINE_RWLOCK(rwlock_Z2);
  82. static DEFINE_MUTEX(mutex_X1);
  83. static DEFINE_MUTEX(mutex_X2);
  84. static DEFINE_MUTEX(mutex_Y1);
  85. static DEFINE_MUTEX(mutex_Y2);
  86. static DEFINE_MUTEX(mutex_Z1);
  87. static DEFINE_MUTEX(mutex_Z2);
  88. static DECLARE_RWSEM(rwsem_X1);
  89. static DECLARE_RWSEM(rwsem_X2);
  90. static DECLARE_RWSEM(rwsem_Y1);
  91. static DECLARE_RWSEM(rwsem_Y2);
  92. static DECLARE_RWSEM(rwsem_Z1);
  93. static DECLARE_RWSEM(rwsem_Z2);
  94. /*
  95. * non-inlined runtime initializers, to let separate locks share
  96. * the same lock-class:
  97. */
  98. #define INIT_CLASS_FUNC(class) \
  99. static noinline void \
  100. init_class_##class(raw_spinlock_t *lock, rwlock_t *rwlock, \
  101. struct mutex *mutex, struct rw_semaphore *rwsem)\
  102. { \
  103. raw_spin_lock_init(lock); \
  104. rwlock_init(rwlock); \
  105. mutex_init(mutex); \
  106. init_rwsem(rwsem); \
  107. }
  108. INIT_CLASS_FUNC(X)
  109. INIT_CLASS_FUNC(Y)
  110. INIT_CLASS_FUNC(Z)
  111. static void init_shared_classes(void)
  112. {
  113. init_class_X(&lock_X1, &rwlock_X1, &mutex_X1, &rwsem_X1);
  114. init_class_X(&lock_X2, &rwlock_X2, &mutex_X2, &rwsem_X2);
  115. init_class_Y(&lock_Y1, &rwlock_Y1, &mutex_Y1, &rwsem_Y1);
  116. init_class_Y(&lock_Y2, &rwlock_Y2, &mutex_Y2, &rwsem_Y2);
  117. init_class_Z(&lock_Z1, &rwlock_Z1, &mutex_Z1, &rwsem_Z1);
  118. init_class_Z(&lock_Z2, &rwlock_Z2, &mutex_Z2, &rwsem_Z2);
  119. }
  120. /*
  121. * For spinlocks and rwlocks we also do hardirq-safe / softirq-safe tests.
  122. * The following functions use a lock from a simulated hardirq/softirq
  123. * context, causing the locks to be marked as hardirq-safe/softirq-safe:
  124. */
  125. #define HARDIRQ_DISABLE local_irq_disable
  126. #define HARDIRQ_ENABLE local_irq_enable
  127. #define HARDIRQ_ENTER() \
  128. local_irq_disable(); \
  129. __irq_enter(); \
  130. WARN_ON(!in_irq());
  131. #define HARDIRQ_EXIT() \
  132. __irq_exit(); \
  133. local_irq_enable();
  134. #define SOFTIRQ_DISABLE local_bh_disable
  135. #define SOFTIRQ_ENABLE local_bh_enable
  136. #define SOFTIRQ_ENTER() \
  137. local_bh_disable(); \
  138. local_irq_disable(); \
  139. lockdep_softirq_enter(); \
  140. WARN_ON(!in_softirq());
  141. #define SOFTIRQ_EXIT() \
  142. lockdep_softirq_exit(); \
  143. local_irq_enable(); \
  144. local_bh_enable();
  145. /*
  146. * Shortcuts for lock/unlock API variants, to keep
  147. * the testcases compact:
  148. */
  149. #define L(x) raw_spin_lock(&lock_##x)
  150. #define U(x) raw_spin_unlock(&lock_##x)
  151. #define LU(x) L(x); U(x)
  152. #define SI(x) raw_spin_lock_init(&lock_##x)
  153. #define WL(x) write_lock(&rwlock_##x)
  154. #define WU(x) write_unlock(&rwlock_##x)
  155. #define WLU(x) WL(x); WU(x)
  156. #define RL(x) read_lock(&rwlock_##x)
  157. #define RU(x) read_unlock(&rwlock_##x)
  158. #define RLU(x) RL(x); RU(x)
  159. #define RWI(x) rwlock_init(&rwlock_##x)
  160. #define ML(x) mutex_lock(&mutex_##x)
  161. #define MU(x) mutex_unlock(&mutex_##x)
  162. #define MI(x) mutex_init(&mutex_##x)
  163. #define WSL(x) down_write(&rwsem_##x)
  164. #define WSU(x) up_write(&rwsem_##x)
  165. #define RSL(x) down_read(&rwsem_##x)
  166. #define RSU(x) up_read(&rwsem_##x)
  167. #define RWSI(x) init_rwsem(&rwsem_##x)
  168. #ifndef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
  169. #define WWAI(x) ww_acquire_init(x, &ww_lockdep)
  170. #else
  171. #define WWAI(x) do { ww_acquire_init(x, &ww_lockdep); (x)->deadlock_inject_countdown = ~0U; } while (0)
  172. #endif
  173. #define WWAD(x) ww_acquire_done(x)
  174. #define WWAF(x) ww_acquire_fini(x)
  175. #define WWL(x, c) ww_mutex_lock(x, c)
  176. #define WWT(x) ww_mutex_trylock(x)
  177. #define WWL1(x) ww_mutex_lock(x, NULL)
  178. #define WWU(x) ww_mutex_unlock(x)
  179. #define LOCK_UNLOCK_2(x,y) LOCK(x); LOCK(y); UNLOCK(y); UNLOCK(x)
  180. /*
  181. * Generate different permutations of the same testcase, using
  182. * the same basic lock-dependency/state events:
  183. */
  184. #define GENERATE_TESTCASE(name) \
  185. \
  186. static void name(void) { E(); }
  187. #define GENERATE_PERMUTATIONS_2_EVENTS(name) \
  188. \
  189. static void name##_12(void) { E1(); E2(); } \
  190. static void name##_21(void) { E2(); E1(); }
  191. #define GENERATE_PERMUTATIONS_3_EVENTS(name) \
  192. \
  193. static void name##_123(void) { E1(); E2(); E3(); } \
  194. static void name##_132(void) { E1(); E3(); E2(); } \
  195. static void name##_213(void) { E2(); E1(); E3(); } \
  196. static void name##_231(void) { E2(); E3(); E1(); } \
  197. static void name##_312(void) { E3(); E1(); E2(); } \
  198. static void name##_321(void) { E3(); E2(); E1(); }
  199. /*
  200. * AA deadlock:
  201. */
  202. #define E() \
  203. \
  204. LOCK(X1); \
  205. LOCK(X2); /* this one should fail */
  206. /*
  207. * 6 testcases:
  208. */
  209. #include "locking-selftest-spin.h"
  210. GENERATE_TESTCASE(AA_spin)
  211. #include "locking-selftest-wlock.h"
  212. GENERATE_TESTCASE(AA_wlock)
  213. #include "locking-selftest-rlock.h"
  214. GENERATE_TESTCASE(AA_rlock)
  215. #include "locking-selftest-mutex.h"
  216. GENERATE_TESTCASE(AA_mutex)
  217. #include "locking-selftest-wsem.h"
  218. GENERATE_TESTCASE(AA_wsem)
  219. #include "locking-selftest-rsem.h"
  220. GENERATE_TESTCASE(AA_rsem)
  221. #undef E
  222. /*
  223. * Special-case for read-locking, they are
  224. * allowed to recurse on the same lock class:
  225. */
  226. static void rlock_AA1(void)
  227. {
  228. RL(X1);
  229. RL(X1); // this one should NOT fail
  230. }
  231. static void rlock_AA1B(void)
  232. {
  233. RL(X1);
  234. RL(X2); // this one should NOT fail
  235. }
  236. static void rsem_AA1(void)
  237. {
  238. RSL(X1);
  239. RSL(X1); // this one should fail
  240. }
  241. static void rsem_AA1B(void)
  242. {
  243. RSL(X1);
  244. RSL(X2); // this one should fail
  245. }
  246. /*
  247. * The mixing of read and write locks is not allowed:
  248. */
  249. static void rlock_AA2(void)
  250. {
  251. RL(X1);
  252. WL(X2); // this one should fail
  253. }
  254. static void rsem_AA2(void)
  255. {
  256. RSL(X1);
  257. WSL(X2); // this one should fail
  258. }
  259. static void rlock_AA3(void)
  260. {
  261. WL(X1);
  262. RL(X2); // this one should fail
  263. }
  264. static void rsem_AA3(void)
  265. {
  266. WSL(X1);
  267. RSL(X2); // this one should fail
  268. }
  269. /*
  270. * ABBA deadlock:
  271. */
  272. #define E() \
  273. \
  274. LOCK_UNLOCK_2(A, B); \
  275. LOCK_UNLOCK_2(B, A); /* fail */
  276. /*
  277. * 6 testcases:
  278. */
  279. #include "locking-selftest-spin.h"
  280. GENERATE_TESTCASE(ABBA_spin)
  281. #include "locking-selftest-wlock.h"
  282. GENERATE_TESTCASE(ABBA_wlock)
  283. #include "locking-selftest-rlock.h"
  284. GENERATE_TESTCASE(ABBA_rlock)
  285. #include "locking-selftest-mutex.h"
  286. GENERATE_TESTCASE(ABBA_mutex)
  287. #include "locking-selftest-wsem.h"
  288. GENERATE_TESTCASE(ABBA_wsem)
  289. #include "locking-selftest-rsem.h"
  290. GENERATE_TESTCASE(ABBA_rsem)
  291. #undef E
  292. /*
  293. * AB BC CA deadlock:
  294. */
  295. #define E() \
  296. \
  297. LOCK_UNLOCK_2(A, B); \
  298. LOCK_UNLOCK_2(B, C); \
  299. LOCK_UNLOCK_2(C, A); /* fail */
  300. /*
  301. * 6 testcases:
  302. */
  303. #include "locking-selftest-spin.h"
  304. GENERATE_TESTCASE(ABBCCA_spin)
  305. #include "locking-selftest-wlock.h"
  306. GENERATE_TESTCASE(ABBCCA_wlock)
  307. #include "locking-selftest-rlock.h"
  308. GENERATE_TESTCASE(ABBCCA_rlock)
  309. #include "locking-selftest-mutex.h"
  310. GENERATE_TESTCASE(ABBCCA_mutex)
  311. #include "locking-selftest-wsem.h"
  312. GENERATE_TESTCASE(ABBCCA_wsem)
  313. #include "locking-selftest-rsem.h"
  314. GENERATE_TESTCASE(ABBCCA_rsem)
  315. #undef E
  316. /*
  317. * AB CA BC deadlock:
  318. */
  319. #define E() \
  320. \
  321. LOCK_UNLOCK_2(A, B); \
  322. LOCK_UNLOCK_2(C, A); \
  323. LOCK_UNLOCK_2(B, C); /* fail */
  324. /*
  325. * 6 testcases:
  326. */
  327. #include "locking-selftest-spin.h"
  328. GENERATE_TESTCASE(ABCABC_spin)
  329. #include "locking-selftest-wlock.h"
  330. GENERATE_TESTCASE(ABCABC_wlock)
  331. #include "locking-selftest-rlock.h"
  332. GENERATE_TESTCASE(ABCABC_rlock)
  333. #include "locking-selftest-mutex.h"
  334. GENERATE_TESTCASE(ABCABC_mutex)
  335. #include "locking-selftest-wsem.h"
  336. GENERATE_TESTCASE(ABCABC_wsem)
  337. #include "locking-selftest-rsem.h"
  338. GENERATE_TESTCASE(ABCABC_rsem)
  339. #undef E
  340. /*
  341. * AB BC CD DA deadlock:
  342. */
  343. #define E() \
  344. \
  345. LOCK_UNLOCK_2(A, B); \
  346. LOCK_UNLOCK_2(B, C); \
  347. LOCK_UNLOCK_2(C, D); \
  348. LOCK_UNLOCK_2(D, A); /* fail */
  349. /*
  350. * 6 testcases:
  351. */
  352. #include "locking-selftest-spin.h"
  353. GENERATE_TESTCASE(ABBCCDDA_spin)
  354. #include "locking-selftest-wlock.h"
  355. GENERATE_TESTCASE(ABBCCDDA_wlock)
  356. #include "locking-selftest-rlock.h"
  357. GENERATE_TESTCASE(ABBCCDDA_rlock)
  358. #include "locking-selftest-mutex.h"
  359. GENERATE_TESTCASE(ABBCCDDA_mutex)
  360. #include "locking-selftest-wsem.h"
  361. GENERATE_TESTCASE(ABBCCDDA_wsem)
  362. #include "locking-selftest-rsem.h"
  363. GENERATE_TESTCASE(ABBCCDDA_rsem)
  364. #undef E
  365. /*
  366. * AB CD BD DA deadlock:
  367. */
  368. #define E() \
  369. \
  370. LOCK_UNLOCK_2(A, B); \
  371. LOCK_UNLOCK_2(C, D); \
  372. LOCK_UNLOCK_2(B, D); \
  373. LOCK_UNLOCK_2(D, A); /* fail */
  374. /*
  375. * 6 testcases:
  376. */
  377. #include "locking-selftest-spin.h"
  378. GENERATE_TESTCASE(ABCDBDDA_spin)
  379. #include "locking-selftest-wlock.h"
  380. GENERATE_TESTCASE(ABCDBDDA_wlock)
  381. #include "locking-selftest-rlock.h"
  382. GENERATE_TESTCASE(ABCDBDDA_rlock)
  383. #include "locking-selftest-mutex.h"
  384. GENERATE_TESTCASE(ABCDBDDA_mutex)
  385. #include "locking-selftest-wsem.h"
  386. GENERATE_TESTCASE(ABCDBDDA_wsem)
  387. #include "locking-selftest-rsem.h"
  388. GENERATE_TESTCASE(ABCDBDDA_rsem)
  389. #undef E
  390. /*
  391. * AB CD BC DA deadlock:
  392. */
  393. #define E() \
  394. \
  395. LOCK_UNLOCK_2(A, B); \
  396. LOCK_UNLOCK_2(C, D); \
  397. LOCK_UNLOCK_2(B, C); \
  398. LOCK_UNLOCK_2(D, A); /* fail */
  399. /*
  400. * 6 testcases:
  401. */
  402. #include "locking-selftest-spin.h"
  403. GENERATE_TESTCASE(ABCDBCDA_spin)
  404. #include "locking-selftest-wlock.h"
  405. GENERATE_TESTCASE(ABCDBCDA_wlock)
  406. #include "locking-selftest-rlock.h"
  407. GENERATE_TESTCASE(ABCDBCDA_rlock)
  408. #include "locking-selftest-mutex.h"
  409. GENERATE_TESTCASE(ABCDBCDA_mutex)
  410. #include "locking-selftest-wsem.h"
  411. GENERATE_TESTCASE(ABCDBCDA_wsem)
  412. #include "locking-selftest-rsem.h"
  413. GENERATE_TESTCASE(ABCDBCDA_rsem)
  414. #undef E
  415. /*
  416. * Double unlock:
  417. */
  418. #define E() \
  419. \
  420. LOCK(A); \
  421. UNLOCK(A); \
  422. UNLOCK(A); /* fail */
  423. /*
  424. * 6 testcases:
  425. */
  426. #include "locking-selftest-spin.h"
  427. GENERATE_TESTCASE(double_unlock_spin)
  428. #include "locking-selftest-wlock.h"
  429. GENERATE_TESTCASE(double_unlock_wlock)
  430. #include "locking-selftest-rlock.h"
  431. GENERATE_TESTCASE(double_unlock_rlock)
  432. #include "locking-selftest-mutex.h"
  433. GENERATE_TESTCASE(double_unlock_mutex)
  434. #include "locking-selftest-wsem.h"
  435. GENERATE_TESTCASE(double_unlock_wsem)
  436. #include "locking-selftest-rsem.h"
  437. GENERATE_TESTCASE(double_unlock_rsem)
  438. #undef E
  439. /*
  440. * Bad unlock ordering:
  441. */
  442. #define E() \
  443. \
  444. LOCK(A); \
  445. LOCK(B); \
  446. UNLOCK(A); /* fail */ \
  447. UNLOCK(B);
  448. /*
  449. * 6 testcases:
  450. */
  451. #include "locking-selftest-spin.h"
  452. GENERATE_TESTCASE(bad_unlock_order_spin)
  453. #include "locking-selftest-wlock.h"
  454. GENERATE_TESTCASE(bad_unlock_order_wlock)
  455. #include "locking-selftest-rlock.h"
  456. GENERATE_TESTCASE(bad_unlock_order_rlock)
  457. #include "locking-selftest-mutex.h"
  458. GENERATE_TESTCASE(bad_unlock_order_mutex)
  459. #include "locking-selftest-wsem.h"
  460. GENERATE_TESTCASE(bad_unlock_order_wsem)
  461. #include "locking-selftest-rsem.h"
  462. GENERATE_TESTCASE(bad_unlock_order_rsem)
  463. #undef E
  464. /*
  465. * initializing a held lock:
  466. */
  467. #define E() \
  468. \
  469. LOCK(A); \
  470. INIT(A); /* fail */
  471. /*
  472. * 6 testcases:
  473. */
  474. #include "locking-selftest-spin.h"
  475. GENERATE_TESTCASE(init_held_spin)
  476. #include "locking-selftest-wlock.h"
  477. GENERATE_TESTCASE(init_held_wlock)
  478. #include "locking-selftest-rlock.h"
  479. GENERATE_TESTCASE(init_held_rlock)
  480. #include "locking-selftest-mutex.h"
  481. GENERATE_TESTCASE(init_held_mutex)
  482. #include "locking-selftest-wsem.h"
  483. GENERATE_TESTCASE(init_held_wsem)
  484. #include "locking-selftest-rsem.h"
  485. GENERATE_TESTCASE(init_held_rsem)
  486. #undef E
  487. /*
  488. * locking an irq-safe lock with irqs enabled:
  489. */
  490. #define E1() \
  491. \
  492. IRQ_ENTER(); \
  493. LOCK(A); \
  494. UNLOCK(A); \
  495. IRQ_EXIT();
  496. #define E2() \
  497. \
  498. LOCK(A); \
  499. UNLOCK(A);
  500. /*
  501. * Generate 24 testcases:
  502. */
  503. #include "locking-selftest-spin-hardirq.h"
  504. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_hard_spin)
  505. #include "locking-selftest-rlock-hardirq.h"
  506. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_hard_rlock)
  507. #include "locking-selftest-wlock-hardirq.h"
  508. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_hard_wlock)
  509. #include "locking-selftest-spin-softirq.h"
  510. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_soft_spin)
  511. #include "locking-selftest-rlock-softirq.h"
  512. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_soft_rlock)
  513. #include "locking-selftest-wlock-softirq.h"
  514. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_soft_wlock)
  515. #undef E1
  516. #undef E2
  517. /*
  518. * Enabling hardirqs with a softirq-safe lock held:
  519. */
  520. #define E1() \
  521. \
  522. SOFTIRQ_ENTER(); \
  523. LOCK(A); \
  524. UNLOCK(A); \
  525. SOFTIRQ_EXIT();
  526. #define E2() \
  527. \
  528. HARDIRQ_DISABLE(); \
  529. LOCK(A); \
  530. HARDIRQ_ENABLE(); \
  531. UNLOCK(A);
  532. /*
  533. * Generate 12 testcases:
  534. */
  535. #include "locking-selftest-spin.h"
  536. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2A_spin)
  537. #include "locking-selftest-wlock.h"
  538. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2A_wlock)
  539. #include "locking-selftest-rlock.h"
  540. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2A_rlock)
  541. #undef E1
  542. #undef E2
  543. /*
  544. * Enabling irqs with an irq-safe lock held:
  545. */
  546. #define E1() \
  547. \
  548. IRQ_ENTER(); \
  549. LOCK(A); \
  550. UNLOCK(A); \
  551. IRQ_EXIT();
  552. #define E2() \
  553. \
  554. IRQ_DISABLE(); \
  555. LOCK(A); \
  556. IRQ_ENABLE(); \
  557. UNLOCK(A);
  558. /*
  559. * Generate 24 testcases:
  560. */
  561. #include "locking-selftest-spin-hardirq.h"
  562. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_hard_spin)
  563. #include "locking-selftest-rlock-hardirq.h"
  564. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_hard_rlock)
  565. #include "locking-selftest-wlock-hardirq.h"
  566. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_hard_wlock)
  567. #include "locking-selftest-spin-softirq.h"
  568. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_soft_spin)
  569. #include "locking-selftest-rlock-softirq.h"
  570. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_soft_rlock)
  571. #include "locking-selftest-wlock-softirq.h"
  572. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_soft_wlock)
  573. #undef E1
  574. #undef E2
  575. /*
  576. * Acquiring a irq-unsafe lock while holding an irq-safe-lock:
  577. */
  578. #define E1() \
  579. \
  580. LOCK(A); \
  581. LOCK(B); \
  582. UNLOCK(B); \
  583. UNLOCK(A); \
  584. #define E2() \
  585. \
  586. LOCK(B); \
  587. UNLOCK(B);
  588. #define E3() \
  589. \
  590. IRQ_ENTER(); \
  591. LOCK(A); \
  592. UNLOCK(A); \
  593. IRQ_EXIT();
  594. /*
  595. * Generate 36 testcases:
  596. */
  597. #include "locking-selftest-spin-hardirq.h"
  598. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_hard_spin)
  599. #include "locking-selftest-rlock-hardirq.h"
  600. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_hard_rlock)
  601. #include "locking-selftest-wlock-hardirq.h"
  602. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_hard_wlock)
  603. #include "locking-selftest-spin-softirq.h"
  604. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_soft_spin)
  605. #include "locking-selftest-rlock-softirq.h"
  606. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_soft_rlock)
  607. #include "locking-selftest-wlock-softirq.h"
  608. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_soft_wlock)
  609. #undef E1
  610. #undef E2
  611. #undef E3
  612. /*
  613. * If a lock turns into softirq-safe, but earlier it took
  614. * a softirq-unsafe lock:
  615. */
  616. #define E1() \
  617. IRQ_DISABLE(); \
  618. LOCK(A); \
  619. LOCK(B); \
  620. UNLOCK(B); \
  621. UNLOCK(A); \
  622. IRQ_ENABLE();
  623. #define E2() \
  624. LOCK(B); \
  625. UNLOCK(B);
  626. #define E3() \
  627. IRQ_ENTER(); \
  628. LOCK(A); \
  629. UNLOCK(A); \
  630. IRQ_EXIT();
  631. /*
  632. * Generate 36 testcases:
  633. */
  634. #include "locking-selftest-spin-hardirq.h"
  635. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_hard_spin)
  636. #include "locking-selftest-rlock-hardirq.h"
  637. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_hard_rlock)
  638. #include "locking-selftest-wlock-hardirq.h"
  639. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_hard_wlock)
  640. #include "locking-selftest-spin-softirq.h"
  641. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_soft_spin)
  642. #include "locking-selftest-rlock-softirq.h"
  643. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_soft_rlock)
  644. #include "locking-selftest-wlock-softirq.h"
  645. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_soft_wlock)
  646. #undef E1
  647. #undef E2
  648. #undef E3
  649. /*
  650. * read-lock / write-lock irq inversion.
  651. *
  652. * Deadlock scenario:
  653. *
  654. * CPU#1 is at #1, i.e. it has write-locked A, but has not
  655. * taken B yet.
  656. *
  657. * CPU#2 is at #2, i.e. it has locked B.
  658. *
  659. * Hardirq hits CPU#2 at point #2 and is trying to read-lock A.
  660. *
  661. * The deadlock occurs because CPU#1 will spin on B, and CPU#2
  662. * will spin on A.
  663. */
  664. #define E1() \
  665. \
  666. IRQ_DISABLE(); \
  667. WL(A); \
  668. LOCK(B); \
  669. UNLOCK(B); \
  670. WU(A); \
  671. IRQ_ENABLE();
  672. #define E2() \
  673. \
  674. LOCK(B); \
  675. UNLOCK(B);
  676. #define E3() \
  677. \
  678. IRQ_ENTER(); \
  679. RL(A); \
  680. RU(A); \
  681. IRQ_EXIT();
  682. /*
  683. * Generate 36 testcases:
  684. */
  685. #include "locking-selftest-spin-hardirq.h"
  686. GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_hard_spin)
  687. #include "locking-selftest-rlock-hardirq.h"
  688. GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_hard_rlock)
  689. #include "locking-selftest-wlock-hardirq.h"
  690. GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_hard_wlock)
  691. #include "locking-selftest-spin-softirq.h"
  692. GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_soft_spin)
  693. #include "locking-selftest-rlock-softirq.h"
  694. GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_soft_rlock)
  695. #include "locking-selftest-wlock-softirq.h"
  696. GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_soft_wlock)
  697. #undef E1
  698. #undef E2
  699. #undef E3
  700. /*
  701. * read-lock / write-lock recursion that is actually safe.
  702. */
  703. #define E1() \
  704. \
  705. IRQ_DISABLE(); \
  706. WL(A); \
  707. WU(A); \
  708. IRQ_ENABLE();
  709. #define E2() \
  710. \
  711. RL(A); \
  712. RU(A); \
  713. #define E3() \
  714. \
  715. IRQ_ENTER(); \
  716. RL(A); \
  717. L(B); \
  718. U(B); \
  719. RU(A); \
  720. IRQ_EXIT();
  721. /*
  722. * Generate 12 testcases:
  723. */
  724. #include "locking-selftest-hardirq.h"
  725. GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion_hard)
  726. #include "locking-selftest-softirq.h"
  727. GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion_soft)
  728. #undef E1
  729. #undef E2
  730. #undef E3
  731. /*
  732. * read-lock / write-lock recursion that is unsafe.
  733. */
  734. #define E1() \
  735. \
  736. IRQ_DISABLE(); \
  737. L(B); \
  738. WL(A); \
  739. WU(A); \
  740. U(B); \
  741. IRQ_ENABLE();
  742. #define E2() \
  743. \
  744. RL(A); \
  745. RU(A); \
  746. #define E3() \
  747. \
  748. IRQ_ENTER(); \
  749. L(B); \
  750. U(B); \
  751. IRQ_EXIT();
  752. /*
  753. * Generate 12 testcases:
  754. */
  755. #include "locking-selftest-hardirq.h"
  756. // GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion2_hard)
  757. #include "locking-selftest-softirq.h"
  758. // GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion2_soft)
  759. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  760. # define I_SPINLOCK(x) lockdep_reset_lock(&lock_##x.dep_map)
  761. # define I_RWLOCK(x) lockdep_reset_lock(&rwlock_##x.dep_map)
  762. # define I_MUTEX(x) lockdep_reset_lock(&mutex_##x.dep_map)
  763. # define I_RWSEM(x) lockdep_reset_lock(&rwsem_##x.dep_map)
  764. # define I_WW(x) lockdep_reset_lock(&x.dep_map)
  765. #else
  766. # define I_SPINLOCK(x)
  767. # define I_RWLOCK(x)
  768. # define I_MUTEX(x)
  769. # define I_RWSEM(x)
  770. # define I_WW(x)
  771. #endif
  772. #define I1(x) \
  773. do { \
  774. I_SPINLOCK(x); \
  775. I_RWLOCK(x); \
  776. I_MUTEX(x); \
  777. I_RWSEM(x); \
  778. } while (0)
  779. #define I2(x) \
  780. do { \
  781. raw_spin_lock_init(&lock_##x); \
  782. rwlock_init(&rwlock_##x); \
  783. mutex_init(&mutex_##x); \
  784. init_rwsem(&rwsem_##x); \
  785. } while (0)
  786. static void reset_locks(void)
  787. {
  788. local_irq_disable();
  789. lockdep_free_key_range(&ww_lockdep.acquire_key, 1);
  790. lockdep_free_key_range(&ww_lockdep.mutex_key, 1);
  791. I1(A); I1(B); I1(C); I1(D);
  792. I1(X1); I1(X2); I1(Y1); I1(Y2); I1(Z1); I1(Z2);
  793. I_WW(t); I_WW(t2); I_WW(o.base); I_WW(o2.base); I_WW(o3.base);
  794. lockdep_reset();
  795. I2(A); I2(B); I2(C); I2(D);
  796. init_shared_classes();
  797. ww_mutex_init(&o, &ww_lockdep); ww_mutex_init(&o2, &ww_lockdep); ww_mutex_init(&o3, &ww_lockdep);
  798. memset(&t, 0, sizeof(t)); memset(&t2, 0, sizeof(t2));
  799. memset(&ww_lockdep.acquire_key, 0, sizeof(ww_lockdep.acquire_key));
  800. memset(&ww_lockdep.mutex_key, 0, sizeof(ww_lockdep.mutex_key));
  801. local_irq_enable();
  802. }
  803. #undef I
  804. static int testcase_total;
  805. static int testcase_successes;
  806. static int expected_testcase_failures;
  807. static int unexpected_testcase_failures;
  808. static void dotest(void (*testcase_fn)(void), int expected, int lockclass_mask)
  809. {
  810. unsigned long saved_preempt_count = preempt_count();
  811. WARN_ON(irqs_disabled());
  812. testcase_fn();
  813. /*
  814. * Filter out expected failures:
  815. */
  816. #ifndef CONFIG_PROVE_LOCKING
  817. if (expected == FAILURE && debug_locks) {
  818. expected_testcase_failures++;
  819. printk("failed|");
  820. }
  821. else
  822. #endif
  823. if (debug_locks != expected) {
  824. unexpected_testcase_failures++;
  825. printk("FAILED|");
  826. dump_stack();
  827. } else {
  828. testcase_successes++;
  829. printk(" ok |");
  830. }
  831. testcase_total++;
  832. if (debug_locks_verbose)
  833. printk(" lockclass mask: %x, debug_locks: %d, expected: %d\n",
  834. lockclass_mask, debug_locks, expected);
  835. /*
  836. * Some tests (e.g. double-unlock) might corrupt the preemption
  837. * count, so restore it:
  838. */
  839. preempt_count_set(saved_preempt_count);
  840. #ifdef CONFIG_TRACE_IRQFLAGS
  841. if (softirq_count())
  842. current->softirqs_enabled = 0;
  843. else
  844. current->softirqs_enabled = 1;
  845. #endif
  846. reset_locks();
  847. }
  848. static inline void print_testname(const char *testname)
  849. {
  850. printk("%33s:", testname);
  851. }
  852. #define DO_TESTCASE_1(desc, name, nr) \
  853. print_testname(desc"/"#nr); \
  854. dotest(name##_##nr, SUCCESS, LOCKTYPE_RWLOCK); \
  855. printk("\n");
  856. #define DO_TESTCASE_1B(desc, name, nr) \
  857. print_testname(desc"/"#nr); \
  858. dotest(name##_##nr, FAILURE, LOCKTYPE_RWLOCK); \
  859. printk("\n");
  860. #define DO_TESTCASE_3(desc, name, nr) \
  861. print_testname(desc"/"#nr); \
  862. dotest(name##_spin_##nr, FAILURE, LOCKTYPE_SPIN); \
  863. dotest(name##_wlock_##nr, FAILURE, LOCKTYPE_RWLOCK); \
  864. dotest(name##_rlock_##nr, SUCCESS, LOCKTYPE_RWLOCK); \
  865. printk("\n");
  866. #define DO_TESTCASE_3RW(desc, name, nr) \
  867. print_testname(desc"/"#nr); \
  868. dotest(name##_spin_##nr, FAILURE, LOCKTYPE_SPIN|LOCKTYPE_RWLOCK);\
  869. dotest(name##_wlock_##nr, FAILURE, LOCKTYPE_RWLOCK); \
  870. dotest(name##_rlock_##nr, SUCCESS, LOCKTYPE_RWLOCK); \
  871. printk("\n");
  872. #define DO_TESTCASE_6(desc, name) \
  873. print_testname(desc); \
  874. dotest(name##_spin, FAILURE, LOCKTYPE_SPIN); \
  875. dotest(name##_wlock, FAILURE, LOCKTYPE_RWLOCK); \
  876. dotest(name##_rlock, FAILURE, LOCKTYPE_RWLOCK); \
  877. dotest(name##_mutex, FAILURE, LOCKTYPE_MUTEX); \
  878. dotest(name##_wsem, FAILURE, LOCKTYPE_RWSEM); \
  879. dotest(name##_rsem, FAILURE, LOCKTYPE_RWSEM); \
  880. printk("\n");
  881. #define DO_TESTCASE_6_SUCCESS(desc, name) \
  882. print_testname(desc); \
  883. dotest(name##_spin, SUCCESS, LOCKTYPE_SPIN); \
  884. dotest(name##_wlock, SUCCESS, LOCKTYPE_RWLOCK); \
  885. dotest(name##_rlock, SUCCESS, LOCKTYPE_RWLOCK); \
  886. dotest(name##_mutex, SUCCESS, LOCKTYPE_MUTEX); \
  887. dotest(name##_wsem, SUCCESS, LOCKTYPE_RWSEM); \
  888. dotest(name##_rsem, SUCCESS, LOCKTYPE_RWSEM); \
  889. printk("\n");
  890. /*
  891. * 'read' variant: rlocks must not trigger.
  892. */
  893. #define DO_TESTCASE_6R(desc, name) \
  894. print_testname(desc); \
  895. dotest(name##_spin, FAILURE, LOCKTYPE_SPIN); \
  896. dotest(name##_wlock, FAILURE, LOCKTYPE_RWLOCK); \
  897. dotest(name##_rlock, SUCCESS, LOCKTYPE_RWLOCK); \
  898. dotest(name##_mutex, FAILURE, LOCKTYPE_MUTEX); \
  899. dotest(name##_wsem, FAILURE, LOCKTYPE_RWSEM); \
  900. dotest(name##_rsem, FAILURE, LOCKTYPE_RWSEM); \
  901. printk("\n");
  902. #define DO_TESTCASE_2I(desc, name, nr) \
  903. DO_TESTCASE_1("hard-"desc, name##_hard, nr); \
  904. DO_TESTCASE_1("soft-"desc, name##_soft, nr);
  905. #define DO_TESTCASE_2IB(desc, name, nr) \
  906. DO_TESTCASE_1B("hard-"desc, name##_hard, nr); \
  907. DO_TESTCASE_1B("soft-"desc, name##_soft, nr);
  908. #define DO_TESTCASE_6I(desc, name, nr) \
  909. DO_TESTCASE_3("hard-"desc, name##_hard, nr); \
  910. DO_TESTCASE_3("soft-"desc, name##_soft, nr);
  911. #define DO_TESTCASE_6IRW(desc, name, nr) \
  912. DO_TESTCASE_3RW("hard-"desc, name##_hard, nr); \
  913. DO_TESTCASE_3RW("soft-"desc, name##_soft, nr);
  914. #define DO_TESTCASE_2x3(desc, name) \
  915. DO_TESTCASE_3(desc, name, 12); \
  916. DO_TESTCASE_3(desc, name, 21);
  917. #define DO_TESTCASE_2x6(desc, name) \
  918. DO_TESTCASE_6I(desc, name, 12); \
  919. DO_TESTCASE_6I(desc, name, 21);
  920. #define DO_TESTCASE_6x2(desc, name) \
  921. DO_TESTCASE_2I(desc, name, 123); \
  922. DO_TESTCASE_2I(desc, name, 132); \
  923. DO_TESTCASE_2I(desc, name, 213); \
  924. DO_TESTCASE_2I(desc, name, 231); \
  925. DO_TESTCASE_2I(desc, name, 312); \
  926. DO_TESTCASE_2I(desc, name, 321);
  927. #define DO_TESTCASE_6x2B(desc, name) \
  928. DO_TESTCASE_2IB(desc, name, 123); \
  929. DO_TESTCASE_2IB(desc, name, 132); \
  930. DO_TESTCASE_2IB(desc, name, 213); \
  931. DO_TESTCASE_2IB(desc, name, 231); \
  932. DO_TESTCASE_2IB(desc, name, 312); \
  933. DO_TESTCASE_2IB(desc, name, 321);
  934. #define DO_TESTCASE_6x6(desc, name) \
  935. DO_TESTCASE_6I(desc, name, 123); \
  936. DO_TESTCASE_6I(desc, name, 132); \
  937. DO_TESTCASE_6I(desc, name, 213); \
  938. DO_TESTCASE_6I(desc, name, 231); \
  939. DO_TESTCASE_6I(desc, name, 312); \
  940. DO_TESTCASE_6I(desc, name, 321);
  941. #define DO_TESTCASE_6x6RW(desc, name) \
  942. DO_TESTCASE_6IRW(desc, name, 123); \
  943. DO_TESTCASE_6IRW(desc, name, 132); \
  944. DO_TESTCASE_6IRW(desc, name, 213); \
  945. DO_TESTCASE_6IRW(desc, name, 231); \
  946. DO_TESTCASE_6IRW(desc, name, 312); \
  947. DO_TESTCASE_6IRW(desc, name, 321);
  948. static void ww_test_fail_acquire(void)
  949. {
  950. int ret;
  951. WWAI(&t);
  952. t.stamp++;
  953. ret = WWL(&o, &t);
  954. if (WARN_ON(!o.ctx) ||
  955. WARN_ON(ret))
  956. return;
  957. /* No lockdep test, pure API */
  958. ret = WWL(&o, &t);
  959. WARN_ON(ret != -EALREADY);
  960. ret = WWT(&o);
  961. WARN_ON(ret);
  962. t2 = t;
  963. t2.stamp++;
  964. ret = WWL(&o, &t2);
  965. WARN_ON(ret != -EDEADLK);
  966. WWU(&o);
  967. if (WWT(&o))
  968. WWU(&o);
  969. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  970. else
  971. DEBUG_LOCKS_WARN_ON(1);
  972. #endif
  973. }
  974. static void ww_test_normal(void)
  975. {
  976. int ret;
  977. WWAI(&t);
  978. /*
  979. * None of the ww_mutex codepaths should be taken in the 'normal'
  980. * mutex calls. The easiest way to verify this is by using the
  981. * normal mutex calls, and making sure o.ctx is unmodified.
  982. */
  983. /* mutex_lock (and indirectly, mutex_lock_nested) */
  984. o.ctx = (void *)~0UL;
  985. mutex_lock(&o.base);
  986. mutex_unlock(&o.base);
  987. WARN_ON(o.ctx != (void *)~0UL);
  988. /* mutex_lock_interruptible (and *_nested) */
  989. o.ctx = (void *)~0UL;
  990. ret = mutex_lock_interruptible(&o.base);
  991. if (!ret)
  992. mutex_unlock(&o.base);
  993. else
  994. WARN_ON(1);
  995. WARN_ON(o.ctx != (void *)~0UL);
  996. /* mutex_lock_killable (and *_nested) */
  997. o.ctx = (void *)~0UL;
  998. ret = mutex_lock_killable(&o.base);
  999. if (!ret)
  1000. mutex_unlock(&o.base);
  1001. else
  1002. WARN_ON(1);
  1003. WARN_ON(o.ctx != (void *)~0UL);
  1004. /* trylock, succeeding */
  1005. o.ctx = (void *)~0UL;
  1006. ret = mutex_trylock(&o.base);
  1007. WARN_ON(!ret);
  1008. if (ret)
  1009. mutex_unlock(&o.base);
  1010. else
  1011. WARN_ON(1);
  1012. WARN_ON(o.ctx != (void *)~0UL);
  1013. /* trylock, failing */
  1014. o.ctx = (void *)~0UL;
  1015. mutex_lock(&o.base);
  1016. ret = mutex_trylock(&o.base);
  1017. WARN_ON(ret);
  1018. mutex_unlock(&o.base);
  1019. WARN_ON(o.ctx != (void *)~0UL);
  1020. /* nest_lock */
  1021. o.ctx = (void *)~0UL;
  1022. mutex_lock_nest_lock(&o.base, &t);
  1023. mutex_unlock(&o.base);
  1024. WARN_ON(o.ctx != (void *)~0UL);
  1025. }
  1026. static void ww_test_two_contexts(void)
  1027. {
  1028. WWAI(&t);
  1029. WWAI(&t2);
  1030. }
  1031. static void ww_test_diff_class(void)
  1032. {
  1033. WWAI(&t);
  1034. #ifdef CONFIG_DEBUG_MUTEXES
  1035. t.ww_class = NULL;
  1036. #endif
  1037. WWL(&o, &t);
  1038. }
  1039. static void ww_test_context_done_twice(void)
  1040. {
  1041. WWAI(&t);
  1042. WWAD(&t);
  1043. WWAD(&t);
  1044. WWAF(&t);
  1045. }
  1046. static void ww_test_context_unlock_twice(void)
  1047. {
  1048. WWAI(&t);
  1049. WWAD(&t);
  1050. WWAF(&t);
  1051. WWAF(&t);
  1052. }
  1053. static void ww_test_context_fini_early(void)
  1054. {
  1055. WWAI(&t);
  1056. WWL(&o, &t);
  1057. WWAD(&t);
  1058. WWAF(&t);
  1059. }
  1060. static void ww_test_context_lock_after_done(void)
  1061. {
  1062. WWAI(&t);
  1063. WWAD(&t);
  1064. WWL(&o, &t);
  1065. }
  1066. static void ww_test_object_unlock_twice(void)
  1067. {
  1068. WWL1(&o);
  1069. WWU(&o);
  1070. WWU(&o);
  1071. }
  1072. static void ww_test_object_lock_unbalanced(void)
  1073. {
  1074. WWAI(&t);
  1075. WWL(&o, &t);
  1076. t.acquired = 0;
  1077. WWU(&o);
  1078. WWAF(&t);
  1079. }
  1080. static void ww_test_object_lock_stale_context(void)
  1081. {
  1082. WWAI(&t);
  1083. o.ctx = &t2;
  1084. WWL(&o, &t);
  1085. }
  1086. static void ww_test_edeadlk_normal(void)
  1087. {
  1088. int ret;
  1089. mutex_lock(&o2.base);
  1090. o2.ctx = &t2;
  1091. mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
  1092. WWAI(&t);
  1093. t2 = t;
  1094. t2.stamp--;
  1095. ret = WWL(&o, &t);
  1096. WARN_ON(ret);
  1097. ret = WWL(&o2, &t);
  1098. WARN_ON(ret != -EDEADLK);
  1099. o2.ctx = NULL;
  1100. mutex_acquire(&o2.base.dep_map, 0, 1, _THIS_IP_);
  1101. mutex_unlock(&o2.base);
  1102. WWU(&o);
  1103. WWL(&o2, &t);
  1104. }
  1105. static void ww_test_edeadlk_normal_slow(void)
  1106. {
  1107. int ret;
  1108. mutex_lock(&o2.base);
  1109. mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
  1110. o2.ctx = &t2;
  1111. WWAI(&t);
  1112. t2 = t;
  1113. t2.stamp--;
  1114. ret = WWL(&o, &t);
  1115. WARN_ON(ret);
  1116. ret = WWL(&o2, &t);
  1117. WARN_ON(ret != -EDEADLK);
  1118. o2.ctx = NULL;
  1119. mutex_acquire(&o2.base.dep_map, 0, 1, _THIS_IP_);
  1120. mutex_unlock(&o2.base);
  1121. WWU(&o);
  1122. ww_mutex_lock_slow(&o2, &t);
  1123. }
  1124. static void ww_test_edeadlk_no_unlock(void)
  1125. {
  1126. int ret;
  1127. mutex_lock(&o2.base);
  1128. o2.ctx = &t2;
  1129. mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
  1130. WWAI(&t);
  1131. t2 = t;
  1132. t2.stamp--;
  1133. ret = WWL(&o, &t);
  1134. WARN_ON(ret);
  1135. ret = WWL(&o2, &t);
  1136. WARN_ON(ret != -EDEADLK);
  1137. o2.ctx = NULL;
  1138. mutex_acquire(&o2.base.dep_map, 0, 1, _THIS_IP_);
  1139. mutex_unlock(&o2.base);
  1140. WWL(&o2, &t);
  1141. }
  1142. static void ww_test_edeadlk_no_unlock_slow(void)
  1143. {
  1144. int ret;
  1145. mutex_lock(&o2.base);
  1146. mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
  1147. o2.ctx = &t2;
  1148. WWAI(&t);
  1149. t2 = t;
  1150. t2.stamp--;
  1151. ret = WWL(&o, &t);
  1152. WARN_ON(ret);
  1153. ret = WWL(&o2, &t);
  1154. WARN_ON(ret != -EDEADLK);
  1155. o2.ctx = NULL;
  1156. mutex_acquire(&o2.base.dep_map, 0, 1, _THIS_IP_);
  1157. mutex_unlock(&o2.base);
  1158. ww_mutex_lock_slow(&o2, &t);
  1159. }
  1160. static void ww_test_edeadlk_acquire_more(void)
  1161. {
  1162. int ret;
  1163. mutex_lock(&o2.base);
  1164. mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
  1165. o2.ctx = &t2;
  1166. WWAI(&t);
  1167. t2 = t;
  1168. t2.stamp--;
  1169. ret = WWL(&o, &t);
  1170. WARN_ON(ret);
  1171. ret = WWL(&o2, &t);
  1172. WARN_ON(ret != -EDEADLK);
  1173. ret = WWL(&o3, &t);
  1174. }
  1175. static void ww_test_edeadlk_acquire_more_slow(void)
  1176. {
  1177. int ret;
  1178. mutex_lock(&o2.base);
  1179. mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
  1180. o2.ctx = &t2;
  1181. WWAI(&t);
  1182. t2 = t;
  1183. t2.stamp--;
  1184. ret = WWL(&o, &t);
  1185. WARN_ON(ret);
  1186. ret = WWL(&o2, &t);
  1187. WARN_ON(ret != -EDEADLK);
  1188. ww_mutex_lock_slow(&o3, &t);
  1189. }
  1190. static void ww_test_edeadlk_acquire_more_edeadlk(void)
  1191. {
  1192. int ret;
  1193. mutex_lock(&o2.base);
  1194. mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
  1195. o2.ctx = &t2;
  1196. mutex_lock(&o3.base);
  1197. mutex_release(&o3.base.dep_map, 1, _THIS_IP_);
  1198. o3.ctx = &t2;
  1199. WWAI(&t);
  1200. t2 = t;
  1201. t2.stamp--;
  1202. ret = WWL(&o, &t);
  1203. WARN_ON(ret);
  1204. ret = WWL(&o2, &t);
  1205. WARN_ON(ret != -EDEADLK);
  1206. ret = WWL(&o3, &t);
  1207. WARN_ON(ret != -EDEADLK);
  1208. }
  1209. static void ww_test_edeadlk_acquire_more_edeadlk_slow(void)
  1210. {
  1211. int ret;
  1212. mutex_lock(&o2.base);
  1213. mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
  1214. o2.ctx = &t2;
  1215. mutex_lock(&o3.base);
  1216. mutex_release(&o3.base.dep_map, 1, _THIS_IP_);
  1217. o3.ctx = &t2;
  1218. WWAI(&t);
  1219. t2 = t;
  1220. t2.stamp--;
  1221. ret = WWL(&o, &t);
  1222. WARN_ON(ret);
  1223. ret = WWL(&o2, &t);
  1224. WARN_ON(ret != -EDEADLK);
  1225. ww_mutex_lock_slow(&o3, &t);
  1226. }
  1227. static void ww_test_edeadlk_acquire_wrong(void)
  1228. {
  1229. int ret;
  1230. mutex_lock(&o2.base);
  1231. mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
  1232. o2.ctx = &t2;
  1233. WWAI(&t);
  1234. t2 = t;
  1235. t2.stamp--;
  1236. ret = WWL(&o, &t);
  1237. WARN_ON(ret);
  1238. ret = WWL(&o2, &t);
  1239. WARN_ON(ret != -EDEADLK);
  1240. if (!ret)
  1241. WWU(&o2);
  1242. WWU(&o);
  1243. ret = WWL(&o3, &t);
  1244. }
  1245. static void ww_test_edeadlk_acquire_wrong_slow(void)
  1246. {
  1247. int ret;
  1248. mutex_lock(&o2.base);
  1249. mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
  1250. o2.ctx = &t2;
  1251. WWAI(&t);
  1252. t2 = t;
  1253. t2.stamp--;
  1254. ret = WWL(&o, &t);
  1255. WARN_ON(ret);
  1256. ret = WWL(&o2, &t);
  1257. WARN_ON(ret != -EDEADLK);
  1258. if (!ret)
  1259. WWU(&o2);
  1260. WWU(&o);
  1261. ww_mutex_lock_slow(&o3, &t);
  1262. }
  1263. static void ww_test_spin_nest_unlocked(void)
  1264. {
  1265. raw_spin_lock_nest_lock(&lock_A, &o.base);
  1266. U(A);
  1267. }
  1268. static void ww_test_unneeded_slow(void)
  1269. {
  1270. WWAI(&t);
  1271. ww_mutex_lock_slow(&o, &t);
  1272. }
  1273. static void ww_test_context_block(void)
  1274. {
  1275. int ret;
  1276. WWAI(&t);
  1277. ret = WWL(&o, &t);
  1278. WARN_ON(ret);
  1279. WWL1(&o2);
  1280. }
  1281. static void ww_test_context_try(void)
  1282. {
  1283. int ret;
  1284. WWAI(&t);
  1285. ret = WWL(&o, &t);
  1286. WARN_ON(ret);
  1287. ret = WWT(&o2);
  1288. WARN_ON(!ret);
  1289. WWU(&o2);
  1290. WWU(&o);
  1291. }
  1292. static void ww_test_context_context(void)
  1293. {
  1294. int ret;
  1295. WWAI(&t);
  1296. ret = WWL(&o, &t);
  1297. WARN_ON(ret);
  1298. ret = WWL(&o2, &t);
  1299. WARN_ON(ret);
  1300. WWU(&o2);
  1301. WWU(&o);
  1302. }
  1303. static void ww_test_try_block(void)
  1304. {
  1305. bool ret;
  1306. ret = WWT(&o);
  1307. WARN_ON(!ret);
  1308. WWL1(&o2);
  1309. WWU(&o2);
  1310. WWU(&o);
  1311. }
  1312. static void ww_test_try_try(void)
  1313. {
  1314. bool ret;
  1315. ret = WWT(&o);
  1316. WARN_ON(!ret);
  1317. ret = WWT(&o2);
  1318. WARN_ON(!ret);
  1319. WWU(&o2);
  1320. WWU(&o);
  1321. }
  1322. static void ww_test_try_context(void)
  1323. {
  1324. int ret;
  1325. ret = WWT(&o);
  1326. WARN_ON(!ret);
  1327. WWAI(&t);
  1328. ret = WWL(&o2, &t);
  1329. WARN_ON(ret);
  1330. }
  1331. static void ww_test_block_block(void)
  1332. {
  1333. WWL1(&o);
  1334. WWL1(&o2);
  1335. }
  1336. static void ww_test_block_try(void)
  1337. {
  1338. bool ret;
  1339. WWL1(&o);
  1340. ret = WWT(&o2);
  1341. WARN_ON(!ret);
  1342. }
  1343. static void ww_test_block_context(void)
  1344. {
  1345. int ret;
  1346. WWL1(&o);
  1347. WWAI(&t);
  1348. ret = WWL(&o2, &t);
  1349. WARN_ON(ret);
  1350. }
  1351. static void ww_test_spin_block(void)
  1352. {
  1353. L(A);
  1354. U(A);
  1355. WWL1(&o);
  1356. L(A);
  1357. U(A);
  1358. WWU(&o);
  1359. L(A);
  1360. WWL1(&o);
  1361. WWU(&o);
  1362. U(A);
  1363. }
  1364. static void ww_test_spin_try(void)
  1365. {
  1366. bool ret;
  1367. L(A);
  1368. U(A);
  1369. ret = WWT(&o);
  1370. WARN_ON(!ret);
  1371. L(A);
  1372. U(A);
  1373. WWU(&o);
  1374. L(A);
  1375. ret = WWT(&o);
  1376. WARN_ON(!ret);
  1377. WWU(&o);
  1378. U(A);
  1379. }
  1380. static void ww_test_spin_context(void)
  1381. {
  1382. int ret;
  1383. L(A);
  1384. U(A);
  1385. WWAI(&t);
  1386. ret = WWL(&o, &t);
  1387. WARN_ON(ret);
  1388. L(A);
  1389. U(A);
  1390. WWU(&o);
  1391. L(A);
  1392. ret = WWL(&o, &t);
  1393. WARN_ON(ret);
  1394. WWU(&o);
  1395. U(A);
  1396. }
  1397. static void ww_tests(void)
  1398. {
  1399. printk(" --------------------------------------------------------------------------\n");
  1400. printk(" | Wound/wait tests |\n");
  1401. printk(" ---------------------\n");
  1402. print_testname("ww api failures");
  1403. dotest(ww_test_fail_acquire, SUCCESS, LOCKTYPE_WW);
  1404. dotest(ww_test_normal, SUCCESS, LOCKTYPE_WW);
  1405. dotest(ww_test_unneeded_slow, FAILURE, LOCKTYPE_WW);
  1406. printk("\n");
  1407. print_testname("ww contexts mixing");
  1408. dotest(ww_test_two_contexts, FAILURE, LOCKTYPE_WW);
  1409. dotest(ww_test_diff_class, FAILURE, LOCKTYPE_WW);
  1410. printk("\n");
  1411. print_testname("finishing ww context");
  1412. dotest(ww_test_context_done_twice, FAILURE, LOCKTYPE_WW);
  1413. dotest(ww_test_context_unlock_twice, FAILURE, LOCKTYPE_WW);
  1414. dotest(ww_test_context_fini_early, FAILURE, LOCKTYPE_WW);
  1415. dotest(ww_test_context_lock_after_done, FAILURE, LOCKTYPE_WW);
  1416. printk("\n");
  1417. print_testname("locking mismatches");
  1418. dotest(ww_test_object_unlock_twice, FAILURE, LOCKTYPE_WW);
  1419. dotest(ww_test_object_lock_unbalanced, FAILURE, LOCKTYPE_WW);
  1420. dotest(ww_test_object_lock_stale_context, FAILURE, LOCKTYPE_WW);
  1421. printk("\n");
  1422. print_testname("EDEADLK handling");
  1423. dotest(ww_test_edeadlk_normal, SUCCESS, LOCKTYPE_WW);
  1424. dotest(ww_test_edeadlk_normal_slow, SUCCESS, LOCKTYPE_WW);
  1425. dotest(ww_test_edeadlk_no_unlock, FAILURE, LOCKTYPE_WW);
  1426. dotest(ww_test_edeadlk_no_unlock_slow, FAILURE, LOCKTYPE_WW);
  1427. dotest(ww_test_edeadlk_acquire_more, FAILURE, LOCKTYPE_WW);
  1428. dotest(ww_test_edeadlk_acquire_more_slow, FAILURE, LOCKTYPE_WW);
  1429. dotest(ww_test_edeadlk_acquire_more_edeadlk, FAILURE, LOCKTYPE_WW);
  1430. dotest(ww_test_edeadlk_acquire_more_edeadlk_slow, FAILURE, LOCKTYPE_WW);
  1431. dotest(ww_test_edeadlk_acquire_wrong, FAILURE, LOCKTYPE_WW);
  1432. dotest(ww_test_edeadlk_acquire_wrong_slow, FAILURE, LOCKTYPE_WW);
  1433. printk("\n");
  1434. print_testname("spinlock nest unlocked");
  1435. dotest(ww_test_spin_nest_unlocked, FAILURE, LOCKTYPE_WW);
  1436. printk("\n");
  1437. printk(" -----------------------------------------------------\n");
  1438. printk(" |block | try |context|\n");
  1439. printk(" -----------------------------------------------------\n");
  1440. print_testname("context");
  1441. dotest(ww_test_context_block, FAILURE, LOCKTYPE_WW);
  1442. dotest(ww_test_context_try, SUCCESS, LOCKTYPE_WW);
  1443. dotest(ww_test_context_context, SUCCESS, LOCKTYPE_WW);
  1444. printk("\n");
  1445. print_testname("try");
  1446. dotest(ww_test_try_block, FAILURE, LOCKTYPE_WW);
  1447. dotest(ww_test_try_try, SUCCESS, LOCKTYPE_WW);
  1448. dotest(ww_test_try_context, FAILURE, LOCKTYPE_WW);
  1449. printk("\n");
  1450. print_testname("block");
  1451. dotest(ww_test_block_block, FAILURE, LOCKTYPE_WW);
  1452. dotest(ww_test_block_try, SUCCESS, LOCKTYPE_WW);
  1453. dotest(ww_test_block_context, FAILURE, LOCKTYPE_WW);
  1454. printk("\n");
  1455. print_testname("spinlock");
  1456. dotest(ww_test_spin_block, FAILURE, LOCKTYPE_WW);
  1457. dotest(ww_test_spin_try, SUCCESS, LOCKTYPE_WW);
  1458. dotest(ww_test_spin_context, FAILURE, LOCKTYPE_WW);
  1459. printk("\n");
  1460. }
  1461. void locking_selftest(void)
  1462. {
  1463. /*
  1464. * Got a locking failure before the selftest ran?
  1465. */
  1466. if (!debug_locks) {
  1467. printk("----------------------------------\n");
  1468. printk("| Locking API testsuite disabled |\n");
  1469. printk("----------------------------------\n");
  1470. return;
  1471. }
  1472. /*
  1473. * Run the testsuite:
  1474. */
  1475. printk("------------------------\n");
  1476. printk("| Locking API testsuite:\n");
  1477. printk("----------------------------------------------------------------------------\n");
  1478. printk(" | spin |wlock |rlock |mutex | wsem | rsem |\n");
  1479. printk(" --------------------------------------------------------------------------\n");
  1480. init_shared_classes();
  1481. debug_locks_silent = !debug_locks_verbose;
  1482. DO_TESTCASE_6R("A-A deadlock", AA);
  1483. DO_TESTCASE_6R("A-B-B-A deadlock", ABBA);
  1484. DO_TESTCASE_6R("A-B-B-C-C-A deadlock", ABBCCA);
  1485. DO_TESTCASE_6R("A-B-C-A-B-C deadlock", ABCABC);
  1486. DO_TESTCASE_6R("A-B-B-C-C-D-D-A deadlock", ABBCCDDA);
  1487. DO_TESTCASE_6R("A-B-C-D-B-D-D-A deadlock", ABCDBDDA);
  1488. DO_TESTCASE_6R("A-B-C-D-B-C-D-A deadlock", ABCDBCDA);
  1489. DO_TESTCASE_6("double unlock", double_unlock);
  1490. DO_TESTCASE_6("initialize held", init_held);
  1491. DO_TESTCASE_6_SUCCESS("bad unlock order", bad_unlock_order);
  1492. printk(" --------------------------------------------------------------------------\n");
  1493. print_testname("recursive read-lock");
  1494. printk(" |");
  1495. dotest(rlock_AA1, SUCCESS, LOCKTYPE_RWLOCK);
  1496. printk(" |");
  1497. dotest(rsem_AA1, FAILURE, LOCKTYPE_RWSEM);
  1498. printk("\n");
  1499. print_testname("recursive read-lock #2");
  1500. printk(" |");
  1501. dotest(rlock_AA1B, SUCCESS, LOCKTYPE_RWLOCK);
  1502. printk(" |");
  1503. dotest(rsem_AA1B, FAILURE, LOCKTYPE_RWSEM);
  1504. printk("\n");
  1505. print_testname("mixed read-write-lock");
  1506. printk(" |");
  1507. dotest(rlock_AA2, FAILURE, LOCKTYPE_RWLOCK);
  1508. printk(" |");
  1509. dotest(rsem_AA2, FAILURE, LOCKTYPE_RWSEM);
  1510. printk("\n");
  1511. print_testname("mixed write-read-lock");
  1512. printk(" |");
  1513. dotest(rlock_AA3, FAILURE, LOCKTYPE_RWLOCK);
  1514. printk(" |");
  1515. dotest(rsem_AA3, FAILURE, LOCKTYPE_RWSEM);
  1516. printk("\n");
  1517. printk(" --------------------------------------------------------------------------\n");
  1518. /*
  1519. * irq-context testcases:
  1520. */
  1521. DO_TESTCASE_2x6("irqs-on + irq-safe-A", irqsafe1);
  1522. DO_TESTCASE_2x3("sirq-safe-A => hirqs-on", irqsafe2A);
  1523. DO_TESTCASE_2x6("safe-A + irqs-on", irqsafe2B);
  1524. DO_TESTCASE_6x6("safe-A + unsafe-B #1", irqsafe3);
  1525. DO_TESTCASE_6x6("safe-A + unsafe-B #2", irqsafe4);
  1526. DO_TESTCASE_6x6RW("irq lock-inversion", irq_inversion);
  1527. DO_TESTCASE_6x2("irq read-recursion", irq_read_recursion);
  1528. // DO_TESTCASE_6x2B("irq read-recursion #2", irq_read_recursion2);
  1529. ww_tests();
  1530. if (unexpected_testcase_failures) {
  1531. printk("-----------------------------------------------------------------\n");
  1532. debug_locks = 0;
  1533. printk("BUG: %3d unexpected failures (out of %3d) - debugging disabled! |\n",
  1534. unexpected_testcase_failures, testcase_total);
  1535. printk("-----------------------------------------------------------------\n");
  1536. } else if (expected_testcase_failures && testcase_successes) {
  1537. printk("--------------------------------------------------------\n");
  1538. printk("%3d out of %3d testcases failed, as expected. |\n",
  1539. expected_testcase_failures, testcase_total);
  1540. printk("----------------------------------------------------\n");
  1541. debug_locks = 1;
  1542. } else if (expected_testcase_failures && !testcase_successes) {
  1543. printk("--------------------------------------------------------\n");
  1544. printk("All %3d testcases failed, as expected. |\n",
  1545. expected_testcase_failures);
  1546. printk("----------------------------------------\n");
  1547. debug_locks = 1;
  1548. } else {
  1549. printk("-------------------------------------------------------\n");
  1550. printk("Good, all %3d testcases passed! |\n",
  1551. testcase_successes);
  1552. printk("---------------------------------\n");
  1553. debug_locks = 1;
  1554. }
  1555. debug_locks_silent = 0;
  1556. }