* [PATCH] x86-32: don't switch to irq stack for a user-mode irq
@ 2012-02-19 19:46 Linus Torvalds
2012-02-20 11:47 ` [tip:irq/core] x86-32/irq: Don' t " tip-bot for Linus Torvalds
0 siblings, 1 reply; 2+ messages in thread
From: Linus Torvalds @ 2012-02-19 19:46 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin
Cc: x86, Linux Kernel Mailing List
From: Linus Torvalds <torvalds@linux-foundation.org>
Date: Sun Feb 19 11:35:34 2012 -0800
x86-32: don't switch to irq stack for a user-mode irq
If the irq happens in user mode, our kernel stack is empty (apart from the
pt_regs themselves, of course), so there's no need or advantage to switch.
And it really doesn't save any stack space, quite the reverse: it means
that a nested interrupt cannot switch irq stacks. So instead of saving
kernel stack space, it actually causes the potential for *more* stack
usage.
Also simplify the preemption count copy when we do switch stacks: just
copy the whole preemption count, rather than just the softirq parts of it.
There is no advantage to the partial copy: it is more effort to get a less
correct result.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
This came up during the i387 work. It's not a bug, but I do believe that
we do stupid things on x86-32 when we get an interrupt in user mode.
I'm throwing this patch out here because I think it's the right thing to
do, but I won't commit it myself or push it any more than this.
arch/x86/kernel/irq_32.c | 11 +++--------
1 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
index 40fc86161d92..58b7f27cb3e9 100644
--- a/arch/x86/kernel/irq_32.c
+++ b/arch/x86/kernel/irq_32.c
@@ -100,13 +100,8 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
irqctx->tinfo.task = curctx->tinfo.task;
irqctx->tinfo.previous_esp = current_stack_pointer;
- /*
- * Copy the softirq bits in preempt_count so that the
- * softirq checks work in the hardirq context.
- */
- irqctx->tinfo.preempt_count =
- (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
- (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
+ /* Copy the preempt_count so that the [soft]irq checks work. */
+ irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
if (unlikely(overflow))
call_on_stack(print_stack_overflow, isp);
@@ -196,7 +191,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
if (unlikely(!desc))
return false;
- if (!execute_on_irq_stack(overflow, desc, irq)) {
+ if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
if (unlikely(overflow))
print_stack_overflow();
desc->handle_irq(irq, desc);
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [tip:irq/core] x86-32/irq: Don' t switch to irq stack for a user-mode irq
2012-02-19 19:46 [PATCH] x86-32: don't switch to irq stack for a user-mode irq Linus Torvalds
@ 2012-02-20 11:47 ` tip-bot for Linus Torvalds
0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for Linus Torvalds @ 2012-02-20 11:47 UTC (permalink / raw)
To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, torvalds, tglx, mingo
Commit-ID: 986cb48c5a4de0085db94d343b4e7dcf54355ec1
Gitweb: http://git.kernel.org/tip/986cb48c5a4de0085db94d343b4e7dcf54355ec1
Author: Linus Torvalds <torvalds@linux-foundation.org>
AuthorDate: Sun, 19 Feb 2012 11:46:36 -0800
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Mon, 20 Feb 2012 09:30:18 +0100
x86-32/irq: Don't switch to irq stack for a user-mode irq
If the irq happens in user mode, our kernel stack is empty
(apart from the pt_regs themselves, of course), so there's no
need or advantage to switch.
And it really doesn't save any stack space, quite the reverse:
it means that a nested interrupt cannot switch irq stacks. So
instead of saving kernel stack space, it actually causes the
potential for *more* stack usage.
Also simplify the preemption count copy when we do switch
stacks: just copy the whole preemption count, rather than just
the softirq parts of it. There is no advantage to the partial
copy: it is more effort to get a less correct result.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/alpine.LFD.2.02.1202191139260.10000@i5.linux-foundation.org
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
arch/x86/kernel/irq_32.c | 11 +++--------
1 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
index 40fc861..58b7f27 100644
--- a/arch/x86/kernel/irq_32.c
+++ b/arch/x86/kernel/irq_32.c
@@ -100,13 +100,8 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
irqctx->tinfo.task = curctx->tinfo.task;
irqctx->tinfo.previous_esp = current_stack_pointer;
- /*
- * Copy the softirq bits in preempt_count so that the
- * softirq checks work in the hardirq context.
- */
- irqctx->tinfo.preempt_count =
- (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
- (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
+ /* Copy the preempt_count so that the [soft]irq checks work. */
+ irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
if (unlikely(overflow))
call_on_stack(print_stack_overflow, isp);
@@ -196,7 +191,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
if (unlikely(!desc))
return false;
- if (!execute_on_irq_stack(overflow, desc, irq)) {
+ if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
if (unlikely(overflow))
print_stack_overflow();
desc->handle_irq(irq, desc);
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-02-20 11:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-19 19:46 [PATCH] x86-32: don't switch to irq stack for a user-mode irq Linus Torvalds
2012-02-20 11:47 ` [tip:irq/core] x86-32/irq: Don' t " tip-bot for Linus Torvalds
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).