Skip to content

Commit 93078ae

Browse files
committed
KVM: arm64: nv: Request vPE doorbell upon nested ERET to L2
Running an L2 guest with GICv4 enabled goes absolutely nowhere, and gets into a vicious cycle of nested ERET followed by nested exception entry into the L1. When KVM does a put on a runnable vCPU, it marks the vPE as nonresident but does not request a doorbell IRQ. Behind the scenes in the ITS driver's view of the vCPU, its_vpe::pending_last gets set to true to indicate that context is still runnable. This comes to a head when doing the nested ERET into L2. The vPE doesn't get scheduled on the redistributor as it is exclusively part of the L1's VGIC context. kvm_vgic_vcpu_pending_irq() returns true because the vPE appears runnable, and KVM does a nested exception entry into the L1 before L2 ever gets off the ground. This issue can be papered over by requesting a doorbell IRQ when descheduling a vPE as part of a nested ERET. KVM needs this anyway to kick the vCPU out of the L2 when an IRQ becomes pending for the L1. Link: https://lore.kernel.org/r/20240823212703.3576061-4-oliver.upton@linux.dev Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20250225172930.1850838-13-maz@kernel.org Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 69c9176 commit 93078ae

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

arch/arm64/include/asm/kvm_host.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,8 @@ struct kvm_vcpu_arch {
946946
#define PMUSERENR_ON_CPU __vcpu_single_flag(sflags, BIT(5))
947947
/* WFI instruction trapped */
948948
#define IN_WFI __vcpu_single_flag(sflags, BIT(6))
949+
/* KVM is currently emulating a nested ERET */
950+
#define IN_NESTED_ERET __vcpu_single_flag(sflags, BIT(7))
949951

950952

951953
/* Pointer to the vcpu's SVE FFR for sve_{save,load}_state() */

arch/arm64/kvm/emulate-nested.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,6 +2503,7 @@ void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu)
25032503
}
25042504

25052505
preempt_disable();
2506+
vcpu_set_flag(vcpu, IN_NESTED_ERET);
25062507
kvm_arch_vcpu_put(vcpu);
25072508

25082509
if (!esr_iss_is_eretax(esr))
@@ -2514,6 +2515,7 @@ void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu)
25142515
*vcpu_cpsr(vcpu) = spsr;
25152516

25162517
kvm_arch_vcpu_load(vcpu, smp_processor_id());
2518+
vcpu_clear_flag(vcpu, IN_NESTED_ERET);
25172519
preempt_enable();
25182520

25192521
kvm_pmu_nested_transition(vcpu);

arch/arm64/kvm/vgic/vgic-v4.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,14 +336,30 @@ void vgic_v4_teardown(struct kvm *kvm)
336336
its_vm->vpes = NULL;
337337
}
338338

339+
static inline bool vgic_v4_want_doorbell(struct kvm_vcpu *vcpu)
340+
{
341+
if (vcpu_get_flag(vcpu, IN_WFI))
342+
return true;
343+
344+
if (likely(!vcpu_has_nv(vcpu)))
345+
return false;
346+
347+
/*
348+
* GICv4 hardware is only ever used for the L1. Mark the vPE (i.e. the
349+
* L1 context) nonresident and request a doorbell to kick us out of the
350+
* L2 when an IRQ becomes pending.
351+
*/
352+
return vcpu_get_flag(vcpu, IN_NESTED_ERET);
353+
}
354+
339355
int vgic_v4_put(struct kvm_vcpu *vcpu)
340356
{
341357
struct its_vpe *vpe = &vcpu->arch.vgic_cpu.vgic_v3.its_vpe;
342358

343359
if (!vgic_supports_direct_msis(vcpu->kvm) || !vpe->resident)
344360
return 0;
345361

346-
return its_make_vpe_non_resident(vpe, !!vcpu_get_flag(vcpu, IN_WFI));
362+
return its_make_vpe_non_resident(vpe, vgic_v4_want_doorbell(vcpu));
347363
}
348364

349365
int vgic_v4_load(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)