diff mbox series

[15/23] KVM: arm64: nVHE: Only save/restore GICv3 state if modeling a GIC

Message ID 20200903152610.1078827-16-maz@kernel.org (mailing list archive)
State New, archived
Headers show
Series KVM: arm64: rVIC/rVID PV interrupt controller | expand

Commit Message

Marc Zyngier Sept. 3, 2020, 3:26 p.m. UTC
If we aren't modeling a GIC, there is no need to save/restore
the GICv3 state at all. Note that this only matters for nVHE,
as VHE already has this code outside of the world switch.

Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 arch/arm64/kvm/hyp/nvhe/switch.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c
index 0970442d2dbc..be77eb156542 100644
--- a/arch/arm64/kvm/hyp/nvhe/switch.c
+++ b/arch/arm64/kvm/hyp/nvhe/switch.c
@@ -101,16 +101,22 @@  static void __deactivate_vm(struct kvm_vcpu *vcpu)
 /* Save VGICv3 state on non-VHE systems */
 static void __hyp_vgic_save_state(struct kvm_vcpu *vcpu)
 {
-	if (static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif)) {
+	struct kvm *kvm = kern_hyp_va(vcpu->kvm);
+
+	if (static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif) &&
+	    (irqchip_is_gic_v2(kvm) || irqchip_is_gic_v3(kvm))) {
 		__vgic_v3_save_state(&vcpu->arch.vgic_cpu.vgic_v3);
 		__vgic_v3_deactivate_traps(&vcpu->arch.vgic_cpu.vgic_v3);
 	}
 }
 
-/* Restore VGICv3 state on non_VEH systems */
+/* Restore VGICv3 state on non-VHE systems */
 static void __hyp_vgic_restore_state(struct kvm_vcpu *vcpu)
 {
-	if (static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif)) {
+	struct kvm *kvm = kern_hyp_va(vcpu->kvm);
+
+	if (static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif) &&
+	    (irqchip_is_gic_v2(kvm) || irqchip_is_gic_v3(kvm))) {
 		__vgic_v3_activate_traps(&vcpu->arch.vgic_cpu.vgic_v3);
 		__vgic_v3_restore_state(&vcpu->arch.vgic_cpu.vgic_v3);
 	}