From: William Lee Irwin III <wli@holomorphy.com>
To: Andi Kleen <andi@firstfloor.org>
Cc: Christoph Hellwig <hch@infradead.org>,
Alan Cox <alan@lxorguk.ukuu.org.uk>, David Chinner <dgc@sgi.com>,
Zan Lynx <zlynx@acm.org>, Adrian Bunk <bunk@stusta.de>,
Linux Kernel <linux-kernel@vger.kernel.org>
Subject: [5/6] dynamically allocate IRQ stacks (was: Re: [-mm patch] i386: enable 4k stacks by default)
Date: Mon, 30 Apr 2007 10:46:30 -0700 [thread overview]
Message-ID: <20070430174630.GH19966@holomorphy.com> (raw)
In-Reply-To: <20070430173819.GC19966@holomorphy.com>
On Mon, Apr 30, 2007 at 10:38:19AM -0700, William Lee Irwin III wrote:
> Here's what I did for i386 for someone concerned about blowing the stack.
Fix up the conflict between IRQ stacks and deep stacks by dynamically
allocating IRQ stacks.
Signed-off-by: William Irwin <wli@holomorphy.com>
Index: stack-paranoia/arch/i386/Kconfig.debug
===================================================================
--- stack-paranoia.orig/arch/i386/Kconfig.debug 2007-04-30 10:34:07.058721717 -0700
+++ stack-paranoia/arch/i386/Kconfig.debug 2007-04-30 10:36:14.553987258 -0700
@@ -107,7 +107,6 @@
config 64KSTACKS
bool "Use 64KB for kernel stacks"
- depends on !IRQSTACKS
help
If you say Y here, the kernel will use a 64KB stacksize.
This impedes running more threads on a system and also increases
Index: stack-paranoia/arch/i386/kernel/irq.c
===================================================================
--- stack-paranoia.orig/arch/i386/kernel/irq.c 2007-04-30 10:34:07.058721717 -0700
+++ stack-paranoia/arch/i386/kernel/irq.c 2007-04-30 10:36:14.553987258 -0700
@@ -17,9 +17,11 @@
#include <linux/notifier.h>
#include <linux/cpu.h>
#include <linux/delay.h>
+#include <linux/bootmem.h>
#include <asm/apic.h>
#include <asm/uaccess.h>
+#include <asm/pgtable.h>
DEFINE_PER_CPU(irq_cpustat_t, irq_stat) ____cacheline_internodealigned_in_smp;
EXPORT_PER_CPU_SYMBOL(irq_stat);
@@ -56,8 +58,8 @@
u32 stack[THREAD_SIZE/sizeof(u32)];
};
-static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
-static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
+static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
+static DEFINE_PER_CPU(union irq_ctx *, softirq_ctx);
#endif
/*
@@ -102,7 +104,7 @@
#ifdef CONFIG_IRQSTACKS
curctx = (union irq_ctx *) current_thread_info();
- irqctx = hardirq_ctx[smp_processor_id()];
+ irqctx = per_cpu(hardirq_ctx, smp_processor_id());
/*
* this is where we switch to the IRQ stack. However, if we are
@@ -150,11 +152,44 @@
* These should really be __section__(".bss.page_aligned") as well, but
* gcc's 3.0 and earlier don't handle that correctly.
*/
-static char softirq_stack[NR_CPUS * THREAD_SIZE]
- __attribute__((__aligned__(THREAD_SIZE)));
+static DEFINE_PER_CPU(char *, softirq_stack);
+static DEFINE_PER_CPU(char *, hardirq_stack);
-static char hardirq_stack[NR_CPUS * THREAD_SIZE]
- __attribute__((__aligned__(THREAD_SIZE)));
+#ifdef CONFIG_VMALLOC_STACK
+static void * __init __alloc_irqstack(int cpu)
+{
+ int i;
+ struct page *pages[THREAD_SIZE/PAGE_SIZE], **tmp = pages;
+ struct vm_struct *area;
+
+ if (!cpu)
+ return __alloc_bootmem(THREAD_SIZE, THREAD_SIZE,
+ __pa(MAX_DMA_ADDRESS));
+
+ /* failures here are unrecoverable anyway */
+ area = get_vm_area(THREAD_SIZE, VM_IOREMAP);
+ for (i = 0; i < ARRAY_SIZE(pages); ++i)
+ pages[i] = alloc_page(GFP_HIGHUSER);
+ map_vm_area(area, PAGE_KERNEL, &tmp);
+ return area->addr;
+}
+#else /* !CONFIG_VMALLOC_STACK */
+static void * __init __alloc_irqstack(int cpu)
+{
+ if (!cpu)
+ return __alloc_bootmem(THREAD_SIZE, THREAD_SIZE,
+ __pa(MAX_DMA_ADDRESS));
+
+ return (void *)__get_free_pages(GFP_KERNEL,
+ ilog2(THREAD_SIZE/PAGE_SIZE));
+}
+#endif /* !CONFIG_VMALLOC_STACK */
+
+static void __init alloc_irqstacks(int cpu)
+{
+ per_cpu(softirq_stack, cpu) = __alloc_irqstack(cpu);
+ per_cpu(hardirq_stack, cpu) = __alloc_irqstack(cpu);
+}
/*
* allocate per-cpu stacks for hardirq and for softirq processing
@@ -163,34 +198,36 @@
{
union irq_ctx *irqctx;
- if (hardirq_ctx[cpu])
+ if (per_cpu(hardirq_ctx, cpu))
return;
- irqctx = (union irq_ctx*) &hardirq_stack[cpu*THREAD_SIZE];
+ alloc_irqstacks(cpu);
+
+ irqctx = (union irq_ctx*)per_cpu(hardirq_stack, cpu);
irqctx->tinfo.task = NULL;
irqctx->tinfo.exec_domain = NULL;
irqctx->tinfo.cpu = cpu;
irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
- hardirq_ctx[cpu] = irqctx;
+ per_cpu(hardirq_ctx, cpu) = irqctx;
- irqctx = (union irq_ctx*) &softirq_stack[cpu*THREAD_SIZE];
+ irqctx = (union irq_ctx*)per_cpu(softirq_stack, cpu);
irqctx->tinfo.task = NULL;
irqctx->tinfo.exec_domain = NULL;
irqctx->tinfo.cpu = cpu;
irqctx->tinfo.preempt_count = 0;
irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
- softirq_ctx[cpu] = irqctx;
+ per_cpu(softirq_ctx, cpu) = irqctx;
printk("CPU %u irqstacks, hard=%p soft=%p\n",
- cpu,hardirq_ctx[cpu],softirq_ctx[cpu]);
+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
}
void irq_ctx_exit(int cpu)
{
- hardirq_ctx[cpu] = NULL;
+ per_cpu(hardirq_ctx, cpu) = NULL;
}
extern asmlinkage void __do_softirq(void);
@@ -209,7 +246,7 @@
if (local_softirq_pending()) {
curctx = current_thread_info();
- irqctx = softirq_ctx[smp_processor_id()];
+ irqctx = per_cpu(softirq_ctx, smp_processor_id());
irqctx->tinfo.task = curctx->task;
irqctx->tinfo.previous_esp = current_stack_pointer;
next prev parent reply other threads:[~2007-04-30 17:46 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-28 19:19 [-mm patch] i386: enable 4k stacks by default Adrian Bunk
2007-04-28 21:18 ` Zan Lynx
2007-04-30 3:58 ` David Chinner
2007-04-30 8:17 ` Alan Cox
2007-04-30 10:26 ` Andi Kleen
2007-04-30 10:48 ` Christoph Hellwig
2007-04-30 12:13 ` Andi Kleen
2007-04-30 17:38 ` William Lee Irwin III
2007-04-30 17:40 ` [1/6] make stack size configurable (was: Re: [-mm patch] i386: enable 4k stacks by default) William Lee Irwin III
2007-04-30 18:10 ` Christoph Hellwig
2007-04-30 18:13 ` William Lee Irwin III
2007-04-30 18:25 ` Adrian Bunk
2007-04-30 18:32 ` William Lee Irwin III
2007-04-30 17:43 ` [2/6] add config option to vmalloc stacks " William Lee Irwin III
2007-04-30 18:11 ` Christoph Hellwig
2007-04-30 18:25 ` Jan Engelhardt
2007-04-30 19:09 ` William Lee Irwin III
2007-04-30 19:15 ` Christoph Hellwig
2007-04-30 19:23 ` Bill Irwin
2007-04-30 22:04 ` Bill Irwin
2007-05-01 22:36 ` Matt Mackall
2007-05-01 22:51 ` Bill Irwin
2007-05-01 23:07 ` Alan Cox
2007-05-01 23:23 ` Bill Irwin
2007-05-01 23:15 ` Matt Mackall
2007-05-01 23:27 ` Bill Irwin
2007-05-04 5:35 ` Joseph Fannin
2007-05-04 7:43 ` Bill Irwin
2007-04-30 17:44 ` [3/6] make IRQ stacks independently configurable " William Lee Irwin III
2007-04-30 18:11 ` Christoph Hellwig
2007-04-30 18:14 ` William Lee Irwin III
2007-04-30 17:45 ` [4/6] go BUG on vmallocspace in __pa() " William Lee Irwin III
2007-04-30 18:52 ` Andi Kleen
2007-04-30 18:58 ` William Lee Irwin III
2007-04-30 19:20 ` Alan Cox
2007-04-30 19:26 ` Bill Irwin
2007-05-02 22:31 ` [4/6] go BUG on vmallocspace in __pa() Jeremy Fitzhardinge
2007-05-02 22:48 ` Bill Irwin
2007-04-30 17:46 ` William Lee Irwin III [this message]
2007-04-30 19:49 ` [5/6] dynamically allocate IRQ stacks (was: Re: [-mm patch] i386: enable 4k stacks by default) Zwane Mwaikambo
2007-04-30 20:03 ` Bill Irwin
2007-04-30 20:07 ` Andi Kleen
2007-04-30 17:47 ` [6/6] arrange for a guard page on cpu 0's IRQ stack " William Lee Irwin III
2007-04-30 18:22 ` [-mm patch] i386: enable 4k stacks by default Jan Engelhardt
2007-04-30 18:35 ` William Lee Irwin III
2007-04-30 18:51 ` Andi Kleen
2007-04-30 8:55 ` Neil Brown
2007-04-30 8:59 ` Christoph Hellwig
2007-04-30 11:30 ` Jens Axboe
2007-04-30 23:24 ` Neil Brown
2007-05-01 8:01 ` Jens Axboe
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=20070430174630.GH19966@holomorphy.com \
--to=wli@holomorphy.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=andi@firstfloor.org \
--cc=bunk@stusta.de \
--cc=dgc@sgi.com \
--cc=hch@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=zlynx@acm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.