linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rik van Riel <riel@redhat.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>,
	Andy Lutomirski <luto@amacapital.net>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Fenghua Yu <fenghua.yu@intel.com>,
	the arch/x86 maintainers <x86@kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH RFC] x86,fpu: merge save_init_fpu & unlazy_fpu
Date: Thu, 29 Jan 2015 16:00:17 -0500	[thread overview]
Message-ID: <20150129160017.6758dd40@cuia.bos.redhat.com> (raw)
In-Reply-To: <20150129204534.GA30530@redhat.com>

The functions save_init_fpu and unlazy_fpu do essentially the
same thing: save the fpu context to memory, and call __thread_fpu_end,
which most of the callers do not need or want.

Get rid of the function unlazy_fpu and make sure save_init_fpu does
what unlazy_fpu does today, including preemption safe state saving
in potentially unusual conditions.

Callers of init_fpu do want __thread_fpu_end, so move the call to
__thread_fpu_end into init_fpu.

I am not sure whether math_error requires __thread_fpu_end. One would
think that it would require that in order to sanitize the math state,
before do_device_not_available and math_state_restore restore it,
but those do not currently seem to do that. I am not sure how a task
that catches SIGFPE is supposed to recover and continue...

Signed-off-by: Rik van Riel <riel@redhat.com>
---
 arch/x86/include/asm/fpu-internal.h | 18 ++++++++----------
 arch/x86/include/asm/i387.h         |  2 --
 arch/x86/kernel/i387.c              | 18 ++++--------------
 arch/x86/kernel/traps.c             |  1 +
 4 files changed, 13 insertions(+), 26 deletions(-)

diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
index 0dbc08282291..c7e440ddd269 100644
--- a/arch/x86/include/asm/fpu-internal.h
+++ b/arch/x86/include/asm/fpu-internal.h
@@ -524,16 +524,14 @@ static inline void __save_fpu(struct task_struct *tsk)
  */
 static inline void save_init_fpu(struct task_struct *tsk)
 {
-	WARN_ON_ONCE(!__thread_has_fpu(tsk));
-
-	if (use_eager_fpu()) {
-		__save_fpu(tsk);
-		return;
-	}
-
 	preempt_disable();
-	__save_init_fpu(tsk);
-	__thread_fpu_end(tsk);
+	if (__thread_has_fpu(tsk)) {
+		if (use_eager_fpu())
+			__save_fpu(tsk);
+		else
+			__save_init_fpu(tsk);
+	} else if (!use_eager_fpu())
+		tsk->thread.fpu_counter = 0;
 	preempt_enable();
 }
 
@@ -600,7 +598,7 @@ static inline void fpu_copy(struct task_struct *dst, struct task_struct *src)
 		struct fpu *dfpu = &dst->thread.fpu;
 		struct fpu *sfpu = &src->thread.fpu;
 
-		unlazy_fpu(src);
+		save_init_fpu(src);
 		memcpy(dfpu->state, sfpu->state, xstate_size);
 	}
 }
diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
index 6eb6fcb83f63..07836671acfb 100644
--- a/arch/x86/include/asm/i387.h
+++ b/arch/x86/include/asm/i387.h
@@ -101,8 +101,6 @@ static inline int user_has_fpu(void)
 	return current->thread.fpu.has_fpu;
 }
 
-extern void unlazy_fpu(struct task_struct *tsk);
-
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_X86_I387_H */
diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
index 47348653503a..3afc4e73b07f 100644
--- a/arch/x86/kernel/i387.c
+++ b/arch/x86/kernel/i387.c
@@ -116,18 +116,6 @@ void __kernel_fpu_end(void)
 }
 EXPORT_SYMBOL(__kernel_fpu_end);
 
-void unlazy_fpu(struct task_struct *tsk)
-{
-	preempt_disable();
-	if (__thread_has_fpu(tsk)) {
-		__save_init_fpu(tsk);
-		__thread_fpu_end(tsk);
-	} else
-		tsk->thread.fpu_counter = 0;
-	preempt_enable();
-}
-EXPORT_SYMBOL(unlazy_fpu);
-
 unsigned int mxcsr_feature_mask __read_mostly = 0xffffffffu;
 unsigned int xstate_size;
 EXPORT_SYMBOL_GPL(xstate_size);
@@ -245,8 +233,10 @@ int init_fpu(struct task_struct *tsk)
 	int ret;
 
 	if (tsk_used_math(tsk)) {
-		if (cpu_has_fpu && tsk == current)
-			unlazy_fpu(tsk);
+		if (cpu_has_fpu && tsk == current) {
+			save_init_fpu(tsk);
+			__thread_fpu_end(tsk);
+		}
 		tsk->thread.fpu.last_cpu = ~0;
 		return 0;
 	}
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index fb4cb6adf225..201522fd2c96 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -664,6 +664,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
 	 * Save the info for the exception handler and clear the error.
 	 */
 	save_init_fpu(task);
+	__thread_fpu_end(task);
 	task->thread.trap_nr = trapnr;
 	task->thread.error_code = error_code;
 	info.si_signo = SIGFPE;


  parent reply	other threads:[~2015-01-29 21:00 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-23 19:34 question about save_xstate_sig() - WHY DOES THIS WORK? Rik van Riel
2015-01-23 20:51 ` [PATCH, RFC] x86,fpu: make signal handling xstate save & restore preemption safe Rik van Riel
2015-01-23 21:07 ` question about save_xstate_sig() - WHY DOES THIS WORK? H. Peter Anvin
2015-01-24 13:39   ` Rik van Riel
2015-01-24 20:20 ` Oleg Nesterov
2015-01-26 23:27   ` Rik van Riel
2015-01-27 19:40     ` Oleg Nesterov
2015-01-27 20:27       ` Rik van Riel
2015-01-27 20:50         ` Rik van Riel
2015-01-29 21:01           ` Oleg Nesterov
2015-01-29 20:45         ` Oleg Nesterov
2015-01-29 20:52           ` Rik van Riel
2015-01-29 21:00           ` Rik van Riel [this message]
2015-01-29 21:21             ` [PATCH RFC] x86,fpu: merge save_init_fpu & unlazy_fpu Oleg Nesterov
2015-01-29 21:07 ` [PATCH 0/3]: x86, fpu: unlazy_fpu fixes/cleanups Oleg Nesterov
2015-01-29 21:07   ` [PATCH 1/3] x86, fpu: unlazy_fpu: don't reset thread.fpu_counter Oleg Nesterov
2015-01-29 21:26     ` Rik van Riel
2015-01-29 21:08   ` [PATCH 2/3] x86, fpu: unlazy_fpu: don't do __thread_fpu_end() if use_eager_fpu() Oleg Nesterov
2015-01-29 21:36     ` Rik van Riel
2015-01-29 21:49       ` Oleg Nesterov
2015-01-29 21:53         ` Rik van Riel
2015-01-29 21:54     ` Rik van Riel
2015-01-29 21:08   ` [PATCH 3/3] x86, fpu: kill save_init_fpu(), change math_error() to use unlazy_fpu() Oleg Nesterov
2015-01-29 21:54     ` Rik van Riel
2015-01-29 21:17   ` [PATCH 0/3]: x86, fpu: unlazy_fpu fixes/cleanups Dave Hansen
2015-01-29 21:33     ` Oleg Nesterov
2015-01-29 21:43       ` Dave Hansen
2015-01-29 21:56         ` Oleg Nesterov
2015-01-29 21:58           ` Rik van Riel
2015-01-29 23:26           ` Dave Hansen
2015-01-30  1:33             ` Rik van Riel
2015-02-02 18:11               ` Dave Hansen
2015-01-30 12:45             ` Oleg Nesterov
2015-01-30 13:30               ` Oleg Nesterov
2015-01-30 13:43                 ` Oleg Nesterov
2015-01-30 17:49   ` [PATCH 0/3] cleanups to the disable lazy fpu restore code riel
2015-01-30 17:49     ` [PATCH 1/3] x86,fpu: move lazy restore functions up a few lines riel
2015-01-30 17:49     ` [PATCH 2/3] x86,fpu: introduce task_disable_lazy_fpu_restore helper riel
2015-01-30 17:49     ` [PATCH 3/3] x86,fpu: use disable_task_lazy_fpu_restore helper riel
2015-01-30 21:46       ` Dave Hansen
2015-01-30 21:48         ` Rik van Riel
2015-02-02 17:56         ` Rik van Riel
2015-02-02 18:00   ` [PATCH 0/6] cleanups to lazy FPU restore code riel
2015-02-02 18:00     ` [PATCH 1/6] x86,fpu: move lazy restore functions up a few lines riel
2015-02-02 18:00     ` [PATCH 2/6] x86,fpu: introduce task_disable_lazy_fpu_restore helper riel
2015-02-02 18:00     ` [PATCH 3/6] x86,fpu: use an explicit if/else in switch_fpu_prepare riel
2015-02-02 18:00     ` [PATCH 4/6] x86,fpu: use disable_task_lazy_fpu_restore helper riel
2015-02-02 19:21       ` Oleg Nesterov
2015-02-02 19:43         ` Rik van Riel
2015-02-03 19:08           ` Oleg Nesterov
2015-02-03 22:01             ` Rik van Riel
2015-02-06 16:42         ` Rik van Riel
2015-02-02 18:00     ` [PATCH 5/6] x86,fpu: also check fpu_lazy_restore when use_eager_fpu riel
2015-02-02 18:55       ` Oleg Nesterov
2015-02-02 19:19         ` Rik van Riel
2015-02-02 18:00     ` [PATCH 6/6] x86,fpu: remove redundant increments of fpu_counter riel
2015-02-02 18:34       ` Oleg Nesterov
2015-02-02 18:40         ` Rik van Riel
2015-02-18 23:40           ` Ingo Molnar
2015-02-18 23:54             ` Borislav Petkov
2015-02-19 20:09             ` Oleg Nesterov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150129160017.6758dd40@cuia.bos.redhat.com \
    --to=riel@redhat.com \
    --cc=fenghua.yu@intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mingo@redhat.com \
    --cc=oleg@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).