]> www.infradead.org Git - users/hch/misc.git/commitdiff
KVM: arm64: nv: Exclude guest's TWED configuration when TWE isn't set
authorOliver Upton <oliver.upton@linux.dev>
Fri, 12 Sep 2025 21:22:54 +0000 (14:22 -0700)
committerMarc Zyngier <maz@kernel.org>
Fri, 19 Sep 2025 13:01:35 +0000 (14:01 +0100)
Ignore the guest hypervisor's configured TWE delay if it hasn't actually
requested WFE traps. Otherwise, OR'ing these fields into the effective
HCR when the guest sets TWE is safe as KVM doesn't use FEAT_TWED and
leaves the fields initialized to 0.

Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/kvm/hyp/vhe/switch.c

index 0998ad4a25524f673c6f513c7d721448847302c1..9984c492305a84c343749b7a1d9078ee1e0cd5b4 100644 (file)
@@ -95,6 +95,13 @@ static u64 __compute_hcr(struct kvm_vcpu *vcpu)
                        /* Force NV2 in case the guest is forgetful... */
                        guest_hcr |= HCR_NV2;
                }
+
+               /*
+                * Exclude the guest's TWED configuration if it hasn't set TWE
+                * to avoid potentially delaying traps for the host.
+                */
+               if (!(guest_hcr & HCR_TWE))
+                       guest_hcr &= ~(HCR_EL2_TWEDEn | HCR_EL2_TWEDEL);
        }
 
        BUG_ON(host_data_test_flag(VCPU_IN_HYP_CONTEXT) &&