book3s_xive.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893
  1. /*
  2. * Copyright 2017 Benjamin Herrenschmidt, IBM Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License, version 2, as
  6. * published by the Free Software Foundation.
  7. */
  8. #define pr_fmt(fmt) "xive-kvm: " fmt
  9. #include <linux/kernel.h>
  10. #include <linux/kvm_host.h>
  11. #include <linux/err.h>
  12. #include <linux/gfp.h>
  13. #include <linux/spinlock.h>
  14. #include <linux/delay.h>
  15. #include <linux/percpu.h>
  16. #include <linux/cpumask.h>
  17. #include <asm/uaccess.h>
  18. #include <asm/kvm_book3s.h>
  19. #include <asm/kvm_ppc.h>
  20. #include <asm/hvcall.h>
  21. #include <asm/xics.h>
  22. #include <asm/xive.h>
  23. #include <asm/xive-regs.h>
  24. #include <asm/debug.h>
  25. #include <asm/time.h>
  26. #include <asm/opal.h>
  27. #include <linux/debugfs.h>
  28. #include <linux/seq_file.h>
  29. #include "book3s_xive.h"
  30. /*
  31. * Virtual mode variants of the hcalls for use on radix/radix
  32. * with AIL. They require the VCPU's VP to be "pushed"
  33. *
  34. * We still instanciate them here because we use some of the
  35. * generated utility functions as well in this file.
  36. */
  37. #define XIVE_RUNTIME_CHECKS
  38. #define X_PFX xive_vm_
  39. #define X_STATIC static
  40. #define X_STAT_PFX stat_vm_
  41. #define __x_tima xive_tima
  42. #define __x_eoi_page(xd) ((void __iomem *)((xd)->eoi_mmio))
  43. #define __x_trig_page(xd) ((void __iomem *)((xd)->trig_mmio))
  44. #define __x_readb __raw_readb
  45. #define __x_writeb __raw_writeb
  46. #define __x_readw __raw_readw
  47. #define __x_readq __raw_readq
  48. #define __x_writeq __raw_writeq
  49. #include "book3s_xive_template.c"
  50. /*
  51. * We leave a gap of a couple of interrupts in the queue to
  52. * account for the IPI and additional safety guard.
  53. */
  54. #define XIVE_Q_GAP 2
  55. /*
  56. * This is a simple trigger for a generic XIVE IRQ. This must
  57. * only be called for interrupts that support a trigger page
  58. */
  59. static bool xive_irq_trigger(struct xive_irq_data *xd)
  60. {
  61. /* This should be only for MSIs */
  62. if (WARN_ON(xd->flags & XIVE_IRQ_FLAG_LSI))
  63. return false;
  64. /* Those interrupts should always have a trigger page */
  65. if (WARN_ON(!xd->trig_mmio))
  66. return false;
  67. out_be64(xd->trig_mmio, 0);
  68. return true;
  69. }
  70. static irqreturn_t xive_esc_irq(int irq, void *data)
  71. {
  72. struct kvm_vcpu *vcpu = data;
  73. /* We use the existing H_PROD mechanism to wake up the target */
  74. vcpu->arch.prodded = 1;
  75. smp_mb();
  76. if (vcpu->arch.ceded)
  77. kvmppc_fast_vcpu_kick(vcpu);
  78. return IRQ_HANDLED;
  79. }
  80. static int xive_attach_escalation(struct kvm_vcpu *vcpu, u8 prio)
  81. {
  82. struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu;
  83. struct xive_q *q = &xc->queues[prio];
  84. char *name = NULL;
  85. int rc;
  86. /* Already there ? */
  87. if (xc->esc_virq[prio])
  88. return 0;
  89. /* Hook up the escalation interrupt */
  90. xc->esc_virq[prio] = irq_create_mapping(NULL, q->esc_irq);
  91. if (!xc->esc_virq[prio]) {
  92. pr_err("Failed to map escalation interrupt for queue %d of VCPU %d\n",
  93. prio, xc->server_num);
  94. return -EIO;
  95. }
  96. /*
  97. * Future improvement: start with them disabled
  98. * and handle DD2 and later scheme of merged escalation
  99. * interrupts
  100. */
  101. name = kasprintf(GFP_KERNEL, "kvm-%d-%d-%d",
  102. vcpu->kvm->arch.lpid, xc->server_num, prio);
  103. if (!name) {
  104. pr_err("Failed to allocate escalation irq name for queue %d of VCPU %d\n",
  105. prio, xc->server_num);
  106. rc = -ENOMEM;
  107. goto error;
  108. }
  109. rc = request_irq(xc->esc_virq[prio], xive_esc_irq,
  110. IRQF_NO_THREAD, name, vcpu);
  111. if (rc) {
  112. pr_err("Failed to request escalation interrupt for queue %d of VCPU %d\n",
  113. prio, xc->server_num);
  114. goto error;
  115. }
  116. xc->esc_virq_names[prio] = name;
  117. return 0;
  118. error:
  119. irq_dispose_mapping(xc->esc_virq[prio]);
  120. xc->esc_virq[prio] = 0;
  121. kfree(name);
  122. return rc;
  123. }
  124. static int xive_provision_queue(struct kvm_vcpu *vcpu, u8 prio)
  125. {
  126. struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu;
  127. struct kvmppc_xive *xive = xc->xive;
  128. struct xive_q *q = &xc->queues[prio];
  129. void *qpage;
  130. int rc;
  131. if (WARN_ON(q->qpage))
  132. return 0;
  133. /* Allocate the queue and retrieve infos on current node for now */
  134. qpage = (__be32 *)__get_free_pages(GFP_KERNEL, xive->q_page_order);
  135. if (!qpage) {
  136. pr_err("Failed to allocate queue %d for VCPU %d\n",
  137. prio, xc->server_num);
  138. return -ENOMEM;;
  139. }
  140. memset(qpage, 0, 1 << xive->q_order);
  141. /*
  142. * Reconfigure the queue. This will set q->qpage only once the
  143. * queue is fully configured. This is a requirement for prio 0
  144. * as we will stop doing EOIs for every IPI as soon as we observe
  145. * qpage being non-NULL, and instead will only EOI when we receive
  146. * corresponding queue 0 entries
  147. */
  148. rc = xive_native_configure_queue(xc->vp_id, q, prio, qpage,
  149. xive->q_order, true);
  150. if (rc)
  151. pr_err("Failed to configure queue %d for VCPU %d\n",
  152. prio, xc->server_num);
  153. return rc;
  154. }
  155. /* Called with kvm_lock held */
  156. static int xive_check_provisioning(struct kvm *kvm, u8 prio)
  157. {
  158. struct kvmppc_xive *xive = kvm->arch.xive;
  159. struct kvm_vcpu *vcpu;
  160. int i, rc;
  161. lockdep_assert_held(&kvm->lock);
  162. /* Already provisioned ? */
  163. if (xive->qmap & (1 << prio))
  164. return 0;
  165. pr_devel("Provisioning prio... %d\n", prio);
  166. /* Provision each VCPU and enable escalations */
  167. kvm_for_each_vcpu(i, vcpu, kvm) {
  168. if (!vcpu->arch.xive_vcpu)
  169. continue;
  170. rc = xive_provision_queue(vcpu, prio);
  171. if (rc == 0)
  172. xive_attach_escalation(vcpu, prio);
  173. if (rc)
  174. return rc;
  175. }
  176. /* Order previous stores and mark it as provisioned */
  177. mb();
  178. xive->qmap |= (1 << prio);
  179. return 0;
  180. }
  181. static void xive_inc_q_pending(struct kvm *kvm, u32 server, u8 prio)
  182. {
  183. struct kvm_vcpu *vcpu;
  184. struct kvmppc_xive_vcpu *xc;
  185. struct xive_q *q;
  186. /* Locate target server */
  187. vcpu = kvmppc_xive_find_server(kvm, server);
  188. if (!vcpu) {
  189. pr_warn("%s: Can't find server %d\n", __func__, server);
  190. return;
  191. }
  192. xc = vcpu->arch.xive_vcpu;
  193. if (WARN_ON(!xc))
  194. return;
  195. q = &xc->queues[prio];
  196. atomic_inc(&q->pending_count);
  197. }
  198. static int xive_try_pick_queue(struct kvm_vcpu *vcpu, u8 prio)
  199. {
  200. struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu;
  201. struct xive_q *q;
  202. u32 max;
  203. if (WARN_ON(!xc))
  204. return -ENXIO;
  205. if (!xc->valid)
  206. return -ENXIO;
  207. q = &xc->queues[prio];
  208. if (WARN_ON(!q->qpage))
  209. return -ENXIO;
  210. /* Calculate max number of interrupts in that queue. */
  211. max = (q->msk + 1) - XIVE_Q_GAP;
  212. return atomic_add_unless(&q->count, 1, max) ? 0 : -EBUSY;
  213. }
  214. static int xive_select_target(struct kvm *kvm, u32 *server, u8 prio)
  215. {
  216. struct kvm_vcpu *vcpu;
  217. int i, rc;
  218. /* Locate target server */
  219. vcpu = kvmppc_xive_find_server(kvm, *server);
  220. if (!vcpu) {
  221. pr_devel("Can't find server %d\n", *server);
  222. return -EINVAL;
  223. }
  224. pr_devel("Finding irq target on 0x%x/%d...\n", *server, prio);
  225. /* Try pick it */
  226. rc = xive_try_pick_queue(vcpu, prio);
  227. if (rc == 0)
  228. return rc;
  229. pr_devel(" .. failed, looking up candidate...\n");
  230. /* Failed, pick another VCPU */
  231. kvm_for_each_vcpu(i, vcpu, kvm) {
  232. if (!vcpu->arch.xive_vcpu)
  233. continue;
  234. rc = xive_try_pick_queue(vcpu, prio);
  235. if (rc == 0) {
  236. *server = vcpu->arch.xive_vcpu->server_num;
  237. pr_devel(" found on 0x%x/%d\n", *server, prio);
  238. return rc;
  239. }
  240. }
  241. pr_devel(" no available target !\n");
  242. /* No available target ! */
  243. return -EBUSY;
  244. }
  245. static u8 xive_lock_and_mask(struct kvmppc_xive *xive,
  246. struct kvmppc_xive_src_block *sb,
  247. struct kvmppc_xive_irq_state *state)
  248. {
  249. struct xive_irq_data *xd;
  250. u32 hw_num;
  251. u8 old_prio;
  252. u64 val;
  253. /*
  254. * Take the lock, set masked, try again if racing
  255. * with H_EOI
  256. */
  257. for (;;) {
  258. arch_spin_lock(&sb->lock);
  259. old_prio = state->guest_priority;
  260. state->guest_priority = MASKED;
  261. mb();
  262. if (!state->in_eoi)
  263. break;
  264. state->guest_priority = old_prio;
  265. arch_spin_unlock(&sb->lock);
  266. }
  267. /* No change ? Bail */
  268. if (old_prio == MASKED)
  269. return old_prio;
  270. /* Get the right irq */
  271. kvmppc_xive_select_irq(state, &hw_num, &xd);
  272. /*
  273. * If the interrupt is marked as needing masking via
  274. * firmware, we do it here. Firmware masking however
  275. * is "lossy", it won't return the old p and q bits
  276. * and won't set the interrupt to a state where it will
  277. * record queued ones. If this is an issue we should do
  278. * lazy masking instead.
  279. *
  280. * For now, we work around this in unmask by forcing
  281. * an interrupt whenever we unmask a non-LSI via FW
  282. * (if ever).
  283. */
  284. if (xd->flags & OPAL_XIVE_IRQ_MASK_VIA_FW) {
  285. xive_native_configure_irq(hw_num,
  286. xive->vp_base + state->act_server,
  287. MASKED, state->number);
  288. /* set old_p so we can track if an H_EOI was done */
  289. state->old_p = true;
  290. state->old_q = false;
  291. } else {
  292. /* Set PQ to 10, return old P and old Q and remember them */
  293. val = xive_vm_esb_load(xd, XIVE_ESB_SET_PQ_10);
  294. state->old_p = !!(val & 2);
  295. state->old_q = !!(val & 1);
  296. /*
  297. * Synchronize hardware to sensure the queues are updated
  298. * when masking
  299. */
  300. xive_native_sync_source(hw_num);
  301. }
  302. return old_prio;
  303. }
  304. static void xive_lock_for_unmask(struct kvmppc_xive_src_block *sb,
  305. struct kvmppc_xive_irq_state *state)
  306. {
  307. /*
  308. * Take the lock try again if racing with H_EOI
  309. */
  310. for (;;) {
  311. arch_spin_lock(&sb->lock);
  312. if (!state->in_eoi)
  313. break;
  314. arch_spin_unlock(&sb->lock);
  315. }
  316. }
  317. static void xive_finish_unmask(struct kvmppc_xive *xive,
  318. struct kvmppc_xive_src_block *sb,
  319. struct kvmppc_xive_irq_state *state,
  320. u8 prio)
  321. {
  322. struct xive_irq_data *xd;
  323. u32 hw_num;
  324. /* If we aren't changing a thing, move on */
  325. if (state->guest_priority != MASKED)
  326. goto bail;
  327. /* Get the right irq */
  328. kvmppc_xive_select_irq(state, &hw_num, &xd);
  329. /*
  330. * See command in xive_lock_and_mask() concerning masking
  331. * via firmware.
  332. */
  333. if (xd->flags & OPAL_XIVE_IRQ_MASK_VIA_FW) {
  334. xive_native_configure_irq(hw_num,
  335. xive->vp_base + state->act_server,
  336. state->act_priority, state->number);
  337. /* If an EOI is needed, do it here */
  338. if (!state->old_p)
  339. xive_vm_source_eoi(hw_num, xd);
  340. /* If this is not an LSI, force a trigger */
  341. if (!(xd->flags & OPAL_XIVE_IRQ_LSI))
  342. xive_irq_trigger(xd);
  343. goto bail;
  344. }
  345. /* Old Q set, set PQ to 11 */
  346. if (state->old_q)
  347. xive_vm_esb_load(xd, XIVE_ESB_SET_PQ_11);
  348. /*
  349. * If not old P, then perform an "effective" EOI,
  350. * on the source. This will handle the cases where
  351. * FW EOI is needed.
  352. */
  353. if (!state->old_p)
  354. xive_vm_source_eoi(hw_num, xd);
  355. /* Synchronize ordering and mark unmasked */
  356. mb();
  357. bail:
  358. state->guest_priority = prio;
  359. }
  360. /*
  361. * Target an interrupt to a given server/prio, this will fallback
  362. * to another server if necessary and perform the HW targetting
  363. * updates as needed
  364. *
  365. * NOTE: Must be called with the state lock held
  366. */
  367. static int xive_target_interrupt(struct kvm *kvm,
  368. struct kvmppc_xive_irq_state *state,
  369. u32 server, u8 prio)
  370. {
  371. struct kvmppc_xive *xive = kvm->arch.xive;
  372. u32 hw_num;
  373. int rc;
  374. /*
  375. * This will return a tentative server and actual
  376. * priority. The count for that new target will have
  377. * already been incremented.
  378. */
  379. rc = xive_select_target(kvm, &server, prio);
  380. /*
  381. * We failed to find a target ? Not much we can do
  382. * at least until we support the GIQ.
  383. */
  384. if (rc)
  385. return rc;
  386. /*
  387. * Increment the old queue pending count if there
  388. * was one so that the old queue count gets adjusted later
  389. * when observed to be empty.
  390. */
  391. if (state->act_priority != MASKED)
  392. xive_inc_q_pending(kvm,
  393. state->act_server,
  394. state->act_priority);
  395. /*
  396. * Update state and HW
  397. */
  398. state->act_priority = prio;
  399. state->act_server = server;
  400. /* Get the right irq */
  401. kvmppc_xive_select_irq(state, &hw_num, NULL);
  402. return xive_native_configure_irq(hw_num,
  403. xive->vp_base + server,
  404. prio, state->number);
  405. }
  406. /*
  407. * Targetting rules: In order to avoid losing track of
  408. * pending interrupts accross mask and unmask, which would
  409. * allow queue overflows, we implement the following rules:
  410. *
  411. * - Unless it was never enabled (or we run out of capacity)
  412. * an interrupt is always targetted at a valid server/queue
  413. * pair even when "masked" by the guest. This pair tends to
  414. * be the last one used but it can be changed under some
  415. * circumstances. That allows us to separate targetting
  416. * from masking, we only handle accounting during (re)targetting,
  417. * this also allows us to let an interrupt drain into its target
  418. * queue after masking, avoiding complex schemes to remove
  419. * interrupts out of remote processor queues.
  420. *
  421. * - When masking, we set PQ to 10 and save the previous value
  422. * of P and Q.
  423. *
  424. * - When unmasking, if saved Q was set, we set PQ to 11
  425. * otherwise we leave PQ to the HW state which will be either
  426. * 10 if nothing happened or 11 if the interrupt fired while
  427. * masked. Effectively we are OR'ing the previous Q into the
  428. * HW Q.
  429. *
  430. * Then if saved P is clear, we do an effective EOI (Q->P->Trigger)
  431. * which will unmask the interrupt and shoot a new one if Q was
  432. * set.
  433. *
  434. * Otherwise (saved P is set) we leave PQ unchanged (so 10 or 11,
  435. * effectively meaning an H_EOI from the guest is still expected
  436. * for that interrupt).
  437. *
  438. * - If H_EOI occurs while masked, we clear the saved P.
  439. *
  440. * - When changing target, we account on the new target and
  441. * increment a separate "pending" counter on the old one.
  442. * This pending counter will be used to decrement the old
  443. * target's count when its queue has been observed empty.
  444. */
  445. int kvmppc_xive_set_xive(struct kvm *kvm, u32 irq, u32 server,
  446. u32 priority)
  447. {
  448. struct kvmppc_xive *xive = kvm->arch.xive;
  449. struct kvmppc_xive_src_block *sb;
  450. struct kvmppc_xive_irq_state *state;
  451. u8 new_act_prio;
  452. int rc = 0;
  453. u16 idx;
  454. if (!xive)
  455. return -ENODEV;
  456. pr_devel("set_xive ! irq 0x%x server 0x%x prio %d\n",
  457. irq, server, priority);
  458. /* First, check provisioning of queues */
  459. if (priority != MASKED)
  460. rc = xive_check_provisioning(xive->kvm,
  461. xive_prio_from_guest(priority));
  462. if (rc) {
  463. pr_devel(" provisioning failure %d !\n", rc);
  464. return rc;
  465. }
  466. sb = kvmppc_xive_find_source(xive, irq, &idx);
  467. if (!sb)
  468. return -EINVAL;
  469. state = &sb->irq_state[idx];
  470. /*
  471. * We first handle masking/unmasking since the locking
  472. * might need to be retried due to EOIs, we'll handle
  473. * targetting changes later. These functions will return
  474. * with the SB lock held.
  475. *
  476. * xive_lock_and_mask() will also set state->guest_priority
  477. * but won't otherwise change other fields of the state.
  478. *
  479. * xive_lock_for_unmask will not actually unmask, this will
  480. * be done later by xive_finish_unmask() once the targetting
  481. * has been done, so we don't try to unmask an interrupt
  482. * that hasn't yet been targetted.
  483. */
  484. if (priority == MASKED)
  485. xive_lock_and_mask(xive, sb, state);
  486. else
  487. xive_lock_for_unmask(sb, state);
  488. /*
  489. * Then we handle targetting.
  490. *
  491. * First calculate a new "actual priority"
  492. */
  493. new_act_prio = state->act_priority;
  494. if (priority != MASKED)
  495. new_act_prio = xive_prio_from_guest(priority);
  496. pr_devel(" new_act_prio=%x act_server=%x act_prio=%x\n",
  497. new_act_prio, state->act_server, state->act_priority);
  498. /*
  499. * Then check if we actually need to change anything,
  500. *
  501. * The condition for re-targetting the interrupt is that
  502. * we have a valid new priority (new_act_prio is not 0xff)
  503. * and either the server or the priority changed.
  504. *
  505. * Note: If act_priority was ff and the new priority is
  506. * also ff, we don't do anything and leave the interrupt
  507. * untargetted. An attempt of doing an int_on on an
  508. * untargetted interrupt will fail. If that is a problem
  509. * we could initialize interrupts with valid default
  510. */
  511. if (new_act_prio != MASKED &&
  512. (state->act_server != server ||
  513. state->act_priority != new_act_prio))
  514. rc = xive_target_interrupt(kvm, state, server, new_act_prio);
  515. /*
  516. * Perform the final unmasking of the interrupt source
  517. * if necessary
  518. */
  519. if (priority != MASKED)
  520. xive_finish_unmask(xive, sb, state, priority);
  521. /*
  522. * Finally Update saved_priority to match. Only int_on/off
  523. * set this field to a different value.
  524. */
  525. state->saved_priority = priority;
  526. arch_spin_unlock(&sb->lock);
  527. return rc;
  528. }
  529. int kvmppc_xive_get_xive(struct kvm *kvm, u32 irq, u32 *server,
  530. u32 *priority)
  531. {
  532. struct kvmppc_xive *xive = kvm->arch.xive;
  533. struct kvmppc_xive_src_block *sb;
  534. struct kvmppc_xive_irq_state *state;
  535. u16 idx;
  536. if (!xive)
  537. return -ENODEV;
  538. sb = kvmppc_xive_find_source(xive, irq, &idx);
  539. if (!sb)
  540. return -EINVAL;
  541. state = &sb->irq_state[idx];
  542. arch_spin_lock(&sb->lock);
  543. *server = state->guest_server;
  544. *priority = state->guest_priority;
  545. arch_spin_unlock(&sb->lock);
  546. return 0;
  547. }
  548. int kvmppc_xive_int_on(struct kvm *kvm, u32 irq)
  549. {
  550. struct kvmppc_xive *xive = kvm->arch.xive;
  551. struct kvmppc_xive_src_block *sb;
  552. struct kvmppc_xive_irq_state *state;
  553. u16 idx;
  554. if (!xive)
  555. return -ENODEV;
  556. sb = kvmppc_xive_find_source(xive, irq, &idx);
  557. if (!sb)
  558. return -EINVAL;
  559. state = &sb->irq_state[idx];
  560. pr_devel("int_on(irq=0x%x)\n", irq);
  561. /*
  562. * Check if interrupt was not targetted
  563. */
  564. if (state->act_priority == MASKED) {
  565. pr_devel("int_on on untargetted interrupt\n");
  566. return -EINVAL;
  567. }
  568. /* If saved_priority is 0xff, do nothing */
  569. if (state->saved_priority == MASKED)
  570. return 0;
  571. /*
  572. * Lock and unmask it.
  573. */
  574. xive_lock_for_unmask(sb, state);
  575. xive_finish_unmask(xive, sb, state, state->saved_priority);
  576. arch_spin_unlock(&sb->lock);
  577. return 0;
  578. }
  579. int kvmppc_xive_int_off(struct kvm *kvm, u32 irq)
  580. {
  581. struct kvmppc_xive *xive = kvm->arch.xive;
  582. struct kvmppc_xive_src_block *sb;
  583. struct kvmppc_xive_irq_state *state;
  584. u16 idx;
  585. if (!xive)
  586. return -ENODEV;
  587. sb = kvmppc_xive_find_source(xive, irq, &idx);
  588. if (!sb)
  589. return -EINVAL;
  590. state = &sb->irq_state[idx];
  591. pr_devel("int_off(irq=0x%x)\n", irq);
  592. /*
  593. * Lock and mask
  594. */
  595. state->saved_priority = xive_lock_and_mask(xive, sb, state);
  596. arch_spin_unlock(&sb->lock);
  597. return 0;
  598. }
  599. static bool xive_restore_pending_irq(struct kvmppc_xive *xive, u32 irq)
  600. {
  601. struct kvmppc_xive_src_block *sb;
  602. struct kvmppc_xive_irq_state *state;
  603. u16 idx;
  604. sb = kvmppc_xive_find_source(xive, irq, &idx);
  605. if (!sb)
  606. return false;
  607. state = &sb->irq_state[idx];
  608. if (!state->valid)
  609. return false;
  610. /*
  611. * Trigger the IPI. This assumes we never restore a pass-through
  612. * interrupt which should be safe enough
  613. */
  614. xive_irq_trigger(&state->ipi_data);
  615. return true;
  616. }
  617. u64 kvmppc_xive_get_icp(struct kvm_vcpu *vcpu)
  618. {
  619. struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu;
  620. if (!xc)
  621. return 0;
  622. /* Return the per-cpu state for state saving/migration */
  623. return (u64)xc->cppr << KVM_REG_PPC_ICP_CPPR_SHIFT |
  624. (u64)xc->mfrr << KVM_REG_PPC_ICP_MFRR_SHIFT;
  625. }
  626. int kvmppc_xive_set_icp(struct kvm_vcpu *vcpu, u64 icpval)
  627. {
  628. struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu;
  629. struct kvmppc_xive *xive = vcpu->kvm->arch.xive;
  630. u8 cppr, mfrr;
  631. u32 xisr;
  632. if (!xc || !xive)
  633. return -ENOENT;
  634. /* Grab individual state fields. We don't use pending_pri */
  635. cppr = icpval >> KVM_REG_PPC_ICP_CPPR_SHIFT;
  636. xisr = (icpval >> KVM_REG_PPC_ICP_XISR_SHIFT) &
  637. KVM_REG_PPC_ICP_XISR_MASK;
  638. mfrr = icpval >> KVM_REG_PPC_ICP_MFRR_SHIFT;
  639. pr_devel("set_icp vcpu %d cppr=0x%x mfrr=0x%x xisr=0x%x\n",
  640. xc->server_num, cppr, mfrr, xisr);
  641. /*
  642. * We can't update the state of a "pushed" VCPU, but that
  643. * shouldn't happen.
  644. */
  645. if (WARN_ON(vcpu->arch.xive_pushed))
  646. return -EIO;
  647. /* Update VCPU HW saved state */
  648. vcpu->arch.xive_saved_state.cppr = cppr;
  649. xc->hw_cppr = xc->cppr = cppr;
  650. /*
  651. * Update MFRR state. If it's not 0xff, we mark the VCPU as
  652. * having a pending MFRR change, which will re-evaluate the
  653. * target. The VCPU will thus potentially get a spurious
  654. * interrupt but that's not a big deal.
  655. */
  656. xc->mfrr = mfrr;
  657. if (mfrr < cppr)
  658. xive_irq_trigger(&xc->vp_ipi_data);
  659. /*
  660. * Now saved XIRR is "interesting". It means there's something in
  661. * the legacy "1 element" queue... for an IPI we simply ignore it,
  662. * as the MFRR restore will handle that. For anything else we need
  663. * to force a resend of the source.
  664. * However the source may not have been setup yet. If that's the
  665. * case, we keep that info and increment a counter in the xive to
  666. * tell subsequent xive_set_source() to go look.
  667. */
  668. if (xisr > XICS_IPI && !xive_restore_pending_irq(xive, xisr)) {
  669. xc->delayed_irq = xisr;
  670. xive->delayed_irqs++;
  671. pr_devel(" xisr restore delayed\n");
  672. }
  673. return 0;
  674. }
  675. int kvmppc_xive_set_mapped(struct kvm *kvm, unsigned long guest_irq,
  676. struct irq_desc *host_desc)
  677. {
  678. struct kvmppc_xive *xive = kvm->arch.xive;
  679. struct kvmppc_xive_src_block *sb;
  680. struct kvmppc_xive_irq_state *state;
  681. struct irq_data *host_data = irq_desc_get_irq_data(host_desc);
  682. unsigned int host_irq = irq_desc_get_irq(host_desc);
  683. unsigned int hw_irq = (unsigned int)irqd_to_hwirq(host_data);
  684. u16 idx;
  685. u8 prio;
  686. int rc;
  687. if (!xive)
  688. return -ENODEV;
  689. pr_devel("set_mapped girq 0x%lx host HW irq 0x%x...\n",guest_irq, hw_irq);
  690. sb = kvmppc_xive_find_source(xive, guest_irq, &idx);
  691. if (!sb)
  692. return -EINVAL;
  693. state = &sb->irq_state[idx];
  694. /*
  695. * Mark the passed-through interrupt as going to a VCPU,
  696. * this will prevent further EOIs and similar operations
  697. * from the XIVE code. It will also mask the interrupt
  698. * to either PQ=10 or 11 state, the latter if the interrupt
  699. * is pending. This will allow us to unmask or retrigger it
  700. * after routing it to the guest with a simple EOI.
  701. *
  702. * The "state" argument is a "token", all it needs is to be
  703. * non-NULL to switch to passed-through or NULL for the
  704. * other way around. We may not yet have an actual VCPU
  705. * target here and we don't really care.
  706. */
  707. rc = irq_set_vcpu_affinity(host_irq, state);
  708. if (rc) {
  709. pr_err("Failed to set VCPU affinity for irq %d\n", host_irq);
  710. return rc;
  711. }
  712. /*
  713. * Mask and read state of IPI. We need to know if its P bit
  714. * is set as that means it's potentially already using a
  715. * queue entry in the target
  716. */
  717. prio = xive_lock_and_mask(xive, sb, state);
  718. pr_devel(" old IPI prio %02x P:%d Q:%d\n", prio,
  719. state->old_p, state->old_q);
  720. /* Turn the IPI hard off */
  721. xive_vm_esb_load(&state->ipi_data, XIVE_ESB_SET_PQ_01);
  722. /* Grab info about irq */
  723. state->pt_number = hw_irq;
  724. state->pt_data = irq_data_get_irq_handler_data(host_data);
  725. /*
  726. * Configure the IRQ to match the existing configuration of
  727. * the IPI if it was already targetted. Otherwise this will
  728. * mask the interrupt in a lossy way (act_priority is 0xff)
  729. * which is fine for a never started interrupt.
  730. */
  731. xive_native_configure_irq(hw_irq,
  732. xive->vp_base + state->act_server,
  733. state->act_priority, state->number);
  734. /*
  735. * We do an EOI to enable the interrupt (and retrigger if needed)
  736. * if the guest has the interrupt unmasked and the P bit was *not*
  737. * set in the IPI. If it was set, we know a slot may still be in
  738. * use in the target queue thus we have to wait for a guest
  739. * originated EOI
  740. */
  741. if (prio != MASKED && !state->old_p)
  742. xive_vm_source_eoi(hw_irq, state->pt_data);
  743. /* Clear old_p/old_q as they are no longer relevant */
  744. state->old_p = state->old_q = false;
  745. /* Restore guest prio (unlocks EOI) */
  746. mb();
  747. state->guest_priority = prio;
  748. arch_spin_unlock(&sb->lock);
  749. return 0;
  750. }
  751. EXPORT_SYMBOL_GPL(kvmppc_xive_set_mapped);
  752. int kvmppc_xive_clr_mapped(struct kvm *kvm, unsigned long guest_irq,
  753. struct irq_desc *host_desc)
  754. {
  755. struct kvmppc_xive *xive = kvm->arch.xive;
  756. struct kvmppc_xive_src_block *sb;
  757. struct kvmppc_xive_irq_state *state;
  758. unsigned int host_irq = irq_desc_get_irq(host_desc);
  759. u16 idx;
  760. u8 prio;
  761. int rc;
  762. if (!xive)
  763. return -ENODEV;
  764. pr_devel("clr_mapped girq 0x%lx...\n", guest_irq);
  765. sb = kvmppc_xive_find_source(xive, guest_irq, &idx);
  766. if (!sb)
  767. return -EINVAL;
  768. state = &sb->irq_state[idx];
  769. /*
  770. * Mask and read state of IRQ. We need to know if its P bit
  771. * is set as that means it's potentially already using a
  772. * queue entry in the target
  773. */
  774. prio = xive_lock_and_mask(xive, sb, state);
  775. pr_devel(" old IRQ prio %02x P:%d Q:%d\n", prio,
  776. state->old_p, state->old_q);
  777. /*
  778. * If old_p is set, the interrupt is pending, we switch it to
  779. * PQ=11. This will force a resend in the host so the interrupt
  780. * isn't lost to whatver host driver may pick it up
  781. */
  782. if (state->old_p)
  783. xive_vm_esb_load(state->pt_data, XIVE_ESB_SET_PQ_11);
  784. /* Release the passed-through interrupt to the host */
  785. rc = irq_set_vcpu_affinity(host_irq, NULL);
  786. if (rc) {
  787. pr_err("Failed to clr VCPU affinity for irq %d\n", host_irq);
  788. return rc;
  789. }
  790. /* Forget about the IRQ */
  791. state->pt_number = 0;
  792. state->pt_data = NULL;
  793. /* Reconfigure the IPI */
  794. xive_native_configure_irq(state->ipi_number,
  795. xive->vp_base + state->act_server,
  796. state->act_priority, state->number);
  797. /*
  798. * If old_p is set (we have a queue entry potentially
  799. * occupied) or the interrupt is masked, we set the IPI
  800. * to PQ=10 state. Otherwise we just re-enable it (PQ=00).
  801. */
  802. if (prio == MASKED || state->old_p)
  803. xive_vm_esb_load(&state->ipi_data, XIVE_ESB_SET_PQ_10);
  804. else
  805. xive_vm_esb_load(&state->ipi_data, XIVE_ESB_SET_PQ_00);
  806. /* Restore guest prio (unlocks EOI) */
  807. mb();
  808. state->guest_priority = prio;
  809. arch_spin_unlock(&sb->lock);
  810. return 0;
  811. }
  812. EXPORT_SYMBOL_GPL(kvmppc_xive_clr_mapped);
  813. static void kvmppc_xive_disable_vcpu_interrupts(struct kvm_vcpu *vcpu)
  814. {
  815. struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu;
  816. struct kvm *kvm = vcpu->kvm;
  817. struct kvmppc_xive *xive = kvm->arch.xive;
  818. int i, j;
  819. for (i = 0; i <= xive->max_sbid; i++) {
  820. struct kvmppc_xive_src_block *sb = xive->src_blocks[i];
  821. if (!sb)
  822. continue;
  823. for (j = 0; j < KVMPPC_XICS_IRQ_PER_ICS; j++) {
  824. struct kvmppc_xive_irq_state *state = &sb->irq_state[j];
  825. if (!state->valid)
  826. continue;
  827. if (state->act_priority == MASKED)
  828. continue;
  829. if (state->act_server != xc->server_num)
  830. continue;
  831. /* Clean it up */
  832. arch_spin_lock(&sb->lock);
  833. state->act_priority = MASKED;
  834. xive_vm_esb_load(&state->ipi_data, XIVE_ESB_SET_PQ_01);
  835. xive_native_configure_irq(state->ipi_number, 0, MASKED, 0);
  836. if (state->pt_number) {
  837. xive_vm_esb_load(state->pt_data, XIVE_ESB_SET_PQ_01);
  838. xive_native_configure_irq(state->pt_number, 0, MASKED, 0);
  839. }
  840. arch_spin_unlock(&sb->lock);
  841. }
  842. }
  843. }
  844. void kvmppc_xive_cleanup_vcpu(struct kvm_vcpu *vcpu)
  845. {
  846. struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu;
  847. struct kvmppc_xive *xive = xc->xive;
  848. int i;
  849. pr_devel("cleanup_vcpu(cpu=%d)\n", xc->server_num);
  850. /* Ensure no interrupt is still routed to that VP */
  851. xc->valid = false;
  852. kvmppc_xive_disable_vcpu_interrupts(vcpu);
  853. /* Mask the VP IPI */
  854. xive_vm_esb_load(&xc->vp_ipi_data, XIVE_ESB_SET_PQ_01);
  855. /* Disable the VP */
  856. xive_native_disable_vp(xc->vp_id);
  857. /* Free the queues & associated interrupts */
  858. for (i = 0; i < KVMPPC_XIVE_Q_COUNT; i++) {
  859. struct xive_q *q = &xc->queues[i];
  860. /* Free the escalation irq */
  861. if (xc->esc_virq[i]) {
  862. free_irq(xc->esc_virq[i], vcpu);
  863. irq_dispose_mapping(xc->esc_virq[i]);
  864. kfree(xc->esc_virq_names[i]);
  865. }
  866. /* Free the queue */
  867. xive_native_disable_queue(xc->vp_id, q, i);
  868. if (q->qpage) {
  869. free_pages((unsigned long)q->qpage,
  870. xive->q_page_order);
  871. q->qpage = NULL;
  872. }
  873. }
  874. /* Free the IPI */
  875. if (xc->vp_ipi) {
  876. xive_cleanup_irq_data(&xc->vp_ipi_data);
  877. xive_native_free_irq(xc->vp_ipi);
  878. }
  879. /* Free the VP */
  880. kfree(xc);
  881. }
  882. int kvmppc_xive_connect_vcpu(struct kvm_device *dev,
  883. struct kvm_vcpu *vcpu, u32 cpu)
  884. {
  885. struct kvmppc_xive *xive = dev->private;
  886. struct kvmppc_xive_vcpu *xc;
  887. int i, r = -EBUSY;
  888. pr_devel("connect_vcpu(cpu=%d)\n", cpu);
  889. if (dev->ops != &kvm_xive_ops) {
  890. pr_devel("Wrong ops !\n");
  891. return -EPERM;
  892. }
  893. if (xive->kvm != vcpu->kvm)
  894. return -EPERM;
  895. if (vcpu->arch.irq_type)
  896. return -EBUSY;
  897. if (kvmppc_xive_find_server(vcpu->kvm, cpu)) {
  898. pr_devel("Duplicate !\n");
  899. return -EEXIST;
  900. }
  901. if (cpu >= KVM_MAX_VCPUS) {
  902. pr_devel("Out of bounds !\n");
  903. return -EINVAL;
  904. }
  905. xc = kzalloc(sizeof(*xc), GFP_KERNEL);
  906. if (!xc)
  907. return -ENOMEM;
  908. /* We need to synchronize with queue provisioning */
  909. mutex_lock(&vcpu->kvm->lock);
  910. vcpu->arch.xive_vcpu = xc;
  911. xc->xive = xive;
  912. xc->vcpu = vcpu;
  913. xc->server_num = cpu;
  914. xc->vp_id = xive->vp_base + cpu;
  915. xc->mfrr = 0xff;
  916. xc->valid = true;
  917. r = xive_native_get_vp_info(xc->vp_id, &xc->vp_cam, &xc->vp_chip_id);
  918. if (r)
  919. goto bail;
  920. /* Configure VCPU fields for use by assembly push/pull */
  921. vcpu->arch.xive_saved_state.w01 = cpu_to_be64(0xff000000);
  922. vcpu->arch.xive_cam_word = cpu_to_be32(xc->vp_cam | TM_QW1W2_VO);
  923. /* Allocate IPI */
  924. xc->vp_ipi = xive_native_alloc_irq();
  925. if (!xc->vp_ipi) {
  926. r = -EIO;
  927. goto bail;
  928. }
  929. pr_devel(" IPI=0x%x\n", xc->vp_ipi);
  930. r = xive_native_populate_irq_data(xc->vp_ipi, &xc->vp_ipi_data);
  931. if (r)
  932. goto bail;
  933. /*
  934. * Initialize queues. Initially we set them all for no queueing
  935. * and we enable escalation for queue 0 only which we'll use for
  936. * our mfrr change notifications. If the VCPU is hot-plugged, we
  937. * do handle provisioning however.
  938. */
  939. for (i = 0; i < KVMPPC_XIVE_Q_COUNT; i++) {
  940. struct xive_q *q = &xc->queues[i];
  941. /* Is queue already enabled ? Provision it */
  942. if (xive->qmap & (1 << i)) {
  943. r = xive_provision_queue(vcpu, i);
  944. if (r == 0)
  945. xive_attach_escalation(vcpu, i);
  946. if (r)
  947. goto bail;
  948. } else {
  949. r = xive_native_configure_queue(xc->vp_id,
  950. q, i, NULL, 0, true);
  951. if (r) {
  952. pr_err("Failed to configure queue %d for VCPU %d\n",
  953. i, cpu);
  954. goto bail;
  955. }
  956. }
  957. }
  958. /* If not done above, attach priority 0 escalation */
  959. r = xive_attach_escalation(vcpu, 0);
  960. if (r)
  961. goto bail;
  962. /* Enable the VP */
  963. r = xive_native_enable_vp(xc->vp_id);
  964. if (r)
  965. goto bail;
  966. /* Route the IPI */
  967. r = xive_native_configure_irq(xc->vp_ipi, xc->vp_id, 0, XICS_IPI);
  968. if (!r)
  969. xive_vm_esb_load(&xc->vp_ipi_data, XIVE_ESB_SET_PQ_00);
  970. bail:
  971. mutex_unlock(&vcpu->kvm->lock);
  972. if (r) {
  973. kvmppc_xive_cleanup_vcpu(vcpu);
  974. return r;
  975. }
  976. vcpu->arch.irq_type = KVMPPC_IRQ_XICS;
  977. return 0;
  978. }
  979. /*
  980. * Scanning of queues before/after migration save
  981. */
  982. static void xive_pre_save_set_queued(struct kvmppc_xive *xive, u32 irq)
  983. {
  984. struct kvmppc_xive_src_block *sb;
  985. struct kvmppc_xive_irq_state *state;
  986. u16 idx;
  987. sb = kvmppc_xive_find_source(xive, irq, &idx);
  988. if (!sb)
  989. return;
  990. state = &sb->irq_state[idx];
  991. /* Some sanity checking */
  992. if (!state->valid) {
  993. pr_err("invalid irq 0x%x in cpu queue!\n", irq);
  994. return;
  995. }
  996. /*
  997. * If the interrupt is in a queue it should have P set.
  998. * We warn so that gets reported. A backtrace isn't useful
  999. * so no need to use a WARN_ON.
  1000. */
  1001. if (!state->saved_p)
  1002. pr_err("Interrupt 0x%x is marked in a queue but P not set !\n", irq);
  1003. /* Set flag */
  1004. state->in_queue = true;
  1005. }
  1006. static void xive_pre_save_mask_irq(struct kvmppc_xive *xive,
  1007. struct kvmppc_xive_src_block *sb,
  1008. u32 irq)
  1009. {
  1010. struct kvmppc_xive_irq_state *state = &sb->irq_state[irq];
  1011. if (!state->valid)
  1012. return;
  1013. /* Mask and save state, this will also sync HW queues */
  1014. state->saved_scan_prio = xive_lock_and_mask(xive, sb, state);
  1015. /* Transfer P and Q */
  1016. state->saved_p = state->old_p;
  1017. state->saved_q = state->old_q;
  1018. /* Unlock */
  1019. arch_spin_unlock(&sb->lock);
  1020. }
  1021. static void xive_pre_save_unmask_irq(struct kvmppc_xive *xive,
  1022. struct kvmppc_xive_src_block *sb,
  1023. u32 irq)
  1024. {
  1025. struct kvmppc_xive_irq_state *state = &sb->irq_state[irq];
  1026. if (!state->valid)
  1027. return;
  1028. /*
  1029. * Lock / exclude EOI (not technically necessary if the
  1030. * guest isn't running concurrently. If this becomes a
  1031. * performance issue we can probably remove the lock.
  1032. */
  1033. xive_lock_for_unmask(sb, state);
  1034. /* Restore mask/prio if it wasn't masked */
  1035. if (state->saved_scan_prio != MASKED)
  1036. xive_finish_unmask(xive, sb, state, state->saved_scan_prio);
  1037. /* Unlock */
  1038. arch_spin_unlock(&sb->lock);
  1039. }
  1040. static void xive_pre_save_queue(struct kvmppc_xive *xive, struct xive_q *q)
  1041. {
  1042. u32 idx = q->idx;
  1043. u32 toggle = q->toggle;
  1044. u32 irq;
  1045. do {
  1046. irq = __xive_read_eq(q->qpage, q->msk, &idx, &toggle);
  1047. if (irq > XICS_IPI)
  1048. xive_pre_save_set_queued(xive, irq);
  1049. } while(irq);
  1050. }
  1051. static void xive_pre_save_scan(struct kvmppc_xive *xive)
  1052. {
  1053. struct kvm_vcpu *vcpu = NULL;
  1054. int i, j;
  1055. /*
  1056. * See comment in xive_get_source() about how this
  1057. * work. Collect a stable state for all interrupts
  1058. */
  1059. for (i = 0; i <= xive->max_sbid; i++) {
  1060. struct kvmppc_xive_src_block *sb = xive->src_blocks[i];
  1061. if (!sb)
  1062. continue;
  1063. for (j = 0; j < KVMPPC_XICS_IRQ_PER_ICS; j++)
  1064. xive_pre_save_mask_irq(xive, sb, j);
  1065. }
  1066. /* Then scan the queues and update the "in_queue" flag */
  1067. kvm_for_each_vcpu(i, vcpu, xive->kvm) {
  1068. struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu;
  1069. if (!xc)
  1070. continue;
  1071. for (j = 0; j < KVMPPC_XIVE_Q_COUNT; j++) {
  1072. if (xc->queues[i].qpage)
  1073. xive_pre_save_queue(xive, &xc->queues[i]);
  1074. }
  1075. }
  1076. /* Finally restore interrupt states */
  1077. for (i = 0; i <= xive->max_sbid; i++) {
  1078. struct kvmppc_xive_src_block *sb = xive->src_blocks[i];
  1079. if (!sb)
  1080. continue;
  1081. for (j = 0; j < KVMPPC_XICS_IRQ_PER_ICS; j++)
  1082. xive_pre_save_unmask_irq(xive, sb, j);
  1083. }
  1084. }
  1085. static void xive_post_save_scan(struct kvmppc_xive *xive)
  1086. {
  1087. u32 i, j;
  1088. /* Clear all the in_queue flags */
  1089. for (i = 0; i <= xive->max_sbid; i++) {
  1090. struct kvmppc_xive_src_block *sb = xive->src_blocks[i];
  1091. if (!sb)
  1092. continue;
  1093. for (j = 0; j < KVMPPC_XICS_IRQ_PER_ICS; j++)
  1094. sb->irq_state[j].in_queue = false;
  1095. }
  1096. /* Next get_source() will do a new scan */
  1097. xive->saved_src_count = 0;
  1098. }
  1099. /*
  1100. * This returns the source configuration and state to user space.
  1101. */
  1102. static int xive_get_source(struct kvmppc_xive *xive, long irq, u64 addr)
  1103. {
  1104. struct kvmppc_xive_src_block *sb;
  1105. struct kvmppc_xive_irq_state *state;
  1106. u64 __user *ubufp = (u64 __user *) addr;
  1107. u64 val, prio;
  1108. u16 idx;
  1109. sb = kvmppc_xive_find_source(xive, irq, &idx);
  1110. if (!sb)
  1111. return -ENOENT;
  1112. state = &sb->irq_state[idx];
  1113. if (!state->valid)
  1114. return -ENOENT;
  1115. pr_devel("get_source(%ld)...\n", irq);
  1116. /*
  1117. * So to properly save the state into something that looks like a
  1118. * XICS migration stream we cannot treat interrupts individually.
  1119. *
  1120. * We need, instead, mask them all (& save their previous PQ state)
  1121. * to get a stable state in the HW, then sync them to ensure that
  1122. * any interrupt that had already fired hits its queue, and finally
  1123. * scan all the queues to collect which interrupts are still present
  1124. * in the queues, so we can set the "pending" flag on them and
  1125. * they can be resent on restore.
  1126. *
  1127. * So we do it all when the "first" interrupt gets saved, all the
  1128. * state is collected at that point, the rest of xive_get_source()
  1129. * will merely collect and convert that state to the expected
  1130. * userspace bit mask.
  1131. */
  1132. if (xive->saved_src_count == 0)
  1133. xive_pre_save_scan(xive);
  1134. xive->saved_src_count++;
  1135. /* Convert saved state into something compatible with xics */
  1136. val = state->guest_server;
  1137. prio = state->saved_scan_prio;
  1138. if (prio == MASKED) {
  1139. val |= KVM_XICS_MASKED;
  1140. prio = state->saved_priority;
  1141. }
  1142. val |= prio << KVM_XICS_PRIORITY_SHIFT;
  1143. if (state->lsi) {
  1144. val |= KVM_XICS_LEVEL_SENSITIVE;
  1145. if (state->saved_p)
  1146. val |= KVM_XICS_PENDING;
  1147. } else {
  1148. if (state->saved_p)
  1149. val |= KVM_XICS_PRESENTED;
  1150. if (state->saved_q)
  1151. val |= KVM_XICS_QUEUED;
  1152. /*
  1153. * We mark it pending (which will attempt a re-delivery)
  1154. * if we are in a queue *or* we were masked and had
  1155. * Q set which is equivalent to the XICS "masked pending"
  1156. * state
  1157. */
  1158. if (state->in_queue || (prio == MASKED && state->saved_q))
  1159. val |= KVM_XICS_PENDING;
  1160. }
  1161. /*
  1162. * If that was the last interrupt saved, reset the
  1163. * in_queue flags
  1164. */
  1165. if (xive->saved_src_count == xive->src_count)
  1166. xive_post_save_scan(xive);
  1167. /* Copy the result to userspace */
  1168. if (put_user(val, ubufp))
  1169. return -EFAULT;
  1170. return 0;
  1171. }
  1172. static struct kvmppc_xive_src_block *xive_create_src_block(struct kvmppc_xive *xive,
  1173. int irq)
  1174. {
  1175. struct kvm *kvm = xive->kvm;
  1176. struct kvmppc_xive_src_block *sb;
  1177. int i, bid;
  1178. bid = irq >> KVMPPC_XICS_ICS_SHIFT;
  1179. mutex_lock(&kvm->lock);
  1180. /* block already exists - somebody else got here first */
  1181. if (xive->src_blocks[bid])
  1182. goto out;
  1183. /* Create the ICS */
  1184. sb = kzalloc(sizeof(*sb), GFP_KERNEL);
  1185. if (!sb)
  1186. goto out;
  1187. sb->id = bid;
  1188. for (i = 0; i < KVMPPC_XICS_IRQ_PER_ICS; i++) {
  1189. sb->irq_state[i].number = (bid << KVMPPC_XICS_ICS_SHIFT) | i;
  1190. sb->irq_state[i].guest_priority = MASKED;
  1191. sb->irq_state[i].saved_priority = MASKED;
  1192. sb->irq_state[i].act_priority = MASKED;
  1193. }
  1194. smp_wmb();
  1195. xive->src_blocks[bid] = sb;
  1196. if (bid > xive->max_sbid)
  1197. xive->max_sbid = bid;
  1198. out:
  1199. mutex_unlock(&kvm->lock);
  1200. return xive->src_blocks[bid];
  1201. }
  1202. static bool xive_check_delayed_irq(struct kvmppc_xive *xive, u32 irq)
  1203. {
  1204. struct kvm *kvm = xive->kvm;
  1205. struct kvm_vcpu *vcpu = NULL;
  1206. int i;
  1207. kvm_for_each_vcpu(i, vcpu, kvm) {
  1208. struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu;
  1209. if (!xc)
  1210. continue;
  1211. if (xc->delayed_irq == irq) {
  1212. xc->delayed_irq = 0;
  1213. xive->delayed_irqs--;
  1214. return true;
  1215. }
  1216. }
  1217. return false;
  1218. }
  1219. static int xive_set_source(struct kvmppc_xive *xive, long irq, u64 addr)
  1220. {
  1221. struct kvmppc_xive_src_block *sb;
  1222. struct kvmppc_xive_irq_state *state;
  1223. u64 __user *ubufp = (u64 __user *) addr;
  1224. u16 idx;
  1225. u64 val;
  1226. u8 act_prio, guest_prio;
  1227. u32 server;
  1228. int rc = 0;
  1229. if (irq < KVMPPC_XICS_FIRST_IRQ || irq >= KVMPPC_XICS_NR_IRQS)
  1230. return -ENOENT;
  1231. pr_devel("set_source(irq=0x%lx)\n", irq);
  1232. /* Find the source */
  1233. sb = kvmppc_xive_find_source(xive, irq, &idx);
  1234. if (!sb) {
  1235. pr_devel("No source, creating source block...\n");
  1236. sb = xive_create_src_block(xive, irq);
  1237. if (!sb) {
  1238. pr_devel("Failed to create block...\n");
  1239. return -ENOMEM;
  1240. }
  1241. }
  1242. state = &sb->irq_state[idx];
  1243. /* Read user passed data */
  1244. if (get_user(val, ubufp)) {
  1245. pr_devel("fault getting user info !\n");
  1246. return -EFAULT;
  1247. }
  1248. server = val & KVM_XICS_DESTINATION_MASK;
  1249. guest_prio = val >> KVM_XICS_PRIORITY_SHIFT;
  1250. pr_devel(" val=0x016%llx (server=0x%x, guest_prio=%d)\n",
  1251. val, server, guest_prio);
  1252. /*
  1253. * If the source doesn't already have an IPI, allocate
  1254. * one and get the corresponding data
  1255. */
  1256. if (!state->ipi_number) {
  1257. state->ipi_number = xive_native_alloc_irq();
  1258. if (state->ipi_number == 0) {
  1259. pr_devel("Failed to allocate IPI !\n");
  1260. return -ENOMEM;
  1261. }
  1262. xive_native_populate_irq_data(state->ipi_number, &state->ipi_data);
  1263. pr_devel(" src_ipi=0x%x\n", state->ipi_number);
  1264. }
  1265. /*
  1266. * We use lock_and_mask() to set us in the right masked
  1267. * state. We will override that state from the saved state
  1268. * further down, but this will handle the cases of interrupts
  1269. * that need FW masking. We set the initial guest_priority to
  1270. * 0 before calling it to ensure it actually performs the masking.
  1271. */
  1272. state->guest_priority = 0;
  1273. xive_lock_and_mask(xive, sb, state);
  1274. /*
  1275. * Now, we select a target if we have one. If we don't we
  1276. * leave the interrupt untargetted. It means that an interrupt
  1277. * can become "untargetted" accross migration if it was masked
  1278. * by set_xive() but there is little we can do about it.
  1279. */
  1280. /* First convert prio and mark interrupt as untargetted */
  1281. act_prio = xive_prio_from_guest(guest_prio);
  1282. state->act_priority = MASKED;
  1283. state->guest_server = server;
  1284. /*
  1285. * We need to drop the lock due to the mutex below. Hopefully
  1286. * nothing is touching that interrupt yet since it hasn't been
  1287. * advertized to a running guest yet
  1288. */
  1289. arch_spin_unlock(&sb->lock);
  1290. /* If we have a priority target the interrupt */
  1291. if (act_prio != MASKED) {
  1292. /* First, check provisioning of queues */
  1293. mutex_lock(&xive->kvm->lock);
  1294. rc = xive_check_provisioning(xive->kvm, act_prio);
  1295. mutex_unlock(&xive->kvm->lock);
  1296. /* Target interrupt */
  1297. if (rc == 0)
  1298. rc = xive_target_interrupt(xive->kvm, state,
  1299. server, act_prio);
  1300. /*
  1301. * If provisioning or targetting failed, leave it
  1302. * alone and masked. It will remain disabled until
  1303. * the guest re-targets it.
  1304. */
  1305. }
  1306. /*
  1307. * Find out if this was a delayed irq stashed in an ICP,
  1308. * in which case, treat it as pending
  1309. */
  1310. if (xive->delayed_irqs && xive_check_delayed_irq(xive, irq)) {
  1311. val |= KVM_XICS_PENDING;
  1312. pr_devel(" Found delayed ! forcing PENDING !\n");
  1313. }
  1314. /* Cleanup the SW state */
  1315. state->old_p = false;
  1316. state->old_q = false;
  1317. state->lsi = false;
  1318. state->asserted = false;
  1319. /* Restore LSI state */
  1320. if (val & KVM_XICS_LEVEL_SENSITIVE) {
  1321. state->lsi = true;
  1322. if (val & KVM_XICS_PENDING)
  1323. state->asserted = true;
  1324. pr_devel(" LSI ! Asserted=%d\n", state->asserted);
  1325. }
  1326. /*
  1327. * Restore P and Q. If the interrupt was pending, we
  1328. * force both P and Q, which will trigger a resend.
  1329. *
  1330. * That means that a guest that had both an interrupt
  1331. * pending (queued) and Q set will restore with only
  1332. * one instance of that interrupt instead of 2, but that
  1333. * is perfectly fine as coalescing interrupts that haven't
  1334. * been presented yet is always allowed.
  1335. */
  1336. if (val & KVM_XICS_PRESENTED || val & KVM_XICS_PENDING)
  1337. state->old_p = true;
  1338. if (val & KVM_XICS_QUEUED || val & KVM_XICS_PENDING)
  1339. state->old_q = true;
  1340. pr_devel(" P=%d, Q=%d\n", state->old_p, state->old_q);
  1341. /*
  1342. * If the interrupt was unmasked, update guest priority and
  1343. * perform the appropriate state transition and do a
  1344. * re-trigger if necessary.
  1345. */
  1346. if (val & KVM_XICS_MASKED) {
  1347. pr_devel(" masked, saving prio\n");
  1348. state->guest_priority = MASKED;
  1349. state->saved_priority = guest_prio;
  1350. } else {
  1351. pr_devel(" unmasked, restoring to prio %d\n", guest_prio);
  1352. xive_finish_unmask(xive, sb, state, guest_prio);
  1353. state->saved_priority = guest_prio;
  1354. }
  1355. /* Increment the number of valid sources and mark this one valid */
  1356. if (!state->valid)
  1357. xive->src_count++;
  1358. state->valid = true;
  1359. return 0;
  1360. }
  1361. int kvmppc_xive_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level,
  1362. bool line_status)
  1363. {
  1364. struct kvmppc_xive *xive = kvm->arch.xive;
  1365. struct kvmppc_xive_src_block *sb;
  1366. struct kvmppc_xive_irq_state *state;
  1367. u16 idx;
  1368. if (!xive)
  1369. return -ENODEV;
  1370. sb = kvmppc_xive_find_source(xive, irq, &idx);
  1371. if (!sb)
  1372. return -EINVAL;
  1373. /* Perform locklessly .... (we need to do some RCUisms here...) */
  1374. state = &sb->irq_state[idx];
  1375. if (!state->valid)
  1376. return -EINVAL;
  1377. /* We don't allow a trigger on a passed-through interrupt */
  1378. if (state->pt_number)
  1379. return -EINVAL;
  1380. if ((level == 1 && state->lsi) || level == KVM_INTERRUPT_SET_LEVEL)
  1381. state->asserted = 1;
  1382. else if (level == 0 || level == KVM_INTERRUPT_UNSET) {
  1383. state->asserted = 0;
  1384. return 0;
  1385. }
  1386. /* Trigger the IPI */
  1387. xive_irq_trigger(&state->ipi_data);
  1388. return 0;
  1389. }
  1390. static int xive_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr)
  1391. {
  1392. struct kvmppc_xive *xive = dev->private;
  1393. /* We honor the existing XICS ioctl */
  1394. switch (attr->group) {
  1395. case KVM_DEV_XICS_GRP_SOURCES:
  1396. return xive_set_source(xive, attr->attr, attr->addr);
  1397. }
  1398. return -ENXIO;
  1399. }
  1400. static int xive_get_attr(struct kvm_device *dev, struct kvm_device_attr *attr)
  1401. {
  1402. struct kvmppc_xive *xive = dev->private;
  1403. /* We honor the existing XICS ioctl */
  1404. switch (attr->group) {
  1405. case KVM_DEV_XICS_GRP_SOURCES:
  1406. return xive_get_source(xive, attr->attr, attr->addr);
  1407. }
  1408. return -ENXIO;
  1409. }
  1410. static int xive_has_attr(struct kvm_device *dev, struct kvm_device_attr *attr)
  1411. {
  1412. /* We honor the same limits as XICS, at least for now */
  1413. switch (attr->group) {
  1414. case KVM_DEV_XICS_GRP_SOURCES:
  1415. if (attr->attr >= KVMPPC_XICS_FIRST_IRQ &&
  1416. attr->attr < KVMPPC_XICS_NR_IRQS)
  1417. return 0;
  1418. break;
  1419. }
  1420. return -ENXIO;
  1421. }
  1422. static void kvmppc_xive_cleanup_irq(u32 hw_num, struct xive_irq_data *xd)
  1423. {
  1424. xive_vm_esb_load(xd, XIVE_ESB_SET_PQ_01);
  1425. xive_native_configure_irq(hw_num, 0, MASKED, 0);
  1426. xive_cleanup_irq_data(xd);
  1427. }
  1428. static void kvmppc_xive_free_sources(struct kvmppc_xive_src_block *sb)
  1429. {
  1430. int i;
  1431. for (i = 0; i < KVMPPC_XICS_IRQ_PER_ICS; i++) {
  1432. struct kvmppc_xive_irq_state *state = &sb->irq_state[i];
  1433. if (!state->valid)
  1434. continue;
  1435. kvmppc_xive_cleanup_irq(state->ipi_number, &state->ipi_data);
  1436. xive_native_free_irq(state->ipi_number);
  1437. /* Pass-through, cleanup too */
  1438. if (state->pt_number)
  1439. kvmppc_xive_cleanup_irq(state->pt_number, state->pt_data);
  1440. state->valid = false;
  1441. }
  1442. }
  1443. static void kvmppc_xive_free(struct kvm_device *dev)
  1444. {
  1445. struct kvmppc_xive *xive = dev->private;
  1446. struct kvm *kvm = xive->kvm;
  1447. int i;
  1448. debugfs_remove(xive->dentry);
  1449. if (kvm)
  1450. kvm->arch.xive = NULL;
  1451. /* Mask and free interrupts */
  1452. for (i = 0; i <= xive->max_sbid; i++) {
  1453. if (xive->src_blocks[i])
  1454. kvmppc_xive_free_sources(xive->src_blocks[i]);
  1455. kfree(xive->src_blocks[i]);
  1456. xive->src_blocks[i] = NULL;
  1457. }
  1458. if (xive->vp_base != XIVE_INVALID_VP)
  1459. xive_native_free_vp_block(xive->vp_base);
  1460. kfree(xive);
  1461. kfree(dev);
  1462. }
  1463. static int kvmppc_xive_create(struct kvm_device *dev, u32 type)
  1464. {
  1465. struct kvmppc_xive *xive;
  1466. struct kvm *kvm = dev->kvm;
  1467. int ret = 0;
  1468. pr_devel("Creating xive for partition\n");
  1469. xive = kzalloc(sizeof(*xive), GFP_KERNEL);
  1470. if (!xive)
  1471. return -ENOMEM;
  1472. dev->private = xive;
  1473. xive->dev = dev;
  1474. xive->kvm = kvm;
  1475. /* Already there ? */
  1476. if (kvm->arch.xive)
  1477. ret = -EEXIST;
  1478. else
  1479. kvm->arch.xive = xive;
  1480. /* We use the default queue size set by the host */
  1481. xive->q_order = xive_native_default_eq_shift();
  1482. if (xive->q_order < PAGE_SHIFT)
  1483. xive->q_page_order = 0;
  1484. else
  1485. xive->q_page_order = xive->q_order - PAGE_SHIFT;
  1486. /* Allocate a bunch of VPs */
  1487. xive->vp_base = xive_native_alloc_vp_block(KVM_MAX_VCPUS);
  1488. pr_devel("VP_Base=%x\n", xive->vp_base);
  1489. if (xive->vp_base == XIVE_INVALID_VP)
  1490. ret = -ENOMEM;
  1491. if (ret) {
  1492. kfree(xive);
  1493. return ret;
  1494. }
  1495. return 0;
  1496. }
  1497. static int xive_debug_show(struct seq_file *m, void *private)
  1498. {
  1499. struct kvmppc_xive *xive = m->private;
  1500. struct kvm *kvm = xive->kvm;
  1501. struct kvm_vcpu *vcpu;
  1502. u64 t_rm_h_xirr = 0;
  1503. u64 t_rm_h_ipoll = 0;
  1504. u64 t_rm_h_cppr = 0;
  1505. u64 t_rm_h_eoi = 0;
  1506. u64 t_rm_h_ipi = 0;
  1507. u64 t_vm_h_xirr = 0;
  1508. u64 t_vm_h_ipoll = 0;
  1509. u64 t_vm_h_cppr = 0;
  1510. u64 t_vm_h_eoi = 0;
  1511. u64 t_vm_h_ipi = 0;
  1512. unsigned int i;
  1513. if (!kvm)
  1514. return 0;
  1515. seq_printf(m, "=========\nVCPU state\n=========\n");
  1516. kvm_for_each_vcpu(i, vcpu, kvm) {
  1517. struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu;
  1518. if (!xc)
  1519. continue;
  1520. seq_printf(m, "cpu server %#x CPPR:%#x HWCPPR:%#x"
  1521. " MFRR:%#x PEND:%#x h_xirr: R=%lld V=%lld\n",
  1522. xc->server_num, xc->cppr, xc->hw_cppr,
  1523. xc->mfrr, xc->pending,
  1524. xc->stat_rm_h_xirr, xc->stat_vm_h_xirr);
  1525. t_rm_h_xirr += xc->stat_rm_h_xirr;
  1526. t_rm_h_ipoll += xc->stat_rm_h_ipoll;
  1527. t_rm_h_cppr += xc->stat_rm_h_cppr;
  1528. t_rm_h_eoi += xc->stat_rm_h_eoi;
  1529. t_rm_h_ipi += xc->stat_rm_h_ipi;
  1530. t_vm_h_xirr += xc->stat_vm_h_xirr;
  1531. t_vm_h_ipoll += xc->stat_vm_h_ipoll;
  1532. t_vm_h_cppr += xc->stat_vm_h_cppr;
  1533. t_vm_h_eoi += xc->stat_vm_h_eoi;
  1534. t_vm_h_ipi += xc->stat_vm_h_ipi;
  1535. }
  1536. seq_printf(m, "Hcalls totals\n");
  1537. seq_printf(m, " H_XIRR R=%10lld V=%10lld\n", t_rm_h_xirr, t_vm_h_xirr);
  1538. seq_printf(m, " H_IPOLL R=%10lld V=%10lld\n", t_rm_h_ipoll, t_vm_h_ipoll);
  1539. seq_printf(m, " H_CPPR R=%10lld V=%10lld\n", t_rm_h_cppr, t_vm_h_cppr);
  1540. seq_printf(m, " H_EOI R=%10lld V=%10lld\n", t_rm_h_eoi, t_vm_h_eoi);
  1541. seq_printf(m, " H_IPI R=%10lld V=%10lld\n", t_rm_h_ipi, t_vm_h_ipi);
  1542. return 0;
  1543. }
  1544. static int xive_debug_open(struct inode *inode, struct file *file)
  1545. {
  1546. return single_open(file, xive_debug_show, inode->i_private);
  1547. }
  1548. static const struct file_operations xive_debug_fops = {
  1549. .open = xive_debug_open,
  1550. .read = seq_read,
  1551. .llseek = seq_lseek,
  1552. .release = single_release,
  1553. };
  1554. static void xive_debugfs_init(struct kvmppc_xive *xive)
  1555. {
  1556. char *name;
  1557. name = kasprintf(GFP_KERNEL, "kvm-xive-%p", xive);
  1558. if (!name) {
  1559. pr_err("%s: no memory for name\n", __func__);
  1560. return;
  1561. }
  1562. xive->dentry = debugfs_create_file(name, S_IRUGO, powerpc_debugfs_root,
  1563. xive, &xive_debug_fops);
  1564. pr_debug("%s: created %s\n", __func__, name);
  1565. kfree(name);
  1566. }
  1567. static void kvmppc_xive_init(struct kvm_device *dev)
  1568. {
  1569. struct kvmppc_xive *xive = (struct kvmppc_xive *)dev->private;
  1570. /* Register some debug interfaces */
  1571. xive_debugfs_init(xive);
  1572. }
  1573. struct kvm_device_ops kvm_xive_ops = {
  1574. .name = "kvm-xive",
  1575. .create = kvmppc_xive_create,
  1576. .init = kvmppc_xive_init,
  1577. .destroy = kvmppc_xive_free,
  1578. .set_attr = xive_set_attr,
  1579. .get_attr = xive_get_attr,
  1580. .has_attr = xive_has_attr,
  1581. };
  1582. void kvmppc_xive_init_module(void)
  1583. {
  1584. __xive_vm_h_xirr = xive_vm_h_xirr;
  1585. __xive_vm_h_ipoll = xive_vm_h_ipoll;
  1586. __xive_vm_h_ipi = xive_vm_h_ipi;
  1587. __xive_vm_h_cppr = xive_vm_h_cppr;
  1588. __xive_vm_h_eoi = xive_vm_h_eoi;
  1589. }
  1590. void kvmppc_xive_exit_module(void)
  1591. {
  1592. __xive_vm_h_xirr = NULL;
  1593. __xive_vm_h_ipoll = NULL;
  1594. __xive_vm_h_ipi = NULL;
  1595. __xive_vm_h_cppr = NULL;
  1596. __xive_vm_h_eoi = NULL;
  1597. }