From: "Jan Beulich" Subject: [PATCH 1/2] x86: do away with the boot time low-memory 1:1 mapping Date: Tue, 09 Nov 2010 11:21:48 +0000 Message-ID: <4CD93CDC02000078000211E1@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part0F2297DC.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part0F2297DC.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline By doing so, we're no longer restricted to be able to place all boot loader modules into the low 1Gb/4Gb (32-/64-bit) of memory, nor is there a dependency anymore on where the boot loader places the modules. We're also no longer restricted to copy the modules into a place below 4Gb, nor to put them all together into a single piece of memory. Further it allows even the 32-bit Dom0 kernel to be loaded anywhere in physical memory (except if it doesn't support PAE-above-4G). Signed-off-by: Jan Beulich --- 2010-11-09.orig/xen/arch/x86/boot/head.S 2010-08-06 08:44:33.0000000= 00 +0200 +++ 2010-11-09/xen/arch/x86/boot/head.S 2010-11-09 10:30:06.000000000 = +0100 @@ -110,12 +110,15 @@ __start: /* Initialise L2 identity-map and xen page table entries (16MB). = */ mov $sym_phys(l2_identmap),%edi mov $sym_phys(l2_xenmap),%esi + mov $sym_phys(l2_bootmap),%edx mov $0x1e3,%eax /* PRESENT+RW+A+D+2MB+GLOBAL = */ mov $8,%ecx 1: mov %eax,(%edi) add $8,%edi mov %eax,(%esi) add $8,%esi + mov %eax,(%edx) + add $8,%edx add $(1<>18) --- 2010-11-09.orig/xen/arch/x86/boot/Makefile 2010-04-22 14:43:25.0000000= 00 +0200 +++ 2010-11-09/xen/arch/x86/boot/Makefile 2010-11-09 10:30:06.0000000= 00 +0100 @@ -4,6 +4,6 @@ head.o: reloc.S =20 BOOT_TRAMPOLINE :=3D $(shell sed -n 's,^\#define[[:space:]]\{1\,\}BOOT_TRA= MPOLINE[[:space:]]\{1\,\},,p' $(BASEDIR)/include/asm-x86/config.h) %.S: %.c - RELOC=3D$(BOOT_TRAMPOLINE) XEN_BITSPERLONG=3D$(patsubst x86_%,%,$(T= ARGET_SUBARCH)) $(MAKE) -f build32.mk $@ + RELOC=3D$(BOOT_TRAMPOLINE) $(MAKE) -f build32.mk $@ =20 reloc.S: $(BASEDIR)/include/asm-x86/config.h --- 2010-11-09.orig/xen/arch/x86/boot/build32.mk 2010-08-06 = 08:44:33.000000000 +0200 +++ 2010-11-09/xen/arch/x86/boot/build32.mk 2010-11-09 10:30:06.0000000= 00 +0100 @@ -19,6 +19,6 @@ CFLAGS +=3D -Werror -fno-builtin -msoft-fl $(LD) $(LDFLAGS_DIRECT) -N -Ttext $(RELOC) -o $@ $< =20 %.o: %.c - $(CC) $(CFLAGS) -DXEN_BITSPERLONG=3D$(XEN_BITSPERLONG) -c $< -o $@ + $(CC) $(CFLAGS) -c $< -o $@ =20 reloc.o: $(BASEDIR)/include/asm-x86/config.h --- 2010-11-09.orig/xen/arch/x86/boot/reloc.c 2010-08-06 08:44:33.0000000= 00 +0200 +++ 2010-11-09/xen/arch/x86/boot/reloc.c 2010-11-09 10:30:06.0000000= 00 +0100 @@ -68,7 +68,6 @@ multiboot_info_t *reloc(multiboot_info_t { module_t *mods =3D reloc_mbi_struct( (module_t *)mbi->mods_addr, mbi->mods_count * sizeof(module_t)= ); - u32 max_addr =3D 0; =20 mbi->mods_addr =3D (u32)mods; =20 @@ -76,29 +75,6 @@ multiboot_info_t *reloc(multiboot_info_t { if ( mods[i].string ) mods[i].string =3D (u32)reloc_mbi_string((char *)mods[i].s= tring); - if ( mods[i].mod_end > max_addr ) - max_addr =3D mods[i].mod_end; - } - - /* - * 32-bit Xen only maps bottom 1GB of memory at boot time. = Relocate=20 - * modules which extend beyond this (GRUB2 in particular likes = to=20 - * place modules as high as possible below 4GB). - */ -#define BOOTMAP_END (1ul<<30) /* 1GB */ - if ( (XEN_BITSPERLONG =3D=3D 32) && (max_addr > BOOTMAP_END) ) - { - char *mod_alloc =3D (char *)BOOTMAP_END; - for ( i =3D 0; i < mbi->mods_count; i++ ) - mod_alloc -=3D mods[i].mod_end - mods[i].mod_start; - for ( i =3D 0; i < mbi->mods_count; i++ ) - { - u32 mod_len =3D mods[i].mod_end - mods[i].mod_start; - mods[i].mod_start =3D (u32)memcpy( - mod_alloc, (char *)mods[i].mod_start, mod_len); - mods[i].mod_end =3D mods[i].mod_start + mod_len; - mod_alloc +=3D mod_len; - } } } =20 --- 2010-11-09.orig/xen/arch/x86/domain_build.c 2010-08-06 08:44:33.0000000= 00 +0200 +++ 2010-11-09/xen/arch/x86/domain_build.c 2010-11-09 10:30:06.0000000= 00 +0100 @@ -31,6 +31,7 @@ #include #include #include +#include #include /* for bzimage_parse */ #include =20 @@ -284,9 +285,9 @@ static void __init process_dom0_ioports_ =20 int __init construct_dom0( struct domain *d, - unsigned long _image_base, - unsigned long _image_start, unsigned long image_len, - unsigned long _initrd_start, unsigned long initrd_len, + const module_t *image, unsigned long image_headroom, + const module_t *initrd, + void *(*bootstrap_map)(const module_t *), char *cmdline) { int i, cpu, rc, compatible, compat32, order, machine; @@ -301,16 +302,14 @@ int __init construct_dom0( start_info_t *si; struct vcpu *v =3D d->vcpu[0]; unsigned long long value; -#if defined(__i386__) - char *image_base =3D (char *)_image_base; /* use lowmem mappings = */ - char *image_start =3D (char *)_image_start; /* use lowmem mappings = */ - char *initrd_start =3D (char *)_initrd_start; /* use lowmem mappings = */ -#elif defined(__x86_64__) - char *image_base =3D __va(_image_base); - char *image_start =3D __va(_image_start); - char *initrd_start =3D __va(_initrd_start); -#endif -#if CONFIG_PAGING_LEVELS >=3D 4 + char *image_base =3D bootstrap_map(image); + unsigned long image_len =3D image->mod_end; + char *image_start =3D image_base + image_headroom; + unsigned long initrd_len =3D initrd ? initrd->mod_end : 0; +#if CONFIG_PAGING_LEVELS < 4 + module_t mpt; + void *mpt_ptr; +#else l4_pgentry_t *l4tab =3D NULL, *l4start =3D NULL; #endif l3_pgentry_t *l3tab =3D NULL, *l3start =3D NULL; @@ -340,7 +339,7 @@ int __init construct_dom0( unsigned long v_end; =20 /* Machine address of next candidate page-table page. */ - unsigned long mpt_alloc; + paddr_t mpt_alloc; =20 /* Sanity! */ BUG_ON(d->domain_id !=3D 0); @@ -495,17 +494,17 @@ int __init construct_dom0( if ( (1UL << order) > nr_pages ) panic("Domain 0 allocation is too small for kernel image.\n"); =20 -#ifdef __i386__ - /* Ensure that our low-memory 1:1 mapping covers the allocation. */ - page =3D alloc_domheap_pages(d, order, MEMF_bits(30)); -#else if ( parms.p2m_base !=3D UNSET_ADDR ) { vphysmap_start =3D parms.p2m_base; vphysmap_end =3D vphysmap_start + nr_pages * sizeof(unsigned = long); } - page =3D alloc_domheap_pages(d, order, 0); +#ifdef __i386__ + if ( !test_bit(XENFEAT_pae_pgdir_above_4gb, parms.f_supported) ) + page =3D alloc_domheap_pages(d, order, MEMF_bits(32)); + else #endif + page =3D alloc_domheap_pages(d, order, 0); if ( page =3D=3D NULL ) panic("Not enough RAM for domain 0 allocation.\n"); alloc_spfn =3D page_to_mfn(page); @@ -534,8 +533,7 @@ int __init construct_dom0( _p(v_start), _p(v_end)); printk(" ENTRY ADDRESS: %p\n", _p(parms.virt_entry)); =20 - mpt_alloc =3D (vpt_start - v_start) + - (unsigned long)pfn_to_paddr(alloc_spfn); + mpt_alloc =3D (vpt_start - v_start) + pfn_to_paddr(alloc_spfn); =20 #if defined(__i386__) /* @@ -548,17 +546,25 @@ int __init construct_dom0( return -EINVAL; } =20 + mpt.mod_start =3D mpt_alloc >> PAGE_SHIFT; + mpt.mod_end =3D vpt_end - vpt_start; + mpt_ptr =3D bootstrap_map(&mpt); +#define MPT_ALLOC(n) (mpt_ptr +=3D (n)*PAGE_SIZE, mpt_alloc +=3D = (n)*PAGE_SIZE) + /* WARNING: The new domain must have its 'processor' field filled in! = */ - l3start =3D l3tab =3D (l3_pgentry_t *)mpt_alloc; mpt_alloc +=3D = PAGE_SIZE; - l2start =3D l2tab =3D (l2_pgentry_t *)mpt_alloc; mpt_alloc +=3D = 4*PAGE_SIZE; + l3start =3D l3tab =3D mpt_ptr; MPT_ALLOC(1); + l2start =3D l2tab =3D mpt_ptr; MPT_ALLOC(4); for (i =3D 0; i < L3_PAGETABLE_ENTRIES; i++) { - copy_page(l2tab + i * L2_PAGETABLE_ENTRIES, - idle_pg_table_l2 + i * L2_PAGETABLE_ENTRIES); - l3tab[i] =3D l3e_from_paddr((u32)l2tab + i*PAGE_SIZE, L3_PROT); + if ( i < 3 ) + clear_page(l2tab + i * L2_PAGETABLE_ENTRIES); + else + copy_page(l2tab + i * L2_PAGETABLE_ENTRIES, + idle_pg_table_l2 + i * L2_PAGETABLE_ENTRIES); + l3tab[i] =3D l3e_from_pfn(mpt.mod_start + 1 + i, L3_PROT); l2tab[(LINEAR_PT_VIRT_START >> L2_PAGETABLE_SHIFT)+i] =3D - l2e_from_paddr((u32)l2tab + i*PAGE_SIZE, __PAGE_HYPERVISOR); + l2e_from_pfn(mpt.mod_start + 1 + i, __PAGE_HYPERVISOR); } - v->arch.guest_table =3D pagetable_from_paddr((unsigned long)l3start); + v->arch.guest_table =3D pagetable_from_pfn(mpt.mod_start); =20 for ( i =3D 0; i < PDPT_L2_ENTRIES; i++ ) l2tab[l2_linear_offset(PERDOMAIN_VIRT_START) + i] =3D @@ -570,9 +576,9 @@ int __init construct_dom0( { if ( !((unsigned long)l1tab & (PAGE_SIZE-1)) ) { - l1start =3D l1tab =3D (l1_pgentry_t *)mpt_alloc; - mpt_alloc +=3D PAGE_SIZE; - *l2tab =3D l2e_from_paddr((unsigned long)l1start, L2_PROT); + l1tab =3D mpt_ptr; + *l2tab =3D l2e_from_paddr(mpt_alloc, L2_PROT); + MPT_ALLOC(1); l2tab++; clear_page(l1tab); if ( count =3D=3D 0 ) @@ -587,11 +593,14 @@ int __init construct_dom0( =20 mfn++; } +#undef MPT_ALLOC =20 /* Pages that are part of page tables must be read only. */ + mpt_alloc =3D (paddr_t)mpt.mod_start << PAGE_SHIFT; + mpt_ptr =3D l3start; l2tab =3D l2start + l2_linear_offset(vpt_start); - l1start =3D l1tab =3D (l1_pgentry_t *)(u32)l2e_get_paddr(*l2tab); - l1tab +=3D l1_table_offset(vpt_start); + l1start =3D mpt_ptr + (l2e_get_paddr(*l2tab) - mpt_alloc); + l1tab =3D l1start + l1_table_offset(vpt_start); for ( count =3D 0; count < nr_pt_pages; count++ )=20 { page =3D mfn_to_page(l1e_get_pfn(*l1tab)); @@ -627,9 +636,15 @@ int __init construct_dom0( break; } if ( !((unsigned long)++l1tab & (PAGE_SIZE - 1)) ) - l1start =3D l1tab =3D (l1_pgentry_t *)(u32)l2e_get_paddr(*++l2= tab); + l1tab =3D mpt_ptr + (l2e_get_paddr(*++l2tab) - mpt_alloc); } =20 + /* + * Put Xen's first L3 entry into Dom0's page tables so that updates + * through bootstrap_map() will affect the page tables we will run = on. + */ + l3start[0] =3D l3e_from_paddr(__pa(idle_pg_table_l2), L3_PROT); + #elif defined(__x86_64__) =20 /* Overlap with Xen protected area? */ @@ -807,6 +822,7 @@ int __init construct_dom0( /* Copy the OS image and free temporary buffer. */ elf.dest =3D (void*)vkern_start; elf_load_binary(&elf); + bootstrap_map(NULL); =20 if ( UNSET_ADDR !=3D parms.virt_hypercall ) { @@ -823,7 +839,12 @@ int __init construct_dom0( =20 /* Copy the initial ramdisk. */ if ( initrd_len !=3D 0 ) + { + char *initrd_start =3D bootstrap_map(initrd); + memcpy((void *)vinitrd_start, initrd_start, initrd_len); + bootstrap_map(NULL); + } =20 /* Free temporary buffers. */ discard_initial_images(); @@ -1033,7 +1054,22 @@ int __init construct_dom0( write_ptbase(current); =20 #if defined(__i386__) - /* Destroy low mappings - they were only for our convenience. */ + /* Restore Dom0's first L3 entry. */ + mpt.mod_end =3D 5 * PAGE_SIZE; + l3start =3D mpt_ptr =3D bootstrap_map(&mpt); + l2start =3D mpt_ptr + PAGE_SIZE; + l3start[0] =3D l3e_from_pfn(mpt.mod_start + 1, L3_PROT); + + /* Re-setup CR3 */ + if ( paging_mode_enabled(d) ) + paging_update_paging_modes(v); + else + update_cr3(v); + + /* + * Destroy low mappings - they were only for our convenience. Note + * that zap_low_mappings() exceeds what bootstrap_map(NULL) would do. + */ zap_low_mappings(l2start); #endif =20 --- 2010-11-09.orig/xen/arch/x86/setup.c 2010-08-12 08:17:22.0000000= 00 +0200 +++ 2010-11-09/xen/arch/x86/setup.c 2010-11-09 10:30:06.000000000 = +0100 @@ -45,14 +45,6 @@ #include #include =20 -#if defined(CONFIG_X86_64) -#define BOOTSTRAP_DIRECTMAP_END (1UL << 32) /* 4GB */ -#define maddr_to_bootstrap_virt(m) maddr_to_virt(m) -#else -#define BOOTSTRAP_DIRECTMAP_END (1UL << 30) /* 1GB */ -#define maddr_to_bootstrap_virt(m) ((void *)(long)(m)) -#endif - extern u16 boot_edid_caps; extern u8 boot_edid_info[128]; extern struct boot_video_info boot_vid_info; @@ -152,21 +144,34 @@ static void __init parse_acpi_param(char for ( ; ; ) halt(); \ } while (0) =20 -static unsigned long __initdata initial_images_base; -static unsigned long __initdata initial_images_start; -static unsigned long __initdata initial_images_end; +static const module_t *__initdata initial_images; +static unsigned int __initdata nr_initial_images; =20 unsigned long __init initial_images_nrpages(void) { - ASSERT(!(initial_images_base & ~PAGE_MASK)); - ASSERT(!(initial_images_end & ~PAGE_MASK)); - return ((initial_images_end >> PAGE_SHIFT) - - (initial_images_base >> PAGE_SHIFT)); + unsigned long nr; + unsigned int i; + + for ( nr =3D i =3D 0; i < nr_initial_images; ++i ) + nr +=3D PFN_UP(initial_images[i].mod_end); + + return nr; } =20 void __init discard_initial_images(void) { - init_domheap_pages(initial_images_base, initial_images_end); + unsigned int i; + + for ( i =3D 0; i < nr_initial_images; ++i ) + { + uint64_t start =3D (uint64_t)initial_images[i].mod_start << = PAGE_SHIFT; + + init_domheap_pages(start, + start + PAGE_ALIGN(initial_images[i].mod_end));= + } + + nr_initial_images =3D 0; + initial_images =3D NULL; } =20 static void free_xen_data(char *s, char *e) @@ -257,33 +262,128 @@ static void __init normalise_cpu_order(v } } =20 +#define BOOTSTRAP_MAP_BASE (16UL << 20) +#define BOOTSTRAP_MAP_LIMIT (1UL << L3_PAGETABLE_SHIFT) + /* * Ensure a given physical memory range is present in the bootstrap = mappings. * Use superpage mappings to ensure that pagetable memory needn't be = allocated. */ -static void __init bootstrap_map(unsigned long start, unsigned long end) +static void *__init bootstrap_map(const module_t *mod) { - unsigned long mask =3D (1UL << L2_PAGETABLE_SHIFT) - 1; - start =3D max_t(unsigned long, start & ~mask, 16UL << 20); - end =3D (end + mask) & ~mask; + static unsigned long __initdata map_cur =3D BOOTSTRAP_MAP_BASE; + uint64_t start, end, mask =3D (1L << L2_PAGETABLE_SHIFT) - 1; + void *ret; + +#ifdef __x86_64__ + if ( !early_boot ) + return mod ? mfn_to_virt(mod->mod_start) : NULL; +#endif + + if ( !mod ) + { + destroy_xen_mappings(BOOTSTRAP_MAP_BASE, BOOTSTRAP_MAP_LIMIT); + map_cur =3D BOOTSTRAP_MAP_BASE; + return NULL; + } + + start =3D (uint64_t)mod->mod_start << PAGE_SHIFT; + end =3D start + mod->mod_end; if ( start >=3D end ) - return; - if ( end > BOOTSTRAP_DIRECTMAP_END ) - panic("Cannot access memory beyond end of " - "bootstrap direct-map area\n"); - map_pages_to_xen( - (unsigned long)maddr_to_bootstrap_virt(start), - start >> PAGE_SHIFT, (end-start) >> PAGE_SHIFT, PAGE_HYPERVISOR); + return NULL; + + if ( end <=3D BOOTSTRAP_MAP_BASE ) + return (void *)(unsigned long)start; + + ret =3D (void *)(map_cur + (unsigned long)(start & mask)); + start &=3D ~mask; + end =3D (end + mask) & ~mask; + if ( end - start > BOOTSTRAP_MAP_LIMIT - map_cur ) + return NULL; + + map_pages_to_xen(map_cur, start >> PAGE_SHIFT, + (end - start) >> PAGE_SHIFT, PAGE_HYPERVISOR); + map_cur +=3D end - start; + return ret; } =20 -static void __init move_memory( - unsigned long dst, unsigned long src_start, unsigned long src_end) +static void *__init move_memory( + uint64_t dst, uint64_t src, unsigned int size, bool_t keep) { - bootstrap_map(src_start, src_end); - bootstrap_map(dst, dst + src_end - src_start); - memmove(maddr_to_bootstrap_virt(dst), - maddr_to_bootstrap_virt(src_start), - src_end - src_start); + unsigned int blksz =3D BOOTSTRAP_MAP_LIMIT - BOOTSTRAP_MAP_BASE; + unsigned int mask =3D (1L << L2_PAGETABLE_SHIFT) - 1; + + if ( src + size > BOOTSTRAP_MAP_BASE ) + blksz >>=3D 1; + + while ( size ) + { + module_t mod; + unsigned int soffs =3D src & mask; + unsigned int doffs =3D dst & mask; + unsigned int sz; + void *d, *s; + + mod.mod_start =3D (src - soffs) >> PAGE_SHIFT; + mod.mod_end =3D soffs + size; + if ( mod.mod_end > blksz ) + mod.mod_end =3D blksz; + sz =3D mod.mod_end - soffs; + s =3D bootstrap_map(&mod); + + mod.mod_start =3D (dst - doffs) >> PAGE_SHIFT; + mod.mod_end =3D doffs + size; + if ( mod.mod_end > blksz ) + mod.mod_end =3D blksz; + if ( sz > mod.mod_end - doffs ) + sz =3D mod.mod_end - doffs; + d =3D bootstrap_map(&mod); + + memmove(d + doffs, s + soffs, sz); + + dst +=3D sz; + src +=3D sz; + size -=3D sz; + + if ( keep ) + return size ? NULL : d + doffs; + + bootstrap_map(NULL); + } + + return NULL; +} + +static uint64_t __init consider_modules( + uint64_t s, uint64_t e, uint32_t size, const module_t *mod, + unsigned int nr_mods, unsigned int this_mod) +{ + unsigned int i; + + if ( s > e || e - s < size ) + return 0; + + for ( i =3D 0; i < nr_mods ; ++i ) + { + uint64_t start =3D (uint64_t)mod[i].mod_start << PAGE_SHIFT; + uint64_t end =3D start + PAGE_ALIGN(mod[i].mod_end); + + if ( i =3D=3D this_mod ) + continue; + + if ( s < end && start < e ) + { + end =3D consider_modules(end, e, size, mod + i + 1, + nr_mods - i - 1, this_mod - i - 1); + if ( end ) + return end; + + return consider_modules(s, start, size, mod + i + 1, + nr_mods - i - 1, this_mod - i - 1); + } + } + + return e; } =20 static void __init setup_max_pdx(void) @@ -447,11 +547,10 @@ void __init __start_xen(unsigned long mb { char *memmap_type =3D NULL; char *cmdline, *kextra, *loader; - unsigned long _initrd_start =3D 0, _initrd_len =3D 0; unsigned int initrdidx =3D 1; multiboot_info_t *mbi =3D __va(mbi_p); module_t *mod =3D (module_t *)__va(mbi->mods_addr); - unsigned long nr_pages, modules_length, modules_headroom; + unsigned long nr_pages, modules_headroom; int i, j, e820_warn =3D 0, bytes =3D 0; bool_t acpi_boot_table_init_done =3D 0; struct ns16550_defaults ns16550 =3D { @@ -647,6 +746,9 @@ void __init __start_xen(unsigned long mb set_kexec_crash_area_size((u64)nr_pages << PAGE_SHIFT); kexec_reserve_area(&boot_e820); =20 + initial_images =3D mod; + nr_initial_images =3D mbi->mods_count; + /* * Iterate backwards over all superpage-aligned RAM regions. *=20 @@ -660,48 +762,64 @@ void __init __start_xen(unsigned long mb * we can relocate the dom0 kernel and other multiboot modules. Also, = on * x86/64, we relocate Xen to higher memory. */ - modules_length =3D 0; for ( i =3D 0; i < mbi->mods_count; i++ ) - modules_length +=3D mod[i].mod_end - mod[i].mod_start; + { + if ( mod[i].mod_start & (PAGE_SIZE - 1) ) + EARLY_FAIL("Bootloader didn't honor module alignment = request.\n"); + mod[i].mod_end -=3D mod[i].mod_start; + mod[i].mod_start >>=3D PAGE_SHIFT; + mod[i].reserved =3D 0; + } =20 - /* ensure mod[0] is mapped before parsing */ - bootstrap_map(mod[0].mod_start, mod[0].mod_end); - modules_headroom =3D bzimage_headroom( - (char *)(unsigned long)mod[0].mod_start, - (unsigned long)(mod[0].mod_end - mod[0].mod_start));= + modules_headroom =3D bzimage_headroom(bootstrap_map(mod), mod->mod_end= ); + bootstrap_map(NULL); =20 for ( i =3D boot_e820.nr_map-1; i >=3D 0; i-- ) { uint64_t s, e, mask =3D (1UL << L2_PAGETABLE_SHIFT) - 1; + uint64_t end, limit =3D ARRAY_SIZE(l2_identmap) << L2_PAGETABLE_SH= IFT; =20 - /* Superpage-aligned chunks from 16MB to BOOTSTRAP_DIRECTMAP_END. = */ + /* Superpage-aligned chunks from BOOTSTRAP_MAP_BASE. */ s =3D (boot_e820.map[i].addr + mask) & ~mask; e =3D (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask; - s =3D max_t(uint64_t, s, 16 << 20); - e =3D min_t(uint64_t, e, BOOTSTRAP_DIRECTMAP_END); + s =3D max_t(uint64_t, s, BOOTSTRAP_MAP_BASE); if ( (boot_e820.map[i].type !=3D E820_RAM) || (s >=3D e) ) continue; =20 - set_pdx_range(s >> PAGE_SHIFT, e >> PAGE_SHIFT); - - /* Map the chunk. No memory will need to be allocated to do this. = */ - map_pages_to_xen( - (unsigned long)maddr_to_bootstrap_virt(s), - s >> PAGE_SHIFT, (e-s) >> PAGE_SHIFT, PAGE_HYPERVISOR); + if ( s < limit ) + { + end =3D min(e, limit); + set_pdx_range(s >> PAGE_SHIFT, end >> PAGE_SHIFT); +#ifdef CONFIG_X86_64 + map_pages_to_xen((unsigned long)__va(s), s >> PAGE_SHIFT, + (end - s) >> PAGE_SHIFT, PAGE_HYPERVISOR); +#endif + } =20 #if defined(CONFIG_X86_64) + e =3D min_t(uint64_t, e, 1ULL << (PAGE_SHIFT + 32)); #define reloc_size ((__pa(&_end) + mask) & ~mask) /* Is the region suitable for relocating Xen? */ - if ( !xen_phys_start && ((e-s) >=3D reloc_size) ) + if ( !xen_phys_start && e <=3D limit ) + { + /* Don't overlap with modules. */ + end =3D consider_modules(s, e, reloc_size + mask, + mod, mbi->mods_count, -1); + end &=3D ~mask; + } + else + end =3D 0; + if ( end > s ) { extern l2_pgentry_t l2_xenmap[]; l4_pgentry_t *pl4e; l3_pgentry_t *pl3e; l2_pgentry_t *pl2e; int i, j, k; + void *dst; =20 /* Select relocation address. */ - e -=3D reloc_size; + e =3D end - reloc_size; xen_phys_start =3D e; bootsym(trampoline_xen_phys_start) =3D e; =20 @@ -712,10 +830,10 @@ void __init __start_xen(unsigned long mb * data until after we have switched to the relocated = pagetables! */ barrier(); - move_memory(e, 0, __pa(&_end) - xen_phys_start); + dst =3D move_memory(e, 0, (unsigned long)&_end - XEN_VIRT_STAR= T, 1); =20 /* Poison low 1MB to detect stray pointers to physical 0-1MB. = */ - memset(maddr_to_bootstrap_virt(e), 0x55, 1U<<20); + memset(dst, 0x55, 1U << 20); =20 /* Walk initial pagetables, relocating page directory = entries. */ pl4e =3D __va(__pa(idle_pg_table)); @@ -772,38 +890,58 @@ void __init __start_xen(unsigned long mb "movq %%rsi,%%cr4 " /* CR4.PGE =3D=3D 1 */ : : "r" (__pa(idle_pg_table)), "S" (cpu0_stack), "D" (__va(__pa(cpu0_stack))), "c" (STACK_SIZE) : "memory" = ); + + bootstrap_map(NULL); } #endif =20 /* Is the region suitable for relocating the multiboot modules? = */ - if ( !initial_images_start && (s < e) && - ((e-s) >=3D (modules_length+modules_headroom)) ) + for ( j =3D mbi->mods_count - 1; j >=3D 0; j-- ) { - initial_images_end =3D e; - initial_images_start =3D initial_images_end - modules_length; - initial_images_base =3D initial_images_start - modules_headroo= m; - initial_images_base &=3D PAGE_MASK; - for ( j =3D mbi->mods_count-1; j >=3D 0; j-- ) + unsigned long headroom =3D j ? 0 : modules_headroom; + unsigned long size =3D PAGE_ALIGN(headroom + mod[j].mod_end); + + if ( mod[j].reserved ) + continue; + + /* Don't overlap with other modules. */ + end =3D consider_modules(s, e, size, mod, mbi->mods_count, = j); + + if ( s < end && + (headroom || + ((end - size) >> PAGE_SHIFT) > mod[j].mod_start) ) { - e -=3D mod[j].mod_end - mod[j].mod_start; - move_memory(e, mod[j].mod_start, mod[j].mod_end); - mod[j].mod_end +=3D e - mod[j].mod_start; - mod[j].mod_start =3D e; + move_memory(end - size + headroom, + (uint64_t)mod[j].mod_start << PAGE_SHIFT, + mod[j].mod_end, 0); + mod[j].mod_start =3D (end - size) >> PAGE_SHIFT; + mod[j].mod_end +=3D headroom; + mod[j].reserved =3D 1; } - e =3D initial_images_base; } =20 - if ( !kexec_crash_area.start && (s < e) && - ((e-s) >=3D kexec_crash_area.size) ) +#ifdef CONFIG_X86_32 + /* Confine the kexec area to below 4Gb. */ + e =3D min_t(uint64_t, e, 1ULL << 32); +#endif + /* Don't overlap with modules. */ + e =3D consider_modules(s, e, PAGE_ALIGN(kexec_crash_area.size), + mod, mbi->mods_count, -1); + if ( !kexec_crash_area.start && (s < e) ) { e =3D (e - kexec_crash_area.size) & PAGE_MASK; kexec_crash_area.start =3D e; } } =20 - if ( !initial_images_start ) + if ( modules_headroom && !mod->reserved ) EARLY_FAIL("Not enough memory to relocate the dom0 kernel = image.\n"); - reserve_e820_ram(&boot_e820, initial_images_base, initial_images_end);= + for ( i =3D 0; i < mbi->mods_count; ++i ) + { + uint64_t s =3D (uint64_t)mod[i].mod_start << PAGE_SHIFT; + + reserve_e820_ram(&boot_e820, s, s + PAGE_ALIGN(mod[i].mod_end)); + } =20 #if defined(CONFIG_X86_32) xenheap_initial_phys_start =3D (PFN_UP(__pa(&_end)) + 1) << PAGE_SHIFT= ; @@ -827,7 +965,10 @@ void __init __start_xen(unsigned long mb */ for ( i =3D 0; i < boot_e820.nr_map; i++ ) { - uint64_t s, e, map_s, map_e, mask =3D PAGE_SIZE - 1; + uint64_t s, e, mask =3D PAGE_SIZE - 1; +#ifdef CONFIG_X86_64 + uint64_t map_s, map_e; +#endif =20 /* Only page alignment required now. */ s =3D (boot_e820.map[i].addr + mask) & ~mask; @@ -842,7 +983,7 @@ void __init __start_xen(unsigned long mb =20 #ifdef __x86_64__ if ( !acpi_boot_table_init_done && - s >=3D BOOTSTRAP_DIRECTMAP_END && + s >=3D (1ULL << 32) && !acpi_boot_table_init() ) { acpi_boot_table_init_done =3D 1; @@ -881,26 +1022,60 @@ void __init __start_xen(unsigned long mb =20 set_pdx_range(s >> PAGE_SHIFT, e >> PAGE_SHIFT); =20 - /* Need to create mappings above 16MB. */ - map_s =3D max_t(uint64_t, s, 16<<20); - map_e =3D e; -#if defined(CONFIG_X86_32) /* mappings are truncated on x86_32 */ - map_e =3D min_t(uint64_t, map_e, BOOTSTRAP_DIRECTMAP_END); -#endif +#ifdef CONFIG_X86_64 + /* Need to create mappings above BOOTSTRAP_MAP_BASE. */ + map_s =3D max_t(uint64_t, s, BOOTSTRAP_MAP_BASE); + map_e =3D min_t(uint64_t, e, + ARRAY_SIZE(l2_identmap) << L2_PAGETABLE_SHIFT); =20 /* Pass mapped memory to allocator /before/ creating new = mappings. */ - init_boot_pages(s, min_t(uint64_t, map_s, e)); + init_boot_pages(s, min(map_s, e)); + s =3D map_s; + if ( s < map_e ) + { + uint64_t mask =3D (1UL << L2_PAGETABLE_SHIFT) - 1; + + map_s =3D (s + mask) & ~mask; + map_e &=3D ~mask; + init_boot_pages(map_s, map_e); + } + + if ( map_s > map_e ) + map_s =3D map_e =3D s; =20 /* Create new mappings /before/ passing memory to the allocator. = */ - if ( map_s < map_e ) - map_pages_to_xen( - (unsigned long)maddr_to_bootstrap_virt(map_s), - map_s >> PAGE_SHIFT, (map_e-map_s) >> PAGE_SHIFT, - PAGE_HYPERVISOR); + if ( map_e < e ) + { + map_pages_to_xen((unsigned long)__va(map_e), map_e >> = PAGE_SHIFT, + (e - map_e) >> PAGE_SHIFT, PAGE_HYPERVISOR); + init_boot_pages(map_e, e); + } + if ( s < map_s ) + { + map_pages_to_xen((unsigned long)__va(s), s >> PAGE_SHIFT, + (map_s - s) >> PAGE_SHIFT, PAGE_HYPERVISOR); + init_boot_pages(s, map_s); + } +#else + init_boot_pages(s, e); +#endif + } =20 - /* Pass remainder of this memory chunk to the allocator. */ - init_boot_pages(map_s, e); + for ( i =3D 0; i < mbi->mods_count; ++i ) + { + set_pdx_range(mod[i].mod_start, + mod[i].mod_start + PFN_UP(mod[i].mod_end)); +#ifdef CONFIG_X86_64 + map_pages_to_xen((unsigned long)mfn_to_virt(mod[i].mod_start), + mod[i].mod_start, + PFN_UP(mod[i].mod_end), PAGE_HYPERVISOR); +#endif } +#ifdef CONFIG_X86_64 + map_pages_to_xen((unsigned long)__va(kexec_crash_area.start), + kexec_crash_area.start >> PAGE_SHIFT, + PFN_UP(kexec_crash_area.size), PAGE_HYPERVISOR); +#endif =20 memguard_init(); =20 @@ -1023,7 +1198,7 @@ void __init __start_xen(unsigned long mb =20 init_IRQ(); =20 - xsm_init(&initrdidx, mbi, initial_images_start); + xsm_init(&initrdidx, mbi, bootstrap_map); =20 timer_init(); =20 @@ -1135,12 +1310,6 @@ void __init __start_xen(unsigned long mb cmdline =3D dom0_cmdline; } =20 - if ( (initrdidx > 0) && (initrdidx < mbi->mods_count) ) - { - _initrd_start =3D mod[initrdidx].mod_start; - _initrd_len =3D mod[initrdidx].mod_end - mod[initrdidx].mod_star= t; - } - if ( xen_cpuidle ) xen_processor_pmbits |=3D XEN_PROCESSOR_PM_CX; =20 @@ -1148,13 +1317,10 @@ void __init __start_xen(unsigned long mb * We're going to setup domain0 using the module(s) that we stashed = safely * above our heap. The second module, if present, is an initrd = ramdisk. */ - if ( construct_dom0(dom0, - initial_images_base, - initial_images_start, - mod[0].mod_end-mod[0].mod_start, - _initrd_start, - _initrd_len, - cmdline) !=3D 0) + if ( construct_dom0(dom0, mod, modules_headroom, + (initrdidx > 0) && (initrdidx < mbi->mods_count) + ? mod + initrdidx : NULL, + bootstrap_map, cmdline) !=3D 0) panic("Could not set up DOM0 guest OS\n"); =20 /* Scrub RAM that is still free and so may go to an unprivileged = domain. */ --- 2010-11-09.orig/xen/arch/x86/x86_64/mm.c 2010-09-06 08:21:15.0000000= 00 +0200 +++ 2010-11-09/xen/arch/x86/x86_64/mm.c 2010-11-09 10:30:06.000000000 = +0100 @@ -65,6 +65,12 @@ l3_pgentry_t __attribute__ ((__section__ l2_pgentry_t __attribute__ ((__section__ (".bss.page_aligned"))) l2_xenmap[L2_PAGETABLE_ENTRIES]; =20 +/* Enough page directories to map into the bottom 1GB. */ +l3_pgentry_t __attribute__ ((__section__ (".bss.page_aligned"))) + l3_bootmap[L3_PAGETABLE_ENTRIES]; +l2_pgentry_t __attribute__ ((__section__ (".bss.page_aligned"))) + l2_bootmap[L2_PAGETABLE_ENTRIES]; + int __mfn_valid(unsigned long mfn) { return likely(mfn < max_page) && --- 2010-11-09.orig/xen/include/asm-x86/domain.h 2010-11-05 = 09:22:58.000000000 +0100 +++ 2010-11-09/xen/include/asm-x86/domain.h 2010-11-09 10:30:06.0000000= 00 +0100 @@ -466,16 +466,6 @@ void domain_cpuid(struct domain *d, unsigned int *ecx, unsigned int *edx); =20 -int construct_dom0( - struct domain *d, - unsigned long image_base, - unsigned long image_start, unsigned long image_len, - unsigned long initrd_start, unsigned long initrd_len, - char *cmdline); - -extern unsigned long initial_images_nrpages(void); -extern void discard_initial_images(void); - #endif /* __ASM_DOMAIN_H__ */ =20 /* --- 2010-11-09.orig/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h = 2010-06-01 13:39:57.000000000 +0200 +++ 2010-11-09/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h 2010-11-09 = 10:30:06.000000000 +0100 @@ -30,7 +30,6 @@ &amd_iommu_head, list) =20 #define DMA_32BIT_MASK 0x00000000ffffffffULL -#define PAGE_ALIGN(addr) (((addr) + PAGE_SIZE - 1) & PAGE_MASK) =20 extern int amd_iommu_debug; extern int amd_iommu_perdev_intremap; --- 2010-11-09.orig/xen/include/asm-x86/page.h 2010-05-28 13:59:16.0000000= 00 +0200 +++ 2010-11-09/xen/include/asm-x86/page.h 2010-11-09 10:30:06.0000000= 00 +0100 @@ -302,6 +302,7 @@ extern l2_pgentry_t idle_pg_table_l2[ extern l2_pgentry_t *compat_idle_pg_table_l2; extern unsigned int m2p_compat_vstart; #endif +extern l2_pgentry_t l2_identmap[4*L2_PAGETABLE_ENTRIES]; void paging_init(void); void setup_idle_pagetable(void); #endif /* !defined(__ASSEMBLY__) */ @@ -397,6 +398,7 @@ static inline uint32_t cacheattr_to_pte_ =20 #define PFN_DOWN(x) ((x) >> PAGE_SHIFT) #define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT) +#define PAGE_ALIGN(x) (((x) + PAGE_SIZE - 1) & PAGE_MASK) =20 #endif /* __X86_PAGE_H__ */ =20 --- 2010-11-09.orig/xen/include/asm-x86/setup.h 2010-05-20 09:59:27.0000000= 00 +0200 +++ 2010-11-09/xen/include/asm-x86/setup.h 2010-11-09 10:30:06.0000000= 00 +0100 @@ -1,6 +1,8 @@ #ifndef __X86_SETUP_H_ #define __X86_SETUP_H_ =20 +#include + extern int early_boot; extern unsigned long xenheap_initial_phys_start; =20 @@ -25,4 +27,14 @@ void init_IRQ(void); void vesa_init(void); void vesa_mtrr_init(void); =20 +int construct_dom0( + struct domain *d, + const module_t *kernel, unsigned long kernel_headroom, + const module_t *initrd, + void *(*bootstrap_map)(const module_t *), + char *cmdline); + +unsigned long initial_images_nrpages(void); +void discard_initial_images(void); + #endif --- 2010-11-09.orig/xen/include/xsm/xsm.h 2010-11-09 08:25:42.0000000= 00 +0100 +++ 2010-11-09/xen/include/xsm/xsm.h 2010-11-09 10:30:06.000000000 = +0100 @@ -432,14 +432,15 @@ static inline long __do_xsm_op (XEN_GUES =20 #ifdef XSM_ENABLE extern int xsm_init(unsigned int *initrdidx, const multiboot_info_t *mbi, - unsigned long initial_images_sta= rt); + void *(*bootstrap_map)(const module_t *)); extern int xsm_policy_init(unsigned int *initrdidx, const multiboot_info_t= *mbi, - unsigned long initial_images_st= art); + void *(*bootstrap_map)(const module_t *)); extern int register_xsm(struct xsm_operations *ops); extern int unregister_xsm(struct xsm_operations *ops); #else static inline int xsm_init (unsigned int *initrdidx, - const multiboot_info_t *mbi, unsigned long initial_images_= start) + const multiboot_info_t *mbi, + void *(*bootstrap_map)(const module_t *)) { return 0; } --- 2010-11-09.orig/xen/xsm/xsm_core.c 2009-10-07 13:31:36.000000000 = +0200 +++ 2010-11-09/xen/xsm/xsm_core.c 2010-11-09 10:30:06.000000000 = +0100 @@ -47,7 +47,7 @@ static void __init do_xsm_initcalls(void } =20 int __init xsm_init(unsigned int *initrdidx, const multiboot_info_t *mbi, - unsigned long initial_images_start) + void *(*bootstrap_map)(const module_t *)) { int ret =3D 0; =20 @@ -55,9 +55,10 @@ int __init xsm_init(unsigned int *initrd =20 if ( XSM_MAGIC ) { - ret =3D xsm_policy_init(initrdidx, mbi, initial_images_start); + ret =3D xsm_policy_init(initrdidx, mbi, bootstrap_map); if ( ret ) { + bootstrap_map(NULL); printk("%s: Error initializing policy.\n", __FUNCTION__); return -EINVAL; } @@ -65,6 +66,7 @@ int __init xsm_init(unsigned int *initrd =20 if ( verify(&dummy_xsm_ops) ) { + bootstrap_map(NULL); printk("%s could not verify " "dummy_xsm_ops structure.\n", __FUNCTION__); return -EIO; @@ -72,6 +74,7 @@ int __init xsm_init(unsigned int *initrd =20 xsm_ops =3D &dummy_xsm_ops; do_xsm_initcalls(); + bootstrap_map(NULL); =20 return 0; } --- 2010-11-09.orig/xen/xsm/xsm_policy.c 2007-11-02 17:25:59.0000000= 00 +0100 +++ 2010-11-09/xen/xsm/xsm_policy.c 2010-11-09 10:30:06.000000000 = +0100 @@ -22,11 +22,11 @@ #include #include =20 -char *policy_buffer =3D NULL; -u32 policy_size =3D 0; +char *__initdata policy_buffer =3D NULL; +u32 __initdata policy_size =3D 0; =20 int xsm_policy_init(unsigned int *initrdidx, const multiboot_info_t *mbi, - unsigned long initial_images_start) + void *(*bootstrap_map)(const module_t *)) { int i; module_t *mod =3D (module_t *)__va(mbi->mods_addr); @@ -40,15 +40,8 @@ int xsm_policy_init(unsigned int *initrd */ for ( i =3D mbi->mods_count-1; i >=3D 1; i-- ) { - start =3D initial_images_start + (mod[i].mod_start-mod[0].mod_star= t); -#if defined(__i386__) - _policy_start =3D (u32 *)start; -#elif defined(__x86_64__) - _policy_start =3D maddr_to_virt(start); -#else - _policy_start =3D NULL; -#endif - _policy_len =3D mod[i].mod_end - mod[i].mod_start; + _policy_start =3D bootstrap_map(mod + i); + _policy_len =3D mod[i].mod_end; =20 if ( (xsm_magic_t)(*_policy_start) =3D=3D XSM_MAGIC ) { @@ -63,6 +56,8 @@ int xsm_policy_init(unsigned int *initrd break; =20 } + + bootstrap_map(NULL); } =20 return rc; --=__Part0F2297DC.0__= Content-Type: text/plain; name="x86-custom-boot-map.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-custom-boot-map.patch" By doing so, we're no longer restricted to be able to place all boot=0Aload= er modules into the low 1Gb/4Gb (32-/64-bit) of memory, nor is=0Athere a = dependency anymore on where the boot loader places the modules.=0A=0AWe're = also no longer restricted to copy the modules into a place below=0A4Gb, = nor to put them all together into a single piece of memory.=0A=0AFurther = it allows even the 32-bit Dom0 kernel to be loaded anywhere in=0Aphysical = memory (except if it doesn't support PAE-above-4G).=0A=0ASigned-off-by: = Jan Beulich =0A=0A--- 2010-11-09.orig/xen/arch/x86/boo= t/head.S 2010-08-06 08:44:33.000000000 +0200=0A+++ 2010-11-09/xen/ar= ch/x86/boot/head.S 2010-11-09 10:30:06.000000000 +0100=0A@@ -110,12 = +110,15 @@ __start:=0A /* Initialise L2 identity-map and xen page = table entries (16MB). */=0A mov $sym_phys(l2_identmap),%edi=0A = mov $sym_phys(l2_xenmap),%esi=0A+ mov $sym_phys(l2_b= ootmap),%edx=0A mov $0x1e3,%eax /* PRESENT+RW+= A+D+2MB+GLOBAL */=0A mov $8,%ecx=0A 1: mov %eax,(%edi)= =0A add $8,%edi=0A mov %eax,(%esi)=0A add = $8,%esi=0A+ mov %eax,(%edx)=0A+ add $8,%edx=0A = add $(1<>18)=0A--- = 2010-11-09.orig/xen/arch/x86/boot/Makefile 2010-04-22 14:43:25.0000000= 00 +0200=0A+++ 2010-11-09/xen/arch/x86/boot/Makefile 2010-11-09 = 10:30:06.000000000 +0100=0A@@ -4,6 +4,6 @@ head.o: reloc.S=0A =0A = BOOT_TRAMPOLINE :=3D $(shell sed -n 's,^\#define[[:space:]]\{1\,\}BOOT_TRAM= POLINE[[:space:]]\{1\,\},,p' $(BASEDIR)/include/asm-x86/config.h)=0A %.S: = %.c=0A- RELOC=3D$(BOOT_TRAMPOLINE) XEN_BITSPERLONG=3D$(patsubst x86_%,%,$(T= ARGET_SUBARCH)) $(MAKE) -f build32.mk $@=0A+ RELOC=3D$(BOOT_TRAMPOLINE) = $(MAKE) -f build32.mk $@=0A =0A reloc.S: $(BASEDIR)/include/asm-x86/config.= h=0A--- 2010-11-09.orig/xen/arch/x86/boot/build32.mk 2010-08-06 = 08:44:33.000000000 +0200=0A+++ 2010-11-09/xen/arch/x86/boot/build32.mk = 2010-11-09 10:30:06.000000000 +0100=0A@@ -19,6 +19,6 @@ CFLAGS +=3D = -Werror -fno-builtin -msoft-fl=0A $(LD) $(LDFLAGS_DIRECT) -N -Ttext = $(RELOC) -o $@ $<=0A =0A %.o: %.c=0A- $(CC) $(CFLAGS) -DXEN_BITSPERLONG= =3D$(XEN_BITSPERLONG) -c $< -o $@=0A+ $(CC) $(CFLAGS) -c $< -o $@=0A =0A = reloc.o: $(BASEDIR)/include/asm-x86/config.h=0A--- 2010-11-09.orig/xen/arch= /x86/boot/reloc.c 2010-08-06 08:44:33.000000000 +0200=0A+++ = 2010-11-09/xen/arch/x86/boot/reloc.c 2010-11-09 10:30:06.000000000 = +0100=0A@@ -68,7 +68,6 @@ multiboot_info_t *reloc(multiboot_info_t=0A = {=0A module_t *mods =3D reloc_mbi_struct(=0A (module_t = *)mbi->mods_addr, mbi->mods_count * sizeof(module_t));=0A- u32 = max_addr =3D 0;=0A =0A mbi->mods_addr =3D (u32)mods;=0A =0A@@ = -76,29 +75,6 @@ multiboot_info_t *reloc(multiboot_info_t=0A {=0A = if ( mods[i].string )=0A mods[i].string =3D = (u32)reloc_mbi_string((char *)mods[i].string);=0A- if ( = mods[i].mod_end > max_addr )=0A- max_addr =3D mods[i].mod_en= d;=0A- }=0A-=0A- /*=0A- * 32-bit Xen only maps = bottom 1GB of memory at boot time. Relocate =0A- * modules which = extend beyond this (GRUB2 in particular likes to =0A- * place = modules as high as possible below 4GB).=0A- */=0A-#define = BOOTMAP_END (1ul<<30) /* 1GB */=0A- if ( (XEN_BITSPERLONG =3D=3D = 32) && (max_addr > BOOTMAP_END) )=0A- {=0A- char = *mod_alloc =3D (char *)BOOTMAP_END;=0A- for ( i =3D 0; i < = mbi->mods_count; i++ )=0A- mod_alloc -=3D mods[i].mod_end - = mods[i].mod_start;=0A- for ( i =3D 0; i < mbi->mods_count; i++ = )=0A- {=0A- u32 mod_len =3D mods[i].mod_end - = mods[i].mod_start;=0A- mods[i].mod_start =3D (u32)memcpy(=0A= - mod_alloc, (char *)mods[i].mod_start, mod_len);=0A- = mods[i].mod_end =3D mods[i].mod_start + mod_len;=0A- = mod_alloc +=3D mod_len;=0A- }=0A }=0A }=0A = =0A--- 2010-11-09.orig/xen/arch/x86/domain_build.c 2010-08-06 = 08:44:33.000000000 +0200=0A+++ 2010-11-09/xen/arch/x86/domain_build.c = 2010-11-09 10:30:06.000000000 +0100=0A@@ -31,6 +31,7 @@=0A #include = =0A #include =0A #include =0A+#include = =0A #include /* for bzimage_parse */=0A = #include =0A =0A@@ -284,9 +285,9 @@ static void __init = process_dom0_ioports_=0A =0A int __init construct_dom0(=0A struct = domain *d,=0A- unsigned long _image_base,=0A- unsigned long = _image_start, unsigned long image_len,=0A- unsigned long _initrd_start, = unsigned long initrd_len,=0A+ const module_t *image, unsigned long = image_headroom,=0A+ const module_t *initrd,=0A+ void *(*bootstrap_map= )(const module_t *),=0A char *cmdline)=0A {=0A int i, cpu, rc, = compatible, compat32, order, machine;=0A@@ -301,16 +302,14 @@ int __init = construct_dom0(=0A start_info_t *si;=0A struct vcpu *v =3D = d->vcpu[0];=0A unsigned long long value;=0A-#if defined(__i386__)=0A- = char *image_base =3D (char *)_image_base; /* use lowmem mappings = */=0A- char *image_start =3D (char *)_image_start; /* use lowmem = mappings */=0A- char *initrd_start =3D (char *)_initrd_start; /* use = lowmem mappings */=0A-#elif defined(__x86_64__)=0A- char *image_base = =3D __va(_image_base);=0A- char *image_start =3D __va(_image_start);=0A= - char *initrd_start =3D __va(_initrd_start);=0A-#endif=0A-#if = CONFIG_PAGING_LEVELS >=3D 4=0A+ char *image_base =3D bootstrap_map(image= );=0A+ unsigned long image_len =3D image->mod_end;=0A+ char = *image_start =3D image_base + image_headroom;=0A+ unsigned long = initrd_len =3D initrd ? initrd->mod_end : 0;=0A+#if CONFIG_PAGING_LEVELS < = 4=0A+ module_t mpt;=0A+ void *mpt_ptr;=0A+#else=0A l4_pgentry_t = *l4tab =3D NULL, *l4start =3D NULL;=0A #endif=0A l3_pgentry_t *l3tab = =3D NULL, *l3start =3D NULL;=0A@@ -340,7 +339,7 @@ int __init construct_dom= 0(=0A unsigned long v_end;=0A =0A /* Machine address of next = candidate page-table page. */=0A- unsigned long mpt_alloc;=0A+ = paddr_t mpt_alloc;=0A =0A /* Sanity! */=0A BUG_ON(d->domain_id = !=3D 0);=0A@@ -495,17 +494,17 @@ int __init construct_dom0(=0A if ( = (1UL << order) > nr_pages )=0A panic("Domain 0 allocation is too = small for kernel image.\n");=0A =0A-#ifdef __i386__=0A- /* Ensure that = our low-memory 1:1 mapping covers the allocation. */=0A- page =3D = alloc_domheap_pages(d, order, MEMF_bits(30));=0A-#else=0A if ( = parms.p2m_base !=3D UNSET_ADDR )=0A {=0A vphysmap_start =3D = parms.p2m_base;=0A vphysmap_end =3D vphysmap_start + nr_pages * = sizeof(unsigned long);=0A }=0A- page =3D alloc_domheap_pages(d, = order, 0);=0A+#ifdef __i386__=0A+ if ( !test_bit(XENFEAT_pae_pgdir_above= _4gb, parms.f_supported) )=0A+ page =3D alloc_domheap_pages(d, = order, MEMF_bits(32));=0A+ else=0A #endif=0A+ page =3D alloc_domh= eap_pages(d, order, 0);=0A if ( page =3D=3D NULL )=0A = panic("Not enough RAM for domain 0 allocation.\n");=0A alloc_spfn =3D = page_to_mfn(page);=0A@@ -534,8 +533,7 @@ int __init construct_dom0(=0A = _p(v_start), _p(v_end));=0A printk(" ENTRY ADDRESS: %p\n", = _p(parms.virt_entry));=0A =0A- mpt_alloc =3D (vpt_start - v_start) = +=0A- (unsigned long)pfn_to_paddr(alloc_spfn);=0A+ mpt_alloc =3D = (vpt_start - v_start) + pfn_to_paddr(alloc_spfn);=0A =0A #if defined(__i386= __)=0A /*=0A@@ -548,17 +546,25 @@ int __init construct_dom0(=0A = return -EINVAL;=0A }=0A =0A+ mpt.mod_start =3D mpt_alloc >> = PAGE_SHIFT;=0A+ mpt.mod_end =3D vpt_end - vpt_start;=0A+ mpt_ptr = =3D bootstrap_map(&mpt);=0A+#define MPT_ALLOC(n) (mpt_ptr +=3D (n)*PAGE_SIZ= E, mpt_alloc +=3D (n)*PAGE_SIZE)=0A+=0A /* WARNING: The new domain = must have its 'processor' field filled in! */=0A- l3start =3D l3tab =3D = (l3_pgentry_t *)mpt_alloc; mpt_alloc +=3D PAGE_SIZE;=0A- l2start =3D = l2tab =3D (l2_pgentry_t *)mpt_alloc; mpt_alloc +=3D 4*PAGE_SIZE;=0A+ = l3start =3D l3tab =3D mpt_ptr; MPT_ALLOC(1);=0A+ l2start =3D l2tab =3D = mpt_ptr; MPT_ALLOC(4);=0A for (i =3D 0; i < L3_PAGETABLE_ENTRIES; i++) = {=0A- copy_page(l2tab + i * L2_PAGETABLE_ENTRIES,=0A- = idle_pg_table_l2 + i * L2_PAGETABLE_ENTRIES);=0A- l3tab[i] =3D = l3e_from_paddr((u32)l2tab + i*PAGE_SIZE, L3_PROT);=0A+ if ( i < 3 = )=0A+ clear_page(l2tab + i * L2_PAGETABLE_ENTRIES);=0A+ = else=0A+ copy_page(l2tab + i * L2_PAGETABLE_ENTRIES,=0A+ = idle_pg_table_l2 + i * L2_PAGETABLE_ENTRIES);=0A+ = l3tab[i] =3D l3e_from_pfn(mpt.mod_start + 1 + i, L3_PROT);=0A = l2tab[(LINEAR_PT_VIRT_START >> L2_PAGETABLE_SHIFT)+i] =3D=0A- = l2e_from_paddr((u32)l2tab + i*PAGE_SIZE, __PAGE_HYPERVISOR);=0A+ = l2e_from_pfn(mpt.mod_start + 1 + i, __PAGE_HYPERVISOR);=0A }=0A- = v->arch.guest_table =3D pagetable_from_paddr((unsigned long)l3start);=0A+ = v->arch.guest_table =3D pagetable_from_pfn(mpt.mod_start);=0A =0A = for ( i =3D 0; i < PDPT_L2_ENTRIES; i++ )=0A l2tab[l2_linear_offset= (PERDOMAIN_VIRT_START) + i] =3D=0A@@ -570,9 +576,9 @@ int __init construct_= dom0(=0A {=0A if ( !((unsigned long)l1tab & (PAGE_SIZE-1)) = )=0A {=0A- l1start =3D l1tab =3D (l1_pgentry_t = *)mpt_alloc;=0A- mpt_alloc +=3D PAGE_SIZE;=0A- = *l2tab =3D l2e_from_paddr((unsigned long)l1start, L2_PROT);=0A+ = l1tab =3D mpt_ptr;=0A+ *l2tab =3D l2e_from_paddr(mpt_alloc, = L2_PROT);=0A+ MPT_ALLOC(1);=0A l2tab++;=0A = clear_page(l1tab);=0A if ( count =3D=3D 0 )=0A@@ -587,11 = +593,14 @@ int __init construct_dom0(=0A =0A mfn++;=0A = }=0A+#undef MPT_ALLOC=0A =0A /* Pages that are part of page tables = must be read only. */=0A+ mpt_alloc =3D (paddr_t)mpt.mod_start << = PAGE_SHIFT;=0A+ mpt_ptr =3D l3start;=0A l2tab =3D l2start + = l2_linear_offset(vpt_start);=0A- l1start =3D l1tab =3D (l1_pgentry_t = *)(u32)l2e_get_paddr(*l2tab);=0A- l1tab +=3D l1_table_offset(vpt_start);= =0A+ l1start =3D mpt_ptr + (l2e_get_paddr(*l2tab) - mpt_alloc);=0A+ = l1tab =3D l1start + l1_table_offset(vpt_start);=0A for ( count =3D 0; = count < nr_pt_pages; count++ ) =0A {=0A page =3D mfn_to_page(l1= e_get_pfn(*l1tab));=0A@@ -627,9 +636,15 @@ int __init construct_dom0(=0A = break;=0A }=0A if ( !((unsigned long)++l1tab & = (PAGE_SIZE - 1)) )=0A- l1start =3D l1tab =3D (l1_pgentry_t = *)(u32)l2e_get_paddr(*++l2tab);=0A+ l1tab =3D mpt_ptr + = (l2e_get_paddr(*++l2tab) - mpt_alloc);=0A }=0A =0A+ /*=0A+ * = Put Xen's first L3 entry into Dom0's page tables so that updates=0A+ * = through bootstrap_map() will affect the page tables we will run on.=0A+ = */=0A+ l3start[0] =3D l3e_from_paddr(__pa(idle_pg_table_l2), = L3_PROT);=0A+=0A #elif defined(__x86_64__)=0A =0A /* Overlap with Xen = protected area? */=0A@@ -807,6 +822,7 @@ int __init construct_dom0(=0A = /* Copy the OS image and free temporary buffer. */=0A elf.dest =3D = (void*)vkern_start;=0A elf_load_binary(&elf);=0A+ bootstrap_map(NULL= );=0A =0A if ( UNSET_ADDR !=3D parms.virt_hypercall )=0A {=0A@@ = -823,7 +839,12 @@ int __init construct_dom0(=0A =0A /* Copy the = initial ramdisk. */=0A if ( initrd_len !=3D 0 )=0A+ {=0A+ = char *initrd_start =3D bootstrap_map(initrd);=0A+=0A memcpy((void = *)vinitrd_start, initrd_start, initrd_len);=0A+ bootstrap_map(NULL);= =0A+ }=0A =0A /* Free temporary buffers. */=0A discard_initial_i= mages();=0A@@ -1033,7 +1054,22 @@ int __init construct_dom0(=0A = write_ptbase(current);=0A =0A #if defined(__i386__)=0A- /* Destroy low = mappings - they were only for our convenience. */=0A+ /* Restore Dom0's = first L3 entry. */=0A+ mpt.mod_end =3D 5 * PAGE_SIZE;=0A+ l3start = =3D mpt_ptr =3D bootstrap_map(&mpt);=0A+ l2start =3D mpt_ptr + = PAGE_SIZE;=0A+ l3start[0] =3D l3e_from_pfn(mpt.mod_start + 1, = L3_PROT);=0A+=0A+ /* Re-setup CR3 */=0A+ if ( paging_mode_enabled(d)= )=0A+ paging_update_paging_modes(v);=0A+ else=0A+ = update_cr3(v);=0A+=0A+ /*=0A+ * Destroy low mappings - they were = only for our convenience. Note=0A+ * that zap_low_mappings() exceeds = what bootstrap_map(NULL) would do.=0A+ */=0A zap_low_mappings(l2sta= rt);=0A #endif=0A =0A--- 2010-11-09.orig/xen/arch/x86/setup.c 2010-08-12 = 08:17:22.000000000 +0200=0A+++ 2010-11-09/xen/arch/x86/setup.c 2010-11-09 = 10:30:06.000000000 +0100=0A@@ -45,14 +45,6 @@=0A #include =0A = #include =0A =0A-#if defined(CONFIG_X86_64)=0A-#define = BOOTSTRAP_DIRECTMAP_END (1UL << 32) /* 4GB */=0A-#define maddr_to_bootstrap= _virt(m) maddr_to_virt(m)=0A-#else=0A-#define BOOTSTRAP_DIRECTMAP_END (1UL = << 30) /* 1GB */=0A-#define maddr_to_bootstrap_virt(m) ((void *)(long)(m))= =0A-#endif=0A-=0A extern u16 boot_edid_caps;=0A extern u8 boot_edid_info[12= 8];=0A extern struct boot_video_info boot_vid_info;=0A@@ -152,21 +144,34 = @@ static void __init parse_acpi_param(char=0A for ( ; ; ) halt(); = \=0A } while (0)=0A =0A-static unsigned long __initdata= initial_images_base;=0A-static unsigned long __initdata initial_images_sta= rt;=0A-static unsigned long __initdata initial_images_end;=0A+static const = module_t *__initdata initial_images;=0A+static unsigned int __initdata = nr_initial_images;=0A =0A unsigned long __init initial_images_nrpages(void)= =0A {=0A- ASSERT(!(initial_images_base & ~PAGE_MASK));=0A- ASSERT(!(i= nitial_images_end & ~PAGE_MASK));=0A- return ((initial_images_end >> = PAGE_SHIFT) -=0A- (initial_images_base >> PAGE_SHIFT));=0A+ = unsigned long nr;=0A+ unsigned int i;=0A+=0A+ for ( nr =3D i =3D 0; = i < nr_initial_images; ++i )=0A+ nr +=3D PFN_UP(initial_images[i].mo= d_end);=0A+=0A+ return nr;=0A }=0A =0A void __init discard_initial_image= s(void)=0A {=0A- init_domheap_pages(initial_images_base, initial_images_= end);=0A+ unsigned int i;=0A+=0A+ for ( i =3D 0; i < nr_initial_image= s; ++i )=0A+ {=0A+ uint64_t start =3D (uint64_t)initial_images[i]= .mod_start << PAGE_SHIFT;=0A+=0A+ init_domheap_pages(start,=0A+ = start + PAGE_ALIGN(initial_images[i].mod_end));=0A+ = }=0A+=0A+ nr_initial_images =3D 0;=0A+ initial_images =3D NULL;=0A = }=0A =0A static void free_xen_data(char *s, char *e)=0A@@ -257,33 +262,128 = @@ static void __init normalise_cpu_order(v=0A }=0A }=0A =0A+#define = BOOTSTRAP_MAP_BASE (16UL << 20)=0A+#define BOOTSTRAP_MAP_LIMIT (1UL << = L3_PAGETABLE_SHIFT)=0A+=0A /*=0A * Ensure a given physical memory range = is present in the bootstrap mappings.=0A * Use superpage mappings to = ensure that pagetable memory needn't be allocated.=0A */=0A-static void = __init bootstrap_map(unsigned long start, unsigned long end)=0A+static = void *__init bootstrap_map(const module_t *mod)=0A {=0A- unsigned long = mask =3D (1UL << L2_PAGETABLE_SHIFT) - 1;=0A- start =3D max_t(unsigned = long, start & ~mask, 16UL << 20);=0A- end =3D (end + mask) & = ~mask;=0A+ static unsigned long __initdata map_cur =3D BOOTSTRAP_MAP_BAS= E;=0A+ uint64_t start, end, mask =3D (1L << L2_PAGETABLE_SHIFT) - = 1;=0A+ void *ret;=0A+=0A+#ifdef __x86_64__=0A+ if ( !early_boot = )=0A+ return mod ? mfn_to_virt(mod->mod_start) : NULL;=0A+#endif=0A+= =0A+ if ( !mod )=0A+ {=0A+ destroy_xen_mappings(BOOTSTRAP_MAP_= BASE, BOOTSTRAP_MAP_LIMIT);=0A+ map_cur =3D BOOTSTRAP_MAP_BASE;=0A+ = return NULL;=0A+ }=0A+=0A+ start =3D (uint64_t)mod->mod_start = << PAGE_SHIFT;=0A+ end =3D start + mod->mod_end;=0A if ( start >=3D = end )=0A- return;=0A- if ( end > BOOTSTRAP_DIRECTMAP_END )=0A- = panic("Cannot access memory beyond end of "=0A- = "bootstrap direct-map area\n");=0A- map_pages_to_xen(=0A- = (unsigned long)maddr_to_bootstrap_virt(start),=0A- start >> = PAGE_SHIFT, (end-start) >> PAGE_SHIFT, PAGE_HYPERVISOR);=0A+ return = NULL;=0A+=0A+ if ( end <=3D BOOTSTRAP_MAP_BASE )=0A+ return = (void *)(unsigned long)start;=0A+=0A+ ret =3D (void *)(map_cur + = (unsigned long)(start & mask));=0A+ start &=3D ~mask;=0A+ end =3D = (end + mask) & ~mask;=0A+ if ( end - start > BOOTSTRAP_MAP_LIMIT - = map_cur )=0A+ return NULL;=0A+=0A+ map_pages_to_xen(map_cur, = start >> PAGE_SHIFT,=0A+ (end - start) >> PAGE_SHIFT, = PAGE_HYPERVISOR);=0A+ map_cur +=3D end - start;=0A+ return ret;=0A = }=0A =0A-static void __init move_memory(=0A- unsigned long dst, = unsigned long src_start, unsigned long src_end)=0A+static void *__init = move_memory(=0A+ uint64_t dst, uint64_t src, unsigned int size, bool_t = keep)=0A {=0A- bootstrap_map(src_start, src_end);=0A- bootstrap_map(d= st, dst + src_end - src_start);=0A- memmove(maddr_to_bootstrap_virt(dst)= ,=0A- maddr_to_bootstrap_virt(src_start),=0A- = src_end - src_start);=0A+ unsigned int blksz =3D BOOTSTRAP_MAP_LIMIT - = BOOTSTRAP_MAP_BASE;=0A+ unsigned int mask =3D (1L << L2_PAGETABLE_SHIFT)= - 1;=0A+=0A+ if ( src + size > BOOTSTRAP_MAP_BASE )=0A+ blksz = >>=3D 1;=0A+=0A+ while ( size )=0A+ {=0A+ module_t mod;=0A+ = unsigned int soffs =3D src & mask;=0A+ unsigned int doffs =3D = dst & mask;=0A+ unsigned int sz;=0A+ void *d, *s;=0A+=0A+ = mod.mod_start =3D (src - soffs) >> PAGE_SHIFT;=0A+ mod.mod_end = =3D soffs + size;=0A+ if ( mod.mod_end > blksz )=0A+ = mod.mod_end =3D blksz;=0A+ sz =3D mod.mod_end - soffs;=0A+ s = =3D bootstrap_map(&mod);=0A+=0A+ mod.mod_start =3D (dst - doffs) >> = PAGE_SHIFT;=0A+ mod.mod_end =3D doffs + size;=0A+ if ( = mod.mod_end > blksz )=0A+ mod.mod_end =3D blksz;=0A+ if = ( sz > mod.mod_end - doffs )=0A+ sz =3D mod.mod_end - doffs;=0A+= d =3D bootstrap_map(&mod);=0A+=0A+ memmove(d + doffs, s + = soffs, sz);=0A+=0A+ dst +=3D sz;=0A+ src +=3D sz;=0A+ = size -=3D sz;=0A+=0A+ if ( keep )=0A+ return size ? NULL = : d + doffs;=0A+=0A+ bootstrap_map(NULL);=0A+ }=0A+=0A+ = return NULL;=0A+}=0A+=0A+static uint64_t __init consider_modules(=0A+ = uint64_t s, uint64_t e, uint32_t size, const module_t *mod,=0A+ = unsigned int nr_mods, unsigned int this_mod)=0A+{=0A+ unsigned int = i;=0A+=0A+ if ( s > e || e - s < size )=0A+ return 0;=0A+=0A+ = for ( i =3D 0; i < nr_mods ; ++i )=0A+ {=0A+ uint64_t start =3D = (uint64_t)mod[i].mod_start << PAGE_SHIFT;=0A+ uint64_t end =3D = start + PAGE_ALIGN(mod[i].mod_end);=0A+=0A+ if ( i =3D=3D this_mod = )=0A+ continue;=0A+=0A+ if ( s < end && start < e )=0A+ = {=0A+ end =3D consider_modules(end, e, size, mod + i + = 1,=0A+ nr_mods - i - 1, this_mod - i - = 1);=0A+ if ( end )=0A+ return end;=0A+=0A+ = return consider_modules(s, start, size, mod + i + 1,=0A+ = nr_mods - i - 1, this_mod - i - 1);=0A+ }=0A+ = }=0A+=0A+ return e;=0A }=0A =0A static void __init setup_max_pdx(void= )=0A@@ -447,11 +547,10 @@ void __init __start_xen(unsigned long mb=0A {=0A = char *memmap_type =3D NULL;=0A char *cmdline, *kextra, *loader;=0A-= unsigned long _initrd_start =3D 0, _initrd_len =3D 0;=0A unsigned = int initrdidx =3D 1;=0A multiboot_info_t *mbi =3D __va(mbi_p);=0A = module_t *mod =3D (module_t *)__va(mbi->mods_addr);=0A- unsigned long = nr_pages, modules_length, modules_headroom;=0A+ unsigned long nr_pages, = modules_headroom;=0A int i, j, e820_warn =3D 0, bytes =3D 0;=0A = bool_t acpi_boot_table_init_done =3D 0;=0A struct ns16550_defaults = ns16550 =3D {=0A@@ -647,6 +746,9 @@ void __init __start_xen(unsigned long = mb=0A set_kexec_crash_area_size((u64)nr_pages << PAGE_SHIFT);=0A = kexec_reserve_area(&boot_e820);=0A =0A+ initial_images =3D mod;=0A+ = nr_initial_images =3D mbi->mods_count;=0A+=0A /*=0A * Iterate = backwards over all superpage-aligned RAM regions.=0A * =0A@@ -660,48 = +762,64 @@ void __init __start_xen(unsigned long mb=0A * we can = relocate the dom0 kernel and other multiboot modules. Also, on=0A * = x86/64, we relocate Xen to higher memory.=0A */=0A- modules_length = =3D 0;=0A for ( i =3D 0; i < mbi->mods_count; i++ )=0A- = modules_length +=3D mod[i].mod_end - mod[i].mod_start;=0A+ {=0A+ = if ( mod[i].mod_start & (PAGE_SIZE - 1) )=0A+ EARLY_FAIL("Bootlo= ader didn't honor module alignment request.\n");=0A+ mod[i].mod_end = -=3D mod[i].mod_start;=0A+ mod[i].mod_start >>=3D PAGE_SHIFT;=0A+ = mod[i].reserved =3D 0;=0A+ }=0A =0A- /* ensure mod[0] is mapped = before parsing */=0A- bootstrap_map(mod[0].mod_start, mod[0].mod_end);= =0A- modules_headroom =3D bzimage_headroom(=0A- = (char *)(unsigned long)mod[0].mod_start,=0A- = (unsigned long)(mod[0].mod_end - mod[0].mod_start));=0A+ modules_headroo= m =3D bzimage_headroom(bootstrap_map(mod), mod->mod_end);=0A+ bootstrap_= map(NULL);=0A =0A for ( i =3D boot_e820.nr_map-1; i >=3D 0; i-- )=0A = {=0A uint64_t s, e, mask =3D (1UL << L2_PAGETABLE_SHIFT) - = 1;=0A+ uint64_t end, limit =3D ARRAY_SIZE(l2_identmap) << L2_PAGETAB= LE_SHIFT;=0A =0A- /* Superpage-aligned chunks from 16MB to = BOOTSTRAP_DIRECTMAP_END. */=0A+ /* Superpage-aligned chunks from = BOOTSTRAP_MAP_BASE. */=0A s =3D (boot_e820.map[i].addr + mask) & = ~mask;=0A e =3D (boot_e820.map[i].addr + boot_e820.map[i].size) & = ~mask;=0A- s =3D max_t(uint64_t, s, 16 << 20);=0A- e =3D = min_t(uint64_t, e, BOOTSTRAP_DIRECTMAP_END);=0A+ s =3D max_t(uint64_= t, s, BOOTSTRAP_MAP_BASE);=0A if ( (boot_e820.map[i].type !=3D = E820_RAM) || (s >=3D e) )=0A continue;=0A =0A- = set_pdx_range(s >> PAGE_SHIFT, e >> PAGE_SHIFT);=0A-=0A- /* Map the = chunk. No memory will need to be allocated to do this. */=0A- = map_pages_to_xen(=0A- (unsigned long)maddr_to_bootstrap_virt(s),= =0A- s >> PAGE_SHIFT, (e-s) >> PAGE_SHIFT, PAGE_HYPERVISOR);=0A+= if ( s < limit )=0A+ {=0A+ end =3D min(e, = limit);=0A+ set_pdx_range(s >> PAGE_SHIFT, end >> PAGE_SHIFT);= =0A+#ifdef CONFIG_X86_64=0A+ map_pages_to_xen((unsigned = long)__va(s), s >> PAGE_SHIFT,=0A+ (end - s) = >> PAGE_SHIFT, PAGE_HYPERVISOR);=0A+#endif=0A+ }=0A =0A #if = defined(CONFIG_X86_64)=0A+ e =3D min_t(uint64_t, e, 1ULL << = (PAGE_SHIFT + 32));=0A #define reloc_size ((__pa(&_end) + mask) & = ~mask)=0A /* Is the region suitable for relocating Xen? */=0A- = if ( !xen_phys_start && ((e-s) >=3D reloc_size) )=0A+ if ( = !xen_phys_start && e <=3D limit )=0A+ {=0A+ /* Don't = overlap with modules. */=0A+ end =3D consider_modules(s, e, = reloc_size + mask,=0A+ mod, mbi->mods_cou= nt, -1);=0A+ end &=3D ~mask;=0A+ }=0A+ else=0A+ = end =3D 0;=0A+ if ( end > s )=0A {=0A = extern l2_pgentry_t l2_xenmap[];=0A l4_pgentry_t *pl4e;=0A = l3_pgentry_t *pl3e;=0A l2_pgentry_t *pl2e;=0A = int i, j, k;=0A+ void *dst;=0A =0A /* Select = relocation address. */=0A- e -=3D reloc_size;=0A+ e = =3D end - reloc_size;=0A xen_phys_start =3D e;=0A = bootsym(trampoline_xen_phys_start) =3D e;=0A =0A@@ -712,10 +830,10 @@ void = __init __start_xen(unsigned long mb=0A * data until after we = have switched to the relocated pagetables!=0A */=0A = barrier();=0A- move_memory(e, 0, __pa(&_end) - xen_phys_start)= ;=0A+ dst =3D move_memory(e, 0, (unsigned long)&_end - = XEN_VIRT_START, 1);=0A =0A /* Poison low 1MB to detect stray = pointers to physical 0-1MB. */=0A- memset(maddr_to_bootstrap_vir= t(e), 0x55, 1U<<20);=0A+ memset(dst, 0x55, 1U << 20);=0A =0A = /* Walk initial pagetables, relocating page directory entries. = */=0A pl4e =3D __va(__pa(idle_pg_table));=0A@@ -772,38 +890,58 = @@ void __init __start_xen(unsigned long mb=0A "movq = %%rsi,%%cr4 " /* CR4.PGE =3D=3D 1 */=0A : : "r" = (__pa(idle_pg_table)), "S" (cpu0_stack),=0A "D" (__va(__pa(= cpu0_stack))), "c" (STACK_SIZE) : "memory" );=0A+=0A+ bootstrap_= map(NULL);=0A }=0A #endif=0A =0A /* Is the region suitable = for relocating the multiboot modules? */=0A- if ( !initial_images_st= art && (s < e) &&=0A- ((e-s) >=3D (modules_length+modules_headr= oom)) )=0A+ for ( j =3D mbi->mods_count - 1; j >=3D 0; j-- )=0A = {=0A- initial_images_end =3D e;=0A- initial_image= s_start =3D initial_images_end - modules_length;=0A- initial_ima= ges_base =3D initial_images_start - modules_headroom;=0A- = initial_images_base &=3D PAGE_MASK;=0A- for ( j =3D mbi->mods_co= unt-1; j >=3D 0; j-- )=0A+ unsigned long headroom =3D j ? 0 : = modules_headroom;=0A+ unsigned long size =3D PAGE_ALIGN(headroom= + mod[j].mod_end);=0A+=0A+ if ( mod[j].reserved )=0A+ = continue;=0A+=0A+ /* Don't overlap with other modules. = */=0A+ end =3D consider_modules(s, e, size, mod, mbi->mods_count= , j);=0A+=0A+ if ( s < end &&=0A+ (headroom = ||=0A+ ((end - size) >> PAGE_SHIFT) > mod[j].mod_start) = )=0A {=0A- e -=3D mod[j].mod_end - mod[j].mod_st= art;=0A- move_memory(e, mod[j].mod_start, mod[j].mod_end);= =0A- mod[j].mod_end +=3D e - mod[j].mod_start;=0A- = mod[j].mod_start =3D e;=0A+ move_memory(end - size + = headroom,=0A+ (uint64_t)mod[j].mod_start << = PAGE_SHIFT,=0A+ mod[j].mod_end, 0);=0A+ = mod[j].mod_start =3D (end - size) >> PAGE_SHIFT;=0A+ = mod[j].mod_end +=3D headroom;=0A+ mod[j].reserved =3D 1;=0A = }=0A- e =3D initial_images_base;=0A }=0A = =0A- if ( !kexec_crash_area.start && (s < e) &&=0A- = ((e-s) >=3D kexec_crash_area.size) )=0A+#ifdef CONFIG_X86_32=0A+ /* = Confine the kexec area to below 4Gb. */=0A+ e =3D min_t(uint64_t, = e, 1ULL << 32);=0A+#endif=0A+ /* Don't overlap with modules. */=0A+ = e =3D consider_modules(s, e, PAGE_ALIGN(kexec_crash_area.size),=0A+ = mod, mbi->mods_count, -1);=0A+ if ( = !kexec_crash_area.start && (s < e) )=0A {=0A e =3D (e = - kexec_crash_area.size) & PAGE_MASK;=0A kexec_crash_area.start= =3D e;=0A }=0A }=0A =0A- if ( !initial_images_start )=0A+ = if ( modules_headroom && !mod->reserved )=0A EARLY_FAIL("Not = enough memory to relocate the dom0 kernel image.\n");=0A- reserve_e820_r= am(&boot_e820, initial_images_base, initial_images_end);=0A+ for ( i = =3D 0; i < mbi->mods_count; ++i )=0A+ {=0A+ uint64_t s =3D = (uint64_t)mod[i].mod_start << PAGE_SHIFT;=0A+=0A+ reserve_e820_ram(&= boot_e820, s, s + PAGE_ALIGN(mod[i].mod_end));=0A+ }=0A =0A #if = defined(CONFIG_X86_32)=0A xenheap_initial_phys_start =3D (PFN_UP(__pa(&= _end)) + 1) << PAGE_SHIFT;=0A@@ -827,7 +965,10 @@ void __init __start_xen(u= nsigned long mb=0A */=0A for ( i =3D 0; i < boot_e820.nr_map; i++ = )=0A {=0A- uint64_t s, e, map_s, map_e, mask =3D PAGE_SIZE - = 1;=0A+ uint64_t s, e, mask =3D PAGE_SIZE - 1;=0A+#ifdef CONFIG_X86_6= 4=0A+ uint64_t map_s, map_e;=0A+#endif=0A =0A /* Only page = alignment required now. */=0A s =3D (boot_e820.map[i].addr + mask) = & ~mask;=0A@@ -842,7 +983,7 @@ void __init __start_xen(unsigned long mb=0A = =0A #ifdef __x86_64__=0A if ( !acpi_boot_table_init_done &&=0A- = s >=3D BOOTSTRAP_DIRECTMAP_END &&=0A+ s >=3D (1ULL << = 32) &&=0A !acpi_boot_table_init() )=0A {=0A = acpi_boot_table_init_done =3D 1;=0A@@ -881,26 +1022,60 @@ void __init = __start_xen(unsigned long mb=0A =0A set_pdx_range(s >> PAGE_SHIFT, = e >> PAGE_SHIFT);=0A =0A- /* Need to create mappings above 16MB. = */=0A- map_s =3D max_t(uint64_t, s, 16<<20);=0A- map_e =3D = e;=0A-#if defined(CONFIG_X86_32) /* mappings are truncated on x86_32 = */=0A- map_e =3D min_t(uint64_t, map_e, BOOTSTRAP_DIRECTMAP_END);=0A= -#endif=0A+#ifdef CONFIG_X86_64=0A+ /* Need to create mappings = above BOOTSTRAP_MAP_BASE. */=0A+ map_s =3D max_t(uint64_t, s, = BOOTSTRAP_MAP_BASE);=0A+ map_e =3D min_t(uint64_t, e,=0A+ = ARRAY_SIZE(l2_identmap) << L2_PAGETABLE_SHIFT);=0A =0A = /* Pass mapped memory to allocator /before/ creating new mappings. */=0A- = init_boot_pages(s, min_t(uint64_t, map_s, e));=0A+ init_boot_p= ages(s, min(map_s, e));=0A+ s =3D map_s;=0A+ if ( s < map_e = )=0A+ {=0A+ uint64_t mask =3D (1UL << L2_PAGETABLE_SHIFT)= - 1;=0A+=0A+ map_s =3D (s + mask) & ~mask;=0A+ = map_e &=3D ~mask;=0A+ init_boot_pages(map_s, map_e);=0A+ = }=0A+=0A+ if ( map_s > map_e )=0A+ map_s =3D map_e =3D = s;=0A =0A /* Create new mappings /before/ passing memory to the = allocator. */=0A- if ( map_s < map_e )=0A- map_pages_to_x= en(=0A- (unsigned long)maddr_to_bootstrap_virt(map_s),=0A- = map_s >> PAGE_SHIFT, (map_e-map_s) >> PAGE_SHIFT,=0A- = PAGE_HYPERVISOR);=0A+ if ( map_e < e )=0A+ {=0A+ = map_pages_to_xen((unsigned long)__va(map_e), map_e >> PAGE_SHIFT,=0A= + (e - map_e) >> PAGE_SHIFT, PAGE_HYPERVISOR);= =0A+ init_boot_pages(map_e, e);=0A+ }=0A+ if ( s = < map_s )=0A+ {=0A+ map_pages_to_xen((unsigned long)__va(= s), s >> PAGE_SHIFT,=0A+ (map_s - s) >> = PAGE_SHIFT, PAGE_HYPERVISOR);=0A+ init_boot_pages(s, map_s);=0A+= }=0A+#else=0A+ init_boot_pages(s, e);=0A+#endif=0A+ }=0A = =0A- /* Pass remainder of this memory chunk to the allocator. = */=0A- init_boot_pages(map_s, e);=0A+ for ( i =3D 0; i < = mbi->mods_count; ++i )=0A+ {=0A+ set_pdx_range(mod[i].mod_start,= =0A+ mod[i].mod_start + PFN_UP(mod[i].mod_end));=0A+#i= fdef CONFIG_X86_64=0A+ map_pages_to_xen((unsigned long)mfn_to_virt(m= od[i].mod_start),=0A+ mod[i].mod_start,=0A+ = PFN_UP(mod[i].mod_end), PAGE_HYPERVISOR);=0A+#endif=0A = }=0A+#ifdef CONFIG_X86_64=0A+ map_pages_to_xen((unsigned long)__va(kexe= c_crash_area.start),=0A+ kexec_crash_area.start >> = PAGE_SHIFT,=0A+ PFN_UP(kexec_crash_area.size), = PAGE_HYPERVISOR);=0A+#endif=0A =0A memguard_init();=0A =0A@@ -1023,7 = +1198,7 @@ void __init __start_xen(unsigned long mb=0A =0A init_IRQ();= =0A =0A- xsm_init(&initrdidx, mbi, initial_images_start);=0A+ = xsm_init(&initrdidx, mbi, bootstrap_map);=0A =0A timer_init();=0A = =0A@@ -1135,12 +1310,6 @@ void __init __start_xen(unsigned long mb=0A = cmdline =3D dom0_cmdline;=0A }=0A =0A- if ( (initrdidx > 0) && = (initrdidx < mbi->mods_count) )=0A- {=0A- _initrd_start =3D = mod[initrdidx].mod_start;=0A- _initrd_len =3D mod[initrdidx].mod_e= nd - mod[initrdidx].mod_start;=0A- }=0A-=0A if ( xen_cpuidle )=0A = xen_processor_pmbits |=3D XEN_PROCESSOR_PM_CX;=0A =0A@@ -1148,13 = +1317,10 @@ void __init __start_xen(unsigned long mb=0A * We're going = to setup domain0 using the module(s) that we stashed safely=0A * = above our heap. The second module, if present, is an initrd ramdisk.=0A = */=0A- if ( construct_dom0(dom0,=0A- initial_im= ages_base,=0A- initial_images_start,=0A- = mod[0].mod_end-mod[0].mod_start,=0A- = _initrd_start,=0A- _initrd_len,=0A- = cmdline) !=3D 0)=0A+ if ( construct_dom0(dom0, mod, modules_headr= oom,=0A+ (initrdidx > 0) && (initrdidx < mbi->mods_c= ount)=0A+ ? mod + initrdidx : NULL,=0A+ = bootstrap_map, cmdline) !=3D 0)=0A panic("Could not set = up DOM0 guest OS\n");=0A =0A /* Scrub RAM that is still free and so = may go to an unprivileged domain. */=0A--- 2010-11-09.orig/xen/arch/x86/x86= _64/mm.c 2010-09-06 08:21:15.000000000 +0200=0A+++ 2010-11-09/xen/ar= ch/x86/x86_64/mm.c 2010-11-09 10:30:06.000000000 +0100=0A@@ -65,6 = +65,12 @@ l3_pgentry_t __attribute__ ((__section__=0A l2_pgentry_t = __attribute__ ((__section__ (".bss.page_aligned")))=0A l2_xenmap[L2_PAG= ETABLE_ENTRIES];=0A =0A+/* Enough page directories to map into the bottom = 1GB. */=0A+l3_pgentry_t __attribute__ ((__section__ (".bss.page_aligned")))= =0A+ l3_bootmap[L3_PAGETABLE_ENTRIES];=0A+l2_pgentry_t __attribute__ = ((__section__ (".bss.page_aligned")))=0A+ l2_bootmap[L2_PAGETABLE_ENTRIE= S];=0A+=0A int __mfn_valid(unsigned long mfn)=0A {=0A return likely(mfn= < max_page) &&=0A--- 2010-11-09.orig/xen/include/asm-x86/domain.h = 2010-11-05 09:22:58.000000000 +0100=0A+++ 2010-11-09/xen/include/asm-x86/do= main.h 2010-11-09 10:30:06.000000000 +0100=0A@@ -466,16 +466,6 @@ void = domain_cpuid(struct domain *d,=0A unsigned int *ecx,=0A = unsigned int *edx);=0A =0A-int construct_dom0(=0A- = struct domain *d,=0A- unsigned long image_base,=0A- unsigned long = image_start, unsigned long image_len,=0A- unsigned long initrd_start, = unsigned long initrd_len,=0A- char *cmdline);=0A-=0A-extern unsigned = long initial_images_nrpages(void);=0A-extern void discard_initial_images(vo= id);=0A-=0A #endif /* __ASM_DOMAIN_H__ */=0A =0A /*=0A--- 2010-11-09.orig/x= en/include/asm-x86/hvm/svm/amd-iommu-proto.h 2010-06-01 13:39:57.0000000= 00 +0200=0A+++ 2010-11-09/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h = 2010-11-09 10:30:06.000000000 +0100=0A@@ -30,7 +30,6 @@=0A = &amd_iommu_head, list)=0A =0A #define DMA_32BIT_MASK 0x00000000ffffffffULL= =0A-#define PAGE_ALIGN(addr) (((addr) + PAGE_SIZE - 1) & PAGE_MASK)=0A = =0A extern int amd_iommu_debug;=0A extern int amd_iommu_perdev_intremap;=0A= --- 2010-11-09.orig/xen/include/asm-x86/page.h 2010-05-28 13:59:16.0000000= 00 +0200=0A+++ 2010-11-09/xen/include/asm-x86/page.h 2010-11-09 = 10:30:06.000000000 +0100=0A@@ -302,6 +302,7 @@ extern l2_pgentry_t = idle_pg_table_l2[=0A extern l2_pgentry_t *compat_idle_pg_table_l2;=0A = extern unsigned int m2p_compat_vstart;=0A #endif=0A+extern l2_pgentry_t = l2_identmap[4*L2_PAGETABLE_ENTRIES];=0A void paging_init(void);=0A void = setup_idle_pagetable(void);=0A #endif /* !defined(__ASSEMBLY__) */=0A@@ = -397,6 +398,7 @@ static inline uint32_t cacheattr_to_pte_=0A =0A #define = PFN_DOWN(x) ((x) >> PAGE_SHIFT)=0A #define PFN_UP(x) (((x) + = PAGE_SIZE-1) >> PAGE_SHIFT)=0A+#define PAGE_ALIGN(x) (((x) + PAGE_SIZE - = 1) & PAGE_MASK)=0A =0A #endif /* __X86_PAGE_H__ */=0A =0A--- 2010-11-09.ori= g/xen/include/asm-x86/setup.h 2010-05-20 09:59:27.000000000 +0200=0A+++ = 2010-11-09/xen/include/asm-x86/setup.h 2010-11-09 10:30:06.000000000 = +0100=0A@@ -1,6 +1,8 @@=0A #ifndef __X86_SETUP_H_=0A #define __X86_SETUP_H_= =0A =0A+#include =0A+=0A extern int early_boot;=0A extern = unsigned long xenheap_initial_phys_start;=0A =0A@@ -25,4 +27,14 @@ void = init_IRQ(void);=0A void vesa_init(void);=0A void vesa_mtrr_init(void);=0A = =0A+int construct_dom0(=0A+ struct domain *d,=0A+ const module_t = *kernel, unsigned long kernel_headroom,=0A+ const module_t *initrd,=0A+ = void *(*bootstrap_map)(const module_t *),=0A+ char *cmdline);=0A+=0A+= unsigned long initial_images_nrpages(void);=0A+void discard_initial_images(= void);=0A+=0A #endif=0A--- 2010-11-09.orig/xen/include/xsm/xsm.h = 2010-11-09 08:25:42.000000000 +0100=0A+++ 2010-11-09/xen/include/xsm/xsm.h = 2010-11-09 10:30:06.000000000 +0100=0A@@ -432,14 +432,15 @@ static inline = long __do_xsm_op (XEN_GUES=0A =0A #ifdef XSM_ENABLE=0A extern int = xsm_init(unsigned int *initrdidx, const multiboot_info_t *mbi,=0A- = unsigned long initial_images_start);=0A+ = void *(*bootstrap_map)(const module_t *));=0A extern int = xsm_policy_init(unsigned int *initrdidx, const multiboot_info_t *mbi,=0A- = unsigned long initial_images_start= );=0A+ void *(*bootstrap_map)(const module_t = *));=0A extern int register_xsm(struct xsm_operations *ops);=0A extern int = unregister_xsm(struct xsm_operations *ops);=0A #else=0A static inline int = xsm_init (unsigned int *initrdidx,=0A- const multiboot_info_= t *mbi, unsigned long initial_images_start)=0A+ = const multiboot_info_t *mbi,=0A+ void *(*bootstr= ap_map)(const module_t *))=0A {=0A return 0;=0A }=0A--- 2010-11-09.orig= /xen/xsm/xsm_core.c 2009-10-07 13:31:36.000000000 +0200=0A+++ = 2010-11-09/xen/xsm/xsm_core.c 2010-11-09 10:30:06.000000000 +0100=0A@@ = -47,7 +47,7 @@ static void __init do_xsm_initcalls(void=0A }=0A =0A int = __init xsm_init(unsigned int *initrdidx, const multiboot_info_t *mbi,=0A- = unsigned long initial_images_start)=0A+ = void *(*bootstrap_map)(const module_t *))=0A {=0A int ret =3D 0;=0A = =0A@@ -55,9 +55,10 @@ int __init xsm_init(unsigned int *initrd=0A =0A = if ( XSM_MAGIC )=0A {=0A- ret =3D xsm_policy_init(initrdidx, = mbi, initial_images_start);=0A+ ret =3D xsm_policy_init(initrdidx, = mbi, bootstrap_map);=0A if ( ret )=0A {=0A+ = bootstrap_map(NULL);=0A printk("%s: Error initializing = policy.\n", __FUNCTION__);=0A return -EINVAL;=0A = }=0A@@ -65,6 +66,7 @@ int __init xsm_init(unsigned int *initrd=0A =0A = if ( verify(&dummy_xsm_ops) )=0A {=0A+ bootstrap_map(NULL);=0A = printk("%s could not verify "=0A "dummy_xsm_ops = structure.\n", __FUNCTION__);=0A return -EIO;=0A@@ -72,6 +74,7 @@ = int __init xsm_init(unsigned int *initrd=0A =0A xsm_ops =3D &dummy_xsm_= ops;=0A do_xsm_initcalls();=0A+ bootstrap_map(NULL);=0A =0A = return 0;=0A }=0A--- 2010-11-09.orig/xen/xsm/xsm_policy.c 2007-11-02 = 17:25:59.000000000 +0100=0A+++ 2010-11-09/xen/xsm/xsm_policy.c 2010-11-09 = 10:30:06.000000000 +0100=0A@@ -22,11 +22,11 @@=0A #include =0A = #include =0A =0A-char *policy_buffer =3D NULL;=0A-u32 = policy_size =3D 0;=0A+char *__initdata policy_buffer =3D NULL;=0A+u32 = __initdata policy_size =3D 0;=0A =0A int xsm_policy_init(unsigned int = *initrdidx, const multiboot_info_t *mbi,=0A- = unsigned long initial_images_start)=0A+ void *(*bootstra= p_map)(const module_t *))=0A {=0A int i;=0A module_t *mod =3D = (module_t *)__va(mbi->mods_addr);=0A@@ -40,15 +40,8 @@ int xsm_policy_init(= unsigned int *initrd=0A */=0A for ( i =3D mbi->mods_count-1; i = >=3D 1; i-- )=0A {=0A- start =3D initial_images_start + = (mod[i].mod_start-mod[0].mod_start);=0A-#if defined(__i386__)=0A- = _policy_start =3D (u32 *)start;=0A-#elif defined(__x86_64__)=0A- = _policy_start =3D maddr_to_virt(start);=0A-#else=0A- _policy_start = =3D NULL;=0A-#endif=0A- _policy_len =3D mod[i].mod_end - = mod[i].mod_start;=0A+ _policy_start =3D bootstrap_map(mod + i);=0A+ = _policy_len =3D mod[i].mod_end;=0A =0A if ( (xsm_magic_t)(= *_policy_start) =3D=3D XSM_MAGIC )=0A {=0A@@ -63,6 +56,8 @@ int = xsm_policy_init(unsigned int *initrd=0A break;=0A =0A = }=0A+=0A+ bootstrap_map(NULL);=0A }=0A =0A return rc;=0A --=__Part0F2297DC.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part0F2297DC.0__=--