locking-selftest.c 40 KB

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