From: Avi Kivity <avi@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Jan Kiszka <jan.kiszka@siemens.com>,
qemu-devel@nongnu.org, kvm@vger.kernel.org, laurent@vivier.eu,
anthony@codemonkey.ws
Subject: Re: [RFC PATCH] fix select(2) race between main_loop_wait and qemu_aio_wait
Date: Mon, 05 Mar 2012 17:14:46 +0200 [thread overview]
Message-ID: <4F54D866.30402@redhat.com> (raw)
In-Reply-To: <4F54CDFE.3030309@redhat.com>
On 03/05/2012 04:30 PM, Paolo Bonzini wrote:
> Il 05/03/2012 15:24, Avi Kivity ha scritto:
> > On 03/05/2012 11:07 AM, Jan Kiszka wrote:
> >> On 2012-03-05 09:34, Paolo Bonzini wrote:
> >>> This is quite ugly. Two threads, one running main_loop_wait and
> >>> one running qemu_aio_wait, can race with each other on running the
> >>> same iohandler. The result is that an iohandler could run while the
> >>> underlying socket is not readable or writable, with possibly ill effects.
> >>
> >> Hmm, isn't it a problem already that a socket is polled by two threads
> >> at the same time? Can't that be avoided?
> >
> > Could it be done simply by adding a mutex there? It's hardly a clean
> > fix, but it's not a clean problem.
>
> Hmm, I don't think so. It would need to protect execution of the
> iohandlers too, and pretty much everything can happen there including a
> nested loop. Of course recursive mutexes exist, but it sounds like too
> big an axe.
The I/O handlers would still use the qemu mutex, no? we'd just protect
the select() (taking the mutex from before releasing the global lock,
and reacquiring it afterwards).
> I could add a generation count updated by qemu_aio_wait(), and rerun the
> select() only if the generation count changes during its execution.
>
> Or we can call it an NBD bug. I'm not against that, but it seemed to me
> that the problem is more general.
What about making sure all callers of qemu_aio_wait() run from
coroutines (or threads)? Then they just ask the main thread to wake
them up, instead of dispatching completions themselves.
--
error compiling committee.c: too many arguments to function
WARNING: multiple messages have this Message-ID (diff)
From: Avi Kivity <avi@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: anthony@codemonkey.ws, Jan Kiszka <jan.kiszka@siemens.com>,
qemu-devel@nongnu.org, kvm@vger.kernel.org, laurent@vivier.eu
Subject: Re: [Qemu-devel] [RFC PATCH] fix select(2) race between main_loop_wait and qemu_aio_wait
Date: Mon, 05 Mar 2012 17:14:46 +0200 [thread overview]
Message-ID: <4F54D866.30402@redhat.com> (raw)
In-Reply-To: <4F54CDFE.3030309@redhat.com>
On 03/05/2012 04:30 PM, Paolo Bonzini wrote:
> Il 05/03/2012 15:24, Avi Kivity ha scritto:
> > On 03/05/2012 11:07 AM, Jan Kiszka wrote:
> >> On 2012-03-05 09:34, Paolo Bonzini wrote:
> >>> This is quite ugly. Two threads, one running main_loop_wait and
> >>> one running qemu_aio_wait, can race with each other on running the
> >>> same iohandler. The result is that an iohandler could run while the
> >>> underlying socket is not readable or writable, with possibly ill effects.
> >>
> >> Hmm, isn't it a problem already that a socket is polled by two threads
> >> at the same time? Can't that be avoided?
> >
> > Could it be done simply by adding a mutex there? It's hardly a clean
> > fix, but it's not a clean problem.
>
> Hmm, I don't think so. It would need to protect execution of the
> iohandlers too, and pretty much everything can happen there including a
> nested loop. Of course recursive mutexes exist, but it sounds like too
> big an axe.
The I/O handlers would still use the qemu mutex, no? we'd just protect
the select() (taking the mutex from before releasing the global lock,
and reacquiring it afterwards).
> I could add a generation count updated by qemu_aio_wait(), and rerun the
> select() only if the generation count changes during its execution.
>
> Or we can call it an NBD bug. I'm not against that, but it seemed to me
> that the problem is more general.
What about making sure all callers of qemu_aio_wait() run from
coroutines (or threads)? Then they just ask the main thread to wake
them up, instead of dispatching completions themselves.
--
error compiling committee.c: too many arguments to function
next prev parent reply other threads:[~2012-03-05 15:14 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-05 8:34 [RFC PATCH] fix select(2) race between main_loop_wait and qemu_aio_wait Paolo Bonzini
2012-03-05 8:34 ` [Qemu-devel] " Paolo Bonzini
2012-03-05 9:07 ` Jan Kiszka
2012-03-05 9:07 ` [Qemu-devel] " Jan Kiszka
2012-03-05 9:25 ` Paolo Bonzini
2012-03-05 9:25 ` [Qemu-devel] " Paolo Bonzini
2012-03-05 14:24 ` Avi Kivity
2012-03-05 14:24 ` [Qemu-devel] " Avi Kivity
2012-03-05 14:30 ` Paolo Bonzini
2012-03-05 14:30 ` [Qemu-devel] " Paolo Bonzini
2012-03-05 15:14 ` Avi Kivity [this message]
2012-03-05 15:14 ` Avi Kivity
2012-03-05 16:14 ` Paolo Bonzini
2012-03-05 16:14 ` [Qemu-devel] " Paolo Bonzini
2012-03-05 17:35 ` Avi Kivity
2012-03-05 17:35 ` [Qemu-devel] " Avi Kivity
2012-03-06 9:01 ` Paolo Bonzini
2012-03-06 9:01 ` [Qemu-devel] " Paolo Bonzini
2012-03-05 14:30 ` Jan Kiszka
2012-03-05 14:30 ` [Qemu-devel] " Jan Kiszka
2012-03-05 17:39 ` Avi Kivity
2012-03-05 17:39 ` [Qemu-devel] " Avi Kivity
2012-03-05 17:55 ` Jan Kiszka
2012-03-05 17:55 ` [Qemu-devel] " Jan Kiszka
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=4F54D866.30402@redhat.com \
--to=avi@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=jan.kiszka@siemens.com \
--cc=kvm@vger.kernel.org \
--cc=laurent@vivier.eu \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.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.