linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Make math_state_restore() save and restore the interrupt flag
@ 2014-01-30 22:01 Nate Eldredge
  2014-01-30 22:24 ` Linus Torvalds
  0 siblings, 1 reply; 41+ messages in thread
From: Nate Eldredge @ 2014-01-30 22:01 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, stable,
	linux-kernel, Maarten Baert, jack, linux, Nate Eldredge,
	torvalds, sbsiddha

From: Nate Eldredge <nate@thatsmathematics.com>

Make math_state_restore() save and restore the interrupt flag, rather
than always disabling interrupts.

If math_state_restore() is called in a task that has not used math, it
needs to allocate some memory (via init_fpu()).  Since this can sleep,
it enables interrupts first.  Currently, it always disables them
afterwards, regardless of whether or not they were enabled on entry.
(See commit aa283f4927 where this was introduced.)  This doesn't make
sense, so instead have it put interrupts back the way they were.

This is the cause of Ubuntu bug #1265841
(https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1265841): if a
user process dumps core on an ecrypt fs while aesni-intel is loaded,
we get a BUG() in __find_get_block() complaining that it was called
with interrupts disabled; then all further accesses to our ecrypt fs
hang and we have to reboot.  The aesni-intel code (encrypting the core
file that we are writing) needs the FPU and quite properly wraps its
code in kernel_fpu_{begin,end}(), the latter of which calls
math_state_restore().  So after kernel_fpu_end(), interrupts may be
disabled, which nobody seems to expect, and they stay that way until
we eventually get to __find_get_block() which barfs.  With this patch,
the testcase works fine and no BUG() is triggered.

math_state_restore() may need further review, as it still seems
suspicious that it can unilaterally enable interupts for itself.  It's
not clear to me what are the intended semantics of
math_state_restore() and kernel_fpu_{begin,end}() with respect to
interrupts.  Nevertheless, this patch should be appropriate for now.

Signed-off-by: Nate Eldredge <nate@thatsmathematics.com>
Tested-by: George Spelvin <linux@horizon.com>
Cc: <stable@vger.kernel.org>
Fixes: aa283f4927

---

Applies to linux-3.13.  Previous discussion in linux-kernel thread
"math_state_restore and kernel_fpu_end disable interrupts?"

diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index b857ed8..09df67d 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -628,6 +628,9 @@ void math_state_restore(void)
  	struct task_struct *tsk = current;

  	if (!tsk_used_math(tsk)) {
+		unsigned long flags;
+
+		local_save_flags(flags);
  		local_irq_enable();
  		/*
  		 * does a slab alloc which can sleep
@@ -639,7 +642,7 @@ void math_state_restore(void)
  			do_group_exit(SIGKILL);
  			return;
  		}
-		local_irq_disable();
+		local_irq_restore(flags);
  	}

  	__thread_fpu_begin(tsk);


-- 
Nate Eldredge
nate@thatsmathematics.com


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

end of thread, other threads:[~2014-03-11 19:37 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-30 22:01 [PATCH] Make math_state_restore() save and restore the interrupt flag Nate Eldredge
2014-01-30 22:24 ` Linus Torvalds
2014-01-31  7:33   ` Suresh Siddha
2014-02-01 19:27     ` Linus Torvalds
2014-02-01 19:35       ` H. Peter Anvin
2014-02-01 19:46         ` Linus Torvalds
2014-02-01 20:00           ` H. Peter Anvin
2014-02-01 20:16             ` Linus Torvalds
2014-02-01 20:16           ` H. Peter Anvin
2014-02-01 21:17           ` George Spelvin
2014-02-01 21:36             ` H. Peter Anvin
2014-02-01 23:40             ` H. Peter Anvin
2014-02-02  0:17               ` Linus Torvalds
2014-02-02  1:19               ` George Spelvin
2014-02-02  1:25                 ` H. Peter Anvin
2014-02-02  8:45           ` Pekka Riikonen
2014-02-02  1:06       ` Suresh Siddha
2014-02-02  1:26         ` H. Peter Anvin
2014-02-02  1:35           ` Suresh Siddha
2014-02-02  1:38             ` Linus Torvalds
2014-02-02  1:47               ` Suresh Siddha
2014-02-02  1:51                 ` Linus Torvalds
2014-02-02  1:57                   ` H. Peter Anvin
2014-02-02  2:05                     ` Linus Torvalds
2014-02-02  2:12                       ` H. Peter Anvin
2014-02-02  1:59                   ` Suresh Siddha
2014-02-02  1:43             ` H. Peter Anvin
2014-02-02  1:47               ` Linus Torvalds
2014-02-02  7:19         ` Suresh Siddha
2014-02-02 19:15           ` Linus Torvalds
2014-02-03  6:56             ` Suresh Siddha
2014-02-03 18:20               ` Linus Torvalds
2014-02-04  6:03                 ` Suresh Siddha
2014-02-06  5:26               ` Nate Eldredge
2014-02-06  5:34                 ` George Spelvin
2014-02-13 15:45               ` Maarten Baert
2014-02-13 20:00                 ` George Spelvin
2014-03-11 19:36               ` [tip:x86/urgent] x86, fpu: Check tsk_used_math() in kernel_fpu_end() for eager FPU tip-bot for Suresh Siddha
2014-02-27 23:44           ` [PATCH] Make math_state_restore() save and restore the interrupt flag H. Peter Anvin
2014-03-07 23:18             ` H. Peter Anvin
2014-03-08  6:18               ` Suresh Siddha

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