aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel
diff options
context:
space:
mode:
authorDave Hansen <dave.hansen@linux.intel.com>2015-09-02 19:31:29 -0400
committerIngo Molnar <mingo@kernel.org>2015-09-14 06:21:59 -0400
commit633d54c47a5bedfb42f10e6a63eeeebd35abdb4c (patch)
tree45237ce470657344893177c898ef7e9b831c6d7c /arch/x86/kernel
parentee9ae257eb17d3426ee9ab91449a3aa443298b36 (diff)
x86/fpu: Add xfeature_enabled() helper instead of test_bit()
We currently use test_bit() in a few places to see if an xfeature is enabled. It ends up being a bit ugly because 'xfeatures_mask' is a u64 and test_bit wants an 'unsigned long' so it requires a cast. The *_bit() functions are also techincally atomic, which we have no need for here. So, remove the test_bit()s and replace with the new xfeature_enabled() helper. This also provides a central place to add a comment about the future need to support 'system xstates'. Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tim Chen <tim.c.chen@linux.intel.com> Cc: dave@sr71.net Cc: linux-kernel@vger.kernel.org Link: http://lkml.kernel.org/r/20150902233129.B1534F86@viggo.jf.intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'arch/x86/kernel')
-rw-r--r--arch/x86/kernel/fpu/xstate.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 61ec60bcbb63..ba6b6e0baf88 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -226,6 +226,16 @@ static void __init print_xstate_features(void)
226} 226}
227 227
228/* 228/*
229 * Note that in the future we will likely need a pair of
230 * functions here: one for user xstates and the other for
231 * system xstates. For now, they are the same.
232 */
233static int xfeature_enabled(enum xfeature xfeature)
234{
235 return !!(xfeatures_mask & (1UL << xfeature));
236}
237
238/*
229 * This function sets up offsets and sizes of all extended states in 239 * This function sets up offsets and sizes of all extended states in
230 * xsave area. This supports both standard format and compacted format 240 * xsave area. This supports both standard format and compacted format
231 * of the xsave aread. 241 * of the xsave aread.
@@ -245,7 +255,7 @@ static void __init setup_xstate_comp(void)
245 255
246 if (!cpu_has_xsaves) { 256 if (!cpu_has_xsaves) {
247 for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) { 257 for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) {
248 if (test_bit(i, (unsigned long *)&xfeatures_mask)) { 258 if (xfeature_enabled(i)) {
249 xstate_comp_offsets[i] = xstate_offsets[i]; 259 xstate_comp_offsets[i] = xstate_offsets[i];
250 xstate_comp_sizes[i] = xstate_sizes[i]; 260 xstate_comp_sizes[i] = xstate_sizes[i];
251 } 261 }
@@ -257,7 +267,7 @@ static void __init setup_xstate_comp(void)
257 FXSAVE_SIZE + XSAVE_HDR_SIZE; 267 FXSAVE_SIZE + XSAVE_HDR_SIZE;
258 268
259 for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) { 269 for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) {
260 if (test_bit(i, (unsigned long *)&xfeatures_mask)) 270 if (xfeature_enabled(i))
261 xstate_comp_sizes[i] = xstate_sizes[i]; 271 xstate_comp_sizes[i] = xstate_sizes[i];
262 else 272 else
263 xstate_comp_sizes[i] = 0; 273 xstate_comp_sizes[i] = 0;
@@ -319,7 +329,7 @@ static unsigned int __init calculate_xstate_size(void)
319 329
320 calculated_xstate_size = FXSAVE_SIZE + XSAVE_HDR_SIZE; 330 calculated_xstate_size = FXSAVE_SIZE + XSAVE_HDR_SIZE;
321 for (i = FIRST_EXTENDED_XFEATURE; i < 64; i++) { 331 for (i = FIRST_EXTENDED_XFEATURE; i < 64; i++) {
322 if (test_bit(i, (unsigned long *)&xfeatures_mask)) { 332 if (xfeature_enabled(i)) {
323 cpuid_count(XSTATE_CPUID, i, &eax, &ebx, &ecx, &edx); 333 cpuid_count(XSTATE_CPUID, i, &eax, &ebx, &ecx, &edx);
324 calculated_xstate_size += eax; 334 calculated_xstate_size += eax;
325 } 335 }