All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: SVM: Sync CR8 to the local APIC after marking the VMCB clean
@ 2026-11-13 16:25 Sean Christopherson
  2026-11-13 16:33 ` sashiko-bot
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sean Christopherson @ 2026-11-13 16:25 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini
  Cc: kvm, linux-kernel, Carlos López, Stefano Garzarella,
	Chris Oo

From: Chris Oo <cho@microsoft.com>

Sync CR8 from the VMCB to the TPR *after* marking all VMCB fields as clean,
as syncing CR8 can toggle the CR8 write intercept and thus mark INTERCEPTS
as dirty.  Clobbering the dirty bit can result in KVM failing to detect CR8
writes if the underlying "hardware" uses the clean bits to optimize VMRUN,
e.g. when KVM is running on Hyper-V.

Failure to intercept CR8 usually manifests as hangs when running Windows as
L2, as KVM's view of vTPR stays high and so KVM never injects pending IRQs.

Fixes: bb365a506b1e ("KVM: x86: Unconditionally recompute CR8 intercept on PPR update")
Cc: stable@vger.kernel.org
Cc: Carlos López <clopez@suse.de>
Cc: Stefano Garzarella <sgarzare@redhat.com>
Not-signed-off-by: Chris Oo <cho@microsoft.com>
[sean: rewrite changelog, massage comment]
Signed-off-by: Sean Christopherson <seanjc@google.com>
---

Chris, as mentioned, I need your SoB.

 arch/x86/kvm/svm/svm.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 581bc3a23c95..3152846a6ccd 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -4726,8 +4726,6 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags)
 	if (unlikely(svm->vmcb->control.exit_code == SVM_EXIT_NMI))
 		kvm_after_interrupt(vcpu);
 
-	sync_cr8_to_lapic(vcpu);
-
 	svm->next_rip = 0;
 	if (is_guest_mode(vcpu)) {
 		nested_sync_control_from_vmcb02(svm);
@@ -4758,6 +4756,13 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags)
 			       vcpu_to_pmu(vcpu)->global_ctrl);
 	}
 
+	/*
+	 * Note!  Any action that might dirty the VMCB must be done *after*
+	 * marking all VMCB fields as clean, e.g. syncing CR8 can toggle the
+	 * CR8 write intercept and thus mark the intercepts field dirty.
+	 */
+	sync_cr8_to_lapic(vcpu);
+
 	/* if exit due to PF check for async PF */
 	if (svm->vmcb->control.exit_code == SVM_EXIT_EXCP_BASE + PF_VECTOR)
 		vcpu->arch.apf.host_apf_flags =

base-commit: d21eef2084a9af87ac2a783bc7c2b175ba114e4e
-- 
2.56.1.703.gf848ed807c-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-13 16:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13 16:25 [PATCH] KVM: SVM: Sync CR8 to the local APIC after marking the VMCB clean Sean Christopherson
2026-11-13 16:33 ` sashiko-bot
2026-11-13 16:36 ` [EXTERNAL] " Chris Oo
2026-11-13 16:59 ` Yosry Ahmed

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.