locking-selftest.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901
  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. #ifndef CONFIG_PROVE_LOCKING
  816. if (expected == FAILURE && debug_locks) {
  817. expected_testcase_failures++;
  818. printk("failed|");
  819. }
  820. else
  821. #endif
  822. if (debug_locks != expected) {
  823. unexpected_testcase_failures++;
  824. printk("FAILED|");
  825. dump_stack();
  826. } else {
  827. testcase_successes++;
  828. printk(" ok |");
  829. }
  830. testcase_total++;
  831. if (debug_locks_verbose)
  832. printk(" lockclass mask: %x, debug_locks: %d, expected: %d\n",
  833. lockclass_mask, debug_locks, expected);
  834. /*
  835. * Some tests (e.g. double-unlock) might corrupt the preemption
  836. * count, so restore it:
  837. */
  838. preempt_count() = saved_preempt_count;
  839. #ifdef CONFIG_TRACE_IRQFLAGS
  840. if (softirq_count())
  841. current->softirqs_enabled = 0;
  842. else
  843. current->softirqs_enabled = 1;
  844. #endif
  845. reset_locks();
  846. }
  847. static inline void print_testname(const char *testname)
  848. {
  849. printk("%33s:", testname);
  850. }
  851. #define DO_TESTCASE_1(desc, name, nr) \
  852. print_testname(desc"/"#nr); \
  853. dotest(name##_##nr, SUCCESS, LOCKTYPE_RWLOCK); \
  854. printk("\n");
  855. #define DO_TESTCASE_1B(desc, name, nr) \
  856. print_testname(desc"/"#nr); \
  857. dotest(name##_##nr, FAILURE, LOCKTYPE_RWLOCK); \
  858. printk("\n");
  859. #define DO_TESTCASE_3(desc, name, nr) \
  860. print_testname(desc"/"#nr); \
  861. dotest(name##_spin_##nr, FAILURE, LOCKTYPE_SPIN); \
  862. dotest(name##_wlock_##nr, FAILURE, LOCKTYPE_RWLOCK); \
  863. dotest(name##_rlock_##nr, SUCCESS, LOCKTYPE_RWLOCK); \
  864. printk("\n");
  865. #define DO_TESTCASE_3RW(desc, name, nr) \
  866. print_testname(desc"/"#nr); \
  867. dotest(name##_spin_##nr, FAILURE, LOCKTYPE_SPIN|LOCKTYPE_RWLOCK);\
  868. dotest(name##_wlock_##nr, FAILURE, LOCKTYPE_RWLOCK); \
  869. dotest(name##_rlock_##nr, SUCCESS, LOCKTYPE_RWLOCK); \
  870. printk("\n");
  871. #define DO_TESTCASE_6(desc, name) \
  872. print_testname(desc); \
  873. dotest(name##_spin, FAILURE, LOCKTYPE_SPIN); \
  874. dotest(name##_wlock, FAILURE, LOCKTYPE_RWLOCK); \
  875. dotest(name##_rlock, FAILURE, LOCKTYPE_RWLOCK); \
  876. dotest(name##_mutex, FAILURE, LOCKTYPE_MUTEX); \
  877. dotest(name##_wsem, FAILURE, LOCKTYPE_RWSEM); \
  878. dotest(name##_rsem, FAILURE, LOCKTYPE_RWSEM); \
  879. printk("\n");
  880. #define DO_TESTCASE_6_SUCCESS(desc, name) \
  881. print_testname(desc); \
  882. dotest(name##_spin, SUCCESS, LOCKTYPE_SPIN); \
  883. dotest(name##_wlock, SUCCESS, LOCKTYPE_RWLOCK); \
  884. dotest(name##_rlock, SUCCESS, LOCKTYPE_RWLOCK); \
  885. dotest(name##_mutex, SUCCESS, LOCKTYPE_MUTEX); \
  886. dotest(name##_wsem, SUCCESS, LOCKTYPE_RWSEM); \
  887. dotest(name##_rsem, SUCCESS, LOCKTYPE_RWSEM); \
  888. printk("\n");
  889. /*
  890. * 'read' variant: rlocks must not trigger.
  891. */
  892. #define DO_TESTCASE_6R(desc, name) \
  893. print_testname(desc); \
  894. dotest(name##_spin, FAILURE, LOCKTYPE_SPIN); \
  895. dotest(name##_wlock, FAILURE, LOCKTYPE_RWLOCK); \
  896. dotest(name##_rlock, SUCCESS, LOCKTYPE_RWLOCK); \
  897. dotest(name##_mutex, FAILURE, LOCKTYPE_MUTEX); \
  898. dotest(name##_wsem, FAILURE, LOCKTYPE_RWSEM); \
  899. dotest(name##_rsem, FAILURE, LOCKTYPE_RWSEM); \
  900. printk("\n");
  901. #define DO_TESTCASE_2I(desc, name, nr) \
  902. DO_TESTCASE_1("hard-"desc, name##_hard, nr); \
  903. DO_TESTCASE_1("soft-"desc, name##_soft, nr);
  904. #define DO_TESTCASE_2IB(desc, name, nr) \
  905. DO_TESTCASE_1B("hard-"desc, name##_hard, nr); \
  906. DO_TESTCASE_1B("soft-"desc, name##_soft, nr);
  907. #define DO_TESTCASE_6I(desc, name, nr) \
  908. DO_TESTCASE_3("hard-"desc, name##_hard, nr); \
  909. DO_TESTCASE_3("soft-"desc, name##_soft, nr);
  910. #define DO_TESTCASE_6IRW(desc, name, nr) \
  911. DO_TESTCASE_3RW("hard-"desc, name##_hard, nr); \
  912. DO_TESTCASE_3RW("soft-"desc, name##_soft, nr);
  913. #define DO_TESTCASE_2x3(desc, name) \
  914. DO_TESTCASE_3(desc, name, 12); \
  915. DO_TESTCASE_3(desc, name, 21);
  916. #define DO_TESTCASE_2x6(desc, name) \
  917. DO_TESTCASE_6I(desc, name, 12); \
  918. DO_TESTCASE_6I(desc, name, 21);
  919. #define DO_TESTCASE_6x2(desc, name) \
  920. DO_TESTCASE_2I(desc, name, 123); \
  921. DO_TESTCASE_2I(desc, name, 132); \
  922. DO_TESTCASE_2I(desc, name, 213); \
  923. DO_TESTCASE_2I(desc, name, 231); \
  924. DO_TESTCASE_2I(desc, name, 312); \
  925. DO_TESTCASE_2I(desc, name, 321);
  926. #define DO_TESTCASE_6x2B(desc, name) \
  927. DO_TESTCASE_2IB(desc, name, 123); \
  928. DO_TESTCASE_2IB(desc, name, 132); \
  929. DO_TESTCASE_2IB(desc, name, 213); \
  930. DO_TESTCASE_2IB(desc, name, 231); \
  931. DO_TESTCASE_2IB(desc, name, 312); \
  932. DO_TESTCASE_2IB(desc, name, 321);
  933. #define DO_TESTCASE_6x6(desc, name) \
  934. DO_TESTCASE_6I(desc, name, 123); \
  935. DO_TESTCASE_6I(desc, name, 132); \
  936. DO_TESTCASE_6I(desc, name, 213); \
  937. DO_TESTCASE_6I(desc, name, 231); \
  938. DO_TESTCASE_6I(desc, name, 312); \
  939. DO_TESTCASE_6I(desc, name, 321);
  940. #define DO_TESTCASE_6x6RW(desc, name) \
  941. DO_TESTCASE_6IRW(desc, name, 123); \
  942. DO_TESTCASE_6IRW(desc, name, 132); \
  943. DO_TESTCASE_6IRW(desc, name, 213); \
  944. DO_TESTCASE_6IRW(desc, name, 231); \
  945. DO_TESTCASE_6IRW(desc, name, 312); \
  946. DO_TESTCASE_6IRW(desc, name, 321);
  947. static void ww_test_fail_acquire(void)
  948. {
  949. int ret;
  950. WWAI(&t);
  951. t.stamp++;
  952. ret = WWL(&o, &t);
  953. if (WARN_ON(!o.ctx) ||
  954. WARN_ON(ret))
  955. return;
  956. /* No lockdep test, pure API */
  957. ret = WWL(&o, &t);
  958. WARN_ON(ret != -EALREADY);
  959. ret = WWT(&o);
  960. WARN_ON(ret);
  961. t2 = t;
  962. t2.stamp++;
  963. ret = WWL(&o, &t2);
  964. WARN_ON(ret != -EDEADLK);
  965. WWU(&o);
  966. if (WWT(&o))
  967. WWU(&o);
  968. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  969. else
  970. DEBUG_LOCKS_WARN_ON(1);
  971. #endif
  972. }
  973. static void ww_test_normal(void)
  974. {
  975. int ret;
  976. WWAI(&t);
  977. /*
  978. * None of the ww_mutex codepaths should be taken in the 'normal'
  979. * mutex calls. The easiest way to verify this is by using the
  980. * normal mutex calls, and making sure o.ctx is unmodified.
  981. */
  982. /* mutex_lock (and indirectly, mutex_lock_nested) */
  983. o.ctx = (void *)~0UL;
  984. mutex_lock(&o.base);
  985. mutex_unlock(&o.base);
  986. WARN_ON(o.ctx != (void *)~0UL);
  987. /* mutex_lock_interruptible (and *_nested) */
  988. o.ctx = (void *)~0UL;
  989. ret = mutex_lock_interruptible(&o.base);
  990. if (!ret)
  991. mutex_unlock(&o.base);
  992. else
  993. WARN_ON(1);
  994. WARN_ON(o.ctx != (void *)~0UL);
  995. /* mutex_lock_killable (and *_nested) */
  996. o.ctx = (void *)~0UL;
  997. ret = mutex_lock_killable(&o.base);
  998. if (!ret)
  999. mutex_unlock(&o.base);
  1000. else
  1001. WARN_ON(1);
  1002. WARN_ON(o.ctx != (void *)~0UL);
  1003. /* trylock, succeeding */
  1004. o.ctx = (void *)~0UL;
  1005. ret = mutex_trylock(&o.base);
  1006. WARN_ON(!ret);
  1007. if (ret)
  1008. mutex_unlock(&o.base);
  1009. else
  1010. WARN_ON(1);
  1011. WARN_ON(o.ctx != (void *)~0UL);
  1012. /* trylock, failing */
  1013. o.ctx = (void *)~0UL;
  1014. mutex_lock(&o.base);
  1015. ret = mutex_trylock(&o.base);
  1016. WARN_ON(ret);
  1017. mutex_unlock(&o.base);
  1018. WARN_ON(o.ctx != (void *)~0UL);
  1019. /* nest_lock */
  1020. o.ctx = (void *)~0UL;
  1021. mutex_lock_nest_lock(&o.base, &t);
  1022. mutex_unlock(&o.base);
  1023. WARN_ON(o.ctx != (void *)~0UL);
  1024. }
  1025. static void ww_test_two_contexts(void)
  1026. {
  1027. WWAI(&t);
  1028. WWAI(&t2);
  1029. }
  1030. static void ww_test_diff_class(void)
  1031. {
  1032. WWAI(&t);
  1033. #ifdef CONFIG_DEBUG_MUTEXES
  1034. t.ww_class = NULL;
  1035. #endif
  1036. WWL(&o, &t);
  1037. }
  1038. static void ww_test_context_done_twice(void)
  1039. {
  1040. WWAI(&t);
  1041. WWAD(&t);
  1042. WWAD(&t);
  1043. WWAF(&t);
  1044. }
  1045. static void ww_test_context_unlock_twice(void)
  1046. {
  1047. WWAI(&t);
  1048. WWAD(&t);
  1049. WWAF(&t);
  1050. WWAF(&t);
  1051. }
  1052. static void ww_test_context_fini_early(void)
  1053. {
  1054. WWAI(&t);
  1055. WWL(&o, &t);
  1056. WWAD(&t);
  1057. WWAF(&t);
  1058. }
  1059. static void ww_test_context_lock_after_done(void)
  1060. {
  1061. WWAI(&t);
  1062. WWAD(&t);
  1063. WWL(&o, &t);
  1064. }
  1065. static void ww_test_object_unlock_twice(void)
  1066. {
  1067. WWL1(&o);
  1068. WWU(&o);
  1069. WWU(&o);
  1070. }
  1071. static void ww_test_object_lock_unbalanced(void)
  1072. {
  1073. WWAI(&t);
  1074. WWL(&o, &t);
  1075. t.acquired = 0;
  1076. WWU(&o);
  1077. WWAF(&t);
  1078. }
  1079. static void ww_test_object_lock_stale_context(void)
  1080. {
  1081. WWAI(&t);
  1082. o.ctx = &t2;
  1083. WWL(&o, &t);
  1084. }
  1085. static void ww_test_edeadlk_normal(void)
  1086. {
  1087. int ret;
  1088. mutex_lock(&o2.base);
  1089. o2.ctx = &t2;
  1090. mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
  1091. WWAI(&t);
  1092. t2 = t;
  1093. t2.stamp--;
  1094. ret = WWL(&o, &t);
  1095. WARN_ON(ret);
  1096. ret = WWL(&o2, &t);
  1097. WARN_ON(ret != -EDEADLK);
  1098. o2.ctx = NULL;
  1099. mutex_acquire(&o2.base.dep_map, 0, 1, _THIS_IP_);
  1100. mutex_unlock(&o2.base);
  1101. WWU(&o);
  1102. WWL(&o2, &t);
  1103. }
  1104. static void ww_test_edeadlk_normal_slow(void)
  1105. {
  1106. int ret;
  1107. mutex_lock(&o2.base);
  1108. mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
  1109. o2.ctx = &t2;
  1110. WWAI(&t);
  1111. t2 = t;
  1112. t2.stamp--;
  1113. ret = WWL(&o, &t);
  1114. WARN_ON(ret);
  1115. ret = WWL(&o2, &t);
  1116. WARN_ON(ret != -EDEADLK);
  1117. o2.ctx = NULL;
  1118. mutex_acquire(&o2.base.dep_map, 0, 1, _THIS_IP_);
  1119. mutex_unlock(&o2.base);
  1120. WWU(&o);
  1121. ww_mutex_lock_slow(&o2, &t);
  1122. }
  1123. static void ww_test_edeadlk_no_unlock(void)
  1124. {
  1125. int ret;
  1126. mutex_lock(&o2.base);
  1127. o2.ctx = &t2;
  1128. mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
  1129. WWAI(&t);
  1130. t2 = t;
  1131. t2.stamp--;
  1132. ret = WWL(&o, &t);
  1133. WARN_ON(ret);
  1134. ret = WWL(&o2, &t);
  1135. WARN_ON(ret != -EDEADLK);
  1136. o2.ctx = NULL;
  1137. mutex_acquire(&o2.base.dep_map, 0, 1, _THIS_IP_);
  1138. mutex_unlock(&o2.base);
  1139. WWL(&o2, &t);
  1140. }
  1141. static void ww_test_edeadlk_no_unlock_slow(void)
  1142. {
  1143. int ret;
  1144. mutex_lock(&o2.base);
  1145. mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
  1146. o2.ctx = &t2;
  1147. WWAI(&t);
  1148. t2 = t;
  1149. t2.stamp--;
  1150. ret = WWL(&o, &t);
  1151. WARN_ON(ret);
  1152. ret = WWL(&o2, &t);
  1153. WARN_ON(ret != -EDEADLK);
  1154. o2.ctx = NULL;
  1155. mutex_acquire(&o2.base.dep_map, 0, 1, _THIS_IP_);
  1156. mutex_unlock(&o2.base);
  1157. ww_mutex_lock_slow(&o2, &t);
  1158. }
  1159. static void ww_test_edeadlk_acquire_more(void)
  1160. {
  1161. int ret;
  1162. mutex_lock(&o2.base);
  1163. mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
  1164. o2.ctx = &t2;
  1165. WWAI(&t);
  1166. t2 = t;
  1167. t2.stamp--;
  1168. ret = WWL(&o, &t);
  1169. WARN_ON(ret);
  1170. ret = WWL(&o2, &t);
  1171. WARN_ON(ret != -EDEADLK);
  1172. ret = WWL(&o3, &t);
  1173. }
  1174. static void ww_test_edeadlk_acquire_more_slow(void)
  1175. {
  1176. int ret;
  1177. mutex_lock(&o2.base);
  1178. mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
  1179. o2.ctx = &t2;
  1180. WWAI(&t);
  1181. t2 = t;
  1182. t2.stamp--;
  1183. ret = WWL(&o, &t);
  1184. WARN_ON(ret);
  1185. ret = WWL(&o2, &t);
  1186. WARN_ON(ret != -EDEADLK);
  1187. ww_mutex_lock_slow(&o3, &t);
  1188. }
  1189. static void ww_test_edeadlk_acquire_more_edeadlk(void)
  1190. {
  1191. int ret;
  1192. mutex_lock(&o2.base);
  1193. mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
  1194. o2.ctx = &t2;
  1195. mutex_lock(&o3.base);
  1196. mutex_release(&o3.base.dep_map, 1, _THIS_IP_);
  1197. o3.ctx = &t2;
  1198. WWAI(&t);
  1199. t2 = t;
  1200. t2.stamp--;
  1201. ret = WWL(&o, &t);
  1202. WARN_ON(ret);
  1203. ret = WWL(&o2, &t);
  1204. WARN_ON(ret != -EDEADLK);
  1205. ret = WWL(&o3, &t);
  1206. WARN_ON(ret != -EDEADLK);
  1207. }
  1208. static void ww_test_edeadlk_acquire_more_edeadlk_slow(void)
  1209. {
  1210. int ret;
  1211. mutex_lock(&o2.base);
  1212. mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
  1213. o2.ctx = &t2;
  1214. mutex_lock(&o3.base);
  1215. mutex_release(&o3.base.dep_map, 1, _THIS_IP_);
  1216. o3.ctx = &t2;
  1217. WWAI(&t);
  1218. t2 = t;
  1219. t2.stamp--;
  1220. ret = WWL(&o, &t);
  1221. WARN_ON(ret);
  1222. ret = WWL(&o2, &t);
  1223. WARN_ON(ret != -EDEADLK);
  1224. ww_mutex_lock_slow(&o3, &t);
  1225. }
  1226. static void ww_test_edeadlk_acquire_wrong(void)
  1227. {
  1228. int ret;
  1229. mutex_lock(&o2.base);
  1230. mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
  1231. o2.ctx = &t2;
  1232. WWAI(&t);
  1233. t2 = t;
  1234. t2.stamp--;
  1235. ret = WWL(&o, &t);
  1236. WARN_ON(ret);
  1237. ret = WWL(&o2, &t);
  1238. WARN_ON(ret != -EDEADLK);
  1239. if (!ret)
  1240. WWU(&o2);
  1241. WWU(&o);
  1242. ret = WWL(&o3, &t);
  1243. }
  1244. static void ww_test_edeadlk_acquire_wrong_slow(void)
  1245. {
  1246. int ret;
  1247. mutex_lock(&o2.base);
  1248. mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
  1249. o2.ctx = &t2;
  1250. WWAI(&t);
  1251. t2 = t;
  1252. t2.stamp--;
  1253. ret = WWL(&o, &t);
  1254. WARN_ON(ret);
  1255. ret = WWL(&o2, &t);
  1256. WARN_ON(ret != -EDEADLK);
  1257. if (!ret)
  1258. WWU(&o2);
  1259. WWU(&o);
  1260. ww_mutex_lock_slow(&o3, &t);
  1261. }
  1262. static void ww_test_spin_nest_unlocked(void)
  1263. {
  1264. raw_spin_lock_nest_lock(&lock_A, &o.base);
  1265. U(A);
  1266. }
  1267. static void ww_test_unneeded_slow(void)
  1268. {
  1269. WWAI(&t);
  1270. ww_mutex_lock_slow(&o, &t);
  1271. }
  1272. static void ww_test_context_block(void)
  1273. {
  1274. int ret;
  1275. WWAI(&t);
  1276. ret = WWL(&o, &t);
  1277. WARN_ON(ret);
  1278. WWL1(&o2);
  1279. }
  1280. static void ww_test_context_try(void)
  1281. {
  1282. int ret;
  1283. WWAI(&t);
  1284. ret = WWL(&o, &t);
  1285. WARN_ON(ret);
  1286. ret = WWT(&o2);
  1287. WARN_ON(!ret);
  1288. WWU(&o2);
  1289. WWU(&o);
  1290. }
  1291. static void ww_test_context_context(void)
  1292. {
  1293. int ret;
  1294. WWAI(&t);
  1295. ret = WWL(&o, &t);
  1296. WARN_ON(ret);
  1297. ret = WWL(&o2, &t);
  1298. WARN_ON(ret);
  1299. WWU(&o2);
  1300. WWU(&o);
  1301. }
  1302. static void ww_test_try_block(void)
  1303. {
  1304. bool ret;
  1305. ret = WWT(&o);
  1306. WARN_ON(!ret);
  1307. WWL1(&o2);
  1308. WWU(&o2);
  1309. WWU(&o);
  1310. }
  1311. static void ww_test_try_try(void)
  1312. {
  1313. bool ret;
  1314. ret = WWT(&o);
  1315. WARN_ON(!ret);
  1316. ret = WWT(&o2);
  1317. WARN_ON(!ret);
  1318. WWU(&o2);
  1319. WWU(&o);
  1320. }
  1321. static void ww_test_try_context(void)
  1322. {
  1323. int ret;
  1324. ret = WWT(&o);
  1325. WARN_ON(!ret);
  1326. WWAI(&t);
  1327. ret = WWL(&o2, &t);
  1328. WARN_ON(ret);
  1329. }
  1330. static void ww_test_block_block(void)
  1331. {
  1332. WWL1(&o);
  1333. WWL1(&o2);
  1334. }
  1335. static void ww_test_block_try(void)
  1336. {
  1337. bool ret;
  1338. WWL1(&o);
  1339. ret = WWT(&o2);
  1340. WARN_ON(!ret);
  1341. }
  1342. static void ww_test_block_context(void)
  1343. {
  1344. int ret;
  1345. WWL1(&o);
  1346. WWAI(&t);
  1347. ret = WWL(&o2, &t);
  1348. WARN_ON(ret);
  1349. }
  1350. static void ww_test_spin_block(void)
  1351. {
  1352. L(A);
  1353. U(A);
  1354. WWL1(&o);
  1355. L(A);
  1356. U(A);
  1357. WWU(&o);
  1358. L(A);
  1359. WWL1(&o);
  1360. WWU(&o);
  1361. U(A);
  1362. }
  1363. static void ww_test_spin_try(void)
  1364. {
  1365. bool ret;
  1366. L(A);
  1367. U(A);
  1368. ret = WWT(&o);
  1369. WARN_ON(!ret);
  1370. L(A);
  1371. U(A);
  1372. WWU(&o);
  1373. L(A);
  1374. ret = WWT(&o);
  1375. WARN_ON(!ret);
  1376. WWU(&o);
  1377. U(A);
  1378. }
  1379. static void ww_test_spin_context(void)
  1380. {
  1381. int ret;
  1382. L(A);
  1383. U(A);
  1384. WWAI(&t);
  1385. ret = WWL(&o, &t);
  1386. WARN_ON(ret);
  1387. L(A);
  1388. U(A);
  1389. WWU(&o);
  1390. L(A);
  1391. ret = WWL(&o, &t);
  1392. WARN_ON(ret);
  1393. WWU(&o);
  1394. U(A);
  1395. }
  1396. static void ww_tests(void)
  1397. {
  1398. printk(" --------------------------------------------------------------------------\n");
  1399. printk(" | Wound/wait tests |\n");
  1400. printk(" ---------------------\n");
  1401. print_testname("ww api failures");
  1402. dotest(ww_test_fail_acquire, SUCCESS, LOCKTYPE_WW);
  1403. dotest(ww_test_normal, SUCCESS, LOCKTYPE_WW);
  1404. dotest(ww_test_unneeded_slow, FAILURE, LOCKTYPE_WW);
  1405. printk("\n");
  1406. print_testname("ww contexts mixing");
  1407. dotest(ww_test_two_contexts, FAILURE, LOCKTYPE_WW);
  1408. dotest(ww_test_diff_class, FAILURE, LOCKTYPE_WW);
  1409. printk("\n");
  1410. print_testname("finishing ww context");
  1411. dotest(ww_test_context_done_twice, FAILURE, LOCKTYPE_WW);
  1412. dotest(ww_test_context_unlock_twice, FAILURE, LOCKTYPE_WW);
  1413. dotest(ww_test_context_fini_early, FAILURE, LOCKTYPE_WW);
  1414. dotest(ww_test_context_lock_after_done, FAILURE, LOCKTYPE_WW);
  1415. printk("\n");
  1416. print_testname("locking mismatches");
  1417. dotest(ww_test_object_unlock_twice, FAILURE, LOCKTYPE_WW);
  1418. dotest(ww_test_object_lock_unbalanced, FAILURE, LOCKTYPE_WW);
  1419. dotest(ww_test_object_lock_stale_context, FAILURE, LOCKTYPE_WW);
  1420. printk("\n");
  1421. print_testname("EDEADLK handling");
  1422. dotest(ww_test_edeadlk_normal, SUCCESS, LOCKTYPE_WW);
  1423. dotest(ww_test_edeadlk_normal_slow, SUCCESS, LOCKTYPE_WW);
  1424. dotest(ww_test_edeadlk_no_unlock, FAILURE, LOCKTYPE_WW);
  1425. dotest(ww_test_edeadlk_no_unlock_slow, FAILURE, LOCKTYPE_WW);
  1426. dotest(ww_test_edeadlk_acquire_more, FAILURE, LOCKTYPE_WW);
  1427. dotest(ww_test_edeadlk_acquire_more_slow, FAILURE, LOCKTYPE_WW);
  1428. dotest(ww_test_edeadlk_acquire_more_edeadlk, FAILURE, LOCKTYPE_WW);
  1429. dotest(ww_test_edeadlk_acquire_more_edeadlk_slow, FAILURE, LOCKTYPE_WW);
  1430. dotest(ww_test_edeadlk_acquire_wrong, FAILURE, LOCKTYPE_WW);
  1431. dotest(ww_test_edeadlk_acquire_wrong_slow, FAILURE, LOCKTYPE_WW);
  1432. printk("\n");
  1433. print_testname("spinlock nest unlocked");
  1434. dotest(ww_test_spin_nest_unlocked, FAILURE, LOCKTYPE_WW);
  1435. printk("\n");
  1436. printk(" -----------------------------------------------------\n");
  1437. printk(" |block | try |context|\n");
  1438. printk(" -----------------------------------------------------\n");
  1439. print_testname("context");
  1440. dotest(ww_test_context_block, FAILURE, LOCKTYPE_WW);
  1441. dotest(ww_test_context_try, SUCCESS, LOCKTYPE_WW);
  1442. dotest(ww_test_context_context, SUCCESS, LOCKTYPE_WW);
  1443. printk("\n");
  1444. print_testname("try");
  1445. dotest(ww_test_try_block, FAILURE, LOCKTYPE_WW);
  1446. dotest(ww_test_try_try, SUCCESS, LOCKTYPE_WW);
  1447. dotest(ww_test_try_context, FAILURE, LOCKTYPE_WW);
  1448. printk("\n");
  1449. print_testname("block");
  1450. dotest(ww_test_block_block, FAILURE, LOCKTYPE_WW);
  1451. dotest(ww_test_block_try, SUCCESS, LOCKTYPE_WW);
  1452. dotest(ww_test_block_context, FAILURE, LOCKTYPE_WW);
  1453. printk("\n");
  1454. print_testname("spinlock");
  1455. dotest(ww_test_spin_block, FAILURE, LOCKTYPE_WW);
  1456. dotest(ww_test_spin_try, SUCCESS, LOCKTYPE_WW);
  1457. dotest(ww_test_spin_context, FAILURE, LOCKTYPE_WW);
  1458. printk("\n");
  1459. }
  1460. void locking_selftest(void)
  1461. {
  1462. /*
  1463. * Got a locking failure before the selftest ran?
  1464. */
  1465. if (!debug_locks) {
  1466. printk("----------------------------------\n");
  1467. printk("| Locking API testsuite disabled |\n");
  1468. printk("----------------------------------\n");
  1469. return;
  1470. }
  1471. /*
  1472. * Run the testsuite:
  1473. */
  1474. printk("------------------------\n");
  1475. printk("| Locking API testsuite:\n");
  1476. printk("----------------------------------------------------------------------------\n");
  1477. printk(" | spin |wlock |rlock |mutex | wsem | rsem |\n");
  1478. printk(" --------------------------------------------------------------------------\n");
  1479. init_shared_classes();
  1480. debug_locks_silent = !debug_locks_verbose;
  1481. DO_TESTCASE_6R("A-A deadlock", AA);
  1482. DO_TESTCASE_6R("A-B-B-A deadlock", ABBA);
  1483. DO_TESTCASE_6R("A-B-B-C-C-A deadlock", ABBCCA);
  1484. DO_TESTCASE_6R("A-B-C-A-B-C deadlock", ABCABC);
  1485. DO_TESTCASE_6R("A-B-B-C-C-D-D-A deadlock", ABBCCDDA);
  1486. DO_TESTCASE_6R("A-B-C-D-B-D-D-A deadlock", ABCDBDDA);
  1487. DO_TESTCASE_6R("A-B-C-D-B-C-D-A deadlock", ABCDBCDA);
  1488. DO_TESTCASE_6("double unlock", double_unlock);
  1489. DO_TESTCASE_6("initialize held", init_held);
  1490. DO_TESTCASE_6_SUCCESS("bad unlock order", bad_unlock_order);
  1491. printk(" --------------------------------------------------------------------------\n");
  1492. print_testname("recursive read-lock");
  1493. printk(" |");
  1494. dotest(rlock_AA1, SUCCESS, LOCKTYPE_RWLOCK);
  1495. printk(" |");
  1496. dotest(rsem_AA1, FAILURE, LOCKTYPE_RWSEM);
  1497. printk("\n");
  1498. print_testname("recursive read-lock #2");
  1499. printk(" |");
  1500. dotest(rlock_AA1B, SUCCESS, LOCKTYPE_RWLOCK);
  1501. printk(" |");
  1502. dotest(rsem_AA1B, FAILURE, LOCKTYPE_RWSEM);
  1503. printk("\n");
  1504. print_testname("mixed read-write-lock");
  1505. printk(" |");
  1506. dotest(rlock_AA2, FAILURE, LOCKTYPE_RWLOCK);
  1507. printk(" |");
  1508. dotest(rsem_AA2, FAILURE, LOCKTYPE_RWSEM);
  1509. printk("\n");
  1510. print_testname("mixed write-read-lock");
  1511. printk(" |");
  1512. dotest(rlock_AA3, FAILURE, LOCKTYPE_RWLOCK);
  1513. printk(" |");
  1514. dotest(rsem_AA3, FAILURE, LOCKTYPE_RWSEM);
  1515. printk("\n");
  1516. printk(" --------------------------------------------------------------------------\n");
  1517. /*
  1518. * irq-context testcases:
  1519. */
  1520. DO_TESTCASE_2x6("irqs-on + irq-safe-A", irqsafe1);
  1521. DO_TESTCASE_2x3("sirq-safe-A => hirqs-on", irqsafe2A);
  1522. DO_TESTCASE_2x6("safe-A + irqs-on", irqsafe2B);
  1523. DO_TESTCASE_6x6("safe-A + unsafe-B #1", irqsafe3);
  1524. DO_TESTCASE_6x6("safe-A + unsafe-B #2", irqsafe4);
  1525. DO_TESTCASE_6x6RW("irq lock-inversion", irq_inversion);
  1526. DO_TESTCASE_6x2("irq read-recursion", irq_read_recursion);
  1527. // DO_TESTCASE_6x2B("irq read-recursion #2", irq_read_recursion2);
  1528. ww_tests();
  1529. if (unexpected_testcase_failures) {
  1530. printk("-----------------------------------------------------------------\n");
  1531. debug_locks = 0;
  1532. printk("BUG: %3d unexpected failures (out of %3d) - debugging disabled! |\n",
  1533. unexpected_testcase_failures, testcase_total);
  1534. printk("-----------------------------------------------------------------\n");
  1535. } else if (expected_testcase_failures && testcase_successes) {
  1536. printk("--------------------------------------------------------\n");
  1537. printk("%3d out of %3d testcases failed, as expected. |\n",
  1538. expected_testcase_failures, testcase_total);
  1539. printk("----------------------------------------------------\n");
  1540. debug_locks = 1;
  1541. } else if (expected_testcase_failures && !testcase_successes) {
  1542. printk("--------------------------------------------------------\n");
  1543. printk("All %3d testcases failed, as expected. |\n",
  1544. expected_testcase_failures);
  1545. printk("----------------------------------------\n");
  1546. debug_locks = 1;
  1547. } else {
  1548. printk("-------------------------------------------------------\n");
  1549. printk("Good, all %3d testcases passed! |\n",
  1550. testcase_successes);
  1551. printk("---------------------------------\n");
  1552. debug_locks = 1;
  1553. }
  1554. debug_locks_silent = 0;
  1555. }