From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756294AbbCCL2i (ORCPT ); Tue, 3 Mar 2015 06:28:38 -0500 Received: from terminus.zytor.com ([198.137.202.10]:51701 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756189AbbCCL2g (ORCPT ); Tue, 3 Mar 2015 06:28:36 -0500 Date: Tue, 3 Mar 2015 03:28:16 -0800 From: tip-bot for Oleg Nesterov Message-ID: Cc: oleg@redhat.com, tglx@linutronix.de, torvalds@linux-foundation.org, riel@redhat.com, luto@amacapital.net, linux-kernel@vger.kernel.org, bp@suse.de, sbsiddha@gmail.com, mingo@kernel.org, hpa@zytor.com Reply-To: mingo@kernel.org, hpa@zytor.com, oleg@redhat.com, luto@amacapital.net, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, tglx@linutronix.de, riel@redhat.com, bp@suse.de, sbsiddha@gmail.com In-Reply-To: <20150119185212.GD16427@redhat.com> References: <20150119185212.GD16427@redhat.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/fpu] x86/fpu: Don' t abuse FPU in kernel threads if use_eager_fpu() Git-Commit-ID: 110d7f7513bbb916b8654da9e2973ac5bed929a9 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 110d7f7513bbb916b8654da9e2973ac5bed929a9 Gitweb: http://git.kernel.org/tip/110d7f7513bbb916b8654da9e2973ac5bed929a9 Author: Oleg Nesterov AuthorDate: Mon, 19 Jan 2015 19:52:12 +0100 Committer: Borislav Petkov CommitDate: Mon, 23 Feb 2015 15:50:45 +0100 x86/fpu: Don't abuse FPU in kernel threads if use_eager_fpu() AFAICS, there is no reason why kernel threads should have FPU context even if use_eager_fpu() == T. Now that interrupted_kernel_fpu_idle() does not check __thread_has_fpu() in the use_eager_fpu() case, we can remove the init_fpu() code from eager_fpu_init() and change flush_thread() called by do_execve() to initialize FPU. Note: of course, the change in flush_thread() is horrible and must be cleanuped. We need the new helper, and flush_thread() should return the error if init_fpu() fails. Signed-off-by: Oleg Nesterov Reviewed-by: Rik van Riel Cc: Linus Torvalds Cc: Suresh Siddha Cc: Andy Lutomirski Link: http://lkml.kernel.org/r/20150119185212.GD16427@redhat.com Signed-off-by: Borislav Petkov --- arch/x86/kernel/process.c | 7 +++++++ arch/x86/kernel/xsave.c | 13 +------------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index ce8b103..8348037 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -130,6 +130,7 @@ void flush_thread(void) flush_ptrace_hw_breakpoint(tsk); memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array)); + drop_init_fpu(tsk); /* * Free the FPU state for non xsave platforms. They get reallocated @@ -137,6 +138,12 @@ void flush_thread(void) */ if (!use_eager_fpu()) free_thread_xstate(tsk); + else if (!used_math()) { + /* kthread execs. TODO: cleanup this horror. */ + if (WARN_ON(init_fpu(current))) + force_sig(SIGKILL, current); + math_state_restore(); + } } static void hard_disable_TSC(void) diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c index 0de1fae..de9dcf8 100644 --- a/arch/x86/kernel/xsave.c +++ b/arch/x86/kernel/xsave.c @@ -688,7 +688,7 @@ void eager_fpu_init(void) { static __refdata void (*boot_func)(void) = eager_fpu_init_bp; - clear_used_math(); + WARN_ON(used_math()); current_thread_info()->status = 0; if (eagerfpu == ENABLE) @@ -703,17 +703,6 @@ void eager_fpu_init(void) boot_func(); boot_func = NULL; } - - /* - * This is same as math_state_restore(). But use_xsave() is - * not yet patched to use math_state_restore(). - */ - init_fpu(current); - __thread_fpu_begin(current); - if (cpu_has_xsave) - xrstor_state(init_xstate_buf, -1); - else - fxrstor_checking(&init_xstate_buf->i387); } /*