direct-io.hg

changeset 5011:9263f821935a

bitkeeper revision 1.1466.1.1 (428cceb2sTCzL9rItLSMlnmH9XrnTQ)

Ensure correct alignment of CPU0 stack -- it must be aligned on a
2^STACK_ORDER page boundary. This requirement is now also checked
at run-time, and a clear fatal error given if it is not satisfied.
This bug affected both x86/32 and x86/64.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu May 19 17:36:50 2005 +0000 (2005-05-19)
parents 8ec7db262b48
children a2e566c5cc72 d1e3efb12a27 5ef9c0cafc1f
files xen/arch/x86/boot/x86_32.S xen/arch/x86/boot/x86_64.S xen/arch/x86/setup.c
line diff
     1.1 --- a/xen/arch/x86/boot/x86_32.S	Thu May 19 15:24:35 2005 +0000
     1.2 +++ b/xen/arch/x86/boot/x86_32.S	Thu May 19 17:36:50 2005 +0000
     1.3 @@ -212,9 +212,13 @@ ENTRY(gdt_table)
     1.4          .fill 2*NR_CPUS,8,0          /* space for TSS and LDT per CPU    */
     1.5  
     1.6          .org 0x2000
     1.7 -ENTRY(idle_pg_table) # Initial page directory is 4kB
     1.8 -        .org 0x3000
     1.9 +/* Maximum STACK_ORDER for x86/32 is 1. We must therefore ensure that the */
    1.10 +/* CPU0 stack is aligned on an even page boundary!                        */
    1.11  ENTRY(cpu0_stack)
    1.12 -        .org 0x3000 + STACK_SIZE
    1.13 +
    1.14 +        .org 0x2000 + STACK_SIZE
    1.15 +ENTRY(idle_pg_table)
    1.16 +
    1.17 +        .org 0x2000 + STACK_SIZE + PAGE_SIZE
    1.18  ENTRY(stext)
    1.19  ENTRY(_stext)
     2.1 --- a/xen/arch/x86/boot/x86_64.S	Thu May 19 15:24:35 2005 +0000
     2.2 +++ b/xen/arch/x86/boot/x86_64.S	Thu May 19 17:36:50 2005 +0000
     2.3 @@ -243,8 +243,13 @@ ENTRY(idle_pg_table_4)
     2.4  ENTRY(idle_pg_table_l3)
     2.5          .quad idle_pg_table_l2 - __PAGE_OFFSET + 7
     2.6  
     2.7 +        .org 0x4000
     2.8 +/* Maximum STACK_ORDER for x86/64 is 2. We must therefore ensure that the */
     2.9 +/* CPU0 stack is aligned on a 4-page boundary.                            */
    2.10 +ENTRY(cpu0_stack)
    2.11 +
    2.12  /* Initial PDE -- level-2 page table. Maps first 64MB physical memory. */
    2.13 -        .org 0x4000
    2.14 +        .org 0x4000 + STACK_SIZE
    2.15  ENTRY(idle_pg_table_l2)
    2.16          .macro identmap from=0, count=32
    2.17          .if \count-1
    2.18 @@ -256,10 +261,7 @@ ENTRY(idle_pg_table_l2)
    2.19          .endm
    2.20          identmap /* Too orangey for crows :-) */
    2.21  
    2.22 -        .org 0x5000
    2.23 -ENTRY(cpu0_stack)
    2.24 -
    2.25 -        .org 0x5000 + STACK_SIZE
    2.26 +        .org 0x4000 + STACK_SIZE + PAGE_SIZE
    2.27          .code64
    2.28  ENTRY(stext)
    2.29  ENTRY(_stext)
     3.1 --- a/xen/arch/x86/setup.c	Thu May 19 15:24:35 2005 +0000
     3.2 +++ b/xen/arch/x86/setup.c	Thu May 19 17:36:50 2005 +0000
     3.3 @@ -69,6 +69,8 @@ extern void ac_timer_init(void);
     3.4  extern void initialize_keytable();
     3.5  extern int do_timer_lists_from_pit;
     3.6  
     3.7 +extern unsigned long cpu0_stack[];
     3.8 +
     3.9  struct cpuinfo_x86 boot_cpu_data = { 0, 0, 0, 0, -1 };
    3.10  
    3.11  #if defined(CONFIG_X86_64)
    3.12 @@ -381,11 +383,8 @@ static void __init do_initcalls(void)
    3.13  
    3.14  static void __init start_of_day(void)
    3.15  {
    3.16 -#ifdef MEMORY_GUARD
    3.17      /* Unmap the first page of CPU0's stack. */
    3.18 -    extern unsigned long cpu0_stack[];
    3.19      memguard_guard_stack(cpu0_stack);
    3.20 -#endif
    3.21  
    3.22      open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period);
    3.23  
    3.24 @@ -469,6 +468,8 @@ static void __init start_of_day(void)
    3.25  #endif
    3.26  }
    3.27  
    3.28 +#define EARLY_FAIL() for ( ; ; ) __asm__ __volatile__ ( "hlt" )
    3.29 +
    3.30  void __init __start_xen(multiboot_info_t *mbi)
    3.31  {
    3.32      char *cmdline;
    3.33 @@ -495,7 +496,13 @@ void __init __start_xen(multiboot_info_t
    3.34      if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
    3.35      {
    3.36          printk("FATAL ERROR: Require at least one Multiboot module.\n");
    3.37 -        for ( ; ; ) ;
    3.38 +        EARLY_FAIL();
    3.39 +    }
    3.40 +
    3.41 +    if ( ((unsigned long)cpu0_stack & (STACK_SIZE-1)) != 0 )
    3.42 +    {
    3.43 +        printk("FATAL ERROR: Misaligned CPU0 stack.\n");
    3.44 +        EARLY_FAIL();
    3.45      }
    3.46  
    3.47      xenheap_phys_end = opt_xenheap_megabytes << 20;