This takes a stab at sizing the xsave buffer so that it will work for
AVX-512 systems.  The logic is explained in the comment.

Cc: Linus Torvalds <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Linux Kernel Mailing List <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Fenghua Yu <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: leg Nesterov <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ross Zwisler <[email protected]>

---

 b/arch/x86/include/asm/fpu/types.h |   27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff -puN arch/x86/include/asm/fpu/types.h~enlarge-init-fpu-buf 
arch/x86/include/asm/fpu/types.h
--- a/arch/x86/include/asm/fpu/types.h~enlarge-init-fpu-buf     2015-07-16 
01:11:03.301028886 -0700
+++ b/arch/x86/include/asm/fpu/types.h  2015-07-16 01:11:03.304029021 -0700
@@ -159,10 +159,19 @@ struct xstate_header {
        u64                             reserved[6];
 } __attribute__((packed));
 
-/* New processor state extensions should be added here: */
-#define XSTATE_RESERVE                 (sizeof(struct ymmh_struct) + \
-                                        sizeof(struct lwp_struct)  + \
-                                        sizeof(struct mpx_struct)  )
+/*
+ * The largest xsave buffer known today is 2752 bytes on a system
+ * implementing AVX-512.  This includes the 512-byte i387 state
+ * and 64-byte header.  We add a small amount of padding in case
+ * an implementation adds some padding or wastes some space.
+ *
+ * Note, if we overflow this, we will disable XSAVE completely.
+ *
+ * Also, note that the real size we need is enumerated by
+ * cpuid leaves and can not be known at compile time.
+ */
+#define XSTATE_MAX_SIZE        (2752 + 256)
+
 /*
  * This is our most modern FPU state format, as saved by the XSAVE
  * and restored by the XRSTOR instructions.
@@ -172,9 +181,13 @@ struct xstate_header {
  * Not all CPUs support all the extensions.
  */
 struct xregs_state {
-       struct fxregs_state             i387;
-       struct xstate_header            header;
-       u8                              __reserved[XSTATE_RESERVE];
+       union {
+               struct {
+                       struct fxregs_state             i387;
+                       struct xstate_header            header;
+               };
+               u8 __reserved[XSTATE_MAX_SIZE];
+       };
 } __attribute__ ((packed, aligned (64)));
 
 /*
_
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to