From: Dave Hansen <dave@sr71.net>
To: oleg@redhat.com
Cc: Dave Hansen <dave@sr71.net>,
dave.hansen@linux.intel.com, riel@redhat.com, sbsiddha@gmail.com,
luto@amacapital.net, tglx@linutronix.de, mingo@redhat.com,
hpa@zytor.com, fenghua.yu@intel.com, x86@kernel.org,
linux-kernel@vger.kernel.org
Subject: [RFC][PATCH 1/2] x86, fpu: wrap get_xsave_addr() to make it safer
Date: Fri, 30 Jan 2015 09:43:09 -0800 [thread overview]
Message-ID: <20150130174309.D666B2A7@viggo.jf.intel.com> (raw)
The MPX code appears to be saving off the FPU in an unsafe
way. It does not disable preemption or ensure that the
FPU state has been allocated.
This patch introduces a new helper which will do both of
those things internally to a helper.
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Suresh Siddha <sbsiddha@gmail.com>
Cc:Andy Lutomirski <luto@amacapital.net>
Cc:Thomas Gleixner <tglx@linutronix.de>
Cc:Ingo Molnar <mingo@redhat.com>
Cc:"H. Peter Anvin" <hpa@zytor.com>
Cc:Fenghua Yu <fenghua.yu@intel.com>
Cc:the arch/x86 maintainers <x86@kernel.org>
Cc:linux-kernel <linux-kernel@vger.kernel.org>
---
b/arch/x86/include/asm/xsave.h | 1 +
b/arch/x86/kernel/xsave.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+)
diff -puN arch/x86/include/asm/xsave.h~tsk_get_xsave_addr arch/x86/include/asm/xsave.h
--- a/arch/x86/include/asm/xsave.h~tsk_get_xsave_addr 2015-01-30 09:42:15.457555582 -0800
+++ b/arch/x86/include/asm/xsave.h 2015-01-30 09:42:15.462555808 -0800
@@ -258,6 +258,7 @@ static inline int xrestore_user(struct x
}
void *get_xsave_addr(struct xsave_struct *xsave, int xstate);
+void *tsk_get_xsave_field(struct task_struct *tsk, int xstate_field);
void setup_xstate_comp(void);
#endif
diff -puN arch/x86/kernel/xsave.c~tsk_get_xsave_addr arch/x86/kernel/xsave.c
--- a/arch/x86/kernel/xsave.c~tsk_get_xsave_addr 2015-01-30 09:42:15.459555673 -0800
+++ b/arch/x86/kernel/xsave.c 2015-01-30 09:42:15.463555853 -0800
@@ -739,3 +739,35 @@ void *get_xsave_addr(struct xsave_struct
return (void *)xsave + xstate_comp_offsets[feature];
}
EXPORT_SYMBOL_GPL(get_xsave_addr);
+
+/*
+ * This wraps up the common operations that need to occur when retrieving
+ * data from an xsave struct. It first ensures that the task was actually
+ * using the FPU and retrieves the data in to a buffer. It then calculates
+ * the offset of the requested field in the buffer.
+ *
+ * This function is safe to call whether the FPU is in use or not.
+ *
+ * Inputs:
+ * tsk: the task from which we are fetching xsave state
+ * xstate: state which is defined in xsave.h (e.g. XSTATE_FP, XSTATE_SSE,
+ * etc.)
+ * Output:
+ * address of the state in the xsave area.
+ */
+void *tsk_get_xsave_field(struct task_struct *tsk, int xsave_field)
+{
+ union thread_xstate *xstate;
+
+ unlazy_fpu(tsk);
+ xstate = tsk->thread.fpu.state;
+ /*
+ * This might be unallocated if the FPU
+ * was never in use.
+ */
+ if (!xstate)
+ return NULL;
+
+ return get_xsave_addr(&xstate->xsave, xsave_field);
+}
+EXPORT_SYMBOL_GPL(tsk_get_xsave_field);
_
next reply other threads:[~2015-01-30 17:43 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-30 17:43 Dave Hansen [this message]
2015-01-30 17:43 ` [RFC][PATCH 2/2] x86, mpx: use new tsk_get_xsave_addr() Dave Hansen
2015-01-30 18:34 ` Oleg Nesterov
2015-01-30 21:37 ` Dave Hansen
2015-01-30 18:28 ` [RFC][PATCH 1/2] x86, fpu: wrap get_xsave_addr() to make it safer Oleg Nesterov
2015-01-30 18:38 ` 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=20150130174309.D666B2A7@viggo.jf.intel.com \
--to=dave@sr71.net \
--cc=dave.hansen@linux.intel.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=riel@redhat.com \
--cc=sbsiddha@gmail.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
Powered by JetHome