x86/AMD: Fix nested svm crash due to assertion in __virt_to_maddr
PATCH v2 1/1 x86/AMD: Fix nested svm crash due to assertion in __virt_to_maddr
From: Suravee Suthikulpanit <[email protected]>
Fix assertion in __virt_to_maddr when starting nested SVM guest in debug mode. Investigation has shown that svm_vmsave/svm_vmload make use of __pa() with invalid address.
---
Changes in V2:
- Uses paddr_t instead of uint64_t (suggested by Tim).
- Rename the nestedsvm_vmxxxx() to svm_vmxxxx_by_paddr() (suggested by Tim).
- Wrapped svm_vmxxxx_by_paddr() with svm_vmxxxx() (suggested by Jan).
xen/arch/x86/hvm/svm/svm.c | 4 ++-- xen/include/asm-x86/hvm/svm/svm.h | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-)
xen/arch/x86/hvm/svm/svm.c +2 -2
@@ -1816,7 +1816,7 @@ svm_vmexit_do_vmload(struct vmcb_struct *vmcb, goto inject; } -svm_vmload (nv->nv_vvmcx); +svm_vmload_by_paddr (nv->nv_vvmcxaddr);/* State in L1 VMCB is stale now */ v->arch.hvm_svm.vmcb_in_sync =0 ;
@@ -1852,7 +1852,7 @@ svm_vmexit_do_vmsave(struct vmcb_struct *vmcb, goto inject; } -svm_vmsave (nv->nv_vvmcx); +svm_vmsave_by_paddr (nv->nv_vvmcxaddr);__update_guest_eip (regs, inst_len);return ;
xen/include/asm-x86/hvm/svm/svm.h +14 -4
@@ -41,18 +41,28 @@#define SVM_REG_R14 (14)#define SVM_REG_R15 (15) -static inline void svm_vmload (void *vmcb) +static inline void svm_vmload_by_paddr (paddr_t vmcb) { asmvolatile (".byte 0x0f,0x01,0xda" /* vmload */ - : :"a" (__pa (vmcb)) :"memory" ); + : :"a" (vmcb) :"memory" ); } -static inline void svm_vmsave (void *vmcb) +static inline void svm_vmsave_by_paddr (paddr_t vmcb) { asmvolatile (".byte 0x0f,0x01,0xdb" /* vmsave */ - : :"a" (__pa (vmcb)) :"memory" ); + : :"a" (vmcb) :"memory" ); +} + +static inline void svm_vmload (void *vmcb) +{ +svm_vmload_by_paddr (__pa (vmcb)); +} + +static inline void svm_vmsave (void *vmcb) +{ +svm_vmsave_by_paddr (__pa (vmcb)); }static inline void svm_invlpga (unsigned long vaddr,uint32_t asid)
Signature · 1 line
1.7.10.4
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 06.07.13 at 00:10, <[email protected]> wrote:
xen/arch/x86/hvm/svm/svm.c +1
-1@@ -1816,7 +1816,7 @@ svm_vmexit_do_vmload(struct vmcb_struct *vmcb, goto inject; } -svm_vmload (nv->nv_vvmcx); +svm_vmload_by_paddr (nv->nv_vvmcxaddr);/* State in L1 VMCB is stale now */ v->arch.hvm_svm.vmcb_in_sync =0 ;
xen/arch/x86/hvm/svm/svm.c svm_vmexit_do_vmsave(struct vmcb_struct *vmcb, · line 1858
Quoted 8 lines
xen/arch/x86/hvm/svm/svm.c +1
-1@@ -1852,7 +1852,7 @@ svm_vmexit_do_vmsave(struct vmcb_struct *vmcb, goto inject; } -svm_vmsave (nv->nv_vvmcx); +svm_vmsave_by_paddr (nv->nv_vvmcxaddr);__update_guest_eip (regs, inst_len);return ;
As said on the previous version already - from all I can tell these are GPAs, not PAs, and hence can't be passed untranslated to VMLOAD/VMSAVE. If I'm right with this, I also can't see how this would have worked for you...
Apart from that I also dislike the _by_paddr suffix. I'd suggest either just _pa, or (slightly preferable) prefixing the names with a double underscore instead.
Jan
Quoted 17 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 06.07.13 at 00:10, <[email protected]> wrote:
xen/arch/x86/hvm/svm/svm.c +2
-2@@ -1816,7 +1816,7 @@ svm_vmexit_do_vmload(struct vmcb_struct *vmcb, goto inject; } -svm_vmload (nv->nv_vvmcx); +svm_vmload_by_paddr (nv->nv_vvmcxaddr);/* State in L1 VMCB is stale now */ v->arch.hvm_svm.vmcb_in_sync =0 ;@@ -1852,7 +1852,7 @@ svm_vmexit_do_vmsave(struct vmcb_struct *vmcb, goto inject; } -svm_vmsave (nv->nv_vvmcx); +svm_vmsave_by_paddr (nv->nv_vvmcxaddr);
Quoted 7 lines
xen/arch/x86/hvm/svm/svm.c svm_vmexit_do_vmsave(struct vmcb_struct *vmcb, · line 1858
Quoted 2 lines
xen/arch/x86/hvm/svm/svm.c +0
-0__update_guest_eip (regs, inst_len);return ;As said on the previous version already - from all I can tell these are GPAs, not PAs, and hence can't be passed untranslated to VMLOAD/VMSAVE. If I'm right with this, I also can't see how this would have worked for you...
You can translate GPA->PA with the hostp2m.
Quoted 3 lines
Apart from that I also dislike the
_by_paddrsuffix. I'd suggest either just_pa, or (slightly preferable) prefixing the names with a double underscore instead.
I prefer _pa suffix over the latter.
Christoph
Quoted 27 lines
Quoted 1 line
Quoted 1 line · Christoph
Quoted 17 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 06.07.13 at 00:10, <[email protected]> wrote:
xen/arch/x86/hvm/svm/svm.c +2
-2@@ -1816,7 +1816,7 @@ svm_vmexit_do_vmload(struct vmcb_struct *vmcb, goto inject; } -svm_vmload (nv->nv_vvmcx); +svm_vmload_by_paddr (nv->nv_vvmcxaddr);/* State in L1 VMCB is stale now */ v->arch.hvm_svm.vmcb_in_sync =0 ;@@ -1852,7 +1852,7 @@ svm_vmexit_do_vmsave(struct vmcb_struct *vmcb, goto inject; } -svm_vmsave (nv->nv_vvmcx); +svm_vmsave_by_paddr (nv->nv_vvmcxaddr);Quoted 7 lines
xen/arch/x86/hvm/svm/svm.c svm_vmexit_do_vmsave(struct vmcb_struct *vmcb, · line 1858
Quoted 2 lines
xen/arch/x86/hvm/svm/svm.c +0
-0__update_guest_eip (regs, inst_len);return ;As said on the previous version already - from all I can tell these are GPAs, not PAs, and hence can't be passed untranslated to VMLOAD/VMSAVE. If I'm right with this, I also can't see how this would have worked for you...
Quoted 1 line
You can translate
GPA->PAwith the hostp2m.
I don't think I understand what you're trying to tell me with this.
Jan
Quoted 27 lines · Jan Beulich
Quoted 27 lines
Quoted 1 line
Quoted 1 line · Christoph
Quoted 24 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 06.07.13 at 00:10, <[email protected]> wrote:
xen/arch/x86/hvm/svm/svm.c +1
-1@@ -1816,7 +1816,7 @@ svm_vmexit_do_vmload(struct vmcb_struct *vmcb, goto inject; } -svm_vmload (nv->nv_vvmcx); +svm_vmload_by_paddr (nv->nv_vvmcxaddr);/* State in L1 VMCB is stale now */ v->arch.hvm_svm.vmcb_in_sync =0 ;xen/arch/x86/hvm/svm/svm.c svm_vmexit_do_vmsave(struct vmcb_struct *vmcb, · line 1858
Quoted 8 lines
xen/arch/x86/hvm/svm/svm.c +1
-1@@ -1852,7 +1852,7 @@ svm_vmexit_do_vmsave(struct vmcb_struct *vmcb, goto inject; } -svm_vmsave (nv->nv_vvmcx); +svm_vmsave_by_paddr (nv->nv_vvmcxaddr);__update_guest_eip (regs, inst_len);return ;As said on the previous version already - from all I can tell these are GPAs, not PAs, and hence can't be passed untranslated to VMLOAD/VMSAVE. If I'm right with this, I also can't see how this would have worked for you...
Quoted 3 lines
Quoted 1 line
You can translate
GPA->PAwith the hostp2m.I don't think I understand what you're trying to tell me with this.
This information is supposed for suravee. Sorry for being unclear.
Christoph
Quoted 25 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 06.07.13 at 00:10, <[email protected]> wrote:
xen/arch/x86/hvm/svm/svm.c +1
-1@@ -1816,7 +1816,7 @@ svm_vmexit_do_vmload(struct vmcb_struct *vmcb, goto inject; } -svm_vmload (nv->nv_vvmcx); +svm_vmload_by_paddr (nv->nv_vvmcxaddr);/* State in L1 VMCB is stale now */ v->arch.hvm_svm.vmcb_in_sync =0 ;xen/arch/x86/hvm/svm/svm.c svm_vmexit_do_vmsave(struct vmcb_struct *vmcb, · line 1858
Quoted 8 lines
xen/arch/x86/hvm/svm/svm.c +1
-1@@ -1852,7 +1852,7 @@ svm_vmexit_do_vmsave(struct vmcb_struct *vmcb, goto inject; } -svm_vmsave (nv->nv_vvmcx); +svm_vmsave_by_paddr (nv->nv_vvmcxaddr);__update_guest_eip (regs, inst_len);return ;As said on the previous version already - from all I can tell these are GPAs, not PAs, and hence can't be passed untranslated to VMLOAD/VMSAVE. If I'm right with this, I also can't see how this would have worked for you...
Quoted 3 lines
Apart from that I also dislike the
_by_paddrsuffix. I'd suggest either just_pa, or (slightly preferable) prefixing the names with a double underscore instead.
I prefer the _pa suffix; it carries a reminder of what this version does.
Tim.