Skip to contentSkip to conversation

target/i386: allow MMX instructions with CR4.OSFXSR=0

PATCH In review Paolo Bonzini 3 participants 4 messages Nov 30, 2022 – Dec 1, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/i386: allow MMX instructions with CR4.OSFXSR=0

MMX state is saved/restored by FSAVE/FRSTOR so the instructions are not illegal opcodes even if CR4.OSFXSR=0. Make sure that validate_vex takes into account the prefix and only checks HF_OSFXSR_MASK in the presence of an SSE instruction.

Fixes 20581aadec5e ("target/i386: validate VEX prefixes via the instructions' exception classes", 2022-10-18)

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1350

---
 target/i386/tcg/decode-new.c.inc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/i386/tcg/decode-new.c.inc +2 -1
index e4878b967f0e..80c579164ff2 100644
@@ -1488,7 +1488,8 @@ static bool validate_vex(DisasContext *s, X86DecodedInsn *decode)
             if (!(s->flags & HF_AVX_EN_MASK)) {
                 goto illegal;
             }
-        } else {
+        } else if (e->special != X86_SPECIAL_MMX ||
+                   (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ | PREFIX_DATA))) {
             if (!(s->flags & HF_OSFXSR_MASK)) {
                 goto illegal;
             }
Signature · 1 line
2.38.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Paolo Bonzini

MMX state is saved/restored by FSAVE/FRSTOR so the instructions are not illegal opcodes even if CR4.OSFXSR=0. Make sure that validate_vex takes into account the prefix and only checks HF_OSFXSR_MASK in the presence of an SSE instruction.

Quoted 7 lines
Fixes 20581aadec5e ("target/i386: validate VEX prefixes via the instructions' exception classes", 2022-10-18)

Resolves:https://gitlab.com/qemu-project/qemu/-/issues/1350

---
  target/i386/tcg/decode-new.c.inc | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

r~

Tested-by on v1 1/1
#2 lore raw
In reply to Paolo Bonzini
Quoted 18 lines · Paolo Bonzini

MMX state is saved/restored by FSAVE/FRSTOR so the instructions are not illegal opcodes even if CR4.OSFXSR=0. Make sure that validate_vex takes into account the prefix and only checks HF_OSFXSR_MASK in the presence of an SSE instruction.

Fixes 20581aadec5e ("target/i386: validate VEX prefixes via the instructions' exception classes", 2022-10-18)

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1350

---
  target/i386/tcg/decode-new.c.inc | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
target/i386/tcg/decode-new.c.inc +0 -0
index e4878b967f0e..80c579164ff2 100644

target/i386/tcg/decode-new.c.inc static bool validate_vex(DisasContext *s, X86DecodedInsn *decode) · line 1495

Quoted 9 lines
target/i386/tcg/decode-new.c.inc +2 -1
@@ -1488,7 +1488,8 @@ static bool validate_vex(DisasContext *s, X86DecodedInsn *decode)
              if (!(s->flags & HF_AVX_EN_MASK)) {
                  goto illegal;
              }
-        } else {
+        } else if (e->special != X86_SPECIAL_MMX ||
+                   (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ | PREFIX_DATA))) {
              if (!(s->flags & HF_OSFXSR_MASK)) {
                  goto illegal;
              }

This fixes the MicroSnow image, indeed, thus:

Should this patch still be included in QEMU 7.2 ? ... since it fixes a regression?

#3 lore raw
Quoted 31 lines · Thomas Huth
Quoted 18 lines · Paolo Bonzini

MMX state is saved/restored by FSAVE/FRSTOR so the instructions are not illegal opcodes even if CR4.OSFXSR=0.  Make sure that validate_vex takes into account the prefix and only checks HF_OSFXSR_MASK in the presence of an SSE instruction.

Fixes 20581aadec5e ("target/i386: validate VEX prefixes via the instructions' exception classes", 2022-10-18)

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1350

---
  target/i386/tcg/decode-new.c.inc | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
target/i386/tcg/decode-new.c.inc +0 -0
index e4878b967f0e..80c579164ff2 100644

target/i386/tcg/decode-new.c.inc static bool validate_vex(DisasContext *s, X86DecodedInsn *decode) · line 1495

Quoted 9 lines
target/i386/tcg/decode-new.c.inc +2 -1
@@ -1488,7 +1488,8 @@ static bool validate_vex(DisasContext *s, X86DecodedInsn *decode)
               if (!(s->flags & HF_AVX_EN_MASK)) {
                   goto illegal;
               }
-        } else {
+        } else if (e->special != X86_SPECIAL_MMX ||
+                   (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ | PREFIX_DATA))) {
               if (!(s->flags & HF_OSFXSR_MASK)) {
                   goto illegal;
               }

This fixes the MicroSnow image, indeed, thus:

Quoted 3 lines

Should this patch still be included in QEMU 7.2 ? ... since it fixes a regression?

Yes.

r~