[Xen-devel] [PATCH v5 05/14] x86/HVM: eliminate custom #MF/#XM handling

2018-03-15 Thread Jan Beulich
Use the generic stub exception handling instead.

Signed-off-by: Jan Beulich 
Reviewed-by: Paul Durrant 
Acked-by: Andrew Cooper 
---
v4: Re-base.
v3: Re-base.
v2: Re-base.

--- a/tools/tests/x86_emulator/x86-emulate.c
+++ b/tools/tests/x86_emulator/x86-emulate.c
@@ -193,8 +193,6 @@ int emul_test_read_xcr(
 }
 
 int emul_test_get_fpu(
-void (*exception_callback)(void *, struct cpu_user_regs *),
-void *exception_callback_arg,
 enum x86_emulate_fpu_type type,
 struct x86_emulate_ctxt *ctxt)
 {
--- a/tools/tests/x86_emulator/x86-emulate.h
+++ b/tools/tests/x86_emulator/x86-emulate.h
@@ -263,8 +263,6 @@ int emul_test_read_xcr(
 struct x86_emulate_ctxt *ctxt);
 
 int emul_test_get_fpu(
-void (*exception_callback)(void *, struct cpu_user_regs *),
-void *exception_callback_arg,
 enum x86_emulate_fpu_type type,
 struct x86_emulate_ctxt *ctxt);
 
--- a/xen/arch/x86/hvm/emulate.c
+++ b/xen/arch/x86/hvm/emulate.c
@@ -1890,8 +1890,6 @@ int hvmemul_cpuid(uint32_t leaf, uint32_
 }
 
 static int hvmemul_get_fpu(
-void (*exception_callback)(void *, struct cpu_user_regs *),
-void *exception_callback_arg,
 enum x86_emulate_fpu_type type,
 struct x86_emulate_ctxt *ctxt)
 {
@@ -1929,9 +1927,6 @@ static int hvmemul_get_fpu(
 }
 }
 
-curr->arch.hvm_vcpu.fpu_exception_callback = exception_callback;
-curr->arch.hvm_vcpu.fpu_exception_callback_arg = exception_callback_arg;
-
 return X86EMUL_OKAY;
 }
 
@@ -1942,8 +1937,6 @@ static void hvmemul_put_fpu(
 {
 struct vcpu *curr = current;
 
-curr->arch.hvm_vcpu.fpu_exception_callback = NULL;
-
 if ( aux )
 {
 typeof(curr->arch.xsave_area->fpu_sse) *fpu_ctxt = curr->arch.fpu_ctxt;
--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -729,7 +729,6 @@ static void do_reserved_trap(struct cpu_
 
 static void do_trap(struct cpu_user_regs *regs)
 {
-struct vcpu *curr = current;
 unsigned int trapnr = regs->entry_vector;
 unsigned long fixup;
 
@@ -749,15 +748,6 @@ static void do_trap(struct cpu_user_regs
 return;
 }
 
-if ( ((trapnr == TRAP_copro_error) || (trapnr == TRAP_simd_error)) &&
- system_state >= SYS_STATE_active && is_hvm_vcpu(curr) &&
- curr->arch.hvm_vcpu.fpu_exception_callback )
-{
-curr->arch.hvm_vcpu.fpu_exception_callback(
-curr->arch.hvm_vcpu.fpu_exception_callback_arg, regs);
-return;
-}
-
 if ( likely((fixup = search_exception_table(regs)) != 0) )
 {
 dprintk(XENLOG_ERR, "Trap %u: %p [%ps] -> %p\n",
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -1094,23 +1094,8 @@ do {
 ops->write_segment(x86_seg_cs, cs, ctxt);   \
 })
 
-struct fpu_insn_ctxt {
-uint8_t insn_bytes;
-uint8_t type;
-int8_t exn_raised;
-};
-
-static void fpu_handle_exception(void *_fic, struct cpu_user_regs *regs)
-{
-struct fpu_insn_ctxt *fic = _fic;
-ASSERT(regs->entry_vector < 0x20);
-fic->exn_raised = regs->entry_vector;
-regs->r(ip) += fic->insn_bytes;
-}
-
 static int _get_fpu(
 enum x86_emulate_fpu_type type,
-struct fpu_insn_ctxt *fic,
 struct x86_emulate_ctxt *ctxt,
 const struct x86_emulate_ops *ops)
 {
@@ -1138,14 +1123,13 @@ static int _get_fpu(
 break;
 }
 
-rc = ops->get_fpu(fpu_handle_exception, fic, type, ctxt);
+rc = ops->get_fpu(type, ctxt);
 
 if ( rc == X86EMUL_OKAY )
 {
 unsigned long cr0;
 
 fail_if(type == X86EMUL_FPU_fpu && !ops->put_fpu);
-fic->type = type;
 
 fail_if(!ops->read_cr);
 if ( type >= X86EMUL_FPU_xmm )
@@ -1183,37 +1167,22 @@ static int _get_fpu(
 return rc;
 }
 
-#define get_fpu(_type, _fic)\
+#define get_fpu(type)   \
 do {\
-rc = _get_fpu(_type, _fic, ctxt, ops);  \
+rc = _get_fpu(fpu_type = (type), ctxt, ops);\
 if ( rc ) goto done;\
 } while (0)
 
-#define check_fpu_exn(fic)  \
-do {\
-generate_exception_if((fic)->exn_raised >= 0,   \
-  (fic)->exn_raised);   \
-} while (0)
-
-#define check_xmm_exn(fic)  \
-do {\
-if ( (fic)->exn_raised == EXC_XM && ops->read_cr && \
- ops->read_cr(4, &cr4, ctxt) == X86EMUL_OKAY && \
- !(cr4 & X86_CR4_OSXMMEXCPT) )  \
-(fic)->exn_raised = EXC_UD; \
-check_fpu_exn(fic); \
-} while (0)
-
 static void put_fpu(
-struct fpu_insn_ctxt *fic,
+enum x8

Re: [Xen-devel] [PATCH v5 05/14] x86/HVM: eliminate custom #MF/#XM handling

2018-03-22 Thread Roger Pau Monné
On Thu, Mar 15, 2018 at 07:06:36AM -0600, Jan Beulich wrote:
> @@ -8478,7 +8411,8 @@ x86_emulate(
>  }
>  
>   complete_insn: /* Commit shadow register state. */
> -put_fpu(&fic, false, state, ctxt, ops);
> +put_fpu(fpu_type, false, state, ctxt, ops);
> +fpu_type = X86EMUL_FPU_none;
>  
>  /* Zero the upper 32 bits of %rip if not in 64-bit mode. */
>  if ( !mode_64bit() )
> @@ -8502,13 +8436,22 @@ x86_emulate(
>  ctxt->regs->eflags &= ~X86_EFLAGS_RF;
>  
>   done:
> -put_fpu(&fic, fic.insn_bytes > 0 && dst.type == OP_MEM, state, ctxt, 
> ops);
> +put_fpu(fpu_type, insn_bytes > 0 && dst.type == OP_MEM, state, ctxt, 
> ops);
>  put_stub(stub);
>  return rc;
>  #undef state
>  
>  #ifdef __XEN__
>   emulation_stub_failure:
> +generate_exception_if(stub_exn.info.fields.trapnr == EXC_MF, EXC_MF);
> +if ( stub_exn.info.fields.trapnr == EXC_XM )
> +{
> +unsigned long cr4;
> +
> +if ( !ops->read_cr || !ops->read_cr(4, &cr4, ctxt) == X86EMUL_OKAY )

Is the second expression in the above line missing parentheses:

if ( !ops->read_cr || !(ops->read_cr(4, &cr4, ctxt) == X86EMUL_OKAY) )

Or should this be:

if ( !ops->read_cr || ops->read_cr(4, &cr4, ctxt) != X86EMUL_OKAY )

clang complains with:

In file included from x86_emulate.c:44:
./x86_emulate/x86_emulate.c:8665:31: error: logical not is only applied to the 
left hand side of
  this comparison [-Werror,-Wlogical-not-parentheses]
if ( !ops->read_cr || !ops->read_cr(4, &cr4, ctxt) == X86EMUL_OKAY )
  ^~~
./x86_emulate/x86_emulate.c:8665:31: note: add parentheses after the '!' to 
evaluate the comparison
  first
if ( !ops->read_cr || !ops->read_cr(4, &cr4, ctxt) == X86EMUL_OKAY )
  ^
   (  )
./x86_emulate/x86_emulate.c:8665:31: note: add parentheses around left hand 
side expression to
  silence this warning
if ( !ops->read_cr || !ops->read_cr(4, &cr4, ctxt) == X86EMUL_OKAY )
  ^
  (   )
1 error generated.

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

Re: [Xen-devel] [PATCH v5 05/14] x86/HVM: eliminate custom #MF/#XM handling

2018-03-22 Thread Jan Beulich
>>> On 22.03.18 at 15:12,  wrote:
> On Thu, Mar 15, 2018 at 07:06:36AM -0600, Jan Beulich wrote:
>> @@ -8478,7 +8411,8 @@ x86_emulate(
>>  }
>>  
>>   complete_insn: /* Commit shadow register state. */
>> -put_fpu(&fic, false, state, ctxt, ops);
>> +put_fpu(fpu_type, false, state, ctxt, ops);
>> +fpu_type = X86EMUL_FPU_none;
>>  
>>  /* Zero the upper 32 bits of %rip if not in 64-bit mode. */
>>  if ( !mode_64bit() )
>> @@ -8502,13 +8436,22 @@ x86_emulate(
>>  ctxt->regs->eflags &= ~X86_EFLAGS_RF;
>>  
>>   done:
>> -put_fpu(&fic, fic.insn_bytes > 0 && dst.type == OP_MEM, state, ctxt, 
>> ops);
>> +put_fpu(fpu_type, insn_bytes > 0 && dst.type == OP_MEM, state, ctxt, 
>> ops);
>>  put_stub(stub);
>>  return rc;
>>  #undef state
>>  
>>  #ifdef __XEN__
>>   emulation_stub_failure:
>> +generate_exception_if(stub_exn.info.fields.trapnr == EXC_MF, EXC_MF);
>> +if ( stub_exn.info.fields.trapnr == EXC_XM )
>> +{
>> +unsigned long cr4;
>> +
>> +if ( !ops->read_cr || !ops->read_cr(4, &cr4, ctxt) == X86EMUL_OKAY )
> 
> Is the second expression in the above line missing parentheses:
> 
> if ( !ops->read_cr || !(ops->read_cr(4, &cr4, ctxt) == X86EMUL_OKAY) )
> 
> Or should this be:
> 
> if ( !ops->read_cr || ops->read_cr(4, &cr4, ctxt) != X86EMUL_OKAY )

Oops, yes indeed, the latter. Thanks for the report.

Jan


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