ia64/xen-unstable

changeset 4225:e23288ce8c14

bitkeeper revision 1.1236.1.92 (423d6436JXz0Sqr0XYUvzrcXNtQ6VA)


I added support to Anthony's vm-tools so that it can start VMX enabled
partitions directly (including forking off a copy of the device-model
with the user's environment variables, such as $DISPLAY). For this I found
it useful to harden xc_vmx_build.c so that it doesn't dump core when called
incorrectly.

Signed-Off-By: Leendert van Doorn <leendert@watson.ibm.com>
Signed-off-by: ian.pratt@cl.cam.ac.uk
author iap10@firebug.cl.cam.ac.uk
date Sun Mar 20 11:53:26 2005 +0000 (2005-03-20)
parents d580210d4a53
children 720d41954256
files tools/libxc/xc_vmx_build.c
line diff
     1.1 --- a/tools/libxc/xc_vmx_build.c	Sun Mar 20 09:40:50 2005 +0000
     1.2 +++ b/tools/libxc/xc_vmx_build.c	Sun Mar 20 11:53:26 2005 +0000
     1.3 @@ -108,7 +108,7 @@ static void build_e820map(struct mem_map
     1.4      mem_mapp->nr_map = nr_map;
     1.5  }
     1.6  
     1.7 -static void zap_mmio_range(int xc_handle, u32 dom,
     1.8 +static int zap_mmio_range(int xc_handle, u32 dom,
     1.9                              l2_pgentry_t *vl2tab,
    1.10                              unsigned long mmio_range_start,
    1.11                              unsigned long mmio_range_size)
    1.12 @@ -123,12 +123,17 @@ static void zap_mmio_range(int xc_handle
    1.13          vl2e = vl2tab[l2_table_offset(mmio_addr)];
    1.14          vl1tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
    1.15                                  PROT_READ|PROT_WRITE, vl2e >> PAGE_SHIFT);
    1.16 +	if (vl1tab == 0) {
    1.17 +	    PERROR("Failed zap MMIO range");
    1.18 +	    return -1;
    1.19 +	}
    1.20          vl1tab[l1_table_offset(mmio_addr)] = 0;
    1.21          munmap(vl1tab, PAGE_SIZE);
    1.22      }
    1.23 +    return 0;
    1.24  }
    1.25  
    1.26 -static void zap_mmio_ranges(int xc_handle, u32 dom,
    1.27 +static int zap_mmio_ranges(int xc_handle, u32 dom,
    1.28                              unsigned long l2tab,
    1.29                              struct mem_map *mem_mapp)
    1.30  {
    1.31 @@ -136,14 +141,17 @@ static void zap_mmio_ranges(int xc_handl
    1.32      l2_pgentry_t *vl2tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
    1.33                                                  PROT_READ|PROT_WRITE,
    1.34                                                  l2tab >> PAGE_SHIFT);
    1.35 +    if (vl2tab == 0)
    1.36 +    	return -1;
    1.37      for (i = 0; i < mem_mapp->nr_map; i++) {
    1.38          if ((mem_mapp->map[i].type == E820_IO)
    1.39            && (mem_mapp->map[i].caching_attr == MEMMAP_UC))
    1.40 -            zap_mmio_range(xc_handle, dom,
    1.41 -                            vl2tab, mem_mapp->map[i].addr,
    1.42 -                            mem_mapp->map[i].size);
    1.43 +            if (zap_mmio_range(xc_handle, dom, vl2tab,
    1.44 +	    		mem_mapp->map[i].addr, mem_mapp->map[i].size) == -1)
    1.45 +		return -1;
    1.46      }
    1.47      munmap(vl2tab, PAGE_SIZE);
    1.48 +    return 0;
    1.49  }
    1.50  
    1.51  static int setup_guest(int xc_handle,
    1.52 @@ -334,9 +342,10 @@ static int setup_guest(int xc_handle,
    1.53                          l2tab | MMU_EXTENDED_COMMAND, MMUEXT_PIN_L2_TABLE) )
    1.54          goto error_out;
    1.55  
    1.56 -    boot_paramsp = xc_map_foreign_range(
    1.57 -        xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
    1.58 -        page_array[(vboot_params_start-dsi.v_start)>>PAGE_SHIFT]);
    1.59 +    if ((boot_paramsp = xc_map_foreign_range(
    1.60 +		xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
    1.61 +		page_array[(vboot_params_start-dsi.v_start)>>PAGE_SHIFT])) == 0)
    1.62 +        goto error_out;
    1.63      memset(boot_paramsp, 0, sizeof(*boot_paramsp));
    1.64  
    1.65      strncpy((char *)boot_paramsp->cmd_line, cmdline, 0x800);
    1.66 @@ -393,7 +402,8 @@ static int setup_guest(int xc_handle,
    1.67  
    1.68      /* memsize is in megabytes */
    1.69      build_e820map(mem_mapp, memsize << 20);
    1.70 -    zap_mmio_ranges(xc_handle, dom, l2tab, mem_mapp);
    1.71 +    if (zap_mmio_ranges(xc_handle, dom, l2tab, mem_mapp) == -1)
    1.72 +    	goto error_out;
    1.73      boot_paramsp->e820_map_nr = mem_mapp->nr_map;
    1.74      for (i=0; i<mem_mapp->nr_map; i++) {
    1.75          boot_paramsp->e820_map[i].addr = mem_mapp->map[i].addr; 
    1.76 @@ -402,9 +412,10 @@ static int setup_guest(int xc_handle,
    1.77      }
    1.78      munmap(boot_paramsp, PAGE_SIZE); 
    1.79  
    1.80 -    boot_gdtp = xc_map_foreign_range(
    1.81 -        xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
    1.82 -        page_array[(vboot_gdt_start-dsi.v_start)>>PAGE_SHIFT]);
    1.83 +    if ((boot_gdtp = xc_map_foreign_range(
    1.84 +		xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
    1.85 +		page_array[(vboot_gdt_start-dsi.v_start)>>PAGE_SHIFT])) == 0)
    1.86 +	goto error_out;
    1.87      memset(boot_gdtp, 0, PAGE_SIZE);
    1.88      boot_gdtp[12*4 + 0] = boot_gdtp[13*4 + 0] = 0xffff; /* limit */
    1.89      boot_gdtp[12*4 + 1] = boot_gdtp[13*4 + 1] = 0x0000; /* base */
    1.90 @@ -413,8 +424,10 @@ static int setup_guest(int xc_handle,
    1.91      munmap(boot_gdtp, PAGE_SIZE);
    1.92  
    1.93      /* shared_info page starts its life empty. */
    1.94 -    shared_info = xc_map_foreign_range(
    1.95 -        xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, shared_info_frame);
    1.96 +    if ((shared_info = xc_map_foreign_range(
    1.97 +		xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
    1.98 +		shared_info_frame)) == 0)
    1.99 +	goto error_out;
   1.100      memset(shared_info, 0, sizeof(shared_info_t));
   1.101      /* Mask all upcalls... */
   1.102      for ( i = 0; i < MAX_VIRT_CPUS; i++ )
   1.103 @@ -720,8 +733,10 @@ loadelfimage(
   1.104          for ( done = 0; done < phdr->p_filesz; done += chunksz )
   1.105          {
   1.106              pa = (phdr->p_paddr + done) - vstart - LINUX_PAGE_OFFSET;
   1.107 -            va = xc_map_foreign_range(
   1.108 -                xch, dom, PAGE_SIZE, PROT_WRITE, parray[pa>>PAGE_SHIFT]);
   1.109 +            if ((va = xc_map_foreign_range(
   1.110 +			xch, dom, PAGE_SIZE, PROT_WRITE,
   1.111 +			parray[pa>>PAGE_SHIFT])) == 0)
   1.112 +		return -1;
   1.113              chunksz = phdr->p_filesz - done;
   1.114              if ( chunksz > (PAGE_SIZE - (pa & (PAGE_SIZE-1))) )
   1.115                  chunksz = PAGE_SIZE - (pa & (PAGE_SIZE-1));
   1.116 @@ -733,8 +748,10 @@ loadelfimage(
   1.117          for ( ; done < phdr->p_memsz; done += chunksz )
   1.118          {
   1.119              pa = (phdr->p_paddr + done) - vstart - LINUX_PAGE_OFFSET;
   1.120 -            va = xc_map_foreign_range(
   1.121 -                xch, dom, PAGE_SIZE, PROT_WRITE, parray[pa>>PAGE_SHIFT]);
   1.122 +            if ((va = xc_map_foreign_range(
   1.123 +			xch, dom, PAGE_SIZE, PROT_WRITE,
   1.124 +			parray[pa>>PAGE_SHIFT])) == 0)
   1.125 +		return -1;
   1.126              chunksz = phdr->p_memsz - done;
   1.127              if ( chunksz > (PAGE_SIZE - (pa & (PAGE_SIZE-1))) )
   1.128                  chunksz = PAGE_SIZE - (pa & (PAGE_SIZE-1));