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