* [PATCH 0/6] system/ramblock: Sanitize header
@ 2025-09-29 15:45 Philippe Mathieu-Daudé
2025-09-29 15:45 ` [PATCH 1/6] system/ramblock: Remove obsolete comment Philippe Mathieu-Daudé
` (5 more replies)
0 siblings, 6 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-09-29 15:45 UTC (permalink / raw)
To: qemu-devel
Cc: Fabiano Rosas, Maciej S. Szmigiero, Richard Henderson,
Michael S. Tsirkin, Paolo Bonzini, David Hildenbrand,
Philippe Mathieu-Daudé, kvm, Peter Xu
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".
Philippe Mathieu-Daudé (6):
system/ramblock: Remove obsolete comment
system/ramblock: Move ram_block_is_pmem() declaration
system/ramblock: Move ram_block_discard_*_range() declarations
system/ramblock: Use ram_addr_t in ram_block_discard_guest_memfd_range
system/ramblock: Use ram_addr_t 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 | 50 ++++++++++++-----------
9 files changed, 55 insertions(+), 45 deletions(-)
--
2.51.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/6] system/ramblock: Remove obsolete comment
2025-09-29 15:45 [PATCH 0/6] system/ramblock: Sanitize header Philippe Mathieu-Daudé
@ 2025-09-29 15:45 ` Philippe Mathieu-Daudé
2025-09-29 16:13 ` David Hildenbrand
2025-09-29 15:45 ` [PATCH 2/6] system/ramblock: Move ram_block_is_pmem() declaration Philippe Mathieu-Daudé
` (4 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-09-29 15:45 UTC (permalink / raw)
To: qemu-devel
Cc: Fabiano Rosas, Maciej S. Szmigiero, Richard Henderson,
Michael S. Tsirkin, Paolo Bonzini, David Hildenbrand,
Philippe Mathieu-Daudé, kvm, Peter Xu
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>
---
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] 11+ messages in thread
* [PATCH 2/6] system/ramblock: Move ram_block_is_pmem() declaration
2025-09-29 15:45 [PATCH 0/6] system/ramblock: Sanitize header Philippe Mathieu-Daudé
2025-09-29 15:45 ` [PATCH 1/6] system/ramblock: Remove obsolete comment Philippe Mathieu-Daudé
@ 2025-09-29 15:45 ` Philippe Mathieu-Daudé
2025-09-29 16:58 ` Alex Bennée
2025-09-29 15:45 ` [PATCH 3/6] system/ramblock: Move ram_block_discard_*_range() declarations Philippe Mathieu-Daudé
` (3 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-09-29 15:45 UTC (permalink / raw)
To: qemu-devel
Cc: Fabiano Rosas, Maciej S. Szmigiero, Richard Henderson,
Michael S. Tsirkin, Paolo Bonzini, David Hildenbrand,
Philippe Mathieu-Daudé, kvm, Peter Xu
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>
---
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..12f64fbf78b 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);
+/**
+ * ramblock_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] 11+ messages in thread
* [PATCH 3/6] system/ramblock: Move ram_block_discard_*_range() declarations
2025-09-29 15:45 [PATCH 0/6] system/ramblock: Sanitize header Philippe Mathieu-Daudé
2025-09-29 15:45 ` [PATCH 1/6] system/ramblock: Remove obsolete comment Philippe Mathieu-Daudé
2025-09-29 15:45 ` [PATCH 2/6] system/ramblock: Move ram_block_is_pmem() declaration Philippe Mathieu-Daudé
@ 2025-09-29 15:45 ` Philippe Mathieu-Daudé
2025-09-29 15:45 ` [PATCH 4/6] system/ramblock: Use ram_addr_t in ram_block_discard_guest_memfd_range Philippe Mathieu-Daudé
` (2 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-09-29 15:45 UTC (permalink / raw)
To: qemu-devel
Cc: Fabiano Rosas, Maciej S. Szmigiero, Richard Henderson,
Michael S. Tsirkin, Paolo Bonzini, David Hildenbrand,
Philippe Mathieu-Daudé, kvm, Peter Xu
Keep RAM blocks API in the same header: "system/ramblock.h".
Signed-off-by: Philippe Mathieu-Daudé <philmd@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 12f64fbf78b..e69af20b810 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] 11+ messages in thread
* [PATCH 4/6] system/ramblock: Use ram_addr_t in ram_block_discard_guest_memfd_range
2025-09-29 15:45 [PATCH 0/6] system/ramblock: Sanitize header Philippe Mathieu-Daudé
` (2 preceding siblings ...)
2025-09-29 15:45 ` [PATCH 3/6] system/ramblock: Move ram_block_discard_*_range() declarations Philippe Mathieu-Daudé
@ 2025-09-29 15:45 ` Philippe Mathieu-Daudé
2025-10-01 15:59 ` Richard Henderson
2025-09-29 15:45 ` [PATCH 5/6] system/ramblock: Use ram_addr_t in ram_block_discard_range() Philippe Mathieu-Daudé
2025-09-29 15:45 ` [PATCH 6/6] system/ramblock: Move RAMBlock helpers out of "system/ram_addr.h" Philippe Mathieu-Daudé
5 siblings, 1 reply; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-09-29 15:45 UTC (permalink / raw)
To: qemu-devel
Cc: Fabiano Rosas, Maciej S. Szmigiero, Richard Henderson,
Michael S. Tsirkin, Paolo Bonzini, David Hildenbrand,
Philippe Mathieu-Daudé, kvm, Peter Xu
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
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 5/6] system/ramblock: Use ram_addr_t in ram_block_discard_range()
2025-09-29 15:45 [PATCH 0/6] system/ramblock: Sanitize header Philippe Mathieu-Daudé
` (3 preceding siblings ...)
2025-09-29 15:45 ` [PATCH 4/6] system/ramblock: Use ram_addr_t in ram_block_discard_guest_memfd_range Philippe Mathieu-Daudé
@ 2025-09-29 15:45 ` Philippe Mathieu-Daudé
2025-09-29 15:45 ` [PATCH 6/6] system/ramblock: Move RAMBlock helpers out of "system/ram_addr.h" Philippe Mathieu-Daudé
5 siblings, 0 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-09-29 15:45 UTC (permalink / raw)
To: qemu-devel
Cc: Fabiano Rosas, Maciej S. Szmigiero, Richard Henderson,
Michael S. Tsirkin, Paolo Bonzini, David Hildenbrand,
Philippe Mathieu-Daudé, kvm, Peter Xu
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
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 6/6] system/ramblock: Move RAMBlock helpers out of "system/ram_addr.h"
2025-09-29 15:45 [PATCH 0/6] system/ramblock: Sanitize header Philippe Mathieu-Daudé
` (4 preceding siblings ...)
2025-09-29 15:45 ` [PATCH 5/6] system/ramblock: Use ram_addr_t in ram_block_discard_range() Philippe Mathieu-Daudé
@ 2025-09-29 15:45 ` Philippe Mathieu-Daudé
2025-10-01 16:03 ` Richard Henderson
5 siblings, 1 reply; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-09-29 15:45 UTC (permalink / raw)
To: qemu-devel
Cc: Fabiano Rosas, Maciej S. Szmigiero, Richard Henderson,
Michael S. Tsirkin, Paolo Bonzini, David Hildenbrand,
Philippe Mathieu-Daudé, kvm, Peter Xu
Signed-off-by: Philippe Mathieu-Daudé <philmd@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 57c00e42ca6..1b4092d6322 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) ? true : false;
+}
+
+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] 11+ messages in thread
* Re: [PATCH 1/6] system/ramblock: Remove obsolete comment
2025-09-29 15:45 ` [PATCH 1/6] system/ramblock: Remove obsolete comment Philippe Mathieu-Daudé
@ 2025-09-29 16:13 ` David Hildenbrand
0 siblings, 0 replies; 11+ messages in thread
From: David Hildenbrand @ 2025-09-29 16:13 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Fabiano Rosas, Maciej S. Szmigiero, Richard Henderson,
Michael S. Tsirkin, Paolo Bonzini, kvm, Peter Xu
On 29.09.25 17:45, Philippe Mathieu-Daudé wrote:
> 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>
--
Cheers
David / dhildenb
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/6] system/ramblock: Move ram_block_is_pmem() declaration
2025-09-29 15:45 ` [PATCH 2/6] system/ramblock: Move ram_block_is_pmem() declaration Philippe Mathieu-Daudé
@ 2025-09-29 16:58 ` Alex Bennée
0 siblings, 0 replies; 11+ messages in thread
From: Alex Bennée @ 2025-09-29 16:58 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: qemu-devel, Fabiano Rosas, Maciej S. Szmigiero, Richard Henderson,
Michael S. Tsirkin, Paolo Bonzini, David Hildenbrand, kvm,
Peter Xu
Philippe Mathieu-Daudé <philmd@linaro.org> writes:
> 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>
> ---
> 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..12f64fbf78b 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);
>
> +/**
> + * ramblock_is_pmem: Whether the RAM block is of persistent memory
missed a rename
Otherwise:
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> + */
> +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;
> }
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 4/6] system/ramblock: Use ram_addr_t in ram_block_discard_guest_memfd_range
2025-09-29 15:45 ` [PATCH 4/6] system/ramblock: Use ram_addr_t in ram_block_discard_guest_memfd_range Philippe Mathieu-Daudé
@ 2025-10-01 15:59 ` Richard Henderson
0 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2025-10-01 15:59 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Fabiano Rosas, Maciej S. Szmigiero, Michael S. Tsirkin,
Paolo Bonzini, David Hildenbrand, kvm, Peter Xu
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~
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 6/6] system/ramblock: Move RAMBlock helpers out of "system/ram_addr.h"
2025-09-29 15:45 ` [PATCH 6/6] system/ramblock: Move RAMBlock helpers out of "system/ram_addr.h" Philippe Mathieu-Daudé
@ 2025-10-01 16:03 ` Richard Henderson
0 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2025-10-01 16:03 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Fabiano Rosas, Maciej S. Szmigiero, Michael S. Tsirkin,
Paolo Bonzini, David Hildenbrand, kvm, Peter Xu
On 9/29/25 08:45, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> include/system/ram_addr.h | 11 -----------
> include/system/ramblock.h | 11 +++++++++++
> 2 files changed, 11 insertions(+), 11 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> +static inline bool offset_in_ramblock(RAMBlock *b, ram_addr_t offset)
> +{
> + return (b && b->host && offset < b->used_length) ? true : false;
... though we could stand to clean up "? true : false" silliness.
I assume this comes from programmers who first learned something other than C, but I can't
work out what language that might be. I see it in patches every once in a while.
r~
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2025-10-01 16:05 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-29 15:45 [PATCH 0/6] system/ramblock: Sanitize header Philippe Mathieu-Daudé
2025-09-29 15:45 ` [PATCH 1/6] system/ramblock: Remove obsolete comment Philippe Mathieu-Daudé
2025-09-29 16:13 ` David Hildenbrand
2025-09-29 15:45 ` [PATCH 2/6] system/ramblock: Move ram_block_is_pmem() declaration Philippe Mathieu-Daudé
2025-09-29 16:58 ` Alex Bennée
2025-09-29 15:45 ` [PATCH 3/6] system/ramblock: Move ram_block_discard_*_range() declarations Philippe Mathieu-Daudé
2025-09-29 15:45 ` [PATCH 4/6] system/ramblock: Use ram_addr_t in ram_block_discard_guest_memfd_range Philippe Mathieu-Daudé
2025-10-01 15:59 ` Richard Henderson
2025-09-29 15:45 ` [PATCH 5/6] system/ramblock: Use ram_addr_t in ram_block_discard_range() Philippe Mathieu-Daudé
2025-09-29 15:45 ` [PATCH 6/6] system/ramblock: Move RAMBlock helpers out of "system/ram_addr.h" Philippe Mathieu-Daudé
2025-10-01 16:03 ` Richard Henderson
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).