xpc_main.c 36 KB

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