Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arm/arm64: KVM: make the value of ICC_SRE_EL1 a per-VM variable

ICC_SRE_EL1 is a system register allowing msr/mrs accesses to the
GIC CPU interface for EL1 (guests). Currently we force it to 0, but
for proper GICv3 support we have to allow guests to use it (depending
on their selected virtual GIC model).
So add ICC_SRE_EL1 to the list of saved/restored registers on a
world switch, but actually disallow a guest to change it by only
restoring a fixed, once-initialized value.
This value depends on the GIC model userland has chosen for a guest.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>

authored by

Andre Przywara and committed by
Christoffer Dall
2f5fa41a 3caa2d8c

+17 -7
+1
arch/arm64/kernel/asm-offsets.c
··· 140 140 DEFINE(VGIC_V2_CPU_ELRSR, offsetof(struct vgic_cpu, vgic_v2.vgic_elrsr)); 141 141 DEFINE(VGIC_V2_CPU_APR, offsetof(struct vgic_cpu, vgic_v2.vgic_apr)); 142 142 DEFINE(VGIC_V2_CPU_LR, offsetof(struct vgic_cpu, vgic_v2.vgic_lr)); 143 + DEFINE(VGIC_V3_CPU_SRE, offsetof(struct vgic_cpu, vgic_v3.vgic_sre)); 143 144 DEFINE(VGIC_V3_CPU_HCR, offsetof(struct vgic_cpu, vgic_v3.vgic_hcr)); 144 145 DEFINE(VGIC_V3_CPU_VMCR, offsetof(struct vgic_cpu, vgic_v3.vgic_vmcr)); 145 146 DEFINE(VGIC_V3_CPU_MISR, offsetof(struct vgic_cpu, vgic_v3.vgic_misr));
+9 -5
arch/arm64/kvm/vgic-v3-switch.S
··· 148 148 * x0: Register pointing to VCPU struct 149 149 */ 150 150 .macro restore_vgic_v3_state 151 - // Disable SRE_EL1 access. Necessary, otherwise 152 - // ICH_VMCR_EL2.VFIQEn becomes one, and FIQ happens... 153 - msr_s ICC_SRE_EL1, xzr 154 - isb 155 - 156 151 // Compute the address of struct vgic_cpu 157 152 add x3, x0, #VCPU_VGIC_CPU 158 153 159 154 // Restore all interesting registers 160 155 ldr w4, [x3, #VGIC_V3_CPU_HCR] 161 156 ldr w5, [x3, #VGIC_V3_CPU_VMCR] 157 + ldr w25, [x3, #VGIC_V3_CPU_SRE] 158 + 159 + msr_s ICC_SRE_EL1, x25 160 + 161 + // make sure SRE is valid before writing the other registers 162 + isb 162 163 163 164 msr_s ICH_HCR_EL2, x4 164 165 msr_s ICH_VMCR_EL2, x5 ··· 245 244 dsb sy 246 245 247 246 // Prevent the guest from touching the GIC system registers 247 + // if SRE isn't enabled for GICv3 emulation 248 + cbnz x25, 1f 248 249 mrs_s x5, ICC_SRE_EL2 249 250 and x5, x5, #~ICC_SRE_EL2_ENABLE 250 251 msr_s ICC_SRE_EL2, x5 252 + 1: 251 253 .endm 252 254 253 255 ENTRY(__save_vgic_v3_state)
+1
include/kvm/arm_vgic.h
··· 245 245 #ifdef CONFIG_ARM_GIC_V3 246 246 u32 vgic_hcr; 247 247 u32 vgic_vmcr; 248 + u32 vgic_sre; /* Restored only, change ignored */ 248 249 u32 vgic_misr; /* Saved only */ 249 250 u32 vgic_eisr; /* Saved only */ 250 251 u32 vgic_elrsr; /* Saved only */
+6 -2
virt/kvm/arm/vgic-v3.c
··· 145 145 146 146 static void vgic_v3_enable(struct kvm_vcpu *vcpu) 147 147 { 148 + struct vgic_v3_cpu_if *vgic_v3 = &vcpu->arch.vgic_cpu.vgic_v3; 149 + 148 150 /* 149 151 * By forcing VMCR to zero, the GIC will restore the binary 150 152 * points to their reset values. Anything else resets to zero 151 153 * anyway. 152 154 */ 153 - vcpu->arch.vgic_cpu.vgic_v3.vgic_vmcr = 0; 155 + vgic_v3->vgic_vmcr = 0; 156 + 157 + vgic_v3->vgic_sre = 0; 154 158 155 159 /* Get the show on the road... */ 156 - vcpu->arch.vgic_cpu.vgic_v3.vgic_hcr = ICH_HCR_EN; 160 + vgic_v3->vgic_hcr = ICH_HCR_EN; 157 161 } 158 162 159 163 static const struct vgic_ops vgic_v3_ops = {