All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PULL for-3.0 1/1] trace/simple: fix hang in child after fork(2)
Date: Tue, 24 Jul 2018 15:41:01 +0100	[thread overview]
Message-ID: <20180724144101.GL19167@redhat.com> (raw)
In-Reply-To: <20180724143551.GK19167@redhat.com>

On Tue, Jul 24, 2018 at 03:35:51PM +0100, Daniel P. Berrangé wrote:
> On Tue, Jul 24, 2018 at 03:25:04PM +0100, Stefan Hajnoczi wrote:
> > The simple trace backend spawns a write-out thread which is used to
> > asynchronously flush the in-memory ring buffer to disk.
> > 
> > fork(2) does not clone all threads, only the thread that invoked
> > fork(2).  As a result there is no write-out thread in the child process!
> > 
> > This causes a hang during shutdown when atexit(3) handler installed by
> > the simple trace backend waits for the non-existent write-out thread.
> > 
> > This patch uses pthread_atfork(3) to terminate the write-out thread
> > before fork and restart it in both the parent and child after fork.
> > This solves a hang in qemu-iotests 147 due to qemu-nbd --fork usage.
> 
> I'm not convinced this is safe, as it looks like it has a window in
> which both the parent and child processes will be doing write-out to
> the same file.
> 
> In particular in the main QEMU system emulators it means that any
> time we fork() in QEMU, eg for spawning commands with migration
> exec: URI, or TAP devuce ifup scripts, etc, we'll be starting a
> write-out thread in the child.

I'd be more inclined to have the pthread_atfork() handle simply terminate
the tracing process, reversing all effects of trace_init_backends(). Then
after qemu-nbd has called fork(), it can simply call trace_init_backends()
explicitly to start it running again. This avoids unecessarily starting
tracing in child processes that are not requiring/expecting it.

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

  reply	other threads:[~2018-07-24 14:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-24 14:25 [Qemu-devel] [PULL for-3.0 0/1] Tracing patches Stefan Hajnoczi
2018-07-24 14:25 ` [Qemu-devel] [PULL for-3.0 1/1] trace/simple: fix hang in child after fork(2) Stefan Hajnoczi
2018-07-24 14:35   ` Daniel P. Berrangé
2018-07-24 14:41     ` Daniel P. Berrangé [this message]
2018-07-26 14:18       ` Stefan Hajnoczi
2018-07-24 15:16   ` Eric Blake
2018-07-24 15:13 ` [Qemu-devel] [PULL for-3.0 0/1] Tracing patches Eric Blake
2018-07-24 19:54   ` Peter Maydell

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=20180724144101.GL19167@redhat.com \
    --to=berrange@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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.