ia64/xen-unstable

changeset 19055:845aa241e163

x86_64: Remove statically-partitioned Xen heap.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jan 16 15:12:12 2009 +0000 (2009-01-16)
parents ba7ed03a3f79
children 3c9b66b1798d
files xen/arch/ia64/xen/machine_kexec.c xen/arch/x86/machine_kexec.c xen/arch/x86/mm.c xen/arch/x86/setup.c xen/arch/x86/x86_32/machine_kexec.c xen/arch/x86/x86_64/machine_kexec.c xen/common/kexec.c xen/common/page_alloc.c xen/include/asm-x86/config.h xen/include/asm-x86/mm.h
line diff
     1.1 --- a/xen/arch/ia64/xen/machine_kexec.c	Fri Jan 16 13:17:53 2009 +0000
     1.2 +++ b/xen/arch/ia64/xen/machine_kexec.c	Fri Jan 16 15:12:12 2009 +0000
     1.3 @@ -195,6 +195,7 @@ int machine_kexec_get(xen_kexec_range_t 
     1.4  
     1.5  void arch_crash_save_vmcoreinfo(void)
     1.6  {
     1.7 +    VMCOREINFO_SYMBOL(xenheap_phys_end);
     1.8  	VMCOREINFO_SYMBOL(dom_xen);
     1.9  	VMCOREINFO_SYMBOL(dom_io);
    1.10  	VMCOREINFO_SYMBOL(xen_pstart);
     2.1 --- a/xen/arch/x86/machine_kexec.c	Fri Jan 16 13:17:53 2009 +0000
     2.2 +++ b/xen/arch/x86/machine_kexec.c	Fri Jan 16 15:12:12 2009 +0000
     2.3 @@ -150,6 +150,9 @@ void arch_crash_save_vmcoreinfo(void)
     2.4  	VMCOREINFO_SYMBOL(dom_xen);
     2.5  	VMCOREINFO_SYMBOL(dom_io);
     2.6  
     2.7 +#ifdef CONFIG_X86_32
     2.8 +    VMCOREINFO_SYMBOL(xenheap_phys_end);
     2.9 +#endif
    2.10  #ifdef CONFIG_X86_PAE
    2.11  	VMCOREINFO_SYMBOL_ALIAS(pgd_l3, idle_pg_table);
    2.12  #endif
     3.1 --- a/xen/arch/x86/mm.c	Fri Jan 16 13:17:53 2009 +0000
     3.2 +++ b/xen/arch/x86/mm.c	Fri Jan 16 15:12:12 2009 +0000
     3.3 @@ -329,7 +329,7 @@ void share_xen_page_with_guest(
     3.4  
     3.5      page_set_owner(page, d);
     3.6      wmb(); /* install valid domain ptr before updating refcnt. */
     3.7 -    ASSERT(page->count_info == 0);
     3.8 +    ASSERT((page->count_info & (PGC_allocated|PGC_count_mask)) == 0);
     3.9  
    3.10      /* Only add to the allocation list if the domain isn't dying. */
    3.11      if ( !d->is_dying )
    3.12 @@ -4722,12 +4722,18 @@ void __set_fixmap(
    3.13  void memguard_init(void)
    3.14  {
    3.15      unsigned long start = max_t(unsigned long, xen_phys_start, 1UL << 20);
    3.16 +#ifdef __i386__
    3.17      map_pages_to_xen(
    3.18          (unsigned long)__va(start),
    3.19          start >> PAGE_SHIFT,
    3.20          (xenheap_phys_end - start) >> PAGE_SHIFT,
    3.21          __PAGE_HYPERVISOR|MAP_SMALL_PAGES);
    3.22 -#ifdef __x86_64__
    3.23 +#else
    3.24 +    map_pages_to_xen(
    3.25 +        (unsigned long)__va(start),
    3.26 +        start >> PAGE_SHIFT,
    3.27 +        (__pa(&_end) + PAGE_SIZE - 1 - start) >> PAGE_SHIFT,
    3.28 +        __PAGE_HYPERVISOR|MAP_SMALL_PAGES);
    3.29      BUG_ON(start != xen_phys_start);
    3.30      map_pages_to_xen(
    3.31          XEN_VIRT_START,
     4.1 --- a/xen/arch/x86/setup.c	Fri Jan 16 13:17:53 2009 +0000
     4.2 +++ b/xen/arch/x86/setup.c	Fri Jan 16 15:12:12 2009 +0000
     4.3 @@ -54,15 +54,6 @@ extern u16 boot_edid_caps;
     4.4  extern u8 boot_edid_info[128];
     4.5  extern struct boot_video_info boot_vid_info;
     4.6  
     4.7 -/*
     4.8 - * opt_xenheap_megabytes: Size of Xen heap in megabytes, excluding the
     4.9 - * page_info table and allocation bitmap.
    4.10 - */
    4.11 -static unsigned int opt_xenheap_megabytes = XENHEAP_DEFAULT_MB;
    4.12 -#if defined(CONFIG_X86_64)
    4.13 -integer_param("xenheap_megabytes", opt_xenheap_megabytes);
    4.14 -#endif
    4.15 -
    4.16  /* opt_nosmp: If true, secondary processors are ignored. */
    4.17  static int opt_nosmp = 0;
    4.18  boolean_param("nosmp", opt_nosmp);
    4.19 @@ -105,8 +96,10 @@ cpumask_t cpu_present_map;
    4.20  
    4.21  unsigned long xen_phys_start;
    4.22  
    4.23 +#ifdef CONFIG_X86_32
    4.24  /* Limits of Xen heap, used to initialise the allocator. */
    4.25  unsigned long xenheap_phys_start, xenheap_phys_end;
    4.26 +#endif
    4.27  
    4.28  extern void arch_init_memory(void);
    4.29  extern void init_IRQ(void);
    4.30 @@ -421,6 +414,7 @@ void __init __start_xen(unsigned long mb
    4.31      multiboot_info_t *mbi = __va(mbi_p);
    4.32      module_t *mod = (module_t *)__va(mbi->mods_addr);
    4.33      unsigned long nr_pages, modules_length;
    4.34 +    unsigned long allocator_bitmap_end;
    4.35      int i, e820_warn = 0, bytes = 0;
    4.36      struct ns16550_defaults ns16550 = {
    4.37          .data_bits = 8,
    4.38 @@ -599,23 +593,6 @@ void __init __start_xen(unsigned long mb
    4.39      /* Sanitise the raw E820 map to produce a final clean version. */
    4.40      max_page = init_e820(memmap_type, e820_raw, &e820_raw_nr);
    4.41  
    4.42 -#ifdef CONFIG_X86_64
    4.43 -    /*
    4.44 -     * On x86/64 we are able to account for the allocation bitmap
    4.45 -     * (allocated in common/page_alloc.c:init_boot_allocator()) stealing
    4.46 -     * from the Xen heap. Here we make the Xen heap appropriately larger.
    4.47 -     */
    4.48 -    opt_xenheap_megabytes += (max_page / 8) >> 20;
    4.49 -#endif
    4.50 -
    4.51 -    /*
    4.52 -     * Since there are some stubs getting built on the stacks which use
    4.53 -     * direct calls/jumps, the heap must be confined to the lower 2G so
    4.54 -     * that those branches can reach their targets.
    4.55 -     */
    4.56 -    if ( opt_xenheap_megabytes > 2048 )
    4.57 -        opt_xenheap_megabytes = 2048;
    4.58 -
    4.59      /* Create a temporary copy of the E820 map. */
    4.60      memcpy(&boot_e820, &e820, sizeof(e820));
    4.61  
    4.62 @@ -654,8 +631,9 @@ void __init __start_xen(unsigned long mb
    4.63              s >> PAGE_SHIFT, (e-s) >> PAGE_SHIFT, PAGE_HYPERVISOR);
    4.64  
    4.65  #if defined(CONFIG_X86_64)
    4.66 +#define reloc_size ((__pa(&_end) + mask) & ~mask)
    4.67          /* Is the region suitable for relocating Xen? */
    4.68 -        if ( !xen_phys_start && (((e-s) >> 20) >= opt_xenheap_megabytes) )
    4.69 +        if ( !xen_phys_start && ((e-s) >= reloc_size) )
    4.70          {
    4.71              extern l2_pgentry_t l2_xenmap[];
    4.72              l4_pgentry_t *pl4e;
    4.73 @@ -664,7 +642,7 @@ void __init __start_xen(unsigned long mb
    4.74              int i, j, k;
    4.75  
    4.76              /* Select relocation address. */
    4.77 -            e = (e - (opt_xenheap_megabytes << 20)) & ~mask;
    4.78 +            e -= reloc_size;
    4.79              xen_phys_start = e;
    4.80              bootsym(trampoline_xen_phys_start) = e;
    4.81  
    4.82 @@ -760,15 +738,15 @@ void __init __start_xen(unsigned long mb
    4.83          EARLY_FAIL("Not enough memory to relocate the dom0 kernel image.\n");
    4.84      reserve_e820_ram(&boot_e820, initial_images_start, initial_images_end);
    4.85  
    4.86 -    /* Initialise Xen heap and boot heap. */
    4.87 -    xenheap_phys_start = init_boot_allocator(__pa(&_end));
    4.88 -    xenheap_phys_end   = opt_xenheap_megabytes << 20;
    4.89 -#if defined(CONFIG_X86_64)
    4.90 +    /* Initialise boot heap. */
    4.91 +    allocator_bitmap_end = init_boot_allocator(__pa(&_end));
    4.92 +#if defined(CONFIG_X86_32)
    4.93 +    xenheap_phys_start = allocator_bitmap_end;
    4.94 +    xenheap_phys_end   = DIRECTMAP_MBYTES << 20;
    4.95 +#else
    4.96      if ( !xen_phys_start )
    4.97          EARLY_FAIL("Not enough memory to relocate Xen.\n");
    4.98 -    xenheap_phys_end += xen_phys_start;
    4.99 -    reserve_e820_ram(&boot_e820, xen_phys_start,
   4.100 -                     xen_phys_start + (opt_xenheap_megabytes<<20));
   4.101 +    reserve_e820_ram(&boot_e820, __pa(&_start), allocator_bitmap_end);
   4.102  #endif
   4.103  
   4.104      /* Late kexec reservation (dynamic start address). */
   4.105 @@ -861,22 +839,22 @@ void __init __start_xen(unsigned long mb
   4.106  
   4.107      numa_initmem_init(0, max_page);
   4.108  
   4.109 -    /* Initialise the Xen heap, skipping RAM holes. */
   4.110 +#if defined(CONFIG_X86_32)
   4.111 +    /* Initialise the Xen heap. */
   4.112      init_xenheap_pages(xenheap_phys_start, xenheap_phys_end);
   4.113      nr_pages = (xenheap_phys_end - xenheap_phys_start) >> PAGE_SHIFT;
   4.114 -#ifdef __x86_64__
   4.115 -    init_xenheap_pages(xen_phys_start, __pa(&_start));
   4.116 -    nr_pages += (__pa(&_start) - xen_phys_start) >> PAGE_SHIFT;
   4.117 -    vesa_init();
   4.118 -#endif
   4.119      xenheap_phys_start = xen_phys_start;
   4.120      printk("Xen heap: %luMB (%lukB)\n", 
   4.121             nr_pages >> (20 - PAGE_SHIFT),
   4.122             nr_pages << (PAGE_SHIFT - 10));
   4.123 +#endif
   4.124  
   4.125      end_boot_allocator();
   4.126 +    early_boot = 0;
   4.127  
   4.128 -    early_boot = 0;
   4.129 +#if defined(CONFIG_X86_64)
   4.130 +    vesa_init();
   4.131 +#endif
   4.132  
   4.133      softirq_init();
   4.134  
   4.135 @@ -1115,10 +1093,15 @@ void arch_get_xen_caps(xen_capabilities_
   4.136  
   4.137  int xen_in_range(paddr_t start, paddr_t end)
   4.138  {
   4.139 -    start = max_t(paddr_t, start, xenheap_phys_start);
   4.140 -    end = min_t(paddr_t, end, xenheap_phys_end);
   4.141 - 
   4.142 -    return start < end; 
   4.143 +#if defined(CONFIG_X86_32)
   4.144 +    paddr_t xs = xenheap_phys_start;
   4.145 +    paddr_t xe = xenheap_phys_end;
   4.146 +#else
   4.147 +    paddr_t xs = __pa(&_start);
   4.148 +    paddr_t xe = __pa(&_end);
   4.149 +#endif
   4.150 +
   4.151 +    return (start < xe) && (end > xs);
   4.152  }
   4.153  
   4.154  /*
     5.1 --- a/xen/arch/x86/x86_32/machine_kexec.c	Fri Jan 16 13:17:53 2009 +0000
     5.2 +++ b/xen/arch/x86/x86_32/machine_kexec.c	Fri Jan 16 15:12:12 2009 +0000
     5.3 @@ -6,8 +6,6 @@
     5.4   * - Magnus Damm <magnus@valinux.co.jp>
     5.5   */
     5.6  
     5.7 -#ifndef CONFIG_COMPAT
     5.8 -
     5.9  #include <xen/types.h>
    5.10  #include <xen/kernel.h>
    5.11  #include <asm/page.h>
    5.12 @@ -20,7 +18,6 @@ int machine_kexec_get_xen(xen_kexec_rang
    5.13                        (unsigned long)range->start;
    5.14          return 0;
    5.15  }
    5.16 -#endif
    5.17  
    5.18  /*
    5.19   * Local variables:
     6.1 --- a/xen/arch/x86/x86_64/machine_kexec.c	Fri Jan 16 13:17:53 2009 +0000
     6.2 +++ b/xen/arch/x86/x86_64/machine_kexec.c	Fri Jan 16 15:12:12 2009 +0000
     6.3 @@ -6,20 +6,17 @@
     6.4   * - Magnus Damm <magnus@valinux.co.jp>
     6.5   */
     6.6  
     6.7 -#ifndef CONFIG_COMPAT
     6.8 -
     6.9  #include <xen/types.h>
    6.10 +#include <xen/kernel.h>
    6.11  #include <asm/page.h>
    6.12  #include <public/kexec.h>
    6.13  
    6.14  int machine_kexec_get_xen(xen_kexec_range_t *range)
    6.15  {
    6.16 -        range->start = xenheap_phys_start;
    6.17 -        range->size = (unsigned long)xenheap_phys_end -
    6.18 -                      (unsigned long)range->start;
    6.19 +        range->start = virt_to_maddr(_start);
    6.20 +        range->size = virt_to_maddr(_end) - (unsigned long)range->start;
    6.21          return 0;
    6.22  }
    6.23 -#endif
    6.24  
    6.25  /*
    6.26   * Local variables:
     7.1 --- a/xen/common/kexec.c	Fri Jan 16 13:17:53 2009 +0000
     7.2 +++ b/xen/common/kexec.c	Fri Jan 16 15:12:12 2009 +0000
     7.3 @@ -336,7 +336,6 @@ static void crash_save_vmcoreinfo(void)
     7.4      VMCOREINFO_SYMBOL(frame_table);
     7.5      VMCOREINFO_SYMBOL(alloc_bitmap);
     7.6      VMCOREINFO_SYMBOL(max_page);
     7.7 -    VMCOREINFO_SYMBOL(xenheap_phys_end);
     7.8  
     7.9      VMCOREINFO_STRUCT_SIZE(page_info);
    7.10      VMCOREINFO_STRUCT_SIZE(domain);
     8.1 --- a/xen/common/page_alloc.c	Fri Jan 16 13:17:53 2009 +0000
     8.2 +++ b/xen/common/page_alloc.c	Fri Jan 16 15:12:12 2009 +0000
     8.3 @@ -634,6 +634,8 @@ void __init scrub_heap_pages(void)
     8.4   * XEN-HEAP SUB-ALLOCATOR
     8.5   */
     8.6  
     8.7 +#ifndef __x86_64__
     8.8 +
     8.9  void init_xenheap_pages(paddr_t ps, paddr_t pe)
    8.10  {
    8.11      ps = round_pgup(ps);
    8.12 @@ -689,6 +691,55 @@ void free_xenheap_pages(void *v, unsigne
    8.13      free_heap_pages(MEMZONE_XEN, virt_to_page(v), order);
    8.14  }
    8.15  
    8.16 +#else
    8.17 +
    8.18 +void init_xenheap_pages(paddr_t ps, paddr_t pe)
    8.19 +{
    8.20 +    init_domheap_pages(ps, pe);
    8.21 +}
    8.22 +
    8.23 +void *alloc_xenheap_pages(unsigned int order)
    8.24 +{
    8.25 +    struct page_info *pg;
    8.26 +    unsigned int i;
    8.27 +
    8.28 +    ASSERT(!in_irq());
    8.29 +
    8.30 +    pg = alloc_heap_pages(
    8.31 +        MEMZONE_XEN+1, 31, cpu_to_node(smp_processor_id()), order);
    8.32 +    if ( unlikely(pg == NULL) )
    8.33 +        goto no_memory;
    8.34 +
    8.35 +    for ( i = 0; i < (1u << order); i++ )
    8.36 +        pg[i].count_info |= PGC_xen_heap;
    8.37 +
    8.38 +    return page_to_virt(pg);
    8.39 +
    8.40 + no_memory:
    8.41 +    printk("Cannot handle page request order %d!\n", order);
    8.42 +    return NULL;
    8.43 +}
    8.44 +
    8.45 +void free_xenheap_pages(void *v, unsigned int order)
    8.46 +{
    8.47 +    struct page_info *pg;
    8.48 +    unsigned int i;
    8.49 +
    8.50 +    ASSERT(!in_irq());
    8.51 +
    8.52 +    if ( v == NULL )
    8.53 +        return;
    8.54 +
    8.55 +    pg = virt_to_page(v);
    8.56 +
    8.57 +    for ( i = 0; i < (1u << order); i++ )
    8.58 +        pg[i].count_info &= ~PGC_xen_heap;
    8.59 +
    8.60 +    free_heap_pages(pfn_dom_zone_type(page_to_mfn(pg)), pg, order);
    8.61 +}
    8.62 +
    8.63 +#endif
    8.64 +
    8.65  
    8.66  
    8.67  /*************************
     9.1 --- a/xen/include/asm-x86/config.h	Fri Jan 16 13:17:53 2009 +0000
     9.2 +++ b/xen/include/asm-x86/config.h	Fri Jan 16 15:12:12 2009 +0000
     9.3 @@ -117,8 +117,6 @@ extern unsigned int video_mode, video_fl
     9.4  
     9.5  #define asmlinkage
     9.6  
     9.7 -#define XENHEAP_DEFAULT_MB (16)
     9.8 -
     9.9  #define PML4_ENTRY_BITS  39
    9.10  #ifndef __ASSEMBLY__
    9.11  #define PML4_ENTRY_BYTES (1UL << PML4_ENTRY_BITS)
    9.12 @@ -310,7 +308,6 @@ extern unsigned int video_mode, video_fl
    9.13  #define RO_MPT_VIRT_END		FRAMETABLE_VIRT_START
    9.14  #define RO_MPT_VIRT_START	(RO_MPT_VIRT_END - (MACHPHYS_MBYTES<<20))
    9.15  
    9.16 -#define XENHEAP_DEFAULT_MB	(DIRECTMAP_MBYTES)
    9.17  #define DIRECTMAP_PHYS_END	(DIRECTMAP_MBYTES<<20)
    9.18  
    9.19  /* Maximum linear address accessible via guest memory segments. */
    9.20 @@ -340,7 +337,10 @@ extern unsigned int video_mode, video_fl
    9.21  #endif /* __i386__ */
    9.22  
    9.23  #ifndef __ASSEMBLY__
    9.24 -extern unsigned long xen_phys_start, xenheap_phys_start, xenheap_phys_end;
    9.25 +extern unsigned long xen_phys_start;
    9.26 +#if defined(__i386__)
    9.27 +extern unsigned long xenheap_phys_start, xenheap_phys_end;
    9.28 +#endif
    9.29  #endif
    9.30  
    9.31  /* GDT/LDT shadow mapping area. The first per-domain-mapping sub-area. */
    10.1 --- a/xen/include/asm-x86/mm.h	Fri Jan 16 13:17:53 2009 +0000
    10.2 +++ b/xen/include/asm-x86/mm.h	Fri Jan 16 15:12:12 2009 +0000
    10.3 @@ -135,6 +135,10 @@ struct page_info
    10.4   /* Page is locked? */
    10.5  # define _PGC_locked        30
    10.6  # define PGC_locked         (1U<<_PGC_out_of_sync)
    10.7 +#else
    10.8 + /* Page is Xen heap? */
    10.9 +# define _PGC_xen_heap      30
   10.10 +# define PGC_xen_heap       (1U<<_PGC_xen_heap)
   10.11  #endif
   10.12   /* Set when is using a page as a page table */
   10.13  #define _PGC_page_table     29
   10.14 @@ -145,12 +149,17 @@ struct page_info
   10.15   /* 26-bit count of references to this frame. */
   10.16  #define PGC_count_mask      ((1U<<26)-1)
   10.17  
   10.18 +#if defined(__i386__)
   10.19  #define is_xen_heap_page(page) is_xen_heap_mfn(page_to_mfn(page))
   10.20  #define is_xen_heap_mfn(mfn) ({                         \
   10.21      unsigned long _mfn = (mfn);                         \
   10.22      ((_mfn >= paddr_to_pfn(xenheap_phys_start)) &&      \
   10.23       (_mfn < paddr_to_pfn(xenheap_phys_end)));          \
   10.24  })
   10.25 +#else
   10.26 +#define is_xen_heap_page(page) ((page)->count_info & PGC_xen_heap)
   10.27 +#define is_xen_heap_mfn(mfn) is_xen_heap_page(&frame_table[mfn])
   10.28 +#endif
   10.29  
   10.30  #if defined(__i386__)
   10.31  #define pickle_domptr(_d)   ((u32)(unsigned long)(_d))