ia64/xen-unstable

changeset 1057:432277fa713c

bitkeeper revision 1.696 (401a7b30TOUK5wUOTZ_RoVNCXsji4g)

sched.h, config.h, current.h, smpboot.c, setup.c, boot.S:
Add support for detecting stack overflow within Xen. This is turned on for debug builds.
author kaf24@scramble.cl.cam.ac.uk
date Fri Jan 30 15:41:36 2004 +0000 (2004-01-30)
parents c67c82ddb44a
children 23d2d95255c7
files xen/arch/i386/boot/boot.S xen/arch/i386/setup.c xen/arch/i386/smpboot.c xen/include/asm-i386/current.h xen/include/xeno/config.h xen/include/xeno/sched.h
line diff
     1.1 --- a/xen/arch/i386/boot/boot.S	Wed Jan 28 18:29:04 2004 +0000
     1.2 +++ b/xen/arch/i386/boot/boot.S	Fri Jan 30 15:41:36 2004 +0000
     1.3 @@ -214,7 +214,7 @@ 1:      jmp     1b
     1.4  /*** STACK LOCATION ***/
     1.5          
     1.6  ENTRY(stack_start)
     1.7 -        .long SYMBOL_NAME(cpu0_stack) + 4000 - __PAGE_OFFSET
     1.8 +        .long SYMBOL_NAME(cpu0_stack) + 8100 - __PAGE_OFFSET
     1.9          .long __HYPERVISOR_DS
    1.10          
    1.11  /*** DESCRIPTOR TABLES ***/
    1.12 @@ -256,11 +256,10 @@ ENTRY(gdt_table)
    1.13          .quad 0x0000000000000000     /* unused                           */
    1.14          .fill 2*NR_CPUS,8,0          /* space for TSS and LDT per CPU    */
    1.15  
    1.16 -# The following adds 8-12kB to the kernel file size.
    1.17          .org 0x1000
    1.18 -ENTRY(idle_pg_table)
    1.19 +ENTRY(idle_pg_table) # Initial page directory is 4kB
    1.20          .org 0x2000
    1.21 -ENTRY(cpu0_stack)
    1.22 -        .org 0x3000
    1.23 +ENTRY(cpu0_stack)    # Initial stack is 8kB
    1.24 +        .org 0x4000
    1.25  ENTRY(stext)
    1.26  ENTRY(_stext)
     2.1 --- a/xen/arch/i386/setup.c	Wed Jan 28 18:29:04 2004 +0000
     2.2 +++ b/xen/arch/i386/setup.c	Fri Jan 30 15:41:36 2004 +0000
     2.3 @@ -321,6 +321,30 @@ void __init start_of_day(void)
     2.4      extern int do_timer_lists_from_pit;
     2.5      unsigned long low_mem_size;
     2.6      
     2.7 +#ifdef STACK_GUARD
     2.8 +    extern unsigned long cpu0_stack[];
     2.9 +    l1_pgentry_t *l1;
    2.10 +    l2_pgentry_t *l2;
    2.11 +    int i, j;
    2.12 +
    2.13 +    /* When stack-guarding, Xen's heap cannot be mapped by super pages. */
    2.14 +    for ( i = 0; i < (MAX_MONITOR_ADDRESS >> L2_PAGETABLE_SHIFT); i++ )
    2.15 +    {
    2.16 +        l1 = (l1_pgentry_t *)get_free_page(GFP_KERNEL);
    2.17 +        for ( j = 0; j < ENTRIES_PER_L1_PAGETABLE; j++ )
    2.18 +            l1[j] = mk_l1_pgentry((i << L2_PAGETABLE_SHIFT) |
    2.19 +                                   (j << L1_PAGETABLE_SHIFT) | 
    2.20 +                                   PAGE_HYPERVISOR);
    2.21 +        idle_pg_table[i] = idle_pg_table[i + l2_table_offset(PAGE_OFFSET)] =
    2.22 +            mk_l2_pgentry(virt_to_phys(l1) | PAGE_HYPERVISOR);
    2.23 +    }
    2.24 +
    2.25 +    /* Unmap the first page of CPU0's stack. */
    2.26 +    l2  = &idle_pg_table[l2_table_offset(virt_to_phys(cpu0_stack))];
    2.27 +    l1  = l2_pgentry_to_l1(*l2) + l1_table_offset(virt_to_phys(cpu0_stack));
    2.28 +    *l1 = mk_l1_pgentry(0);
    2.29 +#endif
    2.30 +
    2.31      if ( opt_watchdog ) 
    2.32          nmi_watchdog = NMI_LOCAL_APIC;
    2.33  
     3.1 --- a/xen/arch/i386/smpboot.c	Wed Jan 28 18:29:04 2004 +0000
     3.2 +++ b/xen/arch/i386/smpboot.c	Fri Jan 30 15:41:36 2004 +0000
     3.3 @@ -667,7 +667,7 @@ static void __init do_boot_cpu (int apic
     3.4      struct task_struct *idle;
     3.5      unsigned long boot_error = 0;
     3.6      int timeout, cpu;
     3.7 -    unsigned long start_eip;
     3.8 +    unsigned long start_eip, stack;
     3.9  
    3.10      cpu = ++cpucount;
    3.11  
    3.12 @@ -687,7 +687,17 @@ static void __init do_boot_cpu (int apic
    3.13  
    3.14      /* So we see what's up. */
    3.15      printk("Booting processor %d/%d eip %lx\n", cpu, apicid, start_eip);
    3.16 -    stack_start.esp = __pa(get_free_page(GFP_KERNEL)) + 4000;
    3.17 +
    3.18 +    stack = __pa(__get_free_pages(GFP_KERNEL, 1));
    3.19 +#ifdef STACK_GUARD
    3.20 +    {
    3.21 +        /* Unmap the first page of the new CPU0's stack. */
    3.22 +        l2_pgentry_t *l2  = &idle_pg_table[l2_table_offset(stack)];
    3.23 +        l1_pgentry_t *l1  = l2_pgentry_to_l1(*l2) + l1_table_offset(stack);
    3.24 +        *l1 = mk_l1_pgentry(0);
    3.25 +    }
    3.26 +#endif
    3.27 +    stack_start.esp = stack + STACK_SIZE - STACK_RESERVED;
    3.28  
    3.29      /*
    3.30       * This grunge runs the startup process for
     4.1 --- a/xen/include/asm-i386/current.h	Wed Jan 28 18:29:04 2004 +0000
     4.2 +++ b/xen/include/asm-i386/current.h	Fri Jan 30 15:41:36 2004 +0000
     4.3 @@ -3,11 +3,14 @@
     4.4  
     4.5  struct task_struct;
     4.6  
     4.7 +#define STACK_RESERVED \
     4.8 +    (sizeof(execution_context_t) + sizeof(struct task_struct *))
     4.9 +
    4.10  static inline struct task_struct * get_current(void)
    4.11  {
    4.12      struct task_struct *current;
    4.13      __asm__ ( "orl %%esp,%0; andl $~3,%0; movl (%0),%0" 
    4.14 -              : "=r" (current) : "0" (4092UL) );
    4.15 +              : "=r" (current) : "0" (STACK_SIZE-4) );
    4.16      return current;
    4.17  }
    4.18   
    4.19 @@ -16,14 +19,15 @@ static inline struct task_struct * get_c
    4.20  static inline void set_current(struct task_struct *p)
    4.21  {
    4.22      __asm__ ( "orl %%esp,%0; andl $~3,%0; movl %1,(%0)" 
    4.23 -              : : "r" (4092UL), "r" (p) );    
    4.24 +              : : "r" (STACK_SIZE-4), "r" (p) );    
    4.25  }
    4.26  
    4.27  static inline execution_context_t *get_execution_context(void)
    4.28  {
    4.29      execution_context_t *execution_context;
    4.30 -    __asm__ ( "andl %%esp,%0; addl $4096-72,%0"
    4.31 -              : "=r" (execution_context) : "0" (~4095UL) );
    4.32 +    __asm__ ( "andl %%esp,%0; addl %2,%0"
    4.33 +              : "=r" (execution_context) 
    4.34 +              : "0" (~(STACK_SIZE-1)), "i" (STACK_SIZE-STACK_RESERVED) );
    4.35      return execution_context;
    4.36  }
    4.37  
    4.38 @@ -31,16 +35,18 @@ static inline unsigned long get_stack_to
    4.39  {
    4.40      unsigned long p;
    4.41      __asm__ ( "orl %%esp,%0; andl $~3,%0" 
    4.42 -              : "=r" (p) : "0" (4092UL) );
    4.43 +              : "=r" (p) : "0" (STACK_SIZE-4) );
    4.44      return p;
    4.45  }
    4.46  
    4.47  #define schedule_tail(_p)                                         \
    4.48      __asm__ __volatile__ (                                        \
    4.49 -        "andl %%esp,%0; addl $4096-72,%0; movl %0,%%esp; jmp *%1" \
    4.50 -        : : "r" (~4095UL), "r" (unlikely(is_idle_task((_p))) ?    \
    4.51 +        "andl %%esp,%0; addl %2,%0; movl %0,%%esp; jmp *%1"       \
    4.52 +        : : "r" (~(STACK_SIZE-1)),                                \
    4.53 +            "r" (unlikely(is_idle_task((_p))) ?                   \
    4.54                                  continue_cpu_idle_loop :          \
    4.55 -                                continue_nonidle_task) )
    4.56 +                                continue_nonidle_task),           \
    4.57 +            "i" (STACK_SIZE-STACK_RESERVED) )
    4.58  
    4.59  
    4.60  #endif /* !(_I386_CURRENT_H) */
     5.1 --- a/xen/include/xeno/config.h	Wed Jan 28 18:29:04 2004 +0000
     5.2 +++ b/xen/include/xeno/config.h	Fri Jan 30 15:41:36 2004 +0000
     5.3 @@ -148,6 +148,7 @@
     5.4  #ifndef NDEBUG
     5.5  #define DPRINTK(_f, _a...) printk("(file=%s, line=%d) " _f, \
     5.6                             __FILE__, __LINE__, ## _a)
     5.7 +#define STACK_GUARD
     5.8  #else
     5.9  #define DPRINTK(_f, _a...) ((void)0)
    5.10  #endif
     6.1 --- a/xen/include/xeno/sched.h	Wed Jan 28 18:29:04 2004 +0000
     6.2 +++ b/xen/include/xeno/sched.h	Fri Jan 30 15:41:36 2004 +0000
     6.3 @@ -7,7 +7,6 @@
     6.4  #include <asm/ptrace.h>
     6.5  #include <xeno/smp.h>
     6.6  #include <asm/processor.h>
     6.7 -#include <asm/current.h>
     6.8  #include <hypervisor-ifs/hypervisor-if.h>
     6.9  #include <hypervisor-ifs/dom0_ops.h>
    6.10  
    6.11 @@ -17,6 +16,9 @@
    6.12  #include <xeno/delay.h>
    6.13  #include <xeno/rbtree.h>
    6.14  
    6.15 +#define STACK_SIZE (2*PAGE_SIZE)
    6.16 +#include <asm/current.h>
    6.17 +
    6.18  #define MAX_DOMAIN_NAME 16
    6.19  
    6.20  extern unsigned long volatile jiffies;
    6.21 @@ -190,8 +192,6 @@ extern struct task_struct *idle_task[NR_
    6.22  #define IDLE_DOMAIN_ID   (~0)
    6.23  #define is_idle_task(_p) ((_p)->domain == IDLE_DOMAIN_ID)
    6.24  
    6.25 -#define STACK_SIZE PAGE_SIZE
    6.26 -
    6.27  #include <xeno/slab.h>
    6.28  
    6.29  extern kmem_cache_t *task_struct_cachep;