aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/include/asm/xsave.h
diff options
context:
space:
mode:
authorFenghua Yu <fenghua.yu@intel.com>2014-05-29 14:12:40 -0400
committerH. Peter Anvin <hpa@linux.intel.com>2014-05-29 17:33:02 -0400
commitadb9d526e98268b647a74726346e1c40e6a37d2e (patch)
treeada7506e46459a3f2ddabb70d109fe44d122952c /arch/x86/include/asm/xsave.h
parent21e726c4a3625a1038e97795b7aad97109ba7e19 (diff)
x86/xsaves: Add xsaves and xrstors support for booting time
Since boot_cpu_data and cpu capabilities are not enabled yet during early booting time, alternative can not be used in some functions to access xsave area. Therefore, we define two new functions xrstor_state_booting() and xsave_state_booting() to access xsave area just during early booting time. xrstor_state_booting restores xstate from xsave area during early booting time. xsave_state_booting saves xstate to xsave area during early booting time. The two functions are similar to xrstor_state and xsave_state respectively. But the two functions don't use alternatives because alternatives are not enabled when they are called in such early booting time. xrstor_state_booting is called only by functions defined as __init. So it's defined as __init and will be removed from memory after booting time. There is no extra memory cost caused by this function during running time. But because xsave_state_booting can be called by run-time function __save_fpu(), it's not defined as __init and will stay in memory during running time although it will not be called anymore during running time. It is not ideal to have this function stay in memory during running time. But it's a pretty small function and the memory cost will be small. By doing in this way, we can avoid to change a lot of code to just remove this small function and save a bit memory for running time. Signed-off-by: Fenghua Yu <fenghua.yu@intel.com> Link: http://lkml.kernel.org/r/1401387164-43416-13-git-send-email-fenghua.yu@intel.com Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'arch/x86/include/asm/xsave.h')
-rw-r--r--arch/x86/include/asm/xsave.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
index 0d1523146545..aa3ff0cca9a1 100644
--- a/arch/x86/include/asm/xsave.h
+++ b/arch/x86/include/asm/xsave.h
@@ -66,6 +66,66 @@ extern int init_fpu(struct task_struct *child);
66 : [err] "=r" (err) 66 : [err] "=r" (err)
67 67
68/* 68/*
69 * This function is called only during boot time when x86 caps are not set
70 * up and alternative can not be used yet.
71 */
72static int xsave_state_booting(struct xsave_struct *fx, u64 mask)
73{
74 u32 lmask = mask;
75 u32 hmask = mask >> 32;
76 int err = 0;
77
78 WARN_ON(system_state != SYSTEM_BOOTING);
79
80 if (boot_cpu_has(X86_FEATURE_XSAVES))
81 asm volatile("1:"XSAVES"\n\t"
82 "2:\n\t"
83 : : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
84 : "memory");
85 else
86 asm volatile("1:"XSAVE"\n\t"
87 "2:\n\t"
88 : : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
89 : "memory");
90
91 asm volatile(xstate_fault
92 : "0" (0)
93 : "memory");
94
95 return err;
96}
97
98/*
99 * This function is called only during boot time when x86 caps are not set
100 * up and alternative can not be used yet.
101 */
102static inline int xrstor_state_booting(struct xsave_struct *fx, u64 mask)
103{
104 u32 lmask = mask;
105 u32 hmask = mask >> 32;
106 int err = 0;
107
108 WARN_ON(system_state != SYSTEM_BOOTING);
109
110 if (boot_cpu_has(X86_FEATURE_XSAVES))
111 asm volatile("1:"XRSTORS"\n\t"
112 "2:\n\t"
113 : : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
114 : "memory");
115 else
116 asm volatile("1:"XRSTOR"\n\t"
117 "2:\n\t"
118 : : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
119 : "memory");
120
121 asm volatile(xstate_fault
122 : "0" (0)
123 : "memory");
124
125 return err;
126}
127
128/*
69 * Save processor xstate to xsave area. 129 * Save processor xstate to xsave area.
70 */ 130 */
71static inline int xsave_state(struct xsave_struct *fx, u64 mask) 131static inline int xsave_state(struct xsave_struct *fx, u64 mask)