[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH XEN v5 14/23] tools: foreignmemory: provide xenforeignmemory_unmap.
And require it be used instead of direct munmap. This will allow e.g. Valgrind hooks to help track incorrect use of foreign mappings. Switch all uses of xenforeignmemory_map to use xenforeignmemory_unmap, not that foreign mappings via the libxc compat xc_map_foreign_* interface will not take advantage of this and will need converting. Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx> Acked-by: Wei Liu <wei.liu2@xxxxxxxxxx> --- v4: xenforeignmemory_unmap takes pages not bytes, adjust callers. --- tools/libs/foreignmemory/freebsd.c | 6 ++++++ tools/libs/foreignmemory/include/xenforeignmemory.h | 7 +++++-- tools/libs/foreignmemory/libxenforeignmemory.map | 1 + tools/libs/foreignmemory/linux.c | 6 ++++++ tools/libs/foreignmemory/minios.c | 6 ++++++ tools/libs/foreignmemory/netbsd.c | 6 ++++++ tools/libs/foreignmemory/solaris.c | 6 ++++++ tools/libxc/xc_sr_restore.c | 2 +- tools/libxc/xc_sr_save.c | 2 +- tools/libxc/xc_vm_event.c | 2 +- 10 files changed, 39 insertions(+), 5 deletions(-) diff --git a/tools/libs/foreignmemory/freebsd.c b/tools/libs/foreignmemory/freebsd.c index a7e0f6b..f9e74fa 100644 --- a/tools/libs/foreignmemory/freebsd.c +++ b/tools/libs/foreignmemory/freebsd.c @@ -118,6 +118,12 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem, return addr; } +int xenforeignmemory_unmap(xenforeignmemory_handle *fmem, + void *addr, unsigned int num) +{ + return munmap(addr, num << PAGE_SHIFT); +} + /* * Local variables: * mode: C diff --git a/tools/libs/foreignmemory/include/xenforeignmemory.h b/tools/libs/foreignmemory/include/xenforeignmemory.h index 0909585..1bcdf6a 100644 --- a/tools/libs/foreignmemory/include/xenforeignmemory.h +++ b/tools/libs/foreignmemory/include/xenforeignmemory.h @@ -44,8 +44,8 @@ int xenforeignmemory_close(xenforeignmemory_handle *xmem); /* * Maps a range within one domain to a local address range. Mappings - * should be unmapped with munmap and should follow the same rules as mmap - * regarding page alignment. + * must be unmapped with xenforeignmemory_unmap and should follow the + * same rules as mmap regarding page alignment. * * prot is as for mmap(2). * @@ -58,6 +58,9 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem, uint32_t dom, int prot, const xen_pfn_t *arr, int *err, unsigned int num); +int xenforeignmemory_unmap(xenforeignmemory_handle *fmem, + void *addr, unsigned int num); + #endif /* diff --git a/tools/libs/foreignmemory/libxenforeignmemory.map b/tools/libs/foreignmemory/libxenforeignmemory.map index 11f0d2b..df206b3 100644 --- a/tools/libs/foreignmemory/libxenforeignmemory.map +++ b/tools/libs/foreignmemory/libxenforeignmemory.map @@ -3,5 +3,6 @@ VERS_1.0 { xenforeignmemory_open; xenforeignmemory_close; xenforeignmemory_map; + xenforeignmemory_unmap; local: *; /* Do not expose anything by default */ }; diff --git a/tools/libs/foreignmemory/linux.c b/tools/libs/foreignmemory/linux.c index 01cd42e..86a5a97 100644 --- a/tools/libs/foreignmemory/linux.c +++ b/tools/libs/foreignmemory/linux.c @@ -276,6 +276,12 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem, return addr; } +int xenforeignmemory_unmap(xenforeignmemory_handle *fmem, + void *addr, unsigned int num) +{ + return munmap(addr, (unsigned long)num << PAGE_SHIFT); +} + /* * Local variables: * mode: C diff --git a/tools/libs/foreignmemory/minios.c b/tools/libs/foreignmemory/minios.c index 981d801..dbb152f 100644 --- a/tools/libs/foreignmemory/minios.c +++ b/tools/libs/foreignmemory/minios.c @@ -51,6 +51,12 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem, return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot); } +int xenforeignmemory_unmap(xenforeignmemory_handle *fmem, + void *addr, unsigned int num) +{ + return munmap(addr, num << PAGE_SHIFT); +} + /* * Local variables: * mode: C diff --git a/tools/libs/foreignmemory/netbsd.c b/tools/libs/foreignmemory/netbsd.c index e84d5ec..4d68b52 100644 --- a/tools/libs/foreignmemory/netbsd.c +++ b/tools/libs/foreignmemory/netbsd.c @@ -93,3 +93,9 @@ void *compat_mapforeign_batch(xenforeignmem_handle *fmem, uint32_t dom, return addr; } + +int xenforeignmemory_unmap(xenforeignmemory_handle *fmem, + void *addr, unsigned int num) +{ + return munmap(addr, num*XC_PAGE_SIZE); +} diff --git a/tools/libs/foreignmemory/solaris.c b/tools/libs/foreignmemory/solaris.c index 1d27b50..3f8e705 100644 --- a/tools/libs/foreignmemory/solaris.c +++ b/tools/libs/foreignmemory/solaris.c @@ -92,3 +92,9 @@ void *compat_mapforeign_batch(xenforeignmem_handle *fmem, uint32_t dom, return addr; } + +int xenforeignmemory_unmap(xenforeignmemory_handle *fmem, + void *addr, unsigned int num) +{ + return munmap(addr, num*XC_PAGE_SIZE); +} diff --git a/tools/libxc/xc_sr_restore.c b/tools/libxc/xc_sr_restore.c index 2e41af8..c96b8c2 100644 --- a/tools/libxc/xc_sr_restore.c +++ b/tools/libxc/xc_sr_restore.c @@ -378,7 +378,7 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned count, err: if ( mapping ) - munmap(mapping, nr_pages * PAGE_SIZE); + xenforeignmemory_unmap(xch->fmem, mapping, nr_pages); free(map_errs); free(mfns); diff --git a/tools/libxc/xc_sr_save.c b/tools/libxc/xc_sr_save.c index a5ac517..ac393ab 100644 --- a/tools/libxc/xc_sr_save.c +++ b/tools/libxc/xc_sr_save.c @@ -263,7 +263,7 @@ static int write_batch(struct xc_sr_context *ctx) err: free(rec_pfns); if ( guest_mapping ) - munmap(guest_mapping, nr_pages_mapped * PAGE_SIZE); + xenforeignmemory_unmap(xch->fmem, guest_mapping, nr_pages_mapped); for ( i = 0; local_pages && i < nr_pfns; ++i ) free(local_pages[i]); free(iov); diff --git a/tools/libxc/xc_vm_event.c b/tools/libxc/xc_vm_event.c index df21f9c..e388278 100644 --- a/tools/libxc/xc_vm_event.c +++ b/tools/libxc/xc_vm_event.c @@ -151,7 +151,7 @@ void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param, } if ( ring_page ) - munmap(ring_page, XC_PAGE_SIZE); + xenforeignmemory_unmap(xch->fmem, ring_page, 1); ring_page = NULL; errno = saved_errno; -- 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |