2006-11-16 02:46:33

by Chris Wright

[permalink] [raw]
Subject: [patch 16/30] x86_64: Fix FPU corruption

-stable review patch. If anyone has any objections, please let us know.
------------------

From: Andi Kleen <[email protected]>

This reverts an earlier patch that was found to cause FPU
state corruption. I think the corruption happens because
unlazy_fpu() can cause FPU exceptions and when it happens
after the current switch some processing would affect
the state in the wrong process.

Thanks to Douglas Crosher and Tom Hughes for testing.

Cc: [email protected]
Signed-off-by: Andi Kleen <[email protected]>
Signed-off-by: Chris Wright <[email protected]>
---
arch/x86_64/kernel/process.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

--- linux-2.6.18.2.orig/arch/x86_64/kernel/process.c
+++ linux-2.6.18.2/arch/x86_64/kernel/process.c
@@ -571,6 +571,9 @@ __switch_to(struct task_struct *prev_p,
prev->gsindex = gsindex;
}

+ /* Must be after DS reload */
+ unlazy_fpu(prev_p);
+
/*
* Switch the PDA and FPU contexts.
*/
@@ -578,10 +581,6 @@ __switch_to(struct task_struct *prev_p,
write_pda(oldrsp, next->userrsp);
write_pda(pcurrent, next_p);

- /* This must be here to ensure both math_state_restore() and
- kernel_fpu_begin() work consistently.
- And the AMD workaround requires it to be after DS reload. */
- unlazy_fpu(prev_p);
write_pda(kernelstack,
task_stack_page(next_p) + THREAD_SIZE - PDA_STACKOFFSET);


--