xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Haozhong Zhang <haozhong.zhang@intel.com>
To: xen-devel@lists.xen.org
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Kevin Tian <kevin.tian@intel.com>,
	Jan Beulich <jbeulich@suse.com>,
	Jun Nakajima <jun.nakajima@intel.com>,
	Haozhong Zhang <haozhong.zhang@intel.com>
Subject: [PATCH 1/3] vvmx: set vmxon_region_pa of vcpu out of VMX operation to an invalid address
Date: Tue, 13 Dec 2016 20:16:18 +0800	[thread overview]
Message-ID: <20161213121620.22745-2-haozhong.zhang@intel.com> (raw)
In-Reply-To: <20161213121620.22745-1-haozhong.zhang@intel.com>

nvmx_handle_vmxon() previously checks whether a vcpu is in VMX
operation by comparing its vmxon_region_pa with GPA 0. However, 0 is
also a valid VMXON region address. If L1 hypervisor had set the VMXON
region address to 0, the check in nvmx_handle_vmxon() will be skipped.
Fix this problem by using an invalid VMXON region address for vcpu
out of VMX operation.

Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
---
 xen/arch/x86/hvm/vmx/vvmx.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c
index e6e9ebd..f5637eb 100644
--- a/xen/arch/x86/hvm/vmx/vvmx.c
+++ b/xen/arch/x86/hvm/vmx/vvmx.c
@@ -32,6 +32,18 @@ static DEFINE_PER_CPU(u64 *, vvmcs_buf);
 
 static void nvmx_purge_vvmcs(struct vcpu *v);
 
+/*
+ * When a vcpu is out of VMXON region, set its vmxon_region_pa to
+ * INVALID_VMXON_REGION_PA. We cannot use 0, because 0 is also a valid
+ * VMXON region address.
+ */
+#define INVALID_VMXON_REGION_PA (~0UL)
+
+static bool nvmx_vcpu_in_vmx(struct vcpu *v)
+{
+    return vcpu_2_nvmx(v).vmxon_region_pa != INVALID_VMXON_REGION_PA;
+}
+
 #define VMCS_BUF_SIZE 100
 
 int nvmx_cpu_up_prepare(unsigned int cpu)
@@ -107,7 +119,7 @@ int nvmx_vcpu_initialise(struct vcpu *v)
 
     nvmx->ept.enabled = 0;
     nvmx->guest_vpid = 0;
-    nvmx->vmxon_region_pa = 0;
+    nvmx->vmxon_region_pa = INVALID_VMXON_REGION_PA;
     nvcpu->nv_vvmcx = NULL;
     nvcpu->nv_vvmcxaddr = VMCX_EADDR;
     nvmx->intr.intr_info = 0;
@@ -357,7 +369,7 @@ static int vmx_inst_check_privilege(struct cpu_user_regs *regs, int vmxop_check)
              !(v->arch.hvm_vcpu.guest_cr[4] & X86_CR4_VMXE) )
             goto invalid_op;
     }
-    else if ( !vcpu_2_nvmx(v).vmxon_region_pa )
+    else if ( !nvmx_vcpu_in_vmx(v) )
         goto invalid_op;
 
     hvm_get_segment_register(v, x86_seg_cs, &cs);
@@ -1384,7 +1396,7 @@ int nvmx_handle_vmxon(struct cpu_user_regs *regs)
     if ( rc != X86EMUL_OKAY )
         return rc;
 
-    if ( nvmx->vmxon_region_pa )
+    if ( nvmx_vcpu_in_vmx(v) )
         gdprintk(XENLOG_WARNING, 
                  "vmxon again: orig %"PRIpaddr" new %lx\n",
                  nvmx->vmxon_region_pa, gpa);
@@ -1417,7 +1429,7 @@ int nvmx_handle_vmxoff(struct cpu_user_regs *regs)
         return rc;
 
     nvmx_purge_vvmcs(v);
-    nvmx->vmxon_region_pa = 0;
+    nvmx->vmxon_region_pa = INVALID_VMXON_REGION_PA;
 
     vmreturn(regs, VMSUCCEED);
     return X86EMUL_OKAY;
-- 
2.10.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  reply	other threads:[~2016-12-13 12:16 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-13 12:16 [PATCH 0/3] vvmx: fix L1 vmxon Haozhong Zhang
2016-12-13 12:16 ` Haozhong Zhang [this message]
2016-12-13 14:35   ` [PATCH 1/3] vvmx: set vmxon_region_pa of vcpu out of VMX operation to an invalid address Andrew Cooper
2016-12-13 15:06     ` Konrad Rzeszutek Wilk
2016-12-13 15:19   ` Jan Beulich
2016-12-13 15:21   ` Jan Beulich
2016-12-14  1:37     ` Haozhong Zhang
2016-12-14  7:08       ` Jan Beulich
2016-12-14  5:18   ` Tian, Kevin
2016-12-13 12:16 ` [PATCH 2/3] vvmx: return VMfail to L1 if L1 vmxon is executed in VMX operation Haozhong Zhang
2016-12-13 14:46   ` Andrew Cooper
2016-12-13 15:16   ` Konrad Rzeszutek Wilk
2016-12-14  1:25     ` Haozhong Zhang
2016-12-14  5:22   ` Tian, Kevin
2016-12-13 12:16 ` [PATCH 3/3] vvmx: check the operand of L1 vmxon Haozhong Zhang
2016-12-13 14:48   ` Andrew Cooper
2016-12-13 15:18   ` Konrad Rzeszutek Wilk
2016-12-14  5:24   ` Tian, Kevin

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=20161213121620.22745-2-haozhong.zhang@intel.com \
    --to=haozhong.zhang@intel.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=jun.nakajima@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=xen-devel@lists.xen.org \
    /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).