Skip to contentSkip to conversation

x86/vvmx: Misc fixes

PATCH In review Andrew Cooper 4 participants 17 messages Nov 15, 2018 – Nov 23, 2018

lore
Share & tools
lore
#0 lore raw

cover x86/vvmx: Misc fixes

All from code inspection

Andrew Cooper (4):
x86/vvmx: Drop unused CASE_{GET,SET}_REG() macros x86/vvmx: Correct the INVALID_PADDR checks for VMPTRLD/VMCLEAR x86/vvmx: Fixes to VMWRITE emulation
x86/vvmx: Don't call vmsucceed() at the end of virtual_vmexit()

 xen/arch/x86/hvm/vmx/vvmx.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH 1/4 x86/vvmx: Drop unused CASE_{GET, SET}_REG() macros

These have been obsolete since c/s 053ae230 "x86/vvmx: Remove enum vmx_regs_enc".

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>

---
 xen/arch/x86/hvm/vmx/vvmx.c | 5 -----
 1 file changed, 5 deletions(-)
xen/arch/x86/hvm/vmx/vvmx.c +0 -5
index 88021af..c296660 100644
@@ -207,11 +207,6 @@ struct vmx_inst_decoded {
     unsigned int reg2;
 };
 
-#define CASE_SET_REG(REG, reg)      \
-    case VMX_REG_ ## REG: regs->reg = value; break
-#define CASE_GET_REG(REG, reg)      \
-    case VMX_REG_ ## REG: value = regs->reg; break
-
 static int vvmcs_offset(u32 width, u32 type, u32 index)
 {
     int offset;
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 1/4
#3 lore raw

Re: [PATCH 1/4] x86/vvmx: Drop unused CASE_{GET, SET}_REG() macros

In reply to Andrew Cooper
Quoted 7 lines

From: Andrew Cooper [mailto:[email protected]]
Sent: Thursday, November 15, 2018 9:53 PM

These have been obsolete since c/s 053ae230 "x86/vvmx: Remove enum vmx_regs_enc".

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw

PATCH 2/4 x86/vvmx: Correct the INVALID_PADDR checks for VMPTRLD/VMCLEAR

In reply to Andrew Cooper

The referenced addresses also need checking against MAXPHYSADDR.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>

---
 xen/arch/x86/hvm/vmx/vvmx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/vmx/vvmx.c +2 -2
index c296660..5daab82 100644
@@ -1672,7 +1672,7 @@ static int nvmx_handle_vmptrld(struct cpu_user_regs *regs)
     if ( rc != X86EMUL_OKAY )
         return rc;
 
-    if ( gpa & 0xfff )
+    if ( (gpa & ~PAGE_MASK) || !gfn_valid(v->domain, gaddr_to_gfn(gpa)) )
     {
         vmfail(regs, VMX_INSN_VMPTRLD_INVALID_PHYADDR);
         goto out;
@@ -1780,7 +1780,7 @@ static int nvmx_handle_vmclear(struct cpu_user_regs *regs)
         goto out;
     }
 
-    if ( gpa & 0xfff )
+    if ( (gpa & ~PAGE_MASK) || !gfn_valid(v->domain, gaddr_to_gfn(gpa)) )
     {
         vmfail(regs, VMX_INSN_VMCLEAR_INVALID_PHYADDR);
         goto out;
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 2/4
#5 lore raw

Re: [PATCH 2/4] x86/vvmx: Correct the INVALID_PADDR checks for VMPTRLD/VMCLEAR

Quoted 3 lines · Andrew Cooper

The referenced addresses also need checking against MAXPHYSADDR.

Quoted 16 lines

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>

---
 xen/arch/x86/hvm/vmx/vvmx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/vmx/vvmx.c +0 -0
index c296660..5daab82 100644

xen/arch/x86/hvm/vmx/vvmx.c static int nvmx_handle_vmptrld(struct cpu_user_regs *regs) · line 1675

Quoted 5 lines
xen/arch/x86/hvm/vmx/vvmx.c +1 -1
@@ -1672,7 +1672,7 @@ static int nvmx_handle_vmptrld(struct cpu_user_regs *regs)
     if ( rc != X86EMUL_OKAY )
         return rc;
 
-    if ( gpa & 0xfff )
+    if ( (gpa & ~PAGE_MASK) || !gfn_valid(v->domain, gaddr_to_gfn(gpa)) )

Seeing this is repeated in several places, it might be helpful to introduce a helper?

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v1 2/4
#6 lore raw

Re: [PATCH 2/4] x86/vvmx: Correct the INVALID_PADDR checks for VMPTRLD/VMCLEAR

In reply to Andrew Cooper
Quoted 6 lines

From: Andrew Cooper [mailto:[email protected]]
Sent: Thursday, November 15, 2018 9:53 PM

The referenced addresses also need checking against MAXPHYSADDR.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw

PATCH 3/4 x86/vvmx: Fixes to VMWRITE emulation

In reply to Andrew Cooper

* Don't assume that decode_vmx_inst() always returns X86EMUL_EXCEPTION.
* The okay boolean is never written, making the else case dead.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>

---
 xen/arch/x86/hvm/vmx/vvmx.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
xen/arch/x86/hvm/vmx/vvmx.c +5 -7
index 5daab82..41c4e2f 100644
@@ -1872,11 +1872,12 @@ static int nvmx_handle_vmwrite(struct cpu_user_regs *regs)
     struct vmx_inst_decoded decode;
     unsigned long operand; 
     u64 vmcs_encoding;
-    bool_t okay = 1;
     enum vmx_insn_errno err;
+    int rc;
 
-    if ( decode_vmx_inst(regs, &decode, &operand) != X86EMUL_OKAY )
-        return X86EMUL_EXCEPTION;
+    rc = decode_vmx_inst(regs, &decode, &operand);
+    if ( rc != X86EMUL_OKAY )
+        return rc;
 
     if ( !vvmcx_valid(v) )
     {
@@ -1905,10 +1906,7 @@ static int nvmx_handle_vmwrite(struct cpu_user_regs *regs)
         break;
     }
 
-    if ( okay )
-        vmsucceed(regs);
-    else
-        vmfail_valid(regs, VMX_INSN_UNSUPPORTED_VMCS_COMPONENT);
+    vmsucceed(regs);
 
     return X86EMUL_OKAY;
 }
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 3/4
#8 lore raw

Re: [PATCH 3/4] x86/vvmx: Fixes to VMWRITE emulation

Quoted 4 lines · Andrew Cooper

* Don't assume that decode_vmx_inst() always returns X86EMUL_EXCEPTION.
* The okay boolean is never written, making the else case dead.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v1 3/4
#9 lore raw

Re: [PATCH 3/4] x86/vvmx: Fixes to VMWRITE emulation

In reply to Andrew Cooper
Quoted 8 lines

From: Andrew Cooper [mailto:[email protected]]
Sent: Thursday, November 15, 2018 9:53 PM

* Don't assume that decode_vmx_inst() always returns
X86EMUL_EXCEPTION.
* The okay boolean is never written, making the else case dead.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#10 lore raw

PATCH 4/4 x86/vvmx: Don't call vmsucceed() at the end of virtual_vmexit()

In reply to Andrew Cooper

This ends up corrupting L1's view of RFLAGS by setting ZF. The correct value is established earlier in the function.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>

---
 xen/arch/x86/hvm/vmx/vvmx.c | 1 -
 1 file changed, 1 deletion(-)
xen/arch/x86/hvm/vmx/vvmx.c +0 -1
index 41c4e2f..a72b519 100644
@@ -1371,7 +1371,6 @@ static void virtual_vmexit(struct cpu_user_regs *regs)
         nvmx_update_apicv(v);
 
     nvcpu->nv_vmswitch_in_progress = 0;
-    vmsucceed(regs);
 }
 
 static void nvmx_eptp_update(void)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 4/4
#11 lore raw

Re: [PATCH 4/4] x86/vvmx: Don't call vmsucceed() at the end of virtual_vmexit()

Quoted 4 lines · Andrew Cooper

This ends up corrupting L1's view of RFLAGS by setting ZF. The correct value is established earlier in the function.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#12 lore raw

Re: [PATCH 4/4] x86/vvmx: Don't call vmsucceed() at the end of virtual_vmexit()

In reply to Andrew Cooper
Quoted 2 lines · Andrew Cooper

This ends up corrupting L1's view of RFLAGS by setting ZF. The correct value is established earlier in the function.

vmsucceed() doesn't set any flags, only clears some. And in this function it's just redundant. ZF is set by VMfailValid. So I think the description must be changed.

--
Sergey

Quoted 18 lines

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>

---
 xen/arch/x86/hvm/vmx/vvmx.c | 1 -
 1 file changed, 1 deletion(-)
xen/arch/x86/hvm/vmx/vvmx.c +0 -0
index 41c4e2f..a72b519 100644

xen/arch/x86/hvm/vmx/vvmx.c static void virtual_vmexit(struct cpu_user_regs *regs) · line 1376

Quoted 7 lines
xen/arch/x86/hvm/vmx/vvmx.c +0 -1
@@ -1371,7 +1371,6 @@ static void virtual_vmexit(struct cpu_user_regs *regs)
         nvmx_update_apicv(v);
 
     nvcpu->nv_vmswitch_in_progress = 0;
-    vmsucceed(regs);
 }
 
 static void nvmx_eptp_update(void)

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#13 lore raw

Re: [PATCH 4/4] x86/vvmx: Don't call vmsucceed() at the end of virtual_vmexit()

Quoted 6 lines · Sergey Dyasli
Quoted 2 lines · Andrew Cooper

This ends up corrupting L1's view of RFLAGS by setting ZF. The correct value is established earlier in the function.

vmsucceed() doesn't set any flags, only clears some. And in this function it's just redundant. ZF is set by VMfailValid. So I think the description must be changed.

Oh - so it does.  Yes - I was confusing it with the failvalid case. I'll fix the wording to "The correct RFLAGS value is established earlier in the function, and this call has no net effect."

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#14 lore raw

Re: [PATCH 4/4] x86/vvmx: Don't call vmsucceed() at the end of virtual_vmexit()

Quoted 8 lines

From: Andrew Cooper [mailto:[email protected]]
Sent: Thursday, November 15, 2018 11:31 PM

Quoted 2 lines · Sergey Dyasli
Quoted 1 line · Andrew Cooper

This ends up corrupting L1's view of RFLAGS by setting ZF. The correct

value

Quoted 1 line
Quoted 1 line

is established earlier in the function.

Quoted 9 lines
Quoted 1 line

vmsucceed() doesn't set any flags, only clears some. And in this function

it's

Quoted 2 lines

just redundant. ZF is set by VMfailValid. So I think the description must be changed.

Oh - so it does.  Yes - I was confusing it with the failvalid case. I'll fix the wording to "The correct RFLAGS value is established earlier in the function, and this call has no net effect."

with wording fixed, Acked-by: Kevin Tian <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on the v1 series
#15 lore raw
In reply to Andrew Cooper
Quoted 7 lines · Andrew Cooper

All from code inspection

Andrew Cooper (4):
x86/vvmx: Drop unused CASE_{GET,SET}_REG() macros x86/vvmx: Correct the INVALID_PADDR checks for VMPTRLD/VMCLEAR x86/vvmx: Fixes to VMWRITE emulation
x86/vvmx: Don't call vmsucceed() at the end of virtual_vmexit()

--
Thanks,
Sergey

Quoted 3 lines
 xen/arch/x86/hvm/vmx/vvmx.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#16 lore raw
In reply to Andrew Cooper

Ping VT-x.

Quoted 11 lines · Andrew Cooper

All from code inspection

Andrew Cooper (4):
x86/vvmx: Drop unused CASE_{GET,SET}_REG() macros x86/vvmx: Correct the INVALID_PADDR checks for VMPTRLD/VMCLEAR x86/vvmx: Fixes to VMWRITE emulation
x86/vvmx: Don't call vmsucceed() at the end of virtual_vmexit()

 xen/arch/x86/hvm/vmx/vvmx.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel