lkml.org 
[lkml]   [2015]   [Aug]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH 09/15] x86, fpu: add helper xfeature_enabled() instead of test_bit()
From
Date

From: Dave Hansen <dave.hansen@linux.intel.com>

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: Ingo Molnar <mingo@redhat.com>
Cc: x86@kernel.org
Cc: Borislav Petkov <bp@alien8.de>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Cc: linux-kernel@vger.kernel.org
---

b/arch/x86/kernel/fpu/xstate.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff -puN arch/x86/kernel/fpu/xstate.c~use-xfeature_enabled arch/x86/kernel/fpu/xstate.c
--- a/arch/x86/kernel/fpu/xstate.c~use-xfeature_enabled 2015-08-31 15:17:35.008910377 -0700
+++ b/arch/x86/kernel/fpu/xstate.c 2015-08-31 15:17:35.011910514 -0700
@@ -226,6 +226,16 @@ static void __init print_xstate_features
}

/*
+ * Note that in the future we will likely need a pair of
+ * functions here: one for user xstates and the other for
+ * system xstates. For now, they are the same.
+ */
+static int xfeature_enabled(enum xfeature xfeature)
+{
+ return !!(xfeatures_mask & (1UL << xfeature));
+}
+
+/*
* 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.
@@ -245,7 +255,7 @@ static void __init setup_xstate_comp(voi

if (!cpu_has_xsaves) {
for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) {
- if (test_bit(i, (unsigned long *)&xfeatures_mask)) {
+ if (xfeature_enabled(i)) {
xstate_comp_offsets[i] = xstate_offsets[i];
xstate_comp_sizes[i] = xstate_sizes[i];
}
@@ -257,7 +267,7 @@ static void __init setup_xstate_comp(voi
FXSAVE_SIZE + XSAVE_HDR_SIZE;

for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) {
- if (test_bit(i, (unsigned long *)&xfeatures_mask))
+ if (xfeature_enabled(i))
xstate_comp_sizes[i] = xstate_sizes[i];
else
xstate_comp_sizes[i] = 0;
@@ -319,7 +329,7 @@ static unsigned int __init calculate_xst

calculated_xstate_size = FXSAVE_SIZE + XSAVE_HDR_SIZE;
for (i = FIRST_EXTENDED_XFEATURE; i < 64; i++) {
- if (test_bit(i, (unsigned long *)&xfeatures_mask)) {
+ if (xfeature_enabled(i)) {
cpuid_count(XSTATE_CPUID, i, &eax, &ebx, &ecx, &edx);
calculated_xstate_size += eax;
}
_

\
 
 \ /
  Last update: 2015-09-01 01:01    [W:0.085 / U:0.272 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site