linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch 1/2] xsave: fix error condition in save_i387_xstate()
@ 2008-10-07 21:04 Suresh Siddha
  2008-10-07 21:04 ` [patch 2/2] xsave: set FP, SSE bits in the xsave header in the user sigcontext Suresh Siddha
  2008-10-07 21:59 ` [patch 1/2] xsave: fix error condition in save_i387_xstate() H. Peter Anvin
  0 siblings, 2 replies; 3+ messages in thread
From: Suresh Siddha @ 2008-10-07 21:04 UTC (permalink / raw)
  To: hpa, mingo, tglx; +Cc: linux-kernel, Suresh Siddha

[-- Attachment #1: fix_save_i387_xstate_err.patch --]
[-- Type: text/plain, Size: 502 bytes --]

Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
---

Index: tip/arch/x86/kernel/xsave.c
===================================================================
--- tip.orig/arch/x86/kernel/xsave.c	2008-10-02 10:30:55.000000000 -0700
+++ tip/arch/x86/kernel/xsave.c	2008-10-02 10:31:26.000000000 -0700
@@ -121,6 +121,8 @@
 		err |= __put_user(FP_XSTATE_MAGIC2,
 				  (__u32 __user *) (buf + sig_xstate_size
 						    - FP_XSTATE_MAGIC2_SIZE));
+		if (err)
+			return err;
 	}
 
 	return 1;

-- 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [patch 2/2] xsave: set FP, SSE bits in the xsave header in the user sigcontext
  2008-10-07 21:04 [patch 1/2] xsave: fix error condition in save_i387_xstate() Suresh Siddha
@ 2008-10-07 21:04 ` Suresh Siddha
  2008-10-07 21:59 ` [patch 1/2] xsave: fix error condition in save_i387_xstate() H. Peter Anvin
  1 sibling, 0 replies; 3+ messages in thread
From: Suresh Siddha @ 2008-10-07 21:04 UTC (permalink / raw)
  To: hpa, mingo, tglx; +Cc: linux-kernel, Suresh Siddha

[-- Attachment #1: fix_signal_handling_with_xsave_init_optimization.patch --]
[-- Type: text/plain, Size: 3476 bytes --]

If a processor implementation discern that a processor state component is in
its initialized state, it may modify the corresponding bit in the
xsave header.xstate_bv as '0'. State in the memory layout setup by 'xsave'
will be consistent with the bit values in the header.

During signal handling, legacy applications may change the FP/SSE bits
in the sigcontext memory layout without touching the FP/SSE header bits
in the xsave header. So always set FP/SSE bits in the xsave header
while saving the sigcontext state to the user space. During signal return,
this will enable the kernel to capture any changes to the FP/SSE bits by the
legacy applications which don't touch xsave headers.

xsave aware apps can change the xstate_bv in the xsave header aswell
as change any contents in the memory layout. xrestor as part of sigreturn
will capture all the changes.

Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
---

Index: tip/arch/x86/kernel/xsave.c
===================================================================
--- tip.orig/arch/x86/kernel/xsave.c	2008-10-06 13:25:16.000000000 -0700
+++ tip/arch/x86/kernel/xsave.c	2008-10-06 13:30:09.000000000 -0700
@@ -114,6 +114,8 @@
 
 	if (task_thread_info(tsk)->status & TS_XSAVE) {
 		struct _fpstate __user *fx = buf;
+		struct _xstate __user *x = buf;
+		u64 xstate_bv;
 
 		err = __copy_to_user(&fx->sw_reserved, &fx_sw_reserved,
 				     sizeof(struct _fpx_sw_bytes));
@@ -121,6 +123,29 @@
 		err |= __put_user(FP_XSTATE_MAGIC2,
 				  (__u32 __user *) (buf + sig_xstate_size
 						    - FP_XSTATE_MAGIC2_SIZE));
+
+		/*
+		 * Read the xstate_bv which we copied (directly from the cpu or
+		 * from the state in task struct) to the user buffers and
+		 * set the FP/SSE bits.
+		 */
+		err |= __get_user(xstate_bv, &x->xstate_hdr.xstate_bv);
+
+		/*
+		 * For legacy compatible, we always set FP/SSE bits in the bit
+		 * vector while saving the state to the user context. This will
+		 * enable us capturing any changes(during sigreturn) to
+		 * the FP/SSE bits by the legacy applications which don't touch
+		 * xstate_bv in the xsave header.
+		 *
+		 * xsave aware apps can change the xstate_bv in the xsave
+		 * header as well as change any contents in the memory layout.
+		 * xrestore as part of sigreturn will capture all the changes.
+		 */
+		xstate_bv |= XSTATE_FPSSE;
+
+		err |= __put_user(xstate_bv, &x->xstate_hdr.xstate_bv);
+
 		if (err)
 			return err;
 	}
Index: tip/arch/x86/kernel/i387.c
===================================================================
--- tip.orig/arch/x86/kernel/i387.c	2008-10-06 12:29:28.000000000 -0700
+++ tip/arch/x86/kernel/i387.c	2008-10-06 13:25:18.000000000 -0700
@@ -468,9 +468,23 @@
 
 static int save_i387_xsave(void __user *buf)
 {
+	struct task_struct *tsk = current;
 	struct _fpstate_ia32 __user *fx = buf;
 	int err = 0;
 
+	/*
+	 * For legacy compatible, we always set FP/SSE bits in the bit
+	 * vector while saving the state to the user context.
+	 * This will enable us capturing any changes(during sigreturn) to
+	 * the FP/SSE bits by the legacy applications which don't touch
+	 * xstate_bv in the xsave header.
+	 *
+	 * xsave aware applications can change the xstate_bv in the xsave
+	 * header as well as change any contents in the memory layout.
+	 * xrestore as part of sigreturn will capture all the changes.
+	 */
+	tsk->thread.xstate->xsave.xsave_hdr.xstate_bv |= XSTATE_FPSSE;
+
 	if (save_i387_fxsave(fx) < 0)
 		return -1;
 

-- 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch 1/2] xsave: fix error condition in save_i387_xstate()
  2008-10-07 21:04 [patch 1/2] xsave: fix error condition in save_i387_xstate() Suresh Siddha
  2008-10-07 21:04 ` [patch 2/2] xsave: set FP, SSE bits in the xsave header in the user sigcontext Suresh Siddha
@ 2008-10-07 21:59 ` H. Peter Anvin
  1 sibling, 0 replies; 3+ messages in thread
From: H. Peter Anvin @ 2008-10-07 21:59 UTC (permalink / raw)
  To: Suresh Siddha; +Cc: mingo, tglx, linux-kernel

Series applied to tip:x86/xsave, thanks!

	-hpa


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-10-07 21:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-07 21:04 [patch 1/2] xsave: fix error condition in save_i387_xstate() Suresh Siddha
2008-10-07 21:04 ` [patch 2/2] xsave: set FP, SSE bits in the xsave header in the user sigcontext Suresh Siddha
2008-10-07 21:59 ` [patch 1/2] xsave: fix error condition in save_i387_xstate() H. Peter Anvin

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).