Skip to content

Commit ef2e78d

Browse files
author
Marc Zyngier
committed
KVM: arm64: Opportunistically turn off WFI trapping when using direct LPI injection
Just like we do for WFE trapping, it can be useful to turn off WFI trapping when the physical CPU is not oversubscribed (that is, the vcpu is the only runnable process on this CPU) *and* that we're using direct injection of interrupts. The conditions are reevaluated on each vcpu_load(), ensuring that we don't switch to this mode on a busy system. On a GICv4 system, this has the effect of reducing the generation of doorbell interrupts to zero when the right conditions are met, which is a huge improvement over the current situation (where the doorbells are screaming if the CPU ever hits a blocking WFI). Signed-off-by: Marc Zyngier <[email protected]> Reviewed-by: Zenghui Yu <[email protected]> Reviewed-by: Christoffer Dall <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5bd90b0 commit ef2e78d

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

arch/arm/include/asm/kvm_emulate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ static inline unsigned long *vcpu_hcr(const struct kvm_vcpu *vcpu)
9595
return (unsigned long *)&vcpu->arch.hcr;
9696
}
9797

98-
static inline void vcpu_clear_wfe_traps(struct kvm_vcpu *vcpu)
98+
static inline void vcpu_clear_wfx_traps(struct kvm_vcpu *vcpu)
9999
{
100100
vcpu->arch.hcr &= ~HCR_TWE;
101101
}
102102

103-
static inline void vcpu_set_wfe_traps(struct kvm_vcpu *vcpu)
103+
static inline void vcpu_set_wfx_traps(struct kvm_vcpu *vcpu)
104104
{
105105
vcpu->arch.hcr |= HCR_TWE;
106106
}

arch/arm64/include/asm/kvm_emulate.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,19 @@ static inline unsigned long *vcpu_hcr(struct kvm_vcpu *vcpu)
8787
return (unsigned long *)&vcpu->arch.hcr_el2;
8888
}
8989

90-
static inline void vcpu_clear_wfe_traps(struct kvm_vcpu *vcpu)
90+
static inline void vcpu_clear_wfx_traps(struct kvm_vcpu *vcpu)
9191
{
9292
vcpu->arch.hcr_el2 &= ~HCR_TWE;
93+
if (atomic_read(&vcpu->arch.vgic_cpu.vgic_v3.its_vpe.vlpi_count))
94+
vcpu->arch.hcr_el2 &= ~HCR_TWI;
95+
else
96+
vcpu->arch.hcr_el2 |= HCR_TWI;
9397
}
9498

95-
static inline void vcpu_set_wfe_traps(struct kvm_vcpu *vcpu)
99+
static inline void vcpu_set_wfx_traps(struct kvm_vcpu *vcpu)
96100
{
97101
vcpu->arch.hcr_el2 |= HCR_TWE;
102+
vcpu->arch.hcr_el2 |= HCR_TWI;
98103
}
99104

100105
static inline void vcpu_ptrauth_enable(struct kvm_vcpu *vcpu)

virt/kvm/arm/arm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,9 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
386386
kvm_vcpu_pmu_restore_guest(vcpu);
387387

388388
if (single_task_running())
389-
vcpu_clear_wfe_traps(vcpu);
389+
vcpu_clear_wfx_traps(vcpu);
390390
else
391-
vcpu_set_wfe_traps(vcpu);
391+
vcpu_set_wfx_traps(vcpu);
392392

393393
vcpu_ptrauth_setup_lazy(vcpu);
394394
}

0 commit comments

Comments
 (0)