Skip to contentSkip to conversation

x86emul: minor cleanup

PATCH Superseded Jan Beulich 2 participants 7 messages Jun 8, 2017 – Jun 12, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86emul: minor cleanup

Drop a redundant input constraint, correct a comment, and (re)move fix.insn_bytes adjustments (these aren't needed for custom stub invocations when the instruction placed in the stub can't raise #XF) plus a corresponding check_xmm_exn() invocation.

xen/arch/x86/x86_emulate/x86_emulate.c +3 -8
@@ -5681,8 +5681,7 @@ x86_emulate(
                     [eflags] "+g" (_regs.eflags),
                     [tmp] "=&r" (dummy), "+m" (*mmvalp),
                     "+m" (fic.exn_raised)
-                    : [func] "rm" (stub.func), "a" (mmvalp),
-                      [mask] "i" (EFLAGS_MASK));
+                    : "a" (mmvalp), [mask] "i" (EFLAGS_MASK));
 
         put_stub(stub);
         check_xmm_exn(&fic);
@@ -6086,7 +6085,7 @@ x86_emulate(
     case X86EMUL_OPC_F3(0x0f, 0x6f):     /* movdqu xmm/m128,xmm */
     case X86EMUL_OPC_VEX_F3(0x0f, 0x6f): /* vmovdqu {x,y}mm/mem,{x,y}mm */
     case X86EMUL_OPC_66(0x0f, 0x7f):     /* movdqa xmm,xmm/m128 */
-    case X86EMUL_OPC_VEX_66(0x0f, 0x7f): /* vmovdqa {x,y}mm,{x,y}mm/m128 */
+    case X86EMUL_OPC_VEX_66(0x0f, 0x7f): /* vmovdqa {x,y}mm,{x,y}mm/mem */
     case X86EMUL_OPC_F3(0x0f, 0x7f):     /* movdqu xmm,xmm/m128 */
     case X86EMUL_OPC_VEX_F3(0x0f, 0x7f): /* vmovdqu {x,y}mm,{x,y}mm/mem */
     movdqa:
@@ -7022,7 +7021,6 @@ x86_emulate(
         if ( !mode_64bit() )
             vex.w = 0;
         opc[1] = modrm & 0xc7;
-        fic.insn_bytes = PFX_BYTES + 2;
         opc[2] = 0xc3;
 
         copy_REX_VEX(opc, rex_prefix, vex);
@@ -7035,6 +7033,7 @@ x86_emulate(
         opc = init_prefixes(stub);
         opc[0] = b;
         opc[1] = modrm;
+        fic.insn_bytes = PFX_BYTES + 2;
         /* Restore high bit of XMM destination. */
         if ( sfence )
         {
@@ -7469,20 +7468,16 @@ x86_emulate(
             vex.w = 0;
         opc[1] = modrm & 0x38;
         opc[2] = imm1;
-        fic.insn_bytes = PFX_BYTES + 3;
         opc[3] = 0xc3;
         if ( vex.opcx == vex_none )
         {
             /* Cover for extra prefix byte. */
             --opc;
-            ++fic.insn_bytes;
         }
 
         copy_REX_VEX(opc, rex_prefix, vex);
         invoke_stub("", "", "=m" (dst.val) : "a" (&dst.val));
-
         put_stub(stub);
-        check_xmm_exn(&fic);
 
         ASSERT(!state->simd_size);
         dst.bytes = dst.type == OP_REG || b == 0x17 ? 4 : 1 << (b & 3);

x86emul: minor cleanup

Drop a redundant input constraint, correct a comment, and (re)move fix.insn_bytes adjustments (these aren't needed for custom stub invocations when the instruction placed in the stub can't raise #XF) plus a corresponding check_xmm_exn() invocation.

xen/arch/x86/x86_emulate/x86_emulate.c +3 -8
@@ -5681,8 +5681,7 @@ x86_emulate(
                     [eflags] "+g" (_regs.eflags),
                     [tmp] "=&r" (dummy), "+m" (*mmvalp),
                     "+m" (fic.exn_raised)
-                    : [func] "rm" (stub.func), "a" (mmvalp),
-                      [mask] "i" (EFLAGS_MASK));
+                    : "a" (mmvalp), [mask] "i" (EFLAGS_MASK));
 
         put_stub(stub);
         check_xmm_exn(&fic);
@@ -6086,7 +6085,7 @@ x86_emulate(
     case X86EMUL_OPC_F3(0x0f, 0x6f):     /* movdqu xmm/m128,xmm */
     case X86EMUL_OPC_VEX_F3(0x0f, 0x6f): /* vmovdqu {x,y}mm/mem,{x,y}mm */
     case X86EMUL_OPC_66(0x0f, 0x7f):     /* movdqa xmm,xmm/m128 */
-    case X86EMUL_OPC_VEX_66(0x0f, 0x7f): /* vmovdqa {x,y}mm,{x,y}mm/m128 */
+    case X86EMUL_OPC_VEX_66(0x0f, 0x7f): /* vmovdqa {x,y}mm,{x,y}mm/mem */
     case X86EMUL_OPC_F3(0x0f, 0x7f):     /* movdqu xmm,xmm/m128 */
     case X86EMUL_OPC_VEX_F3(0x0f, 0x7f): /* vmovdqu {x,y}mm,{x,y}mm/mem */
     movdqa:
@@ -7022,7 +7021,6 @@ x86_emulate(
         if ( !mode_64bit() )
             vex.w = 0;
         opc[1] = modrm & 0xc7;
-        fic.insn_bytes = PFX_BYTES + 2;
         opc[2] = 0xc3;
 
         copy_REX_VEX(opc, rex_prefix, vex);
@@ -7035,6 +7033,7 @@ x86_emulate(
         opc = init_prefixes(stub);
         opc[0] = b;
         opc[1] = modrm;
+        fic.insn_bytes = PFX_BYTES + 2;
         /* Restore high bit of XMM destination. */
         if ( sfence )
         {
@@ -7469,20 +7468,16 @@ x86_emulate(
             vex.w = 0;
         opc[1] = modrm & 0x38;
         opc[2] = imm1;
-        fic.insn_bytes = PFX_BYTES + 3;
         opc[3] = 0xc3;
         if ( vex.opcx == vex_none )
         {
             /* Cover for extra prefix byte. */
             --opc;
-            ++fic.insn_bytes;
         }
 
         copy_REX_VEX(opc, rex_prefix, vex);
         invoke_stub("", "", "=m" (dst.val) : "a" (&dst.val));
-
         put_stub(stub);
-        check_xmm_exn(&fic);
 
         ASSERT(!state->simd_size);
         dst.bytes = dst.type == OP_REG || b == 0x17 ? 4 : 1 << (b & 3);

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

#1 lore raw
Quoted 3 lines · Jan Beulich

Drop a redundant input constraint, correct a comment, and (re)move fix.insn_bytes adjustments (these aren't needed for custom stub invocations when the instruction placed in the stub can't raise #XF)

I'm not sure these are wise to remove. Even if we don't expect an exception, should one occur, fpu_handle_exception() will fail to step over the instruction, and will re-execute it.

~Andrew

Quoted 4 lines

plus a corresponding check_xmm_exn() invocation.

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

#2 lore raw
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 09.06.17 at 19:50, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich

Drop a redundant input constraint, correct a comment, and (re)move fix.insn_bytes adjustments (these aren't needed for custom stub invocations when the instruction placed in the stub can't raise #XF)

I'm not sure these are wise to remove. Even if we don't expect an exception, should one occur, fpu_handle_exception() will fail to step over the instruction, and will re-execute it.

Ah, perhaps I shouldn't have split this off the remaining emulator series I have ready - you refer to a no longer existing function (in my code base). Once there, do_trap() will panic() as usual in that case, which I think it is sort of appropriate if we receive an exception that shouldn't occur - after all we then don't really know what to do with it. This btw goes along the lines of me not really being happy about us handling all sorts of exceptions once an .ex_table entry is associated with an instruction, rather than just the ones we really mean to recover from. You may recall such a discussion from a few years back.

Would you be okay with temporarily adding a respective BUG_ON(!fic->insn_bytes) to fpu_handle_exception() to achieve the same effect?

As a side note, I'm removing these here since the further SIMD emulation patches I have ready, but would prefer to post only once 4.9 is out, do not add respective code in the first place. Without knowing this in advance I'm not even sure this would be reliably spottable during review.

Jan

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

#3 lore raw
Quoted 11 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 09.06.17 at 19:50, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich

Drop a redundant input constraint, correct a comment, and (re)move fix.insn_bytes adjustments (these aren't needed for custom stub invocations when the instruction placed in the stub can't raise #XF)

I'm not sure these are wise to remove. Even if we don't expect an exception, should one occur, fpu_handle_exception() will fail to step over the instruction, and will re-execute it.

Ah, perhaps I shouldn't have split this off the remaining emulator series I have ready - you refer to a no longer existing function (in my code base).

So you have dropped the legacy FPU exception infrastructure in the series?

Quoted 9 lines

Once there, do_trap()
will panic() as usual in that case, which I think it is sort of appropriate if we receive an exception that shouldn't occur - after all we then don't really know what to do with it. This btw goes along the lines of me not really being happy about us handling all sorts of exceptions once an .ex_table entry is associated with an instruction, rather than just the ones we really mean to recover from. You may recall such a discussion from a few years back.

I don't follow what you mean here.

Quoted 4 lines

Would you be okay with temporarily adding a respective BUG_ON(!fic->insn_bytes) to fpu_handle_exception() to achieve the same effect?

That would be better than nothing, but is fic->insn_bytes a useful field with the legacy handling removed? As all recovery is return-address based, the length of the instruction (so long as it fits within the stub) isn't important.

Quoted 6 lines

As a side note, I'm removing these here since the further SIMD emulation patches I have ready, but would prefer to post only once 4.9 is out, do not add respective code in the first place. Without knowing this in advance I'm not even sure this would be reliably spottable during review.

These what? Again sorry, I don't understand what you mean.

~Andrew

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

#4 lore raw
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 12.06.17 at 14:41, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 09.06.17 at 19:50, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich

Drop a redundant input constraint, correct a comment, and (re)move fix.insn_bytes adjustments (these aren't needed for custom stub invocations when the instruction placed in the stub can't raise #XF)

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

I'm not sure these are wise to remove. Even if we don't expect an exception, should one occur, fpu_handle_exception() will fail to step over the instruction, and will re-execute it.

Ah, perhaps I shouldn't have split this off the remaining emulator series I have ready - you refer to a no longer existing function (in my code base).

So you have dropped the legacy FPU exception infrastructure in the series?

Yes.

Quoted 11 lines
Quoted 9 lines

Once there, do_trap()
will panic() as usual in that case, which I think it is sort of appropriate if we receive an exception that shouldn't occur - after all we then don't really know what to do with it. This btw goes along the lines of me not really being happy about us handling all sorts of exceptions once an .ex_table entry is associated with an instruction, rather than just the ones we really mean to recover from. You may recall such a discussion from a few years back.

I don't follow what you mean here.

1) An exception when we don't expect one is bad.

2) If we get an exception we don't expect, we better don't behave as if all was well.

3) This would imo better extend to our already existing exception recovery too, e.g. by .ex_table entries providing a bitmap of expected (i.e. to be recovered from) exceptions.

Quoted 8 lines
Quoted 3 lines

Would you be okay with temporarily adding a respective BUG_ON(!fic->insn_bytes) to fpu_handle_exception() to achieve the same effect?

That would be better than nothing, but is fic->insn_bytes a useful field with the legacy handling removed? As all recovery is return-address based, the length of the instruction (so long as it fits within the stub) isn't important.

The whole struct fpu_insn_ctxt is going away together with the conversion to the "normal" exception handling model. So adding the suggested BUG_ON() would be only a temporary thing until that other patch could be committed. insn_bytes is becoming a local variable, used solely for code outside of the big switch() to know where to place the RET instruction.

Quoted 7 lines
Quoted 5 lines

As a side note, I'm removing these here since the further SIMD emulation patches I have ready, but would prefer to post only once 4.9 is out, do not add respective code in the first place. Without knowing this in advance I'm not even sure this would be reliably spottable during review.

These what? Again sorry, I don't understand what you mean.

I have patches to add full AVX, F16C, FMA4, FMA, AVX2, XOP, and 3DNow! support to the emulator. Various of the instructions added can't raise #XM, and the patches don't set insn_bytes if it's not needed for aforementioned generic code inserting RET. I.e. what the patch here removes is what those patches won't add in the first place, yielding an overall consistent result.

Jan

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

#5 lore raw
Quoted 25 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 12.06.17 at 14:41, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 09.06.17 at 19:50, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich

Drop a redundant input constraint, correct a comment, and (re)move fix.insn_bytes adjustments (these aren't needed for custom stub invocations when the instruction placed in the stub can't raise #XF)

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

I'm not sure these are wise to remove. Even if we don't expect an exception, should one occur, fpu_handle_exception() will fail to step over the instruction, and will re-execute it.

Ah, perhaps I shouldn't have split this off the remaining emulator series I have ready - you refer to a no longer existing function (in my code base).

So you have dropped the legacy FPU exception infrastructure in the series?

Yes.

Quoted 9 lines
Quoted 9 lines

Once there, do_trap()
will panic() as usual in that case, which I think it is sort of appropriate if we receive an exception that shouldn't occur - after all we then don't really know what to do with it. This btw goes along the lines of me not really being happy about us handling all sorts of exceptions once an .ex_table entry is associated with an instruction, rather than just the ones we really mean to recover from. You may recall such a discussion from a few years back.

Quoted 2 lines
Quoted 1 line

I don't follow what you mean here.

1) An exception when we don't expect one is bad.

Agreed.

Quoted 3 lines

2) If we get an exception we don't expect, we better don't behave as if all was well.

The grammar is a little awkward. A more common way of phrasing that is "we shouldn't behave as if".

Also, agreed.

Quoted 4 lines

3) This would imo better extend to our already existing exception recovery too, e.g. by .ex_table entries providing a bitmap of expected (i.e. to be recovered from) exceptions.

Ah - I remember now. That was a long time ago.

ISTR part of the same conversation was to try and turn as many fatal conditions into domain crashes as we reasonably could. We should probably get started on that at some point.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Would you be okay with temporarily adding a respective BUG_ON(!fic->insn_bytes) to fpu_handle_exception() to achieve the same effect?

That would be better than nothing, but is fic->insn_bytes a useful field with the legacy handling removed? As all recovery is return-address based, the length of the instruction (so long as it fits within the stub) isn't important.

Quoted 6 lines

The whole struct fpu_insn_ctxt is going away together with the conversion to the "normal" exception handling model. So adding the suggested BUG_ON() would be only a temporary thing until that other patch could be committed. insn_bytes is becoming a local variable, used solely for code outside of the big switch() to know where to place the RET instruction.

That also sounds like a good improvement.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

As a side note, I'm removing these here since the further SIMD emulation patches I have ready, but would prefer to post only once 4.9 is out, do not add respective code in the first place. Without knowing this in advance I'm not even sure this would be reliably spottable during review.

Quoted 7 lines
Quoted 1 line

These what? Again sorry, I don't understand what you mean.

I have patches to add full AVX, F16C, FMA4, FMA, AVX2, XOP, and 3DNow! support to the emulator. Various of the instructions added can't raise #XM, and the patches don't set insn_bytes if it's not needed for aforementioned generic code inserting RET. I.e. what the patch here removes is what those patches won't add in the first place, yielding an overall consistent result.

Does this mean you have altered some of the instructions to be straight inline? I can't see how you could get away without a RET otherwise.

~Andrew

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

#6 lore raw
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 12.06.17 at 17:03, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 12.06.17 at 14:41, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich

As a side note, I'm removing these here since the further SIMD emulation patches I have ready, but would prefer to post only once 4.9 is out, do not add respective code in the first place. Without knowing this in advance I'm not even sure this would be reliably spottable during review.

Quoted 7 lines
Quoted 1 line

These what? Again sorry, I don't understand what you mean.

I have patches to add full AVX, F16C, FMA4, FMA, AVX2, XOP, and 3DNow! support to the emulator. Various of the instructions added can't raise #XM, and the patches don't set insn_bytes if it's not needed for aforementioned generic code inserting RET. I.e. what the patch here removes is what those patches won't add in the first place, yielding an overall consistent result.

Quoted 2 lines

Does this mean you have altered some of the instructions to be straight inline? I can't see how you could get away without a RET otherwise.

No, there are already now two cases: One (the most common) is for SIMD insns to be taken care of by the respective code block right after the big switch(). That code needs to know insn_bytes to put the RET at the right spot. The other case is various less generic insns being handled entirely inside their case blocks. The respective code needs to place the RET itself, or else it couldn't invoke the stub. But it doesn't need to set insn_bytes for that reason. It is effectively one such case where the patch removes the setting of the field (as well as the check_xmm_exn()), plus one other case where the field simply is being set later, at a point more consistent with how it's being done elsewhere (and where there already is no matching check_xmm_exn()).

Jan

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