KVM: VMX: Extract vmx_update_secondary_exec_control()
PATCH 1/1 KVM: VMX: Extract vmx_update_secondary_exec_control()
Currently, vmx_compute_secondary_exec_control() is invoked by init_vmcs() and vmx_vcpu_after_set_cpuid().init_vmcs() is called when creating vcpu and vmx_vcpu_after_set_cpuid() is called when guest cpuid is settled.
vmx_compute_secondary_exec_control() can be divided into 2 parts: 1) compute guest's effective secondary_exec_control = vmcs_config + guest settings. 2) further update effective secondary_exec_control on those fields related to guest's cpuid.
When vmx_create_vcpu() --> init_vmcs() --> vmx_compute_secondary_exec_control(), guest cpuid is actually blank, so doing part 2 is non sense; and futher, part 2 involves vmx.nested.msrs updates, which later, will be overwritten by copying vmcs_config.nested. This doesn't cause trouble now is because vmx_vcpu_after_set_cpuid() --> vmx_compute_secondary_exec_control() later will update again, but it is wrong in essence.
This patch is to extract part 2 into vmx_update_secondary_exec_control(), which is called only by vmx_vcpu_after_set_cpuid(), when guest cpuid is settled. And vmx_vcpu_after_set_cpuid() doesn't need to redo part 1, which has been done by init_vmcs() earlier.
--- arch/x86/kvm/vmx/vmx.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
arch/x86/kvm/vmx/vmx.c +14 -1
@@ -4239,6 +4239,19 @@ static void vmx_compute_secondary_exec_control(struct vcpu_vmx *vmx)if (!enable_pml) exec_control &= ~SECONDARY_EXEC_ENABLE_PML ; + vmx->secondary_exec_control = exec_control; +} + +/* +* Some features/exits of Secondary VM-Exec control depend on guest cpuid, +* update them when guest cpuid settles/changes. +* In nested case, these updates also spread to nVMX control msrs. +*/ +static void vmx_update_secondary_exec_control (struct vcpu_vmx *vmx) +{ +struct kvm_vcpu *vcpu = &vmx->vcpu; +u32 exec_control = vmx->secondary_exec_control; +if (cpu_has_vmx_xsaves ()) {/* Exposing XSAVES only when XSAVE is exposed */ bool xsaves_enabled =
@@ -7227,7 +7240,7 @@ static void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) vcpu->arch.xsaves_enabled = false;if (cpu_has_secondary_exec_ctrls ()) { -vmx_compute_secondary_exec_control (vmx); +vmx_update_secondary_exec_control (vmx);vmcs_set_secondary_exec_control (vmx); }
Signature · 1 line
1.8.3.1