aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86
diff options
context:
space:
mode:
authorPekka Riikonen <priikone@iki.fi>2013-05-13 08:32:07 -0400
committerH. Peter Anvin <hpa@linux.intel.com>2013-05-30 19:36:42 -0400
commit5187b28ff08249ab8a162e802209ed04e271ca02 (patch)
treed6620d76ab4011f03d5960f0e3dc4711e098b5fb /arch/x86
parent2baad6121e2b2fa3428ee6cb2298107be11ab23a (diff)
x86: Allow FPU to be used at interrupt time even with eagerfpu
With the addition of eagerfpu the irq_fpu_usable() now returns false negatives especially in the case of ksoftirqd and interrupted idle task, two common cases for FPU use for example in networking/crypto. With eagerfpu=off FPU use is possible in those contexts. This is because of the eagerfpu check in interrupted_kernel_fpu_idle(): ... * For now, with eagerfpu we will return interrupted kernel FPU * state as not-idle. TBD: Ideally we can change the return value * to something like __thread_has_fpu(current). But we need to * be careful of doing __thread_clear_has_fpu() before saving * the FPU etc for supporting nested uses etc. For now, take * the simple route! ... if (use_eager_fpu()) return 0; As eagerfpu is automatically "on" on those CPUs that also have the features like AES-NI this patch changes the eagerfpu check to return 1 in case the kernel_fpu_begin() has not been said yet. Once it has been the __thread_has_fpu() will start returning 0. Notice that with eagerfpu the __thread_has_fpu is always true initially. FPU use is thus always possible no matter what task is under us, unless the state has already been saved with kernel_fpu_begin(). [ hpa: this is a performance regression, not a correctness regression, but since it can be quite serious on CPUs which need encryption at interrupt time I am marking this for urgent/stable. ] Signed-off-by: Pekka Riikonen <priikone@iki.fi> Link: http://lkml.kernel.org/r/alpine.GSO.2.00.1305131356320.18@git.silcnet.org Cc: <stable@vger.kernel.org> v3.7+ Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'arch/x86')
-rw-r--r--arch/x86/kernel/i387.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
index 245a71db401a..cb339097b9ea 100644
--- a/arch/x86/kernel/i387.c
+++ b/arch/x86/kernel/i387.c
@@ -22,23 +22,19 @@
22/* 22/*
23 * Were we in an interrupt that interrupted kernel mode? 23 * Were we in an interrupt that interrupted kernel mode?
24 * 24 *
25 * For now, with eagerfpu we will return interrupted kernel FPU
26 * state as not-idle. TBD: Ideally we can change the return value
27 * to something like __thread_has_fpu(current). But we need to
28 * be careful of doing __thread_clear_has_fpu() before saving
29 * the FPU etc for supporting nested uses etc. For now, take
30 * the simple route!
31 *
32 * On others, we can do a kernel_fpu_begin/end() pair *ONLY* if that 25 * On others, we can do a kernel_fpu_begin/end() pair *ONLY* if that
33 * pair does nothing at all: the thread must not have fpu (so 26 * pair does nothing at all: the thread must not have fpu (so
34 * that we don't try to save the FPU state), and TS must 27 * that we don't try to save the FPU state), and TS must
35 * be set (so that the clts/stts pair does nothing that is 28 * be set (so that the clts/stts pair does nothing that is
36 * visible in the interrupted kernel thread). 29 * visible in the interrupted kernel thread).
30 *
31 * Except for the eagerfpu case when we return 1 unless we've already
32 * been eager and saved the state in kernel_fpu_begin().
37 */ 33 */
38static inline bool interrupted_kernel_fpu_idle(void) 34static inline bool interrupted_kernel_fpu_idle(void)
39{ 35{
40 if (use_eager_fpu()) 36 if (use_eager_fpu())
41 return 0; 37 return __thread_has_fpu(current);
42 38
43 return !__thread_has_fpu(current) && 39 return !__thread_has_fpu(current) &&
44 (read_cr0() & X86_CR0_TS); 40 (read_cr0() & X86_CR0_TS);
@@ -78,8 +74,8 @@ void __kernel_fpu_begin(void)
78 struct task_struct *me = current; 74 struct task_struct *me = current;
79 75
80 if (__thread_has_fpu(me)) { 76 if (__thread_has_fpu(me)) {
81 __save_init_fpu(me);
82 __thread_clear_has_fpu(me); 77 __thread_clear_has_fpu(me);
78 __save_init_fpu(me);
83 /* We do 'stts()' in __kernel_fpu_end() */ 79 /* We do 'stts()' in __kernel_fpu_end() */
84 } else if (!use_eager_fpu()) { 80 } else if (!use_eager_fpu()) {
85 this_cpu_write(fpu_owner_task, NULL); 81 this_cpu_write(fpu_owner_task, NULL);