Skip to contentSkip to conversation

x86emul: unconditionally deliver #UD for LWP insns

RFC PATCH In review Jan Beulich 2 participants 7 messages Jul 17, 2019 – Jul 18, 2019

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 x86emul: unconditionally deliver #UD for LWP insns

This is to accompany commit ("x86/svm: Drop support for AMD's Lightweight Profiling").

---
With AMD apparently having abandoned XOP encoded insns, another option would seem to be to simply wire all unrecognized ones into #UD (rather then returning UNIMPLEMENTED/UNRECOGNIZED).
---
TODO/RFC: Insert commit ID of referenced commit.

xen/arch/x86/x86_emulate/x86_emulate.c +20 -0
@@ -10367,6 +10367,16 @@ x86_emulate(
          }
          goto unrecognized_insn;
  
+    case X86EMUL_OPC_XOP(09, 0x12): /* XOP Grp3 */
+        switch ( modrm_reg & 7 )
+        {
+        case 0: /* llwpcb r */
+        case 1: /* slwpcb r */
+            /* LWP is unsupported, so produce #UD unconditionally. */
+            generate_exception(EXC_UD);
+        }
+        goto unrecognized_insn;
+
      case X86EMUL_OPC_XOP(09, 0x82): /* vfrczss xmm/m128,xmm */
      case X86EMUL_OPC_XOP(09, 0x83): /* vfrczsd xmm/m128,xmm */
          generate_exception_if(vex.l, EXC_UD);
@@ -10451,6 +10461,16 @@ x86_emulate(
          break;
      }
  
+    case X86EMUL_OPC_XOP(0a, 0x12): /* XOP Grp4 */
+        switch ( modrm_reg & 7 )
+        {
+        case 0: /* lwpins $imm32,r/m,r */
+        case 1: /* lwpval $imm32,r/m,r */
+            /* LWP is unsupported, so produce #UD unconditionally. */
+            generate_exception(EXC_UD);
+        }
+        goto unrecognized_insn;
+
      default:
      unimplemented_insn:
          rc = X86EMUL_UNIMPLEMENTED;

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

Acked-by on v1 1/1
#1 lore raw
Quoted 1 line · Jan Beulich

This is to accompany commit ("x86/svm: Drop support for AMD's

91f86f8634

Quoted 3 lines

Lightweight Profiling").

Quoted 4 lines

---
With AMD apparently having abandoned XOP encoded insns, another option would seem to be to simply wire all unrecognized ones into #UD (rather then returning UNIMPLEMENTED/UNRECOGNIZED).

There are still some XOP instructions which actually work on Fam17h processors, if you ignore CPUID and go blindly executing.

Given no official statement that XOP is dead, I'd keep the support we currently have.

~Andrew

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

#2 lore raw
Quoted 4 lines · Andrew Cooper
Quoted 1 line · Jan Beulich

This is to accompany commit ("x86/svm: Drop support for AMD's

91f86f8634

Hmm, odd - I'm sure I had checked, resulting in the impression that this didn't get committed yet.

Quoted 10 lines
Quoted 3 lines

Lightweight Profiling").

Quoted 4 lines

---
With AMD apparently having abandoned XOP encoded insns, another option would seem to be to simply wire all unrecognized ones into #UD (rather then returning UNIMPLEMENTED/UNRECOGNIZED).

Quoted 5 lines

There are still some XOP instructions which actually work on Fam17h processors, if you ignore CPUID and go blindly executing.

Given no official statement that XOP is dead, I'd keep the support we currently have.

Then my remark wasn't clear enough: I'm not suggesting to rip out XOP insn support we have. I'm instead considering whether to wire all unsupported XOP encodings into #UD (rather than return UNIMPLEMENTED/UNRECOGNIZED for them), not just the LWP ones.

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

#3 lore raw
Quoted 19 lines · Jan Beulich
Quoted 3 lines · Andrew Cooper
Quoted 1 line · Jan Beulich

This is to accompany commit ("x86/svm: Drop support for AMD's

91f86f8634

Hmm, odd - I'm sure I had checked, resulting in the impression that this didn't get committed yet.

Quoted 12 lines
Quoted 3 lines

Lightweight Profiling").

Quoted 4 lines

---
With AMD apparently having abandoned XOP encoded insns, another option would seem to be to simply wire all unrecognized ones into #UD (rather then returning UNIMPLEMENTED/UNRECOGNIZED).

There are still some XOP instructions which actually work on Fam17h processors, if you ignore CPUID and go blindly executing.

Quoted 6 lines
Quoted 2 lines

Given no official statement that XOP is dead, I'd keep the support we currently have.

Then my remark wasn't clear enough: I'm not suggesting to rip out XOP insn support we have. I'm instead considering whether to wire all unsupported XOP encodings into #UD (rather than return UNIMPLEMENTED/UNRECOGNIZED for them), not just the LWP ones.

Ah, in which case, no.  Turning all unknown instructions into EXCEPTION/#UD will break introspection, which uses UNRECOGNISED to cover the gaps in the emulator by single-stepping the vcpu.

~Andrew

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

#4 lore raw
Quoted 11 lines · Andrew Cooper
Quoted 10 lines · Jan Beulich
Quoted 9 lines · Andrew Cooper
Quoted 3 lines · Jan Beulich

With AMD apparently having abandoned XOP encoded insns, another option would seem to be to simply wire all unrecognized ones into #UD (rather then returning UNIMPLEMENTED/UNRECOGNIZED).

There are still some XOP instructions which actually work on Fam17h processors, if you ignore CPUID and go blindly executing.

Given no official statement that XOP is dead, I'd keep the support we currently have.

Quoted 8 lines
Quoted 4 lines

Then my remark wasn't clear enough: I'm not suggesting to rip out XOP insn support we have. I'm instead considering whether to wire all unsupported XOP encodings into #UD (rather than return UNIMPLEMENTED/UNRECOGNIZED for them), not just the LWP ones.

Ah, in which case, no.  Turning all unknown instructions into EXCEPTION/#UD will break introspection, which uses UNRECOGNISED to cover the gaps in the emulator by single-stepping the vcpu.

But there are no gaps: The only ones we didn't cover (afaik) were the LWP ones, and those would get made raise #UD by the patch here anyway. If there are really opcodes where "unrecognized" is relevant, then we should special case _those_ imo, rather than leaving an opcode space which apparently won't see further extensions all go the "unrecognized" route.

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

#5 lore raw
Quoted 12 lines · Jan Beulich
Quoted 11 lines · Andrew Cooper
Quoted 10 lines · Jan Beulich
Quoted 9 lines · Andrew Cooper
Quoted 3 lines · Jan Beulich

With AMD apparently having abandoned XOP encoded insns, another option would seem to be to simply wire all unrecognized ones into #UD (rather then returning UNIMPLEMENTED/UNRECOGNIZED).

There are still some XOP instructions which actually work on Fam17h processors, if you ignore CPUID and go blindly executing.

Given no official statement that XOP is dead, I'd keep the support we currently have.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Then my remark wasn't clear enough: I'm not suggesting to rip out XOP insn support we have. I'm instead considering whether to wire all unsupported XOP encodings into #UD (rather than return UNIMPLEMENTED/UNRECOGNIZED for them), not just the LWP ones.

Ah, in which case, no.  Turning all unknown instructions into EXCEPTION/#UD will break introspection, which uses UNRECOGNISED to cover the gaps in the emulator by single-stepping the vcpu.

But there are no gaps:

[F]XSAVE et al, VT-x, SVM to name several gaps.

Not to mention running current versions of Xen on newer hardware.

Quoted 6 lines

The only ones we didn't cover (afaik) were the
LWP ones, and those would get made raise #UD by the patch here anyway. If there are really opcodes where "unrecognized" is relevant, then we should special case _those_ imo, rather than leaving an opcode space which apparently won't see further extensions all go the "unrecognized" route.

In terms of "not crashing the guest", it is very important to know if there are instructions which are accepted by the pipeline, trap for an access violation, and that x86_emulate() doesn't know about.

If we do emulation support perfectly, along with CPUID feature handling etc, then this set should be 0, but it is still nonzero even with this patch.

For instructions we know about, and know that we told the guest it couldn't use, then #UD is fine and correct to do.  Given that approximately all of access violations are well-formed non-malicious code, then an instruction which x86_emulate() doesn't know about is most likely a hole or a CPUID handling issue.  Either way, blindly converting this to #UD is not the appropriate course of action.

~Andrew

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

#6 lore raw
Quoted 17 lines · Andrew Cooper
Quoted 16 lines · Jan Beulich
Quoted 15 lines · Andrew Cooper
Quoted 14 lines · Jan Beulich
Quoted 9 lines · Andrew Cooper
Quoted 3 lines · Jan Beulich

With AMD apparently having abandoned XOP encoded insns, another option would seem to be to simply wire all unrecognized ones into #UD (rather then returning UNIMPLEMENTED/UNRECOGNIZED).

There are still some XOP instructions which actually work on Fam17h processors, if you ignore CPUID and go blindly executing.

Given no official statement that XOP is dead, I'd keep the support we currently have.

Then my remark wasn't clear enough: I'm not suggesting to rip out XOP insn support we have. I'm instead considering whether to wire all unsupported XOP encodings into #UD (rather than return UNIMPLEMENTED/UNRECOGNIZED for them), not just the LWP ones.

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

Ah, in which case, no.  Turning all unknown instructions into EXCEPTION/#UD will break introspection, which uses UNRECOGNISED to cover the gaps in the emulator by single-stepping the vcpu.

But there are no gaps:

[F]XSAVE et al, VT-x, SVM to name several gaps.

Not to mention running current versions of Xen on newer hardware.

None of these are XOP encoded. I've never been considering to wire everything into #UD.

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