Skip to contentSkip to conversation

KVM: SVM: Sync CR8 to the local APIC after marking the VMCB clean

PATCH In review Sean Christopherson 6 participants 6 messages Nov 13 – Nov 15

Subsystems (3)
lore
Share & tools
lore

Sean Christopherson

author maintainer
#0 lore raw

PATCH 1/1 KVM: SVM: Sync CR8 to the local APIC after marking the VMCB clean

From: Chris Oo <[email protected]>

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 Carlos López <[email protected]>
Cc Stefano Garzarella <[email protected]>
[sean: rewrite changelog, massage comment]

---

Chris, as mentioned, I need your SoB.

 arch/x86/kvm/svm/svm.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
arch/x86/kvm/svm/svm.c +7 -2
index 581bc3a23c95..3152846a6ccd 100644
@@ -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

Signature · 1 line
2.56.1.703.gf848ed807c-goog
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] KVM: SVM: missing Signed-off-by trailer from patch author --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] KVM: SVM: missing Signed-off-by trailer from patch author --

commit 233803838af902e26ce77bf3e6c981b3c2991bd9
Author: Chris Oo <[email protected]>

Quoted 11 lines

KVM: SVM: Sync CR8 to the local APIC after marking the VMCB clean

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.

Quoted 7 lines
Fixes bb365a506b1e ("KVM: x86: Unconditionally recompute CR8 intercept on PPR update")
Cc Carlos López <[email protected]>
Cc Stefano Garzarella <[email protected]>
[sean: rewrite changelog, massage comment]

[Severity: High]
As noted below the tearline, the patch author's Signed-off-by trailer is missing and currently listed as Not-signed-off-by. A Signed-off-by from Chris Oo <[email protected]> is required under the Developer's Certificate of Origin before this commit can be merged.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Sean Christopherson

Thanks for helping to clean up my patch Sean, appreciate it.

Thanks,
Chris

________________________________________
From: Sean Christopherson <[email protected]>
Sent: Friday, November 13, 2026 8:25 AM
To: Sean Christopherson <[email protected]>; Paolo Bonzini <[email protected]>
Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; Carlos López <[email protected]>; Stefano Garzarella <[email protected]>; Chris Oo <[email protected]>
Subject: [EXTERNAL] [PATCH] KVM: SVM: Sync CR8 to the local APIC after marking the VMCB clean

From: Chris Oo <[email protected]>

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 Carlos López <[email protected]>
Cc Stefano Garzarella <[email protected]>
[sean: rewrite changelog, massage comment]

---

Chris, as mentioned, I need your SoB.

 arch/x86/kvm/svm/svm.c | 9 +++++++--

 1 file changed, 7 insertions(+), 2 deletions(-)
arch/x86/kvm/svm/svm.c +0 -0
index 581bc3a23c95..3152846a6ccd 100644
@@ -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

Reviewed-by on v1 1/1
#3 lore raw
In reply to Sean Christopherson
Quoted 12 lines · Sean Christopherson

From: Chris Oo <[email protected]>

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.

Quoted 7 lines
Fixes bb365a506b1e ("KVM: x86: Unconditionally recompute CR8 intercept on PPR update")
Cc Carlos López <[email protected]>
Cc Stefano Garzarella <[email protected]>
[sean: rewrite changelog, massage comment]
Acked-by on v1 1/1
#4 lore raw
In reply to Sean Christopherson
Quoted 11 lines · Sean Christopherson

From: Chris Oo <[email protected]>

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.

Quoted 8 lines
Fixes bb365a506b1e ("KVM: x86: Unconditionally recompute CR8 intercept on PPR update")
Cc Carlos López <[email protected]>
Cc Stefano Garzarella <[email protected]>
[sean: rewrite changelog, massage comment]

---

LGTM!

Acked-by on v1 1/1
#5 lore raw
In reply to Sean Christopherson
Quoted 11 lines · Sean Christopherson

From: Chris Oo <[email protected]>

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.

Quoted 7 lines
Fixes bb365a506b1e ("KVM: x86: Unconditionally recompute CR8 intercept on PPR update")
Cc Carlos López <[email protected]>
Cc Stefano Garzarella <[email protected]>
[sean: rewrite changelog, massage comment]

Looks good, thanks!

Quoted 36 lines

---

Chris, as mentioned, I need your SoB.

 arch/x86/kvm/svm/svm.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
arch/x86/kvm/svm/svm.c +7 -2
index 581bc3a23c95..3152846a6ccd 100644
@@ -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