aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Henderson <william.henderson@nutanix.com>2023-08-31 09:17:28 +0000
committerJohn Levon <john.levon@nutanix.com>2023-09-15 12:59:39 +0100
commit8f9b9f95ab68763eb8f386985795ce5b14b1a607 (patch)
treee863bada77bb4b9c348003ddef2a1c7248d45446
parent92e9b4998d78bad7857b8fd769e89f3835661643 (diff)
downloadlibvfio-user-8f9b9f95ab68763eb8f386985795ce5b14b1a607.zip
libvfio-user-8f9b9f95ab68763eb8f386985795ce5b14b1a607.tar.gz
libvfio-user-8f9b9f95ab68763eb8f386985795ce5b14b1a607.tar.bz2
minor changes from John's review
Signed-off-by: William Henderson <william.henderson@nutanix.com>
-rw-r--r--lib/common.h14
-rw-r--r--lib/dma.c28
2 files changed, 18 insertions, 24 deletions
diff --git a/lib/common.h b/lib/common.h
index 1b1ee65..36c1a5e 100644
--- a/lib/common.h
+++ b/lib/common.h
@@ -85,17 +85,6 @@ satadd_u64(uint64_t a, uint64_t b)
/*
* The size, in bytes, of the bitmap that represents the given range with the
* given page size.
- */
-static inline size_t
-_get_bitmap_size(size_t size, size_t pgsize)
-{
- size_t nr_pages = (size / pgsize) + (size % pgsize != 0);
- return ROUND_UP(nr_pages, sizeof(uint64_t) * CHAR_BIT) / CHAR_BIT;
-}
-
-/*
- * The size, in bytes, of the bitmap that represents the given range with the
- * given page size.
*
* Returns -1 and sets errno if the given page size is invalid for the given
* range.
@@ -110,7 +99,8 @@ get_bitmap_size(size_t region_size, size_t pgsize)
return ERROR_INT(EINVAL);
}
- return _get_bitmap_size(region_size, pgsize);
+ size_t nr_pages = (region_size / pgsize) + (region_size % pgsize != 0);
+ return ROUND_UP(nr_pages, sizeof(uint64_t) * CHAR_BIT) / CHAR_BIT;
}
#ifdef UNIT_TEST
diff --git a/lib/dma.c b/lib/dma.c
index b9588b7..66fd326 100644
--- a/lib/dma.c
+++ b/lib/dma.c
@@ -683,7 +683,7 @@ dirty_page_get_combine(dma_memory_region_t *region, char *bitmap,
int
dma_controller_dirty_page_get(dma_controller_t *dma, vfu_dma_addr_t addr,
- uint64_t len, size_t pgsize, size_t size,
+ uint64_t len, size_t client_pgsize, size_t size,
char *bitmap)
{
dma_memory_region_t *region;
@@ -720,8 +720,9 @@ dma_controller_dirty_page_get(dma_controller_t *dma, vfu_dma_addr_t addr,
vfu_log(dma->vfu_ctx, LOG_ERR, "dirty page logging not enabled");
return ERROR_INT(EINVAL);
}
- if (pgsize == 0 || (pgsize & (pgsize - 1)) != 0) {
- vfu_log(dma->vfu_ctx, LOG_ERR, "bad page size %zu", pgsize);
+ if (client_pgsize == 0 || (client_pgsize & (client_pgsize - 1)) != 0) {
+ vfu_log(dma->vfu_ctx, LOG_ERR, "bad client page size %zu",
+ client_pgsize);
return ERROR_INT(EINVAL);
}
@@ -731,9 +732,10 @@ dma_controller_dirty_page_get(dma_controller_t *dma, vfu_dma_addr_t addr,
return server_bitmap_size;
}
- client_bitmap_size = get_bitmap_size(len, pgsize);
+ client_bitmap_size = get_bitmap_size(len, client_pgsize);
if (client_bitmap_size < 0) {
- vfu_log(dma->vfu_ctx, LOG_ERR, "bad requested page size %ld", pgsize);
+ vfu_log(dma->vfu_ctx, LOG_ERR, "bad client page size %zu",
+ client_pgsize);
return client_bitmap_size;
}
@@ -742,8 +744,8 @@ dma_controller_dirty_page_get(dma_controller_t *dma, vfu_dma_addr_t addr,
* receive.
*/
if (size != (size_t)client_bitmap_size) {
- vfu_log(dma->vfu_ctx, LOG_ERR, "bad bitmap size %zu != %zu", size,
- client_bitmap_size);
+ vfu_log(dma->vfu_ctx, LOG_ERR, "bad client bitmap size %zu != %zu",
+ size, client_bitmap_size);
return ERROR_INT(EINVAL);
}
@@ -754,15 +756,16 @@ dma_controller_dirty_page_get(dma_controller_t *dma, vfu_dma_addr_t addr,
return ERROR_INT(EINVAL);
}
- if (pgsize == dma->dirty_pgsize) {
+ if (client_pgsize == dma->dirty_pgsize) {
dirty_page_get_same_pgsize(region, bitmap, client_bitmap_size);
- } else if (pgsize < dma->dirty_pgsize) {
+ } else if (client_pgsize < dma->dirty_pgsize) {
/*
* If the requested page size is less than that used for logging by
* the server, the bitmap will need to be extended, repeating bits.
*/
dirty_page_get_extend(region, bitmap, server_bitmap_size,
- dma->dirty_pgsize, client_bitmap_size, pgsize);
+ dma->dirty_pgsize, client_bitmap_size,
+ client_pgsize);
} else {
/*
* If the requested page size is larger than that used for logging by
@@ -770,11 +773,12 @@ dma_controller_dirty_page_get(dma_controller_t *dma, vfu_dma_addr_t addr,
* accuracy.
*/
dirty_page_get_combine(region, bitmap, server_bitmap_size,
- dma->dirty_pgsize, client_bitmap_size, pgsize);
+ dma->dirty_pgsize, client_bitmap_size,
+ client_pgsize);
}
#ifdef DEBUG
- log_dirty_bitmap(dma->vfu_ctx, region, bitmap, size, pgsize);
+ log_dirty_bitmap(dma->vfu_ctx, region, bitmap, size, client_pgsize);
#endif
return 0;