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