From: Sean Christopherson Date: Thu, 9 Apr 2026 22:42:32 +0000 (-0700) Subject: KVM: nVMX: Do a bitwise-AND of regs_avail when switching active VMCS X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3b628ef168dabfff8f413a791675c34beb8a16db;p=thirdparty%2Fkernel%2Flinux.git KVM: nVMX: Do a bitwise-AND of regs_avail when switching active VMCS When switching between vmcs01 and vmcs02, do a bitwise-AND of regs_avail to effectively reset the mask for the new VMCS, purely to be consistent with all other "full" writes of regs_avail. In practice, a straight write versus a bitwise-AND will yield the same result, as kvm_arch_vcpu_create() marks *all* registers available (and dirty), and KVM never marks registers unavailable unless they're lazily loaded. This will allow adding wrapper APIs to set regs_{avail,dirty} without having to add special handling for a nVMX use case that doesn't exist in practice. Signed-off-by: Sean Christopherson Reviewed-by: Kai Huang Tested-by: Kai Huang Message-ID: <20260409224236.2021562-4-seanjc@google.com> Signed-off-by: Paolo Bonzini --- diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 22b1f06a9d40..63c4ca8c97d5 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -310,7 +310,7 @@ static void vmx_switch_vmcs(struct kvm_vcpu *vcpu, struct loaded_vmcs *vmcs) vmx_sync_vmcs_host_state(vmx, prev); put_cpu(); - vcpu->arch.regs_avail = ~VMX_REGS_LAZY_LOAD_SET; + vcpu->arch.regs_avail &= ~VMX_REGS_LAZY_LOAD_SET; /* * All lazily updated registers will be reloaded from VMCS12 on both