qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Umesh Deshpande <udeshpan@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [RFC PATCH v4 3/5] separate migration bitmap
Date: Mon, 22 Aug 2011 10:30:52 +0200	[thread overview]
Message-ID: <4E5213BC.1070905@redhat.com> (raw)
In-Reply-To: <4E506250.6050405@redhat.com>

On 08/21/2011 03:41 AM, Umesh Deshpande wrote:
>>
>> This should be run under the iothread lock.  Pay attention to avoiding
>> lock inversion: the I/O thread always takes the iothread lock outside
>> and the ramlist lock within, so the migration thread must do the same.
>>
>> BTW, I think this code in the migration thread patch also needs the
>> iothread lock:
>>
>>>     if (stage < 0) {
>>>         cpu_physical_memory_set_dirty_tracking(0);
>>>         return 0;
>>>     }
>>>
>>>     if (cpu_physical_sync_dirty_bitmap(0, TARGET_PHYS_ADDR_MAX) != 0) {
>>>         qemu_file_set_error(f);
>>>         return 0;
>>>     }
>>>
> Callers of above code snippets (sync_migration_bitmap etc.) are holding
> the iothread mutex. It has been made sure that the original qemu dirty
> bitmap is only accessed when holding the mutex.

But you cannot do it like in this patch, because here you have a deadlock:

> +    if (stage != 3) {
> +        qemu_mutex_lock_ramlist();
> +        qemu_mutex_unlock_iothread();
> +    }
> +
>      while (!qemu_file_rate_limit(f)) {
>          int bytes_sent;
>
> @@ -308,6 +315,11 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
>          }
>      }
>
> +    if (stage != 3) {
> +        qemu_mutex_lock_iothread();

Lock order: ramlist, iothread.  The I/O thread instead takes the 
iothread lock outside and the ramlist lock inside.  All this makes me 
even more convinced that you're locking is both too coarse and too 
complicated (perhaps it's not complicated, it's just under-documented; 
but the coarseness problem is there and it's what causes these lock 
inversions).

> +        qemu_mutex_unlock_ramlist();
> +    }
> +

Paolo

  reply	other threads:[~2011-08-22  8:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-19 12:51 [Qemu-devel] [RFC PATCH v4 3/5] separate migration bitmap Paolo Bonzini
2011-08-21  1:41 ` Umesh Deshpande
2011-08-22  8:30   ` Paolo Bonzini [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-08-17  3:56 [Qemu-devel] [RFC PATCH v4 0/5] Separate thread for VM migration Umesh Deshpande
2011-08-17  3:56 ` [Qemu-devel] [RFC PATCH v4 3/5] separate migration bitmap Umesh Deshpande

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=4E5213BC.1070905@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=udeshpan@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 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).