locking-selftest.c 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * lib/locking-selftest.c
  4. *
  5. * Testsuite for various locking APIs: spinlocks, rwlocks,
  6. * mutexes and rw-semaphores.
  7. *
  8. * It is checking both false positives and false negatives.
  9. *
  10. * Started by Ingo Molnar:
  11. *
  12. * Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <[email protected]>
  13. */
  14. #include <linux/rwsem.h>
  15. #include <linux/mutex.h>
  16. #include <linux/ww_mutex.h>
  17. #include <linux/sched.h>
  18. #include <linux/sched/mm.h>
  19. #include <linux/delay.h>
  20. #include <linux/lockdep.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/kallsyms.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/debug_locks.h>
  25. #include <linux/irqflags.h>
  26. #include <linux/rtmutex.h>
  27. #include <linux/local_lock.h>
  28. #ifdef CONFIG_PREEMPT_RT
  29. # define NON_RT(...)
  30. #else
  31. # define NON_RT(...) __VA_ARGS__
  32. #endif
  33. /*
  34. * Change this to 1 if you want to see the failure printouts:
  35. */
  36. static unsigned int debug_locks_verbose;
  37. unsigned int force_read_lock_recursive;
  38. static DEFINE_WD_CLASS(ww_lockdep);
  39. static int __init setup_debug_locks_verbose(char *str)
  40. {
  41. get_option(&str, &debug_locks_verbose);
  42. return 1;
  43. }
  44. __setup("debug_locks_verbose=", setup_debug_locks_verbose);
  45. #define FAILURE 0
  46. #define SUCCESS 1
  47. #define LOCKTYPE_SPIN 0x1
  48. #define LOCKTYPE_RWLOCK 0x2
  49. #define LOCKTYPE_MUTEX 0x4
  50. #define LOCKTYPE_RWSEM 0x8
  51. #define LOCKTYPE_WW 0x10
  52. #define LOCKTYPE_RTMUTEX 0x20
  53. #define LOCKTYPE_LL 0x40
  54. #define LOCKTYPE_SPECIAL 0x80
  55. static struct ww_acquire_ctx t, t2;
  56. static struct ww_mutex o, o2, o3;
  57. /*
  58. * Normal standalone locks, for the circular and irq-context
  59. * dependency tests:
  60. */
  61. static DEFINE_SPINLOCK(lock_A);
  62. static DEFINE_SPINLOCK(lock_B);
  63. static DEFINE_SPINLOCK(lock_C);
  64. static DEFINE_SPINLOCK(lock_D);
  65. static DEFINE_RAW_SPINLOCK(raw_lock_A);
  66. static DEFINE_RAW_SPINLOCK(raw_lock_B);
  67. static DEFINE_RWLOCK(rwlock_A);
  68. static DEFINE_RWLOCK(rwlock_B);
  69. static DEFINE_RWLOCK(rwlock_C);
  70. static DEFINE_RWLOCK(rwlock_D);
  71. static DEFINE_MUTEX(mutex_A);
  72. static DEFINE_MUTEX(mutex_B);
  73. static DEFINE_MUTEX(mutex_C);
  74. static DEFINE_MUTEX(mutex_D);
  75. static DECLARE_RWSEM(rwsem_A);
  76. static DECLARE_RWSEM(rwsem_B);
  77. static DECLARE_RWSEM(rwsem_C);
  78. static DECLARE_RWSEM(rwsem_D);
  79. #ifdef CONFIG_RT_MUTEXES
  80. static DEFINE_RT_MUTEX(rtmutex_A);
  81. static DEFINE_RT_MUTEX(rtmutex_B);
  82. static DEFINE_RT_MUTEX(rtmutex_C);
  83. static DEFINE_RT_MUTEX(rtmutex_D);
  84. #endif
  85. /*
  86. * Locks that we initialize dynamically as well so that
  87. * e.g. X1 and X2 becomes two instances of the same class,
  88. * but X* and Y* are different classes. We do this so that
  89. * we do not trigger a real lockup:
  90. */
  91. static DEFINE_SPINLOCK(lock_X1);
  92. static DEFINE_SPINLOCK(lock_X2);
  93. static DEFINE_SPINLOCK(lock_Y1);
  94. static DEFINE_SPINLOCK(lock_Y2);
  95. static DEFINE_SPINLOCK(lock_Z1);
  96. static DEFINE_SPINLOCK(lock_Z2);
  97. static DEFINE_RWLOCK(rwlock_X1);
  98. static DEFINE_RWLOCK(rwlock_X2);
  99. static DEFINE_RWLOCK(rwlock_Y1);
  100. static DEFINE_RWLOCK(rwlock_Y2);
  101. static DEFINE_RWLOCK(rwlock_Z1);
  102. static DEFINE_RWLOCK(rwlock_Z2);
  103. static DEFINE_MUTEX(mutex_X1);
  104. static DEFINE_MUTEX(mutex_X2);
  105. static DEFINE_MUTEX(mutex_Y1);
  106. static DEFINE_MUTEX(mutex_Y2);
  107. static DEFINE_MUTEX(mutex_Z1);
  108. static DEFINE_MUTEX(mutex_Z2);
  109. static DECLARE_RWSEM(rwsem_X1);
  110. static DECLARE_RWSEM(rwsem_X2);
  111. static DECLARE_RWSEM(rwsem_Y1);
  112. static DECLARE_RWSEM(rwsem_Y2);
  113. static DECLARE_RWSEM(rwsem_Z1);
  114. static DECLARE_RWSEM(rwsem_Z2);
  115. #ifdef CONFIG_RT_MUTEXES
  116. static DEFINE_RT_MUTEX(rtmutex_X1);
  117. static DEFINE_RT_MUTEX(rtmutex_X2);
  118. static DEFINE_RT_MUTEX(rtmutex_Y1);
  119. static DEFINE_RT_MUTEX(rtmutex_Y2);
  120. static DEFINE_RT_MUTEX(rtmutex_Z1);
  121. static DEFINE_RT_MUTEX(rtmutex_Z2);
  122. #endif
  123. static DEFINE_PER_CPU(local_lock_t, local_A);
  124. /*
  125. * non-inlined runtime initializers, to let separate locks share
  126. * the same lock-class:
  127. */
  128. #define INIT_CLASS_FUNC(class) \
  129. static noinline void \
  130. init_class_##class(spinlock_t *lock, rwlock_t *rwlock, \
  131. struct mutex *mutex, struct rw_semaphore *rwsem)\
  132. { \
  133. spin_lock_init(lock); \
  134. rwlock_init(rwlock); \
  135. mutex_init(mutex); \
  136. init_rwsem(rwsem); \
  137. }
  138. INIT_CLASS_FUNC(X)
  139. INIT_CLASS_FUNC(Y)
  140. INIT_CLASS_FUNC(Z)
  141. static void init_shared_classes(void)
  142. {
  143. #ifdef CONFIG_RT_MUTEXES
  144. static struct lock_class_key rt_X, rt_Y, rt_Z;
  145. __rt_mutex_init(&rtmutex_X1, __func__, &rt_X);
  146. __rt_mutex_init(&rtmutex_X2, __func__, &rt_X);
  147. __rt_mutex_init(&rtmutex_Y1, __func__, &rt_Y);
  148. __rt_mutex_init(&rtmutex_Y2, __func__, &rt_Y);
  149. __rt_mutex_init(&rtmutex_Z1, __func__, &rt_Z);
  150. __rt_mutex_init(&rtmutex_Z2, __func__, &rt_Z);
  151. #endif
  152. init_class_X(&lock_X1, &rwlock_X1, &mutex_X1, &rwsem_X1);
  153. init_class_X(&lock_X2, &rwlock_X2, &mutex_X2, &rwsem_X2);
  154. init_class_Y(&lock_Y1, &rwlock_Y1, &mutex_Y1, &rwsem_Y1);
  155. init_class_Y(&lock_Y2, &rwlock_Y2, &mutex_Y2, &rwsem_Y2);
  156. init_class_Z(&lock_Z1, &rwlock_Z1, &mutex_Z1, &rwsem_Z1);
  157. init_class_Z(&lock_Z2, &rwlock_Z2, &mutex_Z2, &rwsem_Z2);
  158. }
  159. /*
  160. * For spinlocks and rwlocks we also do hardirq-safe / softirq-safe tests.
  161. * The following functions use a lock from a simulated hardirq/softirq
  162. * context, causing the locks to be marked as hardirq-safe/softirq-safe:
  163. */
  164. #define HARDIRQ_DISABLE local_irq_disable
  165. #define HARDIRQ_ENABLE local_irq_enable
  166. #define HARDIRQ_ENTER() \
  167. local_irq_disable(); \
  168. __irq_enter(); \
  169. lockdep_hardirq_threaded(); \
  170. WARN_ON(!in_irq());
  171. #define HARDIRQ_EXIT() \
  172. __irq_exit(); \
  173. local_irq_enable();
  174. #define SOFTIRQ_DISABLE local_bh_disable
  175. #define SOFTIRQ_ENABLE local_bh_enable
  176. #define SOFTIRQ_ENTER() \
  177. local_bh_disable(); \
  178. local_irq_disable(); \
  179. lockdep_softirq_enter(); \
  180. WARN_ON(!in_softirq());
  181. #define SOFTIRQ_EXIT() \
  182. lockdep_softirq_exit(); \
  183. local_irq_enable(); \
  184. local_bh_enable();
  185. /*
  186. * Shortcuts for lock/unlock API variants, to keep
  187. * the testcases compact:
  188. */
  189. #define L(x) spin_lock(&lock_##x)
  190. #define U(x) spin_unlock(&lock_##x)
  191. #define LU(x) L(x); U(x)
  192. #define SI(x) spin_lock_init(&lock_##x)
  193. #define WL(x) write_lock(&rwlock_##x)
  194. #define WU(x) write_unlock(&rwlock_##x)
  195. #define WLU(x) WL(x); WU(x)
  196. #define RL(x) read_lock(&rwlock_##x)
  197. #define RU(x) read_unlock(&rwlock_##x)
  198. #define RLU(x) RL(x); RU(x)
  199. #define RWI(x) rwlock_init(&rwlock_##x)
  200. #define ML(x) mutex_lock(&mutex_##x)
  201. #define MU(x) mutex_unlock(&mutex_##x)
  202. #define MI(x) mutex_init(&mutex_##x)
  203. #define RTL(x) rt_mutex_lock(&rtmutex_##x)
  204. #define RTU(x) rt_mutex_unlock(&rtmutex_##x)
  205. #define RTI(x) rt_mutex_init(&rtmutex_##x)
  206. #define WSL(x) down_write(&rwsem_##x)
  207. #define WSU(x) up_write(&rwsem_##x)
  208. #define RSL(x) down_read(&rwsem_##x)
  209. #define RSU(x) up_read(&rwsem_##x)
  210. #define RWSI(x) init_rwsem(&rwsem_##x)
  211. #ifndef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
  212. #define WWAI(x) ww_acquire_init(x, &ww_lockdep)
  213. #else
  214. #define WWAI(x) do { ww_acquire_init(x, &ww_lockdep); (x)->deadlock_inject_countdown = ~0U; } while (0)
  215. #endif
  216. #define WWAD(x) ww_acquire_done(x)
  217. #define WWAF(x) ww_acquire_fini(x)
  218. #define WWL(x, c) ww_mutex_lock(x, c)
  219. #define WWT(x) ww_mutex_trylock(x, NULL)
  220. #define WWL1(x) ww_mutex_lock(x, NULL)
  221. #define WWU(x) ww_mutex_unlock(x)
  222. #define LOCK_UNLOCK_2(x,y) LOCK(x); LOCK(y); UNLOCK(y); UNLOCK(x)
  223. /*
  224. * Generate different permutations of the same testcase, using
  225. * the same basic lock-dependency/state events:
  226. */
  227. #define GENERATE_TESTCASE(name) \
  228. \
  229. static void name(void) { E(); }
  230. #define GENERATE_PERMUTATIONS_2_EVENTS(name) \
  231. \
  232. static void name##_12(void) { E1(); E2(); } \
  233. static void name##_21(void) { E2(); E1(); }
  234. #define GENERATE_PERMUTATIONS_3_EVENTS(name) \
  235. \
  236. static void name##_123(void) { E1(); E2(); E3(); } \
  237. static void name##_132(void) { E1(); E3(); E2(); } \
  238. static void name##_213(void) { E2(); E1(); E3(); } \
  239. static void name##_231(void) { E2(); E3(); E1(); } \
  240. static void name##_312(void) { E3(); E1(); E2(); } \
  241. static void name##_321(void) { E3(); E2(); E1(); }
  242. /*
  243. * AA deadlock:
  244. */
  245. #define E() \
  246. \
  247. LOCK(X1); \
  248. LOCK(X2); /* this one should fail */
  249. /*
  250. * 6 testcases:
  251. */
  252. #include "locking-selftest-spin.h"
  253. GENERATE_TESTCASE(AA_spin)
  254. #include "locking-selftest-wlock.h"
  255. GENERATE_TESTCASE(AA_wlock)
  256. #include "locking-selftest-rlock.h"
  257. GENERATE_TESTCASE(AA_rlock)
  258. #include "locking-selftest-mutex.h"
  259. GENERATE_TESTCASE(AA_mutex)
  260. #include "locking-selftest-wsem.h"
  261. GENERATE_TESTCASE(AA_wsem)
  262. #include "locking-selftest-rsem.h"
  263. GENERATE_TESTCASE(AA_rsem)
  264. #ifdef CONFIG_RT_MUTEXES
  265. #include "locking-selftest-rtmutex.h"
  266. GENERATE_TESTCASE(AA_rtmutex);
  267. #endif
  268. #undef E
  269. /*
  270. * Special-case for read-locking, they are
  271. * allowed to recurse on the same lock class:
  272. */
  273. static void rlock_AA1(void)
  274. {
  275. RL(X1);
  276. RL(X1); // this one should NOT fail
  277. }
  278. static void rlock_AA1B(void)
  279. {
  280. RL(X1);
  281. RL(X2); // this one should NOT fail
  282. }
  283. static void rsem_AA1(void)
  284. {
  285. RSL(X1);
  286. RSL(X1); // this one should fail
  287. }
  288. static void rsem_AA1B(void)
  289. {
  290. RSL(X1);
  291. RSL(X2); // this one should fail
  292. }
  293. /*
  294. * The mixing of read and write locks is not allowed:
  295. */
  296. static void rlock_AA2(void)
  297. {
  298. RL(X1);
  299. WL(X2); // this one should fail
  300. }
  301. static void rsem_AA2(void)
  302. {
  303. RSL(X1);
  304. WSL(X2); // this one should fail
  305. }
  306. static void rlock_AA3(void)
  307. {
  308. WL(X1);
  309. RL(X2); // this one should fail
  310. }
  311. static void rsem_AA3(void)
  312. {
  313. WSL(X1);
  314. RSL(X2); // this one should fail
  315. }
  316. /*
  317. * read_lock(A)
  318. * spin_lock(B)
  319. * spin_lock(B)
  320. * write_lock(A)
  321. */
  322. static void rlock_ABBA1(void)
  323. {
  324. RL(X1);
  325. L(Y1);
  326. U(Y1);
  327. RU(X1);
  328. L(Y1);
  329. WL(X1);
  330. WU(X1);
  331. U(Y1); // should fail
  332. }
  333. static void rwsem_ABBA1(void)
  334. {
  335. RSL(X1);
  336. ML(Y1);
  337. MU(Y1);
  338. RSU(X1);
  339. ML(Y1);
  340. WSL(X1);
  341. WSU(X1);
  342. MU(Y1); // should fail
  343. }
  344. /*
  345. * read_lock(A)
  346. * spin_lock(B)
  347. * spin_lock(B)
  348. * write_lock(A)
  349. *
  350. * This test case is aimed at poking whether the chain cache prevents us from
  351. * detecting a read-lock/lock-write deadlock: if the chain cache doesn't differ
  352. * read/write locks, the following case may happen
  353. *
  354. * { read_lock(A)->lock(B) dependency exists }
  355. *
  356. * P0:
  357. * lock(B);
  358. * read_lock(A);
  359. *
  360. * { Not a deadlock, B -> A is added in the chain cache }
  361. *
  362. * P1:
  363. * lock(B);
  364. * write_lock(A);
  365. *
  366. * { B->A found in chain cache, not reported as a deadlock }
  367. *
  368. */
  369. static void rlock_chaincache_ABBA1(void)
  370. {
  371. RL(X1);
  372. L(Y1);
  373. U(Y1);
  374. RU(X1);
  375. L(Y1);
  376. RL(X1);
  377. RU(X1);
  378. U(Y1);
  379. L(Y1);
  380. WL(X1);
  381. WU(X1);
  382. U(Y1); // should fail
  383. }
  384. /*
  385. * read_lock(A)
  386. * spin_lock(B)
  387. * spin_lock(B)
  388. * read_lock(A)
  389. */
  390. static void rlock_ABBA2(void)
  391. {
  392. RL(X1);
  393. L(Y1);
  394. U(Y1);
  395. RU(X1);
  396. L(Y1);
  397. RL(X1);
  398. RU(X1);
  399. U(Y1); // should NOT fail
  400. }
  401. static void rwsem_ABBA2(void)
  402. {
  403. RSL(X1);
  404. ML(Y1);
  405. MU(Y1);
  406. RSU(X1);
  407. ML(Y1);
  408. RSL(X1);
  409. RSU(X1);
  410. MU(Y1); // should fail
  411. }
  412. /*
  413. * write_lock(A)
  414. * spin_lock(B)
  415. * spin_lock(B)
  416. * write_lock(A)
  417. */
  418. static void rlock_ABBA3(void)
  419. {
  420. WL(X1);
  421. L(Y1);
  422. U(Y1);
  423. WU(X1);
  424. L(Y1);
  425. WL(X1);
  426. WU(X1);
  427. U(Y1); // should fail
  428. }
  429. static void rwsem_ABBA3(void)
  430. {
  431. WSL(X1);
  432. ML(Y1);
  433. MU(Y1);
  434. WSU(X1);
  435. ML(Y1);
  436. WSL(X1);
  437. WSU(X1);
  438. MU(Y1); // should fail
  439. }
  440. /*
  441. * ABBA deadlock:
  442. */
  443. #define E() \
  444. \
  445. LOCK_UNLOCK_2(A, B); \
  446. LOCK_UNLOCK_2(B, A); /* fail */
  447. /*
  448. * 6 testcases:
  449. */
  450. #include "locking-selftest-spin.h"
  451. GENERATE_TESTCASE(ABBA_spin)
  452. #include "locking-selftest-wlock.h"
  453. GENERATE_TESTCASE(ABBA_wlock)
  454. #include "locking-selftest-rlock.h"
  455. GENERATE_TESTCASE(ABBA_rlock)
  456. #include "locking-selftest-mutex.h"
  457. GENERATE_TESTCASE(ABBA_mutex)
  458. #include "locking-selftest-wsem.h"
  459. GENERATE_TESTCASE(ABBA_wsem)
  460. #include "locking-selftest-rsem.h"
  461. GENERATE_TESTCASE(ABBA_rsem)
  462. #ifdef CONFIG_RT_MUTEXES
  463. #include "locking-selftest-rtmutex.h"
  464. GENERATE_TESTCASE(ABBA_rtmutex);
  465. #endif
  466. #undef E
  467. /*
  468. * AB BC CA deadlock:
  469. */
  470. #define E() \
  471. \
  472. LOCK_UNLOCK_2(A, B); \
  473. LOCK_UNLOCK_2(B, C); \
  474. LOCK_UNLOCK_2(C, A); /* fail */
  475. /*
  476. * 6 testcases:
  477. */
  478. #include "locking-selftest-spin.h"
  479. GENERATE_TESTCASE(ABBCCA_spin)
  480. #include "locking-selftest-wlock.h"
  481. GENERATE_TESTCASE(ABBCCA_wlock)
  482. #include "locking-selftest-rlock.h"
  483. GENERATE_TESTCASE(ABBCCA_rlock)
  484. #include "locking-selftest-mutex.h"
  485. GENERATE_TESTCASE(ABBCCA_mutex)
  486. #include "locking-selftest-wsem.h"
  487. GENERATE_TESTCASE(ABBCCA_wsem)
  488. #include "locking-selftest-rsem.h"
  489. GENERATE_TESTCASE(ABBCCA_rsem)
  490. #ifdef CONFIG_RT_MUTEXES
  491. #include "locking-selftest-rtmutex.h"
  492. GENERATE_TESTCASE(ABBCCA_rtmutex);
  493. #endif
  494. #undef E
  495. /*
  496. * AB CA BC deadlock:
  497. */
  498. #define E() \
  499. \
  500. LOCK_UNLOCK_2(A, B); \
  501. LOCK_UNLOCK_2(C, A); \
  502. LOCK_UNLOCK_2(B, C); /* fail */
  503. /*
  504. * 6 testcases:
  505. */
  506. #include "locking-selftest-spin.h"
  507. GENERATE_TESTCASE(ABCABC_spin)
  508. #include "locking-selftest-wlock.h"
  509. GENERATE_TESTCASE(ABCABC_wlock)
  510. #include "locking-selftest-rlock.h"
  511. GENERATE_TESTCASE(ABCABC_rlock)
  512. #include "locking-selftest-mutex.h"
  513. GENERATE_TESTCASE(ABCABC_mutex)
  514. #include "locking-selftest-wsem.h"
  515. GENERATE_TESTCASE(ABCABC_wsem)
  516. #include "locking-selftest-rsem.h"
  517. GENERATE_TESTCASE(ABCABC_rsem)
  518. #ifdef CONFIG_RT_MUTEXES
  519. #include "locking-selftest-rtmutex.h"
  520. GENERATE_TESTCASE(ABCABC_rtmutex);
  521. #endif
  522. #undef E
  523. /*
  524. * AB BC CD DA deadlock:
  525. */
  526. #define E() \
  527. \
  528. LOCK_UNLOCK_2(A, B); \
  529. LOCK_UNLOCK_2(B, C); \
  530. LOCK_UNLOCK_2(C, D); \
  531. LOCK_UNLOCK_2(D, A); /* fail */
  532. /*
  533. * 6 testcases:
  534. */
  535. #include "locking-selftest-spin.h"
  536. GENERATE_TESTCASE(ABBCCDDA_spin)
  537. #include "locking-selftest-wlock.h"
  538. GENERATE_TESTCASE(ABBCCDDA_wlock)
  539. #include "locking-selftest-rlock.h"
  540. GENERATE_TESTCASE(ABBCCDDA_rlock)
  541. #include "locking-selftest-mutex.h"
  542. GENERATE_TESTCASE(ABBCCDDA_mutex)
  543. #include "locking-selftest-wsem.h"
  544. GENERATE_TESTCASE(ABBCCDDA_wsem)
  545. #include "locking-selftest-rsem.h"
  546. GENERATE_TESTCASE(ABBCCDDA_rsem)
  547. #ifdef CONFIG_RT_MUTEXES
  548. #include "locking-selftest-rtmutex.h"
  549. GENERATE_TESTCASE(ABBCCDDA_rtmutex);
  550. #endif
  551. #undef E
  552. /*
  553. * AB CD BD DA deadlock:
  554. */
  555. #define E() \
  556. \
  557. LOCK_UNLOCK_2(A, B); \
  558. LOCK_UNLOCK_2(C, D); \
  559. LOCK_UNLOCK_2(B, D); \
  560. LOCK_UNLOCK_2(D, A); /* fail */
  561. /*
  562. * 6 testcases:
  563. */
  564. #include "locking-selftest-spin.h"
  565. GENERATE_TESTCASE(ABCDBDDA_spin)
  566. #include "locking-selftest-wlock.h"
  567. GENERATE_TESTCASE(ABCDBDDA_wlock)
  568. #include "locking-selftest-rlock.h"
  569. GENERATE_TESTCASE(ABCDBDDA_rlock)
  570. #include "locking-selftest-mutex.h"
  571. GENERATE_TESTCASE(ABCDBDDA_mutex)
  572. #include "locking-selftest-wsem.h"
  573. GENERATE_TESTCASE(ABCDBDDA_wsem)
  574. #include "locking-selftest-rsem.h"
  575. GENERATE_TESTCASE(ABCDBDDA_rsem)
  576. #ifdef CONFIG_RT_MUTEXES
  577. #include "locking-selftest-rtmutex.h"
  578. GENERATE_TESTCASE(ABCDBDDA_rtmutex);
  579. #endif
  580. #undef E
  581. /*
  582. * AB CD BC DA deadlock:
  583. */
  584. #define E() \
  585. \
  586. LOCK_UNLOCK_2(A, B); \
  587. LOCK_UNLOCK_2(C, D); \
  588. LOCK_UNLOCK_2(B, C); \
  589. LOCK_UNLOCK_2(D, A); /* fail */
  590. /*
  591. * 6 testcases:
  592. */
  593. #include "locking-selftest-spin.h"
  594. GENERATE_TESTCASE(ABCDBCDA_spin)
  595. #include "locking-selftest-wlock.h"
  596. GENERATE_TESTCASE(ABCDBCDA_wlock)
  597. #include "locking-selftest-rlock.h"
  598. GENERATE_TESTCASE(ABCDBCDA_rlock)
  599. #include "locking-selftest-mutex.h"
  600. GENERATE_TESTCASE(ABCDBCDA_mutex)
  601. #include "locking-selftest-wsem.h"
  602. GENERATE_TESTCASE(ABCDBCDA_wsem)
  603. #include "locking-selftest-rsem.h"
  604. GENERATE_TESTCASE(ABCDBCDA_rsem)
  605. #ifdef CONFIG_RT_MUTEXES
  606. #include "locking-selftest-rtmutex.h"
  607. GENERATE_TESTCASE(ABCDBCDA_rtmutex);
  608. #endif
  609. #undef E
  610. #ifdef CONFIG_PREEMPT_RT
  611. # define RT_PREPARE_DBL_UNLOCK() { migrate_disable(); rcu_read_lock(); }
  612. #else
  613. # define RT_PREPARE_DBL_UNLOCK()
  614. #endif
  615. /*
  616. * Double unlock:
  617. */
  618. #define E() \
  619. \
  620. LOCK(A); \
  621. RT_PREPARE_DBL_UNLOCK(); \
  622. UNLOCK(A); \
  623. UNLOCK(A); /* fail */
  624. /*
  625. * 6 testcases:
  626. */
  627. #include "locking-selftest-spin.h"
  628. GENERATE_TESTCASE(double_unlock_spin)
  629. #include "locking-selftest-wlock.h"
  630. GENERATE_TESTCASE(double_unlock_wlock)
  631. #include "locking-selftest-rlock.h"
  632. GENERATE_TESTCASE(double_unlock_rlock)
  633. #include "locking-selftest-mutex.h"
  634. GENERATE_TESTCASE(double_unlock_mutex)
  635. #include "locking-selftest-wsem.h"
  636. GENERATE_TESTCASE(double_unlock_wsem)
  637. #include "locking-selftest-rsem.h"
  638. GENERATE_TESTCASE(double_unlock_rsem)
  639. #ifdef CONFIG_RT_MUTEXES
  640. #include "locking-selftest-rtmutex.h"
  641. GENERATE_TESTCASE(double_unlock_rtmutex);
  642. #endif
  643. #undef E
  644. /*
  645. * initializing a held lock:
  646. */
  647. #define E() \
  648. \
  649. LOCK(A); \
  650. INIT(A); /* fail */
  651. /*
  652. * 6 testcases:
  653. */
  654. #include "locking-selftest-spin.h"
  655. GENERATE_TESTCASE(init_held_spin)
  656. #include "locking-selftest-wlock.h"
  657. GENERATE_TESTCASE(init_held_wlock)
  658. #include "locking-selftest-rlock.h"
  659. GENERATE_TESTCASE(init_held_rlock)
  660. #include "locking-selftest-mutex.h"
  661. GENERATE_TESTCASE(init_held_mutex)
  662. #include "locking-selftest-wsem.h"
  663. GENERATE_TESTCASE(init_held_wsem)
  664. #include "locking-selftest-rsem.h"
  665. GENERATE_TESTCASE(init_held_rsem)
  666. #ifdef CONFIG_RT_MUTEXES
  667. #include "locking-selftest-rtmutex.h"
  668. GENERATE_TESTCASE(init_held_rtmutex);
  669. #endif
  670. #undef E
  671. /*
  672. * locking an irq-safe lock with irqs enabled:
  673. */
  674. #define E1() \
  675. \
  676. IRQ_ENTER(); \
  677. LOCK(A); \
  678. UNLOCK(A); \
  679. IRQ_EXIT();
  680. #define E2() \
  681. \
  682. LOCK(A); \
  683. UNLOCK(A);
  684. /*
  685. * Generate 24 testcases:
  686. */
  687. #include "locking-selftest-spin-hardirq.h"
  688. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_hard_spin)
  689. #include "locking-selftest-rlock-hardirq.h"
  690. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_hard_rlock)
  691. #include "locking-selftest-wlock-hardirq.h"
  692. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_hard_wlock)
  693. #ifndef CONFIG_PREEMPT_RT
  694. #include "locking-selftest-spin-softirq.h"
  695. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_soft_spin)
  696. #include "locking-selftest-rlock-softirq.h"
  697. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_soft_rlock)
  698. #include "locking-selftest-wlock-softirq.h"
  699. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_soft_wlock)
  700. #endif
  701. #undef E1
  702. #undef E2
  703. #ifndef CONFIG_PREEMPT_RT
  704. /*
  705. * Enabling hardirqs with a softirq-safe lock held:
  706. */
  707. #define E1() \
  708. \
  709. SOFTIRQ_ENTER(); \
  710. LOCK(A); \
  711. UNLOCK(A); \
  712. SOFTIRQ_EXIT();
  713. #define E2() \
  714. \
  715. HARDIRQ_DISABLE(); \
  716. LOCK(A); \
  717. HARDIRQ_ENABLE(); \
  718. UNLOCK(A);
  719. /*
  720. * Generate 12 testcases:
  721. */
  722. #include "locking-selftest-spin.h"
  723. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2A_spin)
  724. #include "locking-selftest-wlock.h"
  725. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2A_wlock)
  726. #include "locking-selftest-rlock.h"
  727. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2A_rlock)
  728. #undef E1
  729. #undef E2
  730. #endif
  731. /*
  732. * Enabling irqs with an irq-safe lock held:
  733. */
  734. #define E1() \
  735. \
  736. IRQ_ENTER(); \
  737. LOCK(A); \
  738. UNLOCK(A); \
  739. IRQ_EXIT();
  740. #define E2() \
  741. \
  742. IRQ_DISABLE(); \
  743. LOCK(A); \
  744. IRQ_ENABLE(); \
  745. UNLOCK(A);
  746. /*
  747. * Generate 24 testcases:
  748. */
  749. #include "locking-selftest-spin-hardirq.h"
  750. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_hard_spin)
  751. #include "locking-selftest-rlock-hardirq.h"
  752. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_hard_rlock)
  753. #include "locking-selftest-wlock-hardirq.h"
  754. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_hard_wlock)
  755. #ifndef CONFIG_PREEMPT_RT
  756. #include "locking-selftest-spin-softirq.h"
  757. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_soft_spin)
  758. #include "locking-selftest-rlock-softirq.h"
  759. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_soft_rlock)
  760. #include "locking-selftest-wlock-softirq.h"
  761. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_soft_wlock)
  762. #endif
  763. #undef E1
  764. #undef E2
  765. /*
  766. * Acquiring a irq-unsafe lock while holding an irq-safe-lock:
  767. */
  768. #define E1() \
  769. \
  770. LOCK(A); \
  771. LOCK(B); \
  772. UNLOCK(B); \
  773. UNLOCK(A); \
  774. #define E2() \
  775. \
  776. LOCK(B); \
  777. UNLOCK(B);
  778. #define E3() \
  779. \
  780. IRQ_ENTER(); \
  781. LOCK(A); \
  782. UNLOCK(A); \
  783. IRQ_EXIT();
  784. /*
  785. * Generate 36 testcases:
  786. */
  787. #include "locking-selftest-spin-hardirq.h"
  788. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_hard_spin)
  789. #include "locking-selftest-rlock-hardirq.h"
  790. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_hard_rlock)
  791. #include "locking-selftest-wlock-hardirq.h"
  792. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_hard_wlock)
  793. #ifndef CONFIG_PREEMPT_RT
  794. #include "locking-selftest-spin-softirq.h"
  795. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_soft_spin)
  796. #include "locking-selftest-rlock-softirq.h"
  797. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_soft_rlock)
  798. #include "locking-selftest-wlock-softirq.h"
  799. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_soft_wlock)
  800. #endif
  801. #undef E1
  802. #undef E2
  803. #undef E3
  804. /*
  805. * If a lock turns into softirq-safe, but earlier it took
  806. * a softirq-unsafe lock:
  807. */
  808. #define E1() \
  809. IRQ_DISABLE(); \
  810. LOCK(A); \
  811. LOCK(B); \
  812. UNLOCK(B); \
  813. UNLOCK(A); \
  814. IRQ_ENABLE();
  815. #define E2() \
  816. LOCK(B); \
  817. UNLOCK(B);
  818. #define E3() \
  819. IRQ_ENTER(); \
  820. LOCK(A); \
  821. UNLOCK(A); \
  822. IRQ_EXIT();
  823. /*
  824. * Generate 36 testcases:
  825. */
  826. #include "locking-selftest-spin-hardirq.h"
  827. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_hard_spin)
  828. #include "locking-selftest-rlock-hardirq.h"
  829. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_hard_rlock)
  830. #include "locking-selftest-wlock-hardirq.h"
  831. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_hard_wlock)
  832. #ifndef CONFIG_PREEMPT_RT
  833. #include "locking-selftest-spin-softirq.h"
  834. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_soft_spin)
  835. #include "locking-selftest-rlock-softirq.h"
  836. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_soft_rlock)
  837. #include "locking-selftest-wlock-softirq.h"
  838. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_soft_wlock)
  839. #endif
  840. #undef E1
  841. #undef E2
  842. #undef E3
  843. /*
  844. * read-lock / write-lock irq inversion.
  845. *
  846. * Deadlock scenario:
  847. *
  848. * CPU#1 is at #1, i.e. it has write-locked A, but has not
  849. * taken B yet.
  850. *
  851. * CPU#2 is at #2, i.e. it has locked B.
  852. *
  853. * Hardirq hits CPU#2 at point #2 and is trying to read-lock A.
  854. *
  855. * The deadlock occurs because CPU#1 will spin on B, and CPU#2
  856. * will spin on A.
  857. */
  858. #define E1() \
  859. \
  860. IRQ_DISABLE(); \
  861. WL(A); \
  862. LOCK(B); \
  863. UNLOCK(B); \
  864. WU(A); \
  865. IRQ_ENABLE();
  866. #define E2() \
  867. \
  868. LOCK(B); \
  869. UNLOCK(B);
  870. #define E3() \
  871. \
  872. IRQ_ENTER(); \
  873. RL(A); \
  874. RU(A); \
  875. IRQ_EXIT();
  876. /*
  877. * Generate 36 testcases:
  878. */
  879. #include "locking-selftest-spin-hardirq.h"
  880. GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_hard_spin)
  881. #include "locking-selftest-rlock-hardirq.h"
  882. GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_hard_rlock)
  883. #include "locking-selftest-wlock-hardirq.h"
  884. GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_hard_wlock)
  885. #ifndef CONFIG_PREEMPT_RT
  886. #include "locking-selftest-spin-softirq.h"
  887. GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_soft_spin)
  888. #include "locking-selftest-rlock-softirq.h"
  889. GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_soft_rlock)
  890. #include "locking-selftest-wlock-softirq.h"
  891. GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_soft_wlock)
  892. #endif
  893. #undef E1
  894. #undef E2
  895. #undef E3
  896. /*
  897. * write-read / write-read / write-read deadlock even if read is recursive
  898. */
  899. #define E1() \
  900. \
  901. WL(X1); \
  902. RL(Y1); \
  903. RU(Y1); \
  904. WU(X1);
  905. #define E2() \
  906. \
  907. WL(Y1); \
  908. RL(Z1); \
  909. RU(Z1); \
  910. WU(Y1);
  911. #define E3() \
  912. \
  913. WL(Z1); \
  914. RL(X1); \
  915. RU(X1); \
  916. WU(Z1);
  917. #include "locking-selftest-rlock.h"
  918. GENERATE_PERMUTATIONS_3_EVENTS(W1R2_W2R3_W3R1)
  919. #undef E1
  920. #undef E2
  921. #undef E3
  922. /*
  923. * write-write / read-read / write-read deadlock even if read is recursive
  924. */
  925. #define E1() \
  926. \
  927. WL(X1); \
  928. WL(Y1); \
  929. WU(Y1); \
  930. WU(X1);
  931. #define E2() \
  932. \
  933. RL(Y1); \
  934. RL(Z1); \
  935. RU(Z1); \
  936. RU(Y1);
  937. #define E3() \
  938. \
  939. WL(Z1); \
  940. RL(X1); \
  941. RU(X1); \
  942. WU(Z1);
  943. #include "locking-selftest-rlock.h"
  944. GENERATE_PERMUTATIONS_3_EVENTS(W1W2_R2R3_W3R1)
  945. #undef E1
  946. #undef E2
  947. #undef E3
  948. /*
  949. * write-write / read-read / read-write is not deadlock when read is recursive
  950. */
  951. #define E1() \
  952. \
  953. WL(X1); \
  954. WL(Y1); \
  955. WU(Y1); \
  956. WU(X1);
  957. #define E2() \
  958. \
  959. RL(Y1); \
  960. RL(Z1); \
  961. RU(Z1); \
  962. RU(Y1);
  963. #define E3() \
  964. \
  965. RL(Z1); \
  966. WL(X1); \
  967. WU(X1); \
  968. RU(Z1);
  969. #include "locking-selftest-rlock.h"
  970. GENERATE_PERMUTATIONS_3_EVENTS(W1R2_R2R3_W3W1)
  971. #undef E1
  972. #undef E2
  973. #undef E3
  974. /*
  975. * write-read / read-read / write-write is not deadlock when read is recursive
  976. */
  977. #define E1() \
  978. \
  979. WL(X1); \
  980. RL(Y1); \
  981. RU(Y1); \
  982. WU(X1);
  983. #define E2() \
  984. \
  985. RL(Y1); \
  986. RL(Z1); \
  987. RU(Z1); \
  988. RU(Y1);
  989. #define E3() \
  990. \
  991. WL(Z1); \
  992. WL(X1); \
  993. WU(X1); \
  994. WU(Z1);
  995. #include "locking-selftest-rlock.h"
  996. GENERATE_PERMUTATIONS_3_EVENTS(W1W2_R2R3_R3W1)
  997. #undef E1
  998. #undef E2
  999. #undef E3
  1000. /*
  1001. * read-lock / write-lock recursion that is actually safe.
  1002. */
  1003. #define E1() \
  1004. \
  1005. IRQ_DISABLE(); \
  1006. WL(A); \
  1007. WU(A); \
  1008. IRQ_ENABLE();
  1009. #define E2() \
  1010. \
  1011. RL(A); \
  1012. RU(A); \
  1013. #define E3() \
  1014. \
  1015. IRQ_ENTER(); \
  1016. LOCK(A); \
  1017. L(B); \
  1018. U(B); \
  1019. UNLOCK(A); \
  1020. IRQ_EXIT();
  1021. /*
  1022. * Generate 24 testcases:
  1023. */
  1024. #include "locking-selftest-hardirq.h"
  1025. #include "locking-selftest-rlock.h"
  1026. GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion_hard_rlock)
  1027. #include "locking-selftest-wlock.h"
  1028. GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion_hard_wlock)
  1029. #ifndef CONFIG_PREEMPT_RT
  1030. #include "locking-selftest-softirq.h"
  1031. #include "locking-selftest-rlock.h"
  1032. GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion_soft_rlock)
  1033. #include "locking-selftest-wlock.h"
  1034. GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion_soft_wlock)
  1035. #endif
  1036. #undef E1
  1037. #undef E2
  1038. #undef E3
  1039. /*
  1040. * read-lock / write-lock recursion that is unsafe.
  1041. */
  1042. #define E1() \
  1043. \
  1044. IRQ_DISABLE(); \
  1045. L(B); \
  1046. LOCK(A); \
  1047. UNLOCK(A); \
  1048. U(B); \
  1049. IRQ_ENABLE();
  1050. #define E2() \
  1051. \
  1052. RL(A); \
  1053. RU(A); \
  1054. #define E3() \
  1055. \
  1056. IRQ_ENTER(); \
  1057. L(B); \
  1058. U(B); \
  1059. IRQ_EXIT();
  1060. /*
  1061. * Generate 24 testcases:
  1062. */
  1063. #include "locking-selftest-hardirq.h"
  1064. #include "locking-selftest-rlock.h"
  1065. GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion2_hard_rlock)
  1066. #include "locking-selftest-wlock.h"
  1067. GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion2_hard_wlock)
  1068. #ifndef CONFIG_PREEMPT_RT
  1069. #include "locking-selftest-softirq.h"
  1070. #include "locking-selftest-rlock.h"
  1071. GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion2_soft_rlock)
  1072. #include "locking-selftest-wlock.h"
  1073. GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion2_soft_wlock)
  1074. #endif
  1075. #undef E1
  1076. #undef E2
  1077. #undef E3
  1078. /*
  1079. * read-lock / write-lock recursion that is unsafe.
  1080. *
  1081. * A is a ENABLED_*_READ lock
  1082. * B is a USED_IN_*_READ lock
  1083. *
  1084. * read_lock(A);
  1085. * write_lock(B);
  1086. * <interrupt>
  1087. * read_lock(B);
  1088. * write_lock(A); // if this one is read_lock(), no deadlock
  1089. */
  1090. #define E1() \
  1091. \
  1092. IRQ_DISABLE(); \
  1093. WL(B); \
  1094. LOCK(A); \
  1095. UNLOCK(A); \
  1096. WU(B); \
  1097. IRQ_ENABLE();
  1098. #define E2() \
  1099. \
  1100. RL(A); \
  1101. RU(A); \
  1102. #define E3() \
  1103. \
  1104. IRQ_ENTER(); \
  1105. RL(B); \
  1106. RU(B); \
  1107. IRQ_EXIT();
  1108. /*
  1109. * Generate 24 testcases:
  1110. */
  1111. #include "locking-selftest-hardirq.h"
  1112. #include "locking-selftest-rlock.h"
  1113. GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion3_hard_rlock)
  1114. #include "locking-selftest-wlock.h"
  1115. GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion3_hard_wlock)
  1116. #ifndef CONFIG_PREEMPT_RT
  1117. #include "locking-selftest-softirq.h"
  1118. #include "locking-selftest-rlock.h"
  1119. GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion3_soft_rlock)
  1120. #include "locking-selftest-wlock.h"
  1121. GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion3_soft_wlock)
  1122. #endif
  1123. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  1124. # define I_SPINLOCK(x) lockdep_reset_lock(&lock_##x.dep_map)
  1125. # define I_RAW_SPINLOCK(x) lockdep_reset_lock(&raw_lock_##x.dep_map)
  1126. # define I_RWLOCK(x) lockdep_reset_lock(&rwlock_##x.dep_map)
  1127. # define I_MUTEX(x) lockdep_reset_lock(&mutex_##x.dep_map)
  1128. # define I_RWSEM(x) lockdep_reset_lock(&rwsem_##x.dep_map)
  1129. # define I_WW(x) lockdep_reset_lock(&x.dep_map)
  1130. # define I_LOCAL_LOCK(x) lockdep_reset_lock(this_cpu_ptr(&local_##x.dep_map))
  1131. #ifdef CONFIG_RT_MUTEXES
  1132. # define I_RTMUTEX(x) lockdep_reset_lock(&rtmutex_##x.dep_map)
  1133. #endif
  1134. #else
  1135. # define I_SPINLOCK(x)
  1136. # define I_RAW_SPINLOCK(x)
  1137. # define I_RWLOCK(x)
  1138. # define I_MUTEX(x)
  1139. # define I_RWSEM(x)
  1140. # define I_WW(x)
  1141. # define I_LOCAL_LOCK(x)
  1142. #endif
  1143. #ifndef I_RTMUTEX
  1144. # define I_RTMUTEX(x)
  1145. #endif
  1146. #ifdef CONFIG_RT_MUTEXES
  1147. #define I2_RTMUTEX(x) rt_mutex_init(&rtmutex_##x)
  1148. #else
  1149. #define I2_RTMUTEX(x)
  1150. #endif
  1151. #define I1(x) \
  1152. do { \
  1153. I_SPINLOCK(x); \
  1154. I_RWLOCK(x); \
  1155. I_MUTEX(x); \
  1156. I_RWSEM(x); \
  1157. I_RTMUTEX(x); \
  1158. } while (0)
  1159. #define I2(x) \
  1160. do { \
  1161. spin_lock_init(&lock_##x); \
  1162. rwlock_init(&rwlock_##x); \
  1163. mutex_init(&mutex_##x); \
  1164. init_rwsem(&rwsem_##x); \
  1165. I2_RTMUTEX(x); \
  1166. } while (0)
  1167. static void reset_locks(void)
  1168. {
  1169. local_irq_disable();
  1170. lockdep_free_key_range(&ww_lockdep.acquire_key, 1);
  1171. lockdep_free_key_range(&ww_lockdep.mutex_key, 1);
  1172. I1(A); I1(B); I1(C); I1(D);
  1173. I1(X1); I1(X2); I1(Y1); I1(Y2); I1(Z1); I1(Z2);
  1174. I_WW(t); I_WW(t2); I_WW(o.base); I_WW(o2.base); I_WW(o3.base);
  1175. I_RAW_SPINLOCK(A); I_RAW_SPINLOCK(B);
  1176. I_LOCAL_LOCK(A);
  1177. lockdep_reset();
  1178. I2(A); I2(B); I2(C); I2(D);
  1179. init_shared_classes();
  1180. raw_spin_lock_init(&raw_lock_A);
  1181. raw_spin_lock_init(&raw_lock_B);
  1182. local_lock_init(this_cpu_ptr(&local_A));
  1183. ww_mutex_init(&o, &ww_lockdep); ww_mutex_init(&o2, &ww_lockdep); ww_mutex_init(&o3, &ww_lockdep);
  1184. memset(&t, 0, sizeof(t)); memset(&t2, 0, sizeof(t2));
  1185. memset(&ww_lockdep.acquire_key, 0, sizeof(ww_lockdep.acquire_key));
  1186. memset(&ww_lockdep.mutex_key, 0, sizeof(ww_lockdep.mutex_key));
  1187. local_irq_enable();
  1188. }
  1189. #undef I
  1190. static int testcase_total;
  1191. static int testcase_successes;
  1192. static int expected_testcase_failures;
  1193. static int unexpected_testcase_failures;
  1194. static void dotest(void (*testcase_fn)(void), int expected, int lockclass_mask)
  1195. {
  1196. int saved_preempt_count = preempt_count();
  1197. #ifdef CONFIG_PREEMPT_RT
  1198. #ifdef CONFIG_SMP
  1199. int saved_mgd_count = current->migration_disabled;
  1200. #endif
  1201. int saved_rcu_count = current->rcu_read_lock_nesting;
  1202. #endif
  1203. WARN_ON(irqs_disabled());
  1204. debug_locks_silent = !(debug_locks_verbose & lockclass_mask);
  1205. testcase_fn();
  1206. /*
  1207. * Filter out expected failures:
  1208. */
  1209. #ifndef CONFIG_PROVE_LOCKING
  1210. if (expected == FAILURE && debug_locks) {
  1211. expected_testcase_failures++;
  1212. pr_cont("failed|");
  1213. }
  1214. else
  1215. #endif
  1216. if (debug_locks != expected) {
  1217. unexpected_testcase_failures++;
  1218. pr_cont("FAILED|");
  1219. } else {
  1220. testcase_successes++;
  1221. pr_cont(" ok |");
  1222. }
  1223. testcase_total++;
  1224. if (debug_locks_verbose & lockclass_mask)
  1225. pr_cont(" lockclass mask: %x, debug_locks: %d, expected: %d\n",
  1226. lockclass_mask, debug_locks, expected);
  1227. /*
  1228. * Some tests (e.g. double-unlock) might corrupt the preemption
  1229. * count, so restore it:
  1230. */
  1231. preempt_count_set(saved_preempt_count);
  1232. #ifdef CONFIG_PREEMPT_RT
  1233. #ifdef CONFIG_SMP
  1234. while (current->migration_disabled > saved_mgd_count)
  1235. migrate_enable();
  1236. #endif
  1237. while (current->rcu_read_lock_nesting > saved_rcu_count)
  1238. rcu_read_unlock();
  1239. WARN_ON_ONCE(current->rcu_read_lock_nesting < saved_rcu_count);
  1240. #endif
  1241. #ifdef CONFIG_TRACE_IRQFLAGS
  1242. if (softirq_count())
  1243. current->softirqs_enabled = 0;
  1244. else
  1245. current->softirqs_enabled = 1;
  1246. #endif
  1247. reset_locks();
  1248. }
  1249. #ifdef CONFIG_RT_MUTEXES
  1250. #define dotest_rt(fn, e, m) dotest((fn), (e), (m))
  1251. #else
  1252. #define dotest_rt(fn, e, m)
  1253. #endif
  1254. static inline void print_testname(const char *testname)
  1255. {
  1256. printk("%33s:", testname);
  1257. }
  1258. #define DO_TESTCASE_1(desc, name, nr) \
  1259. print_testname(desc"/"#nr); \
  1260. dotest(name##_##nr, SUCCESS, LOCKTYPE_RWLOCK); \
  1261. pr_cont("\n");
  1262. #define DO_TESTCASE_1B(desc, name, nr) \
  1263. print_testname(desc"/"#nr); \
  1264. dotest(name##_##nr, FAILURE, LOCKTYPE_RWLOCK); \
  1265. pr_cont("\n");
  1266. #define DO_TESTCASE_1RR(desc, name, nr) \
  1267. print_testname(desc"/"#nr); \
  1268. pr_cont(" |"); \
  1269. dotest(name##_##nr, SUCCESS, LOCKTYPE_RWLOCK); \
  1270. pr_cont("\n");
  1271. #define DO_TESTCASE_1RRB(desc, name, nr) \
  1272. print_testname(desc"/"#nr); \
  1273. pr_cont(" |"); \
  1274. dotest(name##_##nr, FAILURE, LOCKTYPE_RWLOCK); \
  1275. pr_cont("\n");
  1276. #define DO_TESTCASE_3(desc, name, nr) \
  1277. print_testname(desc"/"#nr); \
  1278. dotest(name##_spin_##nr, FAILURE, LOCKTYPE_SPIN); \
  1279. dotest(name##_wlock_##nr, FAILURE, LOCKTYPE_RWLOCK); \
  1280. dotest(name##_rlock_##nr, SUCCESS, LOCKTYPE_RWLOCK); \
  1281. pr_cont("\n");
  1282. #define DO_TESTCASE_3RW(desc, name, nr) \
  1283. print_testname(desc"/"#nr); \
  1284. dotest(name##_spin_##nr, FAILURE, LOCKTYPE_SPIN|LOCKTYPE_RWLOCK);\
  1285. dotest(name##_wlock_##nr, FAILURE, LOCKTYPE_RWLOCK); \
  1286. dotest(name##_rlock_##nr, SUCCESS, LOCKTYPE_RWLOCK); \
  1287. pr_cont("\n");
  1288. #define DO_TESTCASE_2RW(desc, name, nr) \
  1289. print_testname(desc"/"#nr); \
  1290. pr_cont(" |"); \
  1291. dotest(name##_wlock_##nr, FAILURE, LOCKTYPE_RWLOCK); \
  1292. dotest(name##_rlock_##nr, SUCCESS, LOCKTYPE_RWLOCK); \
  1293. pr_cont("\n");
  1294. #define DO_TESTCASE_2x2RW(desc, name, nr) \
  1295. DO_TESTCASE_2RW("hard-"desc, name##_hard, nr) \
  1296. NON_RT(DO_TESTCASE_2RW("soft-"desc, name##_soft, nr)) \
  1297. #define DO_TESTCASE_6x2x2RW(desc, name) \
  1298. DO_TESTCASE_2x2RW(desc, name, 123); \
  1299. DO_TESTCASE_2x2RW(desc, name, 132); \
  1300. DO_TESTCASE_2x2RW(desc, name, 213); \
  1301. DO_TESTCASE_2x2RW(desc, name, 231); \
  1302. DO_TESTCASE_2x2RW(desc, name, 312); \
  1303. DO_TESTCASE_2x2RW(desc, name, 321);
  1304. #define DO_TESTCASE_6(desc, name) \
  1305. print_testname(desc); \
  1306. dotest(name##_spin, FAILURE, LOCKTYPE_SPIN); \
  1307. dotest(name##_wlock, FAILURE, LOCKTYPE_RWLOCK); \
  1308. dotest(name##_rlock, FAILURE, LOCKTYPE_RWLOCK); \
  1309. dotest(name##_mutex, FAILURE, LOCKTYPE_MUTEX); \
  1310. dotest(name##_wsem, FAILURE, LOCKTYPE_RWSEM); \
  1311. dotest(name##_rsem, FAILURE, LOCKTYPE_RWSEM); \
  1312. dotest_rt(name##_rtmutex, FAILURE, LOCKTYPE_RTMUTEX); \
  1313. pr_cont("\n");
  1314. #define DO_TESTCASE_6_SUCCESS(desc, name) \
  1315. print_testname(desc); \
  1316. dotest(name##_spin, SUCCESS, LOCKTYPE_SPIN); \
  1317. dotest(name##_wlock, SUCCESS, LOCKTYPE_RWLOCK); \
  1318. dotest(name##_rlock, SUCCESS, LOCKTYPE_RWLOCK); \
  1319. dotest(name##_mutex, SUCCESS, LOCKTYPE_MUTEX); \
  1320. dotest(name##_wsem, SUCCESS, LOCKTYPE_RWSEM); \
  1321. dotest(name##_rsem, SUCCESS, LOCKTYPE_RWSEM); \
  1322. dotest_rt(name##_rtmutex, SUCCESS, LOCKTYPE_RTMUTEX); \
  1323. pr_cont("\n");
  1324. /*
  1325. * 'read' variant: rlocks must not trigger.
  1326. */
  1327. #define DO_TESTCASE_6R(desc, name) \
  1328. print_testname(desc); \
  1329. dotest(name##_spin, FAILURE, LOCKTYPE_SPIN); \
  1330. dotest(name##_wlock, FAILURE, LOCKTYPE_RWLOCK); \
  1331. dotest(name##_rlock, SUCCESS, LOCKTYPE_RWLOCK); \
  1332. dotest(name##_mutex, FAILURE, LOCKTYPE_MUTEX); \
  1333. dotest(name##_wsem, FAILURE, LOCKTYPE_RWSEM); \
  1334. dotest(name##_rsem, FAILURE, LOCKTYPE_RWSEM); \
  1335. dotest_rt(name##_rtmutex, FAILURE, LOCKTYPE_RTMUTEX); \
  1336. pr_cont("\n");
  1337. #define DO_TESTCASE_2I(desc, name, nr) \
  1338. DO_TESTCASE_1("hard-"desc, name##_hard, nr); \
  1339. NON_RT(DO_TESTCASE_1("soft-"desc, name##_soft, nr));
  1340. #define DO_TESTCASE_2IB(desc, name, nr) \
  1341. DO_TESTCASE_1B("hard-"desc, name##_hard, nr); \
  1342. NON_RT(DO_TESTCASE_1B("soft-"desc, name##_soft, nr));
  1343. #define DO_TESTCASE_6I(desc, name, nr) \
  1344. DO_TESTCASE_3("hard-"desc, name##_hard, nr); \
  1345. NON_RT(DO_TESTCASE_3("soft-"desc, name##_soft, nr));
  1346. #define DO_TESTCASE_6IRW(desc, name, nr) \
  1347. DO_TESTCASE_3RW("hard-"desc, name##_hard, nr); \
  1348. NON_RT(DO_TESTCASE_3RW("soft-"desc, name##_soft, nr));
  1349. #define DO_TESTCASE_2x3(desc, name) \
  1350. DO_TESTCASE_3(desc, name, 12); \
  1351. DO_TESTCASE_3(desc, name, 21);
  1352. #define DO_TESTCASE_2x6(desc, name) \
  1353. DO_TESTCASE_6I(desc, name, 12); \
  1354. DO_TESTCASE_6I(desc, name, 21);
  1355. #define DO_TESTCASE_6x2(desc, name) \
  1356. DO_TESTCASE_2I(desc, name, 123); \
  1357. DO_TESTCASE_2I(desc, name, 132); \
  1358. DO_TESTCASE_2I(desc, name, 213); \
  1359. DO_TESTCASE_2I(desc, name, 231); \
  1360. DO_TESTCASE_2I(desc, name, 312); \
  1361. DO_TESTCASE_2I(desc, name, 321);
  1362. #define DO_TESTCASE_6x2B(desc, name) \
  1363. DO_TESTCASE_2IB(desc, name, 123); \
  1364. DO_TESTCASE_2IB(desc, name, 132); \
  1365. DO_TESTCASE_2IB(desc, name, 213); \
  1366. DO_TESTCASE_2IB(desc, name, 231); \
  1367. DO_TESTCASE_2IB(desc, name, 312); \
  1368. DO_TESTCASE_2IB(desc, name, 321);
  1369. #define DO_TESTCASE_6x1RR(desc, name) \
  1370. DO_TESTCASE_1RR(desc, name, 123); \
  1371. DO_TESTCASE_1RR(desc, name, 132); \
  1372. DO_TESTCASE_1RR(desc, name, 213); \
  1373. DO_TESTCASE_1RR(desc, name, 231); \
  1374. DO_TESTCASE_1RR(desc, name, 312); \
  1375. DO_TESTCASE_1RR(desc, name, 321);
  1376. #define DO_TESTCASE_6x1RRB(desc, name) \
  1377. DO_TESTCASE_1RRB(desc, name, 123); \
  1378. DO_TESTCASE_1RRB(desc, name, 132); \
  1379. DO_TESTCASE_1RRB(desc, name, 213); \
  1380. DO_TESTCASE_1RRB(desc, name, 231); \
  1381. DO_TESTCASE_1RRB(desc, name, 312); \
  1382. DO_TESTCASE_1RRB(desc, name, 321);
  1383. #define DO_TESTCASE_6x6(desc, name) \
  1384. DO_TESTCASE_6I(desc, name, 123); \
  1385. DO_TESTCASE_6I(desc, name, 132); \
  1386. DO_TESTCASE_6I(desc, name, 213); \
  1387. DO_TESTCASE_6I(desc, name, 231); \
  1388. DO_TESTCASE_6I(desc, name, 312); \
  1389. DO_TESTCASE_6I(desc, name, 321);
  1390. #define DO_TESTCASE_6x6RW(desc, name) \
  1391. DO_TESTCASE_6IRW(desc, name, 123); \
  1392. DO_TESTCASE_6IRW(desc, name, 132); \
  1393. DO_TESTCASE_6IRW(desc, name, 213); \
  1394. DO_TESTCASE_6IRW(desc, name, 231); \
  1395. DO_TESTCASE_6IRW(desc, name, 312); \
  1396. DO_TESTCASE_6IRW(desc, name, 321);
  1397. static void ww_test_fail_acquire(void)
  1398. {
  1399. int ret;
  1400. WWAI(&t);
  1401. t.stamp++;
  1402. ret = WWL(&o, &t);
  1403. if (WARN_ON(!o.ctx) ||
  1404. WARN_ON(ret))
  1405. return;
  1406. /* No lockdep test, pure API */
  1407. ret = WWL(&o, &t);
  1408. WARN_ON(ret != -EALREADY);
  1409. ret = WWT(&o);
  1410. WARN_ON(ret);
  1411. t2 = t;
  1412. t2.stamp++;
  1413. ret = WWL(&o, &t2);
  1414. WARN_ON(ret != -EDEADLK);
  1415. WWU(&o);
  1416. if (WWT(&o))
  1417. WWU(&o);
  1418. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  1419. else
  1420. DEBUG_LOCKS_WARN_ON(1);
  1421. #endif
  1422. }
  1423. #ifdef CONFIG_PREEMPT_RT
  1424. #define ww_mutex_base_lock(b) rt_mutex_lock(b)
  1425. #define ww_mutex_base_trylock(b) rt_mutex_trylock(b)
  1426. #define ww_mutex_base_lock_nest_lock(b, b2) rt_mutex_lock_nest_lock(b, b2)
  1427. #define ww_mutex_base_lock_interruptible(b) rt_mutex_lock_interruptible(b)
  1428. #define ww_mutex_base_lock_killable(b) rt_mutex_lock_killable(b)
  1429. #define ww_mutex_base_unlock(b) rt_mutex_unlock(b)
  1430. #else
  1431. #define ww_mutex_base_lock(b) mutex_lock(b)
  1432. #define ww_mutex_base_trylock(b) mutex_trylock(b)
  1433. #define ww_mutex_base_lock_nest_lock(b, b2) mutex_lock_nest_lock(b, b2)
  1434. #define ww_mutex_base_lock_interruptible(b) mutex_lock_interruptible(b)
  1435. #define ww_mutex_base_lock_killable(b) mutex_lock_killable(b)
  1436. #define ww_mutex_base_unlock(b) mutex_unlock(b)
  1437. #endif
  1438. static void ww_test_normal(void)
  1439. {
  1440. int ret;
  1441. WWAI(&t);
  1442. /*
  1443. * None of the ww_mutex codepaths should be taken in the 'normal'
  1444. * mutex calls. The easiest way to verify this is by using the
  1445. * normal mutex calls, and making sure o.ctx is unmodified.
  1446. */
  1447. /* mutex_lock (and indirectly, mutex_lock_nested) */
  1448. o.ctx = (void *)~0UL;
  1449. ww_mutex_base_lock(&o.base);
  1450. ww_mutex_base_unlock(&o.base);
  1451. WARN_ON(o.ctx != (void *)~0UL);
  1452. /* mutex_lock_interruptible (and *_nested) */
  1453. o.ctx = (void *)~0UL;
  1454. ret = ww_mutex_base_lock_interruptible(&o.base);
  1455. if (!ret)
  1456. ww_mutex_base_unlock(&o.base);
  1457. else
  1458. WARN_ON(1);
  1459. WARN_ON(o.ctx != (void *)~0UL);
  1460. /* mutex_lock_killable (and *_nested) */
  1461. o.ctx = (void *)~0UL;
  1462. ret = ww_mutex_base_lock_killable(&o.base);
  1463. if (!ret)
  1464. ww_mutex_base_unlock(&o.base);
  1465. else
  1466. WARN_ON(1);
  1467. WARN_ON(o.ctx != (void *)~0UL);
  1468. /* trylock, succeeding */
  1469. o.ctx = (void *)~0UL;
  1470. ret = ww_mutex_base_trylock(&o.base);
  1471. WARN_ON(!ret);
  1472. if (ret)
  1473. ww_mutex_base_unlock(&o.base);
  1474. else
  1475. WARN_ON(1);
  1476. WARN_ON(o.ctx != (void *)~0UL);
  1477. /* trylock, failing */
  1478. o.ctx = (void *)~0UL;
  1479. ww_mutex_base_lock(&o.base);
  1480. ret = ww_mutex_base_trylock(&o.base);
  1481. WARN_ON(ret);
  1482. ww_mutex_base_unlock(&o.base);
  1483. WARN_ON(o.ctx != (void *)~0UL);
  1484. /* nest_lock */
  1485. o.ctx = (void *)~0UL;
  1486. ww_mutex_base_lock_nest_lock(&o.base, &t);
  1487. ww_mutex_base_unlock(&o.base);
  1488. WARN_ON(o.ctx != (void *)~0UL);
  1489. }
  1490. static void ww_test_two_contexts(void)
  1491. {
  1492. WWAI(&t);
  1493. WWAI(&t2);
  1494. }
  1495. static void ww_test_diff_class(void)
  1496. {
  1497. WWAI(&t);
  1498. #ifdef DEBUG_WW_MUTEXES
  1499. t.ww_class = NULL;
  1500. #endif
  1501. WWL(&o, &t);
  1502. }
  1503. static void ww_test_context_done_twice(void)
  1504. {
  1505. WWAI(&t);
  1506. WWAD(&t);
  1507. WWAD(&t);
  1508. WWAF(&t);
  1509. }
  1510. static void ww_test_context_unlock_twice(void)
  1511. {
  1512. WWAI(&t);
  1513. WWAD(&t);
  1514. WWAF(&t);
  1515. WWAF(&t);
  1516. }
  1517. static void ww_test_context_fini_early(void)
  1518. {
  1519. WWAI(&t);
  1520. WWL(&o, &t);
  1521. WWAD(&t);
  1522. WWAF(&t);
  1523. }
  1524. static void ww_test_context_lock_after_done(void)
  1525. {
  1526. WWAI(&t);
  1527. WWAD(&t);
  1528. WWL(&o, &t);
  1529. }
  1530. static void ww_test_object_unlock_twice(void)
  1531. {
  1532. WWL1(&o);
  1533. WWU(&o);
  1534. WWU(&o);
  1535. }
  1536. static void ww_test_object_lock_unbalanced(void)
  1537. {
  1538. WWAI(&t);
  1539. WWL(&o, &t);
  1540. t.acquired = 0;
  1541. WWU(&o);
  1542. WWAF(&t);
  1543. }
  1544. static void ww_test_object_lock_stale_context(void)
  1545. {
  1546. WWAI(&t);
  1547. o.ctx = &t2;
  1548. WWL(&o, &t);
  1549. }
  1550. static void ww_test_edeadlk_normal(void)
  1551. {
  1552. int ret;
  1553. ww_mutex_base_lock(&o2.base);
  1554. o2.ctx = &t2;
  1555. mutex_release(&o2.base.dep_map, _THIS_IP_);
  1556. WWAI(&t);
  1557. t2 = t;
  1558. t2.stamp--;
  1559. ret = WWL(&o, &t);
  1560. WARN_ON(ret);
  1561. ret = WWL(&o2, &t);
  1562. WARN_ON(ret != -EDEADLK);
  1563. o2.ctx = NULL;
  1564. mutex_acquire(&o2.base.dep_map, 0, 1, _THIS_IP_);
  1565. ww_mutex_base_unlock(&o2.base);
  1566. WWU(&o);
  1567. WWL(&o2, &t);
  1568. }
  1569. static void ww_test_edeadlk_normal_slow(void)
  1570. {
  1571. int ret;
  1572. ww_mutex_base_lock(&o2.base);
  1573. mutex_release(&o2.base.dep_map, _THIS_IP_);
  1574. o2.ctx = &t2;
  1575. WWAI(&t);
  1576. t2 = t;
  1577. t2.stamp--;
  1578. ret = WWL(&o, &t);
  1579. WARN_ON(ret);
  1580. ret = WWL(&o2, &t);
  1581. WARN_ON(ret != -EDEADLK);
  1582. o2.ctx = NULL;
  1583. mutex_acquire(&o2.base.dep_map, 0, 1, _THIS_IP_);
  1584. ww_mutex_base_unlock(&o2.base);
  1585. WWU(&o);
  1586. ww_mutex_lock_slow(&o2, &t);
  1587. }
  1588. static void ww_test_edeadlk_no_unlock(void)
  1589. {
  1590. int ret;
  1591. ww_mutex_base_lock(&o2.base);
  1592. o2.ctx = &t2;
  1593. mutex_release(&o2.base.dep_map, _THIS_IP_);
  1594. WWAI(&t);
  1595. t2 = t;
  1596. t2.stamp--;
  1597. ret = WWL(&o, &t);
  1598. WARN_ON(ret);
  1599. ret = WWL(&o2, &t);
  1600. WARN_ON(ret != -EDEADLK);
  1601. o2.ctx = NULL;
  1602. mutex_acquire(&o2.base.dep_map, 0, 1, _THIS_IP_);
  1603. ww_mutex_base_unlock(&o2.base);
  1604. WWL(&o2, &t);
  1605. }
  1606. static void ww_test_edeadlk_no_unlock_slow(void)
  1607. {
  1608. int ret;
  1609. ww_mutex_base_lock(&o2.base);
  1610. mutex_release(&o2.base.dep_map, _THIS_IP_);
  1611. o2.ctx = &t2;
  1612. WWAI(&t);
  1613. t2 = t;
  1614. t2.stamp--;
  1615. ret = WWL(&o, &t);
  1616. WARN_ON(ret);
  1617. ret = WWL(&o2, &t);
  1618. WARN_ON(ret != -EDEADLK);
  1619. o2.ctx = NULL;
  1620. mutex_acquire(&o2.base.dep_map, 0, 1, _THIS_IP_);
  1621. ww_mutex_base_unlock(&o2.base);
  1622. ww_mutex_lock_slow(&o2, &t);
  1623. }
  1624. static void ww_test_edeadlk_acquire_more(void)
  1625. {
  1626. int ret;
  1627. ww_mutex_base_lock(&o2.base);
  1628. mutex_release(&o2.base.dep_map, _THIS_IP_);
  1629. o2.ctx = &t2;
  1630. WWAI(&t);
  1631. t2 = t;
  1632. t2.stamp--;
  1633. ret = WWL(&o, &t);
  1634. WARN_ON(ret);
  1635. ret = WWL(&o2, &t);
  1636. WARN_ON(ret != -EDEADLK);
  1637. ret = WWL(&o3, &t);
  1638. }
  1639. static void ww_test_edeadlk_acquire_more_slow(void)
  1640. {
  1641. int ret;
  1642. ww_mutex_base_lock(&o2.base);
  1643. mutex_release(&o2.base.dep_map, _THIS_IP_);
  1644. o2.ctx = &t2;
  1645. WWAI(&t);
  1646. t2 = t;
  1647. t2.stamp--;
  1648. ret = WWL(&o, &t);
  1649. WARN_ON(ret);
  1650. ret = WWL(&o2, &t);
  1651. WARN_ON(ret != -EDEADLK);
  1652. ww_mutex_lock_slow(&o3, &t);
  1653. }
  1654. static void ww_test_edeadlk_acquire_more_edeadlk(void)
  1655. {
  1656. int ret;
  1657. ww_mutex_base_lock(&o2.base);
  1658. mutex_release(&o2.base.dep_map, _THIS_IP_);
  1659. o2.ctx = &t2;
  1660. ww_mutex_base_lock(&o3.base);
  1661. mutex_release(&o3.base.dep_map, _THIS_IP_);
  1662. o3.ctx = &t2;
  1663. WWAI(&t);
  1664. t2 = t;
  1665. t2.stamp--;
  1666. ret = WWL(&o, &t);
  1667. WARN_ON(ret);
  1668. ret = WWL(&o2, &t);
  1669. WARN_ON(ret != -EDEADLK);
  1670. ret = WWL(&o3, &t);
  1671. WARN_ON(ret != -EDEADLK);
  1672. }
  1673. static void ww_test_edeadlk_acquire_more_edeadlk_slow(void)
  1674. {
  1675. int ret;
  1676. ww_mutex_base_lock(&o2.base);
  1677. mutex_release(&o2.base.dep_map, _THIS_IP_);
  1678. o2.ctx = &t2;
  1679. ww_mutex_base_lock(&o3.base);
  1680. mutex_release(&o3.base.dep_map, _THIS_IP_);
  1681. o3.ctx = &t2;
  1682. WWAI(&t);
  1683. t2 = t;
  1684. t2.stamp--;
  1685. ret = WWL(&o, &t);
  1686. WARN_ON(ret);
  1687. ret = WWL(&o2, &t);
  1688. WARN_ON(ret != -EDEADLK);
  1689. ww_mutex_lock_slow(&o3, &t);
  1690. }
  1691. static void ww_test_edeadlk_acquire_wrong(void)
  1692. {
  1693. int ret;
  1694. ww_mutex_base_lock(&o2.base);
  1695. mutex_release(&o2.base.dep_map, _THIS_IP_);
  1696. o2.ctx = &t2;
  1697. WWAI(&t);
  1698. t2 = t;
  1699. t2.stamp--;
  1700. ret = WWL(&o, &t);
  1701. WARN_ON(ret);
  1702. ret = WWL(&o2, &t);
  1703. WARN_ON(ret != -EDEADLK);
  1704. if (!ret)
  1705. WWU(&o2);
  1706. WWU(&o);
  1707. ret = WWL(&o3, &t);
  1708. }
  1709. static void ww_test_edeadlk_acquire_wrong_slow(void)
  1710. {
  1711. int ret;
  1712. ww_mutex_base_lock(&o2.base);
  1713. mutex_release(&o2.base.dep_map, _THIS_IP_);
  1714. o2.ctx = &t2;
  1715. WWAI(&t);
  1716. t2 = t;
  1717. t2.stamp--;
  1718. ret = WWL(&o, &t);
  1719. WARN_ON(ret);
  1720. ret = WWL(&o2, &t);
  1721. WARN_ON(ret != -EDEADLK);
  1722. if (!ret)
  1723. WWU(&o2);
  1724. WWU(&o);
  1725. ww_mutex_lock_slow(&o3, &t);
  1726. }
  1727. static void ww_test_spin_nest_unlocked(void)
  1728. {
  1729. spin_lock_nest_lock(&lock_A, &o.base);
  1730. U(A);
  1731. }
  1732. /* This is not a deadlock, because we have X1 to serialize Y1 and Y2 */
  1733. static void ww_test_spin_nest_lock(void)
  1734. {
  1735. spin_lock(&lock_X1);
  1736. spin_lock_nest_lock(&lock_Y1, &lock_X1);
  1737. spin_lock(&lock_A);
  1738. spin_lock_nest_lock(&lock_Y2, &lock_X1);
  1739. spin_unlock(&lock_A);
  1740. spin_unlock(&lock_Y2);
  1741. spin_unlock(&lock_Y1);
  1742. spin_unlock(&lock_X1);
  1743. }
  1744. static void ww_test_unneeded_slow(void)
  1745. {
  1746. WWAI(&t);
  1747. ww_mutex_lock_slow(&o, &t);
  1748. }
  1749. static void ww_test_context_block(void)
  1750. {
  1751. int ret;
  1752. WWAI(&t);
  1753. ret = WWL(&o, &t);
  1754. WARN_ON(ret);
  1755. WWL1(&o2);
  1756. }
  1757. static void ww_test_context_try(void)
  1758. {
  1759. int ret;
  1760. WWAI(&t);
  1761. ret = WWL(&o, &t);
  1762. WARN_ON(ret);
  1763. ret = WWT(&o2);
  1764. WARN_ON(!ret);
  1765. WWU(&o2);
  1766. WWU(&o);
  1767. }
  1768. static void ww_test_context_context(void)
  1769. {
  1770. int ret;
  1771. WWAI(&t);
  1772. ret = WWL(&o, &t);
  1773. WARN_ON(ret);
  1774. ret = WWL(&o2, &t);
  1775. WARN_ON(ret);
  1776. WWU(&o2);
  1777. WWU(&o);
  1778. }
  1779. static void ww_test_try_block(void)
  1780. {
  1781. bool ret;
  1782. ret = WWT(&o);
  1783. WARN_ON(!ret);
  1784. WWL1(&o2);
  1785. WWU(&o2);
  1786. WWU(&o);
  1787. }
  1788. static void ww_test_try_try(void)
  1789. {
  1790. bool ret;
  1791. ret = WWT(&o);
  1792. WARN_ON(!ret);
  1793. ret = WWT(&o2);
  1794. WARN_ON(!ret);
  1795. WWU(&o2);
  1796. WWU(&o);
  1797. }
  1798. static void ww_test_try_context(void)
  1799. {
  1800. int ret;
  1801. ret = WWT(&o);
  1802. WARN_ON(!ret);
  1803. WWAI(&t);
  1804. ret = WWL(&o2, &t);
  1805. WARN_ON(ret);
  1806. }
  1807. static void ww_test_block_block(void)
  1808. {
  1809. WWL1(&o);
  1810. WWL1(&o2);
  1811. }
  1812. static void ww_test_block_try(void)
  1813. {
  1814. bool ret;
  1815. WWL1(&o);
  1816. ret = WWT(&o2);
  1817. WARN_ON(!ret);
  1818. }
  1819. static void ww_test_block_context(void)
  1820. {
  1821. int ret;
  1822. WWL1(&o);
  1823. WWAI(&t);
  1824. ret = WWL(&o2, &t);
  1825. WARN_ON(ret);
  1826. }
  1827. static void ww_test_spin_block(void)
  1828. {
  1829. L(A);
  1830. U(A);
  1831. WWL1(&o);
  1832. L(A);
  1833. U(A);
  1834. WWU(&o);
  1835. L(A);
  1836. WWL1(&o);
  1837. WWU(&o);
  1838. U(A);
  1839. }
  1840. static void ww_test_spin_try(void)
  1841. {
  1842. bool ret;
  1843. L(A);
  1844. U(A);
  1845. ret = WWT(&o);
  1846. WARN_ON(!ret);
  1847. L(A);
  1848. U(A);
  1849. WWU(&o);
  1850. L(A);
  1851. ret = WWT(&o);
  1852. WARN_ON(!ret);
  1853. WWU(&o);
  1854. U(A);
  1855. }
  1856. static void ww_test_spin_context(void)
  1857. {
  1858. int ret;
  1859. L(A);
  1860. U(A);
  1861. WWAI(&t);
  1862. ret = WWL(&o, &t);
  1863. WARN_ON(ret);
  1864. L(A);
  1865. U(A);
  1866. WWU(&o);
  1867. L(A);
  1868. ret = WWL(&o, &t);
  1869. WARN_ON(ret);
  1870. WWU(&o);
  1871. U(A);
  1872. }
  1873. static void ww_tests(void)
  1874. {
  1875. printk(" --------------------------------------------------------------------------\n");
  1876. printk(" | Wound/wait tests |\n");
  1877. printk(" ---------------------\n");
  1878. print_testname("ww api failures");
  1879. dotest(ww_test_fail_acquire, SUCCESS, LOCKTYPE_WW);
  1880. dotest(ww_test_normal, SUCCESS, LOCKTYPE_WW);
  1881. dotest(ww_test_unneeded_slow, FAILURE, LOCKTYPE_WW);
  1882. pr_cont("\n");
  1883. print_testname("ww contexts mixing");
  1884. dotest(ww_test_two_contexts, FAILURE, LOCKTYPE_WW);
  1885. dotest(ww_test_diff_class, FAILURE, LOCKTYPE_WW);
  1886. pr_cont("\n");
  1887. print_testname("finishing ww context");
  1888. dotest(ww_test_context_done_twice, FAILURE, LOCKTYPE_WW);
  1889. dotest(ww_test_context_unlock_twice, FAILURE, LOCKTYPE_WW);
  1890. dotest(ww_test_context_fini_early, FAILURE, LOCKTYPE_WW);
  1891. dotest(ww_test_context_lock_after_done, FAILURE, LOCKTYPE_WW);
  1892. pr_cont("\n");
  1893. print_testname("locking mismatches");
  1894. dotest(ww_test_object_unlock_twice, FAILURE, LOCKTYPE_WW);
  1895. dotest(ww_test_object_lock_unbalanced, FAILURE, LOCKTYPE_WW);
  1896. dotest(ww_test_object_lock_stale_context, FAILURE, LOCKTYPE_WW);
  1897. pr_cont("\n");
  1898. print_testname("EDEADLK handling");
  1899. dotest(ww_test_edeadlk_normal, SUCCESS, LOCKTYPE_WW);
  1900. dotest(ww_test_edeadlk_normal_slow, SUCCESS, LOCKTYPE_WW);
  1901. dotest(ww_test_edeadlk_no_unlock, FAILURE, LOCKTYPE_WW);
  1902. dotest(ww_test_edeadlk_no_unlock_slow, FAILURE, LOCKTYPE_WW);
  1903. dotest(ww_test_edeadlk_acquire_more, FAILURE, LOCKTYPE_WW);
  1904. dotest(ww_test_edeadlk_acquire_more_slow, FAILURE, LOCKTYPE_WW);
  1905. dotest(ww_test_edeadlk_acquire_more_edeadlk, FAILURE, LOCKTYPE_WW);
  1906. dotest(ww_test_edeadlk_acquire_more_edeadlk_slow, FAILURE, LOCKTYPE_WW);
  1907. dotest(ww_test_edeadlk_acquire_wrong, FAILURE, LOCKTYPE_WW);
  1908. dotest(ww_test_edeadlk_acquire_wrong_slow, FAILURE, LOCKTYPE_WW);
  1909. pr_cont("\n");
  1910. print_testname("spinlock nest unlocked");
  1911. dotest(ww_test_spin_nest_unlocked, FAILURE, LOCKTYPE_WW);
  1912. pr_cont("\n");
  1913. print_testname("spinlock nest test");
  1914. dotest(ww_test_spin_nest_lock, SUCCESS, LOCKTYPE_WW);
  1915. pr_cont("\n");
  1916. printk(" -----------------------------------------------------\n");
  1917. printk(" |block | try |context|\n");
  1918. printk(" -----------------------------------------------------\n");
  1919. print_testname("context");
  1920. dotest(ww_test_context_block, FAILURE, LOCKTYPE_WW);
  1921. dotest(ww_test_context_try, SUCCESS, LOCKTYPE_WW);
  1922. dotest(ww_test_context_context, SUCCESS, LOCKTYPE_WW);
  1923. pr_cont("\n");
  1924. print_testname("try");
  1925. dotest(ww_test_try_block, FAILURE, LOCKTYPE_WW);
  1926. dotest(ww_test_try_try, SUCCESS, LOCKTYPE_WW);
  1927. dotest(ww_test_try_context, FAILURE, LOCKTYPE_WW);
  1928. pr_cont("\n");
  1929. print_testname("block");
  1930. dotest(ww_test_block_block, FAILURE, LOCKTYPE_WW);
  1931. dotest(ww_test_block_try, SUCCESS, LOCKTYPE_WW);
  1932. dotest(ww_test_block_context, FAILURE, LOCKTYPE_WW);
  1933. pr_cont("\n");
  1934. print_testname("spinlock");
  1935. dotest(ww_test_spin_block, FAILURE, LOCKTYPE_WW);
  1936. dotest(ww_test_spin_try, SUCCESS, LOCKTYPE_WW);
  1937. dotest(ww_test_spin_context, FAILURE, LOCKTYPE_WW);
  1938. pr_cont("\n");
  1939. }
  1940. /*
  1941. * <in hardirq handler>
  1942. * read_lock(&A);
  1943. * <hardirq disable>
  1944. * spin_lock(&B);
  1945. * spin_lock(&B);
  1946. * read_lock(&A);
  1947. *
  1948. * is a deadlock.
  1949. */
  1950. static void queued_read_lock_hardirq_RE_Er(void)
  1951. {
  1952. HARDIRQ_ENTER();
  1953. read_lock(&rwlock_A);
  1954. LOCK(B);
  1955. UNLOCK(B);
  1956. read_unlock(&rwlock_A);
  1957. HARDIRQ_EXIT();
  1958. HARDIRQ_DISABLE();
  1959. LOCK(B);
  1960. read_lock(&rwlock_A);
  1961. read_unlock(&rwlock_A);
  1962. UNLOCK(B);
  1963. HARDIRQ_ENABLE();
  1964. }
  1965. /*
  1966. * <in hardirq handler>
  1967. * spin_lock(&B);
  1968. * <hardirq disable>
  1969. * read_lock(&A);
  1970. * read_lock(&A);
  1971. * spin_lock(&B);
  1972. *
  1973. * is not a deadlock.
  1974. */
  1975. static void queued_read_lock_hardirq_ER_rE(void)
  1976. {
  1977. HARDIRQ_ENTER();
  1978. LOCK(B);
  1979. read_lock(&rwlock_A);
  1980. read_unlock(&rwlock_A);
  1981. UNLOCK(B);
  1982. HARDIRQ_EXIT();
  1983. HARDIRQ_DISABLE();
  1984. read_lock(&rwlock_A);
  1985. LOCK(B);
  1986. UNLOCK(B);
  1987. read_unlock(&rwlock_A);
  1988. HARDIRQ_ENABLE();
  1989. }
  1990. /*
  1991. * <hardirq disable>
  1992. * spin_lock(&B);
  1993. * read_lock(&A);
  1994. * <in hardirq handler>
  1995. * spin_lock(&B);
  1996. * read_lock(&A);
  1997. *
  1998. * is a deadlock. Because the two read_lock()s are both non-recursive readers.
  1999. */
  2000. static void queued_read_lock_hardirq_inversion(void)
  2001. {
  2002. HARDIRQ_ENTER();
  2003. LOCK(B);
  2004. UNLOCK(B);
  2005. HARDIRQ_EXIT();
  2006. HARDIRQ_DISABLE();
  2007. LOCK(B);
  2008. read_lock(&rwlock_A);
  2009. read_unlock(&rwlock_A);
  2010. UNLOCK(B);
  2011. HARDIRQ_ENABLE();
  2012. read_lock(&rwlock_A);
  2013. read_unlock(&rwlock_A);
  2014. }
  2015. static void queued_read_lock_tests(void)
  2016. {
  2017. printk(" --------------------------------------------------------------------------\n");
  2018. printk(" | queued read lock tests |\n");
  2019. printk(" ---------------------------\n");
  2020. print_testname("hardirq read-lock/lock-read");
  2021. dotest(queued_read_lock_hardirq_RE_Er, FAILURE, LOCKTYPE_RWLOCK);
  2022. pr_cont("\n");
  2023. print_testname("hardirq lock-read/read-lock");
  2024. dotest(queued_read_lock_hardirq_ER_rE, SUCCESS, LOCKTYPE_RWLOCK);
  2025. pr_cont("\n");
  2026. print_testname("hardirq inversion");
  2027. dotest(queued_read_lock_hardirq_inversion, FAILURE, LOCKTYPE_RWLOCK);
  2028. pr_cont("\n");
  2029. }
  2030. static void fs_reclaim_correct_nesting(void)
  2031. {
  2032. fs_reclaim_acquire(GFP_KERNEL);
  2033. might_alloc(GFP_NOFS);
  2034. fs_reclaim_release(GFP_KERNEL);
  2035. }
  2036. static void fs_reclaim_wrong_nesting(void)
  2037. {
  2038. fs_reclaim_acquire(GFP_KERNEL);
  2039. might_alloc(GFP_KERNEL);
  2040. fs_reclaim_release(GFP_KERNEL);
  2041. }
  2042. static void fs_reclaim_protected_nesting(void)
  2043. {
  2044. unsigned int flags;
  2045. fs_reclaim_acquire(GFP_KERNEL);
  2046. flags = memalloc_nofs_save();
  2047. might_alloc(GFP_KERNEL);
  2048. memalloc_nofs_restore(flags);
  2049. fs_reclaim_release(GFP_KERNEL);
  2050. }
  2051. static void fs_reclaim_tests(void)
  2052. {
  2053. printk(" --------------------\n");
  2054. printk(" | fs_reclaim tests |\n");
  2055. printk(" --------------------\n");
  2056. print_testname("correct nesting");
  2057. dotest(fs_reclaim_correct_nesting, SUCCESS, 0);
  2058. pr_cont("\n");
  2059. print_testname("wrong nesting");
  2060. dotest(fs_reclaim_wrong_nesting, FAILURE, 0);
  2061. pr_cont("\n");
  2062. print_testname("protected nesting");
  2063. dotest(fs_reclaim_protected_nesting, SUCCESS, 0);
  2064. pr_cont("\n");
  2065. }
  2066. #define __guard(cleanup) __maybe_unused __attribute__((__cleanup__(cleanup)))
  2067. static void hardirq_exit(int *_)
  2068. {
  2069. HARDIRQ_EXIT();
  2070. }
  2071. #define HARDIRQ_CONTEXT(name, ...) \
  2072. int hardirq_guard_##name __guard(hardirq_exit); \
  2073. HARDIRQ_ENTER();
  2074. #define NOTTHREADED_HARDIRQ_CONTEXT(name, ...) \
  2075. int notthreaded_hardirq_guard_##name __guard(hardirq_exit); \
  2076. local_irq_disable(); \
  2077. __irq_enter(); \
  2078. WARN_ON(!in_irq());
  2079. static void softirq_exit(int *_)
  2080. {
  2081. SOFTIRQ_EXIT();
  2082. }
  2083. #define SOFTIRQ_CONTEXT(name, ...) \
  2084. int softirq_guard_##name __guard(softirq_exit); \
  2085. SOFTIRQ_ENTER();
  2086. static void rcu_exit(int *_)
  2087. {
  2088. rcu_read_unlock();
  2089. }
  2090. #define RCU_CONTEXT(name, ...) \
  2091. int rcu_guard_##name __guard(rcu_exit); \
  2092. rcu_read_lock();
  2093. static void rcu_bh_exit(int *_)
  2094. {
  2095. rcu_read_unlock_bh();
  2096. }
  2097. #define RCU_BH_CONTEXT(name, ...) \
  2098. int rcu_bh_guard_##name __guard(rcu_bh_exit); \
  2099. rcu_read_lock_bh();
  2100. static void rcu_sched_exit(int *_)
  2101. {
  2102. rcu_read_unlock_sched();
  2103. }
  2104. #define RCU_SCHED_CONTEXT(name, ...) \
  2105. int rcu_sched_guard_##name __guard(rcu_sched_exit); \
  2106. rcu_read_lock_sched();
  2107. static void raw_spinlock_exit(raw_spinlock_t **lock)
  2108. {
  2109. raw_spin_unlock(*lock);
  2110. }
  2111. #define RAW_SPINLOCK_CONTEXT(name, lock) \
  2112. raw_spinlock_t *raw_spinlock_guard_##name __guard(raw_spinlock_exit) = &(lock); \
  2113. raw_spin_lock(&(lock));
  2114. static void spinlock_exit(spinlock_t **lock)
  2115. {
  2116. spin_unlock(*lock);
  2117. }
  2118. #define SPINLOCK_CONTEXT(name, lock) \
  2119. spinlock_t *spinlock_guard_##name __guard(spinlock_exit) = &(lock); \
  2120. spin_lock(&(lock));
  2121. static void mutex_exit(struct mutex **lock)
  2122. {
  2123. mutex_unlock(*lock);
  2124. }
  2125. #define MUTEX_CONTEXT(name, lock) \
  2126. struct mutex *mutex_guard_##name __guard(mutex_exit) = &(lock); \
  2127. mutex_lock(&(lock));
  2128. #define GENERATE_2_CONTEXT_TESTCASE(outer, outer_lock, inner, inner_lock) \
  2129. \
  2130. static void __maybe_unused inner##_in_##outer(void) \
  2131. { \
  2132. outer##_CONTEXT(_, outer_lock); \
  2133. { \
  2134. inner##_CONTEXT(_, inner_lock); \
  2135. } \
  2136. }
  2137. /*
  2138. * wait contexts (considering PREEMPT_RT)
  2139. *
  2140. * o: inner is allowed in outer
  2141. * x: inner is disallowed in outer
  2142. *
  2143. * \ inner | RCU | RAW_SPIN | SPIN | MUTEX
  2144. * outer \ | | | |
  2145. * ---------------+-------+----------+------+-------
  2146. * HARDIRQ | o | o | o | x
  2147. * ---------------+-------+----------+------+-------
  2148. * NOTTHREADED_IRQ| o | o | x | x
  2149. * ---------------+-------+----------+------+-------
  2150. * SOFTIRQ | o | o | o | x
  2151. * ---------------+-------+----------+------+-------
  2152. * RCU | o | o | o | x
  2153. * ---------------+-------+----------+------+-------
  2154. * RCU_BH | o | o | o | x
  2155. * ---------------+-------+----------+------+-------
  2156. * RCU_SCHED | o | o | x | x
  2157. * ---------------+-------+----------+------+-------
  2158. * RAW_SPIN | o | o | x | x
  2159. * ---------------+-------+----------+------+-------
  2160. * SPIN | o | o | o | x
  2161. * ---------------+-------+----------+------+-------
  2162. * MUTEX | o | o | o | o
  2163. * ---------------+-------+----------+------+-------
  2164. */
  2165. #define GENERATE_2_CONTEXT_TESTCASE_FOR_ALL_OUTER(inner, inner_lock) \
  2166. GENERATE_2_CONTEXT_TESTCASE(HARDIRQ, , inner, inner_lock) \
  2167. GENERATE_2_CONTEXT_TESTCASE(NOTTHREADED_HARDIRQ, , inner, inner_lock) \
  2168. GENERATE_2_CONTEXT_TESTCASE(SOFTIRQ, , inner, inner_lock) \
  2169. GENERATE_2_CONTEXT_TESTCASE(RCU, , inner, inner_lock) \
  2170. GENERATE_2_CONTEXT_TESTCASE(RCU_BH, , inner, inner_lock) \
  2171. GENERATE_2_CONTEXT_TESTCASE(RCU_SCHED, , inner, inner_lock) \
  2172. GENERATE_2_CONTEXT_TESTCASE(RAW_SPINLOCK, raw_lock_A, inner, inner_lock) \
  2173. GENERATE_2_CONTEXT_TESTCASE(SPINLOCK, lock_A, inner, inner_lock) \
  2174. GENERATE_2_CONTEXT_TESTCASE(MUTEX, mutex_A, inner, inner_lock)
  2175. GENERATE_2_CONTEXT_TESTCASE_FOR_ALL_OUTER(RCU, )
  2176. GENERATE_2_CONTEXT_TESTCASE_FOR_ALL_OUTER(RAW_SPINLOCK, raw_lock_B)
  2177. GENERATE_2_CONTEXT_TESTCASE_FOR_ALL_OUTER(SPINLOCK, lock_B)
  2178. GENERATE_2_CONTEXT_TESTCASE_FOR_ALL_OUTER(MUTEX, mutex_B)
  2179. /* the outer context allows all kinds of preemption */
  2180. #define DO_CONTEXT_TESTCASE_OUTER_PREEMPTIBLE(outer) \
  2181. dotest(RCU_in_##outer, SUCCESS, LOCKTYPE_RWLOCK); \
  2182. dotest(RAW_SPINLOCK_in_##outer, SUCCESS, LOCKTYPE_SPIN); \
  2183. dotest(SPINLOCK_in_##outer, SUCCESS, LOCKTYPE_SPIN); \
  2184. dotest(MUTEX_in_##outer, SUCCESS, LOCKTYPE_MUTEX); \
  2185. /*
  2186. * the outer context only allows the preemption introduced by spinlock_t (which
  2187. * is a sleepable lock for PREEMPT_RT)
  2188. */
  2189. #define DO_CONTEXT_TESTCASE_OUTER_LIMITED_PREEMPTIBLE(outer) \
  2190. dotest(RCU_in_##outer, SUCCESS, LOCKTYPE_RWLOCK); \
  2191. dotest(RAW_SPINLOCK_in_##outer, SUCCESS, LOCKTYPE_SPIN); \
  2192. dotest(SPINLOCK_in_##outer, SUCCESS, LOCKTYPE_SPIN); \
  2193. dotest(MUTEX_in_##outer, FAILURE, LOCKTYPE_MUTEX); \
  2194. /* the outer doesn't allows any kind of preemption */
  2195. #define DO_CONTEXT_TESTCASE_OUTER_NOT_PREEMPTIBLE(outer) \
  2196. dotest(RCU_in_##outer, SUCCESS, LOCKTYPE_RWLOCK); \
  2197. dotest(RAW_SPINLOCK_in_##outer, SUCCESS, LOCKTYPE_SPIN); \
  2198. dotest(SPINLOCK_in_##outer, FAILURE, LOCKTYPE_SPIN); \
  2199. dotest(MUTEX_in_##outer, FAILURE, LOCKTYPE_MUTEX); \
  2200. static void wait_context_tests(void)
  2201. {
  2202. printk(" --------------------------------------------------------------------------\n");
  2203. printk(" | wait context tests |\n");
  2204. printk(" --------------------------------------------------------------------------\n");
  2205. printk(" | rcu | raw | spin |mutex |\n");
  2206. printk(" --------------------------------------------------------------------------\n");
  2207. print_testname("in hardirq context");
  2208. DO_CONTEXT_TESTCASE_OUTER_LIMITED_PREEMPTIBLE(HARDIRQ);
  2209. pr_cont("\n");
  2210. print_testname("in hardirq context (not threaded)");
  2211. DO_CONTEXT_TESTCASE_OUTER_NOT_PREEMPTIBLE(NOTTHREADED_HARDIRQ);
  2212. pr_cont("\n");
  2213. print_testname("in softirq context");
  2214. DO_CONTEXT_TESTCASE_OUTER_LIMITED_PREEMPTIBLE(SOFTIRQ);
  2215. pr_cont("\n");
  2216. print_testname("in RCU context");
  2217. DO_CONTEXT_TESTCASE_OUTER_LIMITED_PREEMPTIBLE(RCU);
  2218. pr_cont("\n");
  2219. print_testname("in RCU-bh context");
  2220. DO_CONTEXT_TESTCASE_OUTER_LIMITED_PREEMPTIBLE(RCU_BH);
  2221. pr_cont("\n");
  2222. print_testname("in RCU-sched context");
  2223. DO_CONTEXT_TESTCASE_OUTER_NOT_PREEMPTIBLE(RCU_SCHED);
  2224. pr_cont("\n");
  2225. print_testname("in RAW_SPINLOCK context");
  2226. DO_CONTEXT_TESTCASE_OUTER_NOT_PREEMPTIBLE(RAW_SPINLOCK);
  2227. pr_cont("\n");
  2228. print_testname("in SPINLOCK context");
  2229. DO_CONTEXT_TESTCASE_OUTER_LIMITED_PREEMPTIBLE(SPINLOCK);
  2230. pr_cont("\n");
  2231. print_testname("in MUTEX context");
  2232. DO_CONTEXT_TESTCASE_OUTER_PREEMPTIBLE(MUTEX);
  2233. pr_cont("\n");
  2234. }
  2235. static void local_lock_2(void)
  2236. {
  2237. local_lock(&local_A); /* IRQ-ON */
  2238. local_unlock(&local_A);
  2239. HARDIRQ_ENTER();
  2240. spin_lock(&lock_A); /* IN-IRQ */
  2241. spin_unlock(&lock_A);
  2242. HARDIRQ_EXIT()
  2243. HARDIRQ_DISABLE();
  2244. spin_lock(&lock_A);
  2245. local_lock(&local_A); /* IN-IRQ <-> IRQ-ON cycle, false */
  2246. local_unlock(&local_A);
  2247. spin_unlock(&lock_A);
  2248. HARDIRQ_ENABLE();
  2249. }
  2250. static void local_lock_3A(void)
  2251. {
  2252. local_lock(&local_A); /* IRQ-ON */
  2253. spin_lock(&lock_B); /* IRQ-ON */
  2254. spin_unlock(&lock_B);
  2255. local_unlock(&local_A);
  2256. HARDIRQ_ENTER();
  2257. spin_lock(&lock_A); /* IN-IRQ */
  2258. spin_unlock(&lock_A);
  2259. HARDIRQ_EXIT()
  2260. HARDIRQ_DISABLE();
  2261. spin_lock(&lock_A);
  2262. local_lock(&local_A); /* IN-IRQ <-> IRQ-ON cycle only if we count local_lock(), false */
  2263. local_unlock(&local_A);
  2264. spin_unlock(&lock_A);
  2265. HARDIRQ_ENABLE();
  2266. }
  2267. static void local_lock_3B(void)
  2268. {
  2269. local_lock(&local_A); /* IRQ-ON */
  2270. spin_lock(&lock_B); /* IRQ-ON */
  2271. spin_unlock(&lock_B);
  2272. local_unlock(&local_A);
  2273. HARDIRQ_ENTER();
  2274. spin_lock(&lock_A); /* IN-IRQ */
  2275. spin_unlock(&lock_A);
  2276. HARDIRQ_EXIT()
  2277. HARDIRQ_DISABLE();
  2278. spin_lock(&lock_A);
  2279. local_lock(&local_A); /* IN-IRQ <-> IRQ-ON cycle only if we count local_lock(), false */
  2280. local_unlock(&local_A);
  2281. spin_unlock(&lock_A);
  2282. HARDIRQ_ENABLE();
  2283. HARDIRQ_DISABLE();
  2284. spin_lock(&lock_A);
  2285. spin_lock(&lock_B); /* IN-IRQ <-> IRQ-ON cycle, true */
  2286. spin_unlock(&lock_B);
  2287. spin_unlock(&lock_A);
  2288. HARDIRQ_DISABLE();
  2289. }
  2290. static void local_lock_tests(void)
  2291. {
  2292. printk(" --------------------------------------------------------------------------\n");
  2293. printk(" | local_lock tests |\n");
  2294. printk(" ---------------------\n");
  2295. print_testname("local_lock inversion 2");
  2296. dotest(local_lock_2, SUCCESS, LOCKTYPE_LL);
  2297. pr_cont("\n");
  2298. print_testname("local_lock inversion 3A");
  2299. dotest(local_lock_3A, SUCCESS, LOCKTYPE_LL);
  2300. pr_cont("\n");
  2301. print_testname("local_lock inversion 3B");
  2302. dotest(local_lock_3B, FAILURE, LOCKTYPE_LL);
  2303. pr_cont("\n");
  2304. }
  2305. static void hardirq_deadlock_softirq_not_deadlock(void)
  2306. {
  2307. /* mutex_A is hardirq-unsafe and softirq-unsafe */
  2308. /* mutex_A -> lock_C */
  2309. mutex_lock(&mutex_A);
  2310. HARDIRQ_DISABLE();
  2311. spin_lock(&lock_C);
  2312. spin_unlock(&lock_C);
  2313. HARDIRQ_ENABLE();
  2314. mutex_unlock(&mutex_A);
  2315. /* lock_A is hardirq-safe */
  2316. HARDIRQ_ENTER();
  2317. spin_lock(&lock_A);
  2318. spin_unlock(&lock_A);
  2319. HARDIRQ_EXIT();
  2320. /* lock_A -> lock_B */
  2321. HARDIRQ_DISABLE();
  2322. spin_lock(&lock_A);
  2323. spin_lock(&lock_B);
  2324. spin_unlock(&lock_B);
  2325. spin_unlock(&lock_A);
  2326. HARDIRQ_ENABLE();
  2327. /* lock_B -> lock_C */
  2328. HARDIRQ_DISABLE();
  2329. spin_lock(&lock_B);
  2330. spin_lock(&lock_C);
  2331. spin_unlock(&lock_C);
  2332. spin_unlock(&lock_B);
  2333. HARDIRQ_ENABLE();
  2334. /* lock_D is softirq-safe */
  2335. SOFTIRQ_ENTER();
  2336. spin_lock(&lock_D);
  2337. spin_unlock(&lock_D);
  2338. SOFTIRQ_EXIT();
  2339. /* And lock_D is hardirq-unsafe */
  2340. SOFTIRQ_DISABLE();
  2341. spin_lock(&lock_D);
  2342. spin_unlock(&lock_D);
  2343. SOFTIRQ_ENABLE();
  2344. /*
  2345. * mutex_A -> lock_C -> lock_D is softirq-unsafe -> softirq-safe, not
  2346. * deadlock.
  2347. *
  2348. * lock_A -> lock_B -> lock_C -> lock_D is hardirq-safe ->
  2349. * hardirq-unsafe, deadlock.
  2350. */
  2351. HARDIRQ_DISABLE();
  2352. spin_lock(&lock_C);
  2353. spin_lock(&lock_D);
  2354. spin_unlock(&lock_D);
  2355. spin_unlock(&lock_C);
  2356. HARDIRQ_ENABLE();
  2357. }
  2358. void locking_selftest(void)
  2359. {
  2360. /*
  2361. * Got a locking failure before the selftest ran?
  2362. */
  2363. if (!debug_locks) {
  2364. printk("----------------------------------\n");
  2365. printk("| Locking API testsuite disabled |\n");
  2366. printk("----------------------------------\n");
  2367. return;
  2368. }
  2369. /*
  2370. * treats read_lock() as recursive read locks for testing purpose
  2371. */
  2372. force_read_lock_recursive = 1;
  2373. /*
  2374. * Run the testsuite:
  2375. */
  2376. printk("------------------------\n");
  2377. printk("| Locking API testsuite:\n");
  2378. printk("----------------------------------------------------------------------------\n");
  2379. printk(" | spin |wlock |rlock |mutex | wsem | rsem |rtmutex\n");
  2380. printk(" --------------------------------------------------------------------------\n");
  2381. init_shared_classes();
  2382. lockdep_set_selftest_task(current);
  2383. DO_TESTCASE_6R("A-A deadlock", AA);
  2384. DO_TESTCASE_6R("A-B-B-A deadlock", ABBA);
  2385. DO_TESTCASE_6R("A-B-B-C-C-A deadlock", ABBCCA);
  2386. DO_TESTCASE_6R("A-B-C-A-B-C deadlock", ABCABC);
  2387. DO_TESTCASE_6R("A-B-B-C-C-D-D-A deadlock", ABBCCDDA);
  2388. DO_TESTCASE_6R("A-B-C-D-B-D-D-A deadlock", ABCDBDDA);
  2389. DO_TESTCASE_6R("A-B-C-D-B-C-D-A deadlock", ABCDBCDA);
  2390. DO_TESTCASE_6("double unlock", double_unlock);
  2391. DO_TESTCASE_6("initialize held", init_held);
  2392. printk(" --------------------------------------------------------------------------\n");
  2393. print_testname("recursive read-lock");
  2394. pr_cont(" |");
  2395. dotest(rlock_AA1, SUCCESS, LOCKTYPE_RWLOCK);
  2396. pr_cont(" |");
  2397. dotest(rsem_AA1, FAILURE, LOCKTYPE_RWSEM);
  2398. pr_cont("\n");
  2399. print_testname("recursive read-lock #2");
  2400. pr_cont(" |");
  2401. dotest(rlock_AA1B, SUCCESS, LOCKTYPE_RWLOCK);
  2402. pr_cont(" |");
  2403. dotest(rsem_AA1B, FAILURE, LOCKTYPE_RWSEM);
  2404. pr_cont("\n");
  2405. print_testname("mixed read-write-lock");
  2406. pr_cont(" |");
  2407. dotest(rlock_AA2, FAILURE, LOCKTYPE_RWLOCK);
  2408. pr_cont(" |");
  2409. dotest(rsem_AA2, FAILURE, LOCKTYPE_RWSEM);
  2410. pr_cont("\n");
  2411. print_testname("mixed write-read-lock");
  2412. pr_cont(" |");
  2413. dotest(rlock_AA3, FAILURE, LOCKTYPE_RWLOCK);
  2414. pr_cont(" |");
  2415. dotest(rsem_AA3, FAILURE, LOCKTYPE_RWSEM);
  2416. pr_cont("\n");
  2417. print_testname("mixed read-lock/lock-write ABBA");
  2418. pr_cont(" |");
  2419. dotest(rlock_ABBA1, FAILURE, LOCKTYPE_RWLOCK);
  2420. pr_cont(" |");
  2421. dotest(rwsem_ABBA1, FAILURE, LOCKTYPE_RWSEM);
  2422. print_testname("mixed read-lock/lock-read ABBA");
  2423. pr_cont(" |");
  2424. dotest(rlock_ABBA2, SUCCESS, LOCKTYPE_RWLOCK);
  2425. pr_cont(" |");
  2426. dotest(rwsem_ABBA2, FAILURE, LOCKTYPE_RWSEM);
  2427. print_testname("mixed write-lock/lock-write ABBA");
  2428. pr_cont(" |");
  2429. dotest(rlock_ABBA3, FAILURE, LOCKTYPE_RWLOCK);
  2430. pr_cont(" |");
  2431. dotest(rwsem_ABBA3, FAILURE, LOCKTYPE_RWSEM);
  2432. print_testname("chain cached mixed R-L/L-W ABBA");
  2433. pr_cont(" |");
  2434. dotest(rlock_chaincache_ABBA1, FAILURE, LOCKTYPE_RWLOCK);
  2435. DO_TESTCASE_6x1RRB("rlock W1R2/W2R3/W3R1", W1R2_W2R3_W3R1);
  2436. DO_TESTCASE_6x1RRB("rlock W1W2/R2R3/W3R1", W1W2_R2R3_W3R1);
  2437. DO_TESTCASE_6x1RR("rlock W1W2/R2R3/R3W1", W1W2_R2R3_R3W1);
  2438. DO_TESTCASE_6x1RR("rlock W1R2/R2R3/W3W1", W1R2_R2R3_W3W1);
  2439. printk(" --------------------------------------------------------------------------\n");
  2440. /*
  2441. * irq-context testcases:
  2442. */
  2443. DO_TESTCASE_2x6("irqs-on + irq-safe-A", irqsafe1);
  2444. NON_RT(DO_TESTCASE_2x3("sirq-safe-A => hirqs-on", irqsafe2A));
  2445. DO_TESTCASE_2x6("safe-A + irqs-on", irqsafe2B);
  2446. DO_TESTCASE_6x6("safe-A + unsafe-B #1", irqsafe3);
  2447. DO_TESTCASE_6x6("safe-A + unsafe-B #2", irqsafe4);
  2448. DO_TESTCASE_6x6RW("irq lock-inversion", irq_inversion);
  2449. DO_TESTCASE_6x2x2RW("irq read-recursion", irq_read_recursion);
  2450. DO_TESTCASE_6x2x2RW("irq read-recursion #2", irq_read_recursion2);
  2451. DO_TESTCASE_6x2x2RW("irq read-recursion #3", irq_read_recursion3);
  2452. ww_tests();
  2453. force_read_lock_recursive = 0;
  2454. /*
  2455. * queued_read_lock() specific test cases can be put here
  2456. */
  2457. if (IS_ENABLED(CONFIG_QUEUED_RWLOCKS))
  2458. queued_read_lock_tests();
  2459. fs_reclaim_tests();
  2460. /* Wait context test cases that are specific for RAW_LOCK_NESTING */
  2461. if (IS_ENABLED(CONFIG_PROVE_RAW_LOCK_NESTING))
  2462. wait_context_tests();
  2463. local_lock_tests();
  2464. print_testname("hardirq_unsafe_softirq_safe");
  2465. dotest(hardirq_deadlock_softirq_not_deadlock, FAILURE, LOCKTYPE_SPECIAL);
  2466. pr_cont("\n");
  2467. if (unexpected_testcase_failures) {
  2468. printk("-----------------------------------------------------------------\n");
  2469. debug_locks = 0;
  2470. printk("BUG: %3d unexpected failures (out of %3d) - debugging disabled! |\n",
  2471. unexpected_testcase_failures, testcase_total);
  2472. printk("-----------------------------------------------------------------\n");
  2473. } else if (expected_testcase_failures && testcase_successes) {
  2474. printk("--------------------------------------------------------\n");
  2475. printk("%3d out of %3d testcases failed, as expected. |\n",
  2476. expected_testcase_failures, testcase_total);
  2477. printk("----------------------------------------------------\n");
  2478. debug_locks = 1;
  2479. } else if (expected_testcase_failures && !testcase_successes) {
  2480. printk("--------------------------------------------------------\n");
  2481. printk("All %3d testcases failed, as expected. |\n",
  2482. expected_testcase_failures);
  2483. printk("----------------------------------------\n");
  2484. debug_locks = 1;
  2485. } else {
  2486. printk("-------------------------------------------------------\n");
  2487. printk("Good, all %3d testcases passed! |\n",
  2488. testcase_successes);
  2489. printk("---------------------------------\n");
  2490. debug_locks = 1;
  2491. }
  2492. lockdep_set_selftest_task(NULL);
  2493. debug_locks_silent = 0;
  2494. }