xpc_main.c 36 KB

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