linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans Rosenfeld <hans.rosenfeld@amd.com>
To: <hpa@zytor.com>
Cc: <brgerst@gmail.com>, <tglx@linutronix.de>, <mingo@elte.hu>,
	<suresh.b.siddha@intel.com>, <eranian@google.com>,
	<robert.richter@amd.com>, <Andreas.Herrmann3@amd.com>,
	<x86@kernel.org>, <linux-kernel@vger.kernel.org>,
	Hans Rosenfeld <hans.rosenfeld@amd.com>
Subject: [RFC v3 6/8] x86, xsave: add support for non-lazy xstates
Date: Tue, 5 Apr 2011 17:50:54 +0200	[thread overview]
Message-ID: <1302018656-586370-7-git-send-email-hans.rosenfeld@amd.com> (raw)
In-Reply-To: <4D91FA76.1010908@zytor.com>

Non-lazy xstates are, as the name suggests, extended states that cannot
be saved or restored lazily. The state for AMDs LWP feature is an
example of this.

This patch adds support for this kind of xstates. If any such states are
present and supported on the running system, they will always be enabled
in xstate_mask so that they are always restored in switch_to. Since lazy
allocation of the xstate area won't work when non-lazy xstates are used,
all user tasks will always have a xstate area preallocated.

Signed-off-by: Hans Rosenfeld <hans.rosenfeld@amd.com>
---
 arch/x86/include/asm/i387.h  |   17 +++++++++++++++++
 arch/x86/include/asm/xsave.h |    5 +++--
 arch/x86/kernel/process_32.c |    2 +-
 arch/x86/kernel/process_64.c |    2 +-
 arch/x86/kernel/xsave.c      |    6 +++++-
 5 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
index b8f9617..efe1476 100644
--- a/arch/x86/include/asm/i387.h
+++ b/arch/x86/include/asm/i387.h
@@ -329,6 +329,23 @@ 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 (pcntxt_mask & XCNTXT_NONLAZY) {
+		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();
+	} else {
+		fpu_free(fpu);
+	}
+}
 
 #endif /* __ASSEMBLY__ */
 
diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
index b8861d4..4ccee3c 100644
--- a/arch/x86/include/asm/xsave.h
+++ b/arch/x86/include/asm/xsave.h
@@ -23,9 +23,10 @@
 /*
  * These are the features that the OS can handle currently.
  */
-#define XCNTXT_MASK	(XSTATE_FP | XSTATE_SSE | XSTATE_YMM)
+#define XCNTXT_LAZY	(XSTATE_FP | XSTATE_SSE | XSTATE_YMM)
+#define XCNTXT_NONLAZY	0
 
-#define XCNTXT_LAZY	XCNTXT_MASK
+#define XCNTXT_MASK	(XCNTXT_LAZY | XCNTXT_NONLAZY)
 
 #ifdef CONFIG_X86_64
 #define REX_PREFIX	"0x48, "
diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
index 8df07c3..a878736 100644
--- a/arch/x86/kernel/process_32.c
+++ b/arch/x86/kernel/process_32.c
@@ -257,7 +257,7 @@ start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp)
 	/*
 	 * Free the old FP and other extended state
 	 */
-	free_thread_xstate(current);
+	fpu_clear(&current->thread.fpu);
 }
 EXPORT_SYMBOL_GPL(start_thread);
 
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index cbf1a67..8ff35fc 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -344,7 +344,7 @@ start_thread_common(struct pt_regs *regs, unsigned long new_ip,
 	/*
 	 * Free the old FP and other extended state
 	 */
-	free_thread_xstate(current);
+	fpu_clear(&current->thread.fpu);
 }
 
 void
diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
index d42810f..56ab3d3 100644
--- a/arch/x86/kernel/xsave.c
+++ b/arch/x86/kernel/xsave.c
@@ -16,6 +16,7 @@
  * Supported feature mask by the CPU and the kernel.
  */
 u64 pcntxt_mask;
+EXPORT_SYMBOL(pcntxt_mask);
 
 /*
  * Represents init state for the supported extended state.
@@ -260,7 +261,7 @@ int restore_xstates_sigframe(void __user *buf, unsigned int size)
 	struct task_struct *tsk = current;
 	struct _fpstate_ia32 __user *fp = buf;
 	struct xsave_struct *xsave;
-	u64 xstate_mask = 0;
+	u64 xstate_mask = pcntxt_mask & XCNTXT_NONLAZY;
 	int err;
 
 	if (!buf) {
@@ -477,6 +478,9 @@ static void __init xstate_enable_boot_cpu(void)
 	printk(KERN_INFO "xsave/xrstor: enabled xstate_bv 0x%llx, "
 	       "cntxt size 0x%x\n",
 	       pcntxt_mask, xstate_size);
+
+	if (pcntxt_mask & XCNTXT_NONLAZY)
+		task_thread_info(&init_task)->xstate_mask |= XCNTXT_NONLAZY;
 }
 
 /*
-- 
1.5.6.5



  parent reply	other threads:[~2011-04-05 15:52 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-09 19:14 [RFC 0/8] rework of extended state handling, LWP support Hans Rosenfeld
2011-03-09 19:14 ` [RFC 1/8] x86, xsave: cleanup fpu/xsave support Hans Rosenfeld
2011-03-09 19:14 ` [RFC 2/8] x86, xsave: rework " Hans Rosenfeld
2011-03-09 19:14 ` [RFC 3/8] x86, xsave: cleanup fpu/xsave signal frame setup Hans Rosenfeld
2011-03-09 19:14 ` [RFC 4/8] x86, xsave: remove unused code Hans Rosenfeld
2011-03-09 19:14 ` [RFC 5/8] x86, xsave: more cleanups Hans Rosenfeld
2011-03-09 19:15 ` [RFC 6/8] x86, xsave: add support for non-lazy xstates Hans Rosenfeld
2011-03-09 19:15 ` [RFC 7/8] x86, xsave: add kernel support for AMDs Lightweight Profiling (LWP) Hans Rosenfeld
2011-03-09 19:15 ` [RFC 8/8] x86, xsave: remove lazy allocation of xstate area Hans Rosenfeld
2011-03-23 15:27   ` [RFC v2 0/8] x86, xsave: rework of extended state handling, LWP support Hans Rosenfeld
2011-03-23 15:27   ` [RFC v2 1/8] x86, xsave: cleanup fpu/xsave support Hans Rosenfeld
2011-03-23 15:27   ` [RFC v2 2/8] x86, xsave: rework " Hans Rosenfeld
2011-03-23 15:27   ` [RFC v2 3/8] x86, xsave: cleanup fpu/xsave signal frame setup Hans Rosenfeld
2011-03-23 15:27   ` [RFC v2 4/8] x86, xsave: remove unused code Hans Rosenfeld
2011-03-23 15:27   ` [RFC v2 5/8] x86, xsave: more cleanups Hans Rosenfeld
2011-03-23 15:27   ` [RFC v2 6/8] x86, xsave: add support for non-lazy xstates Hans Rosenfeld
2011-03-23 15:27   ` [RFC v2 7/8] x86, xsave: add kernel support for AMDs Lightweight Profiling (LWP) Hans Rosenfeld
2011-03-23 15:27   ` [RFC v2 8/8] x86, xsave: remove lazy allocation of xstate area Hans Rosenfeld
2011-03-24 11:39     ` Brian Gerst
2011-03-29 14:17       ` Hans Rosenfeld
2011-03-29 15:27         ` H. Peter Anvin
2011-03-30 13:11           ` Hans Rosenfeld
2011-04-05 15:50           ` [RFC v3 0/8] x86, xsave: rework of extended state handling, LWP support Hans Rosenfeld
2011-04-07  7:23             ` Ingo Molnar
2011-04-07 15:30               ` Hans Rosenfeld
2011-04-07 16:08                 ` [RFC v4 6/8] x86, xsave: add support for non-lazy xstates Hans Rosenfeld
2011-04-07 16:08                 ` [RFC v4 8/8] x86, xsave: remove lazy allocation of xstate area Hans Rosenfeld
2011-04-13 10:58                 ` [PATCH] x86, xsave: fix non-lazy allocation of the xsave area Hans Rosenfeld
2011-04-13 23:21                   ` H. Peter Anvin
2011-04-15 16:47                     ` [PATCH 1/1] " Hans Rosenfeld
2011-05-16 19:10               ` [RFC v3 0/8] x86, xsave: rework of extended state handling, LWP support Hans Rosenfeld
2011-05-17 11:30                 ` Ingo Molnar
2011-05-17 15:22                   ` Hans Rosenfeld
2011-05-18 11:22                     ` Ingo Molnar
2011-05-18 13:51                     ` Ingo Molnar
2011-05-18  8:16                   ` Joerg Roedel
2011-05-18 10:59                     ` Ingo Molnar
2011-05-18 18:02                   ` Andreas Herrmann
2011-04-05 15:50           ` [RFC v3 1/8] x86, xsave: cleanup fpu/xsave support Hans Rosenfeld
2011-04-05 15:50           ` [RFC v3 2/8] x86, xsave: rework " Hans Rosenfeld
2011-04-05 15:50           ` [RFC v3 3/8] x86, xsave: cleanup fpu/xsave signal frame setup Hans Rosenfeld
2011-04-05 15:50           ` [RFC v3 4/8] x86, xsave: remove unused code Hans Rosenfeld
2011-04-05 15:50           ` [RFC v3 5/8] x86, xsave: more cleanups Hans Rosenfeld
2011-04-05 15:50           ` Hans Rosenfeld [this message]
2011-04-05 15:50           ` [RFC v3 7/8] x86, xsave: add kernel support for AMDs Lightweight Profiling (LWP) Hans Rosenfeld
2011-04-06 22:06             ` [tip:x86/xsave] " tip-bot for Hans Rosenfeld
2011-04-05 15:50           ` [RFC v3 8/8] x86, xsave: remove lazy allocation of xstate area Hans Rosenfeld
2011-04-06 22:06             ` [tip:x86/xsave] " tip-bot for Hans Rosenfeld

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=1302018656-586370-7-git-send-email-hans.rosenfeld@amd.com \
    --to=hans.rosenfeld@amd.com \
    --cc=Andreas.Herrmann3@amd.com \
    --cc=brgerst@gmail.com \
    --cc=eranian@google.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=robert.richter@amd.com \
    --cc=suresh.b.siddha@intel.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).