[PATCH v2 3/5] KVM: nSVM: Mark CR3 as dirty when loading CR3 on nested transitions
From: Sean Christopherson
Date: Tue Nov 17 2026 - 16:09:51 EST
Mark CR3 as dirty when loading CR3 on nested VMRUN and nested #VMEXIT, even
though svm_load_mmu_pgd() unconditionally updates vmcb.save.CR3, i.e. never
consumes the dirty bit. This will allow deduplicating nearly-identical
code between nVMX and nSVM with respect to loading CR3.
Note, VMX consumes the dirty flag in kvm_mmu_new_pgd(), i.e. having nVMX
mark CR3 after the fact isn't a viable option. Marking CR3 dirty in nVMX
code before invoking the to-be-common helper also isn't safe in general, as
it's theoretically possible KVM could observe+consume the dirty flag before
vcpu->arch.cr3 is updated (even though that's extremely unlikely to ever be
the case).
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
---
arch/x86/kvm/svm/nested.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
index a743179b172a..32f95c9d72be 100644
--- a/arch/x86/kvm/svm/nested.c
+++ b/arch/x86/kvm/svm/nested.c
@@ -725,6 +725,7 @@ static int nested_svm_load_cr3(struct kvm_vcpu *vcpu, unsigned long cr3,
}
vcpu->arch.cr3 = cr3;
+ kvm_register_mark_dirty(vcpu, VCPU_REG_CR3);
/* Re-initialize the MMU, e.g. to pick up CR4 MMU role changes. */
kvm_init_mmu(vcpu);
--
2.56.1.703.gf848ed807c-goog