[Qemu-devel] [PATCH for-3.0 3/9] migration: fix incorrect bitmap size calculation

Peter Xu posted 9 patches 7 years, 4 months ago
There is a newer version of this series
[Qemu-devel] [PATCH for-3.0 3/9] migration: fix incorrect bitmap size calculation
Posted by Peter Xu 7 years, 4 months ago
The calculation on size of received bitmap is incorrect for postcopy
recovery.  Here we wanted to let the size to cover all the valid bits in
the bitmap, we should use DIV_ROUND_UP() instead of a division.

For example, a RAMBlock with size=4K (which contains only one single 4K
page) will have nbits=1, then nbits/8=0, then the real bitmap won't be
sent to source at all.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 migration/ram.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/migration/ram.c b/migration/ram.c
index fbeb23f750..203c691ded 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -235,7 +235,7 @@ int64_t ramblock_recv_bitmap_send(QEMUFile *file,
     bitmap_to_le(le_bitmap, block->receivedmap, nbits);
 
     /* Size of the bitmap, in bytes */
-    size = nbits / 8;
+    size = DIV_ROUND_UP(nbits, 8);
 
     /*
      * size is always aligned to 8 bytes for 64bit machines, but it
@@ -3944,7 +3944,7 @@ int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block)
     int ret = -EINVAL;
     QEMUFile *file = s->rp_state.from_dst_file;
     unsigned long *le_bitmap, nbits = block->used_length >> TARGET_PAGE_BITS;
-    uint64_t local_size = nbits / 8;
+    uint64_t local_size = DIV_ROUND_UP(nbits, 8);
     uint64_t size, end_mark;
 
     trace_ram_dirty_bitmap_reload_begin(block->idstr);
-- 
2.17.1


Re: [Qemu-devel] [PATCH for-3.0 3/9] migration: fix incorrect bitmap size calculation
Posted by Dr. David Alan Gilbert 7 years, 4 months ago
* Peter Xu (peterx@redhat.com) wrote:
> The calculation on size of received bitmap is incorrect for postcopy
> recovery.  Here we wanted to let the size to cover all the valid bits in
> the bitmap, we should use DIV_ROUND_UP() instead of a division.
> 
> For example, a RAMBlock with size=4K (which contains only one single 4K
> page) will have nbits=1, then nbits/8=0, then the real bitmap won't be
> sent to source at all.
> 
> Signed-off-by: Peter Xu <peterx@redhat.com>

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

> ---
>  migration/ram.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/migration/ram.c b/migration/ram.c
> index fbeb23f750..203c691ded 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -235,7 +235,7 @@ int64_t ramblock_recv_bitmap_send(QEMUFile *file,
>      bitmap_to_le(le_bitmap, block->receivedmap, nbits);
>  
>      /* Size of the bitmap, in bytes */
> -    size = nbits / 8;
> +    size = DIV_ROUND_UP(nbits, 8);
>  
>      /*
>       * size is always aligned to 8 bytes for 64bit machines, but it
> @@ -3944,7 +3944,7 @@ int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block)
>      int ret = -EINVAL;
>      QEMUFile *file = s->rp_state.from_dst_file;
>      unsigned long *le_bitmap, nbits = block->used_length >> TARGET_PAGE_BITS;
> -    uint64_t local_size = nbits / 8;
> +    uint64_t local_size = DIV_ROUND_UP(nbits, 8);
>      uint64_t size, end_mark;
>  
>      trace_ram_dirty_bitmap_reload_begin(block->idstr);
> -- 
> 2.17.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

Re: [Qemu-devel] [PATCH for-3.0 3/9] migration: fix incorrect bitmap size calculation
Posted by Juan Quintela 7 years, 4 months ago
Peter Xu <peterx@redhat.com> wrote:
> The calculation on size of received bitmap is incorrect for postcopy
> recovery.  Here we wanted to let the size to cover all the valid bits in
> the bitmap, we should use DIV_ROUND_UP() instead of a division.
>
> For example, a RAMBlock with size=4K (which contains only one single 4K
> page) will have nbits=1, then nbits/8=0, then the real bitmap won't be
> sent to source at all.
>
> Signed-off-by: Peter Xu <peterx@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>