All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Denis V. Lunev" <den@openvz.org>
Cc: qemu-devel@nongnu.org,
	 Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>,
	John Snow <jsnow@redhat.com>, Peter Xu <peterx@redhat.com>,
	 Fabiano Rosas <farosas@suse.de>,
	qemu-block@nongnu.org
Subject: Re: [PATCH] migration/block-dirty-bitmap: don't hold the load lock across stream reads
Date: Wed, 11 Nov 2026 10:14:32 -0600	[thread overview]
Message-ID: <avSSfOePcQNalVcV@redhat.com> (raw)
In-Reply-To: <20261110155113.2721134-1-den@openvz.org>

On Tue, Nov 10, 2026 at 07:24:08PM +0100, Denis V. Lunev wrote:
> From: Denis V. Lunev <den@openvz.org>
> 
> dirty_bitmap_load() takes dbm_state.load.lock for each chunk and holds
> it while it reads the chunk from the migration stream.
> 
> In precopy the load runs in the incoming migration coroutine, which
> yields in qemu_fill_buffer() while it waits for data, still holding
> the lock. A quit on the destination at that point never completes:
> migration_shutdown() calls dirty_bitmap_mig_cancel_incoming(), which
> takes the same lock in the same main thread.
> 
> In postcopy the load runs in the listen thread, and the main thread
> takes the lock in dirty_bitmap_mig_before_vm_start(), called from
> loadvm_postcopy_handle_run_bh(), and in migration_shutdown(). The main
> loop then waits until the source sends the next chunk.
> 
> Read each chunk into a DBMLoadChunk first and take the lock only to
> resolve the names and apply the chunk. The lock protects the bitmaps
> list and the resolved node and bitmap, which the main thread uses. The
> flags and alias strings read from the stream are only touched by the
> code doing the load.

I'm guessing this should be considered for 11.2, and necessary as a
followup for the recent commit 4d11088a "migration/block-dirty-bitmap:
fix postcopy abort...")?

> 
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> Cc: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> Cc: Eric Blake <eblake@redhat.com>
> Cc: John Snow <jsnow@redhat.com>
> Cc: Peter Xu <peterx@redhat.com>
> Cc: Fabiano Rosas <farosas@suse.de>
> Cc: qemu-block@nongnu.org
> ---
>  migration/block-dirty-bitmap.c | 222 +++++++++++++++++++--------------
>  1 file changed, 130 insertions(+), 92 deletions(-)
> 
> diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c
> index 35623379eb..14e5a984e4 100644
> --- a/migration/block-dirty-bitmap.c
> +++ b/migration/block-dirty-bitmap.c

> -static int dirty_bitmap_load_bits(QEMUFile *f, DBMLoadState *s)
> +static int dirty_bitmap_load_bits(DBMLoadState *s, DBMLoadChunk *c)
>  {
...
> -        needed_size = bdrv_dirty_bitmap_serialization_size(s->bitmap,
> -                                                           first_byte,
> -                                                           nr_bytes);
> -
> -        if (needed_size > buf_size ||
> -            buf_size > QEMU_ALIGN_UP(needed_size, 4 * sizeof(long))
> -             /* Here used same alignment as in send_bitmap_bits */
> -        ) {

It looks odd to see a comment appear mid-argument, which results in
unusual formatting...

> -            error_report("Migrated bitmap granularity doesn't "
> -                         "match the destination bitmap '%s' granularity",
> -                         bdrv_dirty_bitmap_name(s->bitmap));
> -            cancel_incoming_locked(s);
> -            return 0;
> -        }
> +    if (s->cancelled) {
> +        return 0;
> +    }
>  
> -        bdrv_dirty_bitmap_deserialize_part(s->bitmap, buf, first_byte, nr_bytes,
> -                                           false);
> +    needed_size = bdrv_dirty_bitmap_serialization_size(s->bitmap,
> +                                                       c->first_byte,
> +                                                       c->nr_bytes);
> +
> +    if (needed_size > c->buf_size ||
> +        c->buf_size > QEMU_ALIGN_UP(needed_size, 4 * sizeof(long))
> +         /* Here used same alignment as in send_bitmap_bits */
> +    ) {

...which then got preserved with an unindent. Not worth cleaning up,
but it did make me do a double-take.

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org



      reply	other threads:[~2026-11-11 16:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 18:24 [PATCH] migration/block-dirty-bitmap: don't hold the load lock across stream reads Denis V. Lunev
2026-11-11 16:14 ` Eric Blake [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=avSSfOePcQNalVcV@redhat.com \
    --to=eblake@redhat.com \
    --cc=den@openvz.org \
    --cc=farosas@suse.de \
    --cc=jsnow@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@yandex-team.ru \
    /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.