xpc_main.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (c) 2004-2009 Silicon Graphics, Inc. All Rights Reserved.
  7. */
  8. /*
  9. * Cross Partition Communication (XPC) support - standard version.
  10. *
  11. * XPC provides a message passing capability that crosses partition
  12. * boundaries. This module is made up of two parts:
  13. *
  14. * partition This part detects the presence/absence of other
  15. * partitions. It provides a heartbeat and monitors
  16. * the heartbeats of other partitions.
  17. *
  18. * channel This part manages the channels and sends/receives
  19. * messages across them to/from other partitions.
  20. *
  21. * There are a couple of additional functions residing in XP, which
  22. * provide an interface to XPC for its users.
  23. *
  24. *
  25. * Caveats:
  26. *
  27. * . Currently on sn2, we have no way to determine which nasid an IRQ
  28. * came from. Thus, xpc_send_IRQ_sn2() does a remote amo write
  29. * followed by an IPI. The amo indicates where data is to be pulled
  30. * from, so after the IPI arrives, the remote partition checks the amo
  31. * word. The IPI can actually arrive before the amo however, so other
  32. * code must periodically check for this case. Also, remote amo
  33. * operations do not reliably time out. Thus we do a remote PIO read
  34. * solely to know whether the remote partition is down and whether we
  35. * should stop sending IPIs to it. This remote PIO read operation is
  36. * set up in a special nofault region so SAL knows to ignore (and
  37. * cleanup) any errors due to the remote amo write, PIO read, and/or
  38. * PIO write operations.
  39. *
  40. * If/when new hardware solves this IPI problem, we should abandon
  41. * the current approach.
  42. *
  43. */
  44. #include <linux/module.h>
  45. #include <linux/slab.h>
  46. #include <linux/sysctl.h>
  47. #include <linux/device.h>
  48. #include <linux/delay.h>
  49. #include <linux/reboot.h>
  50. #include <linux/kdebug.h>
  51. #include <linux/kthread.h>
  52. #include "xpc.h"
  53. #ifdef CONFIG_X86_64
  54. #include <asm/traps.h>
  55. #endif
  56. /* define two XPC debug device structures to be used with dev_dbg() et al */
  57. struct device_driver xpc_dbg_name = {
  58. .name = "xpc"
  59. };
  60. struct device xpc_part_dbg_subname = {
  61. .init_name = "", /* set to "part" at xpc_init() time */
  62. .driver = &xpc_dbg_name
  63. };
  64. struct device xpc_chan_dbg_subname = {
  65. .init_name = "", /* set to "chan" at xpc_init() time */
  66. .driver = &xpc_dbg_name
  67. };
  68. struct device *xpc_part = &xpc_part_dbg_subname;
  69. struct device *xpc_chan = &xpc_chan_dbg_subname;
  70. static int xpc_kdebug_ignore;
  71. /* systune related variables for /proc/sys directories */
  72. static int xpc_hb_interval = XPC_HB_DEFAULT_INTERVAL;
  73. static int xpc_hb_min_interval = 1;
  74. static int xpc_hb_max_interval = 10;
  75. static int xpc_hb_check_interval = XPC_HB_CHECK_DEFAULT_INTERVAL;
  76. static int xpc_hb_check_min_interval = 10;
  77. static int xpc_hb_check_max_interval = 120;
  78. int xpc_disengage_timelimit = XPC_DISENGAGE_DEFAULT_TIMELIMIT;
  79. static int xpc_disengage_min_timelimit; /* = 0 */
  80. static int xpc_disengage_max_timelimit = 120;
  81. static struct ctl_table xpc_sys_xpc_hb_dir[] = {
  82. {
  83. .procname = "hb_interval",
  84. .data = &xpc_hb_interval,
  85. .maxlen = sizeof(int),
  86. .mode = 0644,
  87. .proc_handler = proc_dointvec_minmax,
  88. .extra1 = &xpc_hb_min_interval,
  89. .extra2 = &xpc_hb_max_interval},
  90. {
  91. .procname = "hb_check_interval",
  92. .data = &xpc_hb_check_interval,
  93. .maxlen = sizeof(int),
  94. .mode = 0644,
  95. .proc_handler = proc_dointvec_minmax,
  96. .extra1 = &xpc_hb_check_min_interval,
  97. .extra2 = &xpc_hb_check_max_interval},
  98. {}
  99. };
  100. static struct ctl_table xpc_sys_xpc_dir[] = {
  101. {
  102. .procname = "hb",
  103. .mode = 0555,
  104. .child = xpc_sys_xpc_hb_dir},
  105. {
  106. .procname = "disengage_timelimit",
  107. .data = &xpc_disengage_timelimit,
  108. .maxlen = sizeof(int),
  109. .mode = 0644,
  110. .proc_handler = proc_dointvec_minmax,
  111. .extra1 = &xpc_disengage_min_timelimit,
  112. .extra2 = &xpc_disengage_max_timelimit},
  113. {}
  114. };
  115. static struct ctl_table xpc_sys_dir[] = {
  116. {
  117. .procname = "xpc",
  118. .mode = 0555,
  119. .child = xpc_sys_xpc_dir},
  120. {}
  121. };
  122. static struct ctl_table_header *xpc_sysctl;
  123. /* non-zero if any remote partition disengage was timed out */
  124. int xpc_disengage_timedout;
  125. /* #of activate IRQs received and not yet processed */
  126. int xpc_activate_IRQ_rcvd;
  127. DEFINE_SPINLOCK(xpc_activate_IRQ_rcvd_lock);
  128. /* IRQ handler notifies this wait queue on receipt of an IRQ */
  129. DECLARE_WAIT_QUEUE_HEAD(xpc_activate_IRQ_wq);
  130. static unsigned long xpc_hb_check_timeout;
  131. static struct timer_list xpc_hb_timer;
  132. /* notification that the xpc_hb_checker thread has exited */
  133. static DECLARE_COMPLETION(xpc_hb_checker_exited);
  134. /* notification that the xpc_discovery thread has exited */
  135. static DECLARE_COMPLETION(xpc_discovery_exited);
  136. static void xpc_kthread_waitmsgs(struct xpc_partition *, struct xpc_channel *);
  137. static int xpc_system_reboot(struct notifier_block *, unsigned long, void *);
  138. static struct notifier_block xpc_reboot_notifier = {
  139. .notifier_call = xpc_system_reboot,
  140. };
  141. static int xpc_system_die(struct notifier_block *, unsigned long, void *);
  142. static struct notifier_block xpc_die_notifier = {
  143. .notifier_call = xpc_system_die,
  144. };
  145. struct xpc_arch_operations xpc_arch_ops;
  146. /*
  147. * Timer function to enforce the timelimit on the partition disengage.
  148. */
  149. static void
  150. xpc_timeout_partition_disengage(struct timer_list *t)
  151. {
  152. struct xpc_partition *part = from_timer(part, t, disengage_timer);
  153. DBUG_ON(time_is_after_jiffies(part->disengage_timeout));
  154. (void)xpc_partition_disengaged(part);
  155. DBUG_ON(part->disengage_timeout != 0);
  156. DBUG_ON(xpc_arch_ops.partition_engaged(XPC_PARTID(part)));
  157. }
  158. /*
  159. * Timer to produce the heartbeat. The timer structures function is
  160. * already set when this is initially called. A tunable is used to
  161. * specify when the next timeout should occur.
  162. */
  163. static void
  164. xpc_hb_beater(struct timer_list *unused)
  165. {
  166. xpc_arch_ops.increment_heartbeat();
  167. if (time_is_before_eq_jiffies(xpc_hb_check_timeout))
  168. wake_up_interruptible(&xpc_activate_IRQ_wq);
  169. xpc_hb_timer.expires = jiffies + (xpc_hb_interval * HZ);
  170. add_timer(&xpc_hb_timer);
  171. }
  172. static void
  173. xpc_start_hb_beater(void)
  174. {
  175. xpc_arch_ops.heartbeat_init();
  176. timer_setup(&xpc_hb_timer, xpc_hb_beater, 0);
  177. xpc_hb_beater(0);
  178. }
  179. static void
  180. xpc_stop_hb_beater(void)
  181. {
  182. del_timer_sync(&xpc_hb_timer);
  183. xpc_arch_ops.heartbeat_exit();
  184. }
  185. /*
  186. * At periodic intervals, scan through all active partitions and ensure
  187. * their heartbeat is still active. If not, the partition is deactivated.
  188. */
  189. static void
  190. xpc_check_remote_hb(void)
  191. {
  192. struct xpc_partition *part;
  193. short partid;
  194. enum xp_retval ret;
  195. for (partid = 0; partid < xp_max_npartitions; partid++) {
  196. if (xpc_exiting)
  197. break;
  198. if (partid == xp_partition_id)
  199. continue;
  200. part = &xpc_partitions[partid];
  201. if (part->act_state == XPC_P_AS_INACTIVE ||
  202. part->act_state == XPC_P_AS_DEACTIVATING) {
  203. continue;
  204. }
  205. ret = xpc_arch_ops.get_remote_heartbeat(part);
  206. if (ret != xpSuccess)
  207. XPC_DEACTIVATE_PARTITION(part, ret);
  208. }
  209. }
  210. /*
  211. * This thread is responsible for nearly all of the partition
  212. * activation/deactivation.
  213. */
  214. static int
  215. xpc_hb_checker(void *ignore)
  216. {
  217. int force_IRQ = 0;
  218. /* this thread was marked active by xpc_hb_init() */
  219. set_cpus_allowed_ptr(current, cpumask_of(XPC_HB_CHECK_CPU));
  220. /* set our heartbeating to other partitions into motion */
  221. xpc_hb_check_timeout = jiffies + (xpc_hb_check_interval * HZ);
  222. xpc_start_hb_beater();
  223. while (!xpc_exiting) {
  224. dev_dbg(xpc_part, "woke up with %d ticks rem; %d IRQs have "
  225. "been received\n",
  226. (int)(xpc_hb_check_timeout - jiffies),
  227. xpc_activate_IRQ_rcvd);
  228. /* checking of remote heartbeats is skewed by IRQ handling */
  229. if (time_is_before_eq_jiffies(xpc_hb_check_timeout)) {
  230. xpc_hb_check_timeout = jiffies +
  231. (xpc_hb_check_interval * HZ);
  232. dev_dbg(xpc_part, "checking remote heartbeats\n");
  233. xpc_check_remote_hb();
  234. /*
  235. * On sn2 we need to periodically recheck to ensure no
  236. * IRQ/amo pairs have been missed.
  237. */
  238. if (is_shub())
  239. force_IRQ = 1;
  240. }
  241. /* check for outstanding IRQs */
  242. if (xpc_activate_IRQ_rcvd > 0 || force_IRQ != 0) {
  243. force_IRQ = 0;
  244. dev_dbg(xpc_part, "processing activate IRQs "
  245. "received\n");
  246. xpc_arch_ops.process_activate_IRQ_rcvd();
  247. }
  248. /* wait for IRQ or timeout */
  249. (void)wait_event_interruptible(xpc_activate_IRQ_wq,
  250. (time_is_before_eq_jiffies(
  251. xpc_hb_check_timeout) ||
  252. xpc_activate_IRQ_rcvd > 0 ||
  253. xpc_exiting));
  254. }
  255. xpc_stop_hb_beater();
  256. dev_dbg(xpc_part, "heartbeat checker is exiting\n");
  257. /* mark this thread as having exited */
  258. complete(&xpc_hb_checker_exited);
  259. return 0;
  260. }
  261. /*
  262. * This thread will attempt to discover other partitions to activate
  263. * based on info provided by SAL. This new thread is short lived and
  264. * will exit once discovery is complete.
  265. */
  266. static int
  267. xpc_initiate_discovery(void *ignore)
  268. {
  269. xpc_discovery();
  270. dev_dbg(xpc_part, "discovery thread is exiting\n");
  271. /* mark this thread as having exited */
  272. complete(&xpc_discovery_exited);
  273. return 0;
  274. }
  275. /*
  276. * The first kthread assigned to a newly activated partition is the one
  277. * created by XPC HB with which it calls xpc_activating(). XPC hangs on to
  278. * that kthread until the partition is brought down, at which time that kthread
  279. * returns back to XPC HB. (The return of that kthread will signify to XPC HB
  280. * that XPC has dismantled all communication infrastructure for the associated
  281. * partition.) This kthread becomes the channel manager for that partition.
  282. *
  283. * Each active partition has a channel manager, who, besides connecting and
  284. * disconnecting channels, will ensure that each of the partition's connected
  285. * channels has the required number of assigned kthreads to get the work done.
  286. */
  287. static void
  288. xpc_channel_mgr(struct xpc_partition *part)
  289. {
  290. while (part->act_state != XPC_P_AS_DEACTIVATING ||
  291. atomic_read(&part->nchannels_active) > 0 ||
  292. !xpc_partition_disengaged(part)) {
  293. xpc_process_sent_chctl_flags(part);
  294. /*
  295. * Wait until we've been requested to activate kthreads or
  296. * all of the channel's message queues have been torn down or
  297. * a signal is pending.
  298. *
  299. * The channel_mgr_requests is set to 1 after being awakened,
  300. * This is done to prevent the channel mgr from making one pass
  301. * through the loop for each request, since he will
  302. * be servicing all the requests in one pass. The reason it's
  303. * set to 1 instead of 0 is so that other kthreads will know
  304. * that the channel mgr is running and won't bother trying to
  305. * wake him up.
  306. */
  307. atomic_dec(&part->channel_mgr_requests);
  308. (void)wait_event_interruptible(part->channel_mgr_wq,
  309. (atomic_read(&part->channel_mgr_requests) > 0 ||
  310. part->chctl.all_flags != 0 ||
  311. (part->act_state == XPC_P_AS_DEACTIVATING &&
  312. atomic_read(&part->nchannels_active) == 0 &&
  313. xpc_partition_disengaged(part))));
  314. atomic_set(&part->channel_mgr_requests, 1);
  315. }
  316. }
  317. /*
  318. * Guarantee that the kzalloc'd memory is cacheline aligned.
  319. */
  320. void *
  321. xpc_kzalloc_cacheline_aligned(size_t size, gfp_t flags, void **base)
  322. {
  323. /* see if kzalloc will give us cachline aligned memory by default */
  324. *base = kzalloc(size, flags);
  325. if (*base == NULL)
  326. return NULL;
  327. if ((u64)*base == L1_CACHE_ALIGN((u64)*base))
  328. return *base;
  329. kfree(*base);
  330. /* nope, we'll have to do it ourselves */
  331. *base = kzalloc(size + L1_CACHE_BYTES, flags);
  332. if (*base == NULL)
  333. return NULL;
  334. return (void *)L1_CACHE_ALIGN((u64)*base);
  335. }
  336. /*
  337. * Setup the channel structures necessary to support XPartition Communication
  338. * between the specified remote partition and the local one.
  339. */
  340. static enum xp_retval
  341. xpc_setup_ch_structures(struct xpc_partition *part)
  342. {
  343. enum xp_retval ret;
  344. int ch_number;
  345. struct xpc_channel *ch;
  346. short partid = XPC_PARTID(part);
  347. /*
  348. * Allocate all of the channel structures as a contiguous chunk of
  349. * memory.
  350. */
  351. DBUG_ON(part->channels != NULL);
  352. part->channels = kcalloc(XPC_MAX_NCHANNELS,
  353. sizeof(struct xpc_channel),
  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 = kcalloc(xp_max_npartitions,
  742. sizeof(struct xpc_partition),
  743. GFP_KERNEL);
  744. if (xpc_partitions == NULL) {
  745. dev_err(xpc_part, "can't get memory for partition structure\n");
  746. return -ENOMEM;
  747. }
  748. /*
  749. * The first few fields of each entry of xpc_partitions[] need to
  750. * be initialized now so that calls to xpc_connect() and
  751. * xpc_disconnect() can be made prior to the activation of any remote
  752. * partition. NOTE THAT NONE OF THE OTHER FIELDS BELONGING TO THESE
  753. * ENTRIES ARE MEANINGFUL UNTIL AFTER AN ENTRY'S CORRESPONDING
  754. * PARTITION HAS BEEN ACTIVATED.
  755. */
  756. for (partid = 0; partid < xp_max_npartitions; partid++) {
  757. part = &xpc_partitions[partid];
  758. DBUG_ON((u64)part != L1_CACHE_ALIGN((u64)part));
  759. part->activate_IRQ_rcvd = 0;
  760. spin_lock_init(&part->act_lock);
  761. part->act_state = XPC_P_AS_INACTIVE;
  762. XPC_SET_REASON(part, 0, 0);
  763. timer_setup(&part->disengage_timer,
  764. xpc_timeout_partition_disengage, 0);
  765. part->setup_state = XPC_P_SS_UNSET;
  766. init_waitqueue_head(&part->teardown_wq);
  767. atomic_set(&part->references, 0);
  768. }
  769. return xpc_arch_ops.setup_partitions();
  770. }
  771. static void
  772. xpc_teardown_partitions(void)
  773. {
  774. xpc_arch_ops.teardown_partitions();
  775. kfree(xpc_partitions);
  776. }
  777. static void
  778. xpc_do_exit(enum xp_retval reason)
  779. {
  780. short partid;
  781. int active_part_count, printed_waiting_msg = 0;
  782. struct xpc_partition *part;
  783. unsigned long printmsg_time, disengage_timeout = 0;
  784. /* a 'rmmod XPC' and a 'reboot' cannot both end up here together */
  785. DBUG_ON(xpc_exiting == 1);
  786. /*
  787. * Let the heartbeat checker thread and the discovery thread
  788. * (if one is running) know that they should exit. Also wake up
  789. * the heartbeat checker thread in case it's sleeping.
  790. */
  791. xpc_exiting = 1;
  792. wake_up_interruptible(&xpc_activate_IRQ_wq);
  793. /* wait for the discovery thread to exit */
  794. wait_for_completion(&xpc_discovery_exited);
  795. /* wait for the heartbeat checker thread to exit */
  796. wait_for_completion(&xpc_hb_checker_exited);
  797. /* sleep for a 1/3 of a second or so */
  798. (void)msleep_interruptible(300);
  799. /* wait for all partitions to become inactive */
  800. printmsg_time = jiffies + (XPC_DEACTIVATE_PRINTMSG_INTERVAL * HZ);
  801. xpc_disengage_timedout = 0;
  802. do {
  803. active_part_count = 0;
  804. for (partid = 0; partid < xp_max_npartitions; partid++) {
  805. part = &xpc_partitions[partid];
  806. if (xpc_partition_disengaged(part) &&
  807. part->act_state == XPC_P_AS_INACTIVE) {
  808. continue;
  809. }
  810. active_part_count++;
  811. XPC_DEACTIVATE_PARTITION(part, reason);
  812. if (part->disengage_timeout > disengage_timeout)
  813. disengage_timeout = part->disengage_timeout;
  814. }
  815. if (xpc_arch_ops.any_partition_engaged()) {
  816. if (time_is_before_jiffies(printmsg_time)) {
  817. dev_info(xpc_part, "waiting for remote "
  818. "partitions to deactivate, timeout in "
  819. "%ld seconds\n", (disengage_timeout -
  820. jiffies) / HZ);
  821. printmsg_time = jiffies +
  822. (XPC_DEACTIVATE_PRINTMSG_INTERVAL * HZ);
  823. printed_waiting_msg = 1;
  824. }
  825. } else if (active_part_count > 0) {
  826. if (printed_waiting_msg) {
  827. dev_info(xpc_part, "waiting for local partition"
  828. " to deactivate\n");
  829. printed_waiting_msg = 0;
  830. }
  831. } else {
  832. if (!xpc_disengage_timedout) {
  833. dev_info(xpc_part, "all partitions have "
  834. "deactivated\n");
  835. }
  836. break;
  837. }
  838. /* sleep for a 1/3 of a second or so */
  839. (void)msleep_interruptible(300);
  840. } while (1);
  841. DBUG_ON(xpc_arch_ops.any_partition_engaged());
  842. xpc_teardown_rsvd_page();
  843. if (reason == xpUnloading) {
  844. (void)unregister_die_notifier(&xpc_die_notifier);
  845. (void)unregister_reboot_notifier(&xpc_reboot_notifier);
  846. }
  847. /* clear the interface to XPC's functions */
  848. xpc_clear_interface();
  849. if (xpc_sysctl)
  850. unregister_sysctl_table(xpc_sysctl);
  851. xpc_teardown_partitions();
  852. if (is_shub())
  853. xpc_exit_sn2();
  854. else if (is_uv())
  855. xpc_exit_uv();
  856. }
  857. /*
  858. * This function is called when the system is being rebooted.
  859. */
  860. static int
  861. xpc_system_reboot(struct notifier_block *nb, unsigned long event, void *unused)
  862. {
  863. enum xp_retval reason;
  864. switch (event) {
  865. case SYS_RESTART:
  866. reason = xpSystemReboot;
  867. break;
  868. case SYS_HALT:
  869. reason = xpSystemHalt;
  870. break;
  871. case SYS_POWER_OFF:
  872. reason = xpSystemPoweroff;
  873. break;
  874. default:
  875. reason = xpSystemGoingDown;
  876. }
  877. xpc_do_exit(reason);
  878. return NOTIFY_DONE;
  879. }
  880. /* Used to only allow one cpu to complete disconnect */
  881. static unsigned int xpc_die_disconnecting;
  882. /*
  883. * Notify other partitions to deactivate from us by first disengaging from all
  884. * references to our memory.
  885. */
  886. static void
  887. xpc_die_deactivate(void)
  888. {
  889. struct xpc_partition *part;
  890. short partid;
  891. int any_engaged;
  892. long keep_waiting;
  893. long wait_to_print;
  894. if (cmpxchg(&xpc_die_disconnecting, 0, 1))
  895. return;
  896. /* keep xpc_hb_checker thread from doing anything (just in case) */
  897. xpc_exiting = 1;
  898. xpc_arch_ops.disallow_all_hbs(); /*indicate we're deactivated */
  899. for (partid = 0; partid < xp_max_npartitions; partid++) {
  900. part = &xpc_partitions[partid];
  901. if (xpc_arch_ops.partition_engaged(partid) ||
  902. part->act_state != XPC_P_AS_INACTIVE) {
  903. xpc_arch_ops.request_partition_deactivation(part);
  904. xpc_arch_ops.indicate_partition_disengaged(part);
  905. }
  906. }
  907. /*
  908. * Though we requested that all other partitions deactivate from us,
  909. * we only wait until they've all disengaged or we've reached the
  910. * defined timelimit.
  911. *
  912. * Given that one iteration through the following while-loop takes
  913. * approximately 200 microseconds, calculate the #of loops to take
  914. * before bailing and the #of loops before printing a waiting message.
  915. */
  916. keep_waiting = xpc_disengage_timelimit * 1000 * 5;
  917. wait_to_print = XPC_DEACTIVATE_PRINTMSG_INTERVAL * 1000 * 5;
  918. while (1) {
  919. any_engaged = xpc_arch_ops.any_partition_engaged();
  920. if (!any_engaged) {
  921. dev_info(xpc_part, "all partitions have deactivated\n");
  922. break;
  923. }
  924. if (!keep_waiting--) {
  925. for (partid = 0; partid < xp_max_npartitions;
  926. partid++) {
  927. if (xpc_arch_ops.partition_engaged(partid)) {
  928. dev_info(xpc_part, "deactivate from "
  929. "remote partition %d timed "
  930. "out\n", partid);
  931. }
  932. }
  933. break;
  934. }
  935. if (!wait_to_print--) {
  936. dev_info(xpc_part, "waiting for remote partitions to "
  937. "deactivate, timeout in %ld seconds\n",
  938. keep_waiting / (1000 * 5));
  939. wait_to_print = XPC_DEACTIVATE_PRINTMSG_INTERVAL *
  940. 1000 * 5;
  941. }
  942. udelay(200);
  943. }
  944. }
  945. /*
  946. * This function is called when the system is being restarted or halted due
  947. * to some sort of system failure. If this is the case we need to notify the
  948. * other partitions to disengage from all references to our memory.
  949. * This function can also be called when our heartbeater could be offlined
  950. * for a time. In this case we need to notify other partitions to not worry
  951. * about the lack of a heartbeat.
  952. */
  953. static int
  954. xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
  955. {
  956. #ifdef CONFIG_IA64 /* !!! temporary kludge */
  957. switch (event) {
  958. case DIE_MACHINE_RESTART:
  959. case DIE_MACHINE_HALT:
  960. xpc_die_deactivate();
  961. break;
  962. case DIE_KDEBUG_ENTER:
  963. /* Should lack of heartbeat be ignored by other partitions? */
  964. if (!xpc_kdebug_ignore)
  965. break;
  966. /* fall through */
  967. case DIE_MCA_MONARCH_ENTER:
  968. case DIE_INIT_MONARCH_ENTER:
  969. xpc_arch_ops.offline_heartbeat();
  970. break;
  971. case DIE_KDEBUG_LEAVE:
  972. /* Is lack of heartbeat being ignored by other partitions? */
  973. if (!xpc_kdebug_ignore)
  974. break;
  975. /* fall through */
  976. case DIE_MCA_MONARCH_LEAVE:
  977. case DIE_INIT_MONARCH_LEAVE:
  978. xpc_arch_ops.online_heartbeat();
  979. break;
  980. }
  981. #else
  982. struct die_args *die_args = _die_args;
  983. switch (event) {
  984. case DIE_TRAP:
  985. if (die_args->trapnr == X86_TRAP_DF)
  986. xpc_die_deactivate();
  987. if (((die_args->trapnr == X86_TRAP_MF) ||
  988. (die_args->trapnr == X86_TRAP_XF)) &&
  989. !user_mode(die_args->regs))
  990. xpc_die_deactivate();
  991. break;
  992. case DIE_INT3:
  993. case DIE_DEBUG:
  994. break;
  995. case DIE_OOPS:
  996. case DIE_GPF:
  997. default:
  998. xpc_die_deactivate();
  999. }
  1000. #endif
  1001. return NOTIFY_DONE;
  1002. }
  1003. int __init
  1004. xpc_init(void)
  1005. {
  1006. int ret;
  1007. struct task_struct *kthread;
  1008. dev_set_name(xpc_part, "part");
  1009. dev_set_name(xpc_chan, "chan");
  1010. if (is_shub()) {
  1011. /*
  1012. * The ia64-sn2 architecture supports at most 64 partitions.
  1013. * And the inability to unregister remote amos restricts us
  1014. * further to only support exactly 64 partitions on this
  1015. * architecture, no less.
  1016. */
  1017. if (xp_max_npartitions != 64) {
  1018. dev_err(xpc_part, "max #of partitions not set to 64\n");
  1019. ret = -EINVAL;
  1020. } else {
  1021. ret = xpc_init_sn2();
  1022. }
  1023. } else if (is_uv()) {
  1024. ret = xpc_init_uv();
  1025. } else {
  1026. ret = -ENODEV;
  1027. }
  1028. if (ret != 0)
  1029. return ret;
  1030. ret = xpc_setup_partitions();
  1031. if (ret != 0) {
  1032. dev_err(xpc_part, "can't get memory for partition structure\n");
  1033. goto out_1;
  1034. }
  1035. xpc_sysctl = register_sysctl_table(xpc_sys_dir);
  1036. /*
  1037. * Fill the partition reserved page with the information needed by
  1038. * other partitions to discover we are alive and establish initial
  1039. * communications.
  1040. */
  1041. ret = xpc_setup_rsvd_page();
  1042. if (ret != 0) {
  1043. dev_err(xpc_part, "can't setup our reserved page\n");
  1044. goto out_2;
  1045. }
  1046. /* add ourselves to the reboot_notifier_list */
  1047. ret = register_reboot_notifier(&xpc_reboot_notifier);
  1048. if (ret != 0)
  1049. dev_warn(xpc_part, "can't register reboot notifier\n");
  1050. /* add ourselves to the die_notifier list */
  1051. ret = register_die_notifier(&xpc_die_notifier);
  1052. if (ret != 0)
  1053. dev_warn(xpc_part, "can't register die notifier\n");
  1054. /*
  1055. * The real work-horse behind xpc. This processes incoming
  1056. * interrupts and monitors remote heartbeats.
  1057. */
  1058. kthread = kthread_run(xpc_hb_checker, NULL, XPC_HB_CHECK_THREAD_NAME);
  1059. if (IS_ERR(kthread)) {
  1060. dev_err(xpc_part, "failed while forking hb check thread\n");
  1061. ret = -EBUSY;
  1062. goto out_3;
  1063. }
  1064. /*
  1065. * Startup a thread that will attempt to discover other partitions to
  1066. * activate based on info provided by SAL. This new thread is short
  1067. * lived and will exit once discovery is complete.
  1068. */
  1069. kthread = kthread_run(xpc_initiate_discovery, NULL,
  1070. XPC_DISCOVERY_THREAD_NAME);
  1071. if (IS_ERR(kthread)) {
  1072. dev_err(xpc_part, "failed while forking discovery thread\n");
  1073. /* mark this new thread as a non-starter */
  1074. complete(&xpc_discovery_exited);
  1075. xpc_do_exit(xpUnloading);
  1076. return -EBUSY;
  1077. }
  1078. /* set the interface to point at XPC's functions */
  1079. xpc_set_interface(xpc_initiate_connect, xpc_initiate_disconnect,
  1080. xpc_initiate_send, xpc_initiate_send_notify,
  1081. xpc_initiate_received, xpc_initiate_partid_to_nasids);
  1082. return 0;
  1083. /* initialization was not successful */
  1084. out_3:
  1085. xpc_teardown_rsvd_page();
  1086. (void)unregister_die_notifier(&xpc_die_notifier);
  1087. (void)unregister_reboot_notifier(&xpc_reboot_notifier);
  1088. out_2:
  1089. if (xpc_sysctl)
  1090. unregister_sysctl_table(xpc_sysctl);
  1091. xpc_teardown_partitions();
  1092. out_1:
  1093. if (is_shub())
  1094. xpc_exit_sn2();
  1095. else if (is_uv())
  1096. xpc_exit_uv();
  1097. return ret;
  1098. }
  1099. module_init(xpc_init);
  1100. void __exit
  1101. xpc_exit(void)
  1102. {
  1103. xpc_do_exit(xpUnloading);
  1104. }
  1105. module_exit(xpc_exit);
  1106. MODULE_AUTHOR("Silicon Graphics, Inc.");
  1107. MODULE_DESCRIPTION("Cross Partition Communication (XPC) support");
  1108. MODULE_LICENSE("GPL");
  1109. module_param(xpc_hb_interval, int, 0);
  1110. MODULE_PARM_DESC(xpc_hb_interval, "Number of seconds between "
  1111. "heartbeat increments.");
  1112. module_param(xpc_hb_check_interval, int, 0);
  1113. MODULE_PARM_DESC(xpc_hb_check_interval, "Number of seconds between "
  1114. "heartbeat checks.");
  1115. module_param(xpc_disengage_timelimit, int, 0);
  1116. MODULE_PARM_DESC(xpc_disengage_timelimit, "Number of seconds to wait "
  1117. "for disengage to complete.");
  1118. module_param(xpc_kdebug_ignore, int, 0);
  1119. MODULE_PARM_DESC(xpc_kdebug_ignore, "Should lack of heartbeat be ignored by "
  1120. "other partitions when dropping into kdebug.");