]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - virt/kvm/arm/vgic/vgic-v3.c
Merge tag 'mac80211-next-for-davem-2018-03-29' of git://git.kernel.org/pub/scm/linux...
[mirror_ubuntu-eoan-kernel.git] / virt / kvm / arm / vgic / vgic-v3.c
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program. If not, see <http://www.gnu.org/licenses/>.
13 */
14
15 #include <linux/irqchip/arm-gic-v3.h>
16 #include <linux/kvm.h>
17 #include <linux/kvm_host.h>
18 #include <kvm/arm_vgic.h>
19 #include <asm/kvm_mmu.h>
20 #include <asm/kvm_asm.h>
21
22 #include "vgic.h"
23
24 static bool group0_trap;
25 static bool group1_trap;
26 static bool common_trap;
27 static bool gicv4_enable;
28
29 void vgic_v3_set_npie(struct kvm_vcpu *vcpu)
30 {
31 struct vgic_v3_cpu_if *cpuif = &vcpu->arch.vgic_cpu.vgic_v3;
32
33 cpuif->vgic_hcr |= ICH_HCR_NPIE;
34 }
35
36 void vgic_v3_set_underflow(struct kvm_vcpu *vcpu)
37 {
38 struct vgic_v3_cpu_if *cpuif = &vcpu->arch.vgic_cpu.vgic_v3;
39
40 cpuif->vgic_hcr |= ICH_HCR_UIE;
41 }
42
43 static bool lr_signals_eoi_mi(u64 lr_val)
44 {
45 return !(lr_val & ICH_LR_STATE) && (lr_val & ICH_LR_EOI) &&
46 !(lr_val & ICH_LR_HW);
47 }
48
49 void vgic_v3_fold_lr_state(struct kvm_vcpu *vcpu)
50 {
51 struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
52 struct vgic_v3_cpu_if *cpuif = &vgic_cpu->vgic_v3;
53 u32 model = vcpu->kvm->arch.vgic.vgic_model;
54 int lr;
55 unsigned long flags;
56
57 cpuif->vgic_hcr &= ~(ICH_HCR_UIE | ICH_HCR_NPIE);
58
59 for (lr = 0; lr < vgic_cpu->used_lrs; lr++) {
60 u64 val = cpuif->vgic_lr[lr];
61 u32 intid;
62 struct vgic_irq *irq;
63
64 if (model == KVM_DEV_TYPE_ARM_VGIC_V3)
65 intid = val & ICH_LR_VIRTUAL_ID_MASK;
66 else
67 intid = val & GICH_LR_VIRTUALID;
68
69 /* Notify fds when the guest EOI'ed a level-triggered IRQ */
70 if (lr_signals_eoi_mi(val) && vgic_valid_spi(vcpu->kvm, intid))
71 kvm_notify_acked_irq(vcpu->kvm, 0,
72 intid - VGIC_NR_PRIVATE_IRQS);
73
74 irq = vgic_get_irq(vcpu->kvm, vcpu, intid);
75 if (!irq) /* An LPI could have been unmapped. */
76 continue;
77
78 spin_lock_irqsave(&irq->irq_lock, flags);
79
80 /* Always preserve the active bit */
81 irq->active = !!(val & ICH_LR_ACTIVE_BIT);
82
83 /* Edge is the only case where we preserve the pending bit */
84 if (irq->config == VGIC_CONFIG_EDGE &&
85 (val & ICH_LR_PENDING_BIT)) {
86 irq->pending_latch = true;
87
88 if (vgic_irq_is_sgi(intid) &&
89 model == KVM_DEV_TYPE_ARM_VGIC_V2) {
90 u32 cpuid = val & GICH_LR_PHYSID_CPUID;
91
92 cpuid >>= GICH_LR_PHYSID_CPUID_SHIFT;
93 irq->source |= (1 << cpuid);
94 }
95 }
96
97 /*
98 * Clear soft pending state when level irqs have been acked.
99 * Always regenerate the pending state.
100 */
101 if (irq->config == VGIC_CONFIG_LEVEL) {
102 if (!(val & ICH_LR_PENDING_BIT))
103 irq->pending_latch = false;
104 }
105
106 /*
107 * Level-triggered mapped IRQs are special because we only
108 * observe rising edges as input to the VGIC.
109 *
110 * If the guest never acked the interrupt we have to sample
111 * the physical line and set the line level, because the
112 * device state could have changed or we simply need to
113 * process the still pending interrupt later.
114 *
115 * If this causes us to lower the level, we have to also clear
116 * the physical active state, since we will otherwise never be
117 * told when the interrupt becomes asserted again.
118 */
119 if (vgic_irq_is_mapped_level(irq) && (val & ICH_LR_PENDING_BIT)) {
120 irq->line_level = vgic_get_phys_line_level(irq);
121
122 if (!irq->line_level)
123 vgic_irq_set_phys_active(irq, false);
124 }
125
126 spin_unlock_irqrestore(&irq->irq_lock, flags);
127 vgic_put_irq(vcpu->kvm, irq);
128 }
129
130 vgic_cpu->used_lrs = 0;
131 }
132
133 /* Requires the irq to be locked already */
134 void vgic_v3_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr)
135 {
136 u32 model = vcpu->kvm->arch.vgic.vgic_model;
137 u64 val = irq->intid;
138
139 if (irq_is_pending(irq)) {
140 val |= ICH_LR_PENDING_BIT;
141
142 if (irq->config == VGIC_CONFIG_EDGE)
143 irq->pending_latch = false;
144
145 if (vgic_irq_is_sgi(irq->intid) &&
146 model == KVM_DEV_TYPE_ARM_VGIC_V2) {
147 u32 src = ffs(irq->source);
148
149 BUG_ON(!src);
150 val |= (src - 1) << GICH_LR_PHYSID_CPUID_SHIFT;
151 irq->source &= ~(1 << (src - 1));
152 if (irq->source)
153 irq->pending_latch = true;
154 }
155 }
156
157 if (irq->active)
158 val |= ICH_LR_ACTIVE_BIT;
159
160 if (irq->hw) {
161 val |= ICH_LR_HW;
162 val |= ((u64)irq->hwintid) << ICH_LR_PHYS_ID_SHIFT;
163 /*
164 * Never set pending+active on a HW interrupt, as the
165 * pending state is kept at the physical distributor
166 * level.
167 */
168 if (irq->active && irq_is_pending(irq))
169 val &= ~ICH_LR_PENDING_BIT;
170 } else {
171 if (irq->config == VGIC_CONFIG_LEVEL)
172 val |= ICH_LR_EOI;
173 }
174
175 /*
176 * Level-triggered mapped IRQs are special because we only observe
177 * rising edges as input to the VGIC. We therefore lower the line
178 * level here, so that we can take new virtual IRQs. See
179 * vgic_v3_fold_lr_state for more info.
180 */
181 if (vgic_irq_is_mapped_level(irq) && (val & ICH_LR_PENDING_BIT))
182 irq->line_level = false;
183
184 /*
185 * We currently only support Group1 interrupts, which is a
186 * known defect. This needs to be addressed at some point.
187 */
188 if (model == KVM_DEV_TYPE_ARM_VGIC_V3)
189 val |= ICH_LR_GROUP;
190
191 val |= (u64)irq->priority << ICH_LR_PRIORITY_SHIFT;
192
193 vcpu->arch.vgic_cpu.vgic_v3.vgic_lr[lr] = val;
194 }
195
196 void vgic_v3_clear_lr(struct kvm_vcpu *vcpu, int lr)
197 {
198 vcpu->arch.vgic_cpu.vgic_v3.vgic_lr[lr] = 0;
199 }
200
201 void vgic_v3_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcrp)
202 {
203 struct vgic_v3_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v3;
204 u32 model = vcpu->kvm->arch.vgic.vgic_model;
205 u32 vmcr;
206
207 if (model == KVM_DEV_TYPE_ARM_VGIC_V2) {
208 vmcr = (vmcrp->ackctl << ICH_VMCR_ACK_CTL_SHIFT) &
209 ICH_VMCR_ACK_CTL_MASK;
210 vmcr |= (vmcrp->fiqen << ICH_VMCR_FIQ_EN_SHIFT) &
211 ICH_VMCR_FIQ_EN_MASK;
212 } else {
213 /*
214 * When emulating GICv3 on GICv3 with SRE=1 on the
215 * VFIQEn bit is RES1 and the VAckCtl bit is RES0.
216 */
217 vmcr = ICH_VMCR_FIQ_EN_MASK;
218 }
219
220 vmcr |= (vmcrp->cbpr << ICH_VMCR_CBPR_SHIFT) & ICH_VMCR_CBPR_MASK;
221 vmcr |= (vmcrp->eoim << ICH_VMCR_EOIM_SHIFT) & ICH_VMCR_EOIM_MASK;
222 vmcr |= (vmcrp->abpr << ICH_VMCR_BPR1_SHIFT) & ICH_VMCR_BPR1_MASK;
223 vmcr |= (vmcrp->bpr << ICH_VMCR_BPR0_SHIFT) & ICH_VMCR_BPR0_MASK;
224 vmcr |= (vmcrp->pmr << ICH_VMCR_PMR_SHIFT) & ICH_VMCR_PMR_MASK;
225 vmcr |= (vmcrp->grpen0 << ICH_VMCR_ENG0_SHIFT) & ICH_VMCR_ENG0_MASK;
226 vmcr |= (vmcrp->grpen1 << ICH_VMCR_ENG1_SHIFT) & ICH_VMCR_ENG1_MASK;
227
228 cpu_if->vgic_vmcr = vmcr;
229 }
230
231 void vgic_v3_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcrp)
232 {
233 struct vgic_v3_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v3;
234 u32 model = vcpu->kvm->arch.vgic.vgic_model;
235 u32 vmcr;
236
237 vmcr = cpu_if->vgic_vmcr;
238
239 if (model == KVM_DEV_TYPE_ARM_VGIC_V2) {
240 vmcrp->ackctl = (vmcr & ICH_VMCR_ACK_CTL_MASK) >>
241 ICH_VMCR_ACK_CTL_SHIFT;
242 vmcrp->fiqen = (vmcr & ICH_VMCR_FIQ_EN_MASK) >>
243 ICH_VMCR_FIQ_EN_SHIFT;
244 } else {
245 /*
246 * When emulating GICv3 on GICv3 with SRE=1 on the
247 * VFIQEn bit is RES1 and the VAckCtl bit is RES0.
248 */
249 vmcrp->fiqen = 1;
250 vmcrp->ackctl = 0;
251 }
252
253 vmcrp->cbpr = (vmcr & ICH_VMCR_CBPR_MASK) >> ICH_VMCR_CBPR_SHIFT;
254 vmcrp->eoim = (vmcr & ICH_VMCR_EOIM_MASK) >> ICH_VMCR_EOIM_SHIFT;
255 vmcrp->abpr = (vmcr & ICH_VMCR_BPR1_MASK) >> ICH_VMCR_BPR1_SHIFT;
256 vmcrp->bpr = (vmcr & ICH_VMCR_BPR0_MASK) >> ICH_VMCR_BPR0_SHIFT;
257 vmcrp->pmr = (vmcr & ICH_VMCR_PMR_MASK) >> ICH_VMCR_PMR_SHIFT;
258 vmcrp->grpen0 = (vmcr & ICH_VMCR_ENG0_MASK) >> ICH_VMCR_ENG0_SHIFT;
259 vmcrp->grpen1 = (vmcr & ICH_VMCR_ENG1_MASK) >> ICH_VMCR_ENG1_SHIFT;
260 }
261
262 #define INITIAL_PENDBASER_VALUE \
263 (GIC_BASER_CACHEABILITY(GICR_PENDBASER, INNER, RaWb) | \
264 GIC_BASER_CACHEABILITY(GICR_PENDBASER, OUTER, SameAsInner) | \
265 GIC_BASER_SHAREABILITY(GICR_PENDBASER, InnerShareable))
266
267 void vgic_v3_enable(struct kvm_vcpu *vcpu)
268 {
269 struct vgic_v3_cpu_if *vgic_v3 = &vcpu->arch.vgic_cpu.vgic_v3;
270
271 /*
272 * By forcing VMCR to zero, the GIC will restore the binary
273 * points to their reset values. Anything else resets to zero
274 * anyway.
275 */
276 vgic_v3->vgic_vmcr = 0;
277 vgic_v3->vgic_elrsr = ~0;
278
279 /*
280 * If we are emulating a GICv3, we do it in an non-GICv2-compatible
281 * way, so we force SRE to 1 to demonstrate this to the guest.
282 * Also, we don't support any form of IRQ/FIQ bypass.
283 * This goes with the spec allowing the value to be RAO/WI.
284 */
285 if (vcpu->kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3) {
286 vgic_v3->vgic_sre = (ICC_SRE_EL1_DIB |
287 ICC_SRE_EL1_DFB |
288 ICC_SRE_EL1_SRE);
289 vcpu->arch.vgic_cpu.pendbaser = INITIAL_PENDBASER_VALUE;
290 } else {
291 vgic_v3->vgic_sre = 0;
292 }
293
294 vcpu->arch.vgic_cpu.num_id_bits = (kvm_vgic_global_state.ich_vtr_el2 &
295 ICH_VTR_ID_BITS_MASK) >>
296 ICH_VTR_ID_BITS_SHIFT;
297 vcpu->arch.vgic_cpu.num_pri_bits = ((kvm_vgic_global_state.ich_vtr_el2 &
298 ICH_VTR_PRI_BITS_MASK) >>
299 ICH_VTR_PRI_BITS_SHIFT) + 1;
300
301 /* Get the show on the road... */
302 vgic_v3->vgic_hcr = ICH_HCR_EN;
303 if (group0_trap)
304 vgic_v3->vgic_hcr |= ICH_HCR_TALL0;
305 if (group1_trap)
306 vgic_v3->vgic_hcr |= ICH_HCR_TALL1;
307 if (common_trap)
308 vgic_v3->vgic_hcr |= ICH_HCR_TC;
309 }
310
311 int vgic_v3_lpi_sync_pending_status(struct kvm *kvm, struct vgic_irq *irq)
312 {
313 struct kvm_vcpu *vcpu;
314 int byte_offset, bit_nr;
315 gpa_t pendbase, ptr;
316 bool status;
317 u8 val;
318 int ret;
319 unsigned long flags;
320
321 retry:
322 vcpu = irq->target_vcpu;
323 if (!vcpu)
324 return 0;
325
326 pendbase = GICR_PENDBASER_ADDRESS(vcpu->arch.vgic_cpu.pendbaser);
327
328 byte_offset = irq->intid / BITS_PER_BYTE;
329 bit_nr = irq->intid % BITS_PER_BYTE;
330 ptr = pendbase + byte_offset;
331
332 ret = kvm_read_guest(kvm, ptr, &val, 1);
333 if (ret)
334 return ret;
335
336 status = val & (1 << bit_nr);
337
338 spin_lock_irqsave(&irq->irq_lock, flags);
339 if (irq->target_vcpu != vcpu) {
340 spin_unlock_irqrestore(&irq->irq_lock, flags);
341 goto retry;
342 }
343 irq->pending_latch = status;
344 vgic_queue_irq_unlock(vcpu->kvm, irq, flags);
345
346 if (status) {
347 /* clear consumed data */
348 val &= ~(1 << bit_nr);
349 ret = kvm_write_guest(kvm, ptr, &val, 1);
350 if (ret)
351 return ret;
352 }
353 return 0;
354 }
355
356 /**
357 * vgic_its_save_pending_tables - Save the pending tables into guest RAM
358 * kvm lock and all vcpu lock must be held
359 */
360 int vgic_v3_save_pending_tables(struct kvm *kvm)
361 {
362 struct vgic_dist *dist = &kvm->arch.vgic;
363 int last_byte_offset = -1;
364 struct vgic_irq *irq;
365 int ret;
366 u8 val;
367
368 list_for_each_entry(irq, &dist->lpi_list_head, lpi_list) {
369 int byte_offset, bit_nr;
370 struct kvm_vcpu *vcpu;
371 gpa_t pendbase, ptr;
372 bool stored;
373
374 vcpu = irq->target_vcpu;
375 if (!vcpu)
376 continue;
377
378 pendbase = GICR_PENDBASER_ADDRESS(vcpu->arch.vgic_cpu.pendbaser);
379
380 byte_offset = irq->intid / BITS_PER_BYTE;
381 bit_nr = irq->intid % BITS_PER_BYTE;
382 ptr = pendbase + byte_offset;
383
384 if (byte_offset != last_byte_offset) {
385 ret = kvm_read_guest(kvm, ptr, &val, 1);
386 if (ret)
387 return ret;
388 last_byte_offset = byte_offset;
389 }
390
391 stored = val & (1U << bit_nr);
392 if (stored == irq->pending_latch)
393 continue;
394
395 if (irq->pending_latch)
396 val |= 1 << bit_nr;
397 else
398 val &= ~(1 << bit_nr);
399
400 ret = kvm_write_guest(kvm, ptr, &val, 1);
401 if (ret)
402 return ret;
403 }
404 return 0;
405 }
406
407 /*
408 * Check for overlapping regions and for regions crossing the end of memory
409 * for base addresses which have already been set.
410 */
411 bool vgic_v3_check_base(struct kvm *kvm)
412 {
413 struct vgic_dist *d = &kvm->arch.vgic;
414 gpa_t redist_size = KVM_VGIC_V3_REDIST_SIZE;
415
416 redist_size *= atomic_read(&kvm->online_vcpus);
417
418 if (!IS_VGIC_ADDR_UNDEF(d->vgic_dist_base) &&
419 d->vgic_dist_base + KVM_VGIC_V3_DIST_SIZE < d->vgic_dist_base)
420 return false;
421
422 if (!IS_VGIC_ADDR_UNDEF(d->vgic_redist_base) &&
423 d->vgic_redist_base + redist_size < d->vgic_redist_base)
424 return false;
425
426 /* Both base addresses must be set to check if they overlap */
427 if (IS_VGIC_ADDR_UNDEF(d->vgic_dist_base) ||
428 IS_VGIC_ADDR_UNDEF(d->vgic_redist_base))
429 return true;
430
431 if (d->vgic_dist_base + KVM_VGIC_V3_DIST_SIZE <= d->vgic_redist_base)
432 return true;
433 if (d->vgic_redist_base + redist_size <= d->vgic_dist_base)
434 return true;
435
436 return false;
437 }
438
439 int vgic_v3_map_resources(struct kvm *kvm)
440 {
441 int ret = 0;
442 struct vgic_dist *dist = &kvm->arch.vgic;
443
444 if (vgic_ready(kvm))
445 goto out;
446
447 if (IS_VGIC_ADDR_UNDEF(dist->vgic_dist_base) ||
448 IS_VGIC_ADDR_UNDEF(dist->vgic_redist_base)) {
449 kvm_err("Need to set vgic distributor addresses first\n");
450 ret = -ENXIO;
451 goto out;
452 }
453
454 if (!vgic_v3_check_base(kvm)) {
455 kvm_err("VGIC redist and dist frames overlap\n");
456 ret = -EINVAL;
457 goto out;
458 }
459
460 /*
461 * For a VGICv3 we require the userland to explicitly initialize
462 * the VGIC before we need to use it.
463 */
464 if (!vgic_initialized(kvm)) {
465 ret = -EBUSY;
466 goto out;
467 }
468
469 ret = vgic_register_dist_iodev(kvm, dist->vgic_dist_base, VGIC_V3);
470 if (ret) {
471 kvm_err("Unable to register VGICv3 dist MMIO regions\n");
472 goto out;
473 }
474
475 dist->ready = true;
476
477 out:
478 return ret;
479 }
480
481 DEFINE_STATIC_KEY_FALSE(vgic_v3_cpuif_trap);
482
483 static int __init early_group0_trap_cfg(char *buf)
484 {
485 return strtobool(buf, &group0_trap);
486 }
487 early_param("kvm-arm.vgic_v3_group0_trap", early_group0_trap_cfg);
488
489 static int __init early_group1_trap_cfg(char *buf)
490 {
491 return strtobool(buf, &group1_trap);
492 }
493 early_param("kvm-arm.vgic_v3_group1_trap", early_group1_trap_cfg);
494
495 static int __init early_common_trap_cfg(char *buf)
496 {
497 return strtobool(buf, &common_trap);
498 }
499 early_param("kvm-arm.vgic_v3_common_trap", early_common_trap_cfg);
500
501 static int __init early_gicv4_enable(char *buf)
502 {
503 return strtobool(buf, &gicv4_enable);
504 }
505 early_param("kvm-arm.vgic_v4_enable", early_gicv4_enable);
506
507 /**
508 * vgic_v3_probe - probe for a GICv3 compatible interrupt controller in DT
509 * @node: pointer to the DT node
510 *
511 * Returns 0 if a GICv3 has been found, returns an error code otherwise
512 */
513 int vgic_v3_probe(const struct gic_kvm_info *info)
514 {
515 u32 ich_vtr_el2 = kvm_call_hyp(__vgic_v3_get_ich_vtr_el2);
516 int ret;
517
518 /*
519 * The ListRegs field is 5 bits, but there is a architectural
520 * maximum of 16 list registers. Just ignore bit 4...
521 */
522 kvm_vgic_global_state.nr_lr = (ich_vtr_el2 & 0xf) + 1;
523 kvm_vgic_global_state.can_emulate_gicv2 = false;
524 kvm_vgic_global_state.ich_vtr_el2 = ich_vtr_el2;
525
526 /* GICv4 support? */
527 if (info->has_v4) {
528 kvm_vgic_global_state.has_gicv4 = gicv4_enable;
529 kvm_info("GICv4 support %sabled\n",
530 gicv4_enable ? "en" : "dis");
531 }
532
533 if (!info->vcpu.start) {
534 kvm_info("GICv3: no GICV resource entry\n");
535 kvm_vgic_global_state.vcpu_base = 0;
536 } else if (!PAGE_ALIGNED(info->vcpu.start)) {
537 pr_warn("GICV physical address 0x%llx not page aligned\n",
538 (unsigned long long)info->vcpu.start);
539 kvm_vgic_global_state.vcpu_base = 0;
540 } else if (!PAGE_ALIGNED(resource_size(&info->vcpu))) {
541 pr_warn("GICV size 0x%llx not a multiple of page size 0x%lx\n",
542 (unsigned long long)resource_size(&info->vcpu),
543 PAGE_SIZE);
544 kvm_vgic_global_state.vcpu_base = 0;
545 } else {
546 kvm_vgic_global_state.vcpu_base = info->vcpu.start;
547 kvm_vgic_global_state.can_emulate_gicv2 = true;
548 ret = kvm_register_vgic_device(KVM_DEV_TYPE_ARM_VGIC_V2);
549 if (ret) {
550 kvm_err("Cannot register GICv2 KVM device.\n");
551 return ret;
552 }
553 kvm_info("vgic-v2@%llx\n", info->vcpu.start);
554 }
555 ret = kvm_register_vgic_device(KVM_DEV_TYPE_ARM_VGIC_V3);
556 if (ret) {
557 kvm_err("Cannot register GICv3 KVM device.\n");
558 kvm_unregister_device_ops(KVM_DEV_TYPE_ARM_VGIC_V2);
559 return ret;
560 }
561
562 if (kvm_vgic_global_state.vcpu_base == 0)
563 kvm_info("disabling GICv2 emulation\n");
564
565 #ifdef CONFIG_ARM64
566 if (cpus_have_const_cap(ARM64_WORKAROUND_CAVIUM_30115)) {
567 group0_trap = true;
568 group1_trap = true;
569 }
570 #endif
571
572 if (group0_trap || group1_trap || common_trap) {
573 kvm_info("GICv3 sysreg trapping enabled ([%s%s%s], reduced performance)\n",
574 group0_trap ? "G0" : "",
575 group1_trap ? "G1" : "",
576 common_trap ? "C" : "");
577 static_branch_enable(&vgic_v3_cpuif_trap);
578 }
579
580 kvm_vgic_global_state.vctrl_base = NULL;
581 kvm_vgic_global_state.type = VGIC_V3;
582 kvm_vgic_global_state.max_gic_vcpus = VGIC_V3_MAX_CPUS;
583
584 return 0;
585 }
586
587 void vgic_v3_load(struct kvm_vcpu *vcpu)
588 {
589 struct vgic_v3_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v3;
590
591 /*
592 * If dealing with a GICv2 emulation on GICv3, VMCR_EL2.VFIQen
593 * is dependent on ICC_SRE_EL1.SRE, and we have to perform the
594 * VMCR_EL2 save/restore in the world switch.
595 */
596 if (likely(cpu_if->vgic_sre))
597 kvm_call_hyp(__vgic_v3_write_vmcr, cpu_if->vgic_vmcr);
598 }
599
600 void vgic_v3_put(struct kvm_vcpu *vcpu)
601 {
602 struct vgic_v3_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v3;
603
604 if (likely(cpu_if->vgic_sre))
605 cpu_if->vgic_vmcr = kvm_call_hyp(__vgic_v3_read_vmcr);
606 }