From mboxrd@z Thu Jan 1 00:00:00 1970 Received: with ECARTIS (v1.0.0; list linux-mips); Fri, 11 Jul 2014 04:58:49 +0200 (CEST) Received: from mail-pd0-f175.google.com ([209.85.192.175]:35903 "EHLO mail-pd0-f175.google.com" rhost-flags-OK-OK-OK-OK) by eddie.linux-mips.org with ESMTP id S6856087AbaGKC6pi6T4g (ORCPT ); Fri, 11 Jul 2014 04:58:45 +0200 Received: by mail-pd0-f175.google.com with SMTP id v10so585634pde.20 for ; Thu, 10 Jul 2014 19:58:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=uCQ19UGR0KPUAKV8UxEBfFdV7rr69uU2h6eLxKT3HUQ=; b=P5oTjgHfWmHZqftjVtYt76RO7H2uIfZogiR9AkvO6SE0921hAovgQKo7rW+ye4Qgog 6CtDAbN8+ddmwI/RPCICtu9dXxBmzBytI2Y2VykW34O4DdsvCpdESxpFGFY7tvpnW9UJ Y+jIx5sI5fwvaP7pZ3rDI2beuwTm+1kqG72TUrjBeQIekx/wewpC3dN/x7RyGlf5TTHm swIkEWTe2x0kvsPgCYCL0r0YJQwzdQkuIa97yJBYS/SJLUGYGu5IFbnHquIIbOi52P30 doHnkHUUyJ6XYD6zB7BKXganVJFuw1K7zjzFZtOZNXltXM2RM4ya6m3lLr0MKuiVg+jb H3gA== X-Received: by 10.70.92.49 with SMTP id cj17mr21005165pdb.53.1405047518673; Thu, 10 Jul 2014 19:58:38 -0700 (PDT) Received: from software.domain.org ([222.92.8.142]) by mx.google.com with ESMTPSA id xz7sm3780247pac.3.2014.07.10.19.58.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Jul 2014 19:58:38 -0700 (PDT) From: Huacai Chen To: Ralf Baechle Cc: John Crispin , "Steven J. Hill" , linux-mips@linux-mips.org, Fuxin Zhang , Zhangjin Wu , Huacai Chen , Jie Chen , Rui Wang Subject: [PATCH] MIPS: Don't BUG_ON(!is_fpu_owner()) in do_ade() when preemptible Date: Fri, 11 Jul 2014 11:06:30 +0800 Message-Id: <1405047990-12519-1-git-send-email-chenhc@lemote.com> X-Mailer: git-send-email 1.9.0 Return-Path: X-Envelope-To: <"|/home/ecartis/ecartis -s linux-mips"> (uid 0) X-Orcpt: rfc822;linux-mips@linux-mips.org Original-Recipient: rfc822;linux-mips@linux-mips.org X-archive-position: 41132 X-ecartis-version: Ecartis v1.0.0 Sender: linux-mips-bounce@linux-mips.org Errors-to: linux-mips-bounce@linux-mips.org X-original-sender: chenhc@lemote.com Precedence: bulk List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: linux-mips X-List-ID: linux-mips List-subscribe: List-owner: List-post: List-archive: X-list: linux-mips 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 Signed-off-by: Jie Chen Signed-off-by: Rui Wang --- 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, ¤t->thread.fpu, 1, -- 1.9.0