ia64/xen-unstable

changeset 3686:253e8e10e986

bitkeeper revision 1.1159.212.105 (420666bemy1hHhMRPUknF0p3-jxn_w)

x86/64 debug builds use guard pages in unallocated heap space and for
stack-limit enforcement.
Signed-off-by: keir.fraser@cl.cam.ac.uk
author kaf24@viper.(none)
date Sun Feb 06 18:49:34 2005 +0000 (2005-02-06)
parents f4eb69e2ad9e
children 7db5b671b347
files xen/arch/x86/boot/x86_32.S xen/arch/x86/boot/x86_64.S xen/arch/x86/setup.c xen/arch/x86/smpboot.c xen/arch/x86/x86_32/mm.c xen/arch/x86/x86_32/traps.c xen/arch/x86/x86_64/entry.S xen/arch/x86/x86_64/mm.c xen/arch/x86/x86_64/traps.c xen/include/asm-x86/config.h xen/include/asm-x86/mm.h xen/include/asm-x86/page.h xen/include/xen/sched.h
line diff
     1.1 --- a/xen/arch/x86/boot/x86_32.S	Sun Feb 06 12:48:31 2005 +0000
     1.2 +++ b/xen/arch/x86/boot/x86_32.S	Sun Feb 06 18:49:34 2005 +0000
     1.3 @@ -169,7 +169,7 @@ 1:      jmp     1b
     1.4  /*** STACK LOCATION ***/
     1.5          
     1.6  ENTRY(stack_start)
     1.7 -        .long SYMBOL_NAME(cpu0_stack) + 8100 - __PAGE_OFFSET
     1.8 +        .long SYMBOL_NAME(cpu0_stack) + STACK_SIZE - 200 - __PAGE_OFFSET
     1.9          .long __HYPERVISOR_DS
    1.10          
    1.11  /*** DESCRIPTOR TABLES ***/
     2.1 --- a/xen/arch/x86/boot/x86_64.S	Sun Feb 06 12:48:31 2005 +0000
     2.2 +++ b/xen/arch/x86/boot/x86_64.S	Sun Feb 06 18:49:34 2005 +0000
     2.3 @@ -211,7 +211,7 @@ SYMBOL_NAME(idt):
     2.4          .quad   SYMBOL_NAME(idt_table)
     2.5  
     2.6  ENTRY(stack_start)
     2.7 -        .quad   SYMBOL_NAME(cpu0_stack) + 8000
     2.8 +        .quad   SYMBOL_NAME(cpu0_stack) + STACK_SIZE - 200
     2.9  
    2.10  high_start:
    2.11          .quad   __high_start
     3.1 --- a/xen/arch/x86/setup.c	Sun Feb 06 12:48:31 2005 +0000
     3.2 +++ b/xen/arch/x86/setup.c	Sun Feb 06 18:49:34 2005 +0000
     3.3 @@ -360,7 +360,7 @@ static void __init start_of_day(void)
     3.4  #ifdef MEMORY_GUARD
     3.5      /* Unmap the first page of CPU0's stack. */
     3.6      extern unsigned long cpu0_stack[];
     3.7 -    memguard_guard_range(cpu0_stack, PAGE_SIZE);
     3.8 +    memguard_guard_stack(cpu0_stack);
     3.9  #endif
    3.10  
    3.11      open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period);
     4.1 --- a/xen/arch/x86/smpboot.c	Sun Feb 06 12:48:31 2005 +0000
     4.2 +++ b/xen/arch/x86/smpboot.c	Sun Feb 06 18:49:34 2005 +0000
     4.3 @@ -675,7 +675,7 @@ static void __init do_boot_cpu (int apic
     4.4      /* So we see what's up. */
     4.5      printk("Booting processor %d/%d eip %lx\n", cpu, apicid, start_eip);
     4.6  
     4.7 -    stack = (void *)alloc_xenheap_pages(1);
     4.8 +    stack = (void *)alloc_xenheap_pages(STACK_ORDER);
     4.9  #if defined(__i386__)
    4.10      stack_start.esp = __pa(stack) + STACK_SIZE - STACK_RESERVED;
    4.11  #elif defined(__x86_64__)
    4.12 @@ -683,7 +683,7 @@ static void __init do_boot_cpu (int apic
    4.13  #endif
    4.14  
    4.15      /* Debug build: detect stack overflow by setting up a guard page. */
    4.16 -    memguard_guard_range(stack, PAGE_SIZE);
    4.17 +    memguard_guard_stack(stack);
    4.18  
    4.19      /*
    4.20       * This grunge runs the startup process for
     5.1 --- a/xen/arch/x86/x86_32/mm.c	Sun Feb 06 12:48:31 2005 +0000
     5.2 +++ b/xen/arch/x86/x86_32/mm.c	Sun Feb 06 18:49:34 2005 +0000
     5.3 @@ -532,6 +532,11 @@ static void __memguard_change_range(void
     5.4      }
     5.5  }
     5.6  
     5.7 +void memguard_guard_stack(void *p)
     5.8 +{
     5.9 +    memguard_guard_range(p, PAGE_SIZE);
    5.10 +}
    5.11 +
    5.12  void memguard_guard_range(void *p, unsigned long l)
    5.13  {
    5.14      __memguard_change_range(p, l, 1);
     6.1 --- a/xen/arch/x86/x86_32/traps.c	Sun Feb 06 12:48:31 2005 +0000
     6.2 +++ b/xen/arch/x86/x86_32/traps.c	Sun Feb 06 18:49:34 2005 +0000
     6.3 @@ -149,6 +149,8 @@ asmlinkage void do_double_fault(void)
     6.4      /* Disable the NMI watchdog. It's useless now. */
     6.5      watchdog_on = 0;
     6.6  
     6.7 +    console_force_unlock();
     6.8 +
     6.9      /* Find information saved during fault and dump it to the console. */
    6.10      tss = &init_tss[cpu];
    6.11      printk("CPU:    %d\nEIP:    %04x:[<%08x>]      \nEFLAGS: %08x\n",
     7.1 --- a/xen/arch/x86/x86_64/entry.S	Sun Feb 06 12:48:31 2005 +0000
     7.2 +++ b/xen/arch/x86/x86_64/entry.S	Sun Feb 06 18:49:34 2005 +0000
     7.3 @@ -133,7 +133,7 @@ ENTRY(double_fault)
     7.4          jmp   error_code
     7.5  
     7.6  ENTRY(nmi)
     7.7 -        iret
     7.8 +        iretq
     7.9  
    7.10  .data
    7.11  
     8.1 --- a/xen/arch/x86/x86_64/mm.c	Sun Feb 06 12:48:31 2005 +0000
     8.2 +++ b/xen/arch/x86/x86_64/mm.c	Sun Feb 06 18:49:34 2005 +0000
     8.3 @@ -495,18 +495,19 @@ long do_update_descriptor(
     8.4  
     8.5  #ifdef MEMORY_GUARD
     8.6  
     8.7 -#if 1
     8.8 -
     8.9 -void *memguard_init(void *heap_start) { return heap_start; }
    8.10 -void memguard_guard_range(void *p, unsigned long l) {}
    8.11 -void memguard_unguard_range(void *p, unsigned long l) {}
    8.12 -
    8.13 -#else
    8.14 -
    8.15 +#define ALLOC_PT(_level) \
    8.16 +do { \
    8.17 +    (_level) = (_level ## _pgentry_t *)heap_start; \
    8.18 +    heap_start = (void *)((unsigned long)heap_start + PAGE_SIZE); \
    8.19 +    clear_page(_level); \
    8.20 +} while ( 0 )
    8.21  void *memguard_init(void *heap_start)
    8.22  {
    8.23 -    l1_pgentry_t *l1;
    8.24 -    int i, j;
    8.25 +    l1_pgentry_t *l1 = NULL;
    8.26 +    l2_pgentry_t *l2 = NULL;
    8.27 +    l3_pgentry_t *l3 = NULL;
    8.28 +    l4_pgentry_t *l4 = &idle_pg_table[l4_table_offset(PAGE_OFFSET)];
    8.29 +    unsigned long i, j;
    8.30  
    8.31      /* Round the allocation pointer up to a page boundary. */
    8.32      heap_start = (void *)(((unsigned long)heap_start + (PAGE_SIZE-1)) & 
    8.33 @@ -515,14 +516,22 @@ void *memguard_init(void *heap_start)
    8.34      /* Memory guarding is incompatible with super pages. */
    8.35      for ( i = 0; i < (xenheap_phys_end >> L2_PAGETABLE_SHIFT); i++ )
    8.36      {
    8.37 -        l1 = (l1_pgentry_t *)heap_start;
    8.38 -        heap_start = (void *)((unsigned long)heap_start + PAGE_SIZE);
    8.39 +        ALLOC_PT(l1);
    8.40          for ( j = 0; j < ENTRIES_PER_L1_PAGETABLE; j++ )
    8.41              l1[j] = mk_l1_pgentry((i << L2_PAGETABLE_SHIFT) |
    8.42                                     (j << L1_PAGETABLE_SHIFT) | 
    8.43                                    __PAGE_HYPERVISOR);
    8.44 -        idle_pg_table[i] = idle_pg_table[i + l2_table_offset(PAGE_OFFSET)] =
    8.45 -            mk_l2_pgentry(virt_to_phys(l1) | __PAGE_HYPERVISOR);
    8.46 +        if ( !((unsigned long)l2 & (PAGE_SIZE-1)) )
    8.47 +        {
    8.48 +            ALLOC_PT(l2);
    8.49 +            if ( !((unsigned long)l3 & (PAGE_SIZE-1)) )
    8.50 +            {
    8.51 +                ALLOC_PT(l3);
    8.52 +                *l4++ = mk_l4_pgentry(virt_to_phys(l3) | __PAGE_HYPERVISOR);
    8.53 +            }
    8.54 +            *l3++ = mk_l3_pgentry(virt_to_phys(l2) | __PAGE_HYPERVISOR);
    8.55 +        }
    8.56 +        *l2++ = mk_l2_pgentry(virt_to_phys(l1) | __PAGE_HYPERVISOR);
    8.57      }
    8.58  
    8.59      return heap_start;
    8.60 @@ -532,6 +541,8 @@ static void __memguard_change_range(void
    8.61  {
    8.62      l1_pgentry_t *l1;
    8.63      l2_pgentry_t *l2;
    8.64 +    l3_pgentry_t *l3;
    8.65 +    l4_pgentry_t *l4;
    8.66      unsigned long _p = (unsigned long)p;
    8.67      unsigned long _l = (unsigned long)l;
    8.68  
    8.69 @@ -543,8 +554,10 @@ static void __memguard_change_range(void
    8.70  
    8.71      while ( _l != 0 )
    8.72      {
    8.73 -        l2  = &idle_pg_table[l2_table_offset(_p)];
    8.74 -        l1  = l2_pgentry_to_l1(*l2) + l1_table_offset(_p);
    8.75 +        l4 = &idle_pg_table[l4_table_offset(_p)];
    8.76 +        l3 = l4_pgentry_to_l3(*l4) + l3_table_offset(_p);
    8.77 +        l2 = l3_pgentry_to_l2(*l3) + l2_table_offset(_p);
    8.78 +        l1 = l2_pgentry_to_l1(*l2) + l1_table_offset(_p);
    8.79          if ( guard )
    8.80              *l1 = mk_l1_pgentry(l1_pgentry_val(*l1) & ~_PAGE_PRESENT);
    8.81          else
    8.82 @@ -554,6 +567,12 @@ static void __memguard_change_range(void
    8.83      }
    8.84  }
    8.85  
    8.86 +void memguard_guard_stack(void *p)
    8.87 +{
    8.88 +    p = (void *)((unsigned long)p + PAGE_SIZE);
    8.89 +    memguard_guard_range(p, 2 * PAGE_SIZE);
    8.90 +}
    8.91 +
    8.92  void memguard_guard_range(void *p, unsigned long l)
    8.93  {
    8.94      __memguard_change_range(p, l, 1);
    8.95 @@ -566,5 +585,3 @@ void memguard_unguard_range(void *p, uns
    8.96  }
    8.97  
    8.98  #endif
    8.99 -
   8.100 -#endif
     9.1 --- a/xen/arch/x86/x86_64/traps.c	Sun Feb 06 12:48:31 2005 +0000
     9.2 +++ b/xen/arch/x86/x86_64/traps.c	Sun Feb 06 18:49:34 2005 +0000
     9.3 @@ -138,6 +138,8 @@ asmlinkage void do_double_fault(struct x
     9.4      /* Disable the NMI watchdog. It's useless now. */
     9.5      watchdog_on = 0;
     9.6  
     9.7 +    console_force_unlock();
     9.8 +
     9.9      /* Find information saved during fault and dump it to the console. */
    9.10      printk("************************************\n");
    9.11      printk("EIP:    %04lx:[<%p>]      \nEFLAGS: %p\n",
    10.1 --- a/xen/include/asm-x86/config.h	Sun Feb 06 12:48:31 2005 +0000
    10.2 +++ b/xen/include/asm-x86/config.h	Sun Feb 06 18:49:34 2005 +0000
    10.3 @@ -83,7 +83,15 @@
    10.4  
    10.5  #ifndef NDEBUG
    10.6  #define MEMORY_GUARD
    10.7 +#ifdef __x86_64__
    10.8 +#define STACK_ORDER 2
    10.9  #endif
   10.10 +#endif
   10.11 +
   10.12 +#ifndef STACK_ORDER
   10.13 +#define STACK_ORDER 1
   10.14 +#endif
   10.15 +#define STACK_SIZE  (PAGE_SIZE << STACK_ORDER)
   10.16  
   10.17  #ifndef __ASSEMBLY__
   10.18  extern unsigned long _end; /* standard ELF symbol */
    11.1 --- a/xen/include/asm-x86/mm.h	Sun Feb 06 12:48:31 2005 +0000
    11.2 +++ b/xen/include/asm-x86/mm.h	Sun Feb 06 18:49:34 2005 +0000
    11.3 @@ -250,10 +250,12 @@ void synchronise_pagetables(unsigned lon
    11.4  
    11.5  #ifdef MEMORY_GUARD
    11.6  void *memguard_init(void *heap_start);
    11.7 +void memguard_guard_stack(void *p);
    11.8  void memguard_guard_range(void *p, unsigned long l);
    11.9  void memguard_unguard_range(void *p, unsigned long l);
   11.10  #else
   11.11  #define memguard_init(_s)              (_s)
   11.12 +#define memguard_guard_stack(_p)       ((void)0)
   11.13  #define memguard_guard_range(_p,_l)    ((void)0)
   11.14  #define memguard_unguard_range(_p,_l)  ((void)0)
   11.15  #endif
    12.1 --- a/xen/include/asm-x86/page.h	Sun Feb 06 12:48:31 2005 +0000
    12.2 +++ b/xen/include/asm-x86/page.h	Sun Feb 06 18:49:34 2005 +0000
    12.3 @@ -34,7 +34,11 @@
    12.4  #endif
    12.5  
    12.6  #define PAGE_SHIFT               L1_PAGETABLE_SHIFT
    12.7 +#ifndef __ASSEMBLY__
    12.8  #define PAGE_SIZE	         (1UL << PAGE_SHIFT)
    12.9 +#else
   12.10 +#define PAGE_SIZE	         (1 << PAGE_SHIFT)
   12.11 +#endif
   12.12  #define PAGE_MASK	         (~(PAGE_SIZE-1))
   12.13  
   12.14  #define clear_page(_p)           memset((void *)(_p), 0, PAGE_SIZE)
    13.1 --- a/xen/include/xen/sched.h	Sun Feb 06 12:48:31 2005 +0000
    13.2 +++ b/xen/include/xen/sched.h	Sun Feb 06 18:49:34 2005 +0000
    13.3 @@ -3,8 +3,6 @@
    13.4  #ifndef __SCHED_H__
    13.5  #define __SCHED_H__
    13.6  
    13.7 -#define STACK_SIZE (2*PAGE_SIZE)
    13.8 -
    13.9  #include <xen/config.h>
   13.10  #include <xen/types.h>
   13.11  #include <xen/spinlock.h>