Skip to contentSkip to conversation

target/i386: fix xsave.flat from kvm-unit-tests

PATCH In review Paolo Bonzini 2 participants 2 messages Jun 3, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/i386: fix xsave.flat from kvm-unit-tests

xsave.flat checks that "executing the XSETBV instruction causes a general- protection fault (#GP) if ECX = 0 and EAX[2:1] has the value 10b". QEMU allows that option, so the test fails. Add the condition.

Fixes 892544317fe ("target/i386: implement XSAVE and XRSTOR of AVX registers", 2022-10-18)
---
 target/i386/tcg/fpu_helper.c | 5 +++++
 1 file changed, 5 insertions(+)
target/i386/tcg/fpu_helper.c +5 -0
index e322293371c..e1b850f3fc2 100644
@@ -3142,6 +3142,11 @@ void helper_xsetbv(CPUX86State *env, uint32_t ecx, uint64_t mask)
         goto do_gpf;
     }
 
+    /* SSE can be disabled, but only if AVX is disabled too.  */
+    if ((mask & (XSTATE_SSE_MASK | XSTATE_YMM_MASK)) == XSTATE_YMM_MASK) {
+        goto do_gpf;
+    }
+
     /* Disallow enabling unimplemented features.  */
     cpu_x86_cpuid(env, 0x0d, 0, &ena_lo, &dummy, &dummy, &ena_hi);
     ena = ((uint64_t)ena_hi << 32) | ena_lo;
Signature · 1 line
2.45.1
Tested-by on v1 1/1
#1 lore raw
Quoted 17 lines · Paolo Bonzini

xsave.flat checks that "executing the XSETBV instruction causes a general- protection fault (#GP) if ECX = 0 and EAX[2:1] has the value 10b". QEMU allows that option, so the test fails. Add the condition.

Fixes 892544317fe ("target/i386: implement XSAVE and XRSTOR of AVX registers", 2022-10-18)
---
  target/i386/tcg/fpu_helper.c | 5 +++++
  1 file changed, 5 insertions(+)
target/i386/tcg/fpu_helper.c +0 -0
index e322293371c..e1b850f3fc2 100644

target/i386/tcg/fpu_helper.c void helper_xsetbv(CPUX86State *env, uint32_t ecx, uint64_t mask) · line 3148

Quoted 7 lines
target/i386/tcg/fpu_helper.c +4 -0
@@ -3142,6 +3142,11 @@ void helper_xsetbv(CPUX86State *env, uint32_t ecx, uint64_t mask)
          goto do_gpf;
      }
 
+    /* SSE can be disabled, but only if AVX is disabled too.  */
+    if ((mask & (XSTATE_SSE_MASK | XSTATE_YMM_MASK)) == XSTATE_YMM_MASK) {
+        goto do_gpf;
+    }

That fixes the kvm-unit-test, indeed! Thanks!