xpc_main.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  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-2009 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. * . Currently on sn2, we have no way to determine which nasid an IRQ
  28. * came from. Thus, xpc_send_IRQ_sn2() does a remote amo write
  29. * followed by an IPI. The amo indicates where data is to be pulled
  30. * from, so after the IPI arrives, the remote partition checks the amo
  31. * word. The IPI can actually arrive before the amo however, so other
  32. * code must periodically check for this case. Also, remote amo
  33. * operations do not reliably time out. Thus we do a remote PIO read
  34. * solely to know whether the remote partition is down and whether we
  35. * should stop sending IPIs to it. This remote PIO read operation is
  36. * set up in a special nofault region so SAL knows to ignore (and
  37. * cleanup) any errors due to the remote amo write, PIO read, and/or
  38. * PIO write operations.
  39. *
  40. * If/when new hardware solves this IPI problem, we should abandon
  41. * the current approach.
  42. *
  43. */
  44. #include <linux/module.h>
  45. #include <linux/slab.h>
  46. #include <linux/sysctl.h>
  47. #include <linux/device.h>
  48. #include <linux/delay.h>
  49. #include <linux/reboot.h>
  50. #include <linux/kdebug.h>
  51. #include <linux/kthread.h>
  52. #include "xpc.h"
  53. /* define two XPC debug device structures to be used with dev_dbg() et al */
  54. struct device_driver xpc_dbg_name = {
  55. .name = "xpc"
  56. };
  57. struct device xpc_part_dbg_subname = {
  58. .init_name = "", /* set to "part" at xpc_init() time */
  59. .driver = &xpc_dbg_name
  60. };
  61. struct device xpc_chan_dbg_subname = {
  62. .init_name = "", /* set to "chan" at xpc_init() time */
  63. .driver = &xpc_dbg_name
  64. };
  65. struct device *xpc_part = &xpc_part_dbg_subname;
  66. struct device *xpc_chan = &xpc_chan_dbg_subname;
  67. static int xpc_kdebug_ignore;
  68. /* systune related variables for /proc/sys directories */
  69. static int xpc_hb_interval = XPC_HB_DEFAULT_INTERVAL;
  70. static int xpc_hb_min_interval = 1;
  71. static int xpc_hb_max_interval = 10;
  72. static int xpc_hb_check_interval = XPC_HB_CHECK_DEFAULT_INTERVAL;
  73. static int xpc_hb_check_min_interval = 10;
  74. static int xpc_hb_check_max_interval = 120;
  75. int xpc_disengage_timelimit = XPC_DISENGAGE_DEFAULT_TIMELIMIT;
  76. static int xpc_disengage_min_timelimit; /* = 0 */
  77. static int xpc_disengage_max_timelimit = 120;
  78. static ctl_table xpc_sys_xpc_hb_dir[] = {
  79. {
  80. .procname = "hb_interval",
  81. .data = &xpc_hb_interval,
  82. .maxlen = sizeof(int),
  83. .mode = 0644,
  84. .proc_handler = proc_dointvec_minmax,
  85. .extra1 = &xpc_hb_min_interval,
  86. .extra2 = &xpc_hb_max_interval},
  87. {
  88. .procname = "hb_check_interval",
  89. .data = &xpc_hb_check_interval,
  90. .maxlen = sizeof(int),
  91. .mode = 0644,
  92. .proc_handler = proc_dointvec_minmax,
  93. .extra1 = &xpc_hb_check_min_interval,
  94. .extra2 = &xpc_hb_check_max_interval},
  95. {}
  96. };
  97. static ctl_table xpc_sys_xpc_dir[] = {
  98. {
  99. .procname = "hb",
  100. .mode = 0555,
  101. .child = xpc_sys_xpc_hb_dir},
  102. {
  103. .procname = "disengage_timelimit",
  104. .data = &xpc_disengage_timelimit,
  105. .maxlen = sizeof(int),
  106. .mode = 0644,
  107. .proc_handler = proc_dointvec_minmax,
  108. .extra1 = &xpc_disengage_min_timelimit,
  109. .extra2 = &xpc_disengage_max_timelimit},
  110. {}
  111. };
  112. static ctl_table xpc_sys_dir[] = {
  113. {
  114. .procname = "xpc",
  115. .mode = 0555,
  116. .child = xpc_sys_xpc_dir},
  117. {}
  118. };
  119. static struct ctl_table_header *xpc_sysctl;
  120. /* non-zero if any remote partition disengage was timed out */
  121. int xpc_disengage_timedout;
  122. /* #of activate IRQs received and not yet processed */
  123. int xpc_activate_IRQ_rcvd;
  124. DEFINE_SPINLOCK(xpc_activate_IRQ_rcvd_lock);
  125. /* IRQ handler notifies this wait queue on receipt of an IRQ */
  126. DECLARE_WAIT_QUEUE_HEAD(xpc_activate_IRQ_wq);
  127. static unsigned long xpc_hb_check_timeout;
  128. static struct timer_list xpc_hb_timer;
  129. /* notification that the xpc_hb_checker thread has exited */
  130. static DECLARE_COMPLETION(xpc_hb_checker_exited);
  131. /* notification that the xpc_discovery thread has exited */
  132. static DECLARE_COMPLETION(xpc_discovery_exited);
  133. static void xpc_kthread_waitmsgs(struct xpc_partition *, struct xpc_channel *);
  134. static int xpc_system_reboot(struct notifier_block *, unsigned long, void *);
  135. static struct notifier_block xpc_reboot_notifier = {
  136. .notifier_call = xpc_system_reboot,
  137. };
  138. static int xpc_system_die(struct notifier_block *, unsigned long, void *);
  139. static struct notifier_block xpc_die_notifier = {
  140. .notifier_call = xpc_system_die,
  141. };
  142. struct xpc_arch_operations xpc_arch_ops;
  143. /*
  144. * Timer function to enforce the timelimit on the partition disengage.
  145. */
  146. static void
  147. xpc_timeout_partition_disengage(unsigned long data)
  148. {
  149. struct xpc_partition *part = (struct xpc_partition *)data;
  150. DBUG_ON(time_is_after_jiffies(part->disengage_timeout));
  151. (void)xpc_partition_disengaged(part);
  152. DBUG_ON(part->disengage_timeout != 0);
  153. DBUG_ON(xpc_arch_ops.partition_engaged(XPC_PARTID(part)));
  154. }
  155. /*
  156. * Timer to produce the heartbeat. The timer structures function is
  157. * already set when this is initially called. A tunable is used to
  158. * specify when the next timeout should occur.
  159. */
  160. static void
  161. xpc_hb_beater(unsigned long dummy)
  162. {
  163. xpc_arch_ops.increment_heartbeat();
  164. if (time_is_before_eq_jiffies(xpc_hb_check_timeout))
  165. wake_up_interruptible(&xpc_activate_IRQ_wq);
  166. xpc_hb_timer.expires = jiffies + (xpc_hb_interval * HZ);
  167. add_timer(&xpc_hb_timer);
  168. }
  169. static void
  170. xpc_start_hb_beater(void)
  171. {
  172. xpc_arch_ops.heartbeat_init();
  173. init_timer(&xpc_hb_timer);
  174. xpc_hb_timer.function = xpc_hb_beater;
  175. xpc_hb_beater(0);
  176. }
  177. static void
  178. xpc_stop_hb_beater(void)
  179. {
  180. del_timer_sync(&xpc_hb_timer);
  181. xpc_arch_ops.heartbeat_exit();
  182. }
  183. /*
  184. * At periodic intervals, scan through all active partitions and ensure
  185. * their heartbeat is still active. If not, the partition is deactivated.
  186. */
  187. static void
  188. xpc_check_remote_hb(void)
  189. {
  190. struct xpc_partition *part;
  191. short partid;
  192. enum xp_retval ret;
  193. for (partid = 0; partid < xp_max_npartitions; partid++) {
  194. if (xpc_exiting)
  195. break;
  196. if (partid == xp_partition_id)
  197. continue;
  198. part = &xpc_partitions[partid];
  199. if (part->act_state == XPC_P_AS_INACTIVE ||
  200. part->act_state == XPC_P_AS_DEACTIVATING) {
  201. continue;
  202. }
  203. ret = xpc_arch_ops.get_remote_heartbeat(part);
  204. if (ret != xpSuccess)
  205. XPC_DEACTIVATE_PARTITION(part, ret);
  206. }
  207. }
  208. /*
  209. * This thread is responsible for nearly all of the partition
  210. * activation/deactivation.
  211. */
  212. static int
  213. xpc_hb_checker(void *ignore)
  214. {
  215. int force_IRQ = 0;
  216. /* this thread was marked active by xpc_hb_init() */
  217. set_cpus_allowed_ptr(current, cpumask_of(XPC_HB_CHECK_CPU));
  218. /* set our heartbeating to other partitions into motion */
  219. xpc_hb_check_timeout = jiffies + (xpc_hb_check_interval * HZ);
  220. xpc_start_hb_beater();
  221. while (!xpc_exiting) {
  222. dev_dbg(xpc_part, "woke up with %d ticks rem; %d IRQs have "
  223. "been received\n",
  224. (int)(xpc_hb_check_timeout - jiffies),
  225. xpc_activate_IRQ_rcvd);
  226. /* checking of remote heartbeats is skewed by IRQ handling */
  227. if (time_is_before_eq_jiffies(xpc_hb_check_timeout)) {
  228. xpc_hb_check_timeout = jiffies +
  229. (xpc_hb_check_interval * HZ);
  230. dev_dbg(xpc_part, "checking remote heartbeats\n");
  231. xpc_check_remote_hb();
  232. /*
  233. * On sn2 we need to periodically recheck to ensure no
  234. * IRQ/amo pairs have been missed.
  235. */
  236. if (is_shub())
  237. force_IRQ = 1;
  238. }
  239. /* check for outstanding IRQs */
  240. if (xpc_activate_IRQ_rcvd > 0 || force_IRQ != 0) {
  241. force_IRQ = 0;
  242. dev_dbg(xpc_part, "processing activate IRQs "
  243. "received\n");
  244. xpc_arch_ops.process_activate_IRQ_rcvd();
  245. }
  246. /* wait for IRQ or timeout */
  247. (void)wait_event_interruptible(xpc_activate_IRQ_wq,
  248. (time_is_before_eq_jiffies(
  249. xpc_hb_check_timeout) ||
  250. xpc_activate_IRQ_rcvd > 0 ||
  251. xpc_exiting));
  252. }
  253. xpc_stop_hb_beater();
  254. dev_dbg(xpc_part, "heartbeat checker is exiting\n");
  255. /* mark this thread as having exited */
  256. complete(&xpc_hb_checker_exited);
  257. return 0;
  258. }
  259. /*
  260. * This thread will attempt to discover other partitions to activate
  261. * based on info provided by SAL. This new thread is short lived and
  262. * will exit once discovery is complete.
  263. */
  264. static int
  265. xpc_initiate_discovery(void *ignore)
  266. {
  267. xpc_discovery();
  268. dev_dbg(xpc_part, "discovery thread is exiting\n");
  269. /* mark this thread as having exited */
  270. complete(&xpc_discovery_exited);
  271. return 0;
  272. }
  273. /*
  274. * The first kthread assigned to a newly activated partition is the one
  275. * created by XPC HB with which it calls xpc_activating(). XPC hangs on to
  276. * that kthread until the partition is brought down, at which time that kthread
  277. * returns back to XPC HB. (The return of that kthread will signify to XPC HB
  278. * that XPC has dismantled all communication infrastructure for the associated
  279. * partition.) This kthread becomes the channel manager for that partition.
  280. *
  281. * Each active partition has a channel manager, who, besides connecting and
  282. * disconnecting channels, will ensure that each of the partition's connected
  283. * channels has the required number of assigned kthreads to get the work done.
  284. */
  285. static void
  286. xpc_channel_mgr(struct xpc_partition *part)
  287. {
  288. while (part->act_state != XPC_P_AS_DEACTIVATING ||
  289. atomic_read(&part->nchannels_active) > 0 ||
  290. !xpc_partition_disengaged(part)) {
  291. xpc_process_sent_chctl_flags(part);
  292. /*
  293. * Wait until we've been requested to activate kthreads or
  294. * all of the channel's message queues have been torn down or
  295. * a signal is pending.
  296. *
  297. * The channel_mgr_requests is set to 1 after being awakened,
  298. * This is done to prevent the channel mgr from making one pass
  299. * through the loop for each request, since he will
  300. * be servicing all the requests in one pass. The reason it's
  301. * set to 1 instead of 0 is so that other kthreads will know
  302. * that the channel mgr is running and won't bother trying to
  303. * wake him up.
  304. */
  305. atomic_dec(&part->channel_mgr_requests);
  306. (void)wait_event_interruptible(part->channel_mgr_wq,
  307. (atomic_read(&part->channel_mgr_requests) > 0 ||
  308. part->chctl.all_flags != 0 ||
  309. (part->act_state == XPC_P_AS_DEACTIVATING &&
  310. atomic_read(&part->nchannels_active) == 0 &&
  311. xpc_partition_disengaged(part))));
  312. atomic_set(&part->channel_mgr_requests, 1);
  313. }
  314. }
  315. /*
  316. * Guarantee that the kzalloc'd memory is cacheline aligned.
  317. */
  318. void *
  319. xpc_kzalloc_cacheline_aligned(size_t size, gfp_t flags, void **base)
  320. {
  321. /* see if kzalloc will give us cachline aligned memory by default */
  322. *base = kzalloc(size, flags);
  323. if (*base == NULL)
  324. return NULL;
  325. if ((u64)*base == L1_CACHE_ALIGN((u64)*base))
  326. return *base;
  327. kfree(*base);
  328. /* nope, we'll have to do it ourselves */
  329. *base = kzalloc(size + L1_CACHE_BYTES, flags);
  330. if (*base == NULL)
  331. return NULL;
  332. return (void *)L1_CACHE_ALIGN((u64)*base);
  333. }
  334. /*
  335. * Setup the channel structures necessary to support XPartition Communication
  336. * between the specified remote partition and the local one.
  337. */
  338. static enum xp_retval
  339. xpc_setup_ch_structures(struct xpc_partition *part)
  340. {
  341. enum xp_retval ret;
  342. int ch_number;
  343. struct xpc_channel *ch;
  344. short partid = XPC_PARTID(part);
  345. /*
  346. * Allocate all of the channel structures as a contiguous chunk of
  347. * memory.
  348. */
  349. DBUG_ON(part->channels != NULL);
  350. part->channels = kzalloc(sizeof(struct xpc_channel) * XPC_MAX_NCHANNELS,
  351. GFP_KERNEL);
  352. if (part->channels == NULL) {
  353. dev_err(xpc_chan, "can't get memory for channels\n");
  354. return xpNoMemory;
  355. }
  356. /* allocate the remote open and close args */
  357. part->remote_openclose_args =
  358. xpc_kzalloc_cacheline_aligned(XPC_OPENCLOSE_ARGS_SIZE,
  359. GFP_KERNEL, &part->
  360. remote_openclose_args_base);
  361. if (part->remote_openclose_args == NULL) {
  362. dev_err(xpc_chan, "can't get memory for remote connect args\n");
  363. ret = xpNoMemory;
  364. goto out_1;
  365. }
  366. part->chctl.all_flags = 0;
  367. spin_lock_init(&part->chctl_lock);
  368. atomic_set(&part->channel_mgr_requests, 1);
  369. init_waitqueue_head(&part->channel_mgr_wq);
  370. part->nchannels = XPC_MAX_NCHANNELS;
  371. atomic_set(&part->nchannels_active, 0);
  372. atomic_set(&part->nchannels_engaged, 0);
  373. for (ch_number = 0; ch_number < part->nchannels; ch_number++) {
  374. ch = &part->channels[ch_number];
  375. ch->partid = partid;
  376. ch->number = ch_number;
  377. ch->flags = XPC_C_DISCONNECTED;
  378. atomic_set(&ch->kthreads_assigned, 0);
  379. atomic_set(&ch->kthreads_idle, 0);
  380. atomic_set(&ch->kthreads_active, 0);
  381. atomic_set(&ch->references, 0);
  382. atomic_set(&ch->n_to_notify, 0);
  383. spin_lock_init(&ch->lock);
  384. init_completion(&ch->wdisconnect_wait);
  385. atomic_set(&ch->n_on_msg_allocate_wq, 0);
  386. init_waitqueue_head(&ch->msg_allocate_wq);
  387. init_waitqueue_head(&ch->idle_wq);
  388. }
  389. ret = xpc_arch_ops.setup_ch_structures(part);
  390. if (ret != xpSuccess)
  391. goto out_2;
  392. /*
  393. * With the setting of the partition setup_state to XPC_P_SS_SETUP,
  394. * we're declaring that this partition is ready to go.
  395. */
  396. part->setup_state = XPC_P_SS_SETUP;
  397. return xpSuccess;
  398. /* setup of ch structures failed */
  399. out_2:
  400. kfree(part->remote_openclose_args_base);
  401. part->remote_openclose_args = NULL;
  402. out_1:
  403. kfree(part->channels);
  404. part->channels = NULL;
  405. return ret;
  406. }
  407. /*
  408. * Teardown the channel structures necessary to support XPartition Communication
  409. * between the specified remote partition and the local one.
  410. */
  411. static void
  412. xpc_teardown_ch_structures(struct xpc_partition *part)
  413. {
  414. DBUG_ON(atomic_read(&part->nchannels_engaged) != 0);
  415. DBUG_ON(atomic_read(&part->nchannels_active) != 0);
  416. /*
  417. * Make this partition inaccessible to local processes by marking it
  418. * as no longer setup. Then wait before proceeding with the teardown
  419. * until all existing references cease.
  420. */
  421. DBUG_ON(part->setup_state != XPC_P_SS_SETUP);
  422. part->setup_state = XPC_P_SS_WTEARDOWN;
  423. wait_event(part->teardown_wq, (atomic_read(&part->references) == 0));
  424. /* now we can begin tearing down the infrastructure */
  425. xpc_arch_ops.teardown_ch_structures(part);
  426. kfree(part->remote_openclose_args_base);
  427. part->remote_openclose_args = NULL;
  428. kfree(part->channels);
  429. part->channels = NULL;
  430. part->setup_state = XPC_P_SS_TORNDOWN;
  431. }
  432. /*
  433. * When XPC HB determines that a partition has come up, it will create a new
  434. * kthread and that kthread will call this function to attempt to set up the
  435. * basic infrastructure used for Cross Partition Communication with the newly
  436. * upped partition.
  437. *
  438. * The kthread that was created by XPC HB and which setup the XPC
  439. * infrastructure will remain assigned to the partition becoming the channel
  440. * manager for that partition until the partition is deactivating, at which
  441. * time the kthread will teardown the XPC infrastructure and then exit.
  442. */
  443. static int
  444. xpc_activating(void *__partid)
  445. {
  446. short partid = (u64)__partid;
  447. struct xpc_partition *part = &xpc_partitions[partid];
  448. unsigned long irq_flags;
  449. DBUG_ON(partid < 0 || partid >= xp_max_npartitions);
  450. spin_lock_irqsave(&part->act_lock, irq_flags);
  451. if (part->act_state == XPC_P_AS_DEACTIVATING) {
  452. part->act_state = XPC_P_AS_INACTIVE;
  453. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  454. part->remote_rp_pa = 0;
  455. return 0;
  456. }
  457. /* indicate the thread is activating */
  458. DBUG_ON(part->act_state != XPC_P_AS_ACTIVATION_REQ);
  459. part->act_state = XPC_P_AS_ACTIVATING;
  460. XPC_SET_REASON(part, 0, 0);
  461. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  462. dev_dbg(xpc_part, "activating partition %d\n", partid);
  463. xpc_arch_ops.allow_hb(partid);
  464. if (xpc_setup_ch_structures(part) == xpSuccess) {
  465. (void)xpc_part_ref(part); /* this will always succeed */
  466. if (xpc_arch_ops.make_first_contact(part) == xpSuccess) {
  467. xpc_mark_partition_active(part);
  468. xpc_channel_mgr(part);
  469. /* won't return until partition is deactivating */
  470. }
  471. xpc_part_deref(part);
  472. xpc_teardown_ch_structures(part);
  473. }
  474. xpc_arch_ops.disallow_hb(partid);
  475. xpc_mark_partition_inactive(part);
  476. if (part->reason == xpReactivating) {
  477. /* interrupting ourselves results in activating partition */
  478. xpc_arch_ops.request_partition_reactivation(part);
  479. }
  480. return 0;
  481. }
  482. void
  483. xpc_activate_partition(struct xpc_partition *part)
  484. {
  485. short partid = XPC_PARTID(part);
  486. unsigned long irq_flags;
  487. struct task_struct *kthread;
  488. spin_lock_irqsave(&part->act_lock, irq_flags);
  489. DBUG_ON(part->act_state != XPC_P_AS_INACTIVE);
  490. part->act_state = XPC_P_AS_ACTIVATION_REQ;
  491. XPC_SET_REASON(part, xpCloneKThread, __LINE__);
  492. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  493. kthread = kthread_run(xpc_activating, (void *)((u64)partid), "xpc%02d",
  494. partid);
  495. if (IS_ERR(kthread)) {
  496. spin_lock_irqsave(&part->act_lock, irq_flags);
  497. part->act_state = XPC_P_AS_INACTIVE;
  498. XPC_SET_REASON(part, xpCloneKThreadFailed, __LINE__);
  499. spin_unlock_irqrestore(&part->act_lock, irq_flags);
  500. }
  501. }
  502. void
  503. xpc_activate_kthreads(struct xpc_channel *ch, int needed)
  504. {
  505. int idle = atomic_read(&ch->kthreads_idle);
  506. int assigned = atomic_read(&ch->kthreads_assigned);
  507. int wakeup;
  508. DBUG_ON(needed <= 0);
  509. if (idle > 0) {
  510. wakeup = (needed > idle) ? idle : needed;
  511. needed -= wakeup;
  512. dev_dbg(xpc_chan, "wakeup %d idle kthreads, partid=%d, "
  513. "channel=%d\n", wakeup, ch->partid, ch->number);
  514. /* only wakeup the requested number of kthreads */
  515. wake_up_nr(&ch->idle_wq, wakeup);
  516. }
  517. if (needed <= 0)
  518. return;
  519. if (needed + assigned > ch->kthreads_assigned_limit) {
  520. needed = ch->kthreads_assigned_limit - assigned;
  521. if (needed <= 0)
  522. return;
  523. }
  524. dev_dbg(xpc_chan, "create %d new kthreads, partid=%d, channel=%d\n",
  525. needed, ch->partid, ch->number);
  526. xpc_create_kthreads(ch, needed, 0);
  527. }
  528. /*
  529. * This function is where XPC's kthreads wait for messages to deliver.
  530. */
  531. static void
  532. xpc_kthread_waitmsgs(struct xpc_partition *part, struct xpc_channel *ch)
  533. {
  534. int (*n_of_deliverable_payloads) (struct xpc_channel *) =
  535. xpc_arch_ops.n_of_deliverable_payloads;
  536. do {
  537. /* deliver messages to their intended recipients */
  538. while (n_of_deliverable_payloads(ch) > 0 &&
  539. !(ch->flags & XPC_C_DISCONNECTING)) {
  540. xpc_deliver_payload(ch);
  541. }
  542. if (atomic_inc_return(&ch->kthreads_idle) >
  543. ch->kthreads_idle_limit) {
  544. /* too many idle kthreads on this channel */
  545. atomic_dec(&ch->kthreads_idle);
  546. break;
  547. }
  548. dev_dbg(xpc_chan, "idle kthread calling "
  549. "wait_event_interruptible_exclusive()\n");
  550. (void)wait_event_interruptible_exclusive(ch->idle_wq,
  551. (n_of_deliverable_payloads(ch) > 0 ||
  552. (ch->flags & XPC_C_DISCONNECTING)));
  553. atomic_dec(&ch->kthreads_idle);
  554. } while (!(ch->flags & XPC_C_DISCONNECTING));
  555. }
  556. static int
  557. xpc_kthread_start(void *args)
  558. {
  559. short partid = XPC_UNPACK_ARG1(args);
  560. u16 ch_number = XPC_UNPACK_ARG2(args);
  561. struct xpc_partition *part = &xpc_partitions[partid];
  562. struct xpc_channel *ch;
  563. int n_needed;
  564. unsigned long irq_flags;
  565. int (*n_of_deliverable_payloads) (struct xpc_channel *) =
  566. xpc_arch_ops.n_of_deliverable_payloads;
  567. dev_dbg(xpc_chan, "kthread starting, partid=%d, channel=%d\n",
  568. partid, ch_number);
  569. ch = &part->channels[ch_number];
  570. if (!(ch->flags & XPC_C_DISCONNECTING)) {
  571. /* let registerer know that connection has been established */
  572. spin_lock_irqsave(&ch->lock, irq_flags);
  573. if (!(ch->flags & XPC_C_CONNECTEDCALLOUT)) {
  574. ch->flags |= XPC_C_CONNECTEDCALLOUT;
  575. spin_unlock_irqrestore(&ch->lock, irq_flags);
  576. xpc_connected_callout(ch);
  577. spin_lock_irqsave(&ch->lock, irq_flags);
  578. ch->flags |= XPC_C_CONNECTEDCALLOUT_MADE;
  579. spin_unlock_irqrestore(&ch->lock, irq_flags);
  580. /*
  581. * It is possible that while the callout was being
  582. * made that the remote partition sent some messages.
  583. * If that is the case, we may need to activate
  584. * additional kthreads to help deliver them. We only
  585. * need one less than total #of messages to deliver.
  586. */
  587. n_needed = n_of_deliverable_payloads(ch) - 1;
  588. if (n_needed > 0 && !(ch->flags & XPC_C_DISCONNECTING))
  589. xpc_activate_kthreads(ch, n_needed);
  590. } else {
  591. spin_unlock_irqrestore(&ch->lock, irq_flags);
  592. }
  593. xpc_kthread_waitmsgs(part, ch);
  594. }
  595. /* let registerer know that connection is disconnecting */
  596. spin_lock_irqsave(&ch->lock, irq_flags);
  597. if ((ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) &&
  598. !(ch->flags & XPC_C_DISCONNECTINGCALLOUT)) {
  599. ch->flags |= XPC_C_DISCONNECTINGCALLOUT;
  600. spin_unlock_irqrestore(&ch->lock, irq_flags);
  601. xpc_disconnect_callout(ch, xpDisconnecting);
  602. spin_lock_irqsave(&ch->lock, irq_flags);
  603. ch->flags |= XPC_C_DISCONNECTINGCALLOUT_MADE;
  604. }
  605. spin_unlock_irqrestore(&ch->lock, irq_flags);
  606. if (atomic_dec_return(&ch->kthreads_assigned) == 0 &&
  607. atomic_dec_return(&part->nchannels_engaged) == 0) {
  608. xpc_arch_ops.indicate_partition_disengaged(part);
  609. }
  610. xpc_msgqueue_deref(ch);
  611. dev_dbg(xpc_chan, "kthread exiting, partid=%d, channel=%d\n",
  612. partid, ch_number);
  613. xpc_part_deref(part);
  614. return 0;
  615. }
  616. /*
  617. * For each partition that XPC has established communications with, there is
  618. * a minimum of one kernel thread assigned to perform any operation that
  619. * may potentially sleep or block (basically the callouts to the asynchronous
  620. * functions registered via xpc_connect()).
  621. *
  622. * Additional kthreads are created and destroyed by XPC as the workload
  623. * demands.
  624. *
  625. * A kthread is assigned to one of the active channels that exists for a given
  626. * partition.
  627. */
  628. void
  629. xpc_create_kthreads(struct xpc_channel *ch, int needed,
  630. int ignore_disconnecting)
  631. {
  632. unsigned long irq_flags;
  633. u64 args = XPC_PACK_ARGS(ch->partid, ch->number);
  634. struct xpc_partition *part = &xpc_partitions[ch->partid];
  635. struct task_struct *kthread;
  636. void (*indicate_partition_disengaged) (struct xpc_partition *) =
  637. xpc_arch_ops.indicate_partition_disengaged;
  638. while (needed-- > 0) {
  639. /*
  640. * The following is done on behalf of the newly created
  641. * kthread. That kthread is responsible for doing the
  642. * counterpart to the following before it exits.
  643. */
  644. if (ignore_disconnecting) {
  645. if (!atomic_inc_not_zero(&ch->kthreads_assigned)) {
  646. /* kthreads assigned had gone to zero */
  647. BUG_ON(!(ch->flags &
  648. XPC_C_DISCONNECTINGCALLOUT_MADE));
  649. break;
  650. }
  651. } else if (ch->flags & XPC_C_DISCONNECTING) {
  652. break;
  653. } else if (atomic_inc_return(&ch->kthreads_assigned) == 1 &&
  654. atomic_inc_return(&part->nchannels_engaged) == 1) {
  655. xpc_arch_ops.indicate_partition_engaged(part);
  656. }
  657. (void)xpc_part_ref(part);
  658. xpc_msgqueue_ref(ch);
  659. kthread = kthread_run(xpc_kthread_start, (void *)args,
  660. "xpc%02dc%d", ch->partid, ch->number);
  661. if (IS_ERR(kthread)) {
  662. /* the fork failed */
  663. /*
  664. * NOTE: if (ignore_disconnecting &&
  665. * !(ch->flags & XPC_C_DISCONNECTINGCALLOUT)) is true,
  666. * then we'll deadlock if all other kthreads assigned
  667. * to this channel are blocked in the channel's
  668. * registerer, because the only thing that will unblock
  669. * them is the xpDisconnecting callout that this
  670. * failed kthread_run() would have made.
  671. */
  672. if (atomic_dec_return(&ch->kthreads_assigned) == 0 &&
  673. atomic_dec_return(&part->nchannels_engaged) == 0) {
  674. indicate_partition_disengaged(part);
  675. }
  676. xpc_msgqueue_deref(ch);
  677. xpc_part_deref(part);
  678. if (atomic_read(&ch->kthreads_assigned) <
  679. ch->kthreads_idle_limit) {
  680. /*
  681. * Flag this as an error only if we have an
  682. * insufficient #of kthreads for the channel
  683. * to function.
  684. */
  685. spin_lock_irqsave(&ch->lock, irq_flags);
  686. XPC_DISCONNECT_CHANNEL(ch, xpLackOfResources,
  687. &irq_flags);
  688. spin_unlock_irqrestore(&ch->lock, irq_flags);
  689. }
  690. break;
  691. }
  692. }
  693. }
  694. void
  695. xpc_disconnect_wait(int ch_number)
  696. {
  697. unsigned long irq_flags;
  698. short partid;
  699. struct xpc_partition *part;
  700. struct xpc_channel *ch;
  701. int wakeup_channel_mgr;
  702. /* now wait for all callouts to the caller's function to cease */
  703. for (partid = 0; partid < xp_max_npartitions; partid++) {
  704. part = &xpc_partitions[partid];
  705. if (!xpc_part_ref(part))
  706. continue;
  707. ch = &part->channels[ch_number];
  708. if (!(ch->flags & XPC_C_WDISCONNECT)) {
  709. xpc_part_deref(part);
  710. continue;
  711. }
  712. wait_for_completion(&ch->wdisconnect_wait);
  713. spin_lock_irqsave(&ch->lock, irq_flags);
  714. DBUG_ON(!(ch->flags & XPC_C_DISCONNECTED));
  715. wakeup_channel_mgr = 0;
  716. if (ch->delayed_chctl_flags) {
  717. if (part->act_state != XPC_P_AS_DEACTIVATING) {
  718. spin_lock(&part->chctl_lock);
  719. part->chctl.flags[ch->number] |=
  720. ch->delayed_chctl_flags;
  721. spin_unlock(&part->chctl_lock);
  722. wakeup_channel_mgr = 1;
  723. }
  724. ch->delayed_chctl_flags = 0;
  725. }
  726. ch->flags &= ~XPC_C_WDISCONNECT;
  727. spin_unlock_irqrestore(&ch->lock, irq_flags);
  728. if (wakeup_channel_mgr)
  729. xpc_wakeup_channel_mgr(part);
  730. xpc_part_deref(part);
  731. }
  732. }
  733. static int
  734. xpc_setup_partitions(void)
  735. {
  736. short partid;
  737. struct xpc_partition *part;
  738. xpc_partitions = kzalloc(sizeof(struct xpc_partition) *
  739. xp_max_npartitions, GFP_KERNEL);
  740. if (xpc_partitions == NULL) {
  741. dev_err(xpc_part, "can't get memory for partition structure\n");
  742. return -ENOMEM;
  743. }
  744. /*
  745. * The first few fields of each entry of xpc_partitions[] need to
  746. * be initialized now so that calls to xpc_connect() and
  747. * xpc_disconnect() can be made prior to the activation of any remote
  748. * partition. NOTE THAT NONE OF THE OTHER FIELDS BELONGING TO THESE
  749. * ENTRIES ARE MEANINGFUL UNTIL AFTER AN ENTRY'S CORRESPONDING
  750. * PARTITION HAS BEEN ACTIVATED.
  751. */
  752. for (partid = 0; partid < xp_max_npartitions; partid++) {
  753. part = &xpc_partitions[partid];
  754. DBUG_ON((u64)part != L1_CACHE_ALIGN((u64)part));
  755. part->activate_IRQ_rcvd = 0;
  756. spin_lock_init(&part->act_lock);
  757. part->act_state = XPC_P_AS_INACTIVE;
  758. XPC_SET_REASON(part, 0, 0);
  759. init_timer(&part->disengage_timer);
  760. part->disengage_timer.function =
  761. xpc_timeout_partition_disengage;
  762. part->disengage_timer.data = (unsigned long)part;
  763. part->setup_state = XPC_P_SS_UNSET;
  764. init_waitqueue_head(&part->teardown_wq);
  765. atomic_set(&part->references, 0);
  766. }
  767. return xpc_arch_ops.setup_partitions();
  768. }
  769. static void
  770. xpc_teardown_partitions(void)
  771. {
  772. xpc_arch_ops.teardown_partitions();
  773. kfree(xpc_partitions);
  774. }
  775. static void
  776. xpc_do_exit(enum xp_retval reason)
  777. {
  778. short partid;
  779. int active_part_count, printed_waiting_msg = 0;
  780. struct xpc_partition *part;
  781. unsigned long printmsg_time, disengage_timeout = 0;
  782. /* a 'rmmod XPC' and a 'reboot' cannot both end up here together */
  783. DBUG_ON(xpc_exiting == 1);
  784. /*
  785. * Let the heartbeat checker thread and the discovery thread
  786. * (if one is running) know that they should exit. Also wake up
  787. * the heartbeat checker thread in case it's sleeping.
  788. */
  789. xpc_exiting = 1;
  790. wake_up_interruptible(&xpc_activate_IRQ_wq);
  791. /* wait for the discovery thread to exit */
  792. wait_for_completion(&xpc_discovery_exited);
  793. /* wait for the heartbeat checker thread to exit */
  794. wait_for_completion(&xpc_hb_checker_exited);
  795. /* sleep for a 1/3 of a second or so */
  796. (void)msleep_interruptible(300);
  797. /* wait for all partitions to become inactive */
  798. printmsg_time = jiffies + (XPC_DEACTIVATE_PRINTMSG_INTERVAL * HZ);
  799. xpc_disengage_timedout = 0;
  800. do {
  801. active_part_count = 0;
  802. for (partid = 0; partid < xp_max_npartitions; partid++) {
  803. part = &xpc_partitions[partid];
  804. if (xpc_partition_disengaged(part) &&
  805. part->act_state == XPC_P_AS_INACTIVE) {
  806. continue;
  807. }
  808. active_part_count++;
  809. XPC_DEACTIVATE_PARTITION(part, reason);
  810. if (part->disengage_timeout > disengage_timeout)
  811. disengage_timeout = part->disengage_timeout;
  812. }
  813. if (xpc_arch_ops.any_partition_engaged()) {
  814. if (time_is_before_jiffies(printmsg_time)) {
  815. dev_info(xpc_part, "waiting for remote "
  816. "partitions to deactivate, timeout in "
  817. "%ld seconds\n", (disengage_timeout -
  818. jiffies) / HZ);
  819. printmsg_time = jiffies +
  820. (XPC_DEACTIVATE_PRINTMSG_INTERVAL * HZ);
  821. printed_waiting_msg = 1;
  822. }
  823. } else if (active_part_count > 0) {
  824. if (printed_waiting_msg) {
  825. dev_info(xpc_part, "waiting for local partition"
  826. " to deactivate\n");
  827. printed_waiting_msg = 0;
  828. }
  829. } else {
  830. if (!xpc_disengage_timedout) {
  831. dev_info(xpc_part, "all partitions have "
  832. "deactivated\n");
  833. }
  834. break;
  835. }
  836. /* sleep for a 1/3 of a second or so */
  837. (void)msleep_interruptible(300);
  838. } while (1);
  839. DBUG_ON(xpc_arch_ops.any_partition_engaged());
  840. xpc_teardown_rsvd_page();
  841. if (reason == xpUnloading) {
  842. (void)unregister_die_notifier(&xpc_die_notifier);
  843. (void)unregister_reboot_notifier(&xpc_reboot_notifier);
  844. }
  845. /* clear the interface to XPC's functions */
  846. xpc_clear_interface();
  847. if (xpc_sysctl)
  848. unregister_sysctl_table(xpc_sysctl);
  849. xpc_teardown_partitions();
  850. if (is_shub())
  851. xpc_exit_sn2();
  852. else if (is_uv())
  853. xpc_exit_uv();
  854. }
  855. /*
  856. * This function is called when the system is being rebooted.
  857. */
  858. static int
  859. xpc_system_reboot(struct notifier_block *nb, unsigned long event, void *unused)
  860. {
  861. enum xp_retval reason;
  862. switch (event) {
  863. case SYS_RESTART:
  864. reason = xpSystemReboot;
  865. break;
  866. case SYS_HALT:
  867. reason = xpSystemHalt;
  868. break;
  869. case SYS_POWER_OFF:
  870. reason = xpSystemPoweroff;
  871. break;
  872. default:
  873. reason = xpSystemGoingDown;
  874. }
  875. xpc_do_exit(reason);
  876. return NOTIFY_DONE;
  877. }
  878. /*
  879. * Notify other partitions to deactivate from us by first disengaging from all
  880. * references to our memory.
  881. */
  882. static void
  883. xpc_die_deactivate(void)
  884. {
  885. struct xpc_partition *part;
  886. short partid;
  887. int any_engaged;
  888. long keep_waiting;
  889. long wait_to_print;
  890. /* keep xpc_hb_checker thread from doing anything (just in case) */
  891. xpc_exiting = 1;
  892. xpc_arch_ops.disallow_all_hbs(); /*indicate we're deactivated */
  893. for (partid = 0; partid < xp_max_npartitions; partid++) {
  894. part = &xpc_partitions[partid];
  895. if (xpc_arch_ops.partition_engaged(partid) ||
  896. part->act_state != XPC_P_AS_INACTIVE) {
  897. xpc_arch_ops.request_partition_deactivation(part);
  898. xpc_arch_ops.indicate_partition_disengaged(part);
  899. }
  900. }
  901. /*
  902. * Though we requested that all other partitions deactivate from us,
  903. * we only wait until they've all disengaged or we've reached the
  904. * defined timelimit.
  905. *
  906. * Given that one iteration through the following while-loop takes
  907. * approximately 200 microseconds, calculate the #of loops to take
  908. * before bailing and the #of loops before printing a waiting message.
  909. */
  910. keep_waiting = xpc_disengage_timelimit * 1000 * 5;
  911. wait_to_print = XPC_DEACTIVATE_PRINTMSG_INTERVAL * 1000 * 5;
  912. while (1) {
  913. any_engaged = xpc_arch_ops.any_partition_engaged();
  914. if (!any_engaged) {
  915. dev_info(xpc_part, "all partitions have deactivated\n");
  916. break;
  917. }
  918. if (!keep_waiting--) {
  919. for (partid = 0; partid < xp_max_npartitions;
  920. partid++) {
  921. if (xpc_arch_ops.partition_engaged(partid)) {
  922. dev_info(xpc_part, "deactivate from "
  923. "remote partition %d timed "
  924. "out\n", partid);
  925. }
  926. }
  927. break;
  928. }
  929. if (!wait_to_print--) {
  930. dev_info(xpc_part, "waiting for remote partitions to "
  931. "deactivate, timeout in %ld seconds\n",
  932. keep_waiting / (1000 * 5));
  933. wait_to_print = XPC_DEACTIVATE_PRINTMSG_INTERVAL *
  934. 1000 * 5;
  935. }
  936. udelay(200);
  937. }
  938. }
  939. /*
  940. * This function is called when the system is being restarted or halted due
  941. * to some sort of system failure. If this is the case we need to notify the
  942. * other partitions to disengage from all references to our memory.
  943. * This function can also be called when our heartbeater could be offlined
  944. * for a time. In this case we need to notify other partitions to not worry
  945. * about the lack of a heartbeat.
  946. */
  947. static int
  948. xpc_system_die(struct notifier_block *nb, unsigned long event, void *unused)
  949. {
  950. #ifdef CONFIG_IA64 /* !!! temporary kludge */
  951. switch (event) {
  952. case DIE_MACHINE_RESTART:
  953. case DIE_MACHINE_HALT:
  954. xpc_die_deactivate();
  955. break;
  956. case DIE_KDEBUG_ENTER:
  957. /* Should lack of heartbeat be ignored by other partitions? */
  958. if (!xpc_kdebug_ignore)
  959. break;
  960. /* fall through */
  961. case DIE_MCA_MONARCH_ENTER:
  962. case DIE_INIT_MONARCH_ENTER:
  963. xpc_arch_ops.offline_heartbeat();
  964. break;
  965. case DIE_KDEBUG_LEAVE:
  966. /* Is lack of heartbeat being ignored by other partitions? */
  967. if (!xpc_kdebug_ignore)
  968. break;
  969. /* fall through */
  970. case DIE_MCA_MONARCH_LEAVE:
  971. case DIE_INIT_MONARCH_LEAVE:
  972. xpc_arch_ops.online_heartbeat();
  973. break;
  974. }
  975. #else
  976. xpc_die_deactivate();
  977. #endif
  978. return NOTIFY_DONE;
  979. }
  980. int __init
  981. xpc_init(void)
  982. {
  983. int ret;
  984. struct task_struct *kthread;
  985. dev_set_name(xpc_part, "part");
  986. dev_set_name(xpc_chan, "chan");
  987. if (is_shub()) {
  988. /*
  989. * The ia64-sn2 architecture supports at most 64 partitions.
  990. * And the inability to unregister remote amos restricts us
  991. * further to only support exactly 64 partitions on this
  992. * architecture, no less.
  993. */
  994. if (xp_max_npartitions != 64) {
  995. dev_err(xpc_part, "max #of partitions not set to 64\n");
  996. ret = -EINVAL;
  997. } else {
  998. ret = xpc_init_sn2();
  999. }
  1000. } else if (is_uv()) {
  1001. ret = xpc_init_uv();
  1002. } else {
  1003. ret = -ENODEV;
  1004. }
  1005. if (ret != 0)
  1006. return ret;
  1007. ret = xpc_setup_partitions();
  1008. if (ret != 0) {
  1009. dev_err(xpc_part, "can't get memory for partition structure\n");
  1010. goto out_1;
  1011. }
  1012. xpc_sysctl = register_sysctl_table(xpc_sys_dir);
  1013. /*
  1014. * Fill the partition reserved page with the information needed by
  1015. * other partitions to discover we are alive and establish initial
  1016. * communications.
  1017. */
  1018. ret = xpc_setup_rsvd_page();
  1019. if (ret != 0) {
  1020. dev_err(xpc_part, "can't setup our reserved page\n");
  1021. goto out_2;
  1022. }
  1023. /* add ourselves to the reboot_notifier_list */
  1024. ret = register_reboot_notifier(&xpc_reboot_notifier);
  1025. if (ret != 0)
  1026. dev_warn(xpc_part, "can't register reboot notifier\n");
  1027. /* add ourselves to the die_notifier list */
  1028. ret = register_die_notifier(&xpc_die_notifier);
  1029. if (ret != 0)
  1030. dev_warn(xpc_part, "can't register die notifier\n");
  1031. /*
  1032. * The real work-horse behind xpc. This processes incoming
  1033. * interrupts and monitors remote heartbeats.
  1034. */
  1035. kthread = kthread_run(xpc_hb_checker, NULL, XPC_HB_CHECK_THREAD_NAME);
  1036. if (IS_ERR(kthread)) {
  1037. dev_err(xpc_part, "failed while forking hb check thread\n");
  1038. ret = -EBUSY;
  1039. goto out_3;
  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_send, xpc_initiate_send_notify,
  1058. xpc_initiate_received, xpc_initiate_partid_to_nasids);
  1059. return 0;
  1060. /* initialization was not successful */
  1061. out_3:
  1062. xpc_teardown_rsvd_page();
  1063. (void)unregister_die_notifier(&xpc_die_notifier);
  1064. (void)unregister_reboot_notifier(&xpc_reboot_notifier);
  1065. out_2:
  1066. if (xpc_sysctl)
  1067. unregister_sysctl_table(xpc_sysctl);
  1068. xpc_teardown_partitions();
  1069. out_1:
  1070. if (is_shub())
  1071. xpc_exit_sn2();
  1072. else if (is_uv())
  1073. xpc_exit_uv();
  1074. return ret;
  1075. }
  1076. module_init(xpc_init);
  1077. void __exit
  1078. xpc_exit(void)
  1079. {
  1080. xpc_do_exit(xpUnloading);
  1081. }
  1082. module_exit(xpc_exit);
  1083. MODULE_AUTHOR("Silicon Graphics, Inc.");
  1084. MODULE_DESCRIPTION("Cross Partition Communication (XPC) support");
  1085. MODULE_LICENSE("GPL");
  1086. module_param(xpc_hb_interval, int, 0);
  1087. MODULE_PARM_DESC(xpc_hb_interval, "Number of seconds between "
  1088. "heartbeat increments.");
  1089. module_param(xpc_hb_check_interval, int, 0);
  1090. MODULE_PARM_DESC(xpc_hb_check_interval, "Number of seconds between "
  1091. "heartbeat checks.");
  1092. module_param(xpc_disengage_timelimit, int, 0);
  1093. MODULE_PARM_DESC(xpc_disengage_timelimit, "Number of seconds to wait "
  1094. "for disengage to complete.");
  1095. module_param(xpc_kdebug_ignore, int, 0);
  1096. MODULE_PARM_DESC(xpc_kdebug_ignore, "Should lack of heartbeat be ignored by "
  1097. "other partitions when dropping into kdebug.");