From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Cc: Ian.Campbell@eu.citrix.com, xen-devel@lists.xensource.com,
Ian.Jackson@eu.citrix.com, Stefano.Stabellini@eu.citrix.com
Subject: Re: [PATCH 2/3] libxc: add xc_gntshr_* functions
Date: Thu, 1 Sep 2011 15:24:55 -0400 [thread overview]
Message-ID: <20110901192455.GA21520@dumpdata.com> (raw)
In-Reply-To: <1314894138-28747-3-git-send-email-dgdegra@tycho.nsa.gov>
On Thu, Sep 01, 2011 at 12:22:17PM -0400, Daniel De Graaf wrote:
> These functions and the xc_gntshr device (/dev/xen/gntalloc on linux)
> allow applications to create pages shared with other domains.
>
> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
> ---
> tools/libxc/xc_gnttab.c | 27 +++++++++
> tools/libxc/xc_linux_osdep.c | 121 ++++++++++++++++++++++++++++++++++++++++++
> tools/libxc/xc_private.c | 13 +++++
> tools/libxc/xenctrl.h | 48 +++++++++++++++++
> tools/libxc/xenctrlosdep.h | 13 +++++
> 5 files changed, 222 insertions(+), 0 deletions(-)
>
> diff --git a/tools/libxc/xc_gnttab.c b/tools/libxc/xc_gnttab.c
> index dc7aa0c..ffa3550 100644
> --- a/tools/libxc/xc_gnttab.c
> +++ b/tools/libxc/xc_gnttab.c
> @@ -204,6 +204,33 @@ int xc_gnttab_set_max_grants(xc_gnttab *xcg, uint32_t count)
> return xcg->ops->u.gnttab.set_max_grants(xcg, xcg->ops_handle, count);
> }
>
> +void *xc_gntshr_share_pages(xc_gntshr *xcg, uint32_t domid,
> + int count, uint32_t *refs, int writable)
> +{
> + return xcg->ops->u.gntshr.share_pages(xcg, xcg->ops_handle, domid,
> + count, refs, writable);
> +}
> +
> +void *xc_gntshr_share_page_notify(xc_gntshr *xcg, uint32_t domid,
> + uint32_t *ref, int writable,
> + uint32_t notify_offset,
> + evtchn_port_t notify_port)
> +{
> + return xcg->ops->u.gntshr.share_page_notify(xcg, xcg->ops_handle,
> + domid, ref, writable, notify_offset, notify_port);
> +}
> +
> +/*
> + * Unmaps the @count pages starting at @start_address, which were mapped by a
> + * call to xc_gntshr_share_*. Never logs.
> + */
> +int xc_gntshr_munmap(xc_gntshr *xcg, void *start_address, uint32_t count)
> +{
> + return xcg->ops->u.gntshr.munmap(xcg, xcg->ops_handle,
> + start_address, count);
> +}
> +
> +
> /*
> * Local variables:
> * mode: C
> diff --git a/tools/libxc/xc_linux_osdep.c b/tools/libxc/xc_linux_osdep.c
> index 8f7718f..871d37c 100644
> --- a/tools/libxc/xc_linux_osdep.c
> +++ b/tools/libxc/xc_linux_osdep.c
> @@ -34,6 +34,7 @@
> #include <xen/memory.h>
> #include <xen/sys/evtchn.h>
> #include <xen/sys/gntdev.h>
> +#include <xen/sys/gntalloc.h>
>
> #include "xenctrl.h"
> #include "xenctrlosdep.h"
> @@ -718,6 +719,124 @@ static struct xc_osdep_ops linux_gnttab_ops = {
> },
> };
>
> +static xc_osdep_handle linux_gntshr_open(xc_gntshr *xcg)
> +{
> + int fd = open(DEVXEN "gntalloc", O_RDWR);
> +
> + if ( fd == -1 )
> + return XC_OSDEP_OPEN_ERROR;
> +
> + return (xc_osdep_handle)fd;
> +}
> +
> +static int linux_gntshr_close(xc_gntshr *xcg, xc_osdep_handle h)
> +{
> + int fd = (int)h;
> + return close(fd);
> +}
> +
> +static void *linux_gntshr_share_pages(xc_gntshr *xch, xc_osdep_handle h,
> + uint32_t domid, int count,
> + uint32_t *refs, int writable)
> +{
> + struct ioctl_gntalloc_alloc_gref *gref_info = NULL;
> + int err;
> + void *area = NULL;
> + gref_info = malloc(sizeof(*gref_info) + count * sizeof(uint32_t));
> + if (!gref_info)
> + return NULL;
> + gref_info->domid = domid;
> + gref_info->flags = writable ? GNTALLOC_FLAG_WRITABLE : 0;
> + gref_info->count = count;
> +
> + err = ioctl((int)h, IOCTL_GNTALLOC_ALLOC_GREF, gref_info);
> + if (err) {
> + PERROR("linux_gntshr_share_pages: ioctl failed");
> + goto out;
> + }
> +
> + area = mmap(NULL, count * XC_PAGE_SIZE, PROT_READ | PROT_WRITE,
> + MAP_SHARED, (int)h, gref_info->index);
> +
> + if (area == MAP_FAILED) {
> + area = NULL;
> + PERROR("linux_gntshr_share_pages: mmap failed");
> + goto out;
> + }
> +
> + memcpy(refs, gref_info->gref_ids, count * sizeof(uint32_t));
> + out:
> + free(gref_info);
> + return area;
> +}
> +
> +static void *linux_gntshr_share_page_notify(xc_gntshr *xch, xc_osdep_handle h,
> + uint32_t domid, uint32_t *ref,
> + int writable, uint32_t notify_offset,
> + evtchn_port_t notify_port)
> +{
> + struct ioctl_gntalloc_alloc_gref gref_info;
> + struct ioctl_gntalloc_unmap_notify notify;
> + int err;
> + int fd = (int)h;
> + void *area = NULL;
> + gref_info.domid = domid;
> + gref_info.flags = writable ? GNTALLOC_FLAG_WRITABLE : 0;
> + gref_info.count = 1;
> +
> + err = ioctl(fd, IOCTL_GNTALLOC_ALLOC_GREF, &gref_info);
> + if (err) {
> + PERROR("linux_gntshr_share_page_notify: ioctl failed");
> + goto out;
> + }
> +
> + area = mmap(NULL, XC_PAGE_SIZE, PROT_READ | PROT_WRITE,
> + MAP_SHARED, fd, gref_info.index);
> +
> + if (area == MAP_FAILED) {
> + PERROR("linux_gntshr_share_page_notify: mmap failed");
> + area = NULL;
> + goto out;
> + }
> +
> + notify.index = gref_info.index;
> + notify.action = 0;
> + if (notify_offset >= 0) {
> + notify.index += notify_offset;
> + notify.action |= UNMAP_NOTIFY_CLEAR_BYTE;
> + }
> + if (notify_port >= 0) {
> + notify.event_channel_port = notify_port;
> + notify.action |= UNMAP_NOTIFY_SEND_EVENT;
> + }
> + if (notify.action && ioctl(fd, IOCTL_GNTALLOC_SET_UNMAP_NOTIFY, ¬ify)) {
> + PERROR("linux_gntshr_share_page_notify: ioctl SET_UNMAP_NOTIFY failed");
Should we report to the caller that we can't set it up? Say
by reporting via a bool (as in through the arguments )?
> + }
> +
> + *ref = gref_info.gref_ids[0];
> + out:
> + return area;
> +}
> +
> +
> +static int linux_gntshr_munmap(xc_gntshr *xcg, xc_osdep_handle h,
> + void *start_address, uint32_t count)
> +{
> + return munmap(start_address, count);
> +}
> +
> +static struct xc_osdep_ops linux_gntshr_ops = {
> + .open = &linux_gntshr_open,
> + .close = &linux_gntshr_close,
> +
> + .u.gntshr = {
> + .share_pages = &linux_gntshr_share_pages,
> + .share_page_notify = &linux_gntshr_share_page_notify,
> + .munmap = &linux_gntshr_munmap,
> + },
> +};
> +
> +
> static struct xc_osdep_ops *linux_osdep_init(xc_interface *xch, enum xc_osdep_type type)
> {
> switch ( type )
> @@ -728,6 +847,8 @@ static struct xc_osdep_ops *linux_osdep_init(xc_interface *xch, enum xc_osdep_ty
> return &linux_evtchn_ops;
> case XC_OSDEP_GNTTAB:
> return &linux_gnttab_ops;
> + case XC_OSDEP_GNTSHR:
> + return &linux_gntshr_ops;
> default:
> return NULL;
> }
> diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c
> index 09c8f23..09a91e7 100644
> --- a/tools/libxc/xc_private.c
> +++ b/tools/libxc/xc_private.c
> @@ -258,6 +258,19 @@ int xc_gnttab_close(xc_gnttab *xcg)
> return xc_interface_close_common(xcg);
> }
>
> +xc_gntshr *xc_gntshr_open(xentoollog_logger *logger,
> + unsigned open_flags)
> +{
> + return xc_interface_open_common(logger, NULL, open_flags,
> + XC_OSDEP_GNTSHR);
> +}
> +
> +int xc_gntshr_close(xc_gntshr *xcg)
> +{
> + return xc_interface_close_common(xcg);
> +}
> +
> +
> static pthread_key_t errbuf_pkey;
> static pthread_once_t errbuf_pkey_once = PTHREAD_ONCE_INIT;
>
> diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h
> index 7859571..374c705 100644
> --- a/tools/libxc/xenctrl.h
> +++ b/tools/libxc/xenctrl.h
> @@ -115,6 +115,7 @@
> typedef struct xc_interface_core xc_interface;
> typedef struct xc_interface_core xc_evtchn;
> typedef struct xc_interface_core xc_gnttab;
> +typedef struct xc_interface_core xc_gntshr;
> typedef enum xc_error_code xc_error_code;
>
>
> @@ -1400,6 +1401,53 @@ grant_entry_v1_t *xc_gnttab_map_table_v1(xc_interface *xch, int domid, int *gnt_
> grant_entry_v2_t *xc_gnttab_map_table_v2(xc_interface *xch, int domid, int *gnt_num);
> /* Sometimes these don't set errno [fixme], and sometimes they don't log. */
>
> +/*
> + * Return an fd onto the grant sharing driver. Logs errors.
> + */
> +xc_gntshr *xc_gntshr_open(xentoollog_logger *logger,
> + unsigned open_flags);
> +
> +/*
> + * Close a handle previously allocated with xc_gntshr_open().
> + * Never logs errors.
> + */
> +int xc_gntshr_close(xc_gntshr *xcg);
> +
> +/*
> + * Creates and shares pages with another domain.
> + *
> + * @parm xcg a handle to an open grant sharing instance
> + * @parm domid the domain to share memory with
> + * @parm count the number of pages to share
> + * @parm refs the grant references of the pages (output)
> + * @parm writable true if the other domain can write to the pages
> + * @return local mapping of the pages
> + */
> +void *xc_gntshr_share_pages(xc_gntshr *xcg, uint32_t domid,
> + int count, uint32_t *refs, int writable);
> +
> +/*
> + * Creates and shares a page with another domain, with unmap notification.
> + *
> + * @parm xcg a handle to an open grant sharing instance
> + * @parm domid the domain to share memory with
> + * @parm refs the grant reference of the pages (output)
> + * @parm writable true if the other domain can write to the page
> + * @parm notify_offset The byte offset in the page to use for unmap
> + * notification; -1 for none.
> + * @parm notify_port The event channel port to use for unmap notify, or -1
> + * @return local mapping of the page
> + */
> +void *xc_gntshr_share_page_notify(xc_gntshr *xcg, uint32_t domid,
> + uint32_t *ref, int writable,
> + uint32_t notify_offset,
> + evtchn_port_t notify_port);
> +/*
> + * Unmaps the @count pages starting at @start_address, which were mapped by a
> + * call to xc_gntshr_share_*. Never logs.
> + */
> +int xc_gntshr_munmap(xc_gntshr *xcg, void *start_address, uint32_t count);
> +
> int xc_physdev_map_pirq(xc_interface *xch,
> int domid,
> int index,
> diff --git a/tools/libxc/xenctrlosdep.h b/tools/libxc/xenctrlosdep.h
> index 01969c5..e1c1ba5 100644
> --- a/tools/libxc/xenctrlosdep.h
> +++ b/tools/libxc/xenctrlosdep.h
> @@ -54,6 +54,7 @@ enum xc_osdep_type {
> XC_OSDEP_PRIVCMD,
> XC_OSDEP_EVTCHN,
> XC_OSDEP_GNTTAB,
> + XC_OSDEP_GNTSHR,
> };
>
> /* Opaque handle internal to the backend */
> @@ -129,6 +130,18 @@ struct xc_osdep_ops
> uint32_t count);
> int (*set_max_grants)(xc_gnttab *xcg, xc_osdep_handle h, uint32_t count);
> } gnttab;
> + struct {
> + void *(*share_pages)(xc_gntshr *xcg, xc_osdep_handle h,
> + uint32_t domid, int count,
> + uint32_t *refs, int writable);
> + void *(*share_page_notify)(xc_gntshr *xcg, xc_osdep_handle h,
> + uint32_t domid,
> + uint32_t *ref, int writable,
> + uint32_t notify_offset,
> + evtchn_port_t notify_port);
> + int (*munmap)(xc_gntshr *xcg, xc_osdep_handle h,
> + void *start_address, uint32_t count);
> + } gntshr;
> } u;
> };
> typedef struct xc_osdep_ops xc_osdep_ops;
> --
> 1.7.6
next prev parent reply other threads:[~2011-09-01 19:24 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-19 14:38 [PATCH] libvchan: interdomain communications library Daniel De Graaf
2011-08-22 7:40 ` Vasiliy G Tolstov
2011-08-24 19:28 ` Konrad Rzeszutek Wilk
2011-08-22 9:15 ` Ian Campbell
2011-08-24 18:52 ` Daniel De Graaf
2011-08-25 10:27 ` Tim Deegan
2011-08-25 18:36 ` Jeremy Fitzhardinge
2011-08-24 18:52 ` [PATCH v2] " Daniel De Graaf
2011-08-26 14:01 ` Ian Jackson
2011-08-29 18:48 ` [PATCH v3] " Daniel De Graaf
2011-08-30 10:32 ` Ian Campbell
2011-08-31 19:17 ` Daniel De Graaf
2011-09-01 16:28 ` Ian Campbell
2011-09-01 16:47 ` Daniel De Graaf
2011-09-01 16:56 ` Ian Jackson
2011-09-01 17:46 ` Daniel De Graaf
2011-09-01 16:22 ` [PATCH v4 0/3] " Daniel De Graaf
2011-09-01 16:22 ` [PATCH 1/3] libxc: add xc_gnttab_map_grant_ref_notify Daniel De Graaf
2011-09-01 19:29 ` Konrad Rzeszutek Wilk
2011-09-01 16:22 ` [PATCH 2/3] libxc: add xc_gntshr_* functions Daniel De Graaf
2011-09-01 19:24 ` Konrad Rzeszutek Wilk [this message]
2011-09-01 16:22 ` [PATCH 3/3] libvchan: interdomain communications library Daniel De Graaf
2011-09-19 22:43 ` [PATCH v5 0/3] Daniel De Graaf
2011-09-19 22:43 ` [PATCH 1/3] libxc: add xc_gnttab_map_grant_ref_notify Daniel De Graaf
2011-09-21 10:03 ` Ian Campbell
2011-09-21 15:02 ` Daniel De Graaf
2011-09-21 15:25 ` Ian Campbell
2011-09-21 17:07 ` Daniel De Graaf
2011-09-22 8:32 ` Ian Campbell
2011-09-22 18:09 ` Daniel De Graaf
2011-09-19 22:43 ` [PATCH 2/3] libxc: add xc_gntshr_* functions Daniel De Graaf
2011-09-21 10:13 ` Ian Campbell
2011-09-19 22:43 ` [PATCH 3/3] libvchan: interdomain communications library Daniel De Graaf
2011-09-21 10:53 ` Ian Campbell
2011-09-21 16:31 ` Daniel De Graaf
2011-09-22 8:18 ` Ian Campbell
2011-09-21 13:44 ` Ian Campbell
2011-09-22 22:14 ` [PATCH v6 0/3] libxenvchan: " Daniel De Graaf
2011-09-22 22:14 ` [PATCH 1/3] libxc: add xc_gnttab_map_grant_ref_notify Daniel De Graaf
2011-09-30 9:16 ` Ian Campbell
2011-09-30 14:12 ` Ian Jackson
2011-09-30 14:17 ` Ian Campbell
2011-09-22 22:14 ` [PATCH 2/3] libxc: add xc_gntshr_* functions Daniel De Graaf
2011-09-22 22:14 ` [PATCH 3/3] libvchan: interdomain communications library Daniel De Graaf
2011-09-30 7:51 ` [PATCH v6 0/3] libxenvchan: " Vasiliy Tolstov
2011-09-30 8:28 ` Vasiliy Tolstov
2011-09-30 14:40 ` Daniel De Graaf
2011-11-24 20:02 ` Anil Madhavapeddy
2011-11-25 16:53 ` Daniel De Graaf
2011-11-25 16:54 ` [PATCH] libxc: Fix checks on grant notify arguments Daniel De Graaf
2011-12-01 18:20 ` Ian Jackson
2011-11-25 16:56 ` [PATCH 1/2] xen/events: prevent calling evtchn_get on invlaid channels Daniel De Graaf
2011-11-25 16:56 ` [PATCH 2/2] xen/gntalloc: release grant references on page free Daniel De Graaf
2011-11-25 18:37 ` [PATCH] xen/gntalloc: fix reference counts on multi-page mappings Daniel De Graaf
2011-09-30 8:34 ` [PATCH v6 0/3] libxenvchan: interdomain communications library Ian Campbell
2011-09-30 8:37 ` [PATCH] libxc: osdep: report missing backends in common code Ian Campbell
2011-10-06 18:44 ` [PATCH v6 0/3] libxenvchan: interdomain communications library Ian Jackson
2011-10-07 8:41 ` Roger Pau Monné
2011-10-07 9:15 ` Keir Fraser
2011-10-07 9:48 ` Ian Jackson
2011-10-07 10:22 ` Roger Pau Monné
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110901192455.GA21520@dumpdata.com \
--to=konrad.wilk@oracle.com \
--cc=Ian.Campbell@eu.citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=Stefano.Stabellini@eu.citrix.com \
--cc=dgdegra@tycho.nsa.gov \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.