Expand the XSAVE test's coverage for unsupported XCRs to more than just XCR16. Somewhat arbitrarily test XCRs 1-63, and XCRs [bit1:bit31] as a middle ground between hardcoding a few XCRs and exhaustively testing all four billion possibilities. Signed-off-by: Sean Christopherson --- x86/xsave.c | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/x86/xsave.c b/x86/xsave.c index ff093db8..a3645622 100644 --- a/x86/xsave.c +++ b/x86/xsave.c @@ -2,12 +2,45 @@ #include "desc.h" #include "processor.h" -#define XCR_XFEATURE_ILLEGAL_MASK 0x00000010 - #define XSTATE_FP 0x1 #define XSTATE_SSE 0x2 #define XSTATE_YMM 0x4 +static void test_unsupported_xcrs(void) +{ + u64 ign; + int i; + + for (i = 1; i < 64; i++) { + /* XGETBV(1) returns "XCR0 & XINUSE" on some CPUs. */ + if (i != 1) + report(xgetbv_safe(i, &ign) == GP_VECTOR, + "XGETBV(%u) - expect #GP", i); + + report(xsetbv_safe(i, XSTATE_FP) == GP_VECTOR, + "XSETBV(%u, FP) - expect #GP", i); + + report(xsetbv_safe(i, XSTATE_FP | XSTATE_SSE) == GP_VECTOR, + "XSETBV(%u, FP|SSE) - expect #GP", i); + + /* + * RCX[63:32] are ignored by XGETBV and XSETBV, i.e. testing + * bits set above 31 will access XCR0. + */ + if (i > 31) + continue; + + report(xgetbv_safe(BIT(i), &ign) == GP_VECTOR, + "XGETBV(0x%lx) - expect #GP", BIT(i)); + + report(xsetbv_safe(BIT(i), XSTATE_FP) == GP_VECTOR, + "XSETBV(0x%lx, FP) - expect #GP", BIT(i)); + + report(xsetbv_safe(BIT(i), XSTATE_FP | XSTATE_SSE) == GP_VECTOR, + "XSETBV(0x%lx, FP|SSE) - expect #GP", BIT(i)); + } +} + static void test_xsave(void) { u64 supported_xcr0, test_bits; @@ -48,13 +81,7 @@ static void test_xsave(void) "\t\tWrite XCR0 = (FP | YMM) - expect #GP"); } - test_bits = XSTATE_SSE; - report(xsetbv_safe(XCR_XFEATURE_ILLEGAL_MASK, test_bits) == GP_VECTOR, - "\t\txsetbv(XCR_XFEATURE_ILLEGAL_MASK, XSTATE_FP) - expect #GP"); - - test_bits = XSTATE_SSE; - report(xsetbv_safe(XCR_XFEATURE_ILLEGAL_MASK, test_bits) == GP_VECTOR, - "\t\txgetbv(XCR_XFEATURE_ILLEGAL_MASK, XSTATE_FP) - expect #GP"); + test_unsupported_xcrs(); write_cr4(cr4); -- 2.52.0.rc2.455.g230fcf2819-goog