x86/fpu, x86/mm/pkeys: Add PKRU xsave fields and data structures
[cascardo/linux.git] / arch / x86 / kernel / fpu / xstate.c
index d425cda..a63ca80 100644 (file)
 
 #include <asm/tlbflush.h>
 
+/*
+ * Although we spell it out in here, the Processor Trace
+ * xfeature is completely unused.  We use other mechanisms
+ * to save/restore PT state in Linux.
+ */
 static const char *xfeature_names[] =
 {
        "x87 floating point registers"  ,
@@ -23,6 +28,8 @@ static const char *xfeature_names[] =
        "AVX-512 opmask"                ,
        "AVX-512 Hi256"                 ,
        "AVX-512 ZMM_Hi256"             ,
+       "Processor Trace (unused)"      ,
+       "Protection Keys User registers",
        "unknown xstate feature"        ,
 };
 
@@ -53,6 +60,7 @@ void fpu__xstate_clear_all_cpu_caps(void)
        setup_clear_cpu_cap(X86_FEATURE_AVX512CD);
        setup_clear_cpu_cap(X86_FEATURE_MPX);
        setup_clear_cpu_cap(X86_FEATURE_XGETBV1);
+       setup_clear_cpu_cap(X86_FEATURE_PKU);
 }
 
 /*
@@ -231,7 +239,7 @@ static void __init print_xstate_feature(u64 xstate_mask)
        const char *feature_name;
 
        if (cpu_has_xfeatures(xstate_mask, &feature_name))
-               pr_info("x86/fpu: Supporting XSAVE feature 0x%02Lx: '%s'\n", xstate_mask, feature_name);
+               pr_info("x86/fpu: Supporting XSAVE feature 0x%03Lx: '%s'\n", xstate_mask, feature_name);
 }
 
 /*
@@ -247,6 +255,7 @@ static void __init print_xstate_features(void)
        print_xstate_feature(XFEATURE_MASK_OPMASK);
        print_xstate_feature(XFEATURE_MASK_ZMM_Hi256);
        print_xstate_feature(XFEATURE_MASK_Hi16_ZMM);
+       print_xstate_feature(XFEATURE_MASK_PKRU);
 }
 
 /*
@@ -463,6 +472,7 @@ static void check_xstate_against_struct(int nr)
        XCHECK_SZ(sz, nr, XFEATURE_OPMASK,    struct avx_512_opmask_state);
        XCHECK_SZ(sz, nr, XFEATURE_ZMM_Hi256, struct avx_512_zmm_uppers_state);
        XCHECK_SZ(sz, nr, XFEATURE_Hi16_ZMM,  struct avx_512_hi16_state);
+       XCHECK_SZ(sz, nr, XFEATURE_PKRU,      struct pkru_state);
 
        /*
         * Make *SURE* to add any feature numbers in below if
@@ -470,7 +480,8 @@ static void check_xstate_against_struct(int nr)
         * numbers.
         */
        if ((nr < XFEATURE_YMM) ||
-           (nr >= XFEATURE_MAX)) {
+           (nr >= XFEATURE_MAX) ||
+           (nr == XFEATURE_PT_UNIMPLEMENTED_SO_FAR)) {
                WARN_ONCE(1, "no structure for xstate: %d\n", nr);
                XSTATE_WARN_ON(1);
        }