libxc: use new (replacement) mmap-batch ioctl
RFC PATCH 2/4 libxc: use new (replacement) mmap-batch ioctl
Replace all calls to xc_map_foreign_batch() where the caller doesn't look at the passed in array to check for errors by calls to xc_map_foreign_pages(). Replace all remaining calls by such to the newly introduced xc_map_foreign_bulk().
As a sideband modification (needed while writing the patch to ensure they're unused) eliminate unused parameters to uncanonicalize_pagetable() and . Also unmap live_p2m_frame_list earlier in map_and_save_p2m_table(), reducing the peak amount of virtual address space required.
All supported OSes other than Linux continue to use the old ioctl for the time being.
Should this change be reflected in changing libxc's MAJOR to 4.0?
tools/include/xen-sys/Linux/privcmd.h +10 -0
@@ -64,6 +64,14 @@ typedef struct privcmd_mmapbatch {xen_pfn_t __user *arr;/* array of mfns - top nibble set on err */ } privcmd_mmapbatch_t; +typedef struct privcmd_mmap_batch { +unsigned int num;/* number of pages to populate */ +domid_t dom;/* target domain */ +__u64 addr;/* virtual address */ +const xen_pfn_t __user *arr;/* array of mfns */ +int __user *err;/* array of error codes */ +}privcmd_mmap_batch_t ; +/* * @cmd: IOCTL_PRIVCMD_HYPERCALL * @arg: &privcmd_hypercall_t
@@ -75,5 +83,7 @@ typedef struct privcmd_mmapbatch { _IOC(_IOC_NONE, 'P', 2, sizeof(privcmd_mmap_t))#define IOCTL_PRIVCMD_MMAPBATCH \ _IOC(_IOC_NONE, 'P', 3, sizeof(privcmd_mmapbatch_t)) +#define IOCTL_PRIVCMD_MMAP_BATCH \ + _IOC(_IOC_NONE, 'P', 4, sizeof(privcmd_mmap_batch_t))#endif /* __LINUX_PUBLIC_PRIVCMD_H__ */
tools/libxc/xc_domain_restore.c +8 -8
@@ -118,7 +118,7 @@ static int break_super_page(int xc_handl page_array[i] = start_pfn + i; } - ram_base =xc_map_foreign_batch (xc_handle, dom,PROT_READ , + ram_base =xc_map_foreign_pages (xc_handle, dom,PROT_READ , page_array, tot_pfns);if ( ram_base ==NULL )
@@ -166,7 +166,7 @@ static int break_super_page(int xc_handl page_array[i] = start_pfn + i; } - ram_base =xc_map_foreign_batch (xc_handle, dom,PROT_WRITE , + ram_base =xc_map_foreign_pages (xc_handle, dom,PROT_WRITE , page_array, tot_pfns);if ( ram_base ==NULL ) {
@@ -494,7 +494,7 @@ static ssize_t read_exact_timed(int fd,** the (now known) appropriate mfn values. */ static int uncanonicalize_pagetable (int xc_handle,uint32_t dom,struct restore_ctx *ctx, -unsigned long type,void *page,int superpages) +void *page,int superpages) {int i, pte_last;unsigned long pfn;
@@ -1186,7 +1186,7 @@ static int apply_batch(int xc_handle, ui }/* Map relevant mfns */ - region_base =xc_map_foreign_batch ( + region_base =xc_map_foreign_pages ( xc_handle, dom,PROT_WRITE , region_mfn, j);if ( region_base ==NULL )
@@ -1240,7 +1240,7 @@ static int apply_batch(int xc_handle, ui (pagetype != XEN_DOMCTL_PFINFO_L1TAB)) {if (!uncanonicalize_pagetable (xc_handle, dom, ctx, - pagetype, page, superpages)) { + page, superpages)) {/* ** Failing to uncanonicalize a page table can be ok ** under live migration since the pages type may have
@@ -1655,7 +1655,7 @@ int xc_domain_restore(int xc_handle, intif ( (i == (dinfo->p2m_size-1 )) || (j ==MAX_BATCH_SIZE ) ) { - region_base =xc_map_foreign_batch ( + region_base =xc_map_foreign_pages ( xc_handle, dom,PROT_READ |PROT_WRITE , region_mfn, j);if ( region_base ==NULL ) {
@@ -1666,7 +1666,7 @@ int xc_domain_restore(int xc_handle, intfor ( k =0 ; k < j; k++ ) {if ( !uncanonicalize_pagetable ( - xc_handle, dom, ctx,XEN_DOMCTL_PFINFO_L1TAB , + xc_handle, dom, ctx, region_base + k*PAGE_SIZE , superpages) ) {ERROR ("failed uncanonicalize pt!" );
@@ -1949,7 +1949,7 @@ int xc_domain_restore(int xc_handle, int }/* Copy the P2M we've constructed to the 'live' P2M */ -if ( !(ctx->live_p2m =xc_map_foreign_batch (xc_handle, dom,PROT_WRITE , +if ( !(ctx->live_p2m =xc_map_foreign_pages (xc_handle, dom,PROT_WRITE , p2m_frame_list,P2M_FL_ENTRIES )) ) {ERROR ("Couldn't map p2m table" );
tools/libxc/xc_domain_save.c +31 -18
124 lines not on this page · raw message
tools/libxc/xc_linux.c +129 -4
163 lines not on this page · raw message
tools/libxc/xc_misc.c +55 -14
90 lines not on this page · raw message
tools/libxc/xenctrl.h +10 -0
@@ -749,6 +749,8 @@ void *xc_map_foreign_pages(int xc_handle const xen_pfn_t *arr, int num );/** +* DEPRECATED - use xc_map_foreign_bulk() instead. +* * Like xc_map_foreign_pages(), except it can succeeed partially. * When a page cannot be mapped, its PFN in @arr is or'ed with * 0xF0000000 to indicate the error.
@@ -757,6 +759,14 @@ void *xc_map_foreign_batch(int xc_handle xen_pfn_t *arr, int num );/** +* Like xc_map_foreign_pages(), except it can succeed partially. +* When a page cannot be mapped, its respective field in @err is +* set to the corresponding errno value. +*/ +void *xc_map_foreign_bulk (int xc_handle,uint32_t dom,int prot, +const xen_pfn_t *arr,int *err,unsigned int num); + +/** * Translates a virtual address in the context of a given domain and * vcpu returning the GFN containing the address (that is, an MFN for * PV guests, a PFN for HVM guests). Returns 0 for failure.
tools/libxc/xc_resume.c +2 -2
@@ -158,7 +158,7 @@ static int xc_domain_resume_any(int xc_h goto out; } - p2m_frame_list =xc_map_foreign_batch (xc_handle, domid,PROT_READ , + p2m_frame_list =xc_map_foreign_pages (xc_handle, domid,PROT_READ , p2m_frame_list_list,P2M_FLL_ENTRIES );if ( p2m_frame_list ==NULL )
@@ -171,7 +171,7 @@ static int xc_domain_resume_any(int xc_hthe guest must not change which frames are used for this purpose. (its not clear why it would want to change them, and we'll be OK from a safety POV anyhow. */ - p2m =xc_map_foreign_batch (xc_handle, domid,PROT_READ , + p2m =xc_map_foreign_pages (xc_handle, domid,PROT_READ , p2m_frame_list,P2M_FL_ENTRIES );if ( p2m ==NULL )
tools/xenpaging/xenpaging.c +3 -10
@@ -310,9 +310,9 @@ int xenpaging_evict_page(xenpaging_t *pa/* Map page */ gfn = victim->gfn; ret = -EFAULT ; - page =xc_map_foreign_batch (paging->xc_handle, victim->domain_id, + page =xc_map_foreign_pages (paging->xc_handle, victim->domain_id,PROT_READ |PROT_WRITE , &gfn,1 ); -if ( (gfn &XEN_DOMCTL_PFINFO_LTAB_MASK ) ==XEN_DOMCTL_PFINFO_XTAB ) +if ( page ==NULL ) {ERROR ("Error mapping page" ); goto out;
@@ -386,7 +386,7 @@ int xenpaging_populate_page(xenpaging_t/* Map page */ ret = -EFAULT ; - page =xc_map_foreign_batch (paging->xc_handle, paging->mem_event.domain_id, + page =xc_map_foreign_pages (paging->xc_handle, paging->mem_event.domain_id,PROT_READ |PROT_WRITE , gfn,1 );if ( page ==NULL ) {
@@ -394,13 +394,6 @@ int xenpaging_populate_page(xenpaging_t goto out_map; } -/* Check that the page exists */ -if ( (*gfn &XEN_DOMCTL_PFINFO_LTAB_MASK ) ==XEN_DOMCTL_PFINFO_XTAB ) - { -ERROR ("Error mapping page: gfn is invalid" ); - goto out; - } -/* Read page */ ret =read_page (fd, page, i);if ( ret !=0 )