Suresh Siddha 870568b390 x86, fpu: fix CONFIG_PREEMPT=y corruption of application's FPU stack
Jürgen Mell reported an FPU state corruption bug under CONFIG_PREEMPT,
and bisected it to commit v2.6.19-1363-gacc2076, "i386: add sleazy FPU
optimization".

Add tsk_used_math() checks to prevent calling math_state_restore()
which can sleep in the case of !tsk_used_math(). This prevents
making a blocking call in __switch_to().

Apparently "fpu_counter > 5" check is not enough, as in some signal handling
and fork/exec scenarios, fpu_counter > 5 and !tsk_used_math() is possible.

It's a side effect though. This is the failing scenario:

process 'A' in save_i387_ia32() just after clear_used_math()

Got an interrupt and pre-empted out.

At the next context switch to process 'A' again, kernel tries to restore
the math state proactively and sees a fpu_counter > 0 and !tsk_used_math()

This results in init_fpu() during the __switch_to()'s math_state_restore()

And resulting in fpu corruption which will be saved/restored
(save_i387_fxsave and restore_i387_fxsave) during the remaining
part of the signal handling after the context switch.

Bisected-by: Jürgen Mell <j.mell@t-online.de>
Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
Tested-by: Jürgen Mell <j.mell@t-online.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@kernel.org
2008-06-04 16:21:24 +02:00
..
2008-06-04 13:11:46 +02:00
2007-10-17 21:19:04 +02:00
2008-04-25 19:54:07 +02:00
2008-04-17 17:41:19 +02:00
2008-04-26 17:35:47 +02:00
2008-04-29 08:06:29 -07:00
2008-04-29 08:06:29 -07:00
2008-04-19 19:10:28 -07:00
2007-10-19 11:53:33 -07:00
2008-01-30 13:31:31 +01:00
2008-04-29 13:45:24 +02:00
2008-02-19 16:18:28 +01:00
2008-04-19 19:19:54 +02:00
2008-01-30 13:31:19 +01:00
2008-04-19 19:19:54 +02:00
2008-04-24 23:57:33 +02:00
2008-04-17 17:41:13 +02:00
2008-04-30 23:15:34 +02:00
2008-04-17 17:41:36 +02:00
2008-04-19 19:19:58 +02:00
2008-04-17 17:40:49 +02:00
2008-04-30 23:15:34 +02:00
2008-04-17 17:41:37 +02:00
2008-04-30 23:15:34 +02:00
2008-04-26 17:35:47 +02:00
2008-04-26 17:35:48 +02:00
2008-03-26 22:23:40 +01:00
2008-01-30 13:33:10 +01:00
2008-04-17 17:40:56 +02:00
2008-04-29 08:06:02 -07:00
2008-04-19 19:19:54 +02:00
2008-04-27 12:00:28 +03:00
2008-05-23 14:08:06 +02:00
2008-05-07 12:42:03 +02:00
2008-04-28 08:58:35 -07:00
2008-05-04 20:04:45 +02:00
2008-04-19 19:10:28 -07:00
2008-01-30 13:33:19 +01:00
2008-05-12 21:27:50 +02:00
2008-04-19 19:19:57 +02:00
2008-04-19 19:19:56 +02:00
2008-04-19 19:19:55 +02:00
2008-04-30 08:29:37 -07:00
2008-04-30 08:29:37 -07:00
2008-05-13 19:36:12 +02:00
2008-04-17 17:40:55 +02:00
2008-04-17 17:40:55 +02:00
2008-04-26 17:35:47 +02:00
2008-04-29 08:06:03 -07:00
2008-02-08 09:22:29 -08:00
2008-04-17 17:40:56 +02:00
2008-01-30 13:31:52 +01:00
2008-04-17 17:41:37 +02:00
2008-05-23 14:08:06 +02:00
2008-04-24 23:57:31 +02:00
2008-04-28 13:49:35 -07:00
2008-04-24 23:15:44 +02:00