mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: tip-bot for Hans Rosenfeld <hans.rosenfeld@amd.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hans.rosenfeld@amd.com,
	hpa@zytor.com, mingo@redhat.com, tglx@linutronix.de
Subject: [tip:x86/xsave] x86, xsave: fix non-lazy allocation of the xsave area
Date: Thu, 28 Apr 2011 05:55:14 GMT	[thread overview]
Message-ID: <tip-300c6120b4653043e8a80b24e0483c0d223c5aac@git.kernel.org> (raw)
In-Reply-To: <1303914395-841373-1-git-send-email-hans.rosenfeld@amd.com>

Commit-ID:  300c6120b4653043e8a80b24e0483c0d223c5aac
Gitweb:     http://git.kernel.org/tip/300c6120b4653043e8a80b24e0483c0d223c5aac
Author:     Hans Rosenfeld <hans.rosenfeld@amd.com>
AuthorDate: Wed, 27 Apr 2011 16:26:34 +0200
Committer:  H. Peter Anvin <hpa@zytor.com>
CommitDate: Wed, 27 Apr 2011 18:03:45 -0700

x86, xsave: fix non-lazy allocation of the xsave area

A single static xsave area just for init is not enough, since there are
more user processes that are directly executed by kernel threads. Add a
call to a new arch-specific function to flush_old_exec(), which will in
turn call fpu_alloc() to allocate a xsave area if necessary.

Signed-off-by: Hans Rosenfeld <hans.rosenfeld@amd.com>
Link: http://lkml.kernel.org/r/1303914395-841373-1-git-send-email-hans.rosenfeld@amd.com
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
 arch/x86/include/asm/i387.h        |    6 ------
 arch/x86/include/asm/thread_info.h |    2 ++
 arch/x86/kernel/process.c          |    7 +++++++
 fs/exec.c                          |    8 ++++++++
 4 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
index f410d16..41f1d7e 100644
--- a/arch/x86/include/asm/i387.h
+++ b/arch/x86/include/asm/i387.h
@@ -327,15 +327,9 @@ static inline void fpu_copy(struct fpu *dst, struct fpu *src)
 }
 
 extern void fpu_finit(struct fpu *fpu);
-static union thread_xstate __init_xstate, *init_xstate = &__init_xstate;
 
 static inline void fpu_clear(struct fpu *fpu)
 {
-	if (!fpu_allocated(fpu)) {
-		BUG_ON(init_xstate == NULL);
-		fpu->state = init_xstate;
-		init_xstate = NULL;
-	}
 	memset(fpu->state, 0, xstate_size);
 	fpu_finit(fpu);
 	set_used_math();
diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
index 0e691c6..07c8cfe 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -265,6 +265,8 @@ static inline void set_restore_sigmask(void)
 extern void arch_task_cache_init(void);
 extern void free_thread_info(struct thread_info *ti);
 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
+extern int arch_prealloc_fpu(struct task_struct *tsk);
+#define arch_prealloc_fpu arch_prealloc_fpu
 #define arch_task_cache_init arch_task_cache_init
 #endif
 #endif /* _ASM_X86_THREAD_INFO_H */
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index d46cbe4..a70f620 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -26,6 +26,13 @@
 struct kmem_cache *task_xstate_cachep;
 EXPORT_SYMBOL_GPL(task_xstate_cachep);
 
+int arch_prealloc_fpu(struct task_struct *tsk)
+{
+	if (!fpu_allocated(&tsk->thread.fpu))
+		return fpu_alloc(&tsk->thread.fpu);
+	return 0;
+}
+
 int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
 {
 	int ret;
diff --git a/fs/exec.c b/fs/exec.c
index 5e62d26..932b9ad 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1022,10 +1022,18 @@ void set_task_comm(struct task_struct *tsk, char *buf)
 	perf_event_comm(tsk);
 }
 
+#if !defined(arch_prealloc_fpu)
+#define arch_prealloc_fpu(tsk) (0)
+#endif
+
 int flush_old_exec(struct linux_binprm * bprm)
 {
 	int retval;
 
+	retval = arch_prealloc_fpu(current);
+	if (retval)
+		goto out;
+
 	/*
 	 * Make sure we have a private signal table and that
 	 * we are unassociated from the previous thread group.

  reply	other threads:[~2011-04-28  5:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <2be7032a-e4b6-4ce7-af53-532d77dbfb48@email.android.com>
2011-04-27 14:26 ` [PATCH 1/2] " Hans Rosenfeld
2011-04-28  5:55   ` tip-bot for Hans Rosenfeld [this message]
2011-04-27 14:26 ` [PATCH 2/2] fork: avoid weak function arch_dup_task_struct Hans Rosenfeld
2011-05-01 19:25   ` Andrew Morton
2011-05-01 22:59     ` H. Peter Anvin
2011-05-02  0:11       ` Andrew Morton
2011-05-02 15:36         ` H. Peter Anvin

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=tip-300c6120b4653043e8a80b24e0483c0d223c5aac@git.kernel.org \
    --to=hans.rosenfeld@amd.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    /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

Powered by JetHome