Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Dave Hansen and committed by
Ingo Molnar
633d54c4 ee9ae257

+13 -3
+13 -3
arch/x86/kernel/fpu/xstate.c
··· 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 + */ 233 + static int xfeature_enabled(enum xfeature xfeature) 234 + { 235 + return !!(xfeatures_mask & (1UL << xfeature)); 236 + } 237 + 238 + /* 229 239 * This function sets up offsets and sizes of all extended states in 230 240 * xsave area. This supports both standard format and compacted format 231 241 * of the xsave aread. ··· 255 245 256 246 if (!cpu_has_xsaves) { 257 247 for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) { 258 - if (test_bit(i, (unsigned long *)&xfeatures_mask)) { 248 + if (xfeature_enabled(i)) { 259 249 xstate_comp_offsets[i] = xstate_offsets[i]; 260 250 xstate_comp_sizes[i] = xstate_sizes[i]; 261 251 } ··· 267 257 FXSAVE_SIZE + XSAVE_HDR_SIZE; 268 258 269 259 for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) { 270 - if (test_bit(i, (unsigned long *)&xfeatures_mask)) 260 + if (xfeature_enabled(i)) 271 261 xstate_comp_sizes[i] = xstate_sizes[i]; 272 262 else 273 263 xstate_comp_sizes[i] = 0; ··· 329 319 330 320 calculated_xstate_size = FXSAVE_SIZE + XSAVE_HDR_SIZE; 331 321 for (i = FIRST_EXTENDED_XFEATURE; i < 64; i++) { 332 - if (test_bit(i, (unsigned long *)&xfeatures_mask)) { 322 + if (xfeature_enabled(i)) { 333 323 cpuid_count(XSTATE_CPUID, i, &eax, &ebx, &ecx, &edx); 334 324 calculated_xstate_size += eax; 335 325 }