From: Sean Christopherson Flush the guest TLB when emulating a RESET even though such a flush should be completely unnecessary since KVM only performs a RESET when creating a vCPU, and so it should be impossible for the vCPU to have any accrued TLB state. Making the flush unconditional aligns KVM's behavior with both the SDM and APM (ignoring that both specifications contradict themselves), and avoids having to worry about hypotheticals like "what if KVM did provide a way to emulate RESET after a vCPU is created?". Signed-off-by: Sean Christopherson Message-ID: <20261022015407.279870-3-seanjc@google.com> Signed-off-by: Paolo Bonzini --- arch/x86/kvm/x86.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 09c6df00ebb6..26e7beaff8a0 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9731,9 +9731,6 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) kvm_x86_call(set_efer)(vcpu, 0); kvm_x86_call(update_exception_bitmap)(vcpu); - if (old_cr0 & X86_CR0_PG) - kvm_make_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu); - /* * Unconditionally reset the MMU, even though super strictly speaking, * a MMU reset is only necessary if and only one of the page role bits @@ -9750,16 +9747,16 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) kvm_mmu_reset_context(vcpu); /* - * Intel's SDM states that all TLB entries are flushed on INIT. AMD's - * APM states the TLBs are untouched by INIT, but it also states that - * the TLBs are flushed on "External initialization of the processor." - * Flush the guest TLB regardless of vendor, there is no meaningful - * benefit in relying on the guest to flush the TLB immediately after - * INIT. A spurious TLB flush is benign and likely negligible from a - * performance perspective. + * Intel's SDM states that all TLB entries are flushed on INIT "as with + * a hardware reset", and AMD's APM states the TLBs are flushed on + * "External initialization of the processor". Flush the guest TLB for + * both RESET and INIT, regardless of vendor, even though both the SDM + * and APM contradict the above statements in other tables. There is + * no meaningful benefit in relying on the guest to flush the TLB, and + * a spurious TLB flush is benign and likely negligible from a + * performance perspective (especially for RESET). */ - if (init_event) - kvm_make_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu); + kvm_make_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu); } EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_vcpu_reset); -- 2.52.0