rcutorture.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826
  1. /*
  2. * Read-Copy Update module-based torture test facility
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, you can access it online at
  16. * http://www.gnu.org/licenses/gpl-2.0.html.
  17. *
  18. * Copyright (C) IBM Corporation, 2005, 2006
  19. *
  20. * Authors: Paul E. McKenney <paulmck@us.ibm.com>
  21. * Josh Triplett <josh@joshtriplett.org>
  22. *
  23. * See also: Documentation/RCU/torture.txt
  24. */
  25. #include <linux/types.h>
  26. #include <linux/kernel.h>
  27. #include <linux/init.h>
  28. #include <linux/module.h>
  29. #include <linux/kthread.h>
  30. #include <linux/err.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/smp.h>
  33. #include <linux/rcupdate.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/sched.h>
  36. #include <linux/atomic.h>
  37. #include <linux/bitops.h>
  38. #include <linux/completion.h>
  39. #include <linux/moduleparam.h>
  40. #include <linux/percpu.h>
  41. #include <linux/notifier.h>
  42. #include <linux/reboot.h>
  43. #include <linux/freezer.h>
  44. #include <linux/cpu.h>
  45. #include <linux/delay.h>
  46. #include <linux/stat.h>
  47. #include <linux/srcu.h>
  48. #include <linux/slab.h>
  49. #include <linux/trace_clock.h>
  50. #include <asm/byteorder.h>
  51. #include <linux/torture.h>
  52. #include <linux/vmalloc.h>
  53. MODULE_LICENSE("GPL");
  54. MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@joshtriplett.org>");
  55. torture_param(int, cbflood_inter_holdoff, HZ,
  56. "Holdoff between floods (jiffies)");
  57. torture_param(int, cbflood_intra_holdoff, 1,
  58. "Holdoff between bursts (jiffies)");
  59. torture_param(int, cbflood_n_burst, 3, "# bursts in flood, zero to disable");
  60. torture_param(int, cbflood_n_per_burst, 20000,
  61. "# callbacks per burst in flood");
  62. torture_param(int, fqs_duration, 0,
  63. "Duration of fqs bursts (us), 0 to disable");
  64. torture_param(int, fqs_holdoff, 0, "Holdoff time within fqs bursts (us)");
  65. torture_param(int, fqs_stutter, 3, "Wait time between fqs bursts (s)");
  66. torture_param(bool, gp_cond, false, "Use conditional/async GP wait primitives");
  67. torture_param(bool, gp_exp, false, "Use expedited GP wait primitives");
  68. torture_param(bool, gp_normal, false,
  69. "Use normal (non-expedited) GP wait primitives");
  70. torture_param(bool, gp_sync, false, "Use synchronous GP wait primitives");
  71. torture_param(int, irqreader, 1, "Allow RCU readers from irq handlers");
  72. torture_param(int, n_barrier_cbs, 0,
  73. "# of callbacks/kthreads for barrier testing");
  74. torture_param(int, nfakewriters, 4, "Number of RCU fake writer threads");
  75. torture_param(int, nreaders, -1, "Number of RCU reader threads");
  76. torture_param(int, object_debug, 0,
  77. "Enable debug-object double call_rcu() testing");
  78. torture_param(int, onoff_holdoff, 0, "Time after boot before CPU hotplugs (s)");
  79. torture_param(int, onoff_interval, 0,
  80. "Time between CPU hotplugs (s), 0=disable");
  81. torture_param(int, shuffle_interval, 3, "Number of seconds between shuffles");
  82. torture_param(int, shutdown_secs, 0, "Shutdown time (s), <= zero to disable.");
  83. torture_param(int, stall_cpu, 0, "Stall duration (s), zero to disable.");
  84. torture_param(int, stall_cpu_holdoff, 10,
  85. "Time to wait before starting stall (s).");
  86. torture_param(int, stat_interval, 60,
  87. "Number of seconds between stats printk()s");
  88. torture_param(int, stutter, 5, "Number of seconds to run/halt test");
  89. torture_param(int, test_boost, 1, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
  90. torture_param(int, test_boost_duration, 4,
  91. "Duration of each boost test, seconds.");
  92. torture_param(int, test_boost_interval, 7,
  93. "Interval between boost tests, seconds.");
  94. torture_param(bool, test_no_idle_hz, true,
  95. "Test support for tickless idle CPUs");
  96. torture_param(bool, verbose, true,
  97. "Enable verbose debugging printk()s");
  98. static char *torture_type = "rcu";
  99. module_param(torture_type, charp, 0444);
  100. MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, ...)");
  101. static int nrealreaders;
  102. static int ncbflooders;
  103. static struct task_struct *writer_task;
  104. static struct task_struct **fakewriter_tasks;
  105. static struct task_struct **reader_tasks;
  106. static struct task_struct *stats_task;
  107. static struct task_struct **cbflood_task;
  108. static struct task_struct *fqs_task;
  109. static struct task_struct *boost_tasks[NR_CPUS];
  110. static struct task_struct *stall_task;
  111. static struct task_struct **barrier_cbs_tasks;
  112. static struct task_struct *barrier_task;
  113. #define RCU_TORTURE_PIPE_LEN 10
  114. struct rcu_torture {
  115. struct rcu_head rtort_rcu;
  116. int rtort_pipe_count;
  117. struct list_head rtort_free;
  118. int rtort_mbtest;
  119. };
  120. static LIST_HEAD(rcu_torture_freelist);
  121. static struct rcu_torture __rcu *rcu_torture_current;
  122. static unsigned long rcu_torture_current_version;
  123. static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
  124. static DEFINE_SPINLOCK(rcu_torture_lock);
  125. static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
  126. rcu_torture_count) = { 0 };
  127. static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
  128. rcu_torture_batch) = { 0 };
  129. static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
  130. static atomic_t n_rcu_torture_alloc;
  131. static atomic_t n_rcu_torture_alloc_fail;
  132. static atomic_t n_rcu_torture_free;
  133. static atomic_t n_rcu_torture_mberror;
  134. static atomic_t n_rcu_torture_error;
  135. static long n_rcu_torture_barrier_error;
  136. static long n_rcu_torture_boost_ktrerror;
  137. static long n_rcu_torture_boost_rterror;
  138. static long n_rcu_torture_boost_failure;
  139. static long n_rcu_torture_boosts;
  140. static long n_rcu_torture_timers;
  141. static long n_barrier_attempts;
  142. static long n_barrier_successes;
  143. static atomic_long_t n_cbfloods;
  144. static struct list_head rcu_torture_removed;
  145. static int rcu_torture_writer_state;
  146. #define RTWS_FIXED_DELAY 0
  147. #define RTWS_DELAY 1
  148. #define RTWS_REPLACE 2
  149. #define RTWS_DEF_FREE 3
  150. #define RTWS_EXP_SYNC 4
  151. #define RTWS_COND_GET 5
  152. #define RTWS_COND_SYNC 6
  153. #define RTWS_SYNC 7
  154. #define RTWS_STUTTER 8
  155. #define RTWS_STOPPING 9
  156. #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
  157. #define RCUTORTURE_RUNNABLE_INIT 1
  158. #else
  159. #define RCUTORTURE_RUNNABLE_INIT 0
  160. #endif
  161. static int torture_runnable = RCUTORTURE_RUNNABLE_INIT;
  162. module_param(torture_runnable, int, 0444);
  163. MODULE_PARM_DESC(torture_runnable, "Start rcutorture at boot");
  164. #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
  165. #define rcu_can_boost() 1
  166. #else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
  167. #define rcu_can_boost() 0
  168. #endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
  169. #ifdef CONFIG_RCU_TRACE
  170. static u64 notrace rcu_trace_clock_local(void)
  171. {
  172. u64 ts = trace_clock_local();
  173. unsigned long __maybe_unused ts_rem = do_div(ts, NSEC_PER_USEC);
  174. return ts;
  175. }
  176. #else /* #ifdef CONFIG_RCU_TRACE */
  177. static u64 notrace rcu_trace_clock_local(void)
  178. {
  179. return 0ULL;
  180. }
  181. #endif /* #else #ifdef CONFIG_RCU_TRACE */
  182. static unsigned long boost_starttime; /* jiffies of next boost test start. */
  183. static DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
  184. /* and boost task create/destroy. */
  185. static atomic_t barrier_cbs_count; /* Barrier callbacks registered. */
  186. static bool barrier_phase; /* Test phase. */
  187. static atomic_t barrier_cbs_invoked; /* Barrier callbacks invoked. */
  188. static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */
  189. static DECLARE_WAIT_QUEUE_HEAD(barrier_wq);
  190. /*
  191. * Allocate an element from the rcu_tortures pool.
  192. */
  193. static struct rcu_torture *
  194. rcu_torture_alloc(void)
  195. {
  196. struct list_head *p;
  197. spin_lock_bh(&rcu_torture_lock);
  198. if (list_empty(&rcu_torture_freelist)) {
  199. atomic_inc(&n_rcu_torture_alloc_fail);
  200. spin_unlock_bh(&rcu_torture_lock);
  201. return NULL;
  202. }
  203. atomic_inc(&n_rcu_torture_alloc);
  204. p = rcu_torture_freelist.next;
  205. list_del_init(p);
  206. spin_unlock_bh(&rcu_torture_lock);
  207. return container_of(p, struct rcu_torture, rtort_free);
  208. }
  209. /*
  210. * Free an element to the rcu_tortures pool.
  211. */
  212. static void
  213. rcu_torture_free(struct rcu_torture *p)
  214. {
  215. atomic_inc(&n_rcu_torture_free);
  216. spin_lock_bh(&rcu_torture_lock);
  217. list_add_tail(&p->rtort_free, &rcu_torture_freelist);
  218. spin_unlock_bh(&rcu_torture_lock);
  219. }
  220. /*
  221. * Operations vector for selecting different types of tests.
  222. */
  223. struct rcu_torture_ops {
  224. int ttype;
  225. void (*init)(void);
  226. int (*readlock)(void);
  227. void (*read_delay)(struct torture_random_state *rrsp);
  228. void (*readunlock)(int idx);
  229. int (*completed)(void);
  230. void (*deferred_free)(struct rcu_torture *p);
  231. void (*sync)(void);
  232. void (*exp_sync)(void);
  233. unsigned long (*get_state)(void);
  234. void (*cond_sync)(unsigned long oldstate);
  235. void (*call)(struct rcu_head *head, void (*func)(struct rcu_head *rcu));
  236. void (*cb_barrier)(void);
  237. void (*fqs)(void);
  238. void (*stats)(void);
  239. int irq_capable;
  240. int can_boost;
  241. const char *name;
  242. };
  243. static struct rcu_torture_ops *cur_ops;
  244. /*
  245. * Definitions for rcu torture testing.
  246. */
  247. static int rcu_torture_read_lock(void) __acquires(RCU)
  248. {
  249. rcu_read_lock();
  250. return 0;
  251. }
  252. static void rcu_read_delay(struct torture_random_state *rrsp)
  253. {
  254. const unsigned long shortdelay_us = 200;
  255. const unsigned long longdelay_ms = 50;
  256. /* We want a short delay sometimes to make a reader delay the grace
  257. * period, and we want a long delay occasionally to trigger
  258. * force_quiescent_state. */
  259. if (!(torture_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
  260. mdelay(longdelay_ms);
  261. if (!(torture_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
  262. udelay(shortdelay_us);
  263. #ifdef CONFIG_PREEMPT
  264. if (!preempt_count() &&
  265. !(torture_random(rrsp) % (nrealreaders * 20000)))
  266. preempt_schedule(); /* No QS if preempt_disable() in effect */
  267. #endif
  268. }
  269. static void rcu_torture_read_unlock(int idx) __releases(RCU)
  270. {
  271. rcu_read_unlock();
  272. }
  273. static int rcu_torture_completed(void)
  274. {
  275. return rcu_batches_completed();
  276. }
  277. /*
  278. * Update callback in the pipe. This should be invoked after a grace period.
  279. */
  280. static bool
  281. rcu_torture_pipe_update_one(struct rcu_torture *rp)
  282. {
  283. int i;
  284. i = rp->rtort_pipe_count;
  285. if (i > RCU_TORTURE_PIPE_LEN)
  286. i = RCU_TORTURE_PIPE_LEN;
  287. atomic_inc(&rcu_torture_wcount[i]);
  288. if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
  289. rp->rtort_mbtest = 0;
  290. return true;
  291. }
  292. return false;
  293. }
  294. /*
  295. * Update all callbacks in the pipe. Suitable for synchronous grace-period
  296. * primitives.
  297. */
  298. static void
  299. rcu_torture_pipe_update(struct rcu_torture *old_rp)
  300. {
  301. struct rcu_torture *rp;
  302. struct rcu_torture *rp1;
  303. if (old_rp)
  304. list_add(&old_rp->rtort_free, &rcu_torture_removed);
  305. list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
  306. if (rcu_torture_pipe_update_one(rp)) {
  307. list_del(&rp->rtort_free);
  308. rcu_torture_free(rp);
  309. }
  310. }
  311. }
  312. static void
  313. rcu_torture_cb(struct rcu_head *p)
  314. {
  315. struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
  316. if (torture_must_stop_irq()) {
  317. /* Test is ending, just drop callbacks on the floor. */
  318. /* The next initialization will pick up the pieces. */
  319. return;
  320. }
  321. if (rcu_torture_pipe_update_one(rp))
  322. rcu_torture_free(rp);
  323. else
  324. cur_ops->deferred_free(rp);
  325. }
  326. static int rcu_no_completed(void)
  327. {
  328. return 0;
  329. }
  330. static void rcu_torture_deferred_free(struct rcu_torture *p)
  331. {
  332. call_rcu(&p->rtort_rcu, rcu_torture_cb);
  333. }
  334. static void rcu_sync_torture_init(void)
  335. {
  336. INIT_LIST_HEAD(&rcu_torture_removed);
  337. }
  338. static struct rcu_torture_ops rcu_ops = {
  339. .ttype = RCU_FLAVOR,
  340. .init = rcu_sync_torture_init,
  341. .readlock = rcu_torture_read_lock,
  342. .read_delay = rcu_read_delay,
  343. .readunlock = rcu_torture_read_unlock,
  344. .completed = rcu_torture_completed,
  345. .deferred_free = rcu_torture_deferred_free,
  346. .sync = synchronize_rcu,
  347. .exp_sync = synchronize_rcu_expedited,
  348. .get_state = get_state_synchronize_rcu,
  349. .cond_sync = cond_synchronize_rcu,
  350. .call = call_rcu,
  351. .cb_barrier = rcu_barrier,
  352. .fqs = rcu_force_quiescent_state,
  353. .stats = NULL,
  354. .irq_capable = 1,
  355. .can_boost = rcu_can_boost(),
  356. .name = "rcu"
  357. };
  358. /*
  359. * Definitions for rcu_bh torture testing.
  360. */
  361. static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
  362. {
  363. rcu_read_lock_bh();
  364. return 0;
  365. }
  366. static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
  367. {
  368. rcu_read_unlock_bh();
  369. }
  370. static int rcu_bh_torture_completed(void)
  371. {
  372. return rcu_batches_completed_bh();
  373. }
  374. static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
  375. {
  376. call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
  377. }
  378. static struct rcu_torture_ops rcu_bh_ops = {
  379. .ttype = RCU_BH_FLAVOR,
  380. .init = rcu_sync_torture_init,
  381. .readlock = rcu_bh_torture_read_lock,
  382. .read_delay = rcu_read_delay, /* just reuse rcu's version. */
  383. .readunlock = rcu_bh_torture_read_unlock,
  384. .completed = rcu_bh_torture_completed,
  385. .deferred_free = rcu_bh_torture_deferred_free,
  386. .sync = synchronize_rcu_bh,
  387. .exp_sync = synchronize_rcu_bh_expedited,
  388. .call = call_rcu_bh,
  389. .cb_barrier = rcu_barrier_bh,
  390. .fqs = rcu_bh_force_quiescent_state,
  391. .stats = NULL,
  392. .irq_capable = 1,
  393. .name = "rcu_bh"
  394. };
  395. /*
  396. * Don't even think about trying any of these in real life!!!
  397. * The names includes "busted", and they really means it!
  398. * The only purpose of these functions is to provide a buggy RCU
  399. * implementation to make sure that rcutorture correctly emits
  400. * buggy-RCU error messages.
  401. */
  402. static void rcu_busted_torture_deferred_free(struct rcu_torture *p)
  403. {
  404. /* This is a deliberate bug for testing purposes only! */
  405. rcu_torture_cb(&p->rtort_rcu);
  406. }
  407. static void synchronize_rcu_busted(void)
  408. {
  409. /* This is a deliberate bug for testing purposes only! */
  410. }
  411. static void
  412. call_rcu_busted(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
  413. {
  414. /* This is a deliberate bug for testing purposes only! */
  415. func(head);
  416. }
  417. static struct rcu_torture_ops rcu_busted_ops = {
  418. .ttype = INVALID_RCU_FLAVOR,
  419. .init = rcu_sync_torture_init,
  420. .readlock = rcu_torture_read_lock,
  421. .read_delay = rcu_read_delay, /* just reuse rcu's version. */
  422. .readunlock = rcu_torture_read_unlock,
  423. .completed = rcu_no_completed,
  424. .deferred_free = rcu_busted_torture_deferred_free,
  425. .sync = synchronize_rcu_busted,
  426. .exp_sync = synchronize_rcu_busted,
  427. .call = call_rcu_busted,
  428. .cb_barrier = NULL,
  429. .fqs = NULL,
  430. .stats = NULL,
  431. .irq_capable = 1,
  432. .name = "rcu_busted"
  433. };
  434. /*
  435. * Definitions for srcu torture testing.
  436. */
  437. DEFINE_STATIC_SRCU(srcu_ctl);
  438. static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
  439. {
  440. return srcu_read_lock(&srcu_ctl);
  441. }
  442. static void srcu_read_delay(struct torture_random_state *rrsp)
  443. {
  444. long delay;
  445. const long uspertick = 1000000 / HZ;
  446. const long longdelay = 10;
  447. /* We want there to be long-running readers, but not all the time. */
  448. delay = torture_random(rrsp) %
  449. (nrealreaders * 2 * longdelay * uspertick);
  450. if (!delay)
  451. schedule_timeout_interruptible(longdelay);
  452. else
  453. rcu_read_delay(rrsp);
  454. }
  455. static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
  456. {
  457. srcu_read_unlock(&srcu_ctl, idx);
  458. }
  459. static int srcu_torture_completed(void)
  460. {
  461. return srcu_batches_completed(&srcu_ctl);
  462. }
  463. static void srcu_torture_deferred_free(struct rcu_torture *rp)
  464. {
  465. call_srcu(&srcu_ctl, &rp->rtort_rcu, rcu_torture_cb);
  466. }
  467. static void srcu_torture_synchronize(void)
  468. {
  469. synchronize_srcu(&srcu_ctl);
  470. }
  471. static void srcu_torture_call(struct rcu_head *head,
  472. void (*func)(struct rcu_head *head))
  473. {
  474. call_srcu(&srcu_ctl, head, func);
  475. }
  476. static void srcu_torture_barrier(void)
  477. {
  478. srcu_barrier(&srcu_ctl);
  479. }
  480. static void srcu_torture_stats(void)
  481. {
  482. int cpu;
  483. int idx = srcu_ctl.completed & 0x1;
  484. pr_alert("%s%s per-CPU(idx=%d):",
  485. torture_type, TORTURE_FLAG, idx);
  486. for_each_possible_cpu(cpu) {
  487. long c0, c1;
  488. c0 = (long)per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx];
  489. c1 = (long)per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx];
  490. pr_cont(" %d(%ld,%ld)", cpu, c0, c1);
  491. }
  492. pr_cont("\n");
  493. }
  494. static void srcu_torture_synchronize_expedited(void)
  495. {
  496. synchronize_srcu_expedited(&srcu_ctl);
  497. }
  498. static struct rcu_torture_ops srcu_ops = {
  499. .ttype = SRCU_FLAVOR,
  500. .init = rcu_sync_torture_init,
  501. .readlock = srcu_torture_read_lock,
  502. .read_delay = srcu_read_delay,
  503. .readunlock = srcu_torture_read_unlock,
  504. .completed = srcu_torture_completed,
  505. .deferred_free = srcu_torture_deferred_free,
  506. .sync = srcu_torture_synchronize,
  507. .exp_sync = srcu_torture_synchronize_expedited,
  508. .call = srcu_torture_call,
  509. .cb_barrier = srcu_torture_barrier,
  510. .stats = srcu_torture_stats,
  511. .name = "srcu"
  512. };
  513. /*
  514. * Definitions for sched torture testing.
  515. */
  516. static int sched_torture_read_lock(void)
  517. {
  518. preempt_disable();
  519. return 0;
  520. }
  521. static void sched_torture_read_unlock(int idx)
  522. {
  523. preempt_enable();
  524. }
  525. static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
  526. {
  527. call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
  528. }
  529. static struct rcu_torture_ops sched_ops = {
  530. .ttype = RCU_SCHED_FLAVOR,
  531. .init = rcu_sync_torture_init,
  532. .readlock = sched_torture_read_lock,
  533. .read_delay = rcu_read_delay, /* just reuse rcu's version. */
  534. .readunlock = sched_torture_read_unlock,
  535. .completed = rcu_no_completed,
  536. .deferred_free = rcu_sched_torture_deferred_free,
  537. .sync = synchronize_sched,
  538. .exp_sync = synchronize_sched_expedited,
  539. .call = call_rcu_sched,
  540. .cb_barrier = rcu_barrier_sched,
  541. .fqs = rcu_sched_force_quiescent_state,
  542. .stats = NULL,
  543. .irq_capable = 1,
  544. .name = "sched"
  545. };
  546. #ifdef CONFIG_TASKS_RCU
  547. /*
  548. * Definitions for RCU-tasks torture testing.
  549. */
  550. static int tasks_torture_read_lock(void)
  551. {
  552. return 0;
  553. }
  554. static void tasks_torture_read_unlock(int idx)
  555. {
  556. }
  557. static void rcu_tasks_torture_deferred_free(struct rcu_torture *p)
  558. {
  559. call_rcu_tasks(&p->rtort_rcu, rcu_torture_cb);
  560. }
  561. static struct rcu_torture_ops tasks_ops = {
  562. .ttype = RCU_TASKS_FLAVOR,
  563. .init = rcu_sync_torture_init,
  564. .readlock = tasks_torture_read_lock,
  565. .read_delay = rcu_read_delay, /* just reuse rcu's version. */
  566. .readunlock = tasks_torture_read_unlock,
  567. .completed = rcu_no_completed,
  568. .deferred_free = rcu_tasks_torture_deferred_free,
  569. .sync = synchronize_rcu_tasks,
  570. .exp_sync = synchronize_rcu_tasks,
  571. .call = call_rcu_tasks,
  572. .cb_barrier = rcu_barrier_tasks,
  573. .fqs = NULL,
  574. .stats = NULL,
  575. .irq_capable = 1,
  576. .name = "tasks"
  577. };
  578. #define RCUTORTURE_TASKS_OPS &tasks_ops,
  579. #else /* #ifdef CONFIG_TASKS_RCU */
  580. #define RCUTORTURE_TASKS_OPS
  581. #endif /* #else #ifdef CONFIG_TASKS_RCU */
  582. /*
  583. * RCU torture priority-boost testing. Runs one real-time thread per
  584. * CPU for moderate bursts, repeatedly registering RCU callbacks and
  585. * spinning waiting for them to be invoked. If a given callback takes
  586. * too long to be invoked, we assume that priority inversion has occurred.
  587. */
  588. struct rcu_boost_inflight {
  589. struct rcu_head rcu;
  590. int inflight;
  591. };
  592. static void rcu_torture_boost_cb(struct rcu_head *head)
  593. {
  594. struct rcu_boost_inflight *rbip =
  595. container_of(head, struct rcu_boost_inflight, rcu);
  596. smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
  597. rbip->inflight = 0;
  598. }
  599. static int rcu_torture_boost(void *arg)
  600. {
  601. unsigned long call_rcu_time;
  602. unsigned long endtime;
  603. unsigned long oldstarttime;
  604. struct rcu_boost_inflight rbi = { .inflight = 0 };
  605. struct sched_param sp;
  606. VERBOSE_TOROUT_STRING("rcu_torture_boost started");
  607. /* Set real-time priority. */
  608. sp.sched_priority = 1;
  609. if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
  610. VERBOSE_TOROUT_STRING("rcu_torture_boost RT prio failed!");
  611. n_rcu_torture_boost_rterror++;
  612. }
  613. init_rcu_head_on_stack(&rbi.rcu);
  614. /* Each pass through the following loop does one boost-test cycle. */
  615. do {
  616. /* Wait for the next test interval. */
  617. oldstarttime = boost_starttime;
  618. while (ULONG_CMP_LT(jiffies, oldstarttime)) {
  619. schedule_timeout_interruptible(oldstarttime - jiffies);
  620. stutter_wait("rcu_torture_boost");
  621. if (torture_must_stop())
  622. goto checkwait;
  623. }
  624. /* Do one boost-test interval. */
  625. endtime = oldstarttime + test_boost_duration * HZ;
  626. call_rcu_time = jiffies;
  627. while (ULONG_CMP_LT(jiffies, endtime)) {
  628. /* If we don't have a callback in flight, post one. */
  629. if (!rbi.inflight) {
  630. smp_mb(); /* RCU core before ->inflight = 1. */
  631. rbi.inflight = 1;
  632. call_rcu(&rbi.rcu, rcu_torture_boost_cb);
  633. if (jiffies - call_rcu_time >
  634. test_boost_duration * HZ - HZ / 2) {
  635. VERBOSE_TOROUT_STRING("rcu_torture_boost boosting failed");
  636. n_rcu_torture_boost_failure++;
  637. }
  638. call_rcu_time = jiffies;
  639. }
  640. cond_resched_rcu_qs();
  641. stutter_wait("rcu_torture_boost");
  642. if (torture_must_stop())
  643. goto checkwait;
  644. }
  645. /*
  646. * Set the start time of the next test interval.
  647. * Yes, this is vulnerable to long delays, but such
  648. * delays simply cause a false negative for the next
  649. * interval. Besides, we are running at RT priority,
  650. * so delays should be relatively rare.
  651. */
  652. while (oldstarttime == boost_starttime &&
  653. !kthread_should_stop()) {
  654. if (mutex_trylock(&boost_mutex)) {
  655. boost_starttime = jiffies +
  656. test_boost_interval * HZ;
  657. n_rcu_torture_boosts++;
  658. mutex_unlock(&boost_mutex);
  659. break;
  660. }
  661. schedule_timeout_uninterruptible(1);
  662. }
  663. /* Go do the stutter. */
  664. checkwait: stutter_wait("rcu_torture_boost");
  665. } while (!torture_must_stop());
  666. /* Clean up and exit. */
  667. while (!kthread_should_stop() || rbi.inflight) {
  668. torture_shutdown_absorb("rcu_torture_boost");
  669. schedule_timeout_uninterruptible(1);
  670. }
  671. smp_mb(); /* order accesses to ->inflight before stack-frame death. */
  672. destroy_rcu_head_on_stack(&rbi.rcu);
  673. torture_kthread_stopping("rcu_torture_boost");
  674. return 0;
  675. }
  676. static void rcu_torture_cbflood_cb(struct rcu_head *rhp)
  677. {
  678. }
  679. /*
  680. * RCU torture callback-flood kthread. Repeatedly induces bursts of calls
  681. * to call_rcu() or analogous, increasing the probability of occurrence
  682. * of callback-overflow corner cases.
  683. */
  684. static int
  685. rcu_torture_cbflood(void *arg)
  686. {
  687. int err = 1;
  688. int i;
  689. int j;
  690. struct rcu_head *rhp;
  691. if (cbflood_n_per_burst > 0 &&
  692. cbflood_inter_holdoff > 0 &&
  693. cbflood_intra_holdoff > 0 &&
  694. cur_ops->call &&
  695. cur_ops->cb_barrier) {
  696. rhp = vmalloc(sizeof(*rhp) *
  697. cbflood_n_burst * cbflood_n_per_burst);
  698. err = !rhp;
  699. }
  700. if (err) {
  701. VERBOSE_TOROUT_STRING("rcu_torture_cbflood disabled: Bad args or OOM");
  702. while (!torture_must_stop())
  703. schedule_timeout_interruptible(HZ);
  704. return 0;
  705. }
  706. VERBOSE_TOROUT_STRING("rcu_torture_cbflood task started");
  707. do {
  708. schedule_timeout_interruptible(cbflood_inter_holdoff);
  709. atomic_long_inc(&n_cbfloods);
  710. WARN_ON(signal_pending(current));
  711. for (i = 0; i < cbflood_n_burst; i++) {
  712. for (j = 0; j < cbflood_n_per_burst; j++) {
  713. cur_ops->call(&rhp[i * cbflood_n_per_burst + j],
  714. rcu_torture_cbflood_cb);
  715. }
  716. schedule_timeout_interruptible(cbflood_intra_holdoff);
  717. WARN_ON(signal_pending(current));
  718. }
  719. cur_ops->cb_barrier();
  720. stutter_wait("rcu_torture_cbflood");
  721. } while (!torture_must_stop());
  722. vfree(rhp);
  723. torture_kthread_stopping("rcu_torture_cbflood");
  724. return 0;
  725. }
  726. /*
  727. * RCU torture force-quiescent-state kthread. Repeatedly induces
  728. * bursts of calls to force_quiescent_state(), increasing the probability
  729. * of occurrence of some important types of race conditions.
  730. */
  731. static int
  732. rcu_torture_fqs(void *arg)
  733. {
  734. unsigned long fqs_resume_time;
  735. int fqs_burst_remaining;
  736. VERBOSE_TOROUT_STRING("rcu_torture_fqs task started");
  737. do {
  738. fqs_resume_time = jiffies + fqs_stutter * HZ;
  739. while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
  740. !kthread_should_stop()) {
  741. schedule_timeout_interruptible(1);
  742. }
  743. fqs_burst_remaining = fqs_duration;
  744. while (fqs_burst_remaining > 0 &&
  745. !kthread_should_stop()) {
  746. cur_ops->fqs();
  747. udelay(fqs_holdoff);
  748. fqs_burst_remaining -= fqs_holdoff;
  749. }
  750. stutter_wait("rcu_torture_fqs");
  751. } while (!torture_must_stop());
  752. torture_kthread_stopping("rcu_torture_fqs");
  753. return 0;
  754. }
  755. /*
  756. * RCU torture writer kthread. Repeatedly substitutes a new structure
  757. * for that pointed to by rcu_torture_current, freeing the old structure
  758. * after a series of grace periods (the "pipeline").
  759. */
  760. static int
  761. rcu_torture_writer(void *arg)
  762. {
  763. unsigned long gp_snap;
  764. bool gp_cond1 = gp_cond, gp_exp1 = gp_exp, gp_normal1 = gp_normal;
  765. bool gp_sync1 = gp_sync;
  766. int i;
  767. struct rcu_torture *rp;
  768. struct rcu_torture *old_rp;
  769. static DEFINE_TORTURE_RANDOM(rand);
  770. int synctype[] = { RTWS_DEF_FREE, RTWS_EXP_SYNC,
  771. RTWS_COND_GET, RTWS_SYNC };
  772. int nsynctypes = 0;
  773. VERBOSE_TOROUT_STRING("rcu_torture_writer task started");
  774. /* Initialize synctype[] array. If none set, take default. */
  775. if (!gp_cond1 && !gp_exp1 && !gp_normal1 && !gp_sync)
  776. gp_cond1 = gp_exp1 = gp_normal1 = gp_sync1 = true;
  777. if (gp_cond1 && cur_ops->get_state && cur_ops->cond_sync)
  778. synctype[nsynctypes++] = RTWS_COND_GET;
  779. else if (gp_cond && (!cur_ops->get_state || !cur_ops->cond_sync))
  780. pr_alert("rcu_torture_writer: gp_cond without primitives.\n");
  781. if (gp_exp1 && cur_ops->exp_sync)
  782. synctype[nsynctypes++] = RTWS_EXP_SYNC;
  783. else if (gp_exp && !cur_ops->exp_sync)
  784. pr_alert("rcu_torture_writer: gp_exp without primitives.\n");
  785. if (gp_normal1 && cur_ops->deferred_free)
  786. synctype[nsynctypes++] = RTWS_DEF_FREE;
  787. else if (gp_normal && !cur_ops->deferred_free)
  788. pr_alert("rcu_torture_writer: gp_normal without primitives.\n");
  789. if (gp_sync1 && cur_ops->sync)
  790. synctype[nsynctypes++] = RTWS_SYNC;
  791. else if (gp_sync && !cur_ops->sync)
  792. pr_alert("rcu_torture_writer: gp_sync without primitives.\n");
  793. if (WARN_ONCE(nsynctypes == 0,
  794. "rcu_torture_writer: No update-side primitives.\n")) {
  795. /*
  796. * No updates primitives, so don't try updating.
  797. * The resulting test won't be testing much, hence the
  798. * above WARN_ONCE().
  799. */
  800. rcu_torture_writer_state = RTWS_STOPPING;
  801. torture_kthread_stopping("rcu_torture_writer");
  802. }
  803. do {
  804. rcu_torture_writer_state = RTWS_FIXED_DELAY;
  805. schedule_timeout_uninterruptible(1);
  806. rp = rcu_torture_alloc();
  807. if (rp == NULL)
  808. continue;
  809. rp->rtort_pipe_count = 0;
  810. rcu_torture_writer_state = RTWS_DELAY;
  811. udelay(torture_random(&rand) & 0x3ff);
  812. rcu_torture_writer_state = RTWS_REPLACE;
  813. old_rp = rcu_dereference_check(rcu_torture_current,
  814. current == writer_task);
  815. rp->rtort_mbtest = 1;
  816. rcu_assign_pointer(rcu_torture_current, rp);
  817. smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
  818. if (old_rp) {
  819. i = old_rp->rtort_pipe_count;
  820. if (i > RCU_TORTURE_PIPE_LEN)
  821. i = RCU_TORTURE_PIPE_LEN;
  822. atomic_inc(&rcu_torture_wcount[i]);
  823. old_rp->rtort_pipe_count++;
  824. switch (synctype[torture_random(&rand) % nsynctypes]) {
  825. case RTWS_DEF_FREE:
  826. rcu_torture_writer_state = RTWS_DEF_FREE;
  827. cur_ops->deferred_free(old_rp);
  828. break;
  829. case RTWS_EXP_SYNC:
  830. rcu_torture_writer_state = RTWS_EXP_SYNC;
  831. cur_ops->exp_sync();
  832. rcu_torture_pipe_update(old_rp);
  833. break;
  834. case RTWS_COND_GET:
  835. rcu_torture_writer_state = RTWS_COND_GET;
  836. gp_snap = cur_ops->get_state();
  837. i = torture_random(&rand) % 16;
  838. if (i != 0)
  839. schedule_timeout_interruptible(i);
  840. udelay(torture_random(&rand) % 1000);
  841. rcu_torture_writer_state = RTWS_COND_SYNC;
  842. cur_ops->cond_sync(gp_snap);
  843. rcu_torture_pipe_update(old_rp);
  844. break;
  845. case RTWS_SYNC:
  846. rcu_torture_writer_state = RTWS_SYNC;
  847. cur_ops->sync();
  848. rcu_torture_pipe_update(old_rp);
  849. break;
  850. default:
  851. WARN_ON_ONCE(1);
  852. break;
  853. }
  854. }
  855. rcutorture_record_progress(++rcu_torture_current_version);
  856. rcu_torture_writer_state = RTWS_STUTTER;
  857. stutter_wait("rcu_torture_writer");
  858. } while (!torture_must_stop());
  859. rcu_torture_writer_state = RTWS_STOPPING;
  860. torture_kthread_stopping("rcu_torture_writer");
  861. return 0;
  862. }
  863. /*
  864. * RCU torture fake writer kthread. Repeatedly calls sync, with a random
  865. * delay between calls.
  866. */
  867. static int
  868. rcu_torture_fakewriter(void *arg)
  869. {
  870. DEFINE_TORTURE_RANDOM(rand);
  871. VERBOSE_TOROUT_STRING("rcu_torture_fakewriter task started");
  872. set_user_nice(current, MAX_NICE);
  873. do {
  874. schedule_timeout_uninterruptible(1 + torture_random(&rand)%10);
  875. udelay(torture_random(&rand) & 0x3ff);
  876. if (cur_ops->cb_barrier != NULL &&
  877. torture_random(&rand) % (nfakewriters * 8) == 0) {
  878. cur_ops->cb_barrier();
  879. } else if (gp_normal == gp_exp) {
  880. if (torture_random(&rand) & 0x80)
  881. cur_ops->sync();
  882. else
  883. cur_ops->exp_sync();
  884. } else if (gp_normal) {
  885. cur_ops->sync();
  886. } else {
  887. cur_ops->exp_sync();
  888. }
  889. stutter_wait("rcu_torture_fakewriter");
  890. } while (!torture_must_stop());
  891. torture_kthread_stopping("rcu_torture_fakewriter");
  892. return 0;
  893. }
  894. static void rcutorture_trace_dump(void)
  895. {
  896. static atomic_t beenhere = ATOMIC_INIT(0);
  897. if (atomic_read(&beenhere))
  898. return;
  899. if (atomic_xchg(&beenhere, 1) != 0)
  900. return;
  901. ftrace_dump(DUMP_ALL);
  902. }
  903. /*
  904. * RCU torture reader from timer handler. Dereferences rcu_torture_current,
  905. * incrementing the corresponding element of the pipeline array. The
  906. * counter in the element should never be greater than 1, otherwise, the
  907. * RCU implementation is broken.
  908. */
  909. static void rcu_torture_timer(unsigned long unused)
  910. {
  911. int idx;
  912. int completed;
  913. int completed_end;
  914. static DEFINE_TORTURE_RANDOM(rand);
  915. static DEFINE_SPINLOCK(rand_lock);
  916. struct rcu_torture *p;
  917. int pipe_count;
  918. unsigned long long ts;
  919. idx = cur_ops->readlock();
  920. completed = cur_ops->completed();
  921. ts = rcu_trace_clock_local();
  922. p = rcu_dereference_check(rcu_torture_current,
  923. rcu_read_lock_bh_held() ||
  924. rcu_read_lock_sched_held() ||
  925. srcu_read_lock_held(&srcu_ctl));
  926. if (p == NULL) {
  927. /* Leave because rcu_torture_writer is not yet underway */
  928. cur_ops->readunlock(idx);
  929. return;
  930. }
  931. if (p->rtort_mbtest == 0)
  932. atomic_inc(&n_rcu_torture_mberror);
  933. spin_lock(&rand_lock);
  934. cur_ops->read_delay(&rand);
  935. n_rcu_torture_timers++;
  936. spin_unlock(&rand_lock);
  937. preempt_disable();
  938. pipe_count = p->rtort_pipe_count;
  939. if (pipe_count > RCU_TORTURE_PIPE_LEN) {
  940. /* Should not happen, but... */
  941. pipe_count = RCU_TORTURE_PIPE_LEN;
  942. }
  943. completed_end = cur_ops->completed();
  944. if (pipe_count > 1) {
  945. do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu, ts,
  946. completed, completed_end);
  947. rcutorture_trace_dump();
  948. }
  949. __this_cpu_inc(rcu_torture_count[pipe_count]);
  950. completed = completed_end - completed;
  951. if (completed > RCU_TORTURE_PIPE_LEN) {
  952. /* Should not happen, but... */
  953. completed = RCU_TORTURE_PIPE_LEN;
  954. }
  955. __this_cpu_inc(rcu_torture_batch[completed]);
  956. preempt_enable();
  957. cur_ops->readunlock(idx);
  958. }
  959. /*
  960. * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
  961. * incrementing the corresponding element of the pipeline array. The
  962. * counter in the element should never be greater than 1, otherwise, the
  963. * RCU implementation is broken.
  964. */
  965. static int
  966. rcu_torture_reader(void *arg)
  967. {
  968. int completed;
  969. int completed_end;
  970. int idx;
  971. DEFINE_TORTURE_RANDOM(rand);
  972. struct rcu_torture *p;
  973. int pipe_count;
  974. struct timer_list t;
  975. unsigned long long ts;
  976. VERBOSE_TOROUT_STRING("rcu_torture_reader task started");
  977. set_user_nice(current, MAX_NICE);
  978. if (irqreader && cur_ops->irq_capable)
  979. setup_timer_on_stack(&t, rcu_torture_timer, 0);
  980. do {
  981. if (irqreader && cur_ops->irq_capable) {
  982. if (!timer_pending(&t))
  983. mod_timer(&t, jiffies + 1);
  984. }
  985. idx = cur_ops->readlock();
  986. completed = cur_ops->completed();
  987. ts = rcu_trace_clock_local();
  988. p = rcu_dereference_check(rcu_torture_current,
  989. rcu_read_lock_bh_held() ||
  990. rcu_read_lock_sched_held() ||
  991. srcu_read_lock_held(&srcu_ctl));
  992. if (p == NULL) {
  993. /* Wait for rcu_torture_writer to get underway */
  994. cur_ops->readunlock(idx);
  995. schedule_timeout_interruptible(HZ);
  996. continue;
  997. }
  998. if (p->rtort_mbtest == 0)
  999. atomic_inc(&n_rcu_torture_mberror);
  1000. cur_ops->read_delay(&rand);
  1001. preempt_disable();
  1002. pipe_count = p->rtort_pipe_count;
  1003. if (pipe_count > RCU_TORTURE_PIPE_LEN) {
  1004. /* Should not happen, but... */
  1005. pipe_count = RCU_TORTURE_PIPE_LEN;
  1006. }
  1007. completed_end = cur_ops->completed();
  1008. if (pipe_count > 1) {
  1009. do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu,
  1010. ts, completed, completed_end);
  1011. rcutorture_trace_dump();
  1012. }
  1013. __this_cpu_inc(rcu_torture_count[pipe_count]);
  1014. completed = completed_end - completed;
  1015. if (completed > RCU_TORTURE_PIPE_LEN) {
  1016. /* Should not happen, but... */
  1017. completed = RCU_TORTURE_PIPE_LEN;
  1018. }
  1019. __this_cpu_inc(rcu_torture_batch[completed]);
  1020. preempt_enable();
  1021. cur_ops->readunlock(idx);
  1022. cond_resched_rcu_qs();
  1023. stutter_wait("rcu_torture_reader");
  1024. } while (!torture_must_stop());
  1025. if (irqreader && cur_ops->irq_capable) {
  1026. del_timer_sync(&t);
  1027. destroy_timer_on_stack(&t);
  1028. }
  1029. torture_kthread_stopping("rcu_torture_reader");
  1030. return 0;
  1031. }
  1032. /*
  1033. * Print torture statistics. Caller must ensure that there is only
  1034. * one call to this function at a given time!!! This is normally
  1035. * accomplished by relying on the module system to only have one copy
  1036. * of the module loaded, and then by giving the rcu_torture_stats
  1037. * kthread full control (or the init/cleanup functions when rcu_torture_stats
  1038. * thread is not running).
  1039. */
  1040. static void
  1041. rcu_torture_stats_print(void)
  1042. {
  1043. int cpu;
  1044. int i;
  1045. long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
  1046. long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
  1047. static unsigned long rtcv_snap = ULONG_MAX;
  1048. for_each_possible_cpu(cpu) {
  1049. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
  1050. pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
  1051. batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
  1052. }
  1053. }
  1054. for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
  1055. if (pipesummary[i] != 0)
  1056. break;
  1057. }
  1058. pr_alert("%s%s ", torture_type, TORTURE_FLAG);
  1059. pr_cont("rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
  1060. rcu_torture_current,
  1061. rcu_torture_current_version,
  1062. list_empty(&rcu_torture_freelist),
  1063. atomic_read(&n_rcu_torture_alloc),
  1064. atomic_read(&n_rcu_torture_alloc_fail),
  1065. atomic_read(&n_rcu_torture_free));
  1066. pr_cont("rtmbe: %d rtbke: %ld rtbre: %ld ",
  1067. atomic_read(&n_rcu_torture_mberror),
  1068. n_rcu_torture_boost_ktrerror,
  1069. n_rcu_torture_boost_rterror);
  1070. pr_cont("rtbf: %ld rtb: %ld nt: %ld ",
  1071. n_rcu_torture_boost_failure,
  1072. n_rcu_torture_boosts,
  1073. n_rcu_torture_timers);
  1074. torture_onoff_stats();
  1075. pr_cont("barrier: %ld/%ld:%ld ",
  1076. n_barrier_successes,
  1077. n_barrier_attempts,
  1078. n_rcu_torture_barrier_error);
  1079. pr_cont("cbflood: %ld\n", atomic_long_read(&n_cbfloods));
  1080. pr_alert("%s%s ", torture_type, TORTURE_FLAG);
  1081. if (atomic_read(&n_rcu_torture_mberror) != 0 ||
  1082. n_rcu_torture_barrier_error != 0 ||
  1083. n_rcu_torture_boost_ktrerror != 0 ||
  1084. n_rcu_torture_boost_rterror != 0 ||
  1085. n_rcu_torture_boost_failure != 0 ||
  1086. i > 1) {
  1087. pr_cont("%s", "!!! ");
  1088. atomic_inc(&n_rcu_torture_error);
  1089. WARN_ON_ONCE(1);
  1090. }
  1091. pr_cont("Reader Pipe: ");
  1092. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
  1093. pr_cont(" %ld", pipesummary[i]);
  1094. pr_cont("\n");
  1095. pr_alert("%s%s ", torture_type, TORTURE_FLAG);
  1096. pr_cont("Reader Batch: ");
  1097. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
  1098. pr_cont(" %ld", batchsummary[i]);
  1099. pr_cont("\n");
  1100. pr_alert("%s%s ", torture_type, TORTURE_FLAG);
  1101. pr_cont("Free-Block Circulation: ");
  1102. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
  1103. pr_cont(" %d", atomic_read(&rcu_torture_wcount[i]));
  1104. }
  1105. pr_cont("\n");
  1106. if (cur_ops->stats)
  1107. cur_ops->stats();
  1108. if (rtcv_snap == rcu_torture_current_version &&
  1109. rcu_torture_current != NULL) {
  1110. int __maybe_unused flags;
  1111. unsigned long __maybe_unused gpnum;
  1112. unsigned long __maybe_unused completed;
  1113. rcutorture_get_gp_data(cur_ops->ttype,
  1114. &flags, &gpnum, &completed);
  1115. pr_alert("??? Writer stall state %d g%lu c%lu f%#x\n",
  1116. rcu_torture_writer_state,
  1117. gpnum, completed, flags);
  1118. show_rcu_gp_kthreads();
  1119. rcutorture_trace_dump();
  1120. }
  1121. rtcv_snap = rcu_torture_current_version;
  1122. }
  1123. /*
  1124. * Periodically prints torture statistics, if periodic statistics printing
  1125. * was specified via the stat_interval module parameter.
  1126. */
  1127. static int
  1128. rcu_torture_stats(void *arg)
  1129. {
  1130. VERBOSE_TOROUT_STRING("rcu_torture_stats task started");
  1131. do {
  1132. schedule_timeout_interruptible(stat_interval * HZ);
  1133. rcu_torture_stats_print();
  1134. torture_shutdown_absorb("rcu_torture_stats");
  1135. } while (!torture_must_stop());
  1136. torture_kthread_stopping("rcu_torture_stats");
  1137. return 0;
  1138. }
  1139. static inline void
  1140. rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, const char *tag)
  1141. {
  1142. pr_alert("%s" TORTURE_FLAG
  1143. "--- %s: nreaders=%d nfakewriters=%d "
  1144. "stat_interval=%d verbose=%d test_no_idle_hz=%d "
  1145. "shuffle_interval=%d stutter=%d irqreader=%d "
  1146. "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
  1147. "test_boost=%d/%d test_boost_interval=%d "
  1148. "test_boost_duration=%d shutdown_secs=%d "
  1149. "stall_cpu=%d stall_cpu_holdoff=%d "
  1150. "n_barrier_cbs=%d "
  1151. "onoff_interval=%d onoff_holdoff=%d\n",
  1152. torture_type, tag, nrealreaders, nfakewriters,
  1153. stat_interval, verbose, test_no_idle_hz, shuffle_interval,
  1154. stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
  1155. test_boost, cur_ops->can_boost,
  1156. test_boost_interval, test_boost_duration, shutdown_secs,
  1157. stall_cpu, stall_cpu_holdoff,
  1158. n_barrier_cbs,
  1159. onoff_interval, onoff_holdoff);
  1160. }
  1161. static void rcutorture_booster_cleanup(int cpu)
  1162. {
  1163. struct task_struct *t;
  1164. if (boost_tasks[cpu] == NULL)
  1165. return;
  1166. mutex_lock(&boost_mutex);
  1167. t = boost_tasks[cpu];
  1168. boost_tasks[cpu] = NULL;
  1169. mutex_unlock(&boost_mutex);
  1170. /* This must be outside of the mutex, otherwise deadlock! */
  1171. torture_stop_kthread(rcu_torture_boost, t);
  1172. }
  1173. static int rcutorture_booster_init(int cpu)
  1174. {
  1175. int retval;
  1176. if (boost_tasks[cpu] != NULL)
  1177. return 0; /* Already created, nothing more to do. */
  1178. /* Don't allow time recalculation while creating a new task. */
  1179. mutex_lock(&boost_mutex);
  1180. VERBOSE_TOROUT_STRING("Creating rcu_torture_boost task");
  1181. boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
  1182. cpu_to_node(cpu),
  1183. "rcu_torture_boost");
  1184. if (IS_ERR(boost_tasks[cpu])) {
  1185. retval = PTR_ERR(boost_tasks[cpu]);
  1186. VERBOSE_TOROUT_STRING("rcu_torture_boost task create failed");
  1187. n_rcu_torture_boost_ktrerror++;
  1188. boost_tasks[cpu] = NULL;
  1189. mutex_unlock(&boost_mutex);
  1190. return retval;
  1191. }
  1192. kthread_bind(boost_tasks[cpu], cpu);
  1193. wake_up_process(boost_tasks[cpu]);
  1194. mutex_unlock(&boost_mutex);
  1195. return 0;
  1196. }
  1197. /*
  1198. * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
  1199. * induces a CPU stall for the time specified by stall_cpu.
  1200. */
  1201. static int rcu_torture_stall(void *args)
  1202. {
  1203. unsigned long stop_at;
  1204. VERBOSE_TOROUT_STRING("rcu_torture_stall task started");
  1205. if (stall_cpu_holdoff > 0) {
  1206. VERBOSE_TOROUT_STRING("rcu_torture_stall begin holdoff");
  1207. schedule_timeout_interruptible(stall_cpu_holdoff * HZ);
  1208. VERBOSE_TOROUT_STRING("rcu_torture_stall end holdoff");
  1209. }
  1210. if (!kthread_should_stop()) {
  1211. stop_at = get_seconds() + stall_cpu;
  1212. /* RCU CPU stall is expected behavior in following code. */
  1213. pr_alert("rcu_torture_stall start.\n");
  1214. rcu_read_lock();
  1215. preempt_disable();
  1216. while (ULONG_CMP_LT(get_seconds(), stop_at))
  1217. continue; /* Induce RCU CPU stall warning. */
  1218. preempt_enable();
  1219. rcu_read_unlock();
  1220. pr_alert("rcu_torture_stall end.\n");
  1221. }
  1222. torture_shutdown_absorb("rcu_torture_stall");
  1223. while (!kthread_should_stop())
  1224. schedule_timeout_interruptible(10 * HZ);
  1225. return 0;
  1226. }
  1227. /* Spawn CPU-stall kthread, if stall_cpu specified. */
  1228. static int __init rcu_torture_stall_init(void)
  1229. {
  1230. if (stall_cpu <= 0)
  1231. return 0;
  1232. return torture_create_kthread(rcu_torture_stall, NULL, stall_task);
  1233. }
  1234. /* Callback function for RCU barrier testing. */
  1235. static void rcu_torture_barrier_cbf(struct rcu_head *rcu)
  1236. {
  1237. atomic_inc(&barrier_cbs_invoked);
  1238. }
  1239. /* kthread function to register callbacks used to test RCU barriers. */
  1240. static int rcu_torture_barrier_cbs(void *arg)
  1241. {
  1242. long myid = (long)arg;
  1243. bool lastphase = 0;
  1244. bool newphase;
  1245. struct rcu_head rcu;
  1246. init_rcu_head_on_stack(&rcu);
  1247. VERBOSE_TOROUT_STRING("rcu_torture_barrier_cbs task started");
  1248. set_user_nice(current, MAX_NICE);
  1249. do {
  1250. wait_event(barrier_cbs_wq[myid],
  1251. (newphase =
  1252. ACCESS_ONCE(barrier_phase)) != lastphase ||
  1253. torture_must_stop());
  1254. lastphase = newphase;
  1255. smp_mb(); /* ensure barrier_phase load before ->call(). */
  1256. if (torture_must_stop())
  1257. break;
  1258. cur_ops->call(&rcu, rcu_torture_barrier_cbf);
  1259. if (atomic_dec_and_test(&barrier_cbs_count))
  1260. wake_up(&barrier_wq);
  1261. } while (!torture_must_stop());
  1262. if (cur_ops->cb_barrier != NULL)
  1263. cur_ops->cb_barrier();
  1264. destroy_rcu_head_on_stack(&rcu);
  1265. torture_kthread_stopping("rcu_torture_barrier_cbs");
  1266. return 0;
  1267. }
  1268. /* kthread function to drive and coordinate RCU barrier testing. */
  1269. static int rcu_torture_barrier(void *arg)
  1270. {
  1271. int i;
  1272. VERBOSE_TOROUT_STRING("rcu_torture_barrier task starting");
  1273. do {
  1274. atomic_set(&barrier_cbs_invoked, 0);
  1275. atomic_set(&barrier_cbs_count, n_barrier_cbs);
  1276. smp_mb(); /* Ensure barrier_phase after prior assignments. */
  1277. barrier_phase = !barrier_phase;
  1278. for (i = 0; i < n_barrier_cbs; i++)
  1279. wake_up(&barrier_cbs_wq[i]);
  1280. wait_event(barrier_wq,
  1281. atomic_read(&barrier_cbs_count) == 0 ||
  1282. torture_must_stop());
  1283. if (torture_must_stop())
  1284. break;
  1285. n_barrier_attempts++;
  1286. cur_ops->cb_barrier(); /* Implies smp_mb() for wait_event(). */
  1287. if (atomic_read(&barrier_cbs_invoked) != n_barrier_cbs) {
  1288. n_rcu_torture_barrier_error++;
  1289. WARN_ON_ONCE(1);
  1290. }
  1291. n_barrier_successes++;
  1292. schedule_timeout_interruptible(HZ / 10);
  1293. } while (!torture_must_stop());
  1294. torture_kthread_stopping("rcu_torture_barrier");
  1295. return 0;
  1296. }
  1297. /* Initialize RCU barrier testing. */
  1298. static int rcu_torture_barrier_init(void)
  1299. {
  1300. int i;
  1301. int ret;
  1302. if (n_barrier_cbs == 0)
  1303. return 0;
  1304. if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) {
  1305. pr_alert("%s" TORTURE_FLAG
  1306. " Call or barrier ops missing for %s,\n",
  1307. torture_type, cur_ops->name);
  1308. pr_alert("%s" TORTURE_FLAG
  1309. " RCU barrier testing omitted from run.\n",
  1310. torture_type);
  1311. return 0;
  1312. }
  1313. atomic_set(&barrier_cbs_count, 0);
  1314. atomic_set(&barrier_cbs_invoked, 0);
  1315. barrier_cbs_tasks =
  1316. kzalloc(n_barrier_cbs * sizeof(barrier_cbs_tasks[0]),
  1317. GFP_KERNEL);
  1318. barrier_cbs_wq =
  1319. kzalloc(n_barrier_cbs * sizeof(barrier_cbs_wq[0]),
  1320. GFP_KERNEL);
  1321. if (barrier_cbs_tasks == NULL || !barrier_cbs_wq)
  1322. return -ENOMEM;
  1323. for (i = 0; i < n_barrier_cbs; i++) {
  1324. init_waitqueue_head(&barrier_cbs_wq[i]);
  1325. ret = torture_create_kthread(rcu_torture_barrier_cbs,
  1326. (void *)(long)i,
  1327. barrier_cbs_tasks[i]);
  1328. if (ret)
  1329. return ret;
  1330. }
  1331. return torture_create_kthread(rcu_torture_barrier, NULL, barrier_task);
  1332. }
  1333. /* Clean up after RCU barrier testing. */
  1334. static void rcu_torture_barrier_cleanup(void)
  1335. {
  1336. int i;
  1337. torture_stop_kthread(rcu_torture_barrier, barrier_task);
  1338. if (barrier_cbs_tasks != NULL) {
  1339. for (i = 0; i < n_barrier_cbs; i++)
  1340. torture_stop_kthread(rcu_torture_barrier_cbs,
  1341. barrier_cbs_tasks[i]);
  1342. kfree(barrier_cbs_tasks);
  1343. barrier_cbs_tasks = NULL;
  1344. }
  1345. if (barrier_cbs_wq != NULL) {
  1346. kfree(barrier_cbs_wq);
  1347. barrier_cbs_wq = NULL;
  1348. }
  1349. }
  1350. static int rcutorture_cpu_notify(struct notifier_block *self,
  1351. unsigned long action, void *hcpu)
  1352. {
  1353. long cpu = (long)hcpu;
  1354. switch (action) {
  1355. case CPU_ONLINE:
  1356. case CPU_DOWN_FAILED:
  1357. (void)rcutorture_booster_init(cpu);
  1358. break;
  1359. case CPU_DOWN_PREPARE:
  1360. rcutorture_booster_cleanup(cpu);
  1361. break;
  1362. default:
  1363. break;
  1364. }
  1365. return NOTIFY_OK;
  1366. }
  1367. static struct notifier_block rcutorture_cpu_nb = {
  1368. .notifier_call = rcutorture_cpu_notify,
  1369. };
  1370. static void
  1371. rcu_torture_cleanup(void)
  1372. {
  1373. int i;
  1374. rcutorture_record_test_transition();
  1375. if (torture_cleanup_begin()) {
  1376. if (cur_ops->cb_barrier != NULL)
  1377. cur_ops->cb_barrier();
  1378. return;
  1379. }
  1380. rcu_torture_barrier_cleanup();
  1381. torture_stop_kthread(rcu_torture_stall, stall_task);
  1382. torture_stop_kthread(rcu_torture_writer, writer_task);
  1383. if (reader_tasks) {
  1384. for (i = 0; i < nrealreaders; i++)
  1385. torture_stop_kthread(rcu_torture_reader,
  1386. reader_tasks[i]);
  1387. kfree(reader_tasks);
  1388. }
  1389. rcu_torture_current = NULL;
  1390. if (fakewriter_tasks) {
  1391. for (i = 0; i < nfakewriters; i++) {
  1392. torture_stop_kthread(rcu_torture_fakewriter,
  1393. fakewriter_tasks[i]);
  1394. }
  1395. kfree(fakewriter_tasks);
  1396. fakewriter_tasks = NULL;
  1397. }
  1398. torture_stop_kthread(rcu_torture_stats, stats_task);
  1399. torture_stop_kthread(rcu_torture_fqs, fqs_task);
  1400. for (i = 0; i < ncbflooders; i++)
  1401. torture_stop_kthread(rcu_torture_cbflood, cbflood_task[i]);
  1402. if ((test_boost == 1 && cur_ops->can_boost) ||
  1403. test_boost == 2) {
  1404. unregister_cpu_notifier(&rcutorture_cpu_nb);
  1405. for_each_possible_cpu(i)
  1406. rcutorture_booster_cleanup(i);
  1407. }
  1408. /* Wait for all RCU callbacks to fire. */
  1409. if (cur_ops->cb_barrier != NULL)
  1410. cur_ops->cb_barrier();
  1411. rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
  1412. if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
  1413. rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
  1414. else if (torture_onoff_failures())
  1415. rcu_torture_print_module_parms(cur_ops,
  1416. "End of test: RCU_HOTPLUG");
  1417. else
  1418. rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
  1419. torture_cleanup_end();
  1420. }
  1421. #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
  1422. static void rcu_torture_leak_cb(struct rcu_head *rhp)
  1423. {
  1424. }
  1425. static void rcu_torture_err_cb(struct rcu_head *rhp)
  1426. {
  1427. /*
  1428. * This -might- happen due to race conditions, but is unlikely.
  1429. * The scenario that leads to this happening is that the
  1430. * first of the pair of duplicate callbacks is queued,
  1431. * someone else starts a grace period that includes that
  1432. * callback, then the second of the pair must wait for the
  1433. * next grace period. Unlikely, but can happen. If it
  1434. * does happen, the debug-objects subsystem won't have splatted.
  1435. */
  1436. pr_alert("rcutorture: duplicated callback was invoked.\n");
  1437. }
  1438. #endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
  1439. /*
  1440. * Verify that double-free causes debug-objects to complain, but only
  1441. * if CONFIG_DEBUG_OBJECTS_RCU_HEAD=y. Otherwise, say that the test
  1442. * cannot be carried out.
  1443. */
  1444. static void rcu_test_debug_objects(void)
  1445. {
  1446. #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
  1447. struct rcu_head rh1;
  1448. struct rcu_head rh2;
  1449. init_rcu_head_on_stack(&rh1);
  1450. init_rcu_head_on_stack(&rh2);
  1451. pr_alert("rcutorture: WARN: Duplicate call_rcu() test starting.\n");
  1452. /* Try to queue the rh2 pair of callbacks for the same grace period. */
  1453. preempt_disable(); /* Prevent preemption from interrupting test. */
  1454. rcu_read_lock(); /* Make it impossible to finish a grace period. */
  1455. call_rcu(&rh1, rcu_torture_leak_cb); /* Start grace period. */
  1456. local_irq_disable(); /* Make it harder to start a new grace period. */
  1457. call_rcu(&rh2, rcu_torture_leak_cb);
  1458. call_rcu(&rh2, rcu_torture_err_cb); /* Duplicate callback. */
  1459. local_irq_enable();
  1460. rcu_read_unlock();
  1461. preempt_enable();
  1462. /* Wait for them all to get done so we can safely return. */
  1463. rcu_barrier();
  1464. pr_alert("rcutorture: WARN: Duplicate call_rcu() test complete.\n");
  1465. destroy_rcu_head_on_stack(&rh1);
  1466. destroy_rcu_head_on_stack(&rh2);
  1467. #else /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
  1468. pr_alert("rcutorture: !CONFIG_DEBUG_OBJECTS_RCU_HEAD, not testing duplicate call_rcu()\n");
  1469. #endif /* #else #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
  1470. }
  1471. static int __init
  1472. rcu_torture_init(void)
  1473. {
  1474. int i;
  1475. int cpu;
  1476. int firsterr = 0;
  1477. static struct rcu_torture_ops *torture_ops[] = {
  1478. &rcu_ops, &rcu_bh_ops, &rcu_busted_ops, &srcu_ops, &sched_ops,
  1479. RCUTORTURE_TASKS_OPS
  1480. };
  1481. if (!torture_init_begin(torture_type, verbose, &torture_runnable))
  1482. return -EBUSY;
  1483. /* Process args and tell the world that the torturer is on the job. */
  1484. for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
  1485. cur_ops = torture_ops[i];
  1486. if (strcmp(torture_type, cur_ops->name) == 0)
  1487. break;
  1488. }
  1489. if (i == ARRAY_SIZE(torture_ops)) {
  1490. pr_alert("rcu-torture: invalid torture type: \"%s\"\n",
  1491. torture_type);
  1492. pr_alert("rcu-torture types:");
  1493. for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
  1494. pr_alert(" %s", torture_ops[i]->name);
  1495. pr_alert("\n");
  1496. torture_init_end();
  1497. return -EINVAL;
  1498. }
  1499. if (cur_ops->fqs == NULL && fqs_duration != 0) {
  1500. pr_alert("rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n");
  1501. fqs_duration = 0;
  1502. }
  1503. if (cur_ops->init)
  1504. cur_ops->init(); /* no "goto unwind" prior to this point!!! */
  1505. if (nreaders >= 0) {
  1506. nrealreaders = nreaders;
  1507. } else {
  1508. nrealreaders = num_online_cpus() - 1;
  1509. if (nrealreaders <= 0)
  1510. nrealreaders = 1;
  1511. }
  1512. rcu_torture_print_module_parms(cur_ops, "Start of test");
  1513. /* Set up the freelist. */
  1514. INIT_LIST_HEAD(&rcu_torture_freelist);
  1515. for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
  1516. rcu_tortures[i].rtort_mbtest = 0;
  1517. list_add_tail(&rcu_tortures[i].rtort_free,
  1518. &rcu_torture_freelist);
  1519. }
  1520. /* Initialize the statistics so that each run gets its own numbers. */
  1521. rcu_torture_current = NULL;
  1522. rcu_torture_current_version = 0;
  1523. atomic_set(&n_rcu_torture_alloc, 0);
  1524. atomic_set(&n_rcu_torture_alloc_fail, 0);
  1525. atomic_set(&n_rcu_torture_free, 0);
  1526. atomic_set(&n_rcu_torture_mberror, 0);
  1527. atomic_set(&n_rcu_torture_error, 0);
  1528. n_rcu_torture_barrier_error = 0;
  1529. n_rcu_torture_boost_ktrerror = 0;
  1530. n_rcu_torture_boost_rterror = 0;
  1531. n_rcu_torture_boost_failure = 0;
  1532. n_rcu_torture_boosts = 0;
  1533. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
  1534. atomic_set(&rcu_torture_wcount[i], 0);
  1535. for_each_possible_cpu(cpu) {
  1536. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
  1537. per_cpu(rcu_torture_count, cpu)[i] = 0;
  1538. per_cpu(rcu_torture_batch, cpu)[i] = 0;
  1539. }
  1540. }
  1541. /* Start up the kthreads. */
  1542. firsterr = torture_create_kthread(rcu_torture_writer, NULL,
  1543. writer_task);
  1544. if (firsterr)
  1545. goto unwind;
  1546. fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
  1547. GFP_KERNEL);
  1548. if (fakewriter_tasks == NULL) {
  1549. VERBOSE_TOROUT_ERRSTRING("out of memory");
  1550. firsterr = -ENOMEM;
  1551. goto unwind;
  1552. }
  1553. for (i = 0; i < nfakewriters; i++) {
  1554. firsterr = torture_create_kthread(rcu_torture_fakewriter,
  1555. NULL, fakewriter_tasks[i]);
  1556. if (firsterr)
  1557. goto unwind;
  1558. }
  1559. reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
  1560. GFP_KERNEL);
  1561. if (reader_tasks == NULL) {
  1562. VERBOSE_TOROUT_ERRSTRING("out of memory");
  1563. firsterr = -ENOMEM;
  1564. goto unwind;
  1565. }
  1566. for (i = 0; i < nrealreaders; i++) {
  1567. firsterr = torture_create_kthread(rcu_torture_reader, NULL,
  1568. reader_tasks[i]);
  1569. if (firsterr)
  1570. goto unwind;
  1571. }
  1572. if (stat_interval > 0) {
  1573. firsterr = torture_create_kthread(rcu_torture_stats, NULL,
  1574. stats_task);
  1575. if (firsterr)
  1576. goto unwind;
  1577. }
  1578. if (test_no_idle_hz) {
  1579. firsterr = torture_shuffle_init(shuffle_interval * HZ);
  1580. if (firsterr)
  1581. goto unwind;
  1582. }
  1583. if (stutter < 0)
  1584. stutter = 0;
  1585. if (stutter) {
  1586. firsterr = torture_stutter_init(stutter * HZ);
  1587. if (firsterr)
  1588. goto unwind;
  1589. }
  1590. if (fqs_duration < 0)
  1591. fqs_duration = 0;
  1592. if (fqs_duration) {
  1593. /* Create the fqs thread */
  1594. firsterr = torture_create_kthread(rcu_torture_fqs, NULL,
  1595. fqs_task);
  1596. if (firsterr)
  1597. goto unwind;
  1598. }
  1599. if (test_boost_interval < 1)
  1600. test_boost_interval = 1;
  1601. if (test_boost_duration < 2)
  1602. test_boost_duration = 2;
  1603. if ((test_boost == 1 && cur_ops->can_boost) ||
  1604. test_boost == 2) {
  1605. boost_starttime = jiffies + test_boost_interval * HZ;
  1606. register_cpu_notifier(&rcutorture_cpu_nb);
  1607. for_each_possible_cpu(i) {
  1608. if (cpu_is_offline(i))
  1609. continue; /* Heuristic: CPU can go offline. */
  1610. firsterr = rcutorture_booster_init(i);
  1611. if (firsterr)
  1612. goto unwind;
  1613. }
  1614. }
  1615. firsterr = torture_shutdown_init(shutdown_secs, rcu_torture_cleanup);
  1616. if (firsterr)
  1617. goto unwind;
  1618. firsterr = torture_onoff_init(onoff_holdoff * HZ, onoff_interval * HZ);
  1619. if (firsterr)
  1620. goto unwind;
  1621. firsterr = rcu_torture_stall_init();
  1622. if (firsterr)
  1623. goto unwind;
  1624. firsterr = rcu_torture_barrier_init();
  1625. if (firsterr)
  1626. goto unwind;
  1627. if (object_debug)
  1628. rcu_test_debug_objects();
  1629. if (cbflood_n_burst > 0) {
  1630. /* Create the cbflood threads */
  1631. ncbflooders = (num_online_cpus() + 3) / 4;
  1632. cbflood_task = kcalloc(ncbflooders, sizeof(*cbflood_task),
  1633. GFP_KERNEL);
  1634. if (!cbflood_task) {
  1635. VERBOSE_TOROUT_ERRSTRING("out of memory");
  1636. firsterr = -ENOMEM;
  1637. goto unwind;
  1638. }
  1639. for (i = 0; i < ncbflooders; i++) {
  1640. firsterr = torture_create_kthread(rcu_torture_cbflood,
  1641. NULL,
  1642. cbflood_task[i]);
  1643. if (firsterr)
  1644. goto unwind;
  1645. }
  1646. }
  1647. rcutorture_record_test_transition();
  1648. torture_init_end();
  1649. return 0;
  1650. unwind:
  1651. torture_init_end();
  1652. rcu_torture_cleanup();
  1653. return firsterr;
  1654. }
  1655. module_init(rcu_torture_init);
  1656. module_exit(rcu_torture_cleanup);