xpc_main.c 36 KB

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