xpc_main.c 36 KB

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