xpc_main.c 38 KB

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