lkml.org 
[lkml]   [2007]   [Apr]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    Subject[6/6] arrange for a guard page on cpu 0's IRQ stack (was: Re: [-mm patch] i386: enable 4k stacks by default)
    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.

    vmap() cpu 0's IRQ stack to ensure a guard page for it.

    Signed-off-by: William Irwin <wli@holomorphy.com>


    Index: stack-paranoia/arch/i386/kernel/irq.c
    ===================================================================
    --- stack-paranoia.orig/arch/i386/kernel/irq.c 2007-04-30 10:36:14.553987258 -0700
    +++ stack-paranoia/arch/i386/kernel/irq.c 2007-04-30 10:37:09.909141769 -0700
    @@ -17,6 +17,7 @@
    #include <linux/notifier.h>
    #include <linux/cpu.h>
    #include <linux/delay.h>
    +#include <linux/mm.h>
    #include <linux/bootmem.h>

    #include <asm/apic.h>
    @@ -156,6 +157,41 @@
    static DEFINE_PER_CPU(char *, hardirq_stack);

    #ifdef CONFIG_VMALLOC_STACK
    +static void * __init irq_remap_stack(void *stack)
    +{
    + int i;
    + struct page *pages[THREAD_SIZE/PAGE_SIZE];
    +
    + for (i = 0; i < ARRAY_SIZE(pages); ++i)
    + pages[i] = virt_to_page(stack + PAGE_SIZE*i);
    + return vmap(pages, THREAD_SIZE/PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
    +}
    +
    +static int __init irq_guard_cpu0(void)
    +{
    + unsigned long flags;
    + void *tmp;
    +
    + tmp = irq_remap_stack(per_cpu(softirq_stack, 0));
    + if (!tmp)
    + return -ENOMEM;
    + else {
    + local_irq_save(flags);
    + per_cpu(softirq_stack, 0) = tmp;
    + local_irq_restore(flags);
    + }
    + tmp = irq_remap_stack(per_cpu(hardirq_stack, 0));
    + if (!tmp)
    + return -ENOMEM;
    + else {
    + local_irq_save(flags);
    + per_cpu(hardirq_stack, 0) = tmp;
    + local_irq_restore(flags);
    + }
    + return 0;
    +}
    +core_initcall(irq_guard_cpu0);
    +
    static void * __init __alloc_irqstack(int cpu)
    {
    int i;
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/
    \
     
     \ /
      Last update: 2007-04-30 19:49    [W:0.053 / U:155.128 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site