[PATCH 4/6] system/ramblock: Use ram_addr_t in ram_block_discard_guest_memfd_range

Philippe Mathieu-Daudé posted 6 patches 1 month, 2 weeks ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, "Maciej S. Szmigiero" <maciej.szmigiero@oracle.com>, "Michael S. Tsirkin" <mst@redhat.com>, David Hildenbrand <david@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>
There is a newer version of this series
[PATCH 4/6] system/ramblock: Use ram_addr_t in ram_block_discard_guest_memfd_range
Posted by Philippe Mathieu-Daudé 1 month, 2 weeks ago
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          | 12 ++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/include/system/ramblock.h b/include/system/ramblock.h
index e69af20b810..897c5333eaf 100644
--- a/include/system/ramblock.h
+++ b/include/system/ramblock.h
@@ -104,7 +104,8 @@ struct RamBlockAttributes {
 };
 
 int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length);
-int ram_block_discard_guest_memfd_range(RAMBlock *rb, uint64_t start,
+/* @offset: the offset within the RAMBlock */
+int ram_block_discard_guest_memfd_range(RAMBlock *rb, ram_addr_t offset,
                                         size_t length);
 
 RamBlockAttributes *ram_block_attributes_create(RAMBlock *ram_block);
diff --git a/system/physmem.c b/system/physmem.c
index 3766fae0aba..e2721b1902a 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -3920,7 +3920,7 @@ err:
     return ret;
 }
 
-int ram_block_discard_guest_memfd_range(RAMBlock *rb, uint64_t start,
+int ram_block_discard_guest_memfd_range(RAMBlock *rb, ram_addr_t offset,
                                         size_t length)
 {
     int ret = -1;
@@ -3928,17 +3928,17 @@ int ram_block_discard_guest_memfd_range(RAMBlock *rb, uint64_t start,
 #ifdef CONFIG_FALLOCATE_PUNCH_HOLE
     /* ignore fd_offset with guest_memfd */
     ret = fallocate(rb->guest_memfd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
-                    start, length);
+                    offset, length);
 
     if (ret) {
         ret = -errno;
-        error_report("%s: Failed to fallocate %s:%" PRIx64 " +%zx (%d)",
-                     __func__, rb->idstr, start, length, ret);
+        error_report("%s: Failed to fallocate %s:" RAM_ADDR_FMT " +%zx (%d)",
+                     __func__, rb->idstr, offset, length, ret);
     }
 #else
     ret = -ENOSYS;
-    error_report("%s: fallocate not available %s:%" PRIx64 " +%zx (%d)",
-                 __func__, rb->idstr, start, length, ret);
+    error_report("%s: fallocate not available %s:" RAM_ADDR_FMT " +%zx (%d)",
+                 __func__, rb->idstr, offset, length, ret);
 #endif
 
     return ret;
-- 
2.51.0


Re: [PATCH 4/6] system/ramblock: Use ram_addr_t in ram_block_discard_guest_memfd_range
Posted by Richard Henderson 1 month, 2 weeks ago
On 9/29/25 08:45, Philippe Mathieu-Daudé wrote:
> 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          | 12 ++++++------
>   2 files changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/include/system/ramblock.h b/include/system/ramblock.h
> index e69af20b810..897c5333eaf 100644
> --- a/include/system/ramblock.h
> +++ b/include/system/ramblock.h
> @@ -104,7 +104,8 @@ struct RamBlockAttributes {
>   };
>   
>   int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length);
> -int ram_block_discard_guest_memfd_range(RAMBlock *rb, uint64_t start,
> +/* @offset: the offset within the RAMBlock */
> +int ram_block_discard_guest_memfd_range(RAMBlock *rb, ram_addr_t offset,
>                                           size_t length);

This isn't a ram_addr_t, it's an offset.
You can't pass the value to one of the lookup functions, for instance.
Though I suppose 80% of the ram_addr.h interface uses ram_addr_t for lots of things that 
aren't.


r~