aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Mundt <lethal@linux-sh.org>2008-03-26 06:02:47 -0400
committerPaul Mundt <lethal@linux-sh.org>2008-03-26 06:02:47 -0400
commit9bbafce2eec190ef7e44b0eb1095ba17ce6ad3af (patch)
tree8deae79efc43d39763bdba8ca9b670e6a1782859
parent05dda977f2574c3341abef9b74c27d2b362e1e3a (diff)
sh: Fix occasional FPU register corruption under preempt.
Presently with preempt enabled there's the possibility to be preempted after the TIF_USEDFPU test and the register save, leading to bogus state post-__switch_to(). Use an explicit preempt_disable()/enable() pair around unlazy_fpu()/clear_fpu() to avoid this. Follows the x86 change. Reported-by: Takuo Koguchi <takuo.koguchi.sw@hitachi.com> Signed-off-by: Paul Mundt <lethal@linux-sh.org>
-rw-r--r--arch/sh/kernel/cpu/sh2a/fpu.c1
-rw-r--r--arch/sh/kernel/cpu/sh4/fpu.c1
-rw-r--r--arch/sh/kernel/cpu/sh5/fpu.c1
-rw-r--r--arch/sh/kernel/dump_task.c1
-rw-r--r--arch/sh/kernel/process_32.c1
-rw-r--r--arch/sh/kernel/signal_32.c1
-rw-r--r--include/asm-sh/fpu.h32
-rw-r--r--include/asm-sh/processor.h1
-rw-r--r--include/asm-sh/processor_32.h1
-rw-r--r--include/asm-sh/processor_64.h1
10 files changed, 26 insertions, 15 deletions
diff --git a/arch/sh/kernel/cpu/sh2a/fpu.c b/arch/sh/kernel/cpu/sh2a/fpu.c
index ff99562456fb..5627c0b3ffa8 100644
--- a/arch/sh/kernel/cpu/sh2a/fpu.c
+++ b/arch/sh/kernel/cpu/sh2a/fpu.c
@@ -13,6 +13,7 @@
13#include <linux/signal.h> 13#include <linux/signal.h>
14#include <asm/processor.h> 14#include <asm/processor.h>
15#include <asm/io.h> 15#include <asm/io.h>
16#include <asm/fpu.h>
16 17
17/* The PR (precision) bit in the FP Status Register must be clear when 18/* The PR (precision) bit in the FP Status Register must be clear when
18 * an frchg instruction is executed, otherwise the instruction is undefined. 19 * an frchg instruction is executed, otherwise the instruction is undefined.
diff --git a/arch/sh/kernel/cpu/sh4/fpu.c b/arch/sh/kernel/cpu/sh4/fpu.c
index 817f9939cda6..8020796139f1 100644
--- a/arch/sh/kernel/cpu/sh4/fpu.c
+++ b/arch/sh/kernel/cpu/sh4/fpu.c
@@ -16,6 +16,7 @@
16#include <asm/cpu/fpu.h> 16#include <asm/cpu/fpu.h>
17#include <asm/processor.h> 17#include <asm/processor.h>
18#include <asm/system.h> 18#include <asm/system.h>
19#include <asm/fpu.h>
19 20
20/* The PR (precision) bit in the FP Status Register must be clear when 21/* The PR (precision) bit in the FP Status Register must be clear when
21 * an frchg instruction is executed, otherwise the instruction is undefined. 22 * an frchg instruction is executed, otherwise the instruction is undefined.
diff --git a/arch/sh/kernel/cpu/sh5/fpu.c b/arch/sh/kernel/cpu/sh5/fpu.c
index 30b76a94abf2..dd4f51ffb50e 100644
--- a/arch/sh/kernel/cpu/sh5/fpu.c
+++ b/arch/sh/kernel/cpu/sh5/fpu.c
@@ -17,6 +17,7 @@
17#include <asm/processor.h> 17#include <asm/processor.h>
18#include <asm/user.h> 18#include <asm/user.h>
19#include <asm/io.h> 19#include <asm/io.h>
20#include <asm/fpu.h>
20 21
21/* 22/*
22 * Initially load the FPU with signalling NANS. This bit pattern 23 * Initially load the FPU with signalling NANS. This bit pattern
diff --git a/arch/sh/kernel/dump_task.c b/arch/sh/kernel/dump_task.c
index 4a8a4083ff0b..1db7ce0f25d4 100644
--- a/arch/sh/kernel/dump_task.c
+++ b/arch/sh/kernel/dump_task.c
@@ -1,5 +1,6 @@
1#include <linux/elfcore.h> 1#include <linux/elfcore.h>
2#include <linux/sched.h> 2#include <linux/sched.h>
3#include <asm/fpu.h>
3 4
4/* 5/*
5 * Capture the user space registers if the task is not running (in user space) 6 * Capture the user space registers if the task is not running (in user space)
diff --git a/arch/sh/kernel/process_32.c b/arch/sh/kernel/process_32.c
index 9ab1926b9d10..b98e37a1f54c 100644
--- a/arch/sh/kernel/process_32.c
+++ b/arch/sh/kernel/process_32.c
@@ -25,6 +25,7 @@
25#include <asm/pgalloc.h> 25#include <asm/pgalloc.h>
26#include <asm/system.h> 26#include <asm/system.h>
27#include <asm/ubc.h> 27#include <asm/ubc.h>
28#include <asm/fpu.h>
28 29
29static int hlt_counter; 30static int hlt_counter;
30int ubc_usercnt = 0; 31int ubc_usercnt = 0;
diff --git a/arch/sh/kernel/signal_32.c b/arch/sh/kernel/signal_32.c
index f6b5fbfe75c4..f311551d9a05 100644
--- a/arch/sh/kernel/signal_32.c
+++ b/arch/sh/kernel/signal_32.c
@@ -29,6 +29,7 @@
29#include <asm/uaccess.h> 29#include <asm/uaccess.h>
30#include <asm/pgtable.h> 30#include <asm/pgtable.h>
31#include <asm/cacheflush.h> 31#include <asm/cacheflush.h>
32#include <asm/fpu.h>
32 33
33#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) 34#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
34 35
diff --git a/include/asm-sh/fpu.h b/include/asm-sh/fpu.h
index f8429880a270..f89abf5920d8 100644
--- a/include/asm-sh/fpu.h
+++ b/include/asm-sh/fpu.h
@@ -1,9 +1,8 @@
1#ifndef __ASM_SH_FPU_H 1#ifndef __ASM_SH_FPU_H
2#define __ASM_SH_FPU_H 2#define __ASM_SH_FPU_H
3 3
4#define SR_FD 0x00008000
5
6#ifndef __ASSEMBLY__ 4#ifndef __ASSEMBLY__
5#include <linux/preempt.h>
7#include <asm/ptrace.h> 6#include <asm/ptrace.h>
8 7
9#ifdef CONFIG_SH_FPU 8#ifdef CONFIG_SH_FPU
@@ -28,18 +27,23 @@ extern void save_fpu(struct task_struct *__tsk, struct pt_regs *regs);
28 27
29extern int do_fpu_inst(unsigned short, struct pt_regs *); 28extern int do_fpu_inst(unsigned short, struct pt_regs *);
30 29
31#define unlazy_fpu(tsk, regs) do { \ 30static inline void unlazy_fpu(struct task_struct *tsk, struct pt_regs *regs)
32 if (test_tsk_thread_flag(tsk, TIF_USEDFPU)) { \ 31{
33 save_fpu(tsk, regs); \ 32 preempt_disable();
34 } \ 33 if (test_tsk_thread_flag(tsk, TIF_USEDFPU))
35} while (0) 34 save_fpu(tsk, regs);
36 35 preempt_enable();
37#define clear_fpu(tsk, regs) do { \ 36}
38 if (test_tsk_thread_flag(tsk, TIF_USEDFPU)) { \ 37
39 clear_tsk_thread_flag(tsk, TIF_USEDFPU); \ 38static inline void clear_fpu(struct task_struct *tsk, struct pt_regs *regs)
40 release_fpu(regs); \ 39{
41 } \ 40 preempt_disable();
42} while (0) 41 if (test_tsk_thread_flag(tsk, TIF_USEDFPU)) {
42 clear_tsk_thread_flag(tsk, TIF_USEDFPU);
43 release_fpu(regs);
44 }
45 preempt_enable();
46}
43 47
44#endif /* __ASSEMBLY__ */ 48#endif /* __ASSEMBLY__ */
45 49
diff --git a/include/asm-sh/processor.h b/include/asm-sh/processor.h
index 19fe47c1ca17..ec707b98e5b9 100644
--- a/include/asm-sh/processor.h
+++ b/include/asm-sh/processor.h
@@ -2,7 +2,6 @@
2#define __ASM_SH_PROCESSOR_H 2#define __ASM_SH_PROCESSOR_H
3 3
4#include <asm/cpu-features.h> 4#include <asm/cpu-features.h>
5#include <asm/fpu.h>
6 5
7#ifndef __ASSEMBLY__ 6#ifndef __ASSEMBLY__
8/* 7/*
diff --git a/include/asm-sh/processor_32.h b/include/asm-sh/processor_32.h
index df2d5b039ef4..c09305d6a9d9 100644
--- a/include/asm-sh/processor_32.h
+++ b/include/asm-sh/processor_32.h
@@ -70,6 +70,7 @@ extern struct sh_cpuinfo cpu_data[];
70 */ 70 */
71#define SR_DSP 0x00001000 71#define SR_DSP 0x00001000
72#define SR_IMASK 0x000000f0 72#define SR_IMASK 0x000000f0
73#define SR_FD 0x00008000
73 74
74/* 75/*
75 * FPU structure and data 76 * FPU structure and data
diff --git a/include/asm-sh/processor_64.h b/include/asm-sh/processor_64.h
index eda4bef448e9..88a2edf8fa5d 100644
--- a/include/asm-sh/processor_64.h
+++ b/include/asm-sh/processor_64.h
@@ -112,6 +112,7 @@ extern struct sh_cpuinfo cpu_data[];
112#endif 112#endif
113 113
114#define SR_IMASK 0x000000f0 114#define SR_IMASK 0x000000f0
115#define SR_FD 0x00008000
115#define SR_SSTEP 0x08000000 116#define SR_SSTEP 0x08000000
116 117
117#ifndef __ASSEMBLY__ 118#ifndef __ASSEMBLY__