target/i386: fix xsave.flat from kvm-unit-tests
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 3 Jun 2024 10:01:12 +0000 (12:01 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 5 Jun 2024 09:01:05 +0000 (11:01 +0200)
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.

Cc: qemu-stable@nongnu.org
Fixes: 892544317fe ("target/i386: implement XSAVE and XRSTOR of AVX registers", 2022-10-18)
Reported-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
target/i386/tcg/fpu_helper.c

index e322293371c4e88e70668f1f124893cdad39d7f7..e1b850f3fc265ef4030ba9c2cca1448d8923351d 100644 (file)
@@ -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;