xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Jackson <Ian.Jackson@eu.citrix.com>
To: Jim Fehlig <jfehlig@suse.com>
Cc: xen-devel@lists.xensource.com, Ian Campbell <ian.campbell@citrix.com>
Subject: Re: [PATCH 00/12] libxl: fork: SIGCHLD flexibility
Date: Fri, 24 Jan 2014 12:41:54 +0000	[thread overview]
Message-ID: <21218.24466.92095.134875@mariner.uk.xensource.com> (raw)
In-Reply-To: <52E1EB97.4080007@suse.com>

Jim Fehlig writes ("Re: [Xen-devel] [PATCH 00/12] libxl: fork: SIGCHLD flexibility"):
> BTW, I only see the crash when the save/restore script is running.  I
> stopped the other scripts and domains, running only save/restore on a
> single domain, and see the crash rather quickly (within 10 iterations).

I'll look at the libvirt code, but:

With a recurring timeout, how can you ever know it's cancelled ?
There might be threads out there, which don't hold any locks, which
are in the process of executing a callback for a timeout.  That might
be arbitrarily delayed from the pov of the rest of the program.

E.g.:

 Thread A                                             Thread B

   invoke some libxl operation
X    do some libxl stuff
X    register timeout (libxl)
XV     record timeout info
X    do some more libxl stuff
     ...
X    do some more libxl stuff
X    deregister timeout (libxl internal)
X     converted to request immediate timeout
XV     record new timeout info
X      release libvirt event loop lock
                                            entering libvirt event loop
                                       V     observe timeout is immediate
                                       V      need to do callback
                                               call libxl driver

      entering libvirt event loop
 V     observe timeout is immediate
 V      need to do callback
         call libxl driver
           call libxl
  X          libxl sees timeout is live
  X          libxl does libxl stuff
         libxl driver deregisters
 V         record lack of timeout
         free driver's timeout struct
                                               call libxl
                                      X          libxl sees timeout is dead
                                      X          libxl does nothing
                                             libxl driver deregisters
                                       V       CRASH due to deregistering
                                       V        already-deregistered timeout

If this is how things are, then I think there is no sane way to use
libvirt's timeouts (!)

In principle I guess the driver could keep its per-timeout structs
around forever and remember whether they've been deregistered or not.
Each one would have to have a lock in it.

But if you think about it, if you have 10 threads all running the
event loop and you set a timeout to zero, doesn't that mean that every
thread's event loop should do the timeout callback as fast as it can ?
That could be a lot of wasted effort.

The best solution would appear to be to provide a non-recurring
callback.

> I'm not so thrilled with the timeout handling code in the libvirt libxl
> driver.  The driver maintains a list of active timeouts because IIRC,
> there were cases when the driver received timeout deregistrations when
> calling libxl_ctx_free, at which point some of the associated structures
> were freed.  The idea was to call libxl_osevent_occurred_timeout on any
> active timeouts before freeing libxlDomainObjPrivate and its contents.

libxl does deregister fd callbacks in libxl_ctx_free.

But libxl doesn't currently "deregister" any timeouts in
libxl_ctx_free; indeed it would be a bit daft for it to do so as at
libxl_ctx_free there are no aos running so there would be nothing to
time out.

But there is a difficulty with timeouts which libxl has set to occur
immediately but which have not yet actually had the callback.  The the
application cannot call libxl_ctx_free with such timeouts outstanding,
because that would imply later calling back into libxl with a stale
ctx.

(Looking at the code I see that the "nexi" are never actually freed.
Bah.)

Thanks,
Ian.

  reply	other threads:[~2014-01-24 12:41 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-17 16:23 [PATCH 00/12] libxl: fork: SIGCHLD flexibility Ian Jackson
2014-01-17 16:23 ` [PATCH 01/12] libxl: fork: Break out checked_waitpid Ian Jackson
2014-01-17 16:23 ` [PATCH 02/12] libxl: fork: Break out childproc_reaped_ours Ian Jackson
2014-01-17 16:23 ` [PATCH 03/12] libxl: fork: Clarify docs for libxl_sigchld_owner Ian Jackson
2014-01-17 16:23 ` [PATCH 04/12] libxl: fork: Document libxl_sigchld_owner_libxl better Ian Jackson
2014-01-17 16:28   ` Ian Campbell
2014-01-17 16:23 ` [PATCH 05/12] libxl: fork: assert that chldmode is right Ian Jackson
2014-01-17 16:23 ` [PATCH 06/12] libxl: fork: Provide libxl_childproc_sigchld_occurred Ian Jackson
2014-01-17 16:24 ` [PATCH 07/12] libxl: fork: Provide ..._always_selective_reap Ian Jackson
2014-01-17 22:17   ` Jim Fehlig
2014-01-17 16:24 ` [PATCH 08/12] libxl: fork: Provide LIBXL_HAVE_SIGCHLD_SELECTIVE_REAP Ian Jackson
2014-01-17 16:24 ` [PATCH 09/12] libxl: fork: Rename sigchld handler functions Ian Jackson
2014-01-20  9:59   ` Ian Campbell
2014-01-17 16:24 ` [PATCH 10/12] libxl: fork: Break out sigchld_installhandler_core Ian Jackson
2014-01-20  9:59   ` Ian Campbell
2014-01-17 16:24 ` [PATCH 11/12] libxl: fork: Break out sigchld_sethandler_raw Ian Jackson
2014-01-20  9:58   ` Ian Campbell
2014-01-20 17:57     ` Ian Jackson
2014-01-17 16:24 ` [PATCH 12/12] libxl: fork: Share SIGCHLD handler amongst ctxs Ian Jackson
2014-01-17 18:13   ` Ian Jackson
2014-01-20  9:56     ` Ian Campbell
2014-01-21 14:40       ` Ian Jackson
2014-01-21 14:53         ` Ian Campbell
2014-01-21 15:09           ` Ian Jackson
2014-01-17 16:37 ` [PATCH 00/12] libxl: fork: SIGCHLD flexibility Ian Jackson
2014-01-17 22:29 ` Jim Fehlig
2014-01-20 18:14   ` Jim Fehlig
2014-01-21 14:46     ` Ian Jackson
2014-01-21 15:11       ` [PATCH 13/12] libxl: events: Break out libxl__pipe_nonblock, _close Ian Jackson
2014-01-21 15:11         ` [PATCH 14/12] libxl: fork: Make SIGCHLD self-pipe nonblocking Ian Jackson
2014-01-21 15:32           ` Ian Campbell
2014-01-21 15:48             ` Ian Jackson
2014-01-21 15:27         ` [PATCH 13/12] libxl: events: Break out libxl__pipe_nonblock, _close Ian Campbell
2014-01-21 15:31           ` Ian Jackson
2014-01-21 15:28     ` [PATCH 00/12] libxl: fork: SIGCHLD flexibility Ian Jackson
2014-01-22  5:32       ` Jim Fehlig
2014-01-23  4:05         ` Jim Fehlig
2014-01-23 10:56           ` Ian Jackson
2014-01-23 21:36             ` Jim Fehlig
2014-01-24  4:27             ` Jim Fehlig
2014-01-24 12:41               ` Ian Jackson [this message]
2014-01-24 12:52                 ` Ian Campbell
2014-01-24 15:14                   ` Ian Jackson
2014-01-24 15:18                     ` Ian Jackson
2014-01-24 16:36                     ` Ian Jackson
2014-01-24 16:57                       ` Ian Jackson
2014-01-27  5:39                   ` Jim Fehlig
2014-01-27  5:22                 ` Jim Fehlig
2014-01-27 14:48                   ` Ian Jackson
2014-01-28  1:39                 ` [libvirt] [Xen-devel] " Jim Fehlig
2014-01-28 10:06                   ` Daniel P. Berrange
2014-01-29 16:23                     ` [libvirt] " Ian Jackson
2014-01-30 12:18                   ` [libvirt] [Xen-devel] " Daniel P. Berrange
2014-01-30 16:14                     ` Jim Fehlig
2014-01-30 16:17                       ` Daniel P. Berrange
2014-01-30 16:28                   ` Ian Jackson
2014-01-30 16:56                     ` Jim Fehlig
2014-01-30 17:12                       ` [libvirt] [Xen-devel] " Ian Jackson

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=21218.24466.92095.134875@mariner.uk.xensource.com \
    --to=ian.jackson@eu.citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=jfehlig@suse.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).