ia64/xen-unstable

changeset 9335:1ecb7f1ddc79

Fix VMX guest can not be created on PAE xen with more than 4G RAM.
Also change v_end type from unsigned long to unsigned long long, for we
will have PAE VMX guest with more than 4G memory on PAE xen.

Signed-off-by: Xin Li <xin.b.li@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Sun Mar 19 18:55:46 2006 +0100 (2006-03-19)
parents 56a775219c88
children cf89e8f0831b
files tools/libxc/xc_hvm_build.c
line diff
     1.1 --- a/tools/libxc/xc_hvm_build.c	Sun Mar 19 18:52:20 2006 +0100
     1.2 +++ b/tools/libxc/xc_hvm_build.c	Sun Mar 19 18:55:46 2006 +0100
     1.3 @@ -51,7 +51,7 @@ loadelfimage(
     1.4      char *elfbase, int xch, uint32_t dom, unsigned long *parray,
     1.5      struct domain_setup_info *dsi);
     1.6  
     1.7 -static unsigned char build_e820map(void *e820_page, unsigned long mem_size)
     1.8 +static unsigned char build_e820map(void *e820_page, unsigned long long mem_size)
     1.9  {
    1.10      struct e820entry *e820entry =
    1.11          (struct e820entry *)(((unsigned char *)e820_page) + E820_MAP_OFFSET);
    1.12 @@ -81,24 +81,24 @@ static unsigned char build_e820map(void 
    1.13  #define STATIC_PAGES    2       /* for ioreq_t and store_mfn */
    1.14      /* Most of the ram goes here */
    1.15      e820entry[nr_map].addr = 0x100000;
    1.16 -    e820entry[nr_map].size = mem_size - 0x100000 - STATIC_PAGES*PAGE_SIZE;
    1.17 +    e820entry[nr_map].size = mem_size - 0x100000 - STATIC_PAGES * PAGE_SIZE;
    1.18      e820entry[nr_map].type = E820_RAM;
    1.19      nr_map++;
    1.20  
    1.21      /* Statically allocated special pages */
    1.22  
    1.23 +    /* For xenstore */
    1.24 +    e820entry[nr_map].addr = mem_size - 2 * PAGE_SIZE;
    1.25 +    e820entry[nr_map].size = PAGE_SIZE;
    1.26 +    e820entry[nr_map].type = E820_XENSTORE;
    1.27 +    nr_map++;
    1.28 +
    1.29      /* Shared ioreq_t page */
    1.30      e820entry[nr_map].addr = mem_size - PAGE_SIZE;
    1.31      e820entry[nr_map].size = PAGE_SIZE;
    1.32      e820entry[nr_map].type = E820_SHARED_PAGE;
    1.33      nr_map++;
    1.34  
    1.35 -    /* For xenstore */
    1.36 -    e820entry[nr_map].addr = mem_size - 2*PAGE_SIZE;
    1.37 -    e820entry[nr_map].size = PAGE_SIZE;
    1.38 -    e820entry[nr_map].type = E820_XENSTORE;
    1.39 -    nr_map++;
    1.40 -
    1.41      e820entry[nr_map].addr = mem_size;
    1.42      e820entry[nr_map].size = 0x3 * PAGE_SIZE;
    1.43      e820entry[nr_map].type = E820_NVS;
    1.44 @@ -117,8 +117,7 @@ static unsigned char build_e820map(void 
    1.45      return (*(((unsigned char *)e820_page) + E820_MAP_NR_OFFSET) = nr_map);
    1.46  }
    1.47  
    1.48 -static void
    1.49 -set_hvm_info_checksum(struct hvm_info_table *t)
    1.50 +static void set_hvm_info_checksum(struct hvm_info_table *t)
    1.51  {
    1.52      uint8_t *ptr = (uint8_t *)t, sum = 0;
    1.53      unsigned int i;
    1.54 @@ -142,19 +141,16 @@ static int set_hvm_info(int xc_handle, u
    1.55      char *va_map;
    1.56      struct hvm_info_table *va_hvm;
    1.57  
    1.58 -
    1.59 -    va_map = xc_map_foreign_range(
    1.60 -        xc_handle,
    1.61 -        dom,
    1.62 -        PAGE_SIZE,
    1.63 -        PROT_READ|PROT_WRITE,
    1.64 -        pfn_list[HVM_INFO_PFN]);
    1.65 +    va_map = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
    1.66 +                                  PROT_READ | PROT_WRITE,
    1.67 +                                  pfn_list[HVM_INFO_PFN]);
    1.68  
    1.69      if ( va_map == NULL )
    1.70          return -1;
    1.71  
    1.72      va_hvm = (struct hvm_info_table *)(va_map + HVM_INFO_OFFSET);
    1.73      memset(va_hvm, 0, sizeof(*va_hvm));
    1.74 +
    1.75      strncpy(va_hvm->signature, "HVM INFO", 8);
    1.76      va_hvm->length       = sizeof(struct hvm_info_table);
    1.77      va_hvm->acpi_enabled = acpi;
    1.78 @@ -183,58 +179,59 @@ static int setup_guest(int xc_handle,
    1.79                         unsigned long *store_mfn)
    1.80  {
    1.81      unsigned long *page_array = NULL;
    1.82 +    unsigned long count, i;
    1.83 +    unsigned long long ptr;
    1.84 +    xc_mmu_t *mmu = NULL;
    1.85  
    1.86 -    unsigned long count, i;
    1.87      shared_info_t *shared_info;
    1.88      void *e820_page;
    1.89      unsigned char e820_map_nr;
    1.90 -    xc_mmu_t *mmu = NULL;
    1.91 -    int rc;
    1.92  
    1.93      struct domain_setup_info dsi;
    1.94 -    unsigned long v_end;
    1.95 +    unsigned long long v_end;
    1.96  
    1.97      unsigned long shared_page_frame = 0;
    1.98      shared_iopage_t *sp;
    1.99  
   1.100      memset(&dsi, 0, sizeof(struct domain_setup_info));
   1.101  
   1.102 -    if ( (rc = parseelfimage(image, image_size, &dsi)) != 0 )
   1.103 +    if ( (parseelfimage(image, image_size, &dsi)) != 0 )
   1.104          goto error_out;
   1.105  
   1.106 -    if ( (dsi.v_start & (PAGE_SIZE-1)) != 0 )
   1.107 +    if ( (dsi.v_kernstart & (PAGE_SIZE - 1)) != 0 )
   1.108      {
   1.109          PERROR("Guest OS must load to a page boundary.\n");
   1.110          goto error_out;
   1.111      }
   1.112  
   1.113      /* memsize is in megabytes */
   1.114 -    v_end              = (unsigned long)memsize << 20;
   1.115 +    v_end = (unsigned long long)memsize << 20;
   1.116  
   1.117      printf("VIRTUAL MEMORY ARRANGEMENT:\n"
   1.118 -           " Loaded HVM loader: %08lx->%08lx\n"
   1.119 -           " TOTAL:         %08lx->%08lx\n",
   1.120 +           "  Loaded HVM loader:    %08lx->%08lx\n"
   1.121 +           "  TOTAL:                %08lx->%016llx\n",
   1.122             dsi.v_kernstart, dsi.v_kernend,
   1.123             dsi.v_start, v_end);
   1.124 -    printf(" ENTRY ADDRESS: %08lx\n", dsi.v_kernentry);
   1.125 +    printf("  ENTRY ADDRESS:        %08lx\n", dsi.v_kernentry);
   1.126  
   1.127 -    if ( (v_end - dsi.v_start) > (nr_pages * PAGE_SIZE) )
   1.128 +    if ( (v_end - dsi.v_start) > ((unsigned long long)nr_pages << PAGE_SHIFT) )
   1.129      {
   1.130 -        ERROR("Initial guest OS requires too much space\n"
   1.131 -               "(%luMB is greater than %luMB limit)\n",
   1.132 -               (v_end-dsi.v_start)>>20, (nr_pages<<PAGE_SHIFT)>>20);
   1.133 +        PERROR("Initial guest OS requires too much space: "
   1.134 +               "(%lluMB is greater than %lluMB limit)\n",
   1.135 +               (unsigned long long)(v_end - dsi.v_start) >> 20,
   1.136 +               ((unsigned long long)nr_pages << PAGE_SHIFT) >> 20);
   1.137          goto error_out;
   1.138      }
   1.139  
   1.140      if ( (page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL )
   1.141      {
   1.142 -        PERROR("Could not allocate memory");
   1.143 +        PERROR("Could not allocate memory.\n");
   1.144          goto error_out;
   1.145      }
   1.146  
   1.147      if ( xc_get_pfn_list(xc_handle, dom, page_array, nr_pages) != nr_pages )
   1.148      {
   1.149 -        PERROR("Could not get the page frame list");
   1.150 +        PERROR("Could not get the page frame list.\n");
   1.151          goto error_out;
   1.152      }
   1.153  
   1.154 @@ -246,20 +243,21 @@ static int setup_guest(int xc_handle,
   1.155      /* Write the machine->phys table entries. */
   1.156      for ( count = 0; count < nr_pages; count++ )
   1.157      {
   1.158 +        ptr = (unsigned long long)page_array[count] << PAGE_SHIFT;
   1.159          if ( xc_add_mmu_update(xc_handle, mmu,
   1.160 -                               (page_array[count] << PAGE_SHIFT) |
   1.161 -                               MMU_MACHPHYS_UPDATE, count) )
   1.162 +                               ptr | MMU_MACHPHYS_UPDATE, count) )
   1.163              goto error_out;
   1.164      }
   1.165  
   1.166 -    if ( set_hvm_info(xc_handle, dom, page_array, vcpus, pae, acpi, apic) ) {
   1.167 -        fprintf(stderr, "Couldn't set hvm info for HVM guest.\n");
   1.168 +    if ( set_hvm_info(xc_handle, dom, page_array, vcpus, pae, acpi, apic) )
   1.169 +    {
   1.170 +        ERROR("Couldn't set hvm info for HVM guest.\n");
   1.171          goto error_out;
   1.172      }
   1.173  
   1.174      if ( (e820_page = xc_map_foreign_range(
   1.175 -         xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
   1.176 -         page_array[E820_MAP_PAGE >> PAGE_SHIFT])) == 0 )
   1.177 +              xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE,
   1.178 +              page_array[E820_MAP_PAGE >> PAGE_SHIFT])) == 0 )
   1.179          goto error_out;
   1.180      memset(e820_page, 0, PAGE_SIZE);
   1.181      e820_map_nr = build_e820map(e820_page, v_end);
   1.182 @@ -267,8 +265,8 @@ static int setup_guest(int xc_handle,
   1.183  
   1.184      /* shared_info page starts its life empty. */
   1.185      if ( (shared_info = xc_map_foreign_range(
   1.186 -         xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
   1.187 -         shared_info_frame)) == 0 )
   1.188 +              xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE,
   1.189 +              shared_info_frame)) == 0 )
   1.190          goto error_out;
   1.191      memset(shared_info, 0, sizeof(shared_info_t));
   1.192      /* Mask all upcalls... */
   1.193 @@ -279,8 +277,8 @@ static int setup_guest(int xc_handle,
   1.194      /* Populate the event channel port in the shared page */
   1.195      shared_page_frame = page_array[(v_end >> PAGE_SHIFT) - 1];
   1.196      if ( (sp = (shared_iopage_t *) xc_map_foreign_range(
   1.197 -         xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
   1.198 -         shared_page_frame)) == 0 )
   1.199 +              xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE,
   1.200 +              shared_page_frame)) == 0 )
   1.201          goto error_out;
   1.202      memset(sp, 0, PAGE_SIZE);
   1.203  
   1.204 @@ -290,7 +288,7 @@ static int setup_guest(int xc_handle,
   1.205  
   1.206          vp_eport = xc_evtchn_alloc_unbound(xc_handle, dom, 0);
   1.207          if ( vp_eport < 0 ) {
   1.208 -            fprintf(stderr, "Couldn't get unbound port from VMX guest.\n");
   1.209 +            PERROR("Couldn't get unbound port from VMX guest.\n");
   1.210              goto error_out;
   1.211          }
   1.212          sp->vcpu_iodata[i].vp_eport = vp_eport;