From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757348AbcGJSRJ (ORCPT ); Sun, 10 Jul 2016 14:17:09 -0400 Received: from terminus.zytor.com ([198.137.202.10]:53926 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757180AbcGJSRF (ORCPT ); Sun, 10 Jul 2016 14:17:05 -0400 Date: Sun, 10 Jul 2016 11:14:03 -0700 From: tip-bot for Yu-cheng Yu Message-ID: Cc: tglx@linutronix.de, fenghua.yu@intel.com, bp@alien8.de, jpoimboe@redhat.com, brgerst@gmail.com, hpa@zytor.com, yu-cheng.yu@intel.com, sai.praneeth.prakhya@intel.com, torvalds@linux-foundation.org, dvlasenk@redhat.com, dave.hansen@intel.com, peterz@infradead.org, quentin.casasnovas@oracle.com, mingo@kernel.org, luto@kernel.org, ravi.v.shankar@intel.com, dave.hansen@linux.intel.com, oleg@redhat.com, linux-kernel@vger.kernel.org Reply-To: dvlasenk@redhat.com, dave.hansen@intel.com, torvalds@linux-foundation.org, hpa@zytor.com, sai.praneeth.prakhya@intel.com, yu-cheng.yu@intel.com, bp@alien8.de, brgerst@gmail.com, jpoimboe@redhat.com, fenghua.yu@intel.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, dave.hansen@linux.intel.com, oleg@redhat.com, ravi.v.shankar@intel.com, luto@kernel.org, peterz@infradead.org, quentin.casasnovas@oracle.com, mingo@kernel.org In-Reply-To: <331e2bef1a0a7a584f06adde095b6bbfbe166472.1466179491.git.yu-cheng.yu@intel.com> References: <331e2bef1a0a7a584f06adde095b6bbfbe166472.1466179491.git.yu-cheng.yu@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/fpu] x86/fpu/xstate: Align xstate components according to CPUID Git-Commit-ID: 03482e08a87d24e5c8c23e6981c482e832cf3bdc X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 03482e08a87d24e5c8c23e6981c482e832cf3bdc Gitweb: http://git.kernel.org/tip/03482e08a87d24e5c8c23e6981c482e832cf3bdc Author: Yu-cheng Yu AuthorDate: Fri, 17 Jun 2016 13:07:15 -0700 Committer: Ingo Molnar CommitDate: Sun, 10 Jul 2016 17:12:10 +0200 x86/fpu/xstate: Align xstate components according to CPUID CPUID function 0x0d, sub function (i, i > 1) returns in ecx[1] the alignment requirement of component 'i' when the compacted format is used. If ecx[1] is 0, component 'i' is located immediately following the preceding component. If ecx[1] is 1, component 'i' is located on the next 64-byte boundary following the preceding component. Signed-off-by: Yu-cheng Yu Reviewed-by: Dave Hansen Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Dave Hansen Cc: Denys Vlasenko Cc: Fenghua Yu Cc: H. Peter Anvin Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Oleg Nesterov Cc: Peter Zijlstra Cc: Quentin Casasnovas Cc: Ravi V. Shankar Cc: Sai Praneeth Prakhya Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/331e2bef1a0a7a584f06adde095b6bbfbe166472.1466179491.git.yu-cheng.yu@intel.com Signed-off-by: Ingo Molnar --- arch/x86/kernel/fpu/xstate.c | 60 +++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index 0b01f00..7963029 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -270,6 +270,33 @@ static void __init print_xstate_features(void) } /* + * This check is important because it is easy to get XSTATE_* + * confused with XSTATE_BIT_*. + */ +#define CHECK_XFEATURE(nr) do { \ + WARN_ON(nr < FIRST_EXTENDED_XFEATURE); \ + WARN_ON(nr >= XFEATURE_MAX); \ +} while (0) + +/* + * We could cache this like xstate_size[], but we only use + * it here, so it would be a waste of space. + */ +static int xfeature_is_aligned(int xfeature_nr) +{ + u32 eax, ebx, ecx, edx; + + CHECK_XFEATURE(xfeature_nr); + cpuid_count(XSTATE_CPUID, xfeature_nr, &eax, &ebx, &ecx, &edx); + /* + * The value returned by ECX[1] indicates the alignment + * of state component 'i' when the compacted format + * of the extended region of an XSAVE area is used: + */ + return !!(ecx & 2); +} + +/* * This function sets up offsets and sizes of all extended states in * xsave area. This supports both standard format and compacted format * of the xsave aread. @@ -306,10 +333,14 @@ static void __init setup_xstate_comp(void) else xstate_comp_sizes[i] = 0; - if (i > FIRST_EXTENDED_XFEATURE) + if (i > FIRST_EXTENDED_XFEATURE) { xstate_comp_offsets[i] = xstate_comp_offsets[i-1] + xstate_comp_sizes[i-1]; + if (xfeature_is_aligned(i)) + xstate_comp_offsets[i] = + ALIGN(xstate_comp_offsets[i], 64); + } } } @@ -366,33 +397,6 @@ static int xfeature_is_user(int xfeature_nr) } */ -/* - * This check is important because it is easy to get XSTATE_* - * confused with XSTATE_BIT_*. - */ -#define CHECK_XFEATURE(nr) do { \ - WARN_ON(nr < FIRST_EXTENDED_XFEATURE); \ - WARN_ON(nr >= XFEATURE_MAX); \ -} while (0) - -/* - * We could cache this like xstate_size[], but we only use - * it here, so it would be a waste of space. - */ -static int xfeature_is_aligned(int xfeature_nr) -{ - u32 eax, ebx, ecx, edx; - - CHECK_XFEATURE(xfeature_nr); - cpuid_count(XSTATE_CPUID, xfeature_nr, &eax, &ebx, &ecx, &edx); - /* - * The value returned by ECX[1] indicates the alignment - * of state component i when the compacted format - * of the extended region of an XSAVE area is used - */ - return !!(ecx & 2); -} - static int xfeature_uncompacted_offset(int xfeature_nr) { u32 eax, ebx, ecx, edx;