xpc_main.c 36 KB

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