Skip to content

Commit

Permalink
fix: incorrect number of dirty pages printed (#766)
Browse files Browse the repository at this point in the history
The `log_dirty_bitmap` function in `dma.c` would output the wrong number of
dirty pages due to the `char` of the bitmap being sign-extended when implicitly
being converted to `unsigned int` for `__builtin_popcount`. By adding an
intermediate cast to `uint8_t` we avoid this incorrect behaviour.

See #746 (comment).

Signed-off-by: William Henderson <[email protected]>
  • Loading branch information
w-henderson authored Aug 23, 2023
1 parent cfb7d90 commit 149aa84
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ log_dirty_bitmap(vfu_ctx_t *vfu_ctx, dma_memory_region_t *region,
size_t i;
size_t count;
for (i = 0, count = 0; i < size; i++) {
count += __builtin_popcount(bitmap[i]);
count += __builtin_popcount((uint8_t)bitmap[i]);
}
vfu_log(vfu_ctx, LOG_DEBUG, "dirty pages: get [%p, %p), %zu dirty pages",
region->info.iova.iov_base, iov_end(&region->info.iova),
Expand Down

0 comments on commit 149aa84

Please sign in to comment.