Re: [Xen-devel] [PATCH v2 2/8] x86/nestedhvm: introduce vvmcx_valid()

2018-11-13 Thread Tian, Kevin
> From: Sergey Dyasli [mailto:sergey.dya...@citrix.com]
> Sent: Tuesday, November 6, 2018 8:08 PM
> 
> As a convenient helper function and refactor the code to use it.
> 
> No functional change.
> 
> Signed-off-by: Sergey Dyasli 

Reviewed-by: Kevin Tian 

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v2 2/8] x86/nestedhvm: introduce vvmcx_valid()

2018-11-07 Thread Wei Liu
On Tue, Nov 06, 2018 at 12:07:53PM +, Sergey Dyasli wrote:
> As a convenient helper function and refactor the code to use it.
> 
> No functional change.
> 
> Signed-off-by: Sergey Dyasli 

Reviewed-by: Wei Liu 

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v2 2/8] x86/nestedhvm: introduce vvmcx_valid()

2018-11-06 Thread Boris Ostrovsky
On 11/6/18 7:07 AM, Sergey Dyasli wrote:
> As a convenient helper function and refactor the code to use it.
>
> No functional change.
>
> Signed-off-by: Sergey Dyasli 
> ---
> CC: Boris Ostrovsky 
> CC: Suravee Suthikulpanit 
> CC: Brian Woods 
>
> v2:
> - Use the new helper in nestedsvm.c

Reviewed-by: Boris Ostrovsky 



___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

[Xen-devel] [PATCH v2 2/8] x86/nestedhvm: introduce vvmcx_valid()

2018-11-06 Thread Sergey Dyasli
As a convenient helper function and refactor the code to use it.

No functional change.

Signed-off-by: Sergey Dyasli 
---
CC: Boris Ostrovsky 
CC: Suravee Suthikulpanit 
CC: Brian Woods 

v2:
- Use the new helper in nestedsvm.c
---
 xen/arch/x86/hvm/svm/nestedsvm.c|  2 +-
 xen/arch/x86/hvm/vmx/vvmx.c | 17 -
 xen/include/asm-x86/hvm/nestedhvm.h |  5 +
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c b/xen/arch/x86/hvm/svm/nestedsvm.c
index 088b3fd562..9660202210 100644
--- a/xen/arch/x86/hvm/svm/nestedsvm.c
+++ b/xen/arch/x86/hvm/svm/nestedsvm.c
@@ -68,7 +68,7 @@ int nestedsvm_vmcb_map(struct vcpu *v, uint64_t vmcbaddr)
 struct nestedvcpu *nv = _nestedhvm(v);
 
 if (nv->nv_vvmcx != NULL && nv->nv_vvmcxaddr != vmcbaddr) {
-ASSERT(nv->nv_vvmcxaddr != INVALID_PADDR);
+ASSERT(vvmcx_valid(v));
 hvm_unmap_guest_frame(nv->nv_vvmcx, 1);
 nv->nv_vvmcx = NULL;
 nv->nv_vvmcxaddr = INVALID_PADDR;
diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c
index c8bc8e6d11..d437f33193 100644
--- a/xen/arch/x86/hvm/vmx/vvmx.c
+++ b/xen/arch/x86/hvm/vmx/vvmx.c
@@ -489,8 +489,7 @@ static void vmfail(struct cpu_user_regs *regs, enum 
vmx_insn_errno errno)
 if ( errno == VMX_INSN_SUCCEED )
 return;
 
-if ( vcpu_nestedhvm(current).nv_vvmcxaddr != INVALID_PADDR &&
- errno != VMX_INSN_FAIL_INVALID )
+if ( vvmcx_valid(current) && errno != VMX_INSN_FAIL_INVALID )
 vmfail_valid(regs, errno);
 else
 vmfail_invalid(regs);
@@ -773,7 +772,7 @@ static void nvmx_purge_vvmcs(struct vcpu *v)
 int i;
 
 __clear_current_vvmcs(v);
-if ( nvcpu->nv_vvmcxaddr != INVALID_PADDR )
+if ( vvmcx_valid(v) )
 hvm_unmap_guest_frame(nvcpu->nv_vvmcx, 1);
 nvcpu->nv_vvmcx = NULL;
 nvcpu->nv_vvmcxaddr = INVALID_PADDR;
@@ -1564,7 +1563,7 @@ static int nvmx_vmresume(struct vcpu *v, struct 
cpu_user_regs *regs)
 struct nestedvcpu *nvcpu = _nestedhvm(v);
 
 /* check VMCS is valid and IO BITMAP is set */
-if ( (nvcpu->nv_vvmcxaddr != INVALID_PADDR) &&
+if ( vvmcx_valid(v) &&
 ((nvmx->iobitmap[0] && nvmx->iobitmap[1]) ||
 !(__n2_exec_control(v) & CPU_BASED_ACTIVATE_IO_BITMAP) ) )
 nvcpu->nv_vmentry_pending = 1;
@@ -1581,7 +1580,7 @@ static int nvmx_handle_vmresume(struct cpu_user_regs 
*regs)
 struct nestedvmx *nvmx = _2_nvmx(v);
 unsigned long intr_shadow;
 
-if ( vcpu_nestedhvm(v).nv_vvmcxaddr == INVALID_PADDR )
+if ( !vvmcx_valid(v) )
 {
 vmfail_invalid(regs);
 return X86EMUL_OKAY;
@@ -1612,7 +1611,7 @@ static int nvmx_handle_vmlaunch(struct cpu_user_regs 
*regs)
 unsigned long intr_shadow;
 int rc;
 
-if ( vcpu_nestedhvm(v).nv_vvmcxaddr == INVALID_PADDR )
+if ( !vvmcx_valid(v) )
 {
 vmfail_invalid(regs);
 return X86EMUL_OKAY;
@@ -1665,7 +1664,7 @@ static int nvmx_handle_vmptrld(struct cpu_user_regs *regs)
 if ( nvcpu->nv_vvmcxaddr != gpa )
 nvmx_purge_vvmcs(v);
 
-if ( nvcpu->nv_vvmcxaddr == INVALID_PADDR )
+if ( !vvmcx_valid(v) )
 {
 bool_t writable;
 void *vvmcx = hvm_map_guest_frame_rw(paddr_to_pfn(gpa), 1, );
@@ -1804,7 +1803,7 @@ static int nvmx_handle_vmread(struct cpu_user_regs *regs)
 if ( rc != X86EMUL_OKAY )
 return rc;
 
-if ( vcpu_nestedhvm(v).nv_vvmcxaddr == INVALID_PADDR )
+if ( !vvmcx_valid(v) )
 {
 vmfail_invalid(regs);
 return X86EMUL_OKAY;
@@ -1846,7 +1845,7 @@ static int nvmx_handle_vmwrite(struct cpu_user_regs *regs)
 if ( decode_vmx_inst(regs, , ) != X86EMUL_OKAY )
 return X86EMUL_EXCEPTION;
 
-if ( vcpu_nestedhvm(v).nv_vvmcxaddr == INVALID_PADDR )
+if ( !vvmcx_valid(v) )
 {
 vmfail_invalid(regs);
 return X86EMUL_OKAY;
diff --git a/xen/include/asm-x86/hvm/nestedhvm.h 
b/xen/include/asm-x86/hvm/nestedhvm.h
index 9d1c2742b5..e09fa9d47d 100644
--- a/xen/include/asm-x86/hvm/nestedhvm.h
+++ b/xen/include/asm-x86/hvm/nestedhvm.h
@@ -92,4 +92,9 @@ static inline void nestedhvm_set_cr(struct vcpu *v, unsigned 
int cr,
 v->arch.hvm.nvcpu.guest_cr[cr] = value;
 }
 
+static inline bool vvmcx_valid(const struct vcpu *v)
+{
+return vcpu_nestedhvm(v).nv_vvmcxaddr != INVALID_PADDR;
+}
+
 #endif /* _HVM_NESTEDHVM_H */
-- 
2.17.1


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel