* [PATCH] powerpc/process: Fix flush_all_to_thread for SPE
@ 2018-10-25 12:07 DATACOM - Felipe.Rechia
2018-10-31 5:43 ` Michael Ellerman
0 siblings, 1 reply; 2+ messages in thread
From: DATACOM - Felipe.Rechia @ 2018-10-25 12:07 UTC (permalink / raw)
To: linuxppc-dev; +Cc: Zaneti
From: "Felipe Rechia" <felipe.rechia@datacom.com.br>
Date: Wed, 24 Oct 2018 10:57:22 -0300
Subject: [PATCH] powerpc/process: Fix flush_all_to_thread for SPE
Fix a bug introduced by the creation of flush_all_to_thread() for
processors that have SPE (Signal Processing Engine) and use it to
compute floating-point operations.
From userspace perspective, the problem was seen in attempts of
computing floating-point operations which should generate exceptions.
For example:
fork();
float x = 0.0 / 0.0;
isnan(x); // forked process returns False (should be True)
The operation above also should always cause the SPEFSCR FINV bit to
be set. However, the SPE floating-point exceptions were turned off
after a fork().
Kernel versions prior to the bug used flush_spe_to_thread(), which
first saves SPEFSCR register values in tsk->thread and then calls
giveup_spe(tsk).
After commit 579e633e764e, the save_all() function was called first
to giveup_spe(), and then the SPEFSCR register values were saved in
tsk->thread. This would save the SPEFSCR register values after
disabling SPE for that thread, causing the bug described above.
Fixes 579e633e764e ("powerpc: create flush_all_to_thread()")
Signed-off-by: felipe.rechia <felipe.rechia@datacom.com.br>
---
arch/powerpc/kernel/process.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index a0c74bb..16eb428 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -566,12 +566,11 @@ void flush_all_to_thread(struct task_struct *tsk)
if (tsk->thread.regs) {
preempt_disable();
BUG_ON(tsk != current);
- save_all(tsk);
-
#ifdef CONFIG_SPE
if (tsk->thread.regs->msr & MSR_SPE)
tsk->thread.spefscr = mfspr(SPRN_SPEFSCR);
#endif
+ save_all(tsk);
preempt_enable();
}
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: powerpc/process: Fix flush_all_to_thread for SPE
2018-10-25 12:07 [PATCH] powerpc/process: Fix flush_all_to_thread for SPE DATACOM - Felipe.Rechia
@ 2018-10-31 5:43 ` Michael Ellerman
0 siblings, 0 replies; 2+ messages in thread
From: Michael Ellerman @ 2018-10-31 5:43 UTC (permalink / raw)
To: DATACOM - Felipe.Rechia, linuxppc-dev; +Cc: Zaneti
On Thu, 2018-10-25 at 12:07:54 UTC, "DATACOM - Felipe.Rechia" wrote:
> From: "Felipe Rechia" <felipe.rechia@datacom.com.br>
> Date: Wed, 24 Oct 2018 10:57:22 -0300
> Subject: [PATCH] powerpc/process: Fix flush_all_to_thread for SPE
>
> Fix a bug introduced by the creation of flush_all_to_thread() for
> processors that have SPE (Signal Processing Engine) and use it to
> compute floating-point operations.
>
> >From userspace perspective, the problem was seen in attempts of
> computing floating-point operations which should generate exceptions.
> For example:
>
> fork();
> float x = 0.0 / 0.0;
> isnan(x); // forked process returns False (should be True)
>
> The operation above also should always cause the SPEFSCR FINV bit to
> be set. However, the SPE floating-point exceptions were turned off
> after a fork().
>
> Kernel versions prior to the bug used flush_spe_to_thread(), which
> first saves SPEFSCR register values in tsk->thread and then calls
> giveup_spe(tsk).
>
> After commit 579e633e764e, the save_all() function was called first
> to giveup_spe(), and then the SPEFSCR register values were saved in
> tsk->thread. This would save the SPEFSCR register values after
> disabling SPE for that thread, causing the bug described above.
>
> Fixes 579e633e764e ("powerpc: create flush_all_to_thread()")
> Signed-off-by: felipe.rechia <felipe.rechia@datacom.com.br>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/e901378578c62202594cba0f6c076f
cheers
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-10-31 5:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-25 12:07 [PATCH] powerpc/process: Fix flush_all_to_thread for SPE DATACOM - Felipe.Rechia
2018-10-31 5:43 ` Michael Ellerman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox