* [PATCH] Use a single mmap interface in libxc
@ 2009-07-20 9:27 Patrick Colp
2009-07-20 9:38 ` Keir Fraser
0 siblings, 1 reply; 3+ messages in thread
From: Patrick Colp @ 2009-07-20 9:27 UTC (permalink / raw)
To: xen-devel
# HG changeset patch
# User Patrick Colp <Patrick.Colp@citrix.com>
# Date 1248081941 -3600
# Node ID 8e1301247d784ffb98b0721d9f6f46daa0640af1
# Parent 91407452cdb62f427c74e227956dc34a107cab46
Use a single mmap interface in libxc.
This patch modifies xc_map_foreign_range and xc_map_foreign_ranges to call
mmap_map_foreign_batch. This eliminates the need for multiple privcmd mmap
ioctls. Now only IOCTL_PRIVCMD_MMAPBATCH is required.
Signed-off-by: Patrick Colp <Patrick.Colp@citrix.com>
diff -r 91407452cdb6 -r 8e1301247d78 tools/libxc/xc_linux.c
--- a/tools/libxc/xc_linux.c Wed Jul 15 13:15:50 2009 +0100
+++ b/tools/libxc/xc_linux.c Mon Jul 20 10:25:41 2009 +0100
@@ -92,67 +92,38 @@
int size, int prot,
unsigned long mfn)
{
- privcmd_mmap_t ioctlx;
- privcmd_mmap_entry_t entry;
- void *addr;
- addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0);
- if ( addr == MAP_FAILED ) {
- perror("xc_map_foreign_range: mmap failed");
- return NULL;
- }
+ xen_pfn_t *arr;
+ int num;
+ int i;
- ioctlx.num=1;
- ioctlx.dom=dom;
- ioctlx.entry=&entry;
- entry.va=(unsigned long) addr;
- entry.mfn=mfn;
- entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT;
- if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0 )
- {
- int saved_errno = errno;
- perror("xc_map_foreign_range: ioctl failed");
- (void)munmap(addr, size);
- errno = saved_errno;
- return NULL;
- }
- return addr;
+ num = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
+ arr = calloc(num, sizeof(xen_pfn_t));
+
+ for ( i = 0; i < num; i++ )
+ arr[i] = mfn + i;
+
+ return xc_map_foreign_batch(xc_handle, dom, prot, arr, num);
}
void *xc_map_foreign_ranges(int xc_handle, uint32_t dom,
size_t size, int prot, size_t chunksize,
privcmd_mmap_entry_t entries[], int nentries)
{
- privcmd_mmap_t ioctlx;
- int i, rc;
- void *addr;
+ xen_pfn_t *arr;
+ int num_per_entry;
+ int num;
+ int i;
+ int j;
- addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0);
- if ( addr == MAP_FAILED )
- goto mmap_failed;
+ num_per_entry = chunksize >> PAGE_SHIFT;
+ num = num_per_entry * nentries;
+ arr = calloc(num, sizeof(xen_pfn_t));
for ( i = 0; i < nentries; i++ )
- {
- entries[i].va = (unsigned long)addr + (i * chunksize);
- entries[i].npages = chunksize >> PAGE_SHIFT;
- }
+ for ( j = 0; j < num_per_entry; j++ )
+ arr[i * num_per_entry + j] = entries[i].mfn + j;
- ioctlx.num = nentries;
- ioctlx.dom = dom;
- ioctlx.entry = entries;
-
- rc = ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx);
- if ( rc )
- goto ioctl_failed;
-
- return addr;
-
-ioctl_failed:
- rc = munmap(addr, size);
- if ( rc == -1 )
- ERROR("%s: error in error path\n", __FUNCTION__);
-
-mmap_failed:
- return NULL;
+ return xc_map_foreign_batch(xc_handle, dom, prot, arr, num);
}
static int do_privcmd(int xc_handle, unsigned int cmd, unsigned long data)
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] Use a single mmap interface in libxc
2009-07-20 9:27 [PATCH] Use a single mmap interface in libxc Patrick Colp
@ 2009-07-20 9:38 ` Keir Fraser
2009-07-20 9:47 ` Patrick Colp
0 siblings, 1 reply; 3+ messages in thread
From: Keir Fraser @ 2009-07-20 9:38 UTC (permalink / raw)
To: Patrick Colp, xen-devel@lists.xensource.com
On 20/07/2009 10:27, "Patrick Colp" <Patrick.Colp@citrix.com> wrote:
> # HG changeset patch
> # User Patrick Colp <Patrick.Colp@citrix.com>
> # Date 1248081941 -3600
> # Node ID 8e1301247d784ffb98b0721d9f6f46daa0640af1
> # Parent 91407452cdb62f427c74e227956dc34a107cab46
> Use a single mmap interface in libxc.
>
> This patch modifies xc_map_foreign_range and xc_map_foreign_ranges to call
> mmap_map_foreign_batch. This eliminates the need for multiple privcmd mmap
> ioctls. Now only IOCTL_PRIVCMD_MMAPBATCH is required.
Some explanation of why this is a useful improvement would be nice.
-- Keir
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Use a single mmap interface in libxc
2009-07-20 9:38 ` Keir Fraser
@ 2009-07-20 9:47 ` Patrick Colp
0 siblings, 0 replies; 3+ messages in thread
From: Patrick Colp @ 2009-07-20 9:47 UTC (permalink / raw)
To: Keir Fraser; +Cc: xen-devel@lists.xensource.com
The idea is that the privcmd interface can also only have one mmap function
instead of two (something to be done to privcmd in pvops). This simplifies
things and removes unnecessary redundant code. While map_batch might not be the
ideal interface, I think it's a step in the right direction, anyway.
Also, for the project I'm working on, I need to intercept mmap calls. This
required me to have to put similar code in two places and, as it turned out,
modifying the mmap_foreign_range functions was going to be difficult. mmap_batch
can do everything required for map_foreign_range (and more), so it seemed like
the thing to do was to use that for everything so there was just the one call
into privcmd (and just one spot to edit code).
Patrick
Keir Fraser wrote:
> On 20/07/2009 10:27, "Patrick Colp" <Patrick.Colp@citrix.com> wrote:
>
>> # HG changeset patch
>> # User Patrick Colp <Patrick.Colp@citrix.com>
>> # Date 1248081941 -3600
>> # Node ID 8e1301247d784ffb98b0721d9f6f46daa0640af1
>> # Parent 91407452cdb62f427c74e227956dc34a107cab46
>> Use a single mmap interface in libxc.
>>
>> This patch modifies xc_map_foreign_range and xc_map_foreign_ranges to call
>> mmap_map_foreign_batch. This eliminates the need for multiple privcmd mmap
>> ioctls. Now only IOCTL_PRIVCMD_MMAPBATCH is required.
>
> Some explanation of why this is a useful improvement would be nice.
>
> -- Keir
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-07-20 9:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-20 9:27 [PATCH] Use a single mmap interface in libxc Patrick Colp
2009-07-20 9:38 ` Keir Fraser
2009-07-20 9:47 ` Patrick Colp
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.