All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Campbell <ian.campbell@citrix.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>, Wei Liu <wei.liu2@citrix.com>
Cc: Daniel De Graaf <dgdegra@tycho.nsa.gov>,
	ian.jackson@eu.citrix.com, xen-devel@lists.xen.org
Subject: Re: [PATCH XEN v6 25/32] tools/libs/gnttab: Extensive updates to API documentation.
Date: Wed, 9 Dec 2015 14:03:24 +0000	[thread overview]
Message-ID: <1449669804.16124.250.camel@citrix.com> (raw)
In-Reply-To: <566831BE.4040809@citrix.com>

On Wed, 2015-12-09 at 13:50 +0000, Andrew Cooper wrote:
> On 09/12/15 13:00, Ian Campbell wrote:
> > On Wed, 2015-12-09 at 12:41 +0000, Wei Liu wrote:
> > > > + */
> > > > +
> > > > +/*
> > > >   * 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.
> > > > + * Returns a handle onto the grant table driver.  Logs errors.
> > > > + *
> > > > + * Note: After fork a child process must not use any opened gnttab
> > > > + * handle inherited from their parent, more access any grant
> > > > mapped
> > > > + * areas associated with that handle.
> > > > + *
> > > And this could use the same cloexec trick as you do in other patch
> > > for
> > > privcmd.
> > I think this statement "do not use the handle" still stands regardless
> > of
> > the underlying fd being cloexec'd.
> > 
> > However, this did make me think about a comment elsewhere, specifically
> > the
> > various instances of:
> >  * This is the only function which may be safely called on a
> >  * xen<foo>_handle in a child after a fork.
> > for several xen<foo>_close() functions.
> > 
> > This is not really true if the fd is cloexec, since then _close() will
> > either fail (EBADF) or, worse, close some other freshly opened file
> > descriptor.
> > 
> > There seems to be two choices here, either require all osdep backends
> > to
> > make their fds O_CLOEXEC (which might involve tolerating a racy
> > fcntl+FD_CLOEXEC pattern after open on some platforms) or don't set
> > O_CLOEXEC ever and declare that the application is responsible for
> > closing
> > after fork, and for taking care of the corner cases themselves in
> > multithreaded applications.
> > 
> > The former seems friendlier to me, even if some platforms need to use
> > FD_CLOEXEC.
> > 
> > Hrm, maybe I can extend the atfork trick to cover the open+fcntl bits.
> > Hopefully there is no issue with using pthreads from each of the
> > affected
> > libraries.
> > 
> > So, I think the advice in the comment would then be:
> > 
> >     If you fork and then exec then you must not (and need not) call
> > _close()
> >     or any other function on the handle.
> > 
> >     If you fork but do not exec then it is permissible to call
> > _close(), but
> >     it is not permissible to call any other function on the handle.
> > 
> > Need to think about that wording.
> 
> This is risky.  What if $FOO_open() allocated more resource than just
> the CLOEXEC fd?

Any allocated memory (the other main class of such resource) will be
abolished by an exec, hence the distinction made above between fork and
fork+exec.

What other sorts of resources are you worried about?

> An _open() call must be matched with a _close() call.

This is not safe after an exec though, since the fd will be closed, or
perhaps even reopened already (although the requirement could be to call
_close before doing such things as opening any fds, at which point close
could silently handle EBADF).

> In the case of fork but no exec, there should be a _close() call in both
> the parent and child, to free other resources.

In the parent I assume you mean "at some point (or call exit())" rather
than in some way associated with the forking, because the parent is
entitled to keep using the handle.

Ian.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  reply	other threads:[~2015-12-09 14:03 UTC|newest]

Thread overview: 134+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-03 11:21 [Qemu-devel] [Minios-devel] [PATCH v6 0/<VARIOUS>] Begin to disentangle libxenctrl and provide some stable libraries Ian Campbell
2015-12-03 11:21 ` [PATCH XEN v6 00/32] " Ian Campbell
2015-12-03 11:21   ` [PATCH XEN v6 01/32] x86/libxc: add an arch domain config parameter to xc_domain_create Ian Campbell
2015-12-09 12:21     ` Wei Liu
2015-12-03 11:21   ` [PATCH XEN v6 02/32] mce-test: do not include libxenguest internal headers Ian Campbell
2015-12-03 12:48     ` Andrew Cooper
2015-12-09 12:22     ` Wei Liu
2015-12-03 11:22   ` [PATCH XEN v6 03/32] tools/ocaml: simplify compile/link of test apps Ian Campbell
2015-12-03 11:59     ` David Scott
2015-12-09 12:22     ` Wei Liu
2015-12-03 11:22   ` [PATCH XEN v6 04/32] tools/Rules.mk: Properly handle libraries with recursive dependencies Ian Campbell
2015-12-03 11:22   ` [PATCH XEN v6 05/32] tools: Refactor "xentoollog" into its own library Ian Campbell
2015-12-03 11:22   ` [PATCH XEN v6 06/32] tools/libxc: Remove osdep indirection for xc_evtchn Ian Campbell
2015-12-03 11:22   ` [PATCH XEN v6 07/32] tools: Refactor /dev/xen/evtchn wrappers into libxenevtchn Ian Campbell
2015-12-03 11:22   ` [PATCH XEN v6 08/32] tools: Arrange to check public headers for ANSI compatiblity Ian Campbell
2015-12-03 11:22   ` [PATCH XEN v6 09/32] tools/libxc: Remove osdep indirection for xc_gnt{shr, tab} Ian Campbell
2015-12-03 11:22   ` [PATCH XEN v6 10/32] tools: Refactor /dev/xen/gnt{dev, shr} wrappers into libxengnttab Ian Campbell
2015-12-14 14:07     ` Ian Campbell
2015-12-03 11:22   ` [PATCH XEN v6 11/32] tools/libxc: Remove osdep indirection for privcmd Ian Campbell
2015-12-03 11:22   ` [PATCH XEN v6 12/32] tools: Refactor hypercall calling wrappers into libxencall Ian Campbell
2015-12-03 11:22   ` [PATCH XEN v6 13/32] tools/libxc: drop xc_map_foreign_bulk_compat wrappers Ian Campbell
2015-12-03 11:22   ` [PATCH XEN v6 14/32] tools: Remove xc_map_foreign_batch Ian Campbell
2015-12-09 12:22     ` Wei Liu
2015-12-10 15:21     ` George Dunlap
2015-12-11 15:42       ` Ian Campbell
2015-12-11 16:04         ` George Dunlap
2015-12-03 11:22   ` [PATCH XEN v6 15/32] tools: Implement xc_map_foreign_range(s) in terms of common helper Ian Campbell
2015-12-03 11:22   ` [PATCH XEN v6 16/32] tools: Refactor foreign memory mapping into libxenforeignmemory Ian Campbell
2015-12-09 15:38     ` Ian Jackson
2015-12-03 11:22   ` [PATCH XEN v6 17/32] tools/libs/foreignmemory: provide xenforeignmemory_unmap Ian Campbell
2015-12-09 15:38     ` Ian Jackson
2015-12-03 11:22   ` [PATCH XEN v6 18/32] tools/libs/foreignmemory: use size_t for size arguments Ian Campbell
2015-12-03 11:22   ` [PATCH XEN v6 19/32] tools/libs/foreignmemory: Mention restrictions on fork in docs Ian Campbell
2015-12-03 11:22   ` [PATCH XEN v6 20/32] tools/libs/foreignmemory: Support err == NULL to map Ian Campbell
2015-12-09 12:22     ` Wei Liu
2015-12-09 12:31       ` Egger, Christoph
2015-12-09 12:45         ` Ian Campbell
2015-12-09 12:41       ` Ian Campbell
2015-12-09 12:56         ` Wei Liu
2015-12-09 13:15           ` Ian Campbell
2015-12-09 16:16             ` Wei Liu
2015-12-09 15:40     ` Ian Jackson
2015-12-03 11:22   ` [PATCH XEN v6 21/32] tools/libs/foreignmemory: pull array length argument to map forward Ian Campbell
2015-12-09 12:22     ` Wei Liu
2015-12-09 15:41     ` Ian Jackson
2015-12-03 11:22   ` [PATCH XEN v6 22/32] tools/libs/foreignmemory: optimise map(num==1, err==NULL) case Ian Campbell
2015-12-09 15:42     ` Ian Jackson
2015-12-11 15:56       ` Ian Campbell
2015-12-03 11:22   ` [PATCH XEN v6 23/32] tools/libs/evtchn: Review and update doc comments Ian Campbell
2015-12-03 11:22   ` [PATCH XEN v6 24/32] tools/libs: Clean up hard tabs Ian Campbell
2015-12-03 11:22   ` [PATCH XEN v6 25/32] tools/libs/gnttab: Extensive updates to API documentation Ian Campbell
2015-12-03 18:08     ` Daniel De Graaf
2015-12-04 10:06       ` Ian Campbell
2015-12-09 12:41     ` Wei Liu
2015-12-09 13:00       ` Ian Campbell
2015-12-09 13:37         ` Wei Liu
2015-12-09 13:50         ` Andrew Cooper
2015-12-09 14:03           ` Ian Campbell [this message]
2015-12-09 16:14             ` Ian Jackson
2015-12-09 16:09     ` Ian Jackson
2015-12-09 16:25       ` Ian Campbell
2015-12-09 16:28         ` Ian Jackson
2015-12-09 17:08           ` Ian Campbell
2015-12-11 17:14             ` Ian Campbell
2015-12-11 17:19               ` Ian Jackson
2015-12-11 17:35                 ` Ian Campbell
2015-12-14 11:29                   ` Ian Campbell
2015-12-14 11:55                     ` Ian Jackson
2015-12-03 11:22   ` [PATCH XEN v6 26/32] tools/libs/call: Update some log messages to not refer to xc Ian Campbell
2015-12-03 11:22   ` [PATCH XEN v6 27/32] tools/libs/call: Describe return values and error semantics for xencall* Ian Campbell
2015-12-09 12:22     ` Wei Liu
2015-12-09 16:15     ` Ian Jackson
2015-12-03 11:22   ` [PATCH XEN v6 28/32] tools/libs/call: Avoid xc_memalign in netbsd and solaris backends Ian Campbell
2015-12-03 11:22   ` [PATCH XEN v6 29/32] tools/libs/call: Use O_CLOEXEC when opening /dev/xen/privcmd on Linux Ian Campbell
2015-12-09 12:22     ` Wei Liu
2015-12-09 16:17     ` Ian Jackson
2015-12-11 17:22       ` Ian Campbell
2015-12-12 10:55         ` Roger Pau Monné
2015-12-03 11:22   ` [PATCH XEN v6 30/32] tools/libs/call: linux: avoid forking between mmap and madvise Ian Campbell
2015-12-09 12:22     ` Wei Liu
2015-12-09 16:18     ` Ian Jackson
2015-12-11 17:16       ` Ian Campbell
2015-12-03 11:22   ` [PATCH XEN v6 31/32] tools: Update CFLAGS for qemu-xen to allow it to use new libraries Ian Campbell
2015-12-03 11:22   ` [PATCH XEN v6 32/32] HACK: Update Config.mk to pull all the right bits from my xenbits trees Ian Campbell
2015-12-03 11:23 ` [PATCH QEMU-XEN v6 0/8] Begin to disentangle libxenctrl and provide some stable libraries Ian Campbell
2015-12-03 11:23 ` [Qemu-devel] " Ian Campbell
2015-12-03 11:23   ` [PATCH QEMU-XEN v6 1/8] xen_console: correctly cleanup primary console on teardown Ian Campbell
2015-12-03 11:23   ` [Qemu-devel] " Ian Campbell
2015-12-03 11:23   ` [PATCH QEMU-XEN v6 2/8] xen: Switch to libxenevtchn interface for compat shims Ian Campbell
2015-12-03 11:23   ` [Qemu-devel] " Ian Campbell
2015-12-03 11:23   ` [Qemu-devel] [PATCH QEMU-XEN v6 3/8] xen: Switch to libxengnttab " Ian Campbell
2015-12-03 11:23     ` Ian Campbell
2015-12-03 11:23   ` [Qemu-devel] [PATCH QEMU-XEN v6 4/8] xen: Switch uses of xc_map_foreign_range into xc_map_foreign_pages Ian Campbell
2015-12-03 11:23     ` Ian Campbell
2015-12-04 15:26     ` [Qemu-devel] " Stefano Stabellini
2015-12-04 15:26     ` Stefano Stabellini
2015-12-09 13:41     ` [Qemu-devel] " Ian Campbell
2015-12-09 13:56       ` Andrew Cooper
2015-12-09 13:56       ` [Qemu-devel] [Xen-devel] " Andrew Cooper
2015-12-09 14:05         ` Ian Campbell
2015-12-09 14:05         ` [Qemu-devel] [Xen-devel] " Ian Campbell
2015-12-11 14:26       ` [Qemu-devel] " Stefano Stabellini
2015-12-11 15:23         ` Ian Campbell
2015-12-11 15:23           ` Ian Campbell
2015-12-11 16:42           ` Stefano Stabellini
2015-12-11 16:42           ` [Qemu-devel] " Stefano Stabellini
2015-12-11 14:26       ` Stefano Stabellini
2015-12-09 13:41     ` Ian Campbell
2015-12-03 11:23   ` [Qemu-devel] [PATCH QEMU-XEN v6 5/8] xen: Switch uses of xc_map_foreign_{pages, bulk} to use libxenforeignmemory API Ian Campbell
2015-12-03 11:23     ` Ian Campbell
2015-12-04 15:26     ` [Qemu-devel] " Stefano Stabellini
2015-12-04 15:26     ` Stefano Stabellini
2015-12-03 11:23   ` [PATCH QEMU-XEN v6 6/8] xen: Use stable library interfaces when they are available Ian Campbell
2015-12-03 11:23   ` [Qemu-devel] " Ian Campbell
2015-12-04 15:31     ` Stefano Stabellini
2015-12-04 15:31     ` [Qemu-devel] " Stefano Stabellini
2015-12-03 11:23   ` [Qemu-devel] [PATCH QEMU-XEN v6 7/8] xen: domainbuild: reopen libxenctrl interface after forking for domain watcher Ian Campbell
2015-12-03 11:23     ` Ian Campbell
2015-12-03 11:23   ` [Qemu-devel] [PATCH QEMU-XEN v6 8/8] xen: make it possible to build without the Xen PV domain builder Ian Campbell
2015-12-03 11:23     ` Ian Campbell
2015-12-03 11:23 ` [PATCH QEMU-XEN-TRADITIONAL v6 0/5] Begin to disentangle libxenctrl and provide some stable libraries Ian Campbell
2015-12-03 11:23   ` [PATCH QEMU-XEN-TRADITIONAL v6 1/5] qemu-xen-traditional: Use xentoollog as a separate library Ian Campbell
2015-12-03 11:23   ` [PATCH QEMU-XEN-TRADITIONAL v6 2/5] qemu-xen-traditional: Use libxenevtchn Ian Campbell
2015-12-03 11:23   ` [PATCH QEMU-XEN-TRADITIONAL v6 3/5] qemu-xen-traditional: Use libxengnttab Ian Campbell
2015-12-03 11:23   ` [PATCH QEMU-XEN-TRADITIONAL v6 4/5] qemu-xen-traditional: Add libxencall to rpath-link Ian Campbell
2015-12-03 11:23   ` [PATCH QEMU-XEN-TRADITIONAL v6 5/5] qemu-xen-traditional: Add libxenforeignmemory " Ian Campbell
2015-12-03 11:23 ` [PATCH MINI-OS v6 0/5] Begin to disentangle libxenctrl and provide some stable libraries Ian Campbell
2015-12-03 11:23   ` [PATCH MINI-OS v6 1/5] mini-os: Include libxentoollog with libxc Ian Campbell
2015-12-03 11:23   ` [PATCH MINI-OS v6 2/5] mini-os: Include libxenevtchn " Ian Campbell
2015-12-03 11:23   ` [PATCH MINI-OS v6 3/5] mini-os: Include libxengnttab " Ian Campbell
2015-12-03 11:23   ` [PATCH MINI-OS v6 4/5] mini-os: Include libxencall " Ian Campbell
2015-12-03 11:23   ` [PATCH MINI-OS v6 5/5] mini-os: Include libxenforeignmemory " Ian Campbell
2015-12-09 12:37 ` [Minios-devel] [PATCH v6 0/<VARIOUS>] Begin to disentangle libxenctrl and provide some stable libraries Ian Campbell
2015-12-09 12:37 ` [Qemu-devel] " 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=1449669804.16124.250.camel@citrix.com \
    --to=ian.campbell@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=dgdegra@tycho.nsa.gov \
    --cc=ian.jackson@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.