From: David Miller <davem@davemloft.net>
To: mpatocka@redhat.com
Cc: sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org, agk@redhat.com
Subject: Re: stack overflow on Sparc64
Date: Fri, 20 Jun 2008 21:51:39 -0700 (PDT) [thread overview]
Message-ID: <20080620.215139.218732028.davem@davemloft.net> (raw)
In-Reply-To: <20080620.144128.32005196.davem@davemloft.net>
From: David Miller <davem@davemloft.net>
Date: Fri, 20 Jun 2008 14:41:28 -0700 (PDT)
> Next week I'll make one of my primary projects the implementation of
> IRQ stacks for sparc64.
Next week came real fast :-)
Amazingly this patch worked the first time I booted it up on my
dual-cpu workstation (using SMP + PREEMPT). I'm worried that maybe
gcc can do some clever things and not allow my extremely simple
approach to work, but anyways it might work for you and it's worth
giving a try.
sparc64: Implement support for IRQ stacks.
Signed-off-by: David S. Miller <davem@davemloft.net>
diff --git a/arch/sparc64/Kconfig.debug b/arch/sparc64/Kconfig.debug
index 6a4d28a..df80962 100644
--- a/arch/sparc64/Kconfig.debug
+++ b/arch/sparc64/Kconfig.debug
@@ -41,4 +41,11 @@ config FRAME_POINTER
depends on MCOUNT
default y
+config IRQSTACKS
+ bool "Use separate kernel stacks when processing interrupts"
+ help
+ If you say Y here the kernel will use separate kernel stacks
+ for handling hard and soft interrupts. This can help avoid
+ overflowing the process kernel stacks.
+
endmenu
diff --git a/arch/sparc64/kernel/irq.c b/arch/sparc64/kernel/irq.c
index b441a26..24820fa 100644
--- a/arch/sparc64/kernel/irq.c
+++ b/arch/sparc64/kernel/irq.c
@@ -674,10 +674,42 @@ void ack_bad_irq(unsigned int virt_irq)
ino, virt_irq);
}
+#ifdef CONFIG_IRQSTACKS
+void *hardirq_stack[NR_CPUS];
+void *softirq_stack[NR_CPUS];
+
+static void *set_hardirq_stack(void)
+{
+ void *orig_sp, *sp = hardirq_stack[smp_processor_id()];
+
+ __asm__ __volatile__("mov %%sp, %0" : "=r" (orig_sp));
+ if (orig_sp < sp ||
+ orig_sp > (sp + THREAD_SIZE)) {
+ sp += THREAD_SIZE - 192 - STACK_BIAS;
+ __asm__ __volatile__("mov %0, %%sp" : : "r" (sp));
+ }
+
+ return orig_sp;
+}
+static void restore_hardirq_stack(void *orig_sp)
+{
+ __asm__ __volatile__("mov %0, %%sp" : : "r" (orig_sp));
+}
+#else
+static void *set_hardirq_stack(void)
+{
+ return NULL;
+}
+static void restore_hardirq_stack(void *orig_sp)
+{
+}
+#endif
+
void handler_irq(int irq, struct pt_regs *regs)
{
unsigned long pstate, bucket_pa;
struct pt_regs *old_regs;
+ void *orig_sp;
clear_softint(1 << irq);
@@ -695,6 +727,8 @@ void handler_irq(int irq, struct pt_regs *regs)
"i" (PSTATE_IE)
: "memory");
+ orig_sp = set_hardirq_stack();
+
while (bucket_pa) {
struct irq_desc *desc;
unsigned long next_pa;
@@ -711,10 +745,40 @@ void handler_irq(int irq, struct pt_regs *regs)
bucket_pa = next_pa;
}
+ restore_hardirq_stack(orig_sp);
+
irq_exit();
set_irq_regs(old_regs);
}
+#ifdef CONFIG_IRQSTACKS
+void do_softirq(void)
+{
+ unsigned long flags;
+
+ if (in_interrupt())
+ return;
+
+ local_irq_save(flags);
+
+ if (local_softirq_pending()) {
+ void *orig_sp, *sp = softirq_stack[smp_processor_id()];
+
+ sp += THREAD_SIZE - 192 - STACK_BIAS;
+
+ __asm__ __volatile__("mov %%sp, %0\n\t"
+ "mov %1, %%sp"
+ : "=&r" (orig_sp)
+ : "r" (sp));
+ __do_softirq();
+ __asm__ __volatile__("mov %0, %%sp"
+ : : "r" (orig_sp));
+ }
+
+ local_irq_restore(flags);
+}
+#endif
+
#ifdef CONFIG_HOTPLUG_CPU
void fixup_irqs(void)
{
diff --git a/arch/sparc64/mm/init.c b/arch/sparc64/mm/init.c
index 84898c4..56e22f4 100644
--- a/arch/sparc64/mm/init.c
+++ b/arch/sparc64/mm/init.c
@@ -49,6 +49,7 @@
#include <asm/sstate.h>
#include <asm/mdesc.h>
#include <asm/cpudata.h>
+#include <asm/irq.h>
#define MAX_PHYS_ADDRESS (1UL << 42UL)
#define KPTE_BITMAP_CHUNK_SZ (256UL * 1024UL * 1024UL)
@@ -1817,6 +1818,18 @@ void __init paging_init(void)
if (tlb_type == hypervisor)
sun4v_mdesc_init();
+#ifdef CONFIG_IRQSTACKS
+ /* Once the OF device tree and MDESC have been setup, we know
+ * the list of possible cpus. Therefore we can allocate the
+ * IRQ stacks.
+ */
+ for_each_possible_cpu(i) {
+ /* XXX Use node local allocations... XXX */
+ softirq_stack[i] = __va(lmb_alloc(THREAD_SIZE, THREAD_SIZE));
+ hardirq_stack[i] = __va(lmb_alloc(THREAD_SIZE, THREAD_SIZE));
+ }
+#endif
+
/* Setup bootmem... */
last_valid_pfn = end_pfn = bootmem_init(phys_base);
diff --git a/include/asm-sparc64/irq.h b/include/asm-sparc64/irq.h
index 0bb9bf5..d71b5ff 100644
--- a/include/asm-sparc64/irq.h
+++ b/include/asm-sparc64/irq.h
@@ -90,4 +90,10 @@ static inline unsigned long get_softint(void)
return retval;
}
+#ifdef CONFIG_IRQSTACKS
+extern void *hardirq_stack[NR_CPUS];
+extern void *softirq_stack[NR_CPUS];
+#define __ARCH_HAS_DO_SOFTIRQ
+#endif
+
#endif
next prev parent reply other threads:[~2008-06-21 4:51 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-18 0:47 Mikulas Patocka
2008-06-18 4:01 ` David Miller
2008-06-19 3:24 ` Mikulas Patocka
2008-06-19 3:59 ` David Miller
2008-06-19 5:17 ` Mikulas Patocka
2008-06-19 6:37 ` David Miller
2008-06-19 13:01 ` Mikulas Patocka
2008-06-20 15:47 ` Mikulas Patocka
2008-06-20 17:26 ` David Miller
2008-06-20 20:34 ` Mikulas Patocka
2008-06-20 20:37 ` David Miller
2008-06-20 21:26 ` Mikulas Patocka
2008-06-20 21:41 ` David Miller
2008-06-21 4:51 ` David Miller [this message]
2008-06-21 19:42 ` Mikulas Patocka
2008-06-22 7:03 ` David Miller
2008-06-22 13:48 ` Mikulas Patocka
2008-08-12 6:30 ` David Miller
2008-08-12 8:22 ` David Miller
2008-08-13 0:53 ` Mikulas Patocka
2008-08-13 0:59 ` David Miller
2008-08-13 1:11 ` console handover badness [was: stack overflow on Sparc64] Mikulas Patocka
2008-08-13 1:22 ` console handover badness David Miller
2008-08-13 1:40 ` David Miller
2008-08-13 8:50 ` David Miller
2008-08-13 12:46 ` Mikulas Patocka
2008-08-14 3:25 ` David Miller
2008-08-14 23:11 ` Bootmem allocator broken [was: console handover badness] Mikulas Patocka
2008-08-14 23:25 ` Bootmem allocator broken David Miller
2008-08-15 11:09 ` Alexander Beregalov
2008-08-15 21:13 ` David Miller
2008-08-14 23:40 ` Johannes Weiner
2008-06-20 21:14 ` stack overflow on Sparc64 Mikulas Patocka
2008-06-20 21:20 ` David Miller
2008-06-20 21:25 ` Mikulas Patocka
2008-06-20 21:44 ` David Miller
2008-06-20 21:47 ` David Miller
2008-06-20 22:22 ` Mikulas Patocka
2008-06-20 22:28 ` David Miller
2008-06-20 22:36 ` Mikulas Patocka
2008-06-20 22:47 ` David Miller
2008-06-21 0:37 ` Mikulas Patocka
2008-06-20 22:33 ` Mikulas Patocka
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=20080620.215139.218732028.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=agk@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mpatocka@redhat.com \
--cc=sparclinux@vger.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
all inboxes | Powered by JetHome®