* [PATCH] KVM: VMX: Extract vmx_update_secondary_exec_control()
@ 2020-11-09 10:49 Robert Hoo
0 siblings, 0 replies; only message in thread
From: Robert Hoo @ 2020-11-09 10:49 UTC (permalink / raw)
To: pbonzini, vkuznets, wanpengli, jmattson, joro, kvm; +Cc: robert.hu, Robert Hoo
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.
Signed-off-by: Robert Hoo <robert.hu@linux.intel.com>
---
arch/x86/kvm/vmx/vmx.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 47b8357..995cb4c 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -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);
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2020-11-09 10:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-09 10:49 [PATCH] KVM: VMX: Extract vmx_update_secondary_exec_control() Robert Hoo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).