From: Peter Maydell <peter.maydell@linaro.org>
To: QEMU Developers <qemu-devel@nongnu.org>
Cc: Riku Voipio <riku.voipio@iki.fi>, Alexander Graf <agraf@suse.de>
Subject: Re: [Qemu-devel] linux-user: interrupting syscalls
Date: Fri, 17 Jan 2014 16:40:13 +0000 [thread overview]
Message-ID: <CAFEAcA-WOR6nNAkvMzEQYNY6ycRegpU7GAFTp51aXJF2977V+Q@mail.gmail.com> (raw)
In-Reply-To: <CAFEAcA_01hEn8fcCF03P7UECPZdbx2CpzxuG7C19h=d1rj_Vwg@mail.gmail.com>
This is resurrecting a two year old waffly proposal (full text
here: http://lists.gnu.org/archive/html/qemu-devel/2011-12/msg00384.html)
because I realised my idea was broken.
On 4 December 2011 16:29, Peter Maydell <peter.maydell@linaro.org> wrote:
> When run natively, this program will block until you send it a
> SIGUSR1; the signal handler will write to the pipe and cause the read
> to complete. Run in linux-user mode, we deadlock, because qemu does
> not run the guest signal handler when in the middle of emulating a
> system call -- it merely queues it to be run when the syscall
> finishes. For cases like this where the event that causes the syscall
> to complete is actually triggered by the guest signal handler, this
> doesn't work. (There is a real-world instance of this problem in the
> Boehm garbage collector, where a signal handler posts to a semaphore
> which is being waited on by the mainline code.)
>
> It's not sufficient to simply force all syscalls to be non-restartable
> (and then to take the signal when the syscall returns EINTR), because
> of the following race condition:
> * qemu enters do_syscall on behalf of main thread
> * do_syscall is about to call the underlying syscall, when...
> * the signal arrives (and we queue it)
> * do_syscall then calls the host syscall, which will block. Oops.
>
> To fix this I think we need to have linux-user's signal handler
> wrapper do a siglongjmp if a signal arrives while we're inside
> do_syscall(). This allows us to properly interrupt whether we'd
> got to the point of making the host syscall or not.
This won't work, because there's no way to tell the difference
between "we longjmped out of a write syscall before the kernel
wrote anything" and "we longjmped out just after the kernel
returned from a write syscall having written the buffer", so
you can't tell if you need to repeat the syscall or not.
I'm no longer sure if there's any fix for these races at all :-(
thanks
-- PMM
prev parent reply other threads:[~2014-01-17 16:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-04 16:29 [Qemu-devel] linux-user: interrupting syscalls Peter Maydell
2014-01-17 16:40 ` Peter Maydell [this message]
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=CAFEAcA-WOR6nNAkvMzEQYNY6ycRegpU7GAFTp51aXJF2977V+Q@mail.gmail.com \
--to=peter.maydell@linaro.org \
--cc=agraf@suse.de \
--cc=qemu-devel@nongnu.org \
--cc=riku.voipio@iki.fi \
/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).