locking-selftest.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903
  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. pr_cont("failed|");
  820. }
  821. else
  822. #endif
  823. if (debug_locks != expected) {
  824. unexpected_testcase_failures++;
  825. pr_cont("FAILED|");
  826. dump_stack();
  827. } else {
  828. testcase_successes++;
  829. pr_cont(" ok |");
  830. }
  831. testcase_total++;
  832. if (debug_locks_verbose)
  833. pr_cont(" 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. pr_cont("\n");
  856. #define DO_TESTCASE_1B(desc, name, nr) \
  857. print_testname(desc"/"#nr); \
  858. dotest(name##_##nr, FAILURE, LOCKTYPE_RWLOCK); \
  859. pr_cont("\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. pr_cont("\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. pr_cont("\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. pr_cont("\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. pr_cont("\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. pr_cont("\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. pr_cont("\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. pr_cont("\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. pr_cont("\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. pr_cont("\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. pr_cont("\n");
  1434. print_testname("spinlock nest unlocked");
  1435. dotest(ww_test_spin_nest_unlocked, FAILURE, LOCKTYPE_WW);
  1436. pr_cont("\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. pr_cont("\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. pr_cont("\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. pr_cont("\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. pr_cont("\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. pr_cont(" |");
  1495. dotest(rlock_AA1, SUCCESS, LOCKTYPE_RWLOCK);
  1496. pr_cont(" |");
  1497. dotest(rsem_AA1, FAILURE, LOCKTYPE_RWSEM);
  1498. pr_cont("\n");
  1499. print_testname("recursive read-lock #2");
  1500. pr_cont(" |");
  1501. dotest(rlock_AA1B, SUCCESS, LOCKTYPE_RWLOCK);
  1502. pr_cont(" |");
  1503. dotest(rsem_AA1B, FAILURE, LOCKTYPE_RWSEM);
  1504. pr_cont("\n");
  1505. print_testname("mixed read-write-lock");
  1506. pr_cont(" |");
  1507. dotest(rlock_AA2, FAILURE, LOCKTYPE_RWLOCK);
  1508. pr_cont(" |");
  1509. dotest(rsem_AA2, FAILURE, LOCKTYPE_RWSEM);
  1510. pr_cont("\n");
  1511. print_testname("mixed write-read-lock");
  1512. pr_cont(" |");
  1513. dotest(rlock_AA3, FAILURE, LOCKTYPE_RWLOCK);
  1514. pr_cont(" |");
  1515. dotest(rsem_AA3, FAILURE, LOCKTYPE_RWSEM);
  1516. pr_cont("\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. }