Rename @start as @offset. Since it express an offset within a
RAMBlock, use the ram_addr_t type to make emphasis on the QEMU
intermediate address space represented.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/system/ramblock.h | 3 ++-
system/physmem.c | 33 ++++++++++++++++++---------------
2 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/include/system/ramblock.h b/include/system/ramblock.h
index 897c5333eaf..57c00e42ca6 100644
--- a/include/system/ramblock.h
+++ b/include/system/ramblock.h
@@ -103,7 +103,8 @@ struct RamBlockAttributes {
QLIST_HEAD(, RamDiscardListener) rdl_list;
};
-int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length);
+/* @offset: the offset within the RAMBlock */
+int ram_block_discard_range(RAMBlock *rb, ram_addr_t offset, size_t length);
/* @offset: the offset within the RAMBlock */
int ram_block_discard_guest_memfd_range(RAMBlock *rb, ram_addr_t offset,
size_t length);
diff --git a/system/physmem.c b/system/physmem.c
index e2721b1902a..bb744f0758e 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -3797,18 +3797,18 @@ int qemu_ram_foreach_block(RAMBlockIterFunc func, void *opaque)
}
/*
- * Unmap pages of memory from start to start+length such that
+ * Unmap pages of memory from offset to offset+length such that
* they a) read as 0, b) Trigger whatever fault mechanism
* the OS provides for postcopy.
* The pages must be unmapped by the end of the function.
* Returns: 0 on success, none-0 on failure
*
*/
-int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
+int ram_block_discard_range(RAMBlock *rb, ram_addr_t offset, size_t length)
{
int ret = -1;
- uint8_t *host_startaddr = rb->host + start;
+ uint8_t *host_startaddr = rb->host + offset;
if (!QEMU_PTR_IS_ALIGNED(host_startaddr, rb->page_size)) {
error_report("%s: Unaligned start address: %p",
@@ -3816,7 +3816,7 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
goto err;
}
- if ((start + length) <= rb->max_length) {
+ if ((offset + length) <= rb->max_length) {
bool need_madvise, need_fallocate;
if (!QEMU_IS_ALIGNED(length, rb->page_size)) {
error_report("%s: Unaligned length: %zx", __func__, length);
@@ -3867,19 +3867,20 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
}
ret = fallocate(rb->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
- start + rb->fd_offset, length);
+ offset + rb->fd_offset, length);
if (ret) {
ret = -errno;
- error_report("%s: Failed to fallocate %s:%" PRIx64 "+%" PRIx64
- " +%zx (%d)", __func__, rb->idstr, start,
+ error_report("%s: Failed to fallocate %s:"
+ RAM_ADDR_FMT "+%" PRIx64 " +%zx (%d)",
+ __func__, rb->idstr, offset,
rb->fd_offset, length, ret);
goto err;
}
#else
ret = -ENOSYS;
error_report("%s: fallocate not available/file"
- "%s:%" PRIx64 "+%" PRIx64 " +%zx (%d)", __func__,
- rb->idstr, start, rb->fd_offset, length, ret);
+ "%s:" RAM_ADDR_FMT "+%" PRIx64 " +%zx (%d)", __func__,
+ rb->idstr, offset, rb->fd_offset, length, ret);
goto err;
#endif
}
@@ -3898,22 +3899,24 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
if (ret) {
ret = -errno;
error_report("%s: Failed to discard range "
- "%s:%" PRIx64 " +%zx (%d)",
- __func__, rb->idstr, start, length, ret);
+ "%s:" RAM_ADDR_FMT " +%zx (%d)",
+ __func__, rb->idstr, offset, length, ret);
goto err;
}
#else
ret = -ENOSYS;
- error_report("%s: MADVISE not available %s:%" PRIx64 " +%zx (%d)",
- __func__, rb->idstr, start, length, ret);
+ error_report("%s: MADVISE not available %s:"
+ RAM_ADDR_FMT " +%zx (%d)",
+ __func__, rb->idstr, offset, length, ret);
goto err;
#endif
}
trace_ram_block_discard_range(rb->idstr, host_startaddr, length,
need_madvise, need_fallocate, ret);
} else {
- error_report("%s: Overrun block '%s' (%" PRIu64 "/%zx/" RAM_ADDR_FMT")",
- __func__, rb->idstr, start, length, rb->max_length);
+ error_report("%s: Overrun block '%s' "
+ "(" RAM_ADDR_FMT "/%zx/" RAM_ADDR_FMT")",
+ __func__, rb->idstr, offset, length, rb->max_length);
}
err:
--
2.51.0