From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755919AbbDVEzW (ORCPT ); Wed, 22 Apr 2015 00:55:22 -0400 Received: from mga11.intel.com ([192.55.52.93]:61457 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752356AbbDVEzN (ORCPT ); Wed, 22 Apr 2015 00:55:13 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,621,1422950400"; d="scan'208";a="698952242" From: "Fenghua Yu" To: "H. Peter Anvin" , "Ingo Molnar" , "Thomas Gleixner" , "Asit K Mallick" , "Dave Hansen" , "Glenn Williamson" Cc: "linux-kernel" , "x86" , "Fenghua Yu" Subject: [PATCH Bugfix v2 1/4] x86/xsave.c: Fix xstate offsets and sizes enumeration Date: Tue, 21 Apr 2015 21:51:56 -0700 Message-Id: <1429678319-61356-2-git-send-email-fenghua.yu@intel.com> X-Mailer: git-send-email 1.8.0.1 In-Reply-To: <1429678319-61356-1-git-send-email-fenghua.yu@intel.com> References: <1429678319-61356-1-git-send-email-fenghua.yu@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Fenghua Yu When enumerating xstate offsets and sizes from cpuid (eax=0x0d, ecx>=2), it's possible that state m is not implemented while state n (n>m) is implemented. So enumeration shouldn't stop at state m. There is no platform configured like above yet. But this could be a problem in the future. For example, suppose XCR0=0xe7, that means FP, SSE, AVX, and AVX-512 states are enabled and MPX states (bit 3 and 4) are not enabled. Then in setup_xstate_features(), after finding BNDREGS size is 0 (i.e. eax from CPUID xstate subleaf 3, break from the for loop. That stops finding xstate_offsets and xstate_sizes for AVX-512. Later on incorrect xstate_offsets and xstate_sizes for AVX-512 will be used in a few places and will causes issues. This patch enumerates xstate offsets and sizes for all kernel supported xstates. If a state is not implemented in hardware or not enabled in XCR0, its size is set as zero and its offset is read from cpuid. Signed-off-by: Fenghua Yu Reviewed-by: Dave Hansen --- arch/x86/kernel/xsave.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c index 87a815b..3c0a9d1 100644 --- a/arch/x86/kernel/xsave.c +++ b/arch/x86/kernel/xsave.c @@ -465,23 +465,18 @@ static inline void xstate_enable(void) */ static void __init setup_xstate_features(void) { - int eax, ebx, ecx, edx, leaf = 0x2; + int eax, ebx, ecx, edx, leaf; xstate_features = fls64(pcntxt_mask); xstate_offsets = alloc_bootmem(xstate_features * sizeof(int)); xstate_sizes = alloc_bootmem(xstate_features * sizeof(int)); - do { + for (leaf = 2; leaf < xstate_features; leaf++) { cpuid_count(XSTATE_CPUID, leaf, &eax, &ebx, &ecx, &edx); - if (eax == 0) - break; - xstate_offsets[leaf] = ebx; xstate_sizes[leaf] = eax; - - leaf++; - } while (1); + } } /* -- 1.8.1.2