[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access
From: |
Jan Kiszka |
Subject: |
Re: [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access |
Date: |
Thu, 01 Sep 2011 23:03:12 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 |
On 2011-09-01 21:35, Luiz Capitulino wrote:
> Sometimes, when having lots of VMs running on a RHEV host and the user
> attempts to close a SPICE window, libvirt will get corrupted json from
> QEMU.
>
> After some investigation, I found out that the problem is that different
> SPICE threads are calling monitor functions (such as
> monitor_protocol_event()) in parallel which causes concurrent access
> to the monitor's internal buffer outbuf[].
>
> This fixes the problem by protecting accesses to outbuf[] with a mutex.
>
> Honestly speaking, I'm not completely sure this the best thing to do
> because the monitor itself and other qemu subsystems are not thread safe,
> so having subsystems like SPICE assuming the contrary seems a bit
> catastrophic to me...
I fully agree.
...
> @@ -246,10 +248,14 @@ static int monitor_read_password(Monitor *mon,
> ReadLineFunc *readline_func,
>
> void monitor_flush(Monitor *mon)
> {
> + qemu_mutex_lock(&mon->mutex);
> +
> if (mon && mon->outbuf_index != 0 && !mon->mux_out) {
> qemu_chr_fe_write(mon->chr, mon->outbuf, mon->outbuf_index);
> mon->outbuf_index = 0;
> }
> +
> + qemu_mutex_unlock(&mon->mutex);
Here is another example for things that can break due to "optimistic"
parallelization: What protects the chardev state that will be touched by
calling qemu_chr_fe_write? Even when ignoring mux'ed channels for now, I
bet there are code paths that modify the state without holding the
frontend lock (i.e. Monitor::mutex).
Jan
signature.asc
Description: OpenPGP digital signature
- [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access, Luiz Capitulino, 2011/09/01
- Re: [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access, Daniel P. Berrange, 2011/09/01
- Re: [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access,
Jan Kiszka <=
- Re: [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access, Anthony Liguori, 2011/09/01
- Re: [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access, Daniel P. Berrange, 2011/09/02
- Re: [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access, Gerd Hoffmann, 2011/09/02
- Re: [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access, Anthony Liguori, 2011/09/02
- Re: [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access, Luiz Capitulino, 2011/09/02
- Re: [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access, Anthony Liguori, 2011/09/02
- Re: [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access, Gerd Hoffmann, 2011/09/02
- Re: [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access, Anthony Liguori, 2011/09/02
- Re: [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access, Paolo Bonzini, 2011/09/02