Next patches
[PULL 02/10] migration/cpr: Add HMP support for cpr-transfer
In reply to Peter XuFrom: Dongli Zhang <[email protected]>
Currently the cpr-transfer source QEMU instance cannot be driven entirely via HMP. The source must use QMP in order to specify both the main migration channel and the CPR channel.
Extend the HMP migrate command with an optional CPR channel URI. When the migration mode is cpr-transfer, HMP uses this URI to build a CPR MigrationChannel in addition to the main migration channel. The new option is rejected unless the migration mode is cpr-transfer, so existing HMP migrate usage is unchanged.
For example, source QEMU HMP commands can be something like below. The "-c unix:/tmp/cpr.sock" is for CPR URI.
(qemu) migrate_set_parameter mode cpr-transfer
(qemu) migrate -c unix:/tmp/cpr.sock tcp:0:50002
--- migration/migration-hmp-cmds.c | 18 ++++++++++++++++++ hmp-commands.hx | 12 ++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-)
migration/migration-hmp-cmds.c +18 -0
@@ -837,9 +837,11 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)bool detach =qdict_get_try_bool (qdict,"detach" , false);bool resume =qdict_get_try_bool (qdict,"resume" , false);const char *uri =qdict_get_str (qdict,"uri" ); +const char *uri_cpr =qdict_get_try_str (qdict,"uri-cpr" );Error *err =NULL ;g_autoptr (MigrationChannelList) caps =NULL ;g_autoptr (MigrationChannel) channel =NULL ; +g_autoptr (MigrationChannel) channel_cpr =NULL ;if (!migrate_uri_parse (uri, &channel, &err)) {hmp_handle_error (mon, err);
@@ -847,6 +849,22 @@ void hmp_migrate(Monitor *mon, const QDict *qdict) }QAPI_LIST_PREPEND (caps,g_steal_pointer (&channel)); +if (uri_cpr) { +if (migrate_mode () !=MIG_MODE_CPR_TRANSFER ) { +error_setg (&err,"-c can only be used in cpr-transfer mode" ); +hmp_handle_error (mon, err); +return ; + } + +if (!migrate_uri_parse (uri_cpr, &channel_cpr, &err)) { +hmp_handle_error (mon, err); +return ; + } + + channel_cpr->channel_type =MIGRATION_CHANNEL_TYPE_CPR ; +QAPI_LIST_PREPEND (caps,g_steal_pointer (&channel_cpr)); + } +qmp_migrate (NULL , true, caps, true, resume, &err);if (hmp_handle_error (mon, err)) {return ;
hmp-commands.hx +8 -4
@@ -928,16 +928,17 @@ ERST { .name = "migrate", - .args_type = "detach:-d,resume:-r,uri:s", - .params = "[-d] [-r] uri", + .args_type = "detach:-d,resume:-r,uri-cpr:-cs,uri:s", + .params = "[-d] [-r] [-c uri-cpr] uri", .help = "migrate to URI (using -d to not wait for completion)" - "\n\t\t\t -r to resume a paused postcopy migration", + "\n\t\t\t -r to resume a paused postcopy migration" + "\n\t\t\t -c to specify a CPR URI for cpr-transfer mode", .cmd = hmp_migrate, }, SRST -``migrate [-d] [-r]`` *uri* +``migrate [-d] [-r] [-c uri-cpr]`` *uri* Migrate the VM to *uri*. ``-d``
@@ -945,6 +946,9 @@ SRST query an ongoing migration process, use "info migrate". ``-r`` Resume a paused postcopy migration. + ``-c`` *uri-cpr* + Specify the CPR URI for cpr-transfer mode. It must be a UNIX domain + socket. ERST {
Signature · 1 line
2.54.0
[PULL 01/10] docs: Add security considerations for migration
In reply to Peter XuFrom: Fabiano Rosas <[email protected]>
Add the security considerations that are unique to migration and that do not already fall into one of the other categories. Some aspects are better framed as security architecture considerations, so extend that section to mention TLS and clarify that disk images and guest network also need to be isolated from other processes, not just other guests.
--- docs/system/security.rst | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)
docs/system/security.rst +18 -4
@@ -133,6 +133,16 @@ an issue as a normal bug. that affect the level 0 QEMU process. While these bugs should be fixed, they will not be triaged as security flaws at this time. +* **migration/snapshots**. Migration failures and snapshot load + failures are considered part of normal operation as long as the + source virtual machine and savevm file, respectively, are still + functional. Aborting the QEMU process at the migration/snapshot + destination is similarly not considered a security issue. The + migration stream is assumed to be secure as long as the design + principles described in the Architecture section are held, in + which case plain manipulation of the stream is not considered as + an attack vector. + * **low severity impact**. As a catch all rule, issues which are judged to have a "low" severity impact on the system will usually not justify handling as security bugs, nor assignment
@@ -159,10 +169,11 @@ could allow malicious guests to gain code execution in QEMU. At this point the guest has escaped the virtual machine and is able to act in the context of the QEMU process on the host. -Guests often interact with other guests and share resources with them. A -malicious guest must not gain control of other guests or access their data. -Disk image files and network traffic must be protected from other guests unless -explicitly shared between them by the user. +Guests often interact with other guests and share resources with them. +A malicious guest must not gain control of other guests or access +their data. Disk image files and network traffic must be protected +from other guests, users and processes unless explicitly shared with +them by the user. Principle of Least Privilege ''''''''''''''''''''''''''''
@@ -223,6 +234,9 @@ Some Linux distros already ship with UNIX groups for these devices by default. system calls that are not needed by QEMU, thereby reducing the host kernel attack surface. +- Transport Layer Security (TLS) protocol can be used to ensure authenticity and + encryption of the live migration connection where the network is untrusted. + Sensitive configurations ------------------------
Signature · 1 line
2.54.0
[PULL 03/10] system/memory: Use memmove() for directly accessible regions
In reply to Peter XuFrom: Gavin Shan <[email protected]>
Similar to what's done in commit 4a73aee88140 ("softmmu: Use memmove in flatview_write_continue"), there are more sites where the overlapping source and destination buffer are allowed for the directly accessible regions. Use memmove() in those sites, listed as below.
hw/remote/vfio-user-obj.c::vfu_object_mr_rw
include/system/memory.h::address_space_read
system/physmem.c::flatview_read_continue_step
--- include/system/memory.h | 2 +- hw/remote/vfio-user-obj.c | 4 ++-- system/physmem.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
include/system/memory.h +1 -1
@@ -2741,7 +2741,7 @@ MemTxResult address_space_read(const AddressSpace *as, hwaddr addr, mr =flatview_translate (fv, addr, &addr1, &l, false, attrs);if (len == l &&memory_access_is_direct (mr, false, attrs)) { ptr =qemu_map_ram_ptr (mr->ram_block, addr1); -memcpy (buf, ptr, len); +memmove (buf, ptr, len); }else { result =flatview_read_continue (fv, addr, attrs, buf, len, addr1, l, mr);
hw/remote/vfio-user-obj.c +2 -2
@@ -375,9 +375,9 @@ static int vfu_object_mr_rw(MemoryRegion *mr, uint8_t *buf, hwaddr offset, ram_ptr =memory_region_get_ram_ptr (mr);if (is_write) { -memcpy ((ram_ptr + offset), buf, size); +memmove ((ram_ptr + offset), buf, size); }else { -memcpy (buf, (ram_ptr + offset), size); +memmove (buf, (ram_ptr + offset), size); }return 0 ;
system/physmem.c +1 -1
@@ -3363,7 +3363,7 @@ static MemTxResult flatview_read_continue_step(MemTxAttrs attrs, uint8_t *buf,uint8_t *ram_ptr =qemu_ram_ptr_length (mr->ram_block, mr_addr, l, false, false); -memcpy (buf, ram_ptr, *l); +memmove (buf, ram_ptr, *l);return MEMTX_OK ; }
Signature · 1 line
2.54.0
[PULL 07/10] migration/multifd: Validate next_packet_size in zlib/zstd recv
In reply to Peter XuThe zlib and zstd multifd compression backends read next_packet_size from the incoming migration stream and use it directly as the read length into a fixed-size buffer (MULTIFD_PACKET_SIZE * 2 = 1MB). A malicious migration source can set next_packet_size bigger than allocated, causing a heap buffer overflow write on the destination.
Add a check against zbuff_len before reading, matching what the qatzip backend already does. Also replace the assert(in_size == 0) for empty packets with proper error reporting, since the value is wire-controlled, meanwhile assert() stops working with -DNDEBUG builds.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3737
--- migration/multifd-zlib.c | 11 ++++++++++- migration/multifd-zstd.c | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-)
migration/multifd-zlib.c +10 -1
@@ -216,10 +216,19 @@ static int multifd_zlib_recv(MultiFDRecvParams *p, Error **errp)return -1 ; } +if (in_size > z->zbuff_len) { +error_setg (errp,"multifd %u: next_packet_size %" PRIu32 +" exceeds allocated %" PRIu32, p->id, in_size, z->zbuff_len); +return -1 ; + } +multifd_recv_zero_page_process (p);if (!p->normal_num) { -assert (in_size ==0 ); +if (in_size !=0 ) { +error_setg (errp,"multifd %u: expected empty packet" , p->id); +return -1 ; + }return 0 ; }
migration/multifd-zstd.c +10 -1
@@ -210,10 +210,19 @@ static int multifd_zstd_recv(MultiFDRecvParams *p, Error **errp)return -1 ; } +if (in_size > z->zbuff_len) { +error_setg (errp,"multifd %u: next_packet_size %" PRIu32 +" exceeds allocated %" PRIu32, p->id, in_size, z->zbuff_len); +return -1 ; + } +multifd_recv_zero_page_process (p);if (!p->normal_num) { -assert (in_size ==0 ); +if (in_size !=0 ) { +error_setg (errp,"multifd %u: expected empty packet" , p->id); +return -1 ; + }return 0 ; }
Signature · 1 line
2.54.0
The following changes since commit 84f07211cc5b4fc6a371559bf8a5de4fb068e648:
Update version for v11.1.0 release (2026-08-11 10:04:46 -0400)
are available in the Git repository at:
https://gitlab.com/peterx/qemu.git tags/next-pull-request
for you to fetch changes up to 2375e9b1239eb6ad794eaae29245b94f429c87c5:
migration: Fix rare hang of migration_channel_read_peek() (2026-08-12 10:42:09 -0400)
----------------------------------------------------------------
migration/mem pull for 11.2
next 11.2:
- Dongli's patch to add cpr-transfer support for HMP
- Fabiano's doc update for migration on security issues
- Gavin's fix for MMIO access support for memory APIs, reverting ram_device ops
- Sam's migration test build fix for !ASN1
- Peter's a few migration hardening fixes
----------------------------------------------------------------
Dongli Zhang (1):
migration/cpr: Add HMP support for cpr-transfer
Fabiano Rosas (1):
docs: Add security considerations for migration
Gavin Shan (3):
system/memory: Use memmove() for directly accessible regions system/memory: Use qemu_ram_move() for directly accessible regions system/memory: Make ram device region directly accessible
Peter Xu (4):
migration/multifd: Validate next_packet_size in zlib/zstd recv migration/multifd: Replace assert() with error_setg() in recv paths migration/ram: Check for RAMBlock size mismatch when parsing
migration: Fix rare hang of migration_channel_read_peek()
Sam Heney (1):
tests/qtest/migration: Only build tls_no_hostname test with TASN1
docs/system/security.rst | 22 +++++++++++--- include/system/memory.h | 46 ++++++++++++++++++++++------- hw/remote/vfio-user-obj.c | 4 +-- migration/channel.c | 11 +++++-- migration/migration-hmp-cmds.c | 18 ++++++++++++ migration/multifd-qatzip.c | 5 +++- migration/multifd-qpl.c | 24 +++++++++++++--- migration/multifd-uadk.c | 24 +++++++++++++--- migration/multifd-zlib.c | 11 ++++++- migration/multifd-zstd.c | 11 ++++++- migration/ram.c | 11 +++++-- system/memory.c | 41 +------------------------- system/physmem.c | 48 +++++++++++++++++++++++++++++-- tests/qtest/migration/tls-tests.c | 4 ++- hmp-commands.hx | 12 +++++--- system/trace-events | 2 -- 16 files changed, 214 insertions(+), 80 deletions(-)
Signature · 1 line
2.54.0
[PULL 04/10] system/memory: Use qemu_ram_move() for directly accessible regions
From: Gavin Shan <[email protected]>
All ram device regions were turned to be indirectly accessible by commit 4a2e242bbb ("memory: Don't use memcpy for ram_device regions"). This leads to guest hang on attempt to build 'cuda-samples' as reported by Julia. The guest is started by the following command lines, with GH100 GPU card passed from the host.
host$ lspci | grep GH100
0009:01:00.0 3D controller: NVIDIA Corporation GH100 [GH200 120GB / 480GB] (rev a1)
host$ /home/sandbox/gavin/qemu.main/build/qemu-system-aarch64 \
-machine virt,gic-version=host,ras=on,highmem-mmio-size=4T \
-accel kvm -cpu host -smp cpus=48 -m size=8G \
-drive file=/home/gavin/sandbox/images/disk.qcow2,if=none,id=d0 \
-device virtio-blk-pci,id=vb0,bus=pcie.0,drive=d0,num-queues=4 \
-device vfio-pci-nohotplug,host=0009:01:00.0,bus=pcie.1.0
:
guest$ cd cuda-samples/build
guest$ make -j 20 clean
guest$ make -j 20
:
[ 54%] Linking CUDA executable graphMemoryNodes
[ 54%] Built target graphMemoryNodes
<no more output afterwards, guest becomes frozen here>guest$ qemu-system-aarch64: virtio: bogus descriptor or out of resources
[ 555.814025] virtio_blk virtio0: [vda] new size: 268435456 512-byte logical blocks (137 GB/128 GiB)
When the GPU's driver (NVidia open driver) is loaded on guest bootup, the memory blocks residing in the PCI BAR#4 of the GH100 GPU card can be presented to the guest through memory hot-add. The page cache can then be allocated from the hot added memory blocks when cuda-samples is being built. Afterwards, the page cache is sent to QEMU's virtio-blk device as part of the DMA request, the bounce buffer has to be used to accomodate the request as the corresponding memory region (MemoryRegion) is an indirectly accessible ram device region in qemu. However, the max bounce bufer size is only 4096 bytes by default and that is exhausted quickly, leading to a reset on the virtio-blk device and frozen guest eventually.
QEMU
====
virtio_blk_handle_output
virtio_blk_handle_vq
virtio_blk_get_request
virtqueue_pop
virtqueue_split_pop
virtqueue_map_desc
address_space_map
memory_access_is_direct # Return false
memory_region_supports_direct_access
(qemu) info mtree
memory-region: pci_bridge_pci
0000000000000000-ffffffffffffffff (prio 0, container): pci_bridge_pci
0000042000000000-0000043fffffffff (prio 1, i/o): 0009:01:00.0 base BAR 4
0000042000000000-0000043fffffffff (prio 0, i/o): 0009:01:00.0 BAR 4
0000042000000000-000004379fffffff (prio 0, ramd): 0009:01:00.0 BAR 4 mmaps[0]This adds qemu_ram_move() where the aligned and small-sized accesses are handled by qatomics, and fall back to memmove() otherwise. The memove() for the directly accessible regions is replaced by qemu_ram_move() so that the issue covered by commit 4a2e242bbb (MMIO access instructions were optimized to SSE instructions) is fixed. This makes 'ram_device_mem_ops' redundant, paving the way to revert that commit to make the ram device region directly accessible again in the next patch.
Besides, this also fixes the issue of the unexpected frozen reception on e1000 NIC in the scenario of DPDK due to the wrong Rx queue full indication caused by the following memcpy(), which is turned to 3 consective 'strb' instructions to the same location by glibc-2.24+ for aarch64. With this applied, the syntax of one-byte store is strictly ensured by a one-byte qatomic set.
QEMU
====
e1000_receive_iov
pci_dma_write
pci_dma_rw
dma_memory_rw
dma_memory_rw_relaxed
address_space_rw
address_space_write
flatview_write
flatview_write_continue
flatview_write_continue_step
memcpy # 3 consective 'strb' instructions
--- include/system/memory.h | 35 +++++++++++++++++++++++++++- hw/remote/vfio-user-obj.c | 4 ++-- system/physmem.c | 48 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 82 insertions(+), 5 deletions(-)
include/system/memory.h +34 -1
@@ -2668,6 +2668,39 @@ void address_space_register_map_client(AddressSpace *as, QEMUBH *bh);void address_space_unregister_map_client (AddressSpace *as,QEMUBH *bh);/* Internal functions, part of the implementation of address_space_read. */ + +/** +* qemu_ram_move: move data from or to ramblock +* +* @dst: destination where the data is moved to +* @src: source where the data is moved from +* @n: length of data to be moved +* +* Move @n bytes from @src to @dst, the memory areas may overlap. This +* provides the same semantics as memmove(), plus an additional stronger +* guarantee: if @n is 1, 2 or 4 or 8 bytes, and @src and @dst are both +* naturally aligned for that access size, then both the load and the store +* will be done as a single atomic access (with the semantics of +* qatomic_read() and qatomic_set()). +* +* This is the underlying function that we use to implement accesses by +* a guest vCPU or a device DMA operation to a ram block. The atomic +* guarantee is needed for two major cases: (A) When the ram block is +* backed by a PCI BAR passed through from a host device (and so it might +* be hardware registers that must be accessed exactly once at the right +* width); (B) When an emulated device updates a data structure shared in +* guest memory with guest software (e.g. a network device's set of tx and +* rx descriptor blocks), if a write to memory is accidentally performed +* multiple times then it can break the guest code when it busy polls the +* guest memory. +* +* We don't attempt to perform the exact access when it would be unaligned +* because this can't be done on all host architectures. Although this is +* strictly speaking not doing what would happen on real hardware, we don't +* think there are going to be situations where that matters in practice. +*/ +void qemu_ram_move (void *dst,const void *src,size_t n); +MemTxResult address_space_read_full (const AddressSpace *as,hwaddr addr,MemTxAttrs attrs,void *buf,hwaddr len); MemTxResult flatview_read_continue(FlatView *fv, hwaddr addr,
@@ -2741,7 +2774,7 @@ MemTxResult address_space_read(const AddressSpace *as, hwaddr addr, mr =flatview_translate (fv, addr, &addr1, &l, false, attrs);if (len == l &&memory_access_is_direct (mr, false, attrs)) { ptr =qemu_map_ram_ptr (mr->ram_block, addr1); -memmove (buf, ptr, len); +qemu_ram_move (buf, ptr, len); }else { result =flatview_read_continue (fv, addr, attrs, buf, len, addr1, l, mr);
hw/remote/vfio-user-obj.c +2 -2
@@ -375,9 +375,9 @@ static int vfu_object_mr_rw(MemoryRegion *mr, uint8_t *buf, hwaddr offset, ram_ptr =memory_region_get_ram_ptr (mr);if (is_write) { -memmove ((ram_ptr + offset), buf, size); +qemu_ram_move ((ram_ptr + offset), buf, size); }else { -memmove (buf, (ram_ptr + offset), size); +qemu_ram_move (buf, (ram_ptr + offset), size); }return 0 ;
system/physmem.c +46 -2
66 lines not on this page · raw message
Signature · 1 line
2.54.0
[PULL 05/10] system/memory: Make ram device region directly accessible
In reply to Peter XuFrom: Gavin Shan <[email protected]>
This basically reverts 4a2e242bbb30 ("memory: Don't use memcpy for ram_device regions") to make ram device region directly accessible again. With this, the bounce buffer is bypassed in address_space_map() when a ram device region is involved, potentially avoid to overrun the (small) bounce buffer.
--- include/system/memory.h | 11 ++--------- system/memory.c | 41 +---------------------------------------- system/trace-events | 2 -- 3 files changed, 3 insertions(+), 51 deletions(-)
include/system/memory.h +2 -9
@@ -2718,15 +2718,8 @@ static inline bool memory_region_supports_direct_access(const MemoryRegion *mr)if (memory_region_is_romd (mr)) {return true; } -if (!memory_region_is_ram (mr)) { -return false; - } -/* -* RAM DEVICE regions can be accessed directly using memcpy, but it might -* be MMIO and access using mempy can be wrong (e.g., using instructions not -* intended for MMIO access). So we treat this as IO. -*/ -return !memory_region_is_ram_device (mr); + +return memory_region_is_ram (mr); } static inline bool memory_access_is_direct(const MemoryRegion *mr,
system/memory.c +1 -40
54 lines not on this page · raw message
system/trace-events +0 -2
@@ -20,8 +20,6 @@ memory_region_ops_read(int cpu_index, void *mr, uint64_t addr, uint64_t value, u memory_region_ops_write(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size, const char *name) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u name '%s'" memory_region_subpage_read(int cpu_index, void *mr, uint64_t offset, uint64_t value, unsigned size) "cpu %d mr %p offset 0x%"PRIx64" value 0x%"PRIx64" size %u" memory_region_subpage_write(int cpu_index, void *mr, uint64_t offset, uint64_t value, unsigned size) "cpu %d mr %p offset 0x%"PRIx64" value 0x%"PRIx64" size %u" -memory_region_ram_device_read(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u" -memory_region_ram_device_write(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u" memory_region_sync_dirty(const char *mr, const char *listener, int global) "mr '%s' listener '%s' synced (global=%d)" flatview_new(void *view, void *root) "%p (root %p)" flatview_destroy(void *view, void *root) "%p (root %p)"
Signature · 1 line
2.54.0
[PULL 06/10] tests/qtest/migration: Only build tls_no_hostname test with TASN1
In reply to Peter XuFrom: Sam Heney <[email protected]>
The test_precopy_tcp_tls_no_hostname test and its start hook use TestMigrateTLSX509 and migrate_hook_start_tls_x509_common(), which are only defined when CONFIG_TASN1 is set. This means building with gnutls enabled but libtasn1 unavailable fails:
../tests/qtest/migration/tls-tests.c: In function 'migrate_hook_start_tls_x509_no_host':
../tests/qtest/migration/tls-tests.c:510:5: error: unknown type name 'TestMigrateTLSX509'
Guard the test with CONFIG_TASN1 like the other x509 tests.
--- tests/qtest/migration/tls-tests.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tests/qtest/migration/tls-tests.c +3 -1
@@ -492,6 +492,7 @@ static void test_precopy_tcp_no_tls(char *name, MigrateCommon *args)test_precopy_common (args); } +#ifdef CONFIG_TASN1 static void *migrate_hook_start_tls_x509_no_host (QTestState *from,QTestState *to) {
@@ -519,7 +520,6 @@ static void test_precopy_tcp_tls_no_hostname(char *name, MigrateCommon *args)test_precopy_common (args); } -#ifdef CONFIG_TASN1 static void test_precopy_tcp_tls_x509_default_host (char *name,MigrateCommon *args) {
@@ -719,8 +719,10 @@ void migration_test_add_tls(MigrationTestEnv *env)migration_test_add ("/migration/precopy/tcp/no-tls" , test_precopy_tcp_no_tls); +#ifdef CONFIG_TASN1 migration_test_add ("/migration/precopy/tcp/tls/no-hostname" , test_precopy_tcp_tls_no_hostname); +#endif /* CONFIG_TASN1 */ migration_test_add ("/migration/precopy/unix/tls/psk" , test_precopy_unix_tls_psk);
Signature · 1 line
2.54.0
[PULL 09/10] migration/ram: Check for RAMBlock size mismatch when parsing
In reply to Peter XuAdd an underflow check for the subtract of total RAMBlock size to make sure it won't underflow. It should not happen in production systems but only if the migration stream was hijacked, which is not a real concern since migration channel is trusted. Still protect against it.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4013
--- migration/ram.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
migration/ram.c +9 -2
@@ -4268,7 +4268,7 @@ static int parse_ramblocks(QEMUFile *f, ram_addr_t total_ram_bytes)int ret =0 ;/* Synchronize RAM block list */ -while (!ret && total_ram_bytes) { +while (total_ram_bytes) {RAMBlock *block;char id[256 ];ram_addr_t length;
@@ -4285,8 +4285,15 @@ static int parse_ramblocks(QEMUFile *f, ram_addr_t total_ram_bytes)error_report ("Unknown ramblock \"%s\", cannot accept " "migration" , id); ret = -EINVAL ; +break ; + } + +if (usub64_overflow (total_ram_bytes, length, &total_ram_bytes)) { +error_report ("%s: RAMBlock '%s' size underflow total RAM size" , + __func__, block->idstr); + ret = -EFAULT ; +break ; } - total_ram_bytes -= length; }return ret;
Signature · 1 line
2.54.0
[PULL 10/10] migration: Fix rare hang of migration_channel_read_peek()
In reply to Peter XuIn an unlikely case, when a migration stream is attached to the destination QEMU and only send <4 bytes to the channel as magic, it's possible that migration_channel_read_peek() may spin forever.
Fix it by adding a manual sleep for partial read.
Since the path isn't attached to a coroutine, it means when partial read happens, there's yet not much we can do but hang the main thread, it will happen even for len==0 case. It means monitors can hang due to this, either partial read or no data arrived (but connection established).
Leave this for later, the hope is this is extremely rare in production.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3889
--- migration/channel.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
migration/channel.c +9 -2
@@ -296,9 +296,16 @@ int migration_channel_read_peek(QIOChannel *ioc,if (len == buflen) {break ; + }else if (len ==QIO_CHANNEL_ERR_BLOCK ) { +qio_channel_wait_cond (ioc,G_IO_IN ); + }else { +/* +* When partially ready, we can't use qio_channel_wait_cond() +* because it will return immediately. Apply a manual wait. +*/ +assert (!qemu_in_coroutine ()); +g_usleep (1000 ); } - -qio_channel_wait_cond (ioc,G_IO_IN ); }return 0 ;
Signature · 1 line
2.54.0
[PULL 08/10] migration/multifd: Replace assert() with error_setg() in recv paths
In reply to Peter XuQPL and UADK multifd backends use assert() to validate wire-controlled fields like per-page compressed lengths and packet size consistency. These asserts will stop working with -DNDEBUG builds, so may stop working.
Replace all assert() calls in the receive path with proper error_setg() so validation failures are reported gracefully rather than crashing or silently ignored.
While at it, touch up an assert() in qatzip recv path too.
--- migration/multifd-qatzip.c | 5 ++++- migration/multifd-qpl.c | 24 ++++++++++++++++++++---- migration/multifd-uadk.c | 24 ++++++++++++++++++++---- 3 files changed, 44 insertions(+), 9 deletions(-)
migration/multifd-qatzip.c +4 -1
@@ -348,7 +348,10 @@ static int qatzip_recv(MultiFDRecvParams *p, Error **errp)multifd_recv_zero_page_process (p);if (!p->normal_num) { -assert (in_size ==0 ); +if (in_size !=0 ) { +error_setg (errp,"multifd %u: expected empty packet" , p->id); +return -1 ; + }return 0 ; }
migration/multifd-qpl.c +20 -4
@@ -664,26 +664,42 @@ static int multifd_qpl_recv(MultiFDRecvParams *p, Error **errp) }multifd_recv_zero_page_process (p);if (!p->normal_num) { -assert (in_size ==0 ); +if (in_size !=0 ) { +error_setg (errp,"multifd %u: expected empty packet" , p->id); +return -1 ; + }return 0 ; }/* read compressed page lengths */ len = p->normal_num *sizeof (uint32_t ); -assert (len < in_size); +if (len >= in_size) { +error_setg (errp,"multifd %u: header len %" PRIu32 +" >= packet size %" PRIu32, p->id, len, in_size); +return -1 ; + } ret =qio_channel_read_all (p->c, (void *) qpl->zlen, len, errp);if (ret !=0 ) {return ret; }for (int i =0 ; i < p->normal_num; i++) { qpl->zlen[i] =be32_to_cpu (qpl->zlen[i]); -assert (qpl->zlen[i] <=multifd_ram_page_size ()); +if (qpl->zlen[i] >multifd_ram_page_size ()) { +error_setg (errp,"multifd %u: page %d compressed len %" + PRIu32" too large" , p->id, i, qpl->zlen[i]); +return -1 ; + } zbuf_len += qpl->zlen[i];ramblock_recv_bitmap_set_offset (p->block, p->normal[i]); }/* read compressed pages */ -assert (in_size == len + zbuf_len); +if (in_size != len + zbuf_len) { +error_setg (errp,"multifd %u: packet size %" PRIu32 +" != header %" PRIu32" + data %" PRIu32, + p->id, in_size, len, zbuf_len); +return -1 ; + } ret =qio_channel_read_all (p->c, (void *) qpl->zbuf, zbuf_len, errp);if (ret !=0 ) {return ret;
migration/multifd-uadk.c +20 -4
@@ -245,12 +245,19 @@ static int multifd_uadk_recv(MultiFDRecvParams *p, Error **errp)multifd_recv_zero_page_process (p);if (!p->normal_num) { -assert (in_size ==0 ); +if (in_size !=0 ) { +error_setg (errp,"multifd %u: expected empty packet" , p->id); +return -1 ; + }return 0 ; }/* read compressed data lengths */ -assert (hdr_len < in_size); +if (hdr_len >= in_size) { +error_setg (errp,"multifd %u: header len %" PRIu32 +" >= packet size %" PRIu32, p->id, hdr_len, in_size); +return -1 ; + } ret =qio_channel_read_all (p->c, (void *) uadk_data->buf_hdr, hdr_len, errp);if (ret !=0 ) {
@@ -259,12 +266,21 @@ static int multifd_uadk_recv(MultiFDRecvParams *p, Error **errp)for (int i =0 ; i < p->normal_num; i++) { uadk_data->buf_hdr[i] =be32_to_cpu (uadk_data->buf_hdr[i]); +if (uadk_data->buf_hdr[i] > page_size) { +error_setg (errp,"multifd %u: page %d compressed len %" PRIu32 +" too large" , p->id, i, uadk_data->buf_hdr[i]); +return -1 ; + } data_len += uadk_data->buf_hdr[i]; -assert (uadk_data->buf_hdr[i] <= page_size); }/* read compressed data */ -assert (in_size == hdr_len + data_len); +if (in_size != hdr_len + data_len) { +error_setg (errp,"multifd %u: packet size %" PRIu32 +" != header %" PRIu32" + data %" PRIu32, + p->id, in_size, hdr_len, data_len); +return -1 ; + } ret =qio_channel_read_all (p->c, (void *)buf, data_len, errp);if (ret !=0 ) {return ret;
Signature · 1 line
2.54.0
Quoted 15 lines · Peter Xu
The following changes since commit
84f07211cc5b4fc6a371559bf8a5de4fb068e648:Update version for v11.1.0 release (2026-08-11 10:04:46 -0400)are available in the Git repository at:
https://gitlab.com/peterx/qemu.git tags/next-pull-request
for you to fetch changes up to
2375e9b1239eb6ad794eaae29245b94f429c87c5:migration: Fix rare hang of migration_channel_read_peek() (2026-08-12 10:42:09 -0400)----------------------------------------------------------------
migration/mem pull for 11.2
Quoted 6 lines
next 11.2:
- Dongli's patch to add cpr-transfer support for HMP
- Fabiano's doc update for migration on security issues
- Gavin's fix for MMIO access support for memory APIs, revertingram_deviceops
- Sam's migration test build fix for !ASN1
- Peter's a few migration hardening fixes
MacOS build failures:
https://gitlab.com/qemu-project/qemu/-/jobs/15865084063
https://gitlab.com/qemu-project/qemu/-/jobs/15865084064
../migration/ram.c:4291:54: error: incompatible pointer types passing 'ram_addr_t *' (aka 'unsigned long *') to parameter of type 'uint64_t *' (aka 'unsigned long long *') [-Werror,-Wincompatible-pointer-types]
4291 | if (usub64_overflow(total_ram_bytes, length, &total_ram_bytes)) {
| ^~~~~~~~~~~~~~~~
/Users/gitlab/builds/qemu-project/qemu/include/qemu/host-utils.h:552:70: note: passing argument to parameter 'ret' here
552 | static inline bool usub64_overflow(uint64_t x, uint64_t y, uint64_t *ret)
| ^
Note that ram_addr_t maps to uintptr_t not uint64_t. Which should be functionally the same, but is probably an 'unsigned long' vs 'unsigned long long' mismatch.
Perhaps we should just be using __builtin_add_overflow via a macro instead of inlines so that we get the full functionality of the types accepted by the builtin.
r~
Quoted 38 lines · Richard Henderson
Quoted 15 lines · Peter Xu
The following changes since commit
84f07211cc5b4fc6a371559bf8a5de4fb068e648:Update version for v11.1.0 release (2026-08-11 10:04:46 -0400)are available in the Git repository at:
https://gitlab.com/peterx/qemu.git tags/next-pull-request
for you to fetch changes up to
2375e9b1239eb6ad794eaae29245b94f429c87c5:migration: Fix rare hang of migration_channel_read_peek() (2026-08-12 10:42:09 -0400)----------------------------------------------------------------
migration/mem pull for 11.2Quoted 6 lines
next 11.2:
- Dongli's patch to add cpr-transfer support for HMP
- Fabiano's doc update for migration on security issues
- Gavin's fix for MMIO access support for memory APIs, revertingram_deviceops
- Sam's migration test build fix for !ASN1
- Peter's a few migration hardening fixesMacOS build failures:
https://gitlab.com/qemu-project/qemu/-/jobs/15865084063
https://gitlab.com/qemu-project/qemu/-/jobs/15865084064
../migration/ram.c:4291:54: error: incompatible pointer types passing 'ram_addr_t*' (aka 'unsigned long *') to parameter of type 'uint64_t*' (aka 'unsigned long long *') [-Werror,-Wincompatible-pointer-types]
4291 | if (usub64_overflow(total_ram_bytes, length, &total_ram_bytes)) {
| ^~~~~~~~~~~~~~~~
/Users/gitlab/builds/qemu-project/qemu/include/qemu/host-utils.h:552:70:
note: passing argument to parameter 'ret' here
552 | static inline boolusub64_overflow(uint64_t x, uint64_t y, uint64_t *ret)
| ^
Quoted 7 lines
Note that
ram_addr_tmaps touintptr_tnotuint64_t. Which should be functionally the same, but is probably an 'unsigned long' vs 'unsigned long long' mismatch.Perhaps we should just be using
__builtin_add_overflowvia a macro instead of inlines so that we get the full functionality of the types accepted by the builtin.
Ohhh I almost missed this email... somehow it lost all CCs include myself. I'll see how to fix and repost, thanks for the hints!
Signature · 1 line
Peter Xu
Quoted 43 lines · Peter Xu
Quoted 42 lines · Richard Henderson
Quoted 15 lines · Peter Xu
The following changes since commit
84f07211cc5b4fc6a371559bf8a5de4fb068e648:Update version for v11.1.0 release (2026-08-11 10:04:46 -0400)are available in the Git repository at:
https://gitlab.com/peterx/qemu.git tags/next-pull-request
for you to fetch changes up to
2375e9b1239eb6ad794eaae29245b94f429c87c5:migration: Fix rare hang of migration_channel_read_peek() (2026-08-12 10:42:09 -0400)----------------------------------------------------------------
migration/mem pull for 11.2Quoted 6 lines
next 11.2:
- Dongli's patch to add cpr-transfer support for HMP
- Fabiano's doc update for migration on security issues
- Gavin's fix for MMIO access support for memory APIs, revertingram_deviceops
- Sam's migration test build fix for !ASN1
- Peter's a few migration hardening fixesMacOS build failures:
https://gitlab.com/qemu-project/qemu/-/jobs/15865084063
https://gitlab.com/qemu-project/qemu/-/jobs/15865084064
../migration/ram.c:4291:54: error: incompatible pointer types passing 'ram_addr_t*' (aka 'unsigned long *') to parameter of type 'uint64_t*' (aka 'unsigned long long *') [-Werror,-Wincompatible-pointer-types]
4291 | if (usub64_overflow(total_ram_bytes, length, &total_ram_bytes)) {
| ^~~~~~~~~~~~~~~~
/Users/gitlab/builds/qemu-project/qemu/include/qemu/host-utils.h:552:70:
note: passing argument to parameter 'ret' here
552 | static inline boolusub64_overflow(uint64_t x, uint64_t y, uint64_t *ret)
| ^Note that
ram_addr_tmaps touintptr_tnotuint64_t. Which should be functionally the same, but is probably an 'unsigned long' vs 'unsigned long long' mismatch.
Quoted 6 lines
Quoted 3 lines
Perhaps we should just be using
__builtin_add_overflowvia a macro instead of inlines so that we get the full functionality of the types accepted by the builtin.Ohhh I almost missed this email... somehow it lost all CCs include myself. I'll see how to fix and repost, thanks for the hints!
So for this one I plan to squash this (will repost in a minute):
migration/ram.c +2 -2
@@ -4263,7 +4263,7 @@ static int parse_ramblock(QEMUFile *f, RAMBlock *block, ram_addr_t length)return ret; } -static int parse_ramblocks (QEMUFile *f,ram_addr_t total_ram_bytes) +static int parse_ramblocks (QEMUFile *f,uint64_t total_ram_bytes) {int ret =0 ;
@@ -4271,7 +4271,7 @@ static int parse_ramblocks(QEMUFile *f, ram_addr_t total_ram_bytes)while (total_ram_bytes) {RAMBlock *block;char id[256 ]; -ram_addr_t length; +uint64_t length;int len =qemu_get_byte (f);qemu_get_buffer (f, (uint8_t *)id, len);
After all, whole migration treats ram_addr_t to be u64, at least on wire.
For the long term, do we want to fully expose __builtin_add_overflow(), or the new macro would do something more than what __builtin_add_overflow() does?
Now when I think about it from the root, I tend to like what Xen defines with ram_addr_t:
/* address in the RAM (different from a physical address) */ #if defined(CONFIG_XEN_BACKEND)
typedef uint64_t ram_addr_t;
# define RAM_ADDR_MAX UINT64_MAX
# define RAM_ADDR_FMT "%" PRIx64
#else
typedef uintptr_t ram_addr_t;
# define RAM_ADDR_MAX UINTPTR_MAX
# define RAM_ADDR_FMT "%" PRIxPTR
#endif
I don't know how we supported 32bit host emulating anything larger, but logically it's doable, then IIUC uintptr_t won't be enough allocating anything >4G? If emulating 64bits is too much, I still think it seems valid to emulate e.g. PAE 36bits on a 32bit. I didn't check how it was done now or before, but logically it sounds that it should still work.
Meanwhile, we should never directly use a ram_addr_t* to be a pointer - it simply is not, but only the address space qemu uses internally for ramblocks. That also implies to me that this seems to be a bit off.
Thanks,
Signature · 1 line
Peter Xu
Quoted 14 lines · Peter Xu
Now when I think about it from the root, I tend to like what Xen defines with
ram_addr_t:/* address in the RAM (different from a physical address) */ #if
defined(CONFIG_XEN_BACKEND)
typedefuint64_tram_addr_t;
# defineRAM_ADDR_MAXUINT64_MAX
# defineRAM_ADDR_FMT"%" PRIx64
#else
typedefuintptr_tram_addr_t;
# defineRAM_ADDR_MAXUINTPTR_MAX
# defineRAM_ADDR_FMT"%" PRIxPTR
#endif
Quoted 3 lines
I don't know how we supported 32bit host emulating anything larger, but logically it's doable, then IIUC
uintptr_twon't be enough allocating anything >4G?
ram_addr_t != hwaddr or vaddr -- it's just an internal token.
So a 32-bit machine could put 1G of ram (identified by ram_addr_t) at 8G (hwaddr) just fine. But obviously it couldn't put 8G of ram anywhere. :-)
That said, Xen was weird in that it used to be possible to have an i386 qemu command-line talking to a x86_64 dom0 kernel controlling x86_64 guests.
So, yeah, now we should drop this ram_addr_t distinction and always use uint64_t.
r~
Quoted 19 lines · Richard Henderson
Quoted 14 lines · Peter Xu
Now when I think about it from the root, I tend to like what Xen defines with
ram_addr_t:/* address in the RAM (different from a physical address) */ #if
defined(CONFIG_XEN_BACKEND)
typedefuint64_tram_addr_t;
# defineRAM_ADDR_MAXUINT64_MAX
# defineRAM_ADDR_FMT"%" PRIx64
#else
typedefuintptr_tram_addr_t;
# defineRAM_ADDR_MAXUINTPTR_MAX
# defineRAM_ADDR_FMT"%" PRIxPTR
#endifQuoted 3 lines
I don't know how we supported 32bit host emulating anything larger, but logically it's doable, then IIUC
uintptr_twon't be enough allocating anything >4G?
Quoted 7 lines
ram_addr_t!= hwaddr or vaddr -- it's just an internal token.So a 32-bit machine could put 1G of ram (identified by
ram_addr_t) at 8G (hwaddr) just fine. But obviously it couldn't put 8G of ram anywhere. :-)That said, Xen was weird in that it used to be possible to have an i386 qemu command-line talking to a
x86_64dom0 kernel controllingx86_64guests.So, yeah, now we should drop this
ram_addr_tdistinction and always useuint64_t.
🩷🩷🩷 lovely 🩷🩷🩷
Quoted 20 lines · Philippe Mathieu-Daudé
Quoted 19 lines · Richard Henderson
Quoted 17 lines · Peter Xu
Now when I think about it from the root, I tend to like what Xen defines with
ram_addr_t:/* address in the RAM (different from a physical address) */ #if
defined(CONFIG_XEN_BACKEND)
typedefuint64_tram_addr_t;
# defineRAM_ADDR_MAXUINT64_MAX
# defineRAM_ADDR_FMT"%" PRIx64
#else
typedefuintptr_tram_addr_t;
# defineRAM_ADDR_MAXUINTPTR_MAX
# defineRAM_ADDR_FMT"%" PRIxPTR
#endifI don't know how we supported 32bit host emulating anything larger, but logically it's doable, then IIUC
uintptr_twon't be enough allocating anything >4G?
Quoted 5 lines
Quoted 5 lines
ram_addr_t!= hwaddr or vaddr -- it's just an internal token.So a 32-bit machine could put 1G of ram (identified by
ram_addr_t) at 8G (hwaddr) just fine. But obviously it couldn't put 8G of ram anywhere. :-)
Yep, I should have described it as allocating >4G in total, rather in one shot. So it's about the address space we can allocate that is limited..
Quoted 9 lines
Quoted 7 lines
That said, Xen was weird in that it used to be possible to have an i386 qemu command-line talking to a
x86_64dom0 kernel controllingx86_64guests.So, yeah, now we should drop this
ram_addr_tdistinction and always useuint64_t.🩷🩷🩷 lovely 🩷🩷🩷
I can throw a patch, just to double check one last thing: we don't support any form of 32bit hosts anymore, am I right?
Signature · 1 line
Peter Xu
Quoted 35 lines · Peter Xu
Quoted 20 lines · Philippe Mathieu-Daudé
Quoted 19 lines · Richard Henderson
Quoted 17 lines · Peter Xu
Now when I think about it from the root, I tend to like what Xen defines with
ram_addr_t:/* address in the RAM (different from a physical address) */ #if
defined(CONFIG_XEN_BACKEND)
typedefuint64_tram_addr_t;
# defineRAM_ADDR_MAXUINT64_MAX
# defineRAM_ADDR_FMT"%" PRIx64
#else
typedefuintptr_tram_addr_t;
# defineRAM_ADDR_MAXUINTPTR_MAX
# defineRAM_ADDR_FMT"%" PRIxPTR
#endifI don't know how we supported 32bit host emulating anything larger, but logically it's doable, then IIUC
uintptr_twon't be enough allocating anything >4G?Quoted 5 lines
Quoted 5 lines
ram_addr_t!= hwaddr or vaddr -- it's just an internal token.So a 32-bit machine could put 1G of ram (identified by
ram_addr_t) at 8G (hwaddr) just fine. But obviously it couldn't put 8G of ram anywhere. :-)Yep, I should have described it as allocating >4G in total, rather in one shot. So it's about the address space we can allocate that is limited..
Quoted 5 lines
Quoted 5 lines
That said, Xen was weird in that it used to be possible to have an i386 qemu command-line talking to a
x86_64dom0 kernel controllingx86_64guests.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
So, yeah, now we should drop this
ram_addr_tdistinction and always useuint64_t.🩷🩷🩷 lovely 🩷🩷🩷
I can throw a patch, just to double check one last thing: we don't support any form of 32bit hosts anymore, am I right?
commit 372ec46b9f1215f48a4717f2b7ed969f65bfadc6
Author: Richard Henderson <[email protected]> Date: Thu Dec 18 09:56:27 2025 +1100
meson: Reject 32-bit hosts
32-bit hosts have been deprecated since 10.0.
docs/about/removed-features.rst +0 -0
+32-bit host operating systems (removed in 11.0)
+'''''''''''''''''''''''''''''''''''''''''''''''