x86/vmx: Don't use hvm_inject_hw_exception() in long_mode_do_msr_write()
PATCH v2 1/2 x86/vmx: Don't use hvm_inject_hw_exception() in long_mode_do_msr_write()
Since c/s 49de10f3c1718 "x86/hvm: Don't raise #GP behind the emulators back for MSR accesses", returning X86EMUL_EXCEPTION has pushed the exception generation to the top of the call tree.
Using hvm_inject_hw_exception() and returning X86EMUL_EXCEPTION causes a double #GP injection, which combines to #DF.
---
CC: Jan Beulich <[email protected]>
v2:
* Drop uncanonical_address and return HNDL_exception_raised directly
This wants backporting to 4.9
--- xen/arch/x86/hvm/vmx/vmx.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +3 -8
@@ -542,7 +542,7 @@ long_mode_do_msr_write(unsigned int msr, uint64_t msr_content)case MSR_GS_BASE :case MSR_SHADOW_GS_BASE :if ( !is_canonical_address (msr_content) ) - goto uncanonical_address; +return HNDL_exception_raised;if ( msr ==MSR_FS_BASE )__vmwrite (GUEST_FS_BASE , msr_content);
@@ -560,14 +560,14 @@ long_mode_do_msr_write(unsigned int msr, uint64_t msr_content)case MSR_LSTAR :if ( !is_canonical_address (msr_content) ) - goto uncanonical_address; +return HNDL_exception_raised; v->arch.hvm_vmx.lstar = msr_content;wrmsrl (MSR_LSTAR , msr_content);break ;case MSR_CSTAR :if ( !is_canonical_address (msr_content) ) - goto uncanonical_address; +return HNDL_exception_raised; v->arch.hvm_vmx.cstar = msr_content;break ;
@@ -581,11 +581,6 @@ long_mode_do_msr_write(unsigned int msr, uint64_t msr_content) }return HNDL_done; - - uncanonical_address: -HVM_DBG_LOG (DBG_LEVEL_MSR ,"Not cano address of msr write %x" , msr); -hvm_inject_hw_exception (TRAP_gp_fault,0 ); -return HNDL_exception_raised; }/*
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 2/2 x86/vmx: Drop enum handler_return
They are straight aliases of the more common X86EMUL_* constants. While adjusting these, fix the case indentation where appropriate.
No functional change, confirmed by diff'ing the compiled binary.
---
CC: Jan Beulich <[email protected]>
v2:
* Rebase over changes in patch 1
* Drop redundant case labels
--- xen/arch/x86/hvm/vmx/vmx.c | 68 +++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 37 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +31 -37
@@ -62,8 +62,6 @@static bool_t __initdata opt_force_ept;boolean_param ("force-ept" , opt_force_ept); -enum handler_return { HNDL_done, HNDL_unhandled, HNDL_exception_raised }; -static void vmx_ctxt_switch_from (struct vcpu *v);static void vmx_ctxt_switch_to (struct vcpu *v);
@@ -485,8 +483,7 @@ static void vmx_vcpu_destroy(struct vcpu *v)passive_domain_destroy (v); } -static enum handler_return -long_mode_do_msr_read (unsigned int msr,uint64_t *msr_content) +static int long_mode_do_msr_read (unsigned int msr,uint64_t *msr_content) {struct vcpu *v = current;
@@ -521,16 +518,15 @@ long_mode_do_msr_read(unsigned int msr, uint64_t *msr_content)break ;default : -return HNDL_unhandled; +return X86EMUL_UNHANDLEABLE ; }HVM_DBG_LOG (DBG_LEVEL_MSR ,"msr %#x content %#" PRIx64, msr, *msr_content); -return HNDL_done; +return X86EMUL_OKAY ; } -static enum handler_return -long_mode_do_msr_write (unsigned int msr,uint64_t msr_content) +static int long_mode_do_msr_write (unsigned int msr,uint64_t msr_content) {struct vcpu *v = current;
@@ -542,7 +538,7 @@ long_mode_do_msr_write(unsigned int msr, uint64_t msr_content)case MSR_GS_BASE :case MSR_SHADOW_GS_BASE :if ( !is_canonical_address (msr_content) ) -return HNDL_exception_raised; +return X86EMUL_EXCEPTION ;if ( msr ==MSR_FS_BASE )__vmwrite (GUEST_FS_BASE , msr_content);
@@ -560,14 +556,14 @@ long_mode_do_msr_write(unsigned int msr, uint64_t msr_content)case MSR_LSTAR :if ( !is_canonical_address (msr_content) ) -return HNDL_exception_raised; +return X86EMUL_EXCEPTION ; v->arch.hvm_vmx.lstar = msr_content;wrmsrl (MSR_LSTAR , msr_content);break ;case MSR_CSTAR :if ( !is_canonical_address (msr_content) ) -return HNDL_exception_raised; +return X86EMUL_EXCEPTION ; v->arch.hvm_vmx.cstar = msr_content;break ;
@@ -577,10 +573,10 @@ long_mode_do_msr_write(unsigned int msr, uint64_t msr_content)break ;default : -return HNDL_unhandled; +return X86EMUL_UNHANDLEABLE ; } -return HNDL_done; +return X86EMUL_OKAY ; }/*
@@ -2934,12 +2930,11 @@ static int vmx_msr_read_intercept(unsigned int msr, uint64_t *msr_content) goto done;switch (long_mode_do_msr_read (msr, msr_content) ) { -case HNDL_unhandled: -break ; -case HNDL_exception_raised: -return X86EMUL_EXCEPTION ; -case HNDL_done: - goto done; +case X86EMUL_EXCEPTION : +return X86EMUL_EXCEPTION ; + +case X86EMUL_OKAY : + goto done; }if (vmx_read_guest_msr (msr, msr_content) ==0 )
@@ -3158,24 +3153,23 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)switch (long_mode_do_msr_write (msr, msr_content) ) { -case HNDL_unhandled: -if ( (vmx_write_guest_msr (msr, msr_content) !=0 ) && - !is_last_branch_msr (msr) ) -switch (wrmsr_hypervisor_regs (msr, msr_content) ) - { -case -ERESTART : -return X86EMUL_RETRY ; -case 0 : -case 1 : -break ; -default : - goto gp_fault; - } -break ; -case HNDL_exception_raised: -return X86EMUL_EXCEPTION ; -case HNDL_done: -break ; +case X86EMUL_UNHANDLEABLE : +if ( (vmx_write_guest_msr (msr, msr_content) !=0 ) && + !is_last_branch_msr (msr) ) +switch (wrmsr_hypervisor_regs (msr, msr_content) ) + { +case -ERESTART : +return X86EMUL_RETRY ; +case 0 : +case 1 : +break ; +default : + goto gp_fault; + } +break ; + +case X86EMUL_EXCEPTION : +return X86EMUL_EXCEPTION ; }break ; }
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 2/2] x86/vmx: Drop enum handler_return
Quoted 32 lines
Quoted 1 line
Quoted 1 line · On 13.12.17 at 11:50, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmx.c +9
-18@@ -3158,24 +3153,23 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)switch (long_mode_do_msr_write (msr, msr_content) ) { -case HNDL_unhandled: -if ( (vmx_write_guest_msr (msr, msr_content) !=0 ) && - !is_last_branch_msr (msr) ) -switch (wrmsr_hypervisor_regs (msr, msr_content) ) - { -case -ERESTART : -return X86EMUL_RETRY ; -case 0 : -case 1 : -break ; -default : - goto gp_fault; - } -break ; -case HNDL_exception_raised: -return X86EMUL_EXCEPTION ; -case HNDL_done: -break ; +case X86EMUL_UNHANDLEABLE : +if ( (vmx_write_guest_msr (msr, msr_content) !=0 ) && + !is_last_branch_msr (msr) ) +switch (wrmsr_hypervisor_regs (msr, msr_content) ) + { +case -ERESTART : +return X86EMUL_RETRY ; +case 0 : +case 1 :
xen/arch/x86/hvm/vmx/vmx.c static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content) · line 3174
Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c +8
-0+break ; +default : + goto gp_fault; + } +break ; + +case X86EMUL_EXCEPTION : +return X86EMUL_EXCEPTION ; }break ;
Wouldn't this better be
case X86EMUL_OKAY:
break;
default:
return <value-from-long_mode_do_msr_write()>;
}for this code to be independent of later uses of other X86EMUL_* values in long_mode_do_msr_write()?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 13.12.17 at 11:50, <[email protected]> wrote:
Since c/s
49de10f3c1718"x86/hvm: Don't raise #GP behind the emulators back for MSR accesses", returningX86EMUL_EXCEPTIONhas pushed the exception generation to the top of the call tree.Using
hvm_inject_hw_exception()and returningX86EMUL_EXCEPTIONcauses a double #GP injection, which combines to #DF.Signed-off-by Andrew Cooper <[email protected]>Acked-by Kevin Tian <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel