From: "Jan Beulich" Subject: [PATCH, RFC 0/4] tools interface changes for supporting MFNs with 32 or more significant bits Date: Mon, 11 Jan 2010 14:49:16 +0000 Message-ID: <4B4B487D0200007800029129@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part2E04237C.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part2E04237C.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline In order to support now possible MFNs with 32 (or more) significant bits, two changes are required to the interfaces the Dom0 tools use: The individual page error indication must no longer be or-ed into the passed in MFN (because the bits used by the error indicator may collide with non-zero bits in the MFN), and a replacement for XEN_DOMCTL_getpageframeinfo2 is needed where full-width MFNs can be passed in and the result is being returned in a non-ambiguous way. 1) linux: add new (replacement) mmap-batch ioctl 2) libxc: use new (replacement) mmap-batch ioctl 3) qemu: use new (replacement) mmap-batch ioctl 4) add and use XEN_DOMCTL_getpageframeinfo3 The fact that pfn and its type get encoded as a 32-bit quantity when writing the save image means that save/restore in its current shape can't support guests with a physical address space covering more than 1Tb. It's not clear to me whether this can be fixed in a compatible way. In case the (lightly tested only so far) changes are acceptable as-is: Signed-off-by: Jan Beulich Jan --=__Part2E04237C.0__= Content-Type: text/plain; name="xen-qemu-privcmd-mmap-new.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-qemu-privcmd-mmap-new.patch" Subject: qemu: use new (replacement) mmap-batch ioctl=0A=0ASigned-off-by: = Jan Beulich =0A=0A--- 2010-01-06.orig/qemu/hw/xen_comm= on.h 2009-01-27 08:32:14.000000000 +0100=0A+++ 2010-01-06/qemu/hw/xen_co= mmon.h 2010-01-08 17:19:07.000000000 +0100=0A@@ -30,5 +30,10 @@=0A # = define xen_rmb() rmb()=0A # define xen_wmb() wmb()=0A #endif=0A+#if = __XEN_LATEST_INTERFACE_VERSION__ < 0x0003020a=0A+void * __attribute__((__we= ak__))=0A+xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,=0A+ = const xen_pfn_t *, int *err, unsigned int num);=0A+#endif= =0A =0A #endif /* QEMU_HW_XEN_COMMON_H */=0A--- 2010-01-06.orig/qemu/hw/xen= _machine_fv.c 2009-05-19 16:24:10.000000000 +0200=0A+++ 2010-01-06/qemu/h= w/xen_machine_fv.c 2010-01-08 17:24:10.000000000 +0100=0A@@ -109,6 = +109,34 @@ static void qemu_remap_bucket(struct map=0A for (i =3D 0; i = < MCACHE_BUCKET_SIZE >> XC_PAGE_SHIFT; i++)=0A pfns[i] =3D = (address_index << (MCACHE_BUCKET_SHIFT-XC_PAGE_SHIFT)) + i;=0A =0A+ if = (xc_map_foreign_bulk !=3D NULL) {=0A+ int err[MCACHE_BUCKET_SIZE >> = XC_PAGE_SHIFT];=0A+=0A+ vaddr_base =3D xc_map_foreign_bulk(xc_handle= , domid,=0A+ PROT_READ|PROT_WRITE, = pfns, err,=0A+ MCACHE_BUCKET_SIZE = >> XC_PAGE_SHIFT);=0A+ if (vaddr_base =3D=3D NULL) {=0A+ = fprintf(logfile, "xc_map_foreign_bulk error %d\n", errno);=0A+ = exit(-1);=0A+ }=0A+=0A+ entry->vaddr_base =3D vaddr_base;=0A= + entry->paddr_index =3D address_index;=0A+=0A+ for (i =3D = 0; i < MCACHE_BUCKET_SIZE >> XC_PAGE_SHIFT;=0A+ i +=3D = BITS_PER_LONG) {=0A+ unsigned long word =3D 0;=0A+ j = =3D ((i + BITS_PER_LONG) > (MCACHE_BUCKET_SIZE >> XC_PAGE_SHIFT)) ?=0A+ = (MCACHE_BUCKET_SIZE >> XC_PAGE_SHIFT) % BITS_PER_LONG :=0A+ = BITS_PER_LONG;=0A+ while (j > 0)=0A+ = word =3D (word << 1) | !err[i + --j];=0A+ entry->valid_mapping[i= / BITS_PER_LONG] =3D word;=0A+ }=0A+=0A+ return;=0A+ = }=0A+=0A vaddr_base =3D xc_map_foreign_batch(xc_handle, domid, = PROT_READ|PROT_WRITE,=0A pfns, = MCACHE_BUCKET_SIZE >> XC_PAGE_SHIFT);=0A if (vaddr_base =3D=3D NULL) = {=0A@@ -347,11 +375,11 @@ static void xen_init_fv(ram_addr_t ram_s=0A = (STORE_PAGE_START >> XC_PAGE_SHIFT); =0A }=0A =0A- = phys_ram_base =3D xc_map_foreign_batch(xc_handle, domid,=0A+ phys_ram_ba= se =3D xc_map_foreign_pages(xc_handle, domid,=0A = PROT_READ|PROT_WRITE,=0A = page_array, nr_pages);=0A if (phys_ram_base =3D=3D 0) {=0A- = fprintf(logfile, "xc_map_foreign_batch returned error %d\n", errno);=0A+ = fprintf(logfile, "xc_map_foreign_pages returned error %d\n", = errno);=0A exit(-1);=0A }=0A free(page_array);=0A --=__Part2E04237C.0__= Content-Type: text/plain; name="xen-domctl-getpageframeinfo3.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-domctl-getpageframeinfo3.patch" Subject: add and use XEN_DOMCTL_getpageframeinfo3=0A=0ATo support wider = than 28-bit MFNs, add XEN_DOMCTL_getpageframeinfo3=0A(with the type = replacing the passed in MFN rather than getting or-ed=0Ainto it) to = properly back what used to be xc_get_pfn_type_batch().=0A=0AAPI-wise the = question is whether xc_get_pfn_type_{batch,bulk}() are=0Asupposed to be = externally visible functions (their implementation=0Aliving in xc_private.c= contradicts their prototypes being in=0Axenctrl.h). If not, the former = can go away altogether (or simply be=0Achanged instead of a new variant = being added). If so, fallback code=0Afor the latter function may be deemed = necessary.=0A=0AThis also fixes a couple of bugs in pre-existing code:=0A- = the failure path for init_mem_info() leaked minfo->pfn_type,=0A- one error = path of the XEN_DOMCTL_getpageframeinfo2 handler used=0A put_domain() = where rcu_unlock_domain() was meant, and=0A- the XEN_DOMCTL_getpageframeinf= o2 handler could call=0A xsm_getpageframeinfo() with an invalid struct = page_info pointer.=0A=0ASigned-off-by: Jan Beulich =0A= =0A--- 2010-01-06.orig/tools/libxc/xc_domain_save.c 2010-01-11 = 14:39:23.000000000 +0100=0A+++ 2010-01-06/tools/libxc/xc_domain_save.c = 2010-01-11 14:41:41.000000000 +0100=0A@@ -959,6 +959,12 @@ int xc_domain_sa= ve(int xc_handle, int io=0A /* Get the size of the P2M table */=0A = dinfo->p2m_size =3D xc_memory_op(xc_handle, XENMEM_maximum_gpfn, &dom) + = 1;=0A =0A+ if ( dinfo->p2m_size > ~XEN_DOMCTL_PFINFO_LTAB_MASK )=0A+ = {=0A+ ERROR("Cannot save this big a guest");=0A+ goto = out;=0A+ }=0A+=0A /* Domain is still running at this point */=0A = if ( live )=0A {=0A@@ -1296,17 +1302,11 @@ int xc_domain_save(int = xc_handle, int io=0A else=0A {=0A = /* Get page types */=0A- for ( j =3D 0; j < batch; j++ = )=0A- ((uint32_t *)pfn_type)[j] =3D pfn_type[j];=0A- = if ( xc_get_pfn_type_batch(xc_handle, dom, batch,=0A- = (uint32_t *)pfn_type) )=0A+ = if ( xc_get_pfn_type_bulk(xc_handle, dom, batch, pfn_type) )=0A = {=0A ERROR("get_pfn_type_batch failed");=0A = goto out;=0A }=0A- for ( j = =3D batch-1; j >=3D 0; j-- )=0A- pfn_type[j] =3D = ((uint32_t *)pfn_type)[j] &=0A- XEN_DOMCTL= _PFINFO_LTAB_MASK;=0A =0A for ( j =3D 0; j < batch; j++ = )=0A {=0A--- 2010-01-06.orig/tools/libxc/xc_offline_page.c = 2010-01-11 14:41:20.000000000 +0100=0A+++ 2010-01-06/tools/libxc/xc_offline= _page.c 2010-01-11 14:09:01.000000000 +0100=0A@@ -24,7 +24,7 @@ struct = domain_mem_info{=0A int domid;=0A unsigned int pt_level;=0A = unsigned int guest_width;=0A- uint32_t *pfn_type;=0A+ xen_pfn_t = *pfn_type;=0A xen_pfn_t *p2m_table;=0A unsigned long p2m_size;=0A = xen_pfn_t *m2p_table;=0A@@ -266,19 +266,18 @@ static int init_mem_info(i= nt xc_handle, =0A }=0A =0A /* Get pfn type */=0A- minfo->pfn_typ= e =3D malloc(sizeof(uint32_t) * minfo->p2m_size);=0A+ minfo->pfn_type = =3D calloc(sizeof(*minfo->pfn_type), minfo->p2m_size);=0A if (!minfo->p= fn_type)=0A {=0A ERROR("Failed to malloc pfn_type\n");=0A = goto failed;=0A }=0A- memset(minfo->pfn_type, 0, sizeof(uint32_t)= * minfo->p2m_size);=0A =0A for (i =3D 0; i < minfo->p2m_size; i++)=0A = minfo->pfn_type[i] =3D pfn_to_mfn(i, minfo->p2m_table,=0A = minfo->guest_width);=0A =0A- if ( = lock_pages(minfo->pfn_type, minfo->p2m_size * sizeof(uint32_t)) )=0A+ = if ( lock_pages(minfo->pfn_type, minfo->p2m_size * sizeof(*minfo->pfn_type)= ) )=0A {=0A ERROR("Unable to lock pfn_type array");=0A = goto failed;=0A@@ -287,7 +286,7 @@ static int init_mem_info(int xc_handle, = =0A for (i =3D 0; i < minfo->p2m_size ; i+=3D1024)=0A {=0A = int count =3D ((dinfo->p2m_size - i ) > 1024 ) ? 1024: (dinfo->p2m_size - = i);=0A- if ( ( rc =3D xc_get_pfn_type_batch(xc_handle, domid, = count,=0A+ if ( ( rc =3D xc_get_pfn_type_bulk(xc_handle, domid, = count,=0A minfo->pfn_type + i)) )=0A {=0A = ERROR("Failed to get pfn_type %x\n", rc);=0A@@ -297,12 +296,12 @@ = static int init_mem_info(int xc_handle, =0A return 0;=0A =0A unlock:=0A= - unlock_pages(minfo->pfn_type, minfo->p2m_size * sizeof(uint32_t));=0A+= unlock_pages(minfo->pfn_type, minfo->p2m_size * sizeof(*minfo->pfn_type= ));=0A failed:=0A if (minfo->pfn_type)=0A {=0A- minfo->pfn_t= ype =3D NULL;=0A free(minfo->pfn_type);=0A+ minfo->pfn_type = =3D NULL;=0A }=0A if (live_shinfo)=0A munmap(live_shinfo, = PAGE_SIZE);=0A@@ -418,7 +417,9 @@ static int change_pte(int xc_handle, = int=0A uint64_t pte, new_pte;=0A int j;=0A =0A- if = ( table_mfn =3D=3D INVALID_P2M_ENTRY )=0A+ if ( (table_mfn =3D=3D = INVALID_P2M_ENTRY) ||=0A+ ((minfo->pfn_type[i] & XEN_DOMCTL_PFI= NFO_LTAB_MASK) =3D=3D=0A+ XEN_DOMCTL_PFINFO_XTAB) )=0A = continue;=0A =0A if ( minfo->pfn_type[i] & XEN_DOMCTL_PFINFO_L= TABTYPE_MASK )=0A--- 2010-01-06.orig/tools/libxc/xc_private.c 2010-01-11 = 14:41:20.000000000 +0100=0A+++ 2010-01-06/tools/libxc/xc_private.c = 2010-01-11 13:52:37.000000000 +0100=0A@@ -160,6 +160,18 @@ int xc_get_pfn_t= ype_batch(int xc_handle,=0A return do_domctl(xc_handle, &domctl);=0A = }=0A =0A+/* NB: arr must be locked */=0A+int xc_get_pfn_type_bulk(int = xc_handle, uint32_t dom,=0A+ unsigned int num, = xen_pfn_t *arr)=0A+{=0A+ DECLARE_DOMCTL;=0A+ domctl.cmd =3D = XEN_DOMCTL_getpageframeinfo3;=0A+ domctl.domain =3D (domid_t)dom;=0A+ = domctl.u.getpageframeinfo3.num =3D num;=0A+ set_xen_guest_handle(domctl= .u.getpageframeinfo3.array, arr);=0A+ return do_domctl(xc_handle, = &domctl);=0A+}=0A+=0A int xc_mmuext_op(=0A int xc_handle,=0A = struct mmuext_op *op,=0A--- 2010-01-06.orig/tools/libxc/xenctrl.h = 2010-01-08 13:50:58.000000000 +0100=0A+++ 2010-01-06/tools/libxc/xenctrl.h = 2010-01-11 13:51:22.000000000 +0100=0A@@ -802,6 +802,9 @@ int xc_mmuext_op(= int xc_handle, struct m=0A =0A int xc_memory_op(int xc_handle, int cmd, = void *arg);=0A =0A+int xc_get_pfn_type_bulk(int xc_handle, uint32_t = dom,=0A+ unsigned int num, xen_pfn_t *);=0A+/* = DEPRECATED - use xc_get_pfn_type_bulk() instead. */=0A int xc_get_pfn_type_= batch(int xc_handle, uint32_t dom,=0A int num, = uint32_t *arr);=0A =0A--- 2010-01-06.orig/xen/arch/x86/domctl.c 2010-01-11 = 14:41:20.000000000 +0100=0A+++ 2010-01-06/xen/arch/x86/domctl.c 2010-01-11 = 14:15:24.000000000 +0100=0A@@ -160,6 +160,106 @@ long arch_do_domctl(=0A = }=0A break;=0A =0A+ case XEN_DOMCTL_getpageframeinfo3:=0A+#ifdef = __x86_64__=0A+ if (!has_32bit_shinfo(current->domain))=0A+ = {=0A+ unsigned int n, j;=0A+ unsigned int num =3D = domctl->u.getpageframeinfo3.num;=0A+ domid_t dom =3D domctl->dom= ain;=0A+ struct domain *d;=0A+ struct page_info = *page;=0A+ xen_pfn_t *arr;=0A+=0A+ ret =3D -ESRCH;=0A= + if ( unlikely((d =3D rcu_lock_domain_by_id(dom)) =3D=3D NULL) = )=0A+ break;=0A+=0A+ if ( unlikely(num > 1024) = ||=0A+ unlikely(num !=3D domctl->u.getpageframeinfo3.num) = )=0A+ {=0A+ ret =3D -E2BIG;=0A+ = rcu_unlock_domain(d);=0A+ break;=0A+ }=0A+=0A+ = page =3D alloc_domheap_page(NULL, 0);=0A+ if ( !page = )=0A+ {=0A+ ret =3D -ENOMEM;=0A+ = rcu_unlock_domain(d);=0A+ break;=0A+ }=0A+ = arr =3D page_to_virt(page);=0A+=0A+ for ( n =3D ret =3D 0; = n < num; )=0A+ {=0A+ unsigned int k =3D = min_t(unsigned int, num - n, PAGE_SIZE / 4);=0A+=0A+ if ( = copy_from_guest_offset(arr,=0A+ = domctl->u.getpageframeinfo3.array,=0A+ = n, k) )=0A+ {=0A+ ret =3D = -EFAULT;=0A+ break;=0A+ }=0A+=0A+ = for ( j =3D 0; j < k; j++ )=0A+ {=0A+ = unsigned long type =3D 0, mfn =3D arr[j];=0A+=0A+ = page =3D mfn_to_page(mfn);=0A+=0A+ if ( unlikely(!mfn_va= lid(mfn)) )=0A+ type =3D XEN_DOMCTL_PFINFO_XTAB;=0A+= else if ( xsm_getpageframeinfo(page) !=3D 0 )=0A+ = ;=0A+ else if ( likely(get_page(page, = d)) )=0A+ {=0A+ switch( = page->u.inuse.type_info & PGT_type_mask )=0A+ {=0A+ = case PGT_l1_page_table:=0A+ = type =3D XEN_DOMCTL_PFINFO_L1TAB;=0A+ = break;=0A+ case PGT_l2_page_table:=0A+ = type =3D XEN_DOMCTL_PFINFO_L2TAB;=0A+ = break;=0A+ case PGT_l3_page_table:=0A+ = type =3D XEN_DOMCTL_PFINFO_L3TAB;=0A+ = break;=0A+ case PGT_l4_page_table:=0A+ = type =3D XEN_DOMCTL_PFINFO_L4TAB;=0A+ = break;=0A+ }=0A+=0A+ = if ( page->u.inuse.type_info & PGT_pinned )=0A+ = type |=3D XEN_DOMCTL_PFINFO_LPINTAB;=0A+=0A+ = put_page(page);=0A+ }=0A+ else=0A+ = type =3D XEN_DOMCTL_PFINFO_XTAB;=0A+=0A+ = arr[j] =3D type;=0A+ }=0A+=0A+ if ( = copy_to_guest_offset(domctl->u.getpageframeinfo3.array,=0A+ = n, arr, k) )=0A+ {=0A+ = ret =3D -EFAULT;=0A+ break;=0A+ = }=0A+=0A+ n +=3D k;=0A+ }=0A+=0A+ = free_domheap_page(virt_to_page(arr));=0A+=0A+ rcu_unlock_domain(= d);=0A+ break;=0A+ }=0A+#endif=0A+ /* fall thru = */=0A case XEN_DOMCTL_getpageframeinfo2:=0A {=0A int = n,j;=0A@@ -183,7 +283,7 @@ long arch_do_domctl(=0A if ( !arr32 = )=0A {=0A ret =3D -ENOMEM;=0A- put_domain(d)= ;=0A+ rcu_unlock_domain(d);=0A break;=0A = }=0A =0A@@ -209,11 +309,14 @@ long arch_do_domctl(=0A =0A = page =3D mfn_to_page(mfn);=0A =0A- ret =3D xsm_getpageframei= nfo(page);=0A- if ( ret )=0A- = continue;=0A+ if ( domctl->cmd =3D=3D XEN_DOMCTL_getpagefram= einfo3)=0A+ arr32[j] =3D 0;=0A =0A- if ( = likely(mfn_valid(mfn) && get_page(page, d)) ) =0A+ if ( = unlikely(!mfn_valid(mfn)) )=0A+ arr32[j] |=3D XEN_DOMCTL= _PFINFO_XTAB;=0A+ else if ( xsm_getpageframeinfo(page) !=3D = 0 )=0A+ continue;=0A+ else if ( = likely(get_page(page, d)) )=0A {=0A = unsigned long type =3D 0;=0A =0A--- 2010-01-06.orig/xen/include/public/domc= tl.h 2010-01-11 14:41:20.000000000 +0100=0A+++ 2010-01-06/xen/include/pu= blic/domctl.h 2010-01-11 12:13:16.000000000 +0100=0A@@ -161,6 +161,14 @@ = struct xen_domctl_getpageframeinfo2 {=0A typedef struct xen_domctl_getpagef= rameinfo2 xen_domctl_getpageframeinfo2_t;=0A DEFINE_XEN_GUEST_HANDLE(xen_do= mctl_getpageframeinfo2_t);=0A =0A+/* XEN_DOMCTL_getpageframeinfo3 = */=0A+struct xen_domctl_getpageframeinfo3 {=0A+ /* IN variables. */=0A+ = uint64_aligned_t num;=0A+ /* IN/OUT variables. */=0A+ XEN_GUEST_HA= NDLE_64(xen_pfn_t) array;=0A+};=0A+=0A =0A /*=0A * Control shadow = pagetables operation=0A@@ -832,6 +840,7 @@ struct xen_domctl {=0A #define = XEN_DOMCTL_disable_migrate 58=0A #define XEN_DOMCTL_gettscinf= o 59=0A #define XEN_DOMCTL_settscinfo = 60=0A+#define XEN_DOMCTL_getpageframeinfo3 61=0A #define = XEN_DOMCTL_gdbsx_guestmemio 1000=0A #define XEN_DOMCTL_gdbsx_pau= sevcpu 1001=0A #define XEN_DOMCTL_gdbsx_unpausevcpu = 1002=0A@@ -844,6 +853,7 @@ struct xen_domctl {=0A struct xen_domctl= _getmemlist getmemlist;=0A struct xen_domctl_getpageframeinf= o getpageframeinfo;=0A struct xen_domctl_getpageframeinfo2 = getpageframeinfo2;=0A+ struct xen_domctl_getpageframeinfo3 = getpageframeinfo3;=0A struct xen_domctl_vcpuaffinity = vcpuaffinity;=0A struct xen_domctl_shadow_op shadow_op;=0A = struct xen_domctl_max_mem max_mem;=0A --=__Part2E04237C.0__= Content-Type: text/plain; name="xen-libxc-privcmd-mmap-new.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-libxc-privcmd-mmap-new.patch" Subject: libxc: use new (replacement) mmap-batch ioctl=0A=0AReplace all = calls to xc_map_foreign_batch() where the caller doesn't=0Alook at the = passed in array to check for errors by calls to=0Axc_map_foreign_pages(). = Replace all remaining calls by such to the=0Anewly introduced xc_map_foreig= n_bulk().=0A=0AAs a sideband modification (needed while writing the patch = to ensure=0Athey're unused) eliminate unused parameters to=0Auncanonicalize= _pagetable() and . Also unmap live_p2m_frame_list=0Aearlier in map_and_save= _p2m_table(), reducing the peak amount of=0Avirtual address space = required.=0A=0AAll supported OSes other than Linux continue to use the old = ioctl for=0Athe time being.=0A=0AShould this change be reflected in = changing libxc's MAJOR to 4.0?=0A=0ASigned-off-by: Jan Beulich =0A=0A--- 2010-01-06.orig/tools/include/xen-sys/Linux/privcmd.h = 2010-01-11 14:30:39.000000000 +0100=0A+++ 2010-01-06/tools/include/xen-sys/= Linux/privcmd.h 2010-01-04 14:02:06.000000000 +0100=0A@@ -64,6 +64,14 @@ = typedef struct privcmd_mmapbatch {=0A xen_pfn_t __user *arr; /* array of = mfns - top nibble set on err */=0A } privcmd_mmapbatch_t; =0A =0A+typedef = struct privcmd_mmap_batch {=0A+ unsigned int num; /* number of pages to = populate */=0A+ domid_t dom; /* target domain */=0A+ __u64 = addr; /* virtual address */=0A+ const xen_pfn_t __user *arr; /* = array of mfns */=0A+ int __user *err; /* array of error codes */=0A+} = privcmd_mmap_batch_t;=0A+=0A /*=0A * @cmd: IOCTL_PRIVCMD_HYPERCALL=0A * = @arg: &privcmd_hypercall_t=0A@@ -75,5 +83,7 @@ typedef struct privcmd_mmapb= atch {=0A _IOC(_IOC_NONE, 'P', 2, sizeof(privcmd_mmap_t))=0A #define = IOCTL_PRIVCMD_MMAPBATCH \=0A _IOC(_IOC_N= ONE, 'P', 3, sizeof(privcmd_mmapbatch_t))=0A+#define IOCTL_PRIVCMD_MMAP_BAT= CH \=0A+ _IOC(_IOC_NONE, 'P', 4, sizeof(priv= cmd_mmap_batch_t))=0A =0A #endif /* __LINUX_PUBLIC_PRIVCMD_H__ */=0A--- = 2010-01-06.orig/tools/libxc/xc_domain_restore.c 2010-01-11 14:30:39.0000000= 00 +0100=0A+++ 2010-01-06/tools/libxc/xc_domain_restore.c 2010-01-08 = 16:36:32.000000000 +0100=0A@@ -118,7 +118,7 @@ static int break_super_page(= int xc_handl=0A page_array[i] =3D start_pfn + i;=0A }=0A =0A- = ram_base =3D xc_map_foreign_batch(xc_handle, dom, PROT_READ,=0A+ = ram_base =3D xc_map_foreign_pages(xc_handle, dom, PROT_READ,=0A = page_array, tot_pfns);=0A =0A if ( ram_base = =3D=3D NULL )=0A@@ -166,7 +166,7 @@ static int break_super_page(int = xc_handl=0A page_array[i] =3D start_pfn + i;=0A }=0A =0A- = ram_base =3D xc_map_foreign_batch(xc_handle, dom, PROT_WRITE,=0A+ = ram_base =3D xc_map_foreign_pages(xc_handle, dom, PROT_WRITE,=0A = page_array, tot_pfns);=0A if ( ram_base = =3D=3D NULL )=0A {=0A@@ -494,7 +494,7 @@ static ssize_t read_exact_time= d(int fd, =0A ** the (now known) appropriate mfn values.=0A */=0A static = int uncanonicalize_pagetable(int xc_handle, uint32_t dom, struct restore_ct= x *ctx,=0A- unsigned long type, void = *page, int superpages)=0A+ void *page, = int superpages)=0A {=0A int i, pte_last;=0A unsigned long = pfn;=0A@@ -1186,7 +1186,7 @@ static int apply_batch(int xc_handle, ui=0A = }=0A =0A /* Map relevant mfns */=0A- region_base =3D xc_map_foreig= n_batch(=0A+ region_base =3D xc_map_foreign_pages(=0A xc_handle,= dom, PROT_WRITE, region_mfn, j);=0A =0A if ( region_base =3D=3D NULL = )=0A@@ -1240,7 +1240,7 @@ static int apply_batch(int xc_handle, ui=0A = (pagetype !=3D XEN_DOMCTL_PFINFO_L1TAB)) {=0A =0A = if (!uncanonicalize_pagetable(xc_handle, dom, ctx,=0A- = pagetype, page, superpages)) {=0A+ = page, superpages)) {=0A = /*=0A ** Failing to uncanonicalize a page table can = be ok=0A ** under live migration since the pages type = may have=0A@@ -1655,7 +1655,7 @@ int xc_domain_restore(int xc_handle, = int=0A =0A if ( (i =3D=3D (dinfo->p2m_size-1)) || (j =3D=3D = MAX_BATCH_SIZE) )=0A {=0A- region_base =3D = xc_map_foreign_batch(=0A+ region_base =3D xc_map_foreign_pag= es(=0A xc_handle, dom, PROT_READ | PROT_WRITE, = region_mfn, j);=0A if ( region_base =3D=3D NULL )=0A = {=0A@@ -1666,7 +1666,7 @@ int xc_domain_restore(int xc_handle, = int=0A for ( k =3D 0; k < j; k++ )=0A {=0A = if ( !uncanonicalize_pagetable(=0A- = xc_handle, dom, ctx, XEN_DOMCTL_PFINFO_L1TAB,=0A+ = xc_handle, dom, ctx,=0A region_base + k*PAGE_SIZE= , superpages) )=0A {=0A = ERROR("failed uncanonicalize pt!");=0A@@ -1949,7 +1949,7 @@ int xc_domain_r= estore(int xc_handle, int=0A }=0A =0A /* Copy the P2M we've = constructed to the 'live' P2M */=0A- if ( !(ctx->live_p2m =3D xc_map_for= eign_batch(xc_handle, dom, PROT_WRITE,=0A+ if ( !(ctx->live_p2m =3D = xc_map_foreign_pages(xc_handle, dom, PROT_WRITE,=0A = p2m_frame_list, P2M_FL_ENTRIES)) )=0A {=0A = ERROR("Couldn't map p2m table");=0A--- 2010-01-06.orig/tools/libxc/xc_domai= n_save.c 2010-01-11 14:30:39.000000000 +0100=0A+++ 2010-01-06/tools/= libxc/xc_domain_save.c 2010-01-11 14:39:23.000000000 +0100=0A@@ -709,7 = +709,7 @@ static xen_pfn_t *map_and_save_p2m_table=0A = p2m_frame_list_list[i] =3D ((uint32_t *)p2m_frame_list_list)[i];=0A =0A = live_p2m_frame_list =3D=0A- xc_map_foreign_batch(xc_handle, dom, = PROT_READ,=0A+ xc_map_foreign_pages(xc_handle, dom, PROT_READ,=0A = p2m_frame_list_list,=0A = P2M_FLL_ENTRIES);=0A if ( !live_p2m_frame_list )=0A@@ -727,6 = +727,9 @@ static xen_pfn_t *map_and_save_p2m_table=0A memset(p2m_frame_= list, 0, P2M_TOOLS_FL_SIZE);=0A memcpy(p2m_frame_list, live_p2m_frame_l= ist, P2M_GUEST_FL_SIZE);=0A =0A+ munmap(live_p2m_frame_list, P2M_FLL_ENT= RIES * PAGE_SIZE);=0A+ live_p2m_frame_list =3D NULL;=0A+=0A /* = Canonicalize guest's unsigned long vs ours */=0A if ( dinfo->guest_widt= h > sizeof(unsigned long) )=0A for ( i =3D 0; i < P2M_FL_ENTRIES; = i++ )=0A@@ -741,7 +744,7 @@ static xen_pfn_t *map_and_save_p2m_table=0A = (its not clear why it would want to change them, and we'll be OK=0A = from a safety POV anyhow. */=0A =0A- p2m =3D xc_map_foreign_batch(xc= _handle, dom, PROT_READ,=0A+ p2m =3D xc_map_foreign_pages(xc_handle, = dom, PROT_READ,=0A p2m_frame_list,=0A = P2M_FL_ENTRIES);=0A if ( !p2m )=0A@@ -873,8 = +876,9 @@ int xc_domain_save(int xc_handle, int io=0A vcpu_guest_contex= t_any_t ctxt;=0A =0A /* A table containing the type of each PFN (/not/ = MFN!). */=0A- unsigned long *pfn_type =3D NULL;=0A+ xen_pfn_t = *pfn_type =3D NULL;=0A unsigned long *pfn_batch =3D NULL;=0A+ int = *pfn_err =3D NULL;=0A =0A /* A copy of one frame of guest memory. = */=0A char page[PAGE_SIZE];=0A@@ -1263,8 +1267,8 @@ int xc_domain_save(= int xc_handle, int io=0A if ( batch =3D=3D 0 )=0A = goto skip; /* vanishingly unlikely... */=0A =0A- region_base = =3D xc_map_foreign_batch(=0A- xc_handle, dom, PROT_READ, = pfn_type, batch);=0A+ region_base =3D xc_map_foreign_bulk(=0A+ = xc_handle, dom, PROT_READ, pfn_type, pfn_err, batch);=0A = if ( region_base =3D=3D NULL )=0A {=0A = ERROR("map batch failed");=0A@@ -1275,14 +1279,19 @@ int xc_domain_save(int= xc_handle, int io=0A {=0A /* Look for and = skip completely empty batches. */=0A for ( j =3D 0; j < = batch; j++ )=0A- if ( (pfn_type[j] & XEN_DOMCTL_PFINFO_L= TAB_MASK) !=3D=0A- XEN_DOMCTL_PFINFO_XTAB )=0A+ = {=0A+ if ( !pfn_err[j] )=0A = break;=0A+ pfn_type[j] |=3D XEN_DOMCTL_PFINFO_XT= AB;=0A+ }=0A if ( j =3D=3D batch )=0A = {=0A munmap(region_base, batch*PAGE_SIZE);=0A= continue; /* bail on this batch: no valid pages */=0A = }=0A+ for ( ; j < batch; j++ )=0A+ = if ( pfn_err[j] )=0A+ pfn_type[j] |=3D = XEN_DOMCTL_PFINFO_XTAB;=0A }=0A else=0A = {=0A@@ -1296,16 +1305,17 @@ int xc_domain_save(int xc_handle, int io=0A = goto out;=0A }=0A for ( = j =3D batch-1; j >=3D 0; j-- )=0A- pfn_type[j] =3D = ((uint32_t *)pfn_type)[j];=0A+ pfn_type[j] =3D = ((uint32_t *)pfn_type)[j] &=0A+ XEN_DOMCTL= _PFINFO_LTAB_MASK;=0A =0A for ( j =3D 0; j < batch; j++ = )=0A {=0A+ unsigned long mfn =3D = pfn_to_mfn(pfn_batch[j]);=0A =0A- = if ( (pfn_type[j] & XEN_DOMCTL_PFINFO_LTAB_MASK) =3D=3D=0A- = XEN_DOMCTL_PFINFO_XTAB )=0A+ if ( pfn_type[j] = =3D=3D XEN_DOMCTL_PFINFO_XTAB )=0A {=0A = DPRINTF("type fail: page %i mfn %08lx\n", =0A- = j, pfn_type[j]);=0A+ j, = mfn);=0A continue;=0A }=0A = =0A@@ -1313,16 +1323,13 @@ int xc_domain_save(int = xc_handle, int io=0A DPRINTF("%d pfn=3D %08lx = mfn=3D %08lx [mfn]=3D %08lx"=0A " sum=3D = %08lx\n",=0A iter,=0A- = (pfn_type[j] & XEN_DOMCTL_PFINFO_LTAB_MASK) |=0A- = pfn_batch[j],=0A- = pfn_type[j],=0A- mfn_to_pfn(pfn_type[j] = &=0A- ~XEN_DOMCTL_PFINFO_LTAB_MAS= K),=0A+ pfn_type[j] | pfn_batch[j],=0A+ = mfn,=0A+ = mfn_to_pfn(mfn),=0A csum_page(region_base = + (PAGE_SIZE*j)));=0A =0A /* = canonicalise mfn->pfn */=0A- pfn_type[j] =3D (pfn_type[j= ] & XEN_DOMCTL_PFINFO_LTAB_MASK) |=0A- pfn_batch[j];= =0A+ pfn_type[j] |=3D pfn_batch[j];=0A = }=0A }=0A =0A@@ -1332,11 +1339,17 @@ int xc_domain_save(int = xc_handle, int io=0A goto out;=0A }=0A =0A+ = if ( sizeof(unsigned long) < sizeof(*pfn_type) )=0A+ = for ( j =3D 0; j < batch; j++ )=0A+ ((unsigned long = *)pfn_type)[j] =3D pfn_type[j];=0A if ( write_exact(io_fd, = pfn_type, sizeof(unsigned long)*batch) )=0A {=0A = PERROR("Error when writing to state file (3)");=0A goto = out;=0A }=0A+ if ( sizeof(unsigned long) < = sizeof(*pfn_type) )=0A+ while ( --j >=3D 0 )=0A+ = pfn_type[j] =3D ((unsigned long *)pfn_type)[j];=0A =0A = /* entering this loop, pfn_type is now in pfns (Not mfns) */=0A = run =3D 0;=0A--- 2010-01-06.orig/tools/libxc/xc_linux.c 2010-01-11 = 14:30:39.000000000 +0100=0A+++ 2010-01-06/tools/libxc/xc_linux.c = 2010-01-08 14:59:57.000000000 +0100=0A@@ -64,7 +64,7 @@ int xc_interface_cl= ose(int xc_handle)=0A return close(xc_handle);=0A }=0A =0A-static int = xc_map_foreign_batch_single(int xc_handle, uint32_t dom, int prot,=0A+stati= c int xc_map_foreign_batch_single(int xc_handle, uint32_t dom,=0A = xen_pfn_t *mfn, unsigned long addr)=0A {=0A = privcmd_mmapbatch_t ioctlx;=0A@@ -116,7 +116,7 @@ void *xc_map_foreign_b= atch(int xc_handle=0A XEN_DOMCTL_PFINFO_PAGEDTAB )=0A = {=0A unsigned long paged_addr =3D (unsigned = long)addr + (i << PAGE_SHIFT);=0A- rc =3D xc_map_foreign_bat= ch_single(xc_handle, dom, prot, &arr[i],=0A+ rc =3D = xc_map_foreign_batch_single(xc_handle, dom, &arr[i],=0A = paged_addr);=0A if ( rc < 0 = )=0A goto out;=0A@@ -137,6 +137,131 @@ void *xc_map_for= eign_batch(int xc_handle=0A return addr;=0A }=0A =0A+void *xc_map_forei= gn_bulk(int xc_handle, uint32_t dom, int prot,=0A+ = const xen_pfn_t *arr, int *err, unsigned int num)=0A+{=0A+ privcmd_mmap= _batch_t ioctlx;=0A+ void *addr;=0A+ unsigned int i;=0A+ int = rc;=0A+=0A+ addr =3D mmap(NULL, (unsigned long)num << PAGE_SHIFT, prot, = MAP_SHARED,=0A+ xc_handle, 0);=0A+ if ( addr =3D=3D = MAP_FAILED )=0A+ {=0A+ perror("xc_map_foreign_batch: mmap = failed");=0A+ return NULL;=0A+ }=0A+=0A+ ioctlx.num =3D = num;=0A+ ioctlx.dom =3D dom;=0A+ ioctlx.addr =3D (unsigned long)addr;= =0A+ ioctlx.arr =3D arr;=0A+ ioctlx.err =3D err;=0A+=0A+ rc =3D = ioctl(xc_handle, IOCTL_PRIVCMD_MMAP_BATCH, &ioctlx);=0A+=0A+ if ( rc < = 0 && errno =3D=3D ENOENT )=0A+ {=0A+ for ( i =3D rc =3D 0; rc = =3D=3D 0 && i < num; i++ )=0A+ {=0A+ if ( err[i] !=3D = -ENOENT )=0A+ continue;=0A+=0A+ ioctlx.num =3D = 1;=0A+ ioctlx.dom =3D dom;=0A+ ioctlx.addr =3D = (unsigned long)addr + ((unsigned long)i< 0 )=0A+ {=0A+ = /*=0A+ * IOCTL_PRIVCMD_MMAP_BATCH is not supported - fall back = to=0A+ * IOCTL_PRIVCMD_MMAPBATCH.=0A+ */=0A+ = xen_pfn_t *pfn =3D calloc(num, sizeof(*pfn));=0A+=0A+ if ( pfn = )=0A+ {=0A+ privcmd_mmapbatch_t ioctlx;=0A+=0A+ = memcpy(pfn, arr, num * sizeof(*arr));=0A+=0A+ ioctlx.num =3D = num;=0A+ ioctlx.dom =3D dom;=0A+ ioctlx.addr =3D = (unsigned long)addr;=0A+ ioctlx.arr =3D pfn;=0A+=0A+ = rc =3D ioctl(xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);=0A+=0A+ = rc =3D rc < 0 ? -errno : 0;=0A+=0A+ for ( i =3D 0; i < num; = ++i )=0A+ {=0A+ switch ( pfn[i] ^ arr[i] )=0A+ = {=0A+ case 0:=0A+ err[i] = =3D rc !=3D -ENOENT ? rc : 0;=0A+ continue;=0A+ = default:=0A+ err[i] =3D -EINVAL;=0A+ = continue;=0A+ case XEN_DOMCTL_PFINFO_PAGEDTAB:=0A+ = if ( rc !=3D -ENOENT )=0A+ {=0A+ = err[i] =3D rc ?: -EINVAL;=0A+ = continue;=0A+ }=0A+ rc =3D xc_map_for= eign_batch_single(xc_handle, dom, pfn + i,=0A+ = (unsigned long)addr + ((unsigned long)i<gfn;=0A ret = =3D -EFAULT;=0A- page =3D xc_map_foreign_batch(paging->xc_handle, = victim->domain_id,=0A+ page =3D xc_map_foreign_pages(paging->xc_handle, = victim->domain_id,=0A PROT_READ | = PROT_WRITE, &gfn, 1);=0A- if ( (gfn & XEN_DOMCTL_PFINFO_LTAB_MASK) = =3D=3D XEN_DOMCTL_PFINFO_XTAB )=0A+ if ( page =3D=3D NULL )=0A {=0A = ERROR("Error mapping page");=0A goto out;=0A@@ -386,7 = +386,7 @@ int xenpaging_populate_page(xenpaging_t =0A =0A /* Map page = */=0A ret =3D -EFAULT;=0A- page =3D xc_map_foreign_batch(paging->xc_= handle, paging->mem_event.domain_id,=0A+ page =3D xc_map_foreign_pages(p= aging->xc_handle, paging->mem_event.domain_id,=0A = PROT_READ | PROT_WRITE, gfn, 1);=0A if ( page =3D=3D NULL )=0A = {=0A@@ -394,13 +394,6 @@ int xenpaging_populate_page(xenpaging_t =0A = goto out_map;=0A }=0A =0A- /* Check that the page exists = */=0A- if ( (*gfn & XEN_DOMCTL_PFINFO_LTAB_MASK) =3D=3D XEN_DOMCTL_PFINF= O_XTAB )=0A- {=0A- ERROR("Error mapping page: gfn is invalid");= =0A- goto out;=0A- }=0A-=0A /* Read page */=0A ret =3D = read_page(fd, page, i);=0A if ( ret !=3D 0 )=0A --=__Part2E04237C.0__= Content-Type: text/plain; name="xenlinux-privcmd-mmap-batch-new.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xenlinux-privcmd-mmap-batch-new.patch" Subject: linux: add new (replacement) mmap-batch ioctl=0A=0AWhile the = error indicator of IOCTL_PRIVCMD_MMAPBATCH should be in the=0Atop nibble = (it is documented that way in include/xen/public/privcmd.h=0Aand include/xe= n/compat_ioctl.h), it really wasn't for 64-bit=0Aimplementations. With = MFNs now possibly being 32 or more bits wide on=0Ax86-64, using bits 28-31 = as failure indicator (and bit 31 as paged-out=0Aindicator) is not longer = acceptable. Instead, a new ioctl with a=0Aseparate error indication array = is being introduced.=0A=0AAs usual, written against 2.6.32.3 and made = apply to the 2.6.18=0Atree without further testing.=0A=0ASigned-off-by: = Jan Beulich =0A=0A--- head-2010-01-04.orig/drivers/xen= /privcmd/compat_privcmd.c 2010-01-04 13:50:00.000000000 +0100=0A+++ = head-2010-01-04/drivers/xen/privcmd/compat_privcmd.c 2010-01-04 = 15:13:52.000000000 +0100=0A@@ -96,6 +96,56 @@ int privcmd_ioctl_32(int fd, = unsigned in=0A #endif=0A }=0A break;=0A+ case = IOCTL_PRIVCMD_MMAP_BATCH_32: {=0A+ struct privcmd_mmap_batch = *p;=0A+ struct privcmd_mmap_batch_32 *p32;=0A+ struct = privcmd_mmap_batch_32 n32;=0A+#ifdef xen_pfn32_t=0A+ xen_pfn_t = *__user arr;=0A+ xen_pfn32_t *__user arr32;=0A+ = unsigned int i;=0A+#endif=0A+=0A+ p32 =3D compat_ptr(arg);=0A= + p =3D compat_alloc_user_space(sizeof(*p));=0A+ if = (copy_from_user(&n32, p32, sizeof(n32)) ||=0A+ put_user(n32.nu= m, &p->num) ||=0A+ put_user(n32.dom, &p->dom) ||=0A+ = put_user(n32.addr, &p->addr) ||=0A+ put_user(compat_ptr(n32= .err), &p->err))=0A+ return -EFAULT;=0A+#ifdef = xen_pfn32_t=0A+ arr =3D compat_alloc_user_space(n32.num * = sizeof(*arr)=0A+ + sizeof(*p))= ;=0A+ arr32 =3D compat_ptr(n32.arr);=0A+ for (i =3D = 0; i < n32.num; ++i) {=0A+ xen_pfn32_t mfn;=0A+=0A+ = if (get_user(mfn, arr32 + i) || put_user(mfn, arr + = i))=0A+ return -EFAULT;=0A+ }=0A+=0A+ = if (put_user(arr, &p->arr))=0A+ return -EFAULT;=0A+= #else=0A+ if (put_user(compat_ptr(n32.arr), &p->arr))=0A+ = return -EFAULT;=0A+#endif=0A+=0A+ ret =3D sys_ioctl(f= d, IOCTL_PRIVCMD_MMAP_BATCH, (unsigned long)p);=0A+=0A+#ifdef xen_pfn32_t= =0A+ for (i =3D 0; !ret && i < n32.num; ++i) {=0A+ = xen_pfn_t mfn;=0A+=0A+ if (get_user(mfn, arr + i) || = put_user(mfn, arr32 + i))=0A+ ret =3D -EFAULT;=0A= + else if (mfn !=3D (xen_pfn32_t)mfn)=0A+ = ret =3D -ERANGE;=0A+ }=0A+#endif=0A+ }=0A+ = break;=0A default:=0A ret =3D -EINVAL;=0A = break;=0A--- head-2010-01-04.orig/drivers/xen/privcmd/privcmd.c 2010-01-05 = 11:21:42.000000000 +0100=0A+++ head-2010-01-04/drivers/xen/privcmd/privcmd.= c 2010-01-05 11:22:28.000000000 +0100=0A@@ -299,6 +299,108 @@ static = long privcmd_ioctl(struct file *f=0A mmapbatch_out:=0A = list_for_each_safe(l,l2,&pagelist)=0A free_page((unsigned= long)l);=0A+ }=0A+ break;=0A+=0A+ case IOCTL_PRIVCMD_MMAP_BATCH: = {=0A+ privcmd_mmap_batch_t m;=0A+ struct mm_struct = *mm =3D current->mm;=0A+ struct vm_area_struct *vma;=0A+ = const xen_pfn_t __user *p;=0A+ xen_pfn_t *mfn;=0A+ = unsigned long addr, nr_pages;=0A+ unsigned int i, nr;=0A+ = LIST_HEAD(pagelist);=0A+ struct list_head *l, *l2;=0A+ = int *err, paged_out;=0A+=0A+ if (!is_initial_xendomain())=0A+ = return -EPERM;=0A+=0A+ if (copy_from_user(&m, = udata, sizeof(m)))=0A+ return -EFAULT;=0A+=0A+ = nr_pages =3D m.num;=0A+ addr =3D m.addr;=0A+ if (m.num = <=3D 0 || nr_pages > (ULONG_MAX >> PAGE_SHIFT) ||=0A+ addr = !=3D m.addr || nr_pages > (-addr >> PAGE_SHIFT))=0A+ = return -EINVAL;=0A+=0A+ p =3D m.arr;=0A+ for (i =3D = 0; i < nr_pages; i +=3D nr, p +=3D nr) {=0A+ nr =3D = min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);=0A+=0A+ = ret =3D -ENOMEM;=0A+ l =3D (struct list_head *)__get_fre= e_page(GFP_KERNEL);=0A+ if (l =3D=3D NULL)=0A+ = goto mmap_batch_out;=0A+=0A+ INIT_LIST_HEAD(l);= =0A+ list_add_tail(l, &pagelist);=0A+=0A+ = mfn =3D (void *)(l + 1);=0A+ ret =3D -EFAULT;=0A+ = if (copy_from_user(mfn, p, nr * sizeof(*mfn)))=0A+ = goto mmap_batch_out;=0A+ }=0A+=0A+ = down_write(&mm->mmap_sem);=0A+=0A+ vma =3D find_vma(mm, = addr);=0A+ ret =3D -EINVAL;=0A+ if (!vma ||=0A+ = addr < vma->vm_start ||=0A+ addr + (nr_pages << PAGE_SHIFT)= > vma->vm_end ||=0A+ !enforce_singleshot_mapping(vma, addr, = nr_pages)) {=0A+ up_write(&mm->mmap_sem);=0A+ = goto mmap_batch_out;=0A+ }=0A+=0A+ i = =3D 0;=0A+ ret =3D 0;=0A+ paged_out =3D 0;=0A+ = list_for_each(l, &pagelist) {=0A+ int rc;=0A+=0A+ = nr =3D i + min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);=0A+ = mfn =3D (void *)(l + 1);=0A+ err =3D (void *)(l = + 1);=0A+ BUILD_BUG_ON(sizeof(*err) > sizeof(*mfn));= =0A+=0A+ while (i < nr) {=0A+ = rc =3D direct_remap_pfn_range(vma, addr & PAGE_MASK,=0A+ = *mfn, PAGE_SIZE,=0A+ = vma->vm_page_prot, m.dom);=0A+ = if (rc < 0) {=0A+ if = (rc =3D=3D -ENOENT)=0A+ paged_out = =3D 1;=0A+ ret++;=0A+ = } else=0A+ BUG_ON(rc > = 0);=0A+ *err++ =3D rc;=0A+ = mfn++; i++; addr +=3D PAGE_SIZE;=0A+ }=0A+ = }=0A+=0A+ up_write(&mm->mmap_sem);=0A+=0A+ if = (ret > 0) {=0A+ int __user *p =3D m.err;=0A+=0A+ = ret =3D paged_out ? -ENOENT : 0;=0A+ i =3D = 0;=0A+ list_for_each(l, &pagelist) {=0A+ = nr =3D min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);=0A+ = err =3D (void *)(l + 1);=0A+ if = (copy_to_user(p, err, nr * sizeof(*err)))=0A+ = ret =3D -EFAULT;=0A+ i +=3D nr; p +=3D nr;=0A+ = }=0A+ }=0A+=0A+ mmap_batch_out:=0A+ = list_for_each_safe(l, l2, &pagelist)=0A+ free_page((= unsigned long)l);=0A #undef MMAPBATCH_NR_PER_PAGE=0A }=0A break;=0A--= - head-2010-01-04.orig/fs/compat_ioctl.c 2009-12-17 16:11:48.0000000= 00 +0100=0A+++ head-2010-01-04/fs/compat_ioctl.c 2010-01-05 = 11:00:04.000000000 +0100=0A@@ -2937,6 +2937,7 @@ IGNORE_IOCTL(FBIOGCURSOR32= )=0A #ifdef CONFIG_XEN=0A HANDLE_IOCTL(IOCTL_PRIVCMD_MMAP_32, privcmd_ioctl= _32)=0A HANDLE_IOCTL(IOCTL_PRIVCMD_MMAPBATCH_32, privcmd_ioctl_32)=0A+HANDL= E_IOCTL(IOCTL_PRIVCMD_MMAP_BATCH_32, privcmd_ioctl_32)=0A COMPATIBLE_IOCTL(= IOCTL_PRIVCMD_HYPERCALL)=0A COMPATIBLE_IOCTL(IOCTL_EVTCHN_BIND_VIRQ)=0A = COMPATIBLE_IOCTL(IOCTL_EVTCHN_BIND_INTERDOMAIN)=0A--- head-2010-01-04.orig/= include/xen/compat_ioctl.h 2009-12-17 15:40:40.000000000 +0100=0A+++ = head-2010-01-04/include/xen/compat_ioctl.h 2010-01-04 14:01:56.0000000= 00 +0100=0A@@ -49,9 +49,27 @@ struct privcmd_mmapbatch_32 {=0A #endif=0A = compat_uptr_t arr; /* array of mfns - top nibble set on err */=0A = };=0A+=0A+struct privcmd_mmap_batch_32 {=0A+ unsigned int num; /* = number of pages to populate */=0A+ domid_t dom; /* target domain = */=0A+#if defined(CONFIG_X86) || defined(CONFIG_IA64)=0A+ union { = /* virtual address */=0A+ __u64 addr __packed;=0A+ = __u32 va;=0A+ };=0A+#else=0A+ __u64 addr; /* virtual address */=0A+#endi= f=0A+ compat_uptr_t arr; /* array of mfns */=0A+ compat_uptr_t err; = /* array of error codes */=0A+};=0A+=0A #define IOCTL_PRIVCMD_MMAP_32 = \=0A _IOC(_IOC_NONE, 'P', 2, sizeof(struct privcmd_mmap_= 32))=0A-#define IOCTL_PRIVCMD_MMAPBATCH_32 \=0A+#define = IOCTL_PRIVCMD_MMAPBATCH_32 \=0A _IOC(_IOC_NONE, 'P', 3, = sizeof(struct privcmd_mmapbatch_32))=0A+#define IOCTL_PRIVCMD_MMAP_BATCH_32= \=0A+ _IOC(_IOC_NONE, 'P', 4, sizeof(struct privcmd_mmap_= batch_32))=0A =0A #endif /* __LINUX_XEN_COMPAT_H__ */=0A--- head-2010-01-04= .orig/include/xen/public/privcmd.h 2009-12-18 10:38:09.000000000 = +0100=0A+++ head-2010-01-04/include/xen/public/privcmd.h 2010-01-04 = 14:02:06.000000000 +0100=0A@@ -60,6 +60,14 @@ typedef struct privcmd_mmapba= tch {=0A xen_pfn_t __user *arr; /* array of mfns - top nibble set = on err */=0A } privcmd_mmapbatch_t; =0A =0A+typedef struct privcmd_mmap_bat= ch {=0A+ unsigned int num; /* number of pages to populate */=0A+ = domid_t dom; /* target domain */=0A+ __u64 addr; /* = virtual address */=0A+ const xen_pfn_t __user *arr; /* array of mfns = */=0A+ int __user *err; /* array of error codes */=0A+} privcmd_mmap_batc= h_t;=0A+=0A /*=0A * @cmd: IOCTL_PRIVCMD_HYPERCALL=0A * @arg: &privcmd_hyp= ercall_t=0A@@ -71,5 +79,7 @@ typedef struct privcmd_mmapbatch {=0A = _IOC(_IOC_NONE, 'P', 2, sizeof(privcmd_mmap_t))=0A #define IOCTL_PRIVCMD_MM= APBATCH \=0A _IOC(_IOC_NONE, 'P', 3, = sizeof(privcmd_mmapbatch_t))=0A+#define IOCTL_PRIVCMD_MMAP_BATCH = \=0A+ _IOC(_IOC_NONE, 'P', 4, sizeof(privcmd_mmap_batch_t= ))=0A =0A #endif /* __LINUX_PUBLIC_PRIVCMD_H__ */=0A --=__Part2E04237C.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part2E04237C.0__=--