Linux MIPS Architecture development
 help / color / mirror / Atom feed
* [PATCH] MIPS: Don't BUG_ON(!is_fpu_owner()) in do_ade() when preemptible
@ 2014-07-11  3:06 Huacai Chen
  2014-07-11  3:14 ` [PATCH] Not preempt in CP1 exception handling chenj
  0 siblings, 1 reply; 11+ messages in thread
From: Huacai Chen @ 2014-07-11  3:06 UTC (permalink / raw)
  To: Ralf Baechle
  Cc: John Crispin, Steven J. Hill, linux-mips, Fuxin Zhang,
	Zhangjin Wu, Huacai Chen, Jie Chen, Rui Wang

In do_ade(), is_fpu_owner() isn't preempt-safe. For example, when an
unaligned ldc1 is executed, do_cpu() is called and then FPU is enabled
(TIF_USEDFPU is set for the current process). Then, do_ade() is called
because the access is unaligned. If the current process is preempted at
this time, TIF_USEDFPU will be cleard. When the process is scheduled
again, BUG_ON(!is_fpu_owner()) is triggered.

This small program can trigger this BUG in a preemptible kernel:
---
int main (int argc, char *argv[])
{
        double u64[2];

        while (1) {
                asm volatile (
                        ".set push \n\t"
                        ".set noreorder \n\t"
                        "ldc1 $f3, 4(%0) \n\t"
                        ".set pop \n\t"
                        ::"r"(u64):
                );
        }

        return 0;
}
---
Signed-off-by: Huacai Chen <chenhc@lemote.com>
Signed-off-by: Jie Chen <chenj@lemote.com>
Signed-off-by: Rui Wang <wangr@lemote.com>
---
 arch/mips/kernel/unaligned.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/mips/kernel/unaligned.c b/arch/mips/kernel/unaligned.c
index 2b35172..a6ff3c2 100644
--- a/arch/mips/kernel/unaligned.c
+++ b/arch/mips/kernel/unaligned.c
@@ -690,7 +690,8 @@ static void emulate_load_store_insn(struct pt_regs *regs,
 	case sdc1_op:
 		die_if_kernel("Unaligned FP access in kernel code", regs);
 		BUG_ON(!used_math());
-		BUG_ON(!is_fpu_owner());
+		if (!preemptible())
+			BUG_ON(!is_fpu_owner());
 
 		lose_fpu(1);	/* Save FPU state for the emulator. */
 		res = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 1,
-- 
1.9.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-08-19 15:57 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-11  3:06 [PATCH] MIPS: Don't BUG_ON(!is_fpu_owner()) in do_ade() when preemptible Huacai Chen
2014-07-11  3:14 ` [PATCH] Not preempt in CP1 exception handling chenj
2014-07-11  3:13   ` Chen Jie
2014-07-11 15:56   ` Paul Burton
2014-07-11 15:56     ` Paul Burton
2014-07-11 23:28     ` Chen Jie
2014-07-12  9:10       ` Huacai Chen
2014-07-12  9:30         ` Paul Burton
2014-07-14  2:22           ` Huacai Chen
2014-08-01 16:48             ` Ralf Baechle
2014-08-19 15:56               ` Chen Jie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox