kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robert Hoo <robert.hu@linux.intel.com>
To: pbonzini@redhat.com, vkuznets@redhat.com, wanpengli@tencent.com,
	jmattson@google.com, joro@8bytes.org, kvm@vger.kernel.org
Cc: robert.hu@intel.com, Robert Hoo <robert.hu@linux.intel.com>
Subject: [PATCH] KVM: VMX: Extract vmx_update_secondary_exec_control()
Date: Mon,  9 Nov 2020 18:49:48 +0800	[thread overview]
Message-ID: <1604918988-26884-1-git-send-email-robert.hu@linux.intel.com> (raw)

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


                 reply	other threads:[~2020-11-09 10:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1604918988-26884-1-git-send-email-robert.hu@linux.intel.com \
    --to=robert.hu@linux.intel.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=robert.hu@intel.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).