From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754430AbbGPINi (ORCPT ); Thu, 16 Jul 2015 04:13:38 -0400 Received: from mga11.intel.com ([192.55.52.93]:21839 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751572AbbGPINf (ORCPT ); Thu, 16 Jul 2015 04:13:35 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,486,1432623600"; d="scan'208";a="748399308" Subject: [RFC][PATCH 2/2] x86, fpu: enlarge xregs_state To: dave@sr71.net Cc: torvalds@linux-foundation.org, mingo@kernel.org, linux-kernel@vger.kernel.org, luto@amacapital.net, bp@alien8.de, fenghua.yu@intel.com, hpa@zytor.com, oleg@redhat.com, tglx@linutronix.de, ross.zwisler@linux.intel.com From: Dave Hansen Date: Thu, 16 Jul 2015 01:13:32 -0700 References: <20150716081332.9413DD5B@viggo.jf.intel.com> In-Reply-To: <20150716081332.9413DD5B@viggo.jf.intel.com> Message-Id: <20150716081332.641D2B2F@viggo.jf.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Ingo Molnar Cc: Linux Kernel Mailing List Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Fenghua Yu Cc: "H. Peter Anvin" Cc: leg Nesterov Cc: Thomas Gleixner Cc: Ross Zwisler --- 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))); /* _