]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: arm64: Make ICC_*SGI*_EL1 undef in the absence of a vGICv3
authorMarc Zyngier <maz@kernel.org>
Tue, 20 Aug 2024 10:03:38 +0000 (11:03 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 4 Sep 2024 11:17:43 +0000 (13:17 +0200)
commit 3e6245ebe7ef341639e9a7e402b3ade8ad45a19f upstream.

On a system with a GICv3, if a guest hasn't been configured with
GICv3 and that the host is not capable of GICv2 emulation,
a write to any of the ICC_*SGI*_EL1 registers is trapped to EL2.

We therefore try to emulate the SGI access, only to hit a NULL
pointer as no private interrupt is allocated (no GIC, remember?).

The obvious fix is to give the guest what it deserves, in the
shape of a UNDEF exception.

Reported-by: Alexander Potapenko <glider@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20240820100349.3544850-2-maz@kernel.org
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/arm64/kvm/sys_regs.c
arch/arm64/kvm/vgic/vgic.h

index 835fa036b2d541f91bdacd22ee9093d8e7a01b98..b4bdabbfafdd26ef6ff71ac756bb6fa1c6c1442b 100644 (file)
@@ -30,6 +30,7 @@
 #include <trace/events/kvm.h>
 
 #include "sys_regs.h"
+#include "vgic/vgic.h"
 
 #include "trace.h"
 
@@ -275,6 +276,11 @@ static bool access_gic_sgi(struct kvm_vcpu *vcpu,
 {
        bool g1;
 
+       if (!kvm_has_gicv3(vcpu->kvm)) {
+               kvm_inject_undefined(vcpu);
+               return false;
+       }
+
        if (!p->is_write)
                return read_from_write_only(vcpu, p, r);
 
index 64fcd75111108c6b7b3b5b74e434339138c44a57..3d7fa7ef353ecf65035467451a4cacf12264f5cd 100644 (file)
@@ -318,4 +318,11 @@ int vgic_v4_init(struct kvm *kvm);
 void vgic_v4_teardown(struct kvm *kvm);
 void vgic_v4_configure_vsgis(struct kvm *kvm);
 
+static inline bool kvm_has_gicv3(struct kvm *kvm)
+{
+       return (static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif) &&
+               irqchip_in_kernel(kvm) &&
+               kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3);
+}
+
 #endif