Re: [PATCH v6 25/31] KVM: nSVM: Cache all used fields from VMCB12

From: Yosry Ahmed

Date: Tue Feb 24 2026 - 18:58:56 EST


> @@ -715,48 +732,48 @@ static void nested_vmcb02_prepare_save(struct vcpu_svm *svm, struct vmcb *vmcb12
> svm->nested.force_msr_bitmap_recalc = true;
> }
>
> - if (unlikely(new_vmcb12 || vmcb_is_dirty(vmcb12, VMCB_SEG))) {
> - vmcb02->save.es = vmcb12->save.es;
> - vmcb02->save.cs = vmcb12->save.cs;
> - vmcb02->save.ss = vmcb12->save.ss;
> - vmcb02->save.ds = vmcb12->save.ds;
> - vmcb02->save.cpl = vmcb12->save.cpl;
> + if (unlikely(new_vmcb12 || vmcb12_is_dirty(control, VMCB_SEG))) {

Internal AI review caught a bug here. We only copy clean bits in
__nested_copy_vmcb_control_to_cache() if Hyper-V extensions are used,
so this patch will treat everything as dirty. Not a correctness bug,
but a perf one. Probably need the following:

diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
index 2159f5fbfc314..3c9643c03b1a4 100644
--- a/arch/x86/kvm/svm/nested.c
+++ b/arch/x86/kvm/svm/nested.c
@@ -524,11 +524,11 @@ void __nested_copy_vmcb_control_to_cache(struct
kvm_vcpu *vcpu,
to->asid = from->asid;
to->msrpm_base_pa &= ~0x0fffULL;
to->iopm_base_pa &= ~0x0fffULL;
+ to->clean = from->clean;

#ifdef CONFIG_KVM_HYPERV
/* Hyper-V extensions (Enlightened VMCB) */
if (kvm_hv_hypercall_enabled(vcpu)) {
- to->clean = from->clean;
memcpy(&to->hv_enlightenments, &from->hv_enlightenments,
sizeof(to->hv_enlightenments));
}