xen-vtx-unstable
changeset 6688:5db85ba1c4e0
Improved "PGDs must be under 4GB" handling for PAE.
Signed-off-by: ian@xensource.com
Signed-off-by: ian@xensource.com
author | iap10@freefall.cl.cam.ac.uk |
---|---|
date | Thu Sep 08 17:36:23 2005 +0000 (2005-09-08) |
parents | 1f4863861d18 |
children | 3bde4219c681 |
files | tools/libxc/xc_domain.c tools/libxc/xc_linux_build.c tools/libxc/xc_linux_restore.c tools/libxc/xc_private.c tools/libxc/xenctrl.h tools/python/xen/lowlevel/xc/xc.c tools/python/xen/xend/image.py |
line diff
1.1 --- a/tools/libxc/xc_domain.c Thu Sep 08 17:35:44 2005 +0000 1.2 +++ b/tools/libxc/xc_domain.c Thu Sep 08 17:36:23 2005 +0000 1.3 @@ -262,28 +262,66 @@ int xc_domain_setmaxmem(int xc_handle, 1.4 1.5 int xc_domain_memory_increase_reservation(int xc_handle, 1.6 u32 domid, 1.7 - unsigned long mem_kb, 1.8 + unsigned long nr_extents, 1.9 unsigned int extent_order, 1.10 - unsigned int address_bits) 1.11 + unsigned int address_bits, 1.12 + unsigned long *extent_start) 1.13 { 1.14 int err; 1.15 - unsigned int npages = mem_kb / (PAGE_SIZE/1024); 1.16 struct xen_memory_reservation reservation = { 1.17 - .nr_extents = npages, 1.18 - .extent_order = extent_order, 1.19 + .extent_start = extent_start, /* may be NULL */ 1.20 + .nr_extents = nr_extents, 1.21 + .extent_order = extent_order, 1.22 .address_bits = address_bits, 1.23 .domid = domid 1.24 }; 1.25 1.26 err = xc_memory_op(xc_handle, XENMEM_increase_reservation, &reservation); 1.27 - if (err == npages) 1.28 + if (err == nr_extents) 1.29 return 0; 1.30 1.31 if (err > 0) { 1.32 - fprintf(stderr,"Failed alocation for dom %d : %d pages order %d addr_bits %d\n", 1.33 - domid, npages, extent_order, address_bits); 1.34 + fprintf(stderr,"Failed alocation for dom %d : %ld pages order %d addr_bits %d\n", 1.35 + domid, nr_extents, extent_order, address_bits); 1.36 errno = ENOMEM; 1.37 err = -1; 1.38 } 1.39 return err; 1.40 } 1.41 + 1.42 +int xc_domain_memory_decrease_reservation(int xc_handle, 1.43 + u32 domid, 1.44 + unsigned long nr_extents, 1.45 + unsigned int extent_order, 1.46 + unsigned long *extent_start) 1.47 +{ 1.48 + int err; 1.49 + struct xen_memory_reservation reservation = { 1.50 + .extent_start = extent_start, 1.51 + .nr_extents = nr_extents, 1.52 + .extent_order = extent_order, 1.53 + .address_bits = 0, 1.54 + .domid = domid 1.55 + }; 1.56 + 1.57 + if (extent_start == NULL) 1.58 + { 1.59 + fprintf(stderr,"decrease_reservation extent_start is NULL!\n"); 1.60 + errno = EINVAL; 1.61 + err = -1; 1.62 + goto out; 1.63 + } 1.64 + 1.65 + err = xc_memory_op(xc_handle, XENMEM_increase_reservation, &reservation); 1.66 + if (err == nr_extents) 1.67 + return 0; 1.68 + 1.69 + if (err > 0) { 1.70 + fprintf(stderr,"Failed de-alocation for dom %d : %ld pages order %d\n", 1.71 + domid, nr_extents, extent_order); 1.72 + errno = EBUSY; 1.73 + err = -1; 1.74 + } 1.75 +out: 1.76 + return err; 1.77 +}
2.1 --- a/tools/libxc/xc_linux_build.c Thu Sep 08 17:35:44 2005 +0000 2.2 +++ b/tools/libxc/xc_linux_build.c Thu Sep 08 17:36:23 2005 +0000 2.3 @@ -136,11 +136,24 @@ static int setup_pg_tables_pae(int xc_ha 2.4 2.5 /* First allocate page for page dir. */ 2.6 ppt_alloc = (vpt_start - dsi_v_start) >> PAGE_SHIFT; 2.7 + 2.8 + if ( page_array[ppt_alloc] > 0xfffff ) 2.9 + { 2.10 + unsigned long nmfn; 2.11 + nmfn = xc_make_page_below_4G( xc_handle, dom, page_array[ppt_alloc] ); 2.12 + if ( nmfn == 0 ) 2.13 + { 2.14 + fprintf(stderr, "Couldn't get a page below 4GB :-(\n"); 2.15 + goto error_out; 2.16 + } 2.17 + page_array[ppt_alloc] = nmfn; 2.18 + } 2.19 + 2.20 alloc_pt(l3tab, vl3tab); 2.21 vl3e = &vl3tab[l3_table_offset_pae(dsi_v_start)]; 2.22 ctxt->ctrlreg[3] = l3tab; 2.23 2.24 - if(l3tab>0xfffff000) 2.25 + if(l3tab>0xfffff000ULL) 2.26 { 2.27 fprintf(stderr,"L3TAB = %llx above 4GB!\n",l3tab); 2.28 goto error_out;
3.1 --- a/tools/libxc/xc_linux_restore.c Thu Sep 08 17:35:44 2005 +0000 3.2 +++ b/tools/libxc/xc_linux_restore.c Thu Sep 08 17:36:23 2005 +0000 3.3 @@ -149,7 +149,7 @@ int xc_linux_restore(int xc_handle, int 3.4 } 3.5 3.6 err = xc_domain_memory_increase_reservation(xc_handle, dom, 3.7 - nr_pfns * PAGE_SIZE / 1024, 0, 0); //FIX ME 3.8 + nr_pfns, 0, 0, NULL); 3.9 if (err != 0) { 3.10 ERR("Failed to increase reservation by %lx\n", 3.11 nr_pfns * PAGE_SIZE / 1024);
4.1 --- a/tools/libxc/xc_private.c Thu Sep 08 17:35:44 2005 +0000 4.2 +++ b/tools/libxc/xc_private.c Thu Sep 08 17:36:23 2005 +0000 4.3 @@ -427,3 +427,21 @@ int xc_version(int xc_handle, int cmd, v 4.4 { 4.5 return do_xen_version(xc_handle, cmd, arg); 4.6 } 4.7 + 4.8 +unsigned long xc_make_page_below_4G(int xc_handle, u32 domid, 4.9 + unsigned long mfn) 4.10 +{ 4.11 + unsigned long new_mfn; 4.12 + if ( xc_domain_memory_decrease_reservation( 4.13 + xc_handle, domid, 1, 0, &mfn ) != 1 ) 4.14 + { 4.15 + fprintf(stderr,"xc_make_page_below_4G decrease failed. mfn=%lx\n",mfn); 4.16 + return 0; 4.17 + } 4.18 + if ( xc_domain_memory_increase_reservation( xc_handle, domid, 1, 0, 32, &new_mfn ) != 1 ) 4.19 + { 4.20 + fprintf(stderr,"xc_make_page_below_4G increase failed. mfn=%lx\n",mfn); 4.21 + return 0; 4.22 + } 4.23 + return new_mfn; 4.24 +}
5.1 --- a/tools/libxc/xenctrl.h Thu Sep 08 17:35:44 2005 +0000 5.2 +++ b/tools/libxc/xenctrl.h Thu Sep 08 17:36:23 2005 +0000 5.3 @@ -387,9 +387,19 @@ int xc_domain_setmaxmem(int xc_handle, 5.4 5.5 int xc_domain_memory_increase_reservation(int xc_handle, 5.6 u32 domid, 5.7 - unsigned long mem_kb, 5.8 + unsigned long nr_extents, 5.9 unsigned int extent_order, 5.10 - unsigned int address_bits); 5.11 + unsigned int address_bits, 5.12 + unsigned long *extent_start); 5.13 + 5.14 +int xc_domain_memory_decrease_reservation(int xc_handle, 5.15 + u32 domid, 5.16 + unsigned long nr_extents, 5.17 + unsigned int extent_order, 5.18 + unsigned long *extent_start); 5.19 + 5.20 +unsigned long xc_make_page_below_4G(int xc_handle, u32 domid, 5.21 + unsigned long mfn); 5.22 5.23 typedef dom0_perfc_desc_t xc_perfc_desc_t; 5.24 /* IMPORTANT: The caller is responsible for mlock()'ing the @desc array. */
6.1 --- a/tools/python/xen/lowlevel/xc/xc.c Thu Sep 08 17:35:44 2005 +0000 6.2 +++ b/tools/python/xen/lowlevel/xc/xc.c Thu Sep 08 17:36:23 2005 +0000 6.3 @@ -842,6 +842,7 @@ static PyObject *pyxc_domain_memory_incr 6.4 u32 dom; 6.5 unsigned long mem_kb; 6.6 unsigned int extent_order = 0 , address_bits = 0; 6.7 + unsigned long nr_extents; 6.8 6.9 static char *kwd_list[] = { "dom", "mem_kb", "extent_order", "address_bits", NULL }; 6.10 6.11 @@ -849,8 +850,12 @@ static PyObject *pyxc_domain_memory_incr 6.12 &dom, &mem_kb, &extent_order, &address_bits) ) 6.13 return NULL; 6.14 6.15 + /* round down to nearest power of 2. Assume callers using extent_order>0 6.16 + know what they are doing */ 6.17 + nr_extents = (mem_kb / (XC_PAGE_SIZE/1024)) >> extent_order; 6.18 if ( xc_domain_memory_increase_reservation(xc->xc_handle, dom, 6.19 - mem_kb, extent_order, address_bits) ) 6.20 + nr_extents, extent_order, 6.21 + address_bits, NULL) ) 6.22 return PyErr_SetFromErrno(xc_error); 6.23 6.24 Py_INCREF(zero);
7.1 --- a/tools/python/xen/xend/image.py Thu Sep 08 17:35:44 2005 +0000 7.2 +++ b/tools/python/xen/xend/image.py Thu Sep 08 17:36:23 2005 +0000 7.3 @@ -160,8 +160,9 @@ class ImageHandler: 7.4 7.5 try: 7.6 # Give the domain some memory below 4GB 7.7 - lmem_kb = 4096 7.8 - xc.domain_memory_increase_reservation(dom, min(lmem_kb,mem_kb), 0, 32) 7.9 + lmem_kb = 0 7.10 + if lmem_kb > 0: 7.11 + xc.domain_memory_increase_reservation(dom, min(lmem_kb,mem_kb), 0, 32) 7.12 if mem_kb > lmem_kb: 7.13 xc.domain_memory_increase_reservation(dom, mem_kb-lmem_kb, 0, 0) 7.14 except: