Stefano Stabellini
2010-Jan-14 17:33 UTC
[Xen-devel] [PATCH] implement xc_map_foreign_bulk for minios
Hi all, this patch provides an implementation of xc_map_foreign_bulk for minios. In order to do so it modifies map_frames_ex and do_map_frames to take an int *err as parameter and return any error that way. Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> --- diff -r 4327d8110e59 extras/mini-os/arch/ia64/mm.c --- a/extras/mini-os/arch/ia64/mm.c Thu Jan 14 15:40:35 2010 +0000 +++ b/extras/mini-os/arch/ia64/mm.c Thu Jan 14 16:00:04 2010 +0000 @@ -137,17 +137,17 @@ /* Helper function used in gnttab.c. */ void do_map_frames(unsigned long addr, - unsigned long *f, unsigned long n, unsigned long stride, - unsigned long increment, domid_t id, int may_fail, unsigned long prot) + const unsigned long *f, unsigned long n, unsigned long stride, + unsigned long increment, domid_t id, int *err, unsigned long prot) { /* TODO */ ASSERT(0); } void* -map_frames_ex(unsigned long* frames, unsigned long n, unsigned long stride, +map_frames_ex(const unsigned long* frames, unsigned long n, unsigned long stride, unsigned long increment, unsigned long alignment, domid_t id, - int may_fail, unsigned long prot) + int *err, unsigned long prot) { /* TODO: incomplete! */ ASSERT(n == 1 || (stride == 0 && increment == 1)); diff -r 4327d8110e59 extras/mini-os/arch/x86/ioremap.c --- a/extras/mini-os/arch/x86/ioremap.c Thu Jan 14 15:40:35 2010 +0000 +++ b/extras/mini-os/arch/x86/ioremap.c Thu Jan 14 16:00:04 2010 +0000 @@ -53,7 +53,7 @@ } } va = (unsigned long)map_frames_ex(&mfns, num_pages, 0, 1, 1, - DOMID_IO, 0, prot); + DOMID_IO, NULL, prot); return (void *)(va + offset); mfn_invalid: diff -r 4327d8110e59 extras/mini-os/arch/x86/mm.c --- a/extras/mini-os/arch/x86/mm.c Thu Jan 14 15:40:35 2010 +0000 +++ b/extras/mini-os/arch/x86/mm.c Thu Jan 14 16:00:04 2010 +0000 @@ -568,10 +568,9 @@ */ #define MAP_BATCH ((STACK_SIZE / 2) / sizeof(mmu_update_t)) void do_map_frames(unsigned long va, - unsigned long *mfns, unsigned long n, + const unsigned long *mfns, unsigned long n, unsigned long stride, unsigned long incr, - domid_t id, int may_fail, - unsigned long prot) + domid_t id, int *err, unsigned long prot) { pgentry_t *pgt = NULL; unsigned long done = 0; @@ -585,12 +584,14 @@ } DEBUG("va=%p n=0x%lx, mfns[0]=0x%lx stride=0x%lx incr=0x%lx prot=0x%lx\n", va, n, mfns[0], stride, incr, prot); - + + if ( err ) + memset(err, 0x00, n * sizeof(int)); while ( done < n ) { unsigned long todo; - if ( may_fail ) + if ( err ) todo = 1; else todo = n - done; @@ -615,8 +616,8 @@ rc = HYPERVISOR_mmu_update(mmu_updates, todo, NULL, id); if ( rc < 0 ) { - if (may_fail) - mfns[done * stride] |= 0xF0000000; + if (err) + err[done * stride] = rc; else { printk("Map %ld (%lx, ...) at %p failed: %d.\n", todo, mfns[done * stride] + done * incr, va, rc); @@ -632,17 +633,17 @@ * Map an array of MFNs contiguous into virtual address space. Virtual * addresses are allocated from the on demand area. */ -void *map_frames_ex(unsigned long *mfns, unsigned long n, +void *map_frames_ex(const unsigned long *mfns, unsigned long n, unsigned long stride, unsigned long incr, unsigned long alignment, - domid_t id, int may_fail, unsigned long prot) + domid_t id, int *err, unsigned long prot) { unsigned long va = allocate_ondemand(n, alignment); if ( !va ) return NULL; - do_map_frames(va, mfns, n, stride, incr, id, may_fail, prot); + do_map_frames(va, mfns, n, stride, incr, id, err, prot); return (void *)va; } diff -r 4327d8110e59 extras/mini-os/include/ia64/arch_mm.h --- a/extras/mini-os/include/ia64/arch_mm.h Thu Jan 14 15:40:35 2010 +0000 +++ b/extras/mini-os/include/ia64/arch_mm.h Thu Jan 14 16:00:04 2010 +0000 @@ -35,9 +35,9 @@ #define virt_to_mfn(x) virt_to_pfn(x) #define virtual_to_mfn(x) (ia64_tpa((uint64_t)(x)) >> PAGE_SHIFT) -#define map_frames(f, n) map_frames_ex(f, n, 1, 0, 1, DOMID_SELF, 0, 0) +#define map_frames(f, n) map_frames_ex(f, n, 1, 0, 1, DOMID_SELF, NULL, 0) /* TODO */ -#define map_zero(n, a) map_frames_ex(NULL, n, 0, 0, a, DOMID_SELF, 0, 0) +#define map_zero(n, a) map_frames_ex(NULL, n, 0, 0, a, DOMID_SELF, NULL, 0) #define do_map_zero(start, n) ASSERT(n == 0) #endif /* __ARCH_MM_H__ */ diff -r 4327d8110e59 extras/mini-os/include/mm.h --- a/extras/mini-os/include/mm.h Thu Jan 14 15:40:35 2010 +0000 +++ b/extras/mini-os/include/mm.h Thu Jan 14 16:00:04 2010 +0000 @@ -65,12 +65,12 @@ unsigned long allocate_ondemand(unsigned long n, unsigned long alignment); /* map f[i*stride]+i*increment for i in 0..n-1, aligned on alignment pages */ -void *map_frames_ex(unsigned long *f, unsigned long n, unsigned long stride, +void *map_frames_ex(const unsigned long *f, unsigned long n, unsigned long stride, unsigned long increment, unsigned long alignment, domid_t id, - int may_fail, unsigned long prot); + int *err, unsigned long prot); void do_map_frames(unsigned long addr, - unsigned long *f, unsigned long n, unsigned long stride, - unsigned long increment, domid_t id, int may_fail, unsigned long prot); + const unsigned long *f, unsigned long n, unsigned long stride, + unsigned long increment, domid_t id, int *err, unsigned long prot); int unmap_frames(unsigned long va, unsigned long num_frames); unsigned long alloc_contig_pages(int order, unsigned int addr_bits); #ifdef HAVE_LIBC diff -r 4327d8110e59 extras/mini-os/include/x86/arch_mm.h --- a/extras/mini-os/include/x86/arch_mm.h Thu Jan 14 15:40:35 2010 +0000 +++ b/extras/mini-os/include/x86/arch_mm.h Thu Jan 14 16:00:04 2010 +0000 @@ -224,9 +224,9 @@ }) #define virtual_to_mfn(_virt) pte_to_mfn(virtual_to_pte(_virt)) -#define map_frames(f, n) map_frames_ex(f, n, 1, 0, 1, DOMID_SELF, 0, L1_PROT) -#define map_zero(n, a) map_frames_ex(&mfn_zero, n, 0, 0, a, DOMID_SELF, 0, L1_PROT_RO) -#define do_map_zero(start, n) do_map_frames(start, &mfn_zero, n, 0, 0, DOMID_SELF, 0, L1_PROT_RO) +#define map_frames(f, n) map_frames_ex(f, n, 1, 0, 1, DOMID_SELF, NULL, L1_PROT) +#define map_zero(n, a) map_frames_ex(&mfn_zero, n, 0, 0, a, DOMID_SELF, NULL, L1_PROT_RO) +#define do_map_zero(start, n) do_map_frames(start, &mfn_zero, n, 0, 0, DOMID_SELF, NULL, L1_PROT_RO) pgentry_t *need_pgt(unsigned long addr); int mfn_is_ram(unsigned long mfn); diff -r 4327d8110e59 extras/mini-os/lib/sys.c --- a/extras/mini-os/lib/sys.c Thu Jan 14 15:40:35 2010 +0000 +++ b/extras/mini-os/lib/sys.c Thu Jan 14 16:00:04 2010 +0000 @@ -1254,10 +1254,10 @@ return map_zero(n, 1); else if (files[fd].type == FTYPE_XC) { unsigned long zero = 0; - return map_frames_ex(&zero, n, 0, 0, 1, DOMID_SELF, 0, 0); + return map_frames_ex(&zero, n, 0, 0, 1, DOMID_SELF, NULL, 0); } else if (files[fd].type == FTYPE_MEM) { unsigned long first_mfn = offset >> PAGE_SHIFT; - return map_frames_ex(&first_mfn, n, 0, 1, 1, DOMID_IO, 0, _PAGE_PRESENT|_PAGE_RW); + return map_frames_ex(&first_mfn, n, 0, 1, 1, DOMID_IO, NULL, _PAGE_PRESENT|_PAGE_RW); } else ASSERT(0); } diff -r 4327d8110e59 tools/libxc/xc_minios.c --- a/tools/libxc/xc_minios.c Thu Jan 14 15:40:35 2010 +0000 +++ b/tools/libxc/xc_minios.c Thu Jan 14 16:00:04 2010 +0000 @@ -44,8 +44,8 @@ return 0; } -void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot, - xen_pfn_t *arr, int num) +void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot, + const xen_pfn_t *arr, int *err, unsigned int num) { unsigned long pt_prot = 0; #ifdef __ia64__ @@ -56,7 +56,31 @@ if (prot & PROT_WRITE) pt_prot = L1_PROT; #endif - return map_frames_ex(arr, num, 1, 0, 1, dom, 1, pt_prot); + return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot); +} + +void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot, + xen_pfn_t *arr, int num) +{ + unsigned long pt_prot = 0; + int err[num]; + int i; + unsigned long addr; + +#ifdef __ia64__ + /* TODO */ +#else + if (prot & PROT_READ) + pt_prot = L1_PROT_RO; + if (prot & PROT_WRITE) + pt_prot = L1_PROT; +#endif + addr = (unsigned long) map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot); + for (i = 0; i < num; i++) { + if (err[i]) + arr[i] |= 0xF0000000; + } + return (void *) addr; } void *xc_map_foreign_range(int xc_handle, uint32_t dom, @@ -73,7 +97,7 @@ pt_prot = L1_PROT; #endif assert(!(size % getpagesize())); - return map_frames_ex(&mfn, size / getpagesize(), 0, 1, 1, dom, 0, pt_prot); + return map_frames_ex(&mfn, size / getpagesize(), 0, 1, 1, dom, NULL, pt_prot); } void *xc_map_foreign_ranges(int xc_handle, uint32_t dom, @@ -100,7 +124,7 @@ for (j = 0; j < chunksize / PAGE_SIZE; j++) mfns[n++] = entries[i].mfn + j; - ret = map_frames_ex(mfns, n, 1, 0, 1, dom, 0, pt_prot); + ret = map_frames_ex(mfns, n, 1, 0, 1, dom, NULL, pt_prot); free(mfns); return ret; } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2010-Jan-17 18:02 UTC
Re: [Xen-devel] [PATCH] implement xc_map_foreign_bulk for minios
On 14/01/2010 17:33, "Stefano Stabellini" <stefano.stabellini@eu.citrix.com> wrote:> Hi all, > this patch provides an implementation of xc_map_foreign_bulk for minios. > In order to do so it modifies map_frames_ex and do_map_frames to take an > int *err as parameter and return any error that way. > > Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>I was unable to apply this patch. Please try re-sending as an attachment. -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel