direct-io.hg
changeset 15011:e370c94bd6fd
hvm: Domains must be at least 2MB in size.
Signed-off-by: Keir Fraser <keir@xensource.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author | Keir Fraser <keir@xensource.com> |
---|---|
date | Sat May 05 13:48:05 2007 +0100 (2007-05-05) |
parents | 195e3dbba3ca |
children | ebe1460ff6ce |
files | tools/libxc/xc_hvm_build.c |
line diff
1.1 --- a/tools/libxc/xc_hvm_build.c Sat May 05 11:23:55 2007 +0100 1.2 +++ b/tools/libxc/xc_hvm_build.c Sat May 05 13:48:05 2007 +0100 1.3 @@ -108,43 +108,45 @@ static void build_e820map(void *e820_pag 1.4 *(((unsigned char *)e820_page) + E820_MAP_NR_OFFSET) = nr_map; 1.5 } 1.6 1.7 -static int 1.8 -loadelfimage(struct elf_binary *elf, int xch, uint32_t dom, unsigned long *parray) 1.9 +static int loadelfimage( 1.10 + struct elf_binary *elf, int xch, uint32_t dom, unsigned long *parray) 1.11 { 1.12 privcmd_mmap_entry_t *entries = NULL; 1.13 int pages = (elf->pend - elf->pstart + PAGE_SIZE - 1) >> PAGE_SHIFT; 1.14 int i, rc = -1; 1.15 1.16 - /* map hvmloader address space */ 1.17 + /* Map address space for initial elf image. */ 1.18 entries = malloc(pages * sizeof(privcmd_mmap_entry_t)); 1.19 - if (NULL == entries) 1.20 + if ( entries == NULL ) 1.21 goto err; 1.22 elf->dest = mmap(NULL, pages << PAGE_SHIFT, PROT_READ | PROT_WRITE, 1.23 MAP_SHARED, xch, 0); 1.24 - if (MAP_FAILED == elf->dest) 1.25 + if ( elf->dest == MAP_FAILED ) 1.26 goto err; 1.27 1.28 - for (i = 0; i < pages; i++) 1.29 + for ( i = 0; i < pages; i++ ) 1.30 { 1.31 entries[i].va = (uintptr_t)elf->dest + (i << PAGE_SHIFT); 1.32 entries[i].mfn = parray[(elf->pstart >> PAGE_SHIFT) + i]; 1.33 entries[i].npages = 1; 1.34 } 1.35 + 1.36 rc = xc_map_foreign_ranges(xch, dom, entries, pages); 1.37 - if (rc < 0) 1.38 + if ( rc < 0 ) 1.39 goto err; 1.40 1.41 - /* load hvmloader */ 1.42 + /* Load the initial elf image. */ 1.43 elf_load_binary(elf); 1.44 rc = 0; 1.45 1.46 err: 1.47 - /* cleanup */ 1.48 - if (elf->dest) { 1.49 + if ( elf->dest ) 1.50 + { 1.51 munmap(elf->dest, pages << PAGE_SHIFT); 1.52 elf->dest = NULL; 1.53 } 1.54 - if (entries) 1.55 + 1.56 + if ( entries ) 1.57 free(entries); 1.58 1.59 return rc; 1.60 @@ -166,13 +168,17 @@ static int setup_guest(int xc_handle, 1.61 int rc; 1.62 xen_capabilities_info_t caps; 1.63 1.64 - if (0 != elf_init(&elf, image, image_size)) 1.65 + /* An HVM guest must be initialised with at least 2MB memory. */ 1.66 + if ( memsize < 2 ) 1.67 + goto error_out; 1.68 + 1.69 + if ( elf_init(&elf, image, image_size) != 0 ) 1.70 goto error_out; 1.71 elf_parse_binary(&elf); 1.72 v_start = 0; 1.73 v_end = (unsigned long long)memsize << 20; 1.74 1.75 - if (xc_version(xc_handle, XENVER_capabilities, &caps) != 0) 1.76 + if ( xc_version(xc_handle, XENVER_capabilities, &caps) != 0 ) 1.77 { 1.78 PERROR("Could not get Xen capabilities\n"); 1.79 goto error_out; 1.80 @@ -185,9 +191,9 @@ static int setup_guest(int xc_handle, 1.81 } 1.82 1.83 IPRINTF("VIRTUAL MEMORY ARRANGEMENT:\n" 1.84 - " Loaded HVM loader: %016"PRIx64"->%016"PRIx64"\n" 1.85 - " TOTAL: %016"PRIx64"->%016"PRIx64"\n" 1.86 - " ENTRY ADDRESS: %016"PRIx64"\n", 1.87 + " Loader: %016"PRIx64"->%016"PRIx64"\n" 1.88 + " TOTAL: %016"PRIx64"->%016"PRIx64"\n" 1.89 + " ENTRY ADDRESS: %016"PRIx64"\n", 1.90 elf.pstart, elf.pend, 1.91 v_start, v_end, 1.92 elf_uval(&elf, elf.ehdr, e_entry)); 1.93 @@ -205,9 +211,8 @@ static int setup_guest(int xc_handle, 1.94 1.95 /* Allocate memory for HVM guest, skipping VGA hole 0xA0000-0xC0000. */ 1.96 rc = xc_domain_memory_populate_physmap( 1.97 - xc_handle, dom, (nr_pages > 0xa0) ? 0xa0 : nr_pages, 1.98 - 0, 0, &page_array[0x00]); 1.99 - if ( (rc == 0) && (nr_pages > 0xc0) ) 1.100 + xc_handle, dom, 0xa0, 0, 0, &page_array[0x00]); 1.101 + if ( rc == 0 ) 1.102 rc = xc_domain_memory_populate_physmap( 1.103 xc_handle, dom, nr_pages - 0xc0, 0, 0, &page_array[0xc0]); 1.104 if ( rc != 0 ) 1.105 @@ -216,7 +221,8 @@ static int setup_guest(int xc_handle, 1.106 goto error_out; 1.107 } 1.108 1.109 - loadelfimage(&elf, xc_handle, dom, page_array); 1.110 + if ( loadelfimage(&elf, xc_handle, dom, page_array) != 0 ) 1.111 + goto error_out; 1.112 1.113 if ( (e820_page = xc_map_foreign_range( 1.114 xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE, 1.115 @@ -328,12 +334,9 @@ static inline int is_loadable_phdr(Elf32 1.116 ((phdr->p_flags & (PF_W|PF_X)) != 0)); 1.117 } 1.118 1.119 -/* xc_hvm_build 1.120 - * 1.121 - * Create a domain for a virtualized Linux, using files/filenames 1.122 - * 1.123 +/* xc_hvm_build: 1.124 + * Create a domain for a virtualized Linux, using files/filenames. 1.125 */ 1.126 - 1.127 int xc_hvm_build(int xc_handle, 1.128 uint32_t domid, 1.129 int memsize, 1.130 @@ -354,12 +357,9 @@ int xc_hvm_build(int xc_handle, 1.131 return sts; 1.132 } 1.133 1.134 -/* xc_hvm_build_mem 1.135 - * 1.136 - * Create a domain for a virtualized Linux, using buffers 1.137 - * 1.138 +/* xc_hvm_build_mem: 1.139 + * Create a domain for a virtualized Linux, using memory buffers. 1.140 */ 1.141 - 1.142 int xc_hvm_build_mem(int xc_handle, 1.143 uint32_t domid, 1.144 int memsize, 1.145 @@ -379,7 +379,7 @@ int xc_hvm_build_mem(int xc_handle, 1.146 } 1.147 1.148 img = xc_inflate_buffer(image_buffer, image_size, &img_len); 1.149 - if (img == NULL) 1.150 + if ( img == NULL ) 1.151 { 1.152 ERROR("unable to inflate ram disk buffer"); 1.153 return -1;