qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: Stefan Reiter <s.reiter@proxmox.com>,
	quintela@redhat.com, dgilbert@redhat.com
Cc: jsnow@redhat.com, eblake@redhat.com, fam@euphon.net,
	stefanha@redhat.com,  qemu-block@nongnu.org,
	qemu-devel@nongnu.org
Subject: Re: [PATCH] migration/block-dirty-bitmap: fix larger granularity bitmaps
Date: Thu, 22 Oct 2020 11:46:43 +0300	[thread overview]
Message-ID: <b409b754-c63c-ad64-e108-a2e58f6dced8@virtuozzo.com> (raw)
In-Reply-To: <f7ad1bf2-067e-5de2-8ba4-6000761c7367@proxmox.com>

22.10.2020 10:46, Stefan Reiter wrote:
> On 10/21/20 5:17 PM, Vladimir Sementsov-Ogievskiy wrote:
>> 21.10.2020 17:44, Stefan Reiter wrote:
>>> sectors_per_chunk is a 64 bit integer, but the calculation is done in 32
>>> bits, leading to an overflow for coarse bitmap granularities.
>>>
>>> If that results in the value 0, it leads to a hang where no progress is
>>> made but send_bitmap_bits is constantly called with nr_sectors being 0.
>>>
>>> Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
>>> ---
>>>   migration/block-dirty-bitmap.c | 3 ++-
>>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c
>>> index 5bef793ac0..5398869e2b 100644
>>> --- a/migration/block-dirty-bitmap.c
>>> +++ b/migration/block-dirty-bitmap.c
>>> @@ -562,8 +562,9 @@ static int add_bitmaps_to_list(DBMSaveState *s, BlockDriverState *bs,
>>>           dbms->bitmap_alias = g_strdup(bitmap_alias);
>>>           dbms->bitmap = bitmap;
>>>           dbms->total_sectors = bdrv_nb_sectors(bs);
>>> -        dbms->sectors_per_chunk = CHUNK_SIZE * 8 *
>>> +        dbms->sectors_per_chunk = CHUNK_SIZE * 8lu *
>>
>> I'd prefer 8llu for absolute safety.
>>
>>>               bdrv_dirty_bitmap_granularity(bitmap) >> BDRV_SECTOR_BITS;
>>> +        assert(dbms->sectors_per_chunk != 0);
>>
>> I doubt that we need this assertion. Bug fixed, and it's obviously impossible.
>> And if we really want to assert that there is no overflow (assuming future changes),
>> it should look like this:
>>
>>    assert(bdrv_dirty_bitmap_granularity(bitmap) < (1ull << 63) / CHUNK_SIZE / 8 >> BDRV_SECTOR_BITS);
>>
>> to cover not only corner case but any overflow.. And of course we should modify original expression
>> to do ">> BDRV_SECTOR_BITS" earlier than all multiplies, like
>>
>>    dbms->sectors_per_chunk = CHUNK_SIZE * 8llu * (bdrv_dirty_bitmap_granularity(bitmap) >> BDRV_SECTOR_BITS);
>>
>>
>> But I think that only s/8/8ull/ change is enough.
>>
> 
> I agree, and I wouldn't mind removing the assert, but just to clarify it was mostly meant to prevent the case where the migration gets stuck entirely. Even if the calculation is wrong, it would at least do _something_ instead of endlessly looping.
> 
> Maybe an
> 
>      assert(nr_sectors != 0);
> 
> in send_bitmap_bits instead for that?

Hmm, just sending 0 sectors should not be a problem by itself. It's a problem when we don't make a progress in the loop in bulk_phase().. So, I'd prefer your original assertion, as sectors_per_chunk=0 is definitely wrong thing.

> 
>>>           if (bdrv_dirty_bitmap_enabled(bitmap)) {
>>>               dbms->flags |= DIRTY_BITMAP_MIG_START_FLAG_ENABLED;
>>>           }
>>>
>>
>>
>> With 8llu and with or without assertion:
>> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>>
> 


-- 
Best regards,
Vladimir


  reply	other threads:[~2020-10-22  8:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-21 14:44 [PATCH] migration/block-dirty-bitmap: fix larger granularity bitmaps Stefan Reiter
2020-10-21 15:17 ` Vladimir Sementsov-Ogievskiy
2020-10-22  7:46   ` Stefan Reiter
2020-10-22  8:46     ` Vladimir Sementsov-Ogievskiy [this message]
2020-10-21 16:02 ` Eric Blake

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=b409b754-c63c-ad64-e108-a2e58f6dced8@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=dgilbert@redhat.com \
    --cc=eblake@redhat.com \
    --cc=fam@euphon.net \
    --cc=jsnow@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=s.reiter@proxmox.com \
    --cc=stefanha@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).