qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/5] system/ramblock: Sanitize header
@ 2025-10-02  3:28 Philippe Mathieu-Daudé
  2025-10-02  3:28 ` [PATCH v3 1/5] system/ramblock: Remove obsolete comment Philippe Mathieu-Daudé
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-02  3:28 UTC (permalink / raw)
  To: qemu-devel
  Cc: David Hildenbrand, Maciej S. Szmigiero, Paolo Bonzini,
	Richard Henderson, Peter Xu, kvm, Philippe Mathieu-Daudé,
	Michael S. Tsirkin, Fabiano Rosas

(series fully reviewed, I plan to merge via my tree)

Usual API cleanups, here focusing on RAMBlock API:
move few prototypes out of "exec/cpu-common.h" and
"system/ram_addr.h" to "system/ramblock.h".

v2:
- Do not use ram_addr_t for offsets (rth)
v3:
- Updated subject & squashed (rth)

Philippe Mathieu-Daudé (5):
  system/ramblock: Remove obsolete comment
  system/ramblock: Move ram_block_is_pmem() declaration
  system/ramblock: Move ram_block_discard_*_range() declarations
  system/ramblock: Rename @start -> @offset in ram_block_discard_range()
  system/ramblock: Move RAMBlock helpers out of "system/ram_addr.h"

 include/exec/cpu-common.h                 |  3 ---
 include/system/ram_addr.h                 | 13 ---------
 include/system/ramblock.h                 | 27 +++++++++++++++----
 accel/kvm/kvm-all.c                       |  1 +
 hw/hyperv/hv-balloon-our_range_memslots.c |  1 +
 hw/virtio/virtio-balloon.c                |  1 +
 hw/virtio/virtio-mem.c                    |  1 +
 migration/ram.c                           |  3 ++-
 system/physmem.c                          | 33 ++++++++++++-----------
 9 files changed, 45 insertions(+), 38 deletions(-)

-- 
2.51.0



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 1/5] system/ramblock: Remove obsolete comment
  2025-10-02  3:28 [PATCH v3 0/5] system/ramblock: Sanitize header Philippe Mathieu-Daudé
@ 2025-10-02  3:28 ` Philippe Mathieu-Daudé
  2025-10-02  3:28 ` [PATCH v3 2/5] system/ramblock: Move ram_block_is_pmem() declaration Philippe Mathieu-Daudé
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-02  3:28 UTC (permalink / raw)
  To: qemu-devel
  Cc: David Hildenbrand, Maciej S. Szmigiero, Paolo Bonzini,
	Richard Henderson, Peter Xu, kvm, Philippe Mathieu-Daudé,
	Michael S. Tsirkin, Fabiano Rosas

This comment was added almost 5 years ago in commit 41aa4e9fd84
("ram_addr: Split RAMBlock definition"). Clearly it got ignored:

  $ git grep -l system/ramblock.h
  hw/display/virtio-gpu-udmabuf.c
  hw/hyperv/hv-balloon.c
  hw/virtio/vhost-user.c
  migration/dirtyrate.c
  migration/file.c
  migration/multifd-nocomp.c
  migration/multifd-qatzip.c
  migration/multifd-qpl.c
  migration/multifd-uadk.c
  migration/multifd-zero-page.c
  migration/multifd-zlib.c
  migration/multifd-zstd.c
  migration/multifd.c
  migration/postcopy-ram.c
  system/ram-block-attributes.c
  target/i386/kvm/tdx.c
  tests/qtest/fuzz/generic_fuzz.c

At this point it seems saner to just remove it.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/system/ramblock.h | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/include/system/ramblock.h b/include/system/ramblock.h
index 87e847e184a..8999206592d 100644
--- a/include/system/ramblock.h
+++ b/include/system/ramblock.h
@@ -11,11 +11,6 @@
  *
  */
 
-/*
- * This header is for use by exec.c and memory.c ONLY.  Do not include it.
- * The functions declared here will be removed soon.
- */
-
 #ifndef SYSTEM_RAMBLOCK_H
 #define SYSTEM_RAMBLOCK_H
 
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 2/5] system/ramblock: Move ram_block_is_pmem() declaration
  2025-10-02  3:28 [PATCH v3 0/5] system/ramblock: Sanitize header Philippe Mathieu-Daudé
  2025-10-02  3:28 ` [PATCH v3 1/5] system/ramblock: Remove obsolete comment Philippe Mathieu-Daudé
@ 2025-10-02  3:28 ` Philippe Mathieu-Daudé
  2025-10-02  3:28 ` [PATCH v3 3/5] system/ramblock: Move ram_block_discard_*_range() declarations Philippe Mathieu-Daudé
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-02  3:28 UTC (permalink / raw)
  To: qemu-devel
  Cc: David Hildenbrand, Maciej S. Szmigiero, Paolo Bonzini,
	Richard Henderson, Peter Xu, kvm, Philippe Mathieu-Daudé,
	Michael S. Tsirkin, Fabiano Rosas, Alex Bennée

Move ramblock_is_pmem() along with the RAM Block API
exposed by the "system/ramblock.h" header. Rename as
ram_block_is_pmem() to keep API prefix consistency.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/system/ram_addr.h | 2 --
 include/system/ramblock.h | 5 +++++
 migration/ram.c           | 3 ++-
 system/physmem.c          | 5 +++--
 4 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/include/system/ram_addr.h b/include/system/ram_addr.h
index 15a1b1a4fa2..53c0c8c3856 100644
--- a/include/system/ram_addr.h
+++ b/include/system/ram_addr.h
@@ -99,8 +99,6 @@ static inline unsigned long int ramblock_recv_bitmap_offset(void *host_addr,
     return host_addr_offset >> TARGET_PAGE_BITS;
 }
 
-bool ramblock_is_pmem(RAMBlock *rb);
-
 /**
  * qemu_ram_alloc_from_file,
  * qemu_ram_alloc_from_fd:  Allocate a ram block from the specified backing
diff --git a/include/system/ramblock.h b/include/system/ramblock.h
index 8999206592d..7059b20d919 100644
--- a/include/system/ramblock.h
+++ b/include/system/ramblock.h
@@ -108,4 +108,9 @@ void ram_block_attributes_destroy(RamBlockAttributes *attr);
 int ram_block_attributes_state_change(RamBlockAttributes *attr, uint64_t offset,
                                       uint64_t size, bool to_discard);
 
+/**
+ * ram_block_is_pmem: Whether the RAM block is of persistent memory
+ */
+bool ram_block_is_pmem(RAMBlock *rb);
+
 #endif
diff --git a/migration/ram.c b/migration/ram.c
index 7208bc114fb..91e65be83d8 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -53,6 +53,7 @@
 #include "qemu/rcu_queue.h"
 #include "migration/colo.h"
 #include "system/cpu-throttle.h"
+#include "system/ramblock.h"
 #include "savevm.h"
 #include "qemu/iov.h"
 #include "multifd.h"
@@ -4367,7 +4368,7 @@ static bool ram_has_postcopy(void *opaque)
 {
     RAMBlock *rb;
     RAMBLOCK_FOREACH_NOT_IGNORED(rb) {
-        if (ramblock_is_pmem(rb)) {
+        if (ram_block_is_pmem(rb)) {
             info_report("Block: %s, host: %p is a nvdimm memory, postcopy"
                          "is not supported now!", rb->idstr, rb->host);
             return false;
diff --git a/system/physmem.c b/system/physmem.c
index ae8ecd50ea1..3766fae0aba 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -43,6 +43,7 @@
 #include "system/kvm.h"
 #include "system/tcg.h"
 #include "system/qtest.h"
+#include "system/ramblock.h"
 #include "qemu/timer.h"
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
@@ -1804,7 +1805,7 @@ void qemu_ram_msync(RAMBlock *block, ram_addr_t start, ram_addr_t length)
 
 #ifdef CONFIG_LIBPMEM
     /* The lack of support for pmem should not block the sync */
-    if (ramblock_is_pmem(block)) {
+    if (ram_block_is_pmem(block)) {
         void *addr = ramblock_ptr(block, start);
         pmem_persist(addr, length);
         return;
@@ -3943,7 +3944,7 @@ int ram_block_discard_guest_memfd_range(RAMBlock *rb, uint64_t start,
     return ret;
 }
 
-bool ramblock_is_pmem(RAMBlock *rb)
+bool ram_block_is_pmem(RAMBlock *rb)
 {
     return rb->flags & RAM_PMEM;
 }
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 3/5] system/ramblock: Move ram_block_discard_*_range() declarations
  2025-10-02  3:28 [PATCH v3 0/5] system/ramblock: Sanitize header Philippe Mathieu-Daudé
  2025-10-02  3:28 ` [PATCH v3 1/5] system/ramblock: Remove obsolete comment Philippe Mathieu-Daudé
  2025-10-02  3:28 ` [PATCH v3 2/5] system/ramblock: Move ram_block_is_pmem() declaration Philippe Mathieu-Daudé
@ 2025-10-02  3:28 ` Philippe Mathieu-Daudé
  2025-10-02  3:28 ` [PATCH v3 4/5] system/ramblock: Rename @start -> @offset in ram_block_discard_range() Philippe Mathieu-Daudé
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-02  3:28 UTC (permalink / raw)
  To: qemu-devel
  Cc: David Hildenbrand, Maciej S. Szmigiero, Paolo Bonzini,
	Richard Henderson, Peter Xu, kvm, Philippe Mathieu-Daudé,
	Michael S. Tsirkin, Fabiano Rosas

Keep RAM blocks API in the same header: "system/ramblock.h".

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/exec/cpu-common.h                 | 3 ---
 include/system/ramblock.h                 | 4 ++++
 accel/kvm/kvm-all.c                       | 1 +
 hw/hyperv/hv-balloon-our_range_memslots.c | 1 +
 hw/virtio/virtio-balloon.c                | 1 +
 hw/virtio/virtio-mem.c                    | 1 +
 6 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index f373781ae07..e413d8b3079 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -163,9 +163,6 @@ void cpu_flush_icache_range(hwaddr start, hwaddr len);
 typedef int (RAMBlockIterFunc)(RAMBlock *rb, void *opaque);
 
 int qemu_ram_foreach_block(RAMBlockIterFunc func, void *opaque);
-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,
-                                        size_t length);
 
 /* Returns: 0 on success, -1 on error */
 int cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
diff --git a/include/system/ramblock.h b/include/system/ramblock.h
index 7059b20d919..530c5a2e4c2 100644
--- a/include/system/ramblock.h
+++ b/include/system/ramblock.h
@@ -103,6 +103,10 @@ struct RamBlockAttributes {
     QLIST_HEAD(, RamDiscardListener) rdl_list;
 };
 
+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,
+                                        size_t length);
+
 RamBlockAttributes *ram_block_attributes_create(RAMBlock *ram_block);
 void ram_block_attributes_destroy(RamBlockAttributes *attr);
 int ram_block_attributes_state_change(RamBlockAttributes *attr, uint64_t offset,
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 9060599cd73..e3c84723406 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -32,6 +32,7 @@
 #include "system/runstate.h"
 #include "system/cpus.h"
 #include "system/accel-blocker.h"
+#include "system/ramblock.h"
 #include "accel/accel-ops.h"
 #include "qemu/bswap.h"
 #include "exec/tswap.h"
diff --git a/hw/hyperv/hv-balloon-our_range_memslots.c b/hw/hyperv/hv-balloon-our_range_memslots.c
index 1505a395cf7..1fc95e16480 100644
--- a/hw/hyperv/hv-balloon-our_range_memslots.c
+++ b/hw/hyperv/hv-balloon-our_range_memslots.c
@@ -8,6 +8,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "system/ramblock.h"
 #include "hv-balloon-internal.h"
 #include "hv-balloon-our_range_memslots.h"
 #include "trace.h"
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index db787d00b31..02cdd807d77 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -23,6 +23,7 @@
 #include "hw/qdev-properties.h"
 #include "hw/boards.h"
 #include "system/balloon.h"
+#include "system/ramblock.h"
 #include "hw/virtio/virtio-balloon.h"
 #include "system/address-spaces.h"
 #include "qapi/error.h"
diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c
index c46f6f9c3e2..1de2d3de521 100644
--- a/hw/virtio/virtio-mem.c
+++ b/hw/virtio/virtio-mem.c
@@ -17,6 +17,7 @@
 #include "qemu/units.h"
 #include "system/numa.h"
 #include "system/system.h"
+#include "system/ramblock.h"
 #include "system/reset.h"
 #include "system/runstate.h"
 #include "hw/virtio/virtio.h"
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 4/5] system/ramblock: Rename @start -> @offset in ram_block_discard_range()
  2025-10-02  3:28 [PATCH v3 0/5] system/ramblock: Sanitize header Philippe Mathieu-Daudé
                   ` (2 preceding siblings ...)
  2025-10-02  3:28 ` [PATCH v3 3/5] system/ramblock: Move ram_block_discard_*_range() declarations Philippe Mathieu-Daudé
@ 2025-10-02  3:28 ` Philippe Mathieu-Daudé
  2025-10-02  3:28 ` [PATCH v3 5/5] system/ramblock: Move RAMBlock helpers out of "system/ram_addr.h" Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-02  3:28 UTC (permalink / raw)
  To: qemu-devel
  Cc: David Hildenbrand, Maciej S. Szmigiero, Paolo Bonzini,
	Richard Henderson, Peter Xu, kvm, Philippe Mathieu-Daudé,
	Michael S. Tsirkin, Fabiano Rosas

Rename @start as @offset, since it express an offset within a RAMBlock.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/system/ramblock.h |  6 ++++--
 system/physmem.c          | 28 ++++++++++++++--------------
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/include/system/ramblock.h b/include/system/ramblock.h
index 530c5a2e4c2..85cceff6bce 100644
--- a/include/system/ramblock.h
+++ b/include/system/ramblock.h
@@ -103,8 +103,10 @@ struct RamBlockAttributes {
     QLIST_HEAD(, RamDiscardListener) rdl_list;
 };
 
-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_range(RAMBlock *rb, uint64_t offset, size_t length);
+/* @offset: the offset within the RAMBlock */
+int ram_block_discard_guest_memfd_range(RAMBlock *rb, uint64_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..1a74e48157b 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, uint64_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,11 +3867,11 @@ 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,
+                             " +%zx (%d)", __func__, rb->idstr, offset,
                              rb->fd_offset, length, ret);
                 goto err;
             }
@@ -3879,7 +3879,7 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
             ret = -ENOSYS;
             error_report("%s: fallocate not available/file"
                          "%s:%" PRIx64 "+%" PRIx64 " +%zx (%d)", __func__,
-                         rb->idstr, start, rb->fd_offset, length, ret);
+                         rb->idstr, offset, rb->fd_offset, length, ret);
             goto err;
 #endif
         }
@@ -3899,13 +3899,13 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
                 ret = -errno;
                 error_report("%s: Failed to discard range "
                              "%s:%" PRIx64 " +%zx (%d)",
-                             __func__, rb->idstr, start, length, ret);
+                             __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);
+                         __func__, rb->idstr, offset, length, ret);
             goto err;
 #endif
         }
@@ -3913,14 +3913,14 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t 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);
+                     __func__, rb->idstr, offset, length, rb->max_length);
     }
 
 err:
     return ret;
 }
 
-int ram_block_discard_guest_memfd_range(RAMBlock *rb, uint64_t start,
+int ram_block_discard_guest_memfd_range(RAMBlock *rb, uint64_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);
+                     __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);
+                 __func__, rb->idstr, offset, length, ret);
 #endif
 
     return ret;
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 5/5] system/ramblock: Move RAMBlock helpers out of "system/ram_addr.h"
  2025-10-02  3:28 [PATCH v3 0/5] system/ramblock: Sanitize header Philippe Mathieu-Daudé
                   ` (3 preceding siblings ...)
  2025-10-02  3:28 ` [PATCH v3 4/5] system/ramblock: Rename @start -> @offset in ram_block_discard_range() Philippe Mathieu-Daudé
@ 2025-10-02  3:28 ` Philippe Mathieu-Daudé
  2025-10-02 14:43 ` [PATCH v3 0/5] system/ramblock: Sanitize header Peter Xu
  2025-10-03 20:37 ` Philippe Mathieu-Daudé
  6 siblings, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-02  3:28 UTC (permalink / raw)
  To: qemu-devel
  Cc: David Hildenbrand, Maciej S. Szmigiero, Paolo Bonzini,
	Richard Henderson, Peter Xu, kvm, Philippe Mathieu-Daudé,
	Michael S. Tsirkin, Fabiano Rosas

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/system/ram_addr.h | 11 -----------
 include/system/ramblock.h | 11 +++++++++++
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/include/system/ram_addr.h b/include/system/ram_addr.h
index 53c0c8c3856..6b528338efc 100644
--- a/include/system/ram_addr.h
+++ b/include/system/ram_addr.h
@@ -80,17 +80,6 @@ static inline bool clear_bmap_test_and_clear(RAMBlock *rb, uint64_t page)
     return bitmap_test_and_clear(rb->clear_bmap, page >> shift, 1);
 }
 
-static inline bool offset_in_ramblock(RAMBlock *b, ram_addr_t offset)
-{
-    return (b && b->host && offset < b->used_length) ? true : false;
-}
-
-static inline void *ramblock_ptr(RAMBlock *block, ram_addr_t offset)
-{
-    assert(offset_in_ramblock(block, offset));
-    return (char *)block->host + offset;
-}
-
 static inline unsigned long int ramblock_recv_bitmap_offset(void *host_addr,
                                                             RAMBlock *rb)
 {
diff --git a/include/system/ramblock.h b/include/system/ramblock.h
index 85cceff6bce..76694fe1b5b 100644
--- a/include/system/ramblock.h
+++ b/include/system/ramblock.h
@@ -119,4 +119,15 @@ int ram_block_attributes_state_change(RamBlockAttributes *attr, uint64_t offset,
  */
 bool ram_block_is_pmem(RAMBlock *rb);
 
+static inline bool offset_in_ramblock(RAMBlock *b, ram_addr_t offset)
+{
+    return b && b->host && (offset < b->used_length);
+}
+
+static inline void *ramblock_ptr(RAMBlock *block, ram_addr_t offset)
+{
+    assert(offset_in_ramblock(block, offset));
+    return (char *)block->host + offset;
+}
+
 #endif
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 0/5] system/ramblock: Sanitize header
  2025-10-02  3:28 [PATCH v3 0/5] system/ramblock: Sanitize header Philippe Mathieu-Daudé
                   ` (4 preceding siblings ...)
  2025-10-02  3:28 ` [PATCH v3 5/5] system/ramblock: Move RAMBlock helpers out of "system/ram_addr.h" Philippe Mathieu-Daudé
@ 2025-10-02 14:43 ` Peter Xu
  2025-10-03 20:37 ` Philippe Mathieu-Daudé
  6 siblings, 0 replies; 8+ messages in thread
From: Peter Xu @ 2025-10-02 14:43 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, David Hildenbrand, Maciej S. Szmigiero, Paolo Bonzini,
	Richard Henderson, kvm, Michael S. Tsirkin, Fabiano Rosas

On Thu, Oct 02, 2025 at 05:28:07AM +0200, Philippe Mathieu-Daudé wrote:
> (series fully reviewed, I plan to merge via my tree)
> 
> Usual API cleanups, here focusing on RAMBlock API:
> move few prototypes out of "exec/cpu-common.h" and
> "system/ram_addr.h" to "system/ramblock.h".

Acked-by: Peter Xu <peterx@redhat.com>

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 0/5] system/ramblock: Sanitize header
  2025-10-02  3:28 [PATCH v3 0/5] system/ramblock: Sanitize header Philippe Mathieu-Daudé
                   ` (5 preceding siblings ...)
  2025-10-02 14:43 ` [PATCH v3 0/5] system/ramblock: Sanitize header Peter Xu
@ 2025-10-03 20:37 ` Philippe Mathieu-Daudé
  6 siblings, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-03 20:37 UTC (permalink / raw)
  To: qemu-devel
  Cc: David Hildenbrand, Maciej S. Szmigiero, Paolo Bonzini,
	Richard Henderson, Peter Xu, kvm, Michael S. Tsirkin,
	Fabiano Rosas

On 2/10/25 05:28, Philippe Mathieu-Daudé wrote:

> Philippe Mathieu-Daudé (5):
>    system/ramblock: Remove obsolete comment
>    system/ramblock: Move ram_block_is_pmem() declaration
>    system/ramblock: Move ram_block_discard_*_range() declarations
>    system/ramblock: Rename @start -> @offset in ram_block_discard_range()
>    system/ramblock: Move RAMBlock helpers out of "system/ram_addr.h"

Series queued, thanks.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-10-03 20:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-02  3:28 [PATCH v3 0/5] system/ramblock: Sanitize header Philippe Mathieu-Daudé
2025-10-02  3:28 ` [PATCH v3 1/5] system/ramblock: Remove obsolete comment Philippe Mathieu-Daudé
2025-10-02  3:28 ` [PATCH v3 2/5] system/ramblock: Move ram_block_is_pmem() declaration Philippe Mathieu-Daudé
2025-10-02  3:28 ` [PATCH v3 3/5] system/ramblock: Move ram_block_discard_*_range() declarations Philippe Mathieu-Daudé
2025-10-02  3:28 ` [PATCH v3 4/5] system/ramblock: Rename @start -> @offset in ram_block_discard_range() Philippe Mathieu-Daudé
2025-10-02  3:28 ` [PATCH v3 5/5] system/ramblock: Move RAMBlock helpers out of "system/ram_addr.h" Philippe Mathieu-Daudé
2025-10-02 14:43 ` [PATCH v3 0/5] system/ramblock: Sanitize header Peter Xu
2025-10-03 20:37 ` Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).