Skip to content

Commit 3e6245e

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Make ICC_*SGI*_EL1 undef in the absence of a vGICv3
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 <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 1d8c3c2 commit 3e6245e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

arch/arm64/kvm/sys_regs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <trace/events/kvm.h>
3434

3535
#include "sys_regs.h"
36+
#include "vgic/vgic.h"
3637

3738
#include "trace.h"
3839

@@ -435,6 +436,11 @@ static bool access_gic_sgi(struct kvm_vcpu *vcpu,
435436
{
436437
bool g1;
437438

439+
if (!kvm_has_gicv3(vcpu->kvm)) {
440+
kvm_inject_undefined(vcpu);
441+
return false;
442+
}
443+
438444
if (!p->is_write)
439445
return read_from_write_only(vcpu, p, r);
440446

arch/arm64/kvm/vgic/vgic.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,4 +346,11 @@ void vgic_v4_configure_vsgis(struct kvm *kvm);
346346
void vgic_v4_get_vlpi_state(struct vgic_irq *irq, bool *val);
347347
int vgic_v4_request_vpe_irq(struct kvm_vcpu *vcpu, int irq);
348348

349+
static inline bool kvm_has_gicv3(struct kvm *kvm)
350+
{
351+
return (static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif) &&
352+
irqchip_in_kernel(kvm) &&
353+
kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3);
354+
}
355+
349356
#endif

0 commit comments

Comments
 (0)