@@ -140,6 +140,9 @@ static void sync_shadow_el1_state(struct kvm_vcpu *vcpu, bool setup)
void kvm_arm_setup_shadow_state(struct kvm_vcpu *vcpu)
{
struct kvm_cpu_context *ctxt = &vcpu->arch.ctxt;
+
+ vgic_handle_nested_maint_irq(vcpu);
+
if (unlikely(vcpu_mode_el2(vcpu))) {
ctxt->hw_pstate = *vcpu_cpsr(vcpu) & ~PSR_MODE_MASK;
@@ -315,9 +315,11 @@ int kvm_vgic_inject_mapped_irq(struct kvm *kvm, int cpuid, unsigned int intid,
#ifdef CONFIG_KVM_ARM_NESTED_HYP
void vgic_v2_setup_shadow_state(struct kvm_vcpu *vcpu);
void vgic_v2_restore_shadow_state(struct kvm_vcpu *vcpu);
+void vgic_handle_nested_maint_irq(struct kvm_vcpu *vcpu);
#else
static inline void vgic_v2_setup_shadow_state(struct kvm_vcpu *vcpu) { }
static inline void vgic_v2_restore_shadow_state(struct kvm_vcpu *vcpu) { }
+static inline void vgic_handle_nested_maint_irq(struct kvm_vcpu *vcpu) { }
#endif
#define irqchip_in_kernel(k) (!!((k)->arch.vgic.in_kernel))
@@ -300,6 +300,22 @@ void vgic_v2_restore_shadow_state(struct kvm_vcpu *vcpu)
vgic_cpu->nested_vgic_v2 = vgic_cpu->shadow_vgic_v2;
}
+void vgic_handle_nested_maint_irq(struct kvm_vcpu *vcpu)
+{
+ struct vgic_v2_cpu_if *cpu_if = vcpu_nested_if(vcpu);
+
+ /*
+ * If we exit a nested VM with a pending maintenance interrupt from the
+ * GIC, then we need to forward this to the guest hypervisor so that it
+ * can re-sync the appropriate LRs and sample level triggered interrupts
+ * again.
+ */
+ if (vcpu_el2_imo_is_set(vcpu) && !vcpu_mode_el2(vcpu) &&
+ (cpu_if->vgic_hcr & GICH_HCR_EN) &&
+ vgic_mmio_read_v2_misr(vcpu, 0, 0))
+ kvm_inject_nested_irq(vcpu);
+}
+
void vgic_init_nested(struct kvm_vcpu *vcpu)
{
vgic_v2_setup_shadow_state(vcpu);