KVM: selftests: Verify XTILE_DATA in XSTATE isn't affected by IA32_XFD
authorMingwei Zhang <mizhang@google.com>
Tue, 21 Feb 2023 16:36:50 +0000 (16:36 +0000)
committerSean Christopherson <seanjc@google.com>
Fri, 24 Mar 2023 21:21:39 +0000 (14:21 -0700)
Add asserts to verify the XSTATE metadata for XTILE_DATA isn't affected
by disabling AMX tile data via IA32_XFD.  XFD doesn't intercept XSAVE,
it only prevents setting bits in XCR0, i.e. regardless of XFD, AMX state
is managed by XSAVE/XRSTOR as long as the corresponding bits are set XCR0.

Signed-off-by: Mingwei Zhang <mizhang@google.com>
Link: https://lore.kernel.org/r/20230221163655.920289-9-mizhang@google.com
[sean: massage changelog]
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/x86_64/amx_test.c

index cd0491cc7c8c95cbd2d1638f104d3ca19e040356..e6bc6cd108dc0912514daba5e898d8779a61bbf6 100644 (file)
@@ -201,6 +201,16 @@ static void __attribute__((__flatten__)) guest_code(struct tile_config *amx_cfg,
 
        /* xfd=0x40000, disable amx tiledata */
        wrmsr(MSR_IA32_XFD, XFEATURE_MASK_XTILEDATA);
+
+       /*
+        * XTILEDATA is cleared in xstate_bv but set in xcomp_bv, this property
+        * remains the same even when amx tiledata is disabled by IA32_XFD.
+        */
+       xstate->header.xstate_bv = XFEATURE_MASK_XTILEDATA;
+       __xsavec(xstate, XFEATURE_MASK_XTILEDATA);
+       GUEST_ASSERT(!(xstate->header.xstate_bv & XFEATURE_MASK_XTILEDATA));
+       GUEST_ASSERT((xstate->header.xcomp_bv & XFEATURE_MASK_XTILEDATA));
+
        GUEST_SYNC(6);
        GUEST_ASSERT(rdmsr(MSR_IA32_XFD) == XFEATURE_MASK_XTILEDATA);
        set_tilecfg(amx_cfg);