ia64/xen-unstable

changeset 3605:a920f0ced90f

bitkeeper revision 1.1159.212.66 (42001b6f4kUEhmWXQmgg_vNH-AqiWQ)

Right now, the memory for the 1:1 physical mode page tables comes from the
VMX domain's memory. With this change, when the user asks for a domain with
M Megabytes of memory, we actually allocate M+N megabytes in xend, where
N is the memory for the page table pages.

This simplifies the code in the device models that maps guest memory (we
now map all of it) and the E820 map can also give the full M megabytes to
the guest.

Signed-off-by: Xin B Li <xin.b.li@intel.com>
Signed-off-by: Arun Sharma <arun.sharma@intel.com>
Signed-off-by: ian.pratt@cl.cam.ac.uk
author iap10@labyrinth.cl.cam.ac.uk
date Wed Feb 02 00:14:39 2005 +0000 (2005-02-02)
parents d03ad25af1a8
children 281346e5fc97
files tools/ioemu/memory/misc_mem.cc tools/libxc/xc.h tools/libxc/xc_vmx_build.c tools/python/xen/lowlevel/xc/xc.c tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/tools/ioemu/memory/misc_mem.cc	Wed Feb 02 00:12:05 2005 +0000
     1.2 +++ b/tools/ioemu/memory/misc_mem.cc	Wed Feb 02 00:14:39 2005 +0000
     1.3 @@ -174,20 +174,16 @@ BX_MEM_C::init_memory(int memsize)
     1.4  
     1.5  #define PAGE_SHIFT 12
     1.6  #define PAGE_SIZE  (1 << PAGE_SHIFT)
     1.7 -#define round_pgup(x)	(((x) + PAGE_SIZE-1) & ~ (PAGE_SIZE-1))
     1.8  
     1.9 -    int npte_pages = 1 + (round_pgup(nr_pages * 4) / PAGE_SIZE); 
    1.10 -
    1.11 -    /* We don't map pte pages and the top 64k -- XXX: this could be a problem */
    1.12      if ((vector = (Bit8u *) xc_map_foreign_batch(xc_handle, domid,
    1.13                                                   PROT_READ|PROT_WRITE,
    1.14                                                   page_array,
    1.15 -                                                 nr_pages - npte_pages - 16)) == 0) {
    1.16 +                                                 nr_pages - 1)) == 0) {
    1.17          BX_ERROR(("Could not map guest physical"));
    1.18          return;
    1.19      }
    1.20  
    1.21 -    BX_MEM_THIS dma_limit = (nr_pages - npte_pages - 16) << PAGE_SHIFT;
    1.22 +    BX_MEM_THIS dma_limit = (nr_pages - 1) << PAGE_SHIFT;
    1.23      BX_INFO(("DMA limit: %lx", BX_MEM_THIS dma_limit));
    1.24  
    1.25      shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE, 
     2.1 --- a/tools/libxc/xc.h	Wed Feb 02 00:12:05 2005 +0000
     2.2 +++ b/tools/libxc/xc.h	Wed Feb 02 00:14:39 2005 +0000
     2.3 @@ -211,6 +211,7 @@ xc_plan9_build (int xc_handle,
     2.4  struct mem_map;
     2.5  int xc_vmx_build(int xc_handle,
     2.6                   u32 domid,
     2.7 +                 int memsize,
     2.8                   const char *image_name,
     2.9                   struct mem_map *memmap,
    2.10                   const char *ramdisk_name,
     3.1 --- a/tools/libxc/xc_vmx_build.c	Wed Feb 02 00:12:05 2005 +0000
     3.2 +++ b/tools/libxc/xc_vmx_build.c	Wed Feb 02 00:14:39 2005 +0000
     3.3 @@ -47,7 +47,7 @@ loadelfsymtab(
     3.4      struct domain_setup_info *dsi);
     3.5  
     3.6  static int setup_guestos(int xc_handle,
     3.7 -                         u32 dom,
     3.8 +                         u32 dom, int memsize,
     3.9                           char *image, unsigned long image_size,
    3.10                           gzFile initrd_gfd, unsigned long initrd_len,
    3.11                           unsigned long nr_pages,
    3.12 @@ -110,21 +110,23 @@ static int setup_guestos(int xc_handle,
    3.13       * read-only). We have a pair of simultaneous equations in two unknowns, 
    3.14       * which we solve by exhaustive search.
    3.15       */
    3.16 -    nr_pt_pages = 1 + (nr_pages >> (PAGE_SHIFT - 2));
    3.17      vboot_params_start = LINUX_BOOT_PARAMS_ADDR;
    3.18      vboot_params_end   = vboot_params_start + PAGE_SIZE;
    3.19      vboot_gdt_start    = vboot_params_end;
    3.20      vboot_gdt_end      = vboot_gdt_start + PAGE_SIZE;
    3.21 -    v_end              = nr_pages << PAGE_SHIFT;
    3.22 -    vpt_end            = v_end - (16 << PAGE_SHIFT); /* leaving the top 64k untouched */
    3.23 -    vpt_start          = vpt_end - (nr_pt_pages << PAGE_SHIFT);
    3.24 -    vinitrd_end        = vpt_start;
    3.25 +
    3.26 +    v_end              = memsize << 20;
    3.27 +    vinitrd_end        = v_end - PAGE_SIZE; /* leaving the top 4k untouched for IO requests page use */
    3.28      vinitrd_start      = vinitrd_end - initrd_len;
    3.29      vinitrd_start      = vinitrd_start & (~(PAGE_SIZE - 1));
    3.30  
    3.31      if(initrd_len == 0)
    3.32          vinitrd_start = vinitrd_end = 0;
    3.33  
    3.34 +    nr_pt_pages = 1 + ((memsize + 3) >> 2);
    3.35 +    vpt_start   = v_end;
    3.36 +    vpt_end     = vpt_start + (nr_pt_pages * PAGE_SIZE);
    3.37 +
    3.38      printf("VIRTUAL MEMORY ARRANGEMENT:\n"
    3.39             " Boot_params:   %08lx->%08lx\n"
    3.40             " boot_gdt:      %08lx->%08lx\n"
    3.41 @@ -218,9 +220,6 @@ static int setup_guestos(int xc_handle,
    3.42          }
    3.43  
    3.44          *vl1e = (page_array[count] << PAGE_SHIFT) | L1_PROT;
    3.45 -        if ( (count >= ((vpt_start-dsi.v_start)>>PAGE_SHIFT)) && 
    3.46 -             (count <  ((vpt_end  -dsi.v_start)>>PAGE_SHIFT)) )
    3.47 -            *vl1e &= ~_PAGE_RW;
    3.48          vl1e++;
    3.49      }
    3.50      munmap(vl1tab, PAGE_SIZE);
    3.51 @@ -267,7 +266,7 @@ static int setup_guestos(int xc_handle,
    3.52      boot_paramsp->initrd_start = vinitrd_start;
    3.53      boot_paramsp->initrd_size = initrd_len;
    3.54  
    3.55 -    i = (nr_pages >> (PAGE_SHIFT - 10)) - (1 << 10) - 4;
    3.56 +    i = ((memsize - 1) << 10) - 4;
    3.57      boot_paramsp->alt_mem_k = i; /* alt_mem_k */
    3.58      boot_paramsp->screen.overlap.ext_mem_k = i & 0xFFFF; /* ext_mem_k */
    3.59  
    3.60 @@ -374,6 +373,7 @@ int vmx_identify(void)
    3.61  
    3.62  int xc_vmx_build(int xc_handle,
    3.63                     u32 domid,
    3.64 +                   int memsize,
    3.65                     const char *image_name,
    3.66                     struct mem_map *mem_mapp,
    3.67                     const char *ramdisk_name,
    3.68 @@ -445,7 +445,7 @@ int xc_vmx_build(int xc_handle,
    3.69          goto error_out;
    3.70      }
    3.71  
    3.72 -    if ( setup_guestos(xc_handle, domid, image, image_size, 
    3.73 +    if ( setup_guestos(xc_handle, domid, memsize, image, image_size, 
    3.74                         initrd_gfd, initrd_size, nr_pages, 
    3.75                         ctxt, cmdline,
    3.76                         op.u.getdomaininfo.shared_info_frame,
     4.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Wed Feb 02 00:12:05 2005 +0000
     4.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Wed Feb 02 00:14:39 2005 +0000
     4.3 @@ -405,15 +405,18 @@ static PyObject *pyxc_vmx_build(PyObject
     4.4      PyObject *memmap;
     4.5      int   control_evtchn, flags = 0;
     4.6      int numItems, i;
     4.7 +    int memsize;
     4.8      struct mem_map mem_map;
     4.9  
    4.10 -    static char *kwd_list[] = { "dom", "control_evtchn", 
    4.11 +    static char *kwd_list[] = { "dom", "control_evtchn",
    4.12 +                                "memsize",
    4.13                                  "image", "memmap",
    4.14  				"ramdisk", "cmdline", "flags",
    4.15                                  NULL };
    4.16  
    4.17 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iisO!|ssi", kwd_list, 
    4.18 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiisO!|ssi", kwd_list, 
    4.19                                        &dom, &control_evtchn, 
    4.20 +                                      &memsize,
    4.21                                        &image, &PyList_Type, &memmap,
    4.22  				      &ramdisk, &cmdline, &flags) )
    4.23          return NULL;
    4.24 @@ -467,7 +470,7 @@ static PyObject *pyxc_vmx_build(PyObject
    4.25              mem_map.map[i-1].caching_attr = lf4;
    4.26      }
    4.27  
    4.28 -    if ( xc_vmx_build(xc->xc_handle, dom, image, &mem_map,
    4.29 +    if ( xc_vmx_build(xc->xc_handle, dom, memsize, image, &mem_map,
    4.30                          ramdisk, cmdline, control_evtchn, flags) != 0 )
    4.31          return PyErr_SetFromErrno(xc_error);
    4.32      
     5.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Wed Feb 02 00:12:05 2005 +0000
     5.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Wed Feb 02 00:14:39 2005 +0000
     5.3 @@ -320,6 +320,7 @@ class XendDomainInfo:
     5.4          self.restart_time = None
     5.5          self.console_port = None
     5.6          self.savedinfo = None
     5.7 +        self.image_handler = None
     5.8          self.is_vmx = 0
     5.9          self.vcpus = 1
    5.10  
    5.11 @@ -455,6 +456,7 @@ class XendDomainInfo:
    5.12              except:
    5.13                  raise VmError('invalid vcpus value')
    5.14  
    5.15 +            self.find_image_handler()
    5.16              self.init_domain()
    5.17              self.configure_console()
    5.18              self.configure_backends()
    5.19 @@ -471,7 +473,7 @@ class XendDomainInfo:
    5.20              raise
    5.21          return deferred
    5.22  
    5.23 -    def construct_image(self):
    5.24 +    def find_image_handler(self):
    5.25          """Construct the boot image for the domain.
    5.26  
    5.27          @return vm
    5.28 @@ -482,10 +484,17 @@ class XendDomainInfo:
    5.29          image_name = sxp.name(image)
    5.30          if image_name is None:
    5.31              raise VmError('missing image name')
    5.32 +        if image_name == "vmx":
    5.33 +            self.is_vmx = 1
    5.34          image_handler = get_image_handler(image_name)
    5.35          if image_handler is None:
    5.36              raise VmError('unknown image type: ' + image_name)
    5.37 -        image_handler(self, image)
    5.38 +        self.image_handler = image_handler
    5.39 +        return self
    5.40 +
    5.41 +    def construct_image(self):
    5.42 +        image = sxp.child_value(self.config, 'image')
    5.43 +        self.image_handler(self, image)
    5.44          return self
    5.45  
    5.46      def config_devices(self, name):
    5.47 @@ -730,7 +739,8 @@ class XendDomainInfo:
    5.48          except:
    5.49              raise VmError('invalid cpu')
    5.50          cpu_weight = self.cpu_weight
    5.51 -        dom = xc.domain_create(dom= dom, mem_kb= memory * 1024,
    5.52 +        memory = memory * 1024 + self.pgtable_size(memory)
    5.53 +        dom = xc.domain_create(dom= dom, mem_kb= memory,
    5.54                                 cpu= cpu, cpu_weight= cpu_weight)
    5.55          if dom <= 0:
    5.56              raise VmError('Creating domain failed: name=%s memory=%d'
    5.57 @@ -757,6 +767,7 @@ class XendDomainInfo:
    5.58          	err = buildfn(dom      = dom,
    5.59                 	      	image          = kernel,
    5.60                        	control_evtchn = 0,
    5.61 +                        memsize        = self.memory,
    5.62  			memmap	       = memmap,
    5.63                        	cmdline        = cmdline,
    5.64                        	ramdisk        = ramdisk,
    5.65 @@ -1084,6 +1095,18 @@ class XendDomainInfo:
    5.66          d.addErrback(dlist_err)
    5.67          return d
    5.68  
    5.69 +    def pgtable_size(self, memory):
    5.70 +        """Return the size of memory needed for 1:1 page tables for physical
    5.71 +           mode.
    5.72 +
    5.73 +        @param memory: size in MB
    5.74 +        @return size in KB
    5.75 +        """
    5.76 +        if self.is_vmx:
    5.77 +            # Logic x86-32 specific. 
    5.78 +            # 1 page for the PGD + 1 pte page for 4MB of memory (rounded)
    5.79 +            return (1 + ((memory + 3) >> 2)) * 4
    5.80 +        return 0
    5.81  
    5.82  def vm_image_linux(vm, image):
    5.83      """Create a VM for a linux image.
    5.84 @@ -1159,7 +1182,6 @@ def vm_image_vmx(vm, image):
    5.85      from xen.util.memmap import memmap_parse
    5.86      memmap = memmap_parse(memmap)
    5.87      vm.create_domain("vmx", kernel, ramdisk, cmdline, memmap)
    5.88 -    vm.is_vmx = 1
    5.89      return vm
    5.90  
    5.91  def vm_dev_vif(vm, val, index, change=0):