xref: /openbmc/linux/arch/x86/kernel/fpu/xstate.c (revision d65fcd60)
162784854SIngo Molnar /*
262784854SIngo Molnar  * xsave/xrstor support.
362784854SIngo Molnar  *
462784854SIngo Molnar  * Author: Suresh Siddha <suresh.b.siddha@intel.com>
562784854SIngo Molnar  */
662784854SIngo Molnar #include <linux/compat.h>
762784854SIngo Molnar #include <linux/cpu.h>
859a36d16SIngo Molnar 
962784854SIngo Molnar #include <asm/fpu/api.h>
1062784854SIngo Molnar #include <asm/fpu/internal.h>
11fcbc99c4SIngo Molnar #include <asm/fpu/signal.h>
1259a36d16SIngo Molnar #include <asm/fpu/regset.h>
13b992c660SIngo Molnar 
1462784854SIngo Molnar #include <asm/tlbflush.h>
1562784854SIngo Molnar 
165b073430SIngo Molnar static const char *xfeature_names[] =
175b073430SIngo Molnar {
185b073430SIngo Molnar 	"x87 floating point registers"	,
195b073430SIngo Molnar 	"SSE registers"			,
205b073430SIngo Molnar 	"AVX registers"			,
215b073430SIngo Molnar 	"MPX bounds registers"		,
225b073430SIngo Molnar 	"MPX CSR"			,
235b073430SIngo Molnar 	"AVX-512 opmask"		,
245b073430SIngo Molnar 	"AVX-512 Hi256"			,
255b073430SIngo Molnar 	"AVX-512 ZMM_Hi256"		,
265b073430SIngo Molnar 	"unknown xstate feature"	,
275b073430SIngo Molnar };
285b073430SIngo Molnar 
2962784854SIngo Molnar /*
3062784854SIngo Molnar  * Mask of xstate features supported by the CPU and the kernel:
3162784854SIngo Molnar  */
325b073430SIngo Molnar u64 xfeatures_mask __read_mostly;
3362784854SIngo Molnar 
3462784854SIngo Molnar static unsigned int xstate_offsets[XFEATURES_NR_MAX], xstate_sizes[XFEATURES_NR_MAX];
3562784854SIngo Molnar static unsigned int xstate_comp_offsets[sizeof(xfeatures_mask)*8];
3662784854SIngo Molnar 
3762784854SIngo Molnar /* The number of supported xfeatures in xfeatures_mask: */
3862784854SIngo Molnar static unsigned int xfeatures_nr;
3962784854SIngo Molnar 
4062784854SIngo Molnar /*
415b073430SIngo Molnar  * Return whether the system supports a given xfeature.
425b073430SIngo Molnar  *
435b073430SIngo Molnar  * Also return the name of the (most advanced) feature that the caller requested:
445b073430SIngo Molnar  */
455b073430SIngo Molnar int cpu_has_xfeatures(u64 xfeatures_needed, const char **feature_name)
465b073430SIngo Molnar {
475b073430SIngo Molnar 	u64 xfeatures_missing = xfeatures_needed & ~xfeatures_mask;
485b073430SIngo Molnar 
495b073430SIngo Molnar 	if (unlikely(feature_name)) {
505b073430SIngo Molnar 		long xfeature_idx, max_idx;
515b073430SIngo Molnar 		u64 xfeatures_print;
525b073430SIngo Molnar 		/*
535b073430SIngo Molnar 		 * So we use FLS here to be able to print the most advanced
545b073430SIngo Molnar 		 * feature that was requested but is missing. So if a driver
555b073430SIngo Molnar 		 * asks about "XSTATE_SSE | XSTATE_YMM" we'll print the
565b073430SIngo Molnar 		 * missing AVX feature - this is the most informative message
575b073430SIngo Molnar 		 * to users:
585b073430SIngo Molnar 		 */
595b073430SIngo Molnar 		if (xfeatures_missing)
605b073430SIngo Molnar 			xfeatures_print = xfeatures_missing;
615b073430SIngo Molnar 		else
625b073430SIngo Molnar 			xfeatures_print = xfeatures_needed;
635b073430SIngo Molnar 
645b073430SIngo Molnar 		xfeature_idx = fls64(xfeatures_print)-1;
655b073430SIngo Molnar 		max_idx = ARRAY_SIZE(xfeature_names)-1;
665b073430SIngo Molnar 		xfeature_idx = min(xfeature_idx, max_idx);
675b073430SIngo Molnar 
685b073430SIngo Molnar 		*feature_name = xfeature_names[xfeature_idx];
695b073430SIngo Molnar 	}
705b073430SIngo Molnar 
715b073430SIngo Molnar 	if (xfeatures_missing)
725b073430SIngo Molnar 		return 0;
735b073430SIngo Molnar 
745b073430SIngo Molnar 	return 1;
755b073430SIngo Molnar }
765b073430SIngo Molnar EXPORT_SYMBOL_GPL(cpu_has_xfeatures);
775b073430SIngo Molnar 
785b073430SIngo Molnar /*
79aeb997b9SIngo Molnar  * When executing XSAVEOPT (or other optimized XSAVE instructions), if
80aeb997b9SIngo Molnar  * a processor implementation detects that an FPU state component is still
81aeb997b9SIngo Molnar  * (or is again) in its initialized state, it may clear the corresponding
82aeb997b9SIngo Molnar  * bit in the header.xfeatures field, and can skip the writeout of registers
83aeb997b9SIngo Molnar  * to the corresponding memory layout.
8462784854SIngo Molnar  *
8562784854SIngo Molnar  * This means that when the bit is zero, the state component might still contain
8662784854SIngo Molnar  * some previous - non-initialized register state.
8762784854SIngo Molnar  *
8862784854SIngo Molnar  * Before writing xstate information to user-space we sanitize those components,
8962784854SIngo Molnar  * to always ensure that the memory layout of a feature will be in the init state
9062784854SIngo Molnar  * if the corresponding header bit is zero. This is to ensure that user-space doesn't
9162784854SIngo Molnar  * see some stale state in the memory layout during signal handling, debugging etc.
9262784854SIngo Molnar  */
9336e49e7fSIngo Molnar void fpstate_sanitize_xstate(struct fpu *fpu)
9462784854SIngo Molnar {
95c47ada30SIngo Molnar 	struct fxregs_state *fx = &fpu->state.fxsave;
9662784854SIngo Molnar 	int feature_bit;
9762784854SIngo Molnar 	u64 xfeatures;
9862784854SIngo Molnar 
991ac91a76SIngo Molnar 	if (!use_xsaveopt())
10062784854SIngo Molnar 		return;
10162784854SIngo Molnar 
10236e49e7fSIngo Molnar 	xfeatures = fpu->state.xsave.header.xfeatures;
10362784854SIngo Molnar 
10462784854SIngo Molnar 	/*
10562784854SIngo Molnar 	 * None of the feature bits are in init state. So nothing else
10662784854SIngo Molnar 	 * to do for us, as the memory layout is up to date.
10762784854SIngo Molnar 	 */
10862784854SIngo Molnar 	if ((xfeatures & xfeatures_mask) == xfeatures_mask)
10962784854SIngo Molnar 		return;
11062784854SIngo Molnar 
11162784854SIngo Molnar 	/*
11262784854SIngo Molnar 	 * FP is in init state
11362784854SIngo Molnar 	 */
11462784854SIngo Molnar 	if (!(xfeatures & XSTATE_FP)) {
11562784854SIngo Molnar 		fx->cwd = 0x37f;
11662784854SIngo Molnar 		fx->swd = 0;
11762784854SIngo Molnar 		fx->twd = 0;
11862784854SIngo Molnar 		fx->fop = 0;
11962784854SIngo Molnar 		fx->rip = 0;
12062784854SIngo Molnar 		fx->rdp = 0;
12162784854SIngo Molnar 		memset(&fx->st_space[0], 0, 128);
12262784854SIngo Molnar 	}
12362784854SIngo Molnar 
12462784854SIngo Molnar 	/*
12562784854SIngo Molnar 	 * SSE is in init state
12662784854SIngo Molnar 	 */
12762784854SIngo Molnar 	if (!(xfeatures & XSTATE_SSE))
12862784854SIngo Molnar 		memset(&fx->xmm_space[0], 0, 256);
12962784854SIngo Molnar 
13062784854SIngo Molnar 	/*
13162784854SIngo Molnar 	 * First two features are FPU and SSE, which above we handled
13262784854SIngo Molnar 	 * in a special way already:
13362784854SIngo Molnar 	 */
13462784854SIngo Molnar 	feature_bit = 0x2;
13562784854SIngo Molnar 	xfeatures = (xfeatures_mask & ~xfeatures) >> 2;
13662784854SIngo Molnar 
13762784854SIngo Molnar 	/*
13862784854SIngo Molnar 	 * Update all the remaining memory layouts according to their
13962784854SIngo Molnar 	 * standard xstate layout, if their header bit is in the init
14062784854SIngo Molnar 	 * state:
14162784854SIngo Molnar 	 */
14262784854SIngo Molnar 	while (xfeatures) {
14362784854SIngo Molnar 		if (xfeatures & 0x1) {
14462784854SIngo Molnar 			int offset = xstate_offsets[feature_bit];
14562784854SIngo Molnar 			int size = xstate_sizes[feature_bit];
14662784854SIngo Molnar 
14762784854SIngo Molnar 			memcpy((void *)fx + offset,
1486f575023SIngo Molnar 			       (void *)&init_fpstate.xsave + offset,
14962784854SIngo Molnar 			       size);
15062784854SIngo Molnar 		}
15162784854SIngo Molnar 
15262784854SIngo Molnar 		xfeatures >>= 1;
15362784854SIngo Molnar 		feature_bit++;
15462784854SIngo Molnar 	}
15562784854SIngo Molnar }
15662784854SIngo Molnar 
15762784854SIngo Molnar /*
15862784854SIngo Molnar  * Enable the extended processor state save/restore feature.
15962784854SIngo Molnar  * Called once per CPU onlining.
16062784854SIngo Molnar  */
16162784854SIngo Molnar void fpu__init_cpu_xstate(void)
16262784854SIngo Molnar {
16362784854SIngo Molnar 	if (!cpu_has_xsave || !xfeatures_mask)
16462784854SIngo Molnar 		return;
16562784854SIngo Molnar 
16662784854SIngo Molnar 	cr4_set_bits(X86_CR4_OSXSAVE);
16762784854SIngo Molnar 	xsetbv(XCR_XFEATURE_ENABLED_MASK, xfeatures_mask);
16862784854SIngo Molnar }
16962784854SIngo Molnar 
17062784854SIngo Molnar /*
17139f1acd2SIngo Molnar  * Record the offsets and sizes of various xstates contained
17239f1acd2SIngo Molnar  * in the XSAVE state memory layout.
17339f1acd2SIngo Molnar  *
17439f1acd2SIngo Molnar  * ( Note that certain features might be non-present, for them
17539f1acd2SIngo Molnar  *   we'll have 0 offset and 0 size. )
17662784854SIngo Molnar  */
17762784854SIngo Molnar static void __init setup_xstate_features(void)
17862784854SIngo Molnar {
17939f1acd2SIngo Molnar 	u32 eax, ebx, ecx, edx, leaf;
18062784854SIngo Molnar 
18162784854SIngo Molnar 	xfeatures_nr = fls64(xfeatures_mask);
18262784854SIngo Molnar 
18339f1acd2SIngo Molnar 	for (leaf = 2; leaf < xfeatures_nr; leaf++) {
18462784854SIngo Molnar 		cpuid_count(XSTATE_CPUID, leaf, &eax, &ebx, &ecx, &edx);
18562784854SIngo Molnar 
18662784854SIngo Molnar 		xstate_offsets[leaf] = ebx;
18762784854SIngo Molnar 		xstate_sizes[leaf] = eax;
18862784854SIngo Molnar 
18939f1acd2SIngo Molnar 		printk(KERN_INFO "x86/fpu: xstate_offset[%d]: %04x, xstate_sizes[%d]: %04x\n", leaf, ebx, leaf, eax);
19062784854SIngo Molnar 		leaf++;
19139f1acd2SIngo Molnar 	}
19262784854SIngo Molnar }
19362784854SIngo Molnar 
19432231879SIngo Molnar static void __init print_xstate_feature(u64 xstate_mask)
19562784854SIngo Molnar {
19633588b52SIngo Molnar 	const char *feature_name;
19762784854SIngo Molnar 
19833588b52SIngo Molnar 	if (cpu_has_xfeatures(xstate_mask, &feature_name))
19933588b52SIngo Molnar 		pr_info("x86/fpu: Supporting XSAVE feature 0x%02Lx: '%s'\n", xstate_mask, feature_name);
20062784854SIngo Molnar }
20162784854SIngo Molnar 
20262784854SIngo Molnar /*
20362784854SIngo Molnar  * Print out all the supported xstate features:
20462784854SIngo Molnar  */
20532231879SIngo Molnar static void __init print_xstate_features(void)
20662784854SIngo Molnar {
20733588b52SIngo Molnar 	print_xstate_feature(XSTATE_FP);
20833588b52SIngo Molnar 	print_xstate_feature(XSTATE_SSE);
20933588b52SIngo Molnar 	print_xstate_feature(XSTATE_YMM);
21033588b52SIngo Molnar 	print_xstate_feature(XSTATE_BNDREGS);
21133588b52SIngo Molnar 	print_xstate_feature(XSTATE_BNDCSR);
21233588b52SIngo Molnar 	print_xstate_feature(XSTATE_OPMASK);
21333588b52SIngo Molnar 	print_xstate_feature(XSTATE_ZMM_Hi256);
21433588b52SIngo Molnar 	print_xstate_feature(XSTATE_Hi16_ZMM);
21562784854SIngo Molnar }
21662784854SIngo Molnar 
21762784854SIngo Molnar /*
21862784854SIngo Molnar  * This function sets up offsets and sizes of all extended states in
21962784854SIngo Molnar  * xsave area. This supports both standard format and compacted format
22062784854SIngo Molnar  * of the xsave aread.
22162784854SIngo Molnar  */
22232231879SIngo Molnar static void __init setup_xstate_comp(void)
22362784854SIngo Molnar {
22462784854SIngo Molnar 	unsigned int xstate_comp_sizes[sizeof(xfeatures_mask)*8];
22562784854SIngo Molnar 	int i;
22662784854SIngo Molnar 
22762784854SIngo Molnar 	/*
22862784854SIngo Molnar 	 * The FP xstates and SSE xstates are legacy states. They are always
22962784854SIngo Molnar 	 * in the fixed offsets in the xsave area in either compacted form
23062784854SIngo Molnar 	 * or standard form.
23162784854SIngo Molnar 	 */
23262784854SIngo Molnar 	xstate_comp_offsets[0] = 0;
233c47ada30SIngo Molnar 	xstate_comp_offsets[1] = offsetof(struct fxregs_state, xmm_space);
23462784854SIngo Molnar 
23562784854SIngo Molnar 	if (!cpu_has_xsaves) {
23662784854SIngo Molnar 		for (i = 2; i < xfeatures_nr; i++) {
23762784854SIngo Molnar 			if (test_bit(i, (unsigned long *)&xfeatures_mask)) {
23862784854SIngo Molnar 				xstate_comp_offsets[i] = xstate_offsets[i];
23962784854SIngo Molnar 				xstate_comp_sizes[i] = xstate_sizes[i];
24062784854SIngo Molnar 			}
24162784854SIngo Molnar 		}
24262784854SIngo Molnar 		return;
24362784854SIngo Molnar 	}
24462784854SIngo Molnar 
24562784854SIngo Molnar 	xstate_comp_offsets[2] = FXSAVE_SIZE + XSAVE_HDR_SIZE;
24662784854SIngo Molnar 
24762784854SIngo Molnar 	for (i = 2; i < xfeatures_nr; i++) {
24862784854SIngo Molnar 		if (test_bit(i, (unsigned long *)&xfeatures_mask))
24962784854SIngo Molnar 			xstate_comp_sizes[i] = xstate_sizes[i];
25062784854SIngo Molnar 		else
25162784854SIngo Molnar 			xstate_comp_sizes[i] = 0;
25262784854SIngo Molnar 
25362784854SIngo Molnar 		if (i > 2)
25462784854SIngo Molnar 			xstate_comp_offsets[i] = xstate_comp_offsets[i-1]
25562784854SIngo Molnar 					+ xstate_comp_sizes[i-1];
25662784854SIngo Molnar 
25762784854SIngo Molnar 	}
25862784854SIngo Molnar }
25962784854SIngo Molnar 
26062784854SIngo Molnar /*
26162784854SIngo Molnar  * setup the xstate image representing the init state
26262784854SIngo Molnar  */
26332231879SIngo Molnar static void __init setup_init_fpu_buf(void)
26462784854SIngo Molnar {
265e97131a8SIngo Molnar 	static int on_boot_cpu = 1;
266e97131a8SIngo Molnar 
267e97131a8SIngo Molnar 	WARN_ON_FPU(!on_boot_cpu);
268e97131a8SIngo Molnar 	on_boot_cpu = 0;
269e97131a8SIngo Molnar 
27062784854SIngo Molnar 	if (!cpu_has_xsave)
27162784854SIngo Molnar 		return;
27262784854SIngo Molnar 
27362784854SIngo Molnar 	setup_xstate_features();
27462784854SIngo Molnar 	print_xstate_features();
27562784854SIngo Molnar 
27662784854SIngo Molnar 	if (cpu_has_xsaves) {
2776f575023SIngo Molnar 		init_fpstate.xsave.header.xcomp_bv = (u64)1 << 63 | xfeatures_mask;
2786f575023SIngo Molnar 		init_fpstate.xsave.header.xfeatures = xfeatures_mask;
27962784854SIngo Molnar 	}
28062784854SIngo Molnar 
28162784854SIngo Molnar 	/*
28262784854SIngo Molnar 	 * Init all the features state with header_bv being 0x0
28362784854SIngo Molnar 	 */
284d65fcd60SIngo Molnar 	copy_kernel_to_xregs_booting(&init_fpstate.xsave);
28562784854SIngo Molnar 
28662784854SIngo Molnar 	/*
28762784854SIngo Molnar 	 * Dump the init state again. This is to identify the init state
28862784854SIngo Molnar 	 * of any feature which is not represented by all zero's.
28962784854SIngo Molnar 	 */
290c6813144SIngo Molnar 	copy_xregs_to_kernel_booting(&init_fpstate.xsave);
29162784854SIngo Molnar }
29262784854SIngo Molnar 
29362784854SIngo Molnar /*
29462784854SIngo Molnar  * Calculate total size of enabled xstates in XCR0/xfeatures_mask.
29562784854SIngo Molnar  */
29662784854SIngo Molnar static void __init init_xstate_size(void)
29762784854SIngo Molnar {
29862784854SIngo Molnar 	unsigned int eax, ebx, ecx, edx;
29962784854SIngo Molnar 	int i;
30062784854SIngo Molnar 
30162784854SIngo Molnar 	if (!cpu_has_xsaves) {
30262784854SIngo Molnar 		cpuid_count(XSTATE_CPUID, 0, &eax, &ebx, &ecx, &edx);
30362784854SIngo Molnar 		xstate_size = ebx;
30462784854SIngo Molnar 		return;
30562784854SIngo Molnar 	}
30662784854SIngo Molnar 
30762784854SIngo Molnar 	xstate_size = FXSAVE_SIZE + XSAVE_HDR_SIZE;
30862784854SIngo Molnar 	for (i = 2; i < 64; i++) {
30962784854SIngo Molnar 		if (test_bit(i, (unsigned long *)&xfeatures_mask)) {
31062784854SIngo Molnar 			cpuid_count(XSTATE_CPUID, i, &eax, &ebx, &ecx, &edx);
31162784854SIngo Molnar 			xstate_size += eax;
31262784854SIngo Molnar 		}
31362784854SIngo Molnar 	}
31462784854SIngo Molnar }
31562784854SIngo Molnar 
31662784854SIngo Molnar /*
31762784854SIngo Molnar  * Enable and initialize the xsave feature.
31862784854SIngo Molnar  * Called once per system bootup.
31962784854SIngo Molnar  */
32032231879SIngo Molnar void __init fpu__init_system_xstate(void)
32162784854SIngo Molnar {
32262784854SIngo Molnar 	unsigned int eax, ebx, ecx, edx;
323e97131a8SIngo Molnar 	static int on_boot_cpu = 1;
324e97131a8SIngo Molnar 
325e97131a8SIngo Molnar 	WARN_ON_FPU(!on_boot_cpu);
326e97131a8SIngo Molnar 	on_boot_cpu = 0;
32762784854SIngo Molnar 
32862784854SIngo Molnar 	if (!cpu_has_xsave) {
32962784854SIngo Molnar 		pr_info("x86/fpu: Legacy x87 FPU detected.\n");
33062784854SIngo Molnar 		return;
33162784854SIngo Molnar 	}
33262784854SIngo Molnar 
33362784854SIngo Molnar 	if (boot_cpu_data.cpuid_level < XSTATE_CPUID) {
334e97131a8SIngo Molnar 		WARN_ON_FPU(1);
33562784854SIngo Molnar 		return;
33662784854SIngo Molnar 	}
33762784854SIngo Molnar 
33862784854SIngo Molnar 	cpuid_count(XSTATE_CPUID, 0, &eax, &ebx, &ecx, &edx);
33962784854SIngo Molnar 	xfeatures_mask = eax + ((u64)edx << 32);
34062784854SIngo Molnar 
34162784854SIngo Molnar 	if ((xfeatures_mask & XSTATE_FPSSE) != XSTATE_FPSSE) {
34262784854SIngo Molnar 		pr_err("x86/fpu: FP/SSE not present amongst the CPU's xstate features: 0x%llx.\n", xfeatures_mask);
34362784854SIngo Molnar 		BUG();
34462784854SIngo Molnar 	}
34562784854SIngo Molnar 
3466e553594SIngo Molnar 	/* Support only the state known to the OS: */
34762784854SIngo Molnar 	xfeatures_mask = xfeatures_mask & XCNTXT_MASK;
34862784854SIngo Molnar 
34962784854SIngo Molnar 	/* Enable xstate instructions to be able to continue with initialization: */
35062784854SIngo Molnar 	fpu__init_cpu_xstate();
35162784854SIngo Molnar 
3526e553594SIngo Molnar 	/* Recompute the context size for enabled features: */
35362784854SIngo Molnar 	init_xstate_size();
35462784854SIngo Molnar 
35562784854SIngo Molnar 	update_regset_xstate_info(xstate_size, xfeatures_mask);
356b992c660SIngo Molnar 	fpu__init_prepare_fx_sw_frame();
35762784854SIngo Molnar 	setup_init_fpu_buf();
3585fd402dfSIngo Molnar 	setup_xstate_comp();
35962784854SIngo Molnar 
36062784854SIngo Molnar 	pr_info("x86/fpu: Enabled xstate features 0x%llx, context size is 0x%x bytes, using '%s' format.\n",
36162784854SIngo Molnar 		xfeatures_mask,
36262784854SIngo Molnar 		xstate_size,
36362784854SIngo Molnar 		cpu_has_xsaves ? "compacted" : "standard");
36462784854SIngo Molnar }
36562784854SIngo Molnar 
36662784854SIngo Molnar /*
36762784854SIngo Molnar  * Restore minimal FPU state after suspend:
36862784854SIngo Molnar  */
36962784854SIngo Molnar void fpu__resume_cpu(void)
37062784854SIngo Molnar {
37162784854SIngo Molnar 	/*
37262784854SIngo Molnar 	 * Restore XCR0 on xsave capable CPUs:
37362784854SIngo Molnar 	 */
37462784854SIngo Molnar 	if (cpu_has_xsave)
37562784854SIngo Molnar 		xsetbv(XCR_XFEATURE_ENABLED_MASK, xfeatures_mask);
37662784854SIngo Molnar }
37762784854SIngo Molnar 
37862784854SIngo Molnar /*
37962784854SIngo Molnar  * Given the xsave area and a state inside, this function returns the
38062784854SIngo Molnar  * address of the state.
38162784854SIngo Molnar  *
38262784854SIngo Molnar  * This is the API that is called to get xstate address in either
38362784854SIngo Molnar  * standard format or compacted format of xsave area.
38462784854SIngo Molnar  *
38562784854SIngo Molnar  * Inputs:
38662784854SIngo Molnar  *	xsave: base address of the xsave area;
38762784854SIngo Molnar  *	xstate: state which is defined in xsave.h (e.g. XSTATE_FP, XSTATE_SSE,
38862784854SIngo Molnar  *	etc.)
38962784854SIngo Molnar  * Output:
39062784854SIngo Molnar  *	address of the state in the xsave area.
39162784854SIngo Molnar  */
392c47ada30SIngo Molnar void *get_xsave_addr(struct xregs_state *xsave, int xstate)
39362784854SIngo Molnar {
39462784854SIngo Molnar 	int feature = fls64(xstate) - 1;
39562784854SIngo Molnar 	if (!test_bit(feature, (unsigned long *)&xfeatures_mask))
39662784854SIngo Molnar 		return NULL;
39762784854SIngo Molnar 
39862784854SIngo Molnar 	return (void *)xsave + xstate_comp_offsets[feature];
39962784854SIngo Molnar }
40062784854SIngo Molnar EXPORT_SYMBOL_GPL(get_xsave_addr);
401