Commit 05062d96 authored by Peter Chubb's avatar Peter Chubb Committed by Linus Torvalds

[PATCH] ia64: fix floating-point preemption problem

There've been reports of problems with CONFIG_PREEMPT=y and the high
floating point partition.  This is caused by the possibility of preemption
and rescheduling on a different processor while saving or restioirng the
high partition.

The only places where the FPU state is touched are in ptrace, in
switch_to(), and where handling a floating-point exception.  In switch_to()
preemption is off.  So it's only in trap.c and ptrace.c that we need to
prevent preemption.

Here is a patch that adds commentary to make the conditions clear, and adds
appropriate preempt_{en,dis}able() calls to make it so.  In trap.c I use
preempt_enable_no_resched(), as we're about to return to user space where
the preemption flag will be checked anyway.
Signed-off-by: default avatarPeter Chubb <peterc@gelato.unsw.edu.au>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent f829fd23
...@@ -635,11 +635,17 @@ ia64_flush_fph (struct task_struct *task) ...@@ -635,11 +635,17 @@ ia64_flush_fph (struct task_struct *task)
{ {
struct ia64_psr *psr = ia64_psr(ia64_task_regs(task)); struct ia64_psr *psr = ia64_psr(ia64_task_regs(task));
/*
* Prevent migrating this task while
* we're fiddling with the FPU state
*/
preempt_disable();
if (ia64_is_local_fpu_owner(task) && psr->mfh) { if (ia64_is_local_fpu_owner(task) && psr->mfh) {
psr->mfh = 0; psr->mfh = 0;
task->thread.flags |= IA64_THREAD_FPH_VALID; task->thread.flags |= IA64_THREAD_FPH_VALID;
ia64_save_fpu(&task->thread.fph[0]); ia64_save_fpu(&task->thread.fph[0]);
} }
preempt_enable();
} }
/* /*
......
...@@ -220,13 +220,21 @@ disabled_fph_fault (struct pt_regs *regs) ...@@ -220,13 +220,21 @@ disabled_fph_fault (struct pt_regs *regs)
/* first, grant user-level access to fph partition: */ /* first, grant user-level access to fph partition: */
psr->dfh = 0; psr->dfh = 0;
/*
* Make sure that no other task gets in on this processor
* while we're claiming the FPU
*/
preempt_disable();
#ifndef CONFIG_SMP #ifndef CONFIG_SMP
{ {
struct task_struct *fpu_owner struct task_struct *fpu_owner
= (struct task_struct *)ia64_get_kr(IA64_KR_FPU_OWNER); = (struct task_struct *)ia64_get_kr(IA64_KR_FPU_OWNER);
if (ia64_is_local_fpu_owner(current)) if (ia64_is_local_fpu_owner(current)) {
preempt_enable_no_resched();
return; return;
}
if (fpu_owner) if (fpu_owner)
ia64_flush_fph(fpu_owner); ia64_flush_fph(fpu_owner);
...@@ -244,6 +252,7 @@ disabled_fph_fault (struct pt_regs *regs) ...@@ -244,6 +252,7 @@ disabled_fph_fault (struct pt_regs *regs)
*/ */
psr->mfh = 1; psr->mfh = 1;
} }
preempt_enable_no_resched();
} }
static inline int static inline int
......
...@@ -403,7 +403,10 @@ extern void ia64_setreg_unknown_kr (void); ...@@ -403,7 +403,10 @@ extern void ia64_setreg_unknown_kr (void);
* task_struct at this point. * task_struct at this point.
*/ */
/* Return TRUE if task T owns the fph partition of the CPU we're running on. */ /*
* Return TRUE if task T owns the fph partition of the CPU we're running on.
* Must be called from code that has preemption disabled.
*/
#define ia64_is_local_fpu_owner(t) \ #define ia64_is_local_fpu_owner(t) \
({ \ ({ \
struct task_struct *__ia64_islfo_task = (t); \ struct task_struct *__ia64_islfo_task = (t); \
...@@ -411,7 +414,10 @@ extern void ia64_setreg_unknown_kr (void); ...@@ -411,7 +414,10 @@ extern void ia64_setreg_unknown_kr (void);
&& __ia64_islfo_task == (struct task_struct *) ia64_get_kr(IA64_KR_FPU_OWNER)); \ && __ia64_islfo_task == (struct task_struct *) ia64_get_kr(IA64_KR_FPU_OWNER)); \
}) })
/* Mark task T as owning the fph partition of the CPU we're running on. */ /*
* Mark task T as owning the fph partition of the CPU we're running on.
* Must be called from code that has preemption disabled.
*/
#define ia64_set_local_fpu_owner(t) do { \ #define ia64_set_local_fpu_owner(t) do { \
struct task_struct *__ia64_slfo_task = (t); \ struct task_struct *__ia64_slfo_task = (t); \
__ia64_slfo_task->thread.last_fph_cpu = smp_processor_id(); \ __ia64_slfo_task->thread.last_fph_cpu = smp_processor_id(); \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment