All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Campbell <ian.campbell@citrix.com>
To: ian.jackson@eu.citrix.com, wei.liu2@citrix.com, xen-devel@lists.xen.org
Cc: roger.pau@citrix.com, stefano.stabellini@eu.citrix.com
Subject: Re: [PATCH XEN v2 08/15] tools: Refactor /dev/xen/gnt{dev, shr} wrappers into libxengnttab.
Date: Tue, 22 Sep 2015 12:25:12 +0100	[thread overview]
Message-ID: <1442921112.10338.153.camel@citrix.com> (raw)
In-Reply-To: <1436975223-11098-8-git-send-email-ian.campbell@citrix.com>

Any thoughts/preferences on this library interface regarding:

The use of a (perhaps to be added) grant_ref_t in preference to uint32_t as
it is now?

The use of bool rather than int for "writeable"?

Mapping functions returning NULL on failure (rather than e.g MAP_FAILED)?
(current code squashes any underlying MAP_FAILED into NULL, but of course
that prevents mapping things at NULL, but then I'm not sure why we would
want to support that).

Ian.

On Wed, 2015-07-15 at 16:46 +0100, Ian Campbell wrote:
> diff --git a/tools/libxengnttab/include/xengnttab.h b/tools/libxengnttab/include/xengnttab.h
> new file mode 100644
> index 0000000..b333662
> --- /dev/null
> +++ b/tools/libxengnttab/include/xengnttab.h
> @@ -0,0 +1,215 @@
> +/*
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation;
> + * version 2.1 of the License.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * Split off from:
> + * xenctrl.h
> + *
> + * A library for low-level access to the Xen control interfaces.
> + *
> + * Copyright (c) 2007-2008, D G Murray <Derek.Murray@cl.cam.ac.uk>
> + */
> +#ifndef XENGNTTAB_H
> +#define XENGNTTAB_H
> +
> +#include 
> +
> +#include 
> +#include 
> +
> +/* Callers who don't care don't need to #include  */
> +typedef struct xentoollog_logger xentoollog_logger;
> +
> +/*
> + * Grant Table Interface (making use of grants from other domains)
> + */
> +
> +typedef struct xengntdev_handle xengnttab_handle;
> +
> +/*
> + * Note:
> + * After fork a child process must not use any opened xc gnttab
> + * handle inherited from their parent. They must open a new handle if
> + * they want to interact with xc.
> + *
> + * Return an fd onto the grant table driver.  Logs errors.
> + */
> +xengnttab_handle *xengnttab_open(xentoollog_logger *logger, unsigned open_flags);
> +
> +/*
> + * Close a handle previously allocated with xengnttab_open().
> + * Never logs errors.
> + */
> +int xengnttab_close(xengnttab_handle *xgt);
> +
> +/*
> + * Memory maps a grant reference from one domain to a local address range.
> + * Mappings should be unmapped with xengnttab_munmap.  Logs errors.
> + *
> + * @parm xgt a handle on an open grant table interface
> + * @parm domid the domain to map memory from
> + * @parm ref the grant reference ID to map
> + * @parm prot same flag as in mmap()
> + */
> +void *xengnttab_map_grant_ref(xengnttab_handle *xgt,
> +                              uint32_t domid,
> +                              uint32_t ref,
> +                              int prot);
> +
> +/**
> + * Memory maps one or more grant references from one or more domains to a
> + * contiguous local address range. Mappings should be unmapped with
> + * xengnttab_munmap.  Logs errors.
> + *
> + * @parm xgt a handle on an open grant table interface
> + * @parm count the number of grant references to be mapped
> + * @parm domids an array of @count domain IDs by which the corresponding @refs
> + *              were granted
> + * @parm refs an array of @count grant references to be mapped
> + * @parm prot same flag as in mmap()
> + */
> +void *xengnttab_map_grant_refs(xengnttab_handle *xgt,
> +                               uint32_t count,
> +                               uint32_t *domids,
> +                               uint32_t *refs,
> +                               int prot);
> +
> +/**
> + * Memory maps one or more grant references from one domain to a
> + * contiguous local address range. Mappings should be unmapped with
> + * xengnttab_munmap.  Logs errors.
> + *
> + * @parm xgt a handle on an open grant table interface
> + * @parm count the number of grant references to be mapped
> + * @parm domid the domain to map memory from
> + * @parm refs an array of @count grant references to be mapped
> + * @parm prot same flag as in mmap()
> + */
> +void *xengnttab_map_domain_grant_refs(xengnttab_handle *xgt,
> +                                      uint32_t count,
> +                                      uint32_t domid,
> +                                      uint32_t *refs,
> +                                      int prot);
> +
> +/**
> + * Memory maps a grant reference from one domain to a local address range.
> + * Mappings should be unmapped with xengnttab_munmap. If notify_offset or
> + * notify_port are not -1, this version will attempt to set up an unmap
> + * notification at the given offset and event channel. When the page is
> + * unmapped, the byte at the given offset will be zeroed and a wakeup will be
> + * sent to the given event channel.  Logs errors.
> + *
> + * @parm xgt a handle on an open grant table interface
> + * @parm domid the domain to map memory from
> + * @parm ref the grant reference ID to map
> + * @parm prot same flag as in mmap()
> + * @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
> + */
> +void *xengnttab_map_grant_ref_notify(xengnttab_handle *xgt,
> +                                     uint32_t domid,
> +                                     uint32_t ref,
> +                                     int prot,
> +                                     uint32_t notify_offset,
> +                                     evtchn_port_t notify_port);
> +
> +/*
> + * Unmaps the @count pages starting at @start_address, which were mapped by a
> + * call to xengnttab_map_grant_ref or xengnttab_map_grant_refs. Never logs.
> + */
> +int xengnttab_munmap(xengnttab_handle *xgt,
> +                     void *start_address,
> +                     uint32_t count);
> +
> +/*
> + * Sets the maximum number of grants that may be mapped by the given instance
> + * to @count.  Never logs.
> + *
> + * N.B. This function must be called after opening the handle, and before any
> + *      other functions are invoked on it.
> + *
> + * N.B. When variable-length grants are mapped, fragmentation may be observed,
> + *      and it may not be possible to satisfy requests up to the maximum number
> + *      of grants.
> + */
> +int xengnttab_set_max_grants(xengnttab_handle *xgt,
> +                            uint32_t count);
> +
> +/*
> + * Grant Sharing Interface (allocating and granting pages)
> + */
> +
> +typedef struct xengntdev_handle xengntshr_handle;
> +
> +/*
> + * Return an fd onto the grant sharing driver.  Logs errors.
> + *
> + * Note:
> + * After fork a child process must not use any opened xc gntshr
> + * handle inherited from their parent. They must open a new handle if
> + * they want to interact with xc.
> + *
> + */
> +xengntshr_handle *xengntshr_open(xentoollog_logger *logger,
> +                         unsigned open_flags);
> +
> +/*
> + * Close a handle previously allocated with xengntshr_open().
> + * Never logs errors.
> + */
> +int xengntshr_close(xengntshr_handle *xgs);
> +
> +/*
> + * Creates and shares pages with another domain.
> + *
> + * @parm xgs 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 *xengntshr_share_pages(xengntshr_handle *xgs, uint32_t domid,
> +                            int count, uint32_t *refs, int writable);
> +
> +/*
> + * Creates and shares a page with another domain, with unmap notification.
> + *
> + * @parm xgs 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 *xengntshr_share_page_notify(xengntshr_handle *xgs, 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 xengntshr_share_*. Never logs.
> + */
> +int xengntshr_munmap(xengntshr_handle *xgs, void *start_address, uint32_t count);
> +
> +#endif
> +
> +/*
> + * Local variables:
> + * mode: C
> + * c-file-style: "BSD"
> + * c-basic-offset: 4
> + * tab-width: 4
> + * indent-tabs-mode: nil
> + * End:
> + */

  reply	other threads:[~2015-09-22 11:25 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-15 15:46 [PATCH v2 0/15+5+5] Begin to disentangle libxenctrl and provide some stable libraries Ian Campbell
2015-07-15 15:46 ` [PATCH XEN v2 01/15] docs: Partial toolstack library API/ABI stabilisation Ian Campbell
2015-07-15 15:46 ` [PATCH XEN v2 02/15] tools/Rules.mk: Properly handle libraries with recursive dependcies Ian Campbell
2015-07-15 15:46 ` [PATCH XEN v2 03/15] tools: Refactor "xentoollog" into its own library Ian Campbell
2015-07-15 15:46 ` [PATCH XEN v2 04/15] tools/libxc: Remove osdep indirection for xc_evtchn Ian Campbell
2015-07-15 15:46 ` [PATCH XEN v2 05/15] tools: Refactor /dev/xen/evtchn wrappers into libxenevtchn Ian Campbell
2015-09-21 15:53   ` Ian Campbell
2015-07-15 15:46 ` [PATCH XEN v2 06/15] tools: Arrange to check public headers for ANSI compatiblity Ian Campbell
2015-07-15 15:46 ` [PATCH XEN v2 07/15] tools/libxc: Remove osdep indirection for xc_gnt{shr, tab} Ian Campbell
2015-07-15 15:46 ` [PATCH XEN v2 08/15] tools: Refactor /dev/xen/gnt{dev, shr} wrappers into libxengnttab Ian Campbell
2015-09-22 11:25   ` Ian Campbell [this message]
2015-09-22 11:36     ` Andrew Cooper
2015-09-22 12:41       ` Ian Jackson
2015-09-22 12:51         ` Ian Campbell
2015-07-15 15:46 ` [PATCH XEN v2 09/15] tools/libxc: Remove osdep indirection for privcmd Ian Campbell
     [not found]   ` <01C96D24-A13F-46A6-A8A9-5C04E2E199AF@citrix.com>
2015-07-16  7:59     ` Dave Scott
2015-07-16  8:35       ` Ian Campbell
2015-07-15 15:46 ` [PATCH XEN v2 10/15] tools: Refactor hypercall calling wrappers into libxencall Ian Campbell
2015-07-15 15:46 ` [PATCH XEN v2 11/15] tools/libxc: drop xc_map_foreign_bulk_compat wrappers Ian Campbell
2015-07-15 15:47 ` [PATCH XEN v2 12/15] tools: Remove xc_map_foreign_batch Ian Campbell
2015-07-15 16:08   ` George Dunlap
2015-07-15 15:47 ` [PATCH XEN v2 13/15] tools: Implement xc_map_foreign_range(s) in terms of common helper Ian Campbell
2015-07-15 15:47 ` [PATCH XEN v2 14/15] tools: Refactor foreign memory mapping into libxenforeignmemory Ian Campbell
2015-07-15 15:47 ` [PATCH XEN v2 15/15] HACK: Add a .config to pull all the right bits Ian Campbell
2015-07-15 15:47 ` [PATCH QEMUT v2 1/5] qemu-xen-traditional: Use xentoollog as a separate library Ian Campbell
2015-07-15 15:47 ` [PATCH QEMUT v2 2/5] qemu-xen-traditional: Use libxenevtchn Ian Campbell
2015-07-15 15:47 ` [PATCH QEMUT v2 3/5] qemu-xen-traditional: Use libxengnttab Ian Campbell
2015-07-15 15:47 ` [PATCH QEMUT v2 4/5] qemu-xen-traditional: Add libxencall to rpath-link Ian Campbell
2015-07-15 15:47 ` [PATCH QEMUT v2 5/5] qemu-xen-traditional: Add libxenforeignmemory " Ian Campbell
2015-07-15 15:48 ` [PATCH MINI-OS v2 1/5] mini-os: Include libxentoollog with libxc Ian Campbell
2015-07-15 15:48 ` [PATCH MINI-OS v2 2/5] mini-os: Include libxenevtchn " Ian Campbell
2015-07-15 15:48 ` [PATCH MINI-OS v2 3/5] mini-os: Include libxengnttab " Ian Campbell
2015-07-15 15:48 ` [PATCH MINI-OS v2 4/5] mini-os: Include libxencall " Ian Campbell
2015-07-15 15:48 ` [PATCH MINI-OS v2 5/5] mini-os: Include libxenforeignmemory " Ian Campbell
2015-07-15 15:53 ` [PATCH v2 0/15+5+5] Begin to disentangle libxenctrl and provide some stable libraries Andrew Cooper
2015-07-22 11:12   ` Ian Campbell
2015-07-22 12:58     ` Andrew Cooper
2015-07-22 13:05       ` Ian Campbell
2015-07-27  8:57     ` Ian Campbell
2015-09-22 15:03 ` Oldest supported Xen version in upstream QEMU (Was: Re: [Minios-devel] [PATCH v2 0/15+5+5] Begin to disentangle libxenctrl and provide some stable libraries) Ian Campbell
2015-09-22 21:31   ` Stefano Stabellini
2015-09-23  8:29     ` Ian Campbell
2015-09-23 14:09       ` Konrad Rzeszutek Wilk
2015-09-23 14:17         ` Juergen Gross
2015-09-23 14:21           ` Konrad Rzeszutek Wilk
2015-09-23 14:26             ` Ian Campbell
2015-09-23 17:36       ` Stefano Stabellini
2015-09-24  7:15         ` Ian Campbell
2015-09-24  9:03           ` Fabio Fantoni
2015-09-24 19:33           ` Stefano Stabellini
2015-09-24 21:11             ` Ian Campbell
2015-09-24 22:19               ` Stefano Stabellini
2015-09-25  8:27                 ` Ian Campbell
2015-09-25 20:31                   ` Stefano Stabellini
2015-09-24 16:47 ` [Minios-devel] [PATCH v2 0/15+5+5] Begin to disentangle libxenctrl and provide some stable libraries Ian Campbell
     [not found] <55A7C446.3050308@aero.org>
2015-07-16 14:56 ` [PATCH XEN v2 08/15] tools: Refactor /dev/xen/gnt{dev, shr} wrappers into libxengnttab Ian Campbell

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=1442921112.10338.153.camel@citrix.com \
    --to=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=roger.pau@citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /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.