xpc_main.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (c) 2004-2008 Silicon Graphics, Inc. All Rights Reserved.
  7. */
  8. /*
  9. * Cross Partition Communication (XPC) support - standard version.
  10. *
  11. * XPC provides a message passing capability that crosses partition
  12. * boundaries. This module is made up of two parts:
  13. *
  14. * partition This part detects the presence/absence of other
  15. * partitions. It provides a heartbeat and monitors
  16. * the heartbeats of other partitions.
  17. *
  18. * channel This part manages the channels and sends/receives
  19. * messages across them to/from other partitions.
  20. *
  21. * There are a couple of additional functions residing in XP, which
  22. * provide an interface to XPC for its users.
  23. *
  24. *
  25. * Caveats:
  26. *
  27. * . We currently have no way to determine which nasid an IPI came
  28. * from. Thus, xpc_IPI_send() does a remote AMO write followed by
  29. * an IPI. The AMO indicates where data is to be pulled from, so
  30. * after the IPI arrives, the remote partition checks the AMO word.
  31. * The IPI can actually arrive before the AMO however, so other code
  32. * must periodically check for this case. Also, remote AMO operations
  33. * do not reliably time out. Thus we do a remote PIO read solely to
  34. * know whether the remote partition is down and whether we should
  35. * stop sending IPIs to it. This remote PIO read operation is set up
  36. * in a special nofault region so SAL knows to ignore (and cleanup)
  37. * any errors due to the remote AMO write, PIO read, and/or PIO
  38. * write operations.
  39. *
  40. * If/when new hardware solves this IPI problem, we should abandon
  41. * the current approach.
  42. *
  43. */
  44. #include <linux/kernel.h>
  45. #include <linux/module.h>
  46. #include <linux/init.h>
  47. #include <linux/cache.h>
  48. #include <linux/interrupt.h>
  49. #include <linux/delay.h>
  50. #include <linux/reboot.h>
  51. #include <linux/completion.h>
  52. #include <linux/kdebug.h>
  53. #include <linux/kthread.h>
  54. #include <linux/uaccess.h>
  55. #include <asm/sn/intr.h>
  56. #include <asm/sn/sn_sal.h>
  57. #include "xpc.h"
  58. /* define two XPC debug device structures to be used with dev_dbg() et al */
  59. struct device_driver xpc_dbg_name = {
  60. .name = "xpc"
  61. };
  62. struct device xpc_part_dbg_subname = {
  63. .bus_id = {0}, /* set to "part" at xpc_init() time */
  64. .driver = &xpc_dbg_name
  65. };
  66. struct device xpc_chan_dbg_subname = {
  67. .bus_id = {0}, /* set to "chan" at xpc_init() time */
  68. .driver = &xpc_dbg_name
  69. };
  70. struct device *xpc_part = &xpc_part_dbg_subname;
  71. struct device *xpc_chan = &xpc_chan_dbg_subname;
  72. static int xpc_kdebug_ignore;
  73. /* systune related variables for /proc/sys directories */
  74. static int xpc_hb_interval = XPC_HB_DEFAULT_INTERVAL;
  75. static int xpc_hb_min_interval = 1;
  76. static int xpc_hb_max_interval = 10;
  77. static int xpc_hb_check_interval = XPC_HB_CHECK_DEFAULT_INTERVAL;
  78. static int xpc_hb_check_min_interval = 10;
  79. static int xpc_hb_check_max_interval = 120;
  80. int xpc_disengage_request_timelimit = XPC_DISENGAGE_REQUEST_DEFAULT_TIMELIMIT;
  81. static int xpc_disengage_request_min_timelimit; /* = 0 */
  82. static int xpc_disengage_request_max_timelimit = 120;
  83. static ctl_table xpc_sys_xpc_hb_dir[] = {
  84. {
  85. .ctl_name = CTL_UNNUMBERED,
  86. .procname = "hb_interval",
  87. .data = &xpc_hb_interval,
  88. .maxlen = sizeof(int),
  89. .mode = 0644,
  90. .proc_handler = &proc_dointvec_minmax,
  91. .strategy = &sysctl_intvec,
  92. .extra1 = &xpc_hb_min_interval,
  93. .extra2 = &xpc_hb_max_interval},
  94. {
  95. .ctl_name = CTL_UNNUMBERED,
  96. .procname = "hb_check_interval",
  97. .data = &xpc_hb_check_interval,
  98. .maxlen = sizeof(int),
  99. .mode = 0644,
  100. .proc_handler = &proc_dointvec_minmax,
  101. .strategy = &sysctl_intvec,
  102. .extra1 = &xpc_hb_check_min_interval,
  103. .extra2 = &xpc_hb_check_max_interval},
  104. {}
  105. };
  106. static ctl_table xpc_sys_xpc_dir[] = {
  107. {
  108. .ctl_name = CTL_UNNUMBERED,
  109. .procname = "hb",
  110. .mode = 0555,
  111. .child = xpc_sys_xpc_hb_dir},
  112. {
  113. .ctl_name = CTL_UNNUMBERED,
  114. .procname = "disengage_request_timelimit",
  115. .data = &xpc_disengage_request_timelimit,
  116. .maxlen = sizeof(int),
  117. .mode = 0644,
  118. .proc_handler = &proc_dointvec_minmax,
  119. .strategy = &sysctl_intvec,
  120. .extra1 = &xpc_disengage_request_min_timelimit,
  121. .extra2 = &xpc_disengage_request_max_timelimit},
  122. {}
  123. };
  124. static ctl_table xpc_sys_dir[] = {
  125. {
  126. .ctl_name = CTL_UNNUMBERED,
  127. .procname = "xpc",
  128. .mode = 0555,
  129. .child = xpc_sys_xpc_dir},
  130. {}
  131. };
  132. static struct ctl_table_header *xpc_sysctl;
  133. /* non-zero if any remote partition disengage request was timed out */
  134. int xpc_disengage_request_timedout;
  135. /* #of IRQs received */
  136. static atomic_t xpc_act_IRQ_rcvd;
  137. /* IRQ handler notifies this wait queue on receipt of an IRQ */
  138. static DECLARE_WAIT_QUEUE_HEAD(xpc_act_IRQ_wq);
  139. static unsigned long xpc_hb_check_timeout;
  140. /* notification that the xpc_hb_checker thread has exited */
  141. static DECLARE_COMPLETION(xpc_hb_checker_exited);
  142. /* notification that the xpc_discovery thread has exited */
  143. static DECLARE_COMPLETION(xpc_discovery_exited);
  144. static struct timer_list xpc_hb_timer;
  145. static void xpc_kthread_waitmsgs(struct xpc_partition *, struct xpc_channel *);
  146. static int xpc_system_reboot(struct notifier_block *, unsigned long, void *);
  147. static struct notifier_block xpc_reboot_notifier = {
  148. .notifier_call = xpc_system_reboot,
  149. };
  150. static int xpc_system_die(struct notifier_block *, unsigned long, void *);
  151. static struct notifier_block xpc_die_notifier = {
  152. .notifier_call = xpc_system_die,
  153. };
  154. /*
  155. * Timer function to enforce the timelimit on the partition disengage request.
  156. */
  157. static void
  158. xpc_timeout_partition_disengage_request(unsigned long data)
  159. {
  160. struct xpc_partition *part = (struct xpc_partition *)data;
  161. DBUG_ON(time_before(jiffies, part->disengage_request_timeout));
  162. (void)xpc_partition_disengaged(part);
  163. DBUG_ON(part->disengage_request_timeout != 0);
  164. DBUG_ON(xpc_partition_engaged(1UL << XPC_PARTID(part)) != 0);
  165. }
  166. /*
  167. * Notify the heartbeat check thread that an IRQ has been received.
  168. */
  169. static irqreturn_t
  170. xpc_act_IRQ_handler(int irq, void *dev_id)
  171. {
  172. atomic_inc(&xpc_act_IRQ_rcvd);
  173. wake_up_interruptible(&xpc_act_IRQ_wq);
  174. return IRQ_HANDLED;
  175. }
  176. /*
  177. * Timer to produce the heartbeat. The timer structures function is
  178. * already set when this is initially called. A tunable is used to
  179. * specify when the next timeout should occur.
  180. */
  181. static void
  182. xpc_hb_beater(unsigned long dummy)
  183. {
  184. xpc_vars->heartbeat++;
  185. if (time_after_eq(jiffies, xpc_hb_check_timeout))
  186. wake_up_interruptible(&xpc_act_IRQ_wq);
  187. xpc_hb_timer.expires = jiffies + (xpc_hb_interval * HZ);
  188. add_timer(&xpc_hb_timer);
  189. }
  190. /*
  191. * This thread is responsible for nearly all of the partition
  192. * activation/deactivation.
  193. */
  194. static int
  195. xpc_hb_checker(void *ignore)
  196. {
  197. int last_IRQ_count = 0;
  198. int new_IRQ_count;
  199. int force_IRQ = 0;
  200. /* this thread was marked active by xpc_hb_init() */
  201. set_cpus_allowed_ptr(current, &cpumask_of_cpu(XPC_HB_CHECK_CPU));
  202. /* set our heartbeating to other partitions into motion */
  203. xpc_hb_check_timeout = jiffies + (xpc_hb_check_interval * HZ);
  204. xpc_hb_beater(0);
  205. while (!xpc_exiting) {
  206. dev_dbg(xpc_part, "woke up with %d ticks rem; %d IRQs have "
  207. "been received\n",
  208. (int)(xpc_hb_check_timeout - jiffies),
  209. atomic_read(&xpc_act_IRQ_rcvd) - last_IRQ_count);
  210. /* checking of remote heartbeats is skewed by IRQ handling */
  211. if (time_after_eq(jiffies, xpc_hb_check_timeout)) {
  212. dev_dbg(xpc_part, "checking remote heartbeats\n");
  213. xpc_check_remote_hb();
  214. /*
  215. * We need to periodically recheck to ensure no
  216. * IPI/AMO pairs have been missed. That check
  217. * must always reset xpc_hb_check_timeout.
  218. */
  219. force_IRQ = 1;
  220. }
  221. /* check for outstanding IRQs */
  222. new_IRQ_count = atomic_read(&xpc_act_IRQ_rcvd);
  223. if (last_IRQ_count < new_IRQ_count || force_IRQ != 0) {
  224. force_IRQ = 0;
  225. dev_dbg(xpc_part, "found an IRQ to process; will be "
  226. "resetting xpc_hb_check_timeout\n");
  227. last_IRQ_count += xpc_identify_act_IRQ_sender();
  228. if (last_IRQ_count < new_IRQ_count) {
  229. /* retry once to help avoid missing AMO */
  230. (void)xpc_identify_act_IRQ_sender();
  231. }
  232. last_IRQ_count = new_IRQ_count;
  233. xpc_hb_check_timeout = jiffies +
  234. (xpc_hb_check_interval * HZ);
  235. }
  236. /* wait for IRQ or timeout */
  237. (void)wait_event_interruptible(xpc_act_IRQ_wq,
  238. (last_IRQ_count <
  239. atomic_read(&xpc_act_IRQ_rcvd)
  240. || time_after_eq(jiffies,
  241. xpc_hb_check_timeout) ||
  242. xpc_exiting));
  243. }
  244. dev_dbg(xpc_part, "heartbeat checker is exiting\n");
  245. /* mark this thread as having exited */
  246. complete(&xpc_hb_checker_exited);
  247. return 0;
  248. }
  249. /*
  250. * This thread will attempt to discover other partitions to activate
  251. * based on info provided by SAL. This new thread is short lived and
  252. * will exit once discovery is complete.
  253. */
  254. static int
  255. xpc_initiate_discovery(void *ignore)
  256. {
  257. xpc_discovery();
  258. dev_dbg(xpc_part, "discovery thread is exiting\n");
  259. /* mark this thread as having exited */
  260. complete(&xpc_discovery_exited);
  261. return 0;
  262. }
  263. /*
  264. * Establish first contact with the remote partititon. This involves pulling
  265. * the XPC per partition variables from the remote partition and waiting for
  266. * the remote partition to pull ours.
  267. */
  268. static enum xp_retval
  269. xpc_make_first_contact(struct xpc_partition *part)
  270. {
  271. enum xp_retval ret;
  272. while ((ret = xpc_pull_remote_vars_part(part)) != xpSuccess) {
  273. if (ret != xpRetry) {
  274. XPC_DEACTIVATE_PARTITION(part, ret);
  275. return ret;
  276. }
  277. dev_dbg(xpc_chan, "waiting to make first contact with "
  278. "partition %d\n", XPC_PARTID(part));
  279. /* wait a 1/4 of a second or so */
  280. (void)msleep_interruptible(250);
  281. if (part->act_state == XPC_P_DEACTIVATING)
  282. return part->reason;
  283. }
  284. return xpc_mark_partition_active(part);
  285. }
  286. /*
  287. * The first kthread assigned to a newly activated partition is the one
  288. * created by XPC HB with which it calls xpc_partition_up(). XPC hangs on to
  289. * that kthread until the partition is brought down, at which time that kthread
  290. * returns back to XPC HB. (The return of that kthread will signify to XPC HB
  291. * that XPC has dismantled all communication infrastructure for the associated
  292. * partition.) This kthread becomes the channel manager for that partition.
  293. *
  294. * Each active partition has a channel manager, who, besides connecting and
  295. * disconnecting channels, will ensure that each of the partition's connected
  296. * channels has the required number of assigned kthreads to get the work done.
  297. */
  298. static void
  299. xpc_channel_mgr(struct xpc_partition *part)
  300. {
  301. while (part->act_state != XPC_P_DEACTIVATING ||
  302. atomic_read(&part->nchannels_active) > 0 ||
  303. !xpc_partition_disengaged(part)) {
  304. xpc_process_channel_activity(part);
  305. /*
  306. * Wait until we've been requested to activate kthreads or
  307. * all of the channel's message queues have been torn down or
  308. * a signal is pending.
  309. *
  310. * The channel_mgr_requests is set to 1 after being awakened,
  311. * This is done to prevent the channel mgr from making one pass
  312. * through the loop for each request, since he will
  313. * be servicing all the requests in one pass. The reason it's
  314. * set to 1 instead of 0 is so that other kthreads will know
  315. * that the channel mgr is running and won't bother trying to
  316. * wake him up.
  317. */
  318. atomic_dec(&part->channel_mgr_requests);
  319. (void)wait_event_interruptible(part->channel_mgr_wq,
  320. (atomic_read(&part->channel_mgr_requests) > 0 ||
  321. part->local_IPI_amo != 0 ||
  322. (part->act_state == XPC_P_DEACTIVATING &&
  323. atomic_read(&part->nchannels_active) == 0 &&
  324. xpc_partition_disengaged(part))));
  325. atomic_set(&part->channel_mgr_requests, 1);
  326. }
  327. }
  328. /*
  329. * When XPC HB determines that a partition has come up, it will create a new
  330. * kthread and that kthread will call this function to attempt to set up the
  331. * basic infrastructure used for Cross Partition Communication with the newly
  332. * upped partition.
  333. *
  334. * The kthread that was created by XPC HB and which setup the XPC
  335. * infrastructure will remain assigned to the partition until the partition
  336. * goes down. At which time the kthread will teardown the XPC infrastructure
  337. * and then exit.
  338. *
  339. * XPC HB will put the remote partition's XPC per partition specific variables
  340. * physical address into xpc_partitions[partid].remote_vars_part_pa prior to
  341. * calling xpc_partition_up().
  342. */
  343. static void
  344. xpc_partition_up(struct xpc_partition *part)
  345. {
  346. DBUG_ON(part->channels != NULL);
  347. dev_dbg(xpc_chan, "activating partition %d\n", XPC_PARTID(part));
  348. if (xpc_setup_infrastructure(part) != xpSuccess)
  349. return;
  350. /*
  351. * The kthread that XPC HB called us with will become the
  352. * channel manager for this partition. It will not return
  353. * back to XPC HB until the partition's XPC infrastructure
  354. * has been dismantled.
  355. */
  356. (void)xpc_part_ref(part); /* this will always succeed */
  357. if (xpc_make_first_contact(part) == xpSuccess)
  358. xpc_channel_mgr(part);
  359. xpc_part_deref(part);
  360. xpc_teardown_infrastructure(part);
  361. }
  362. static int
  363. xpc_activating(void *__partid)
  364. {
  365. short partid = (u64)__partid;
  366. struct xpc_partition *part = &xpc_partitions[partid];
  367. unsigned long irq_flags;
  368. DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS);
  369. spin_lock_irqsave(&part->act_lock, irq_flags);
  370. if (part->act_state == XPC_P_DEACTIVATING) {
  371. part->act_state = XPC_P_INACTIVE;
  372. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  373. part->remote_rp_pa = 0;
  374. return 0;
  375. }
  376. /* indicate the thread is activating */
  377. DBUG_ON(part->act_state != XPC_P_ACTIVATION_REQ);
  378. part->act_state = XPC_P_ACTIVATING;
  379. XPC_SET_REASON(part, 0, 0);
  380. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  381. dev_dbg(xpc_part, "bringing partition %d up\n", partid);
  382. /*
  383. * Register the remote partition's AMOs with SAL so it can handle
  384. * and cleanup errors within that address range should the remote
  385. * partition go down. We don't unregister this range because it is
  386. * difficult to tell when outstanding writes to the remote partition
  387. * are finished and thus when it is safe to unregister. This should
  388. * not result in wasted space in the SAL xp_addr_region table because
  389. * we should get the same page for remote_amos_page_pa after module
  390. * reloads and system reboots.
  391. */
  392. if (sn_register_xp_addr_region(part->remote_amos_page_pa,
  393. PAGE_SIZE, 1) < 0) {
  394. dev_warn(xpc_part, "xpc_partition_up(%d) failed to register "
  395. "xp_addr region\n", partid);
  396. spin_lock_irqsave(&part->act_lock, irq_flags);
  397. part->act_state = XPC_P_INACTIVE;
  398. XPC_SET_REASON(part, xpPhysAddrRegFailed, __LINE__);
  399. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  400. part->remote_rp_pa = 0;
  401. return 0;
  402. }
  403. xpc_allow_hb(partid, xpc_vars);
  404. xpc_IPI_send_activated(part);
  405. /*
  406. * xpc_partition_up() holds this thread and marks this partition as
  407. * XPC_P_ACTIVE by calling xpc_hb_mark_active().
  408. */
  409. (void)xpc_partition_up(part);
  410. xpc_disallow_hb(partid, xpc_vars);
  411. xpc_mark_partition_inactive(part);
  412. if (part->reason == xpReactivating) {
  413. /* interrupting ourselves results in activating partition */
  414. xpc_IPI_send_reactivate(part);
  415. }
  416. return 0;
  417. }
  418. void
  419. xpc_activate_partition(struct xpc_partition *part)
  420. {
  421. short partid = XPC_PARTID(part);
  422. unsigned long irq_flags;
  423. struct task_struct *kthread;
  424. spin_lock_irqsave(&part->act_lock, irq_flags);
  425. DBUG_ON(part->act_state != XPC_P_INACTIVE);
  426. part->act_state = XPC_P_ACTIVATION_REQ;
  427. XPC_SET_REASON(part, xpCloneKThread, __LINE__);
  428. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  429. kthread = kthread_run(xpc_activating, (void *)((u64)partid), "xpc%02d",
  430. partid);
  431. if (IS_ERR(kthread)) {
  432. spin_lock_irqsave(&part->act_lock, irq_flags);
  433. part->act_state = XPC_P_INACTIVE;
  434. XPC_SET_REASON(part, xpCloneKThreadFailed, __LINE__);
  435. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  436. }
  437. }
  438. /*
  439. * Handle the receipt of a SGI_XPC_NOTIFY IRQ by seeing whether the specified
  440. * partition actually sent it. Since SGI_XPC_NOTIFY IRQs may be shared by more
  441. * than one partition, we use an AMO_t structure per partition to indicate
  442. * whether a partition has sent an IPI or not. If it has, then wake up the
  443. * associated kthread to handle it.
  444. *
  445. * All SGI_XPC_NOTIFY IRQs received by XPC are the result of IPIs sent by XPC
  446. * running on other partitions.
  447. *
  448. * Noteworthy Arguments:
  449. *
  450. * irq - Interrupt ReQuest number. NOT USED.
  451. *
  452. * dev_id - partid of IPI's potential sender.
  453. */
  454. irqreturn_t
  455. xpc_notify_IRQ_handler(int irq, void *dev_id)
  456. {
  457. short partid = (short)(u64)dev_id;
  458. struct xpc_partition *part = &xpc_partitions[partid];
  459. DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS);
  460. if (xpc_part_ref(part)) {
  461. xpc_check_for_channel_activity(part);
  462. xpc_part_deref(part);
  463. }
  464. return IRQ_HANDLED;
  465. }
  466. /*
  467. * Check to see if xpc_notify_IRQ_handler() dropped any IPIs on the floor
  468. * because the write to their associated IPI amo completed after the IRQ/IPI
  469. * was received.
  470. */
  471. void
  472. xpc_dropped_IPI_check(struct xpc_partition *part)
  473. {
  474. if (xpc_part_ref(part)) {
  475. xpc_check_for_channel_activity(part);
  476. part->dropped_IPI_timer.expires = jiffies +
  477. XPC_P_DROPPED_IPI_WAIT;
  478. add_timer(&part->dropped_IPI_timer);
  479. xpc_part_deref(part);
  480. }
  481. }
  482. void
  483. xpc_activate_kthreads(struct xpc_channel *ch, int needed)
  484. {
  485. int idle = atomic_read(&ch->kthreads_idle);
  486. int assigned = atomic_read(&ch->kthreads_assigned);
  487. int wakeup;
  488. DBUG_ON(needed <= 0);
  489. if (idle > 0) {
  490. wakeup = (needed > idle) ? idle : needed;
  491. needed -= wakeup;
  492. dev_dbg(xpc_chan, "wakeup %d idle kthreads, partid=%d, "
  493. "channel=%d\n", wakeup, ch->partid, ch->number);
  494. /* only wakeup the requested number of kthreads */
  495. wake_up_nr(&ch->idle_wq, wakeup);
  496. }
  497. if (needed <= 0)
  498. return;
  499. if (needed + assigned > ch->kthreads_assigned_limit) {
  500. needed = ch->kthreads_assigned_limit - assigned;
  501. if (needed <= 0)
  502. return;
  503. }
  504. dev_dbg(xpc_chan, "create %d new kthreads, partid=%d, channel=%d\n",
  505. needed, ch->partid, ch->number);
  506. xpc_create_kthreads(ch, needed, 0);
  507. }
  508. /*
  509. * This function is where XPC's kthreads wait for messages to deliver.
  510. */
  511. static void
  512. xpc_kthread_waitmsgs(struct xpc_partition *part, struct xpc_channel *ch)
  513. {
  514. do {
  515. /* deliver messages to their intended recipients */
  516. while (ch->w_local_GP.get < ch->w_remote_GP.put &&
  517. !(ch->flags & XPC_C_DISCONNECTING)) {
  518. xpc_deliver_msg(ch);
  519. }
  520. if (atomic_inc_return(&ch->kthreads_idle) >
  521. ch->kthreads_idle_limit) {
  522. /* too many idle kthreads on this channel */
  523. atomic_dec(&ch->kthreads_idle);
  524. break;
  525. }
  526. dev_dbg(xpc_chan, "idle kthread calling "
  527. "wait_event_interruptible_exclusive()\n");
  528. (void)wait_event_interruptible_exclusive(ch->idle_wq,
  529. (ch->w_local_GP.get < ch->w_remote_GP.put ||
  530. (ch->flags & XPC_C_DISCONNECTING)));
  531. atomic_dec(&ch->kthreads_idle);
  532. } while (!(ch->flags & XPC_C_DISCONNECTING));
  533. }
  534. static int
  535. xpc_kthread_start(void *args)
  536. {
  537. short partid = XPC_UNPACK_ARG1(args);
  538. u16 ch_number = XPC_UNPACK_ARG2(args);
  539. struct xpc_partition *part = &xpc_partitions[partid];
  540. struct xpc_channel *ch;
  541. int n_needed;
  542. unsigned long irq_flags;
  543. dev_dbg(xpc_chan, "kthread starting, partid=%d, channel=%d\n",
  544. partid, ch_number);
  545. ch = &part->channels[ch_number];
  546. if (!(ch->flags & XPC_C_DISCONNECTING)) {
  547. /* let registerer know that connection has been established */
  548. spin_lock_irqsave(&ch->lock, irq_flags);
  549. if (!(ch->flags & XPC_C_CONNECTEDCALLOUT)) {
  550. ch->flags |= XPC_C_CONNECTEDCALLOUT;
  551. spin_unlock_irqrestore(&ch->lock, irq_flags);
  552. xpc_connected_callout(ch);
  553. spin_lock_irqsave(&ch->lock, irq_flags);
  554. ch->flags |= XPC_C_CONNECTEDCALLOUT_MADE;
  555. spin_unlock_irqrestore(&ch->lock, irq_flags);
  556. /*
  557. * It is possible that while the callout was being
  558. * made that the remote partition sent some messages.
  559. * If that is the case, we may need to activate
  560. * additional kthreads to help deliver them. We only
  561. * need one less than total #of messages to deliver.
  562. */
  563. n_needed = ch->w_remote_GP.put - ch->w_local_GP.get - 1;
  564. if (n_needed > 0 && !(ch->flags & XPC_C_DISCONNECTING))
  565. xpc_activate_kthreads(ch, n_needed);
  566. } else {
  567. spin_unlock_irqrestore(&ch->lock, irq_flags);
  568. }
  569. xpc_kthread_waitmsgs(part, ch);
  570. }
  571. /* let registerer know that connection is disconnecting */
  572. spin_lock_irqsave(&ch->lock, irq_flags);
  573. if ((ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) &&
  574. !(ch->flags & XPC_C_DISCONNECTINGCALLOUT)) {
  575. ch->flags |= XPC_C_DISCONNECTINGCALLOUT;
  576. spin_unlock_irqrestore(&ch->lock, irq_flags);
  577. xpc_disconnect_callout(ch, xpDisconnecting);
  578. spin_lock_irqsave(&ch->lock, irq_flags);
  579. ch->flags |= XPC_C_DISCONNECTINGCALLOUT_MADE;
  580. }
  581. spin_unlock_irqrestore(&ch->lock, irq_flags);
  582. if (atomic_dec_return(&ch->kthreads_assigned) == 0) {
  583. if (atomic_dec_return(&part->nchannels_engaged) == 0) {
  584. xpc_mark_partition_disengaged(part);
  585. xpc_IPI_send_disengage(part);
  586. }
  587. }
  588. xpc_msgqueue_deref(ch);
  589. dev_dbg(xpc_chan, "kthread exiting, partid=%d, channel=%d\n",
  590. partid, ch_number);
  591. xpc_part_deref(part);
  592. return 0;
  593. }
  594. /*
  595. * For each partition that XPC has established communications with, there is
  596. * a minimum of one kernel thread assigned to perform any operation that
  597. * may potentially sleep or block (basically the callouts to the asynchronous
  598. * functions registered via xpc_connect()).
  599. *
  600. * Additional kthreads are created and destroyed by XPC as the workload
  601. * demands.
  602. *
  603. * A kthread is assigned to one of the active channels that exists for a given
  604. * partition.
  605. */
  606. void
  607. xpc_create_kthreads(struct xpc_channel *ch, int needed,
  608. int ignore_disconnecting)
  609. {
  610. unsigned long irq_flags;
  611. u64 args = XPC_PACK_ARGS(ch->partid, ch->number);
  612. struct xpc_partition *part = &xpc_partitions[ch->partid];
  613. struct task_struct *kthread;
  614. while (needed-- > 0) {
  615. /*
  616. * The following is done on behalf of the newly created
  617. * kthread. That kthread is responsible for doing the
  618. * counterpart to the following before it exits.
  619. */
  620. if (ignore_disconnecting) {
  621. if (!atomic_inc_not_zero(&ch->kthreads_assigned)) {
  622. /* kthreads assigned had gone to zero */
  623. BUG_ON(!(ch->flags &
  624. XPC_C_DISCONNECTINGCALLOUT_MADE));
  625. break;
  626. }
  627. } else if (ch->flags & XPC_C_DISCONNECTING) {
  628. break;
  629. } else if (atomic_inc_return(&ch->kthreads_assigned) == 1) {
  630. if (atomic_inc_return(&part->nchannels_engaged) == 1)
  631. xpc_mark_partition_engaged(part);
  632. }
  633. (void)xpc_part_ref(part);
  634. xpc_msgqueue_ref(ch);
  635. kthread = kthread_run(xpc_kthread_start, (void *)args,
  636. "xpc%02dc%d", ch->partid, ch->number);
  637. if (IS_ERR(kthread)) {
  638. /* the fork failed */
  639. /*
  640. * NOTE: if (ignore_disconnecting &&
  641. * !(ch->flags & XPC_C_DISCONNECTINGCALLOUT)) is true,
  642. * then we'll deadlock if all other kthreads assigned
  643. * to this channel are blocked in the channel's
  644. * registerer, because the only thing that will unblock
  645. * them is the xpDisconnecting callout that this
  646. * failed kthread_run() would have made.
  647. */
  648. if (atomic_dec_return(&ch->kthreads_assigned) == 0 &&
  649. atomic_dec_return(&part->nchannels_engaged) == 0) {
  650. xpc_mark_partition_disengaged(part);
  651. xpc_IPI_send_disengage(part);
  652. }
  653. xpc_msgqueue_deref(ch);
  654. xpc_part_deref(part);
  655. if (atomic_read(&ch->kthreads_assigned) <
  656. ch->kthreads_idle_limit) {
  657. /*
  658. * Flag this as an error only if we have an
  659. * insufficient #of kthreads for the channel
  660. * to function.
  661. */
  662. spin_lock_irqsave(&ch->lock, irq_flags);
  663. XPC_DISCONNECT_CHANNEL(ch, xpLackOfResources,
  664. &irq_flags);
  665. spin_unlock_irqrestore(&ch->lock, irq_flags);
  666. }
  667. break;
  668. }
  669. }
  670. }
  671. void
  672. xpc_disconnect_wait(int ch_number)
  673. {
  674. unsigned long irq_flags;
  675. short partid;
  676. struct xpc_partition *part;
  677. struct xpc_channel *ch;
  678. int wakeup_channel_mgr;
  679. /* now wait for all callouts to the caller's function to cease */
  680. for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
  681. part = &xpc_partitions[partid];
  682. if (!xpc_part_ref(part))
  683. continue;
  684. ch = &part->channels[ch_number];
  685. if (!(ch->flags & XPC_C_WDISCONNECT)) {
  686. xpc_part_deref(part);
  687. continue;
  688. }
  689. wait_for_completion(&ch->wdisconnect_wait);
  690. spin_lock_irqsave(&ch->lock, irq_flags);
  691. DBUG_ON(!(ch->flags & XPC_C_DISCONNECTED));
  692. wakeup_channel_mgr = 0;
  693. if (ch->delayed_IPI_flags) {
  694. if (part->act_state != XPC_P_DEACTIVATING) {
  695. spin_lock(&part->IPI_lock);
  696. XPC_SET_IPI_FLAGS(part->local_IPI_amo,
  697. ch->number,
  698. ch->delayed_IPI_flags);
  699. spin_unlock(&part->IPI_lock);
  700. wakeup_channel_mgr = 1;
  701. }
  702. ch->delayed_IPI_flags = 0;
  703. }
  704. ch->flags &= ~XPC_C_WDISCONNECT;
  705. spin_unlock_irqrestore(&ch->lock, irq_flags);
  706. if (wakeup_channel_mgr)
  707. xpc_wakeup_channel_mgr(part);
  708. xpc_part_deref(part);
  709. }
  710. }
  711. static void
  712. xpc_do_exit(enum xp_retval reason)
  713. {
  714. short partid;
  715. int active_part_count, printed_waiting_msg = 0;
  716. struct xpc_partition *part;
  717. unsigned long printmsg_time, disengage_request_timeout = 0;
  718. /* a 'rmmod XPC' and a 'reboot' cannot both end up here together */
  719. DBUG_ON(xpc_exiting == 1);
  720. /*
  721. * Let the heartbeat checker thread and the discovery thread
  722. * (if one is running) know that they should exit. Also wake up
  723. * the heartbeat checker thread in case it's sleeping.
  724. */
  725. xpc_exiting = 1;
  726. wake_up_interruptible(&xpc_act_IRQ_wq);
  727. /* ignore all incoming interrupts */
  728. free_irq(SGI_XPC_ACTIVATE, NULL);
  729. /* wait for the discovery thread to exit */
  730. wait_for_completion(&xpc_discovery_exited);
  731. /* wait for the heartbeat checker thread to exit */
  732. wait_for_completion(&xpc_hb_checker_exited);
  733. /* sleep for a 1/3 of a second or so */
  734. (void)msleep_interruptible(300);
  735. /* wait for all partitions to become inactive */
  736. printmsg_time = jiffies + (XPC_DISENGAGE_PRINTMSG_INTERVAL * HZ);
  737. xpc_disengage_request_timedout = 0;
  738. do {
  739. active_part_count = 0;
  740. for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
  741. part = &xpc_partitions[partid];
  742. if (xpc_partition_disengaged(part) &&
  743. part->act_state == XPC_P_INACTIVE) {
  744. continue;
  745. }
  746. active_part_count++;
  747. XPC_DEACTIVATE_PARTITION(part, reason);
  748. if (part->disengage_request_timeout >
  749. disengage_request_timeout) {
  750. disengage_request_timeout =
  751. part->disengage_request_timeout;
  752. }
  753. }
  754. if (xpc_partition_engaged(-1UL)) {
  755. if (time_after(jiffies, printmsg_time)) {
  756. dev_info(xpc_part, "waiting for remote "
  757. "partitions to disengage, timeout in "
  758. "%ld seconds\n",
  759. (disengage_request_timeout - jiffies)
  760. / HZ);
  761. printmsg_time = jiffies +
  762. (XPC_DISENGAGE_PRINTMSG_INTERVAL * HZ);
  763. printed_waiting_msg = 1;
  764. }
  765. } else if (active_part_count > 0) {
  766. if (printed_waiting_msg) {
  767. dev_info(xpc_part, "waiting for local partition"
  768. " to disengage\n");
  769. printed_waiting_msg = 0;
  770. }
  771. } else {
  772. if (!xpc_disengage_request_timedout) {
  773. dev_info(xpc_part, "all partitions have "
  774. "disengaged\n");
  775. }
  776. break;
  777. }
  778. /* sleep for a 1/3 of a second or so */
  779. (void)msleep_interruptible(300);
  780. } while (1);
  781. DBUG_ON(xpc_partition_engaged(-1UL));
  782. /* indicate to others that our reserved page is uninitialized */
  783. xpc_rsvd_page->vars_pa = 0;
  784. /* now it's time to eliminate our heartbeat */
  785. del_timer_sync(&xpc_hb_timer);
  786. DBUG_ON(xpc_vars->heartbeating_to_mask != 0);
  787. if (reason == xpUnloading) {
  788. /* take ourselves off of the reboot_notifier_list */
  789. (void)unregister_reboot_notifier(&xpc_reboot_notifier);
  790. /* take ourselves off of the die_notifier list */
  791. (void)unregister_die_notifier(&xpc_die_notifier);
  792. }
  793. /* close down protections for IPI operations */
  794. xpc_restrict_IPI_ops();
  795. /* clear the interface to XPC's functions */
  796. xpc_clear_interface();
  797. if (xpc_sysctl)
  798. unregister_sysctl_table(xpc_sysctl);
  799. kfree(xpc_remote_copy_buffer_base);
  800. }
  801. /*
  802. * This function is called when the system is being rebooted.
  803. */
  804. static int
  805. xpc_system_reboot(struct notifier_block *nb, unsigned long event, void *unused)
  806. {
  807. enum xp_retval reason;
  808. switch (event) {
  809. case SYS_RESTART:
  810. reason = xpSystemReboot;
  811. break;
  812. case SYS_HALT:
  813. reason = xpSystemHalt;
  814. break;
  815. case SYS_POWER_OFF:
  816. reason = xpSystemPoweroff;
  817. break;
  818. default:
  819. reason = xpSystemGoingDown;
  820. }
  821. xpc_do_exit(reason);
  822. return NOTIFY_DONE;
  823. }
  824. /*
  825. * Notify other partitions to disengage from all references to our memory.
  826. */
  827. static void
  828. xpc_die_disengage(void)
  829. {
  830. struct xpc_partition *part;
  831. short partid;
  832. unsigned long engaged;
  833. long time, printmsg_time, disengage_request_timeout;
  834. /* keep xpc_hb_checker thread from doing anything (just in case) */
  835. xpc_exiting = 1;
  836. xpc_vars->heartbeating_to_mask = 0; /* indicate we're deactivated */
  837. for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
  838. part = &xpc_partitions[partid];
  839. if (!XPC_SUPPORTS_DISENGAGE_REQUEST(part->
  840. remote_vars_version)) {
  841. /* just in case it was left set by an earlier XPC */
  842. xpc_clear_partition_engaged(1UL << partid);
  843. continue;
  844. }
  845. if (xpc_partition_engaged(1UL << partid) ||
  846. part->act_state != XPC_P_INACTIVE) {
  847. xpc_request_partition_disengage(part);
  848. xpc_mark_partition_disengaged(part);
  849. xpc_IPI_send_disengage(part);
  850. }
  851. }
  852. time = rtc_time();
  853. printmsg_time = time +
  854. (XPC_DISENGAGE_PRINTMSG_INTERVAL * sn_rtc_cycles_per_second);
  855. disengage_request_timeout = time +
  856. (xpc_disengage_request_timelimit * sn_rtc_cycles_per_second);
  857. /* wait for all other partitions to disengage from us */
  858. while (1) {
  859. engaged = xpc_partition_engaged(-1UL);
  860. if (!engaged) {
  861. dev_info(xpc_part, "all partitions have disengaged\n");
  862. break;
  863. }
  864. time = rtc_time();
  865. if (time >= disengage_request_timeout) {
  866. for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
  867. if (engaged & (1UL << partid)) {
  868. dev_info(xpc_part, "disengage from "
  869. "remote partition %d timed "
  870. "out\n", partid);
  871. }
  872. }
  873. break;
  874. }
  875. if (time >= printmsg_time) {
  876. dev_info(xpc_part, "waiting for remote partitions to "
  877. "disengage, timeout in %ld seconds\n",
  878. (disengage_request_timeout - time) /
  879. sn_rtc_cycles_per_second);
  880. printmsg_time = time +
  881. (XPC_DISENGAGE_PRINTMSG_INTERVAL *
  882. sn_rtc_cycles_per_second);
  883. }
  884. }
  885. }
  886. /*
  887. * This function is called when the system is being restarted or halted due
  888. * to some sort of system failure. If this is the case we need to notify the
  889. * other partitions to disengage from all references to our memory.
  890. * This function can also be called when our heartbeater could be offlined
  891. * for a time. In this case we need to notify other partitions to not worry
  892. * about the lack of a heartbeat.
  893. */
  894. static int
  895. xpc_system_die(struct notifier_block *nb, unsigned long event, void *unused)
  896. {
  897. switch (event) {
  898. case DIE_MACHINE_RESTART:
  899. case DIE_MACHINE_HALT:
  900. xpc_die_disengage();
  901. break;
  902. case DIE_KDEBUG_ENTER:
  903. /* Should lack of heartbeat be ignored by other partitions? */
  904. if (!xpc_kdebug_ignore)
  905. break;
  906. /* fall through */
  907. case DIE_MCA_MONARCH_ENTER:
  908. case DIE_INIT_MONARCH_ENTER:
  909. xpc_vars->heartbeat++;
  910. xpc_vars->heartbeat_offline = 1;
  911. break;
  912. case DIE_KDEBUG_LEAVE:
  913. /* Is lack of heartbeat being ignored by other partitions? */
  914. if (!xpc_kdebug_ignore)
  915. break;
  916. /* fall through */
  917. case DIE_MCA_MONARCH_LEAVE:
  918. case DIE_INIT_MONARCH_LEAVE:
  919. xpc_vars->heartbeat++;
  920. xpc_vars->heartbeat_offline = 0;
  921. break;
  922. }
  923. return NOTIFY_DONE;
  924. }
  925. int __init
  926. xpc_init(void)
  927. {
  928. int ret;
  929. short partid;
  930. struct xpc_partition *part;
  931. struct task_struct *kthread;
  932. size_t buf_size;
  933. if (!ia64_platform_is("sn2"))
  934. return -ENODEV;
  935. buf_size = max(XPC_RP_VARS_SIZE,
  936. XPC_RP_HEADER_SIZE + XP_NASID_MASK_BYTES);
  937. xpc_remote_copy_buffer = xpc_kmalloc_cacheline_aligned(buf_size,
  938. GFP_KERNEL,
  939. &xpc_remote_copy_buffer_base);
  940. if (xpc_remote_copy_buffer == NULL)
  941. return -ENOMEM;
  942. snprintf(xpc_part->bus_id, BUS_ID_SIZE, "part");
  943. snprintf(xpc_chan->bus_id, BUS_ID_SIZE, "chan");
  944. xpc_sysctl = register_sysctl_table(xpc_sys_dir);
  945. /*
  946. * The first few fields of each entry of xpc_partitions[] need to
  947. * be initialized now so that calls to xpc_connect() and
  948. * xpc_disconnect() can be made prior to the activation of any remote
  949. * partition. NOTE THAT NONE OF THE OTHER FIELDS BELONGING TO THESE
  950. * ENTRIES ARE MEANINGFUL UNTIL AFTER AN ENTRY'S CORRESPONDING
  951. * PARTITION HAS BEEN ACTIVATED.
  952. */
  953. for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
  954. part = &xpc_partitions[partid];
  955. DBUG_ON((u64)part != L1_CACHE_ALIGN((u64)part));
  956. part->act_IRQ_rcvd = 0;
  957. spin_lock_init(&part->act_lock);
  958. part->act_state = XPC_P_INACTIVE;
  959. XPC_SET_REASON(part, 0, 0);
  960. init_timer(&part->disengage_request_timer);
  961. part->disengage_request_timer.function =
  962. xpc_timeout_partition_disengage_request;
  963. part->disengage_request_timer.data = (unsigned long)part;
  964. part->setup_state = XPC_P_UNSET;
  965. init_waitqueue_head(&part->teardown_wq);
  966. atomic_set(&part->references, 0);
  967. }
  968. /*
  969. * Open up protections for IPI operations (and AMO operations on
  970. * Shub 1.1 systems).
  971. */
  972. xpc_allow_IPI_ops();
  973. /*
  974. * Interrupts being processed will increment this atomic variable and
  975. * awaken the heartbeat thread which will process the interrupts.
  976. */
  977. atomic_set(&xpc_act_IRQ_rcvd, 0);
  978. /*
  979. * This is safe to do before the xpc_hb_checker thread has started
  980. * because the handler releases a wait queue. If an interrupt is
  981. * received before the thread is waiting, it will not go to sleep,
  982. * but rather immediately process the interrupt.
  983. */
  984. ret = request_irq(SGI_XPC_ACTIVATE, xpc_act_IRQ_handler, 0,
  985. "xpc hb", NULL);
  986. if (ret != 0) {
  987. dev_err(xpc_part, "can't register ACTIVATE IRQ handler, "
  988. "errno=%d\n", -ret);
  989. xpc_restrict_IPI_ops();
  990. if (xpc_sysctl)
  991. unregister_sysctl_table(xpc_sysctl);
  992. kfree(xpc_remote_copy_buffer_base);
  993. return -EBUSY;
  994. }
  995. /*
  996. * Fill the partition reserved page with the information needed by
  997. * other partitions to discover we are alive and establish initial
  998. * communications.
  999. */
  1000. xpc_rsvd_page = xpc_rsvd_page_init();
  1001. if (xpc_rsvd_page == NULL) {
  1002. dev_err(xpc_part, "could not setup our reserved page\n");
  1003. free_irq(SGI_XPC_ACTIVATE, NULL);
  1004. xpc_restrict_IPI_ops();
  1005. if (xpc_sysctl)
  1006. unregister_sysctl_table(xpc_sysctl);
  1007. kfree(xpc_remote_copy_buffer_base);
  1008. return -EBUSY;
  1009. }
  1010. /* add ourselves to the reboot_notifier_list */
  1011. ret = register_reboot_notifier(&xpc_reboot_notifier);
  1012. if (ret != 0)
  1013. dev_warn(xpc_part, "can't register reboot notifier\n");
  1014. /* add ourselves to the die_notifier list */
  1015. ret = register_die_notifier(&xpc_die_notifier);
  1016. if (ret != 0)
  1017. dev_warn(xpc_part, "can't register die notifier\n");
  1018. init_timer(&xpc_hb_timer);
  1019. xpc_hb_timer.function = xpc_hb_beater;
  1020. /*
  1021. * The real work-horse behind xpc. This processes incoming
  1022. * interrupts and monitors remote heartbeats.
  1023. */
  1024. kthread = kthread_run(xpc_hb_checker, NULL, XPC_HB_CHECK_THREAD_NAME);
  1025. if (IS_ERR(kthread)) {
  1026. dev_err(xpc_part, "failed while forking hb check thread\n");
  1027. /* indicate to others that our reserved page is uninitialized */
  1028. xpc_rsvd_page->vars_pa = 0;
  1029. /* take ourselves off of the reboot_notifier_list */
  1030. (void)unregister_reboot_notifier(&xpc_reboot_notifier);
  1031. /* take ourselves off of the die_notifier list */
  1032. (void)unregister_die_notifier(&xpc_die_notifier);
  1033. del_timer_sync(&xpc_hb_timer);
  1034. free_irq(SGI_XPC_ACTIVATE, NULL);
  1035. xpc_restrict_IPI_ops();
  1036. if (xpc_sysctl)
  1037. unregister_sysctl_table(xpc_sysctl);
  1038. kfree(xpc_remote_copy_buffer_base);
  1039. return -EBUSY;
  1040. }
  1041. /*
  1042. * Startup a thread that will attempt to discover other partitions to
  1043. * activate based on info provided by SAL. This new thread is short
  1044. * lived and will exit once discovery is complete.
  1045. */
  1046. kthread = kthread_run(xpc_initiate_discovery, NULL,
  1047. XPC_DISCOVERY_THREAD_NAME);
  1048. if (IS_ERR(kthread)) {
  1049. dev_err(xpc_part, "failed while forking discovery thread\n");
  1050. /* mark this new thread as a non-starter */
  1051. complete(&xpc_discovery_exited);
  1052. xpc_do_exit(xpUnloading);
  1053. return -EBUSY;
  1054. }
  1055. /* set the interface to point at XPC's functions */
  1056. xpc_set_interface(xpc_initiate_connect, xpc_initiate_disconnect,
  1057. xpc_initiate_allocate, xpc_initiate_send,
  1058. xpc_initiate_send_notify, xpc_initiate_received,
  1059. xpc_initiate_partid_to_nasids);
  1060. return 0;
  1061. }
  1062. module_init(xpc_init);
  1063. void __exit
  1064. xpc_exit(void)
  1065. {
  1066. xpc_do_exit(xpUnloading);
  1067. }
  1068. module_exit(xpc_exit);
  1069. MODULE_AUTHOR("Silicon Graphics, Inc.");
  1070. MODULE_DESCRIPTION("Cross Partition Communication (XPC) support");
  1071. MODULE_LICENSE("GPL");
  1072. module_param(xpc_hb_interval, int, 0);
  1073. MODULE_PARM_DESC(xpc_hb_interval, "Number of seconds between "
  1074. "heartbeat increments.");
  1075. module_param(xpc_hb_check_interval, int, 0);
  1076. MODULE_PARM_DESC(xpc_hb_check_interval, "Number of seconds between "
  1077. "heartbeat checks.");
  1078. module_param(xpc_disengage_request_timelimit, int, 0);
  1079. MODULE_PARM_DESC(xpc_disengage_request_timelimit, "Number of seconds to wait "
  1080. "for disengage request to complete.");
  1081. module_param(xpc_kdebug_ignore, int, 0);
  1082. MODULE_PARM_DESC(xpc_kdebug_ignore, "Should lack of heartbeat be ignored by "
  1083. "other partitions when dropping into kdebug.");