@samitouri / QOSamiQemu / commits / 3d56a3c35b

migration/rdma: Drop RDMALocalBlock.is_ram_block

This is guaranteed to be true. There seems to have support for some dynamically allocated buffers but it was never really supported. Remove dead code. As a side effect, this patch closes a report by removing the buggy code completely. Reported-by: Tristan (@TristanInSec) Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4006 Reviewed-by: Jinpu Wang <jinpu.wang@cloud.ionos.com> Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: Fabiano Rosas <farosas@suse.de> Signed-off-by: Fabiano Rosas <farosas@suse.de>

Peter Xu committed Aug 20, 2026 at 16:03 UTC 3d56a3c35b0e91779b488c147c3c27f09f35e665
1 file changed +21 -54
migration/rdma.c
+21 -54
@@ -196,7 +196,6 @@ typedef struct RDMALocalBlock {
196 uint32_t remote_rkey; /* rkeys for non-chunk-level registration */
197 int index; /* which block are we */
198 unsigned int src_index; /* (Only used on dest) */
199 - bool is_ram_block;
199 int nb_chunks;
200 unsigned long *transit_bitmap;
201 unsigned long *unregister_bitmap;
@@ -279,7 +278,6 @@ static void network_to_dest_block(RDMADestBlock *db)
278 */
279 typedef struct RDMALocalBlocks {
280 int nb_blocks;
282 - bool init; /* main memory init complete */
281 RDMALocalBlock *block;
282 } RDMALocalBlocks;
283
@@ -441,14 +439,12 @@ static void register_to_network(RDMAContext *rdma, RDMARegister *reg)
439 RDMALocalBlock *local_block;
440 local_block = &rdma->local_ram_blocks.block[reg->current_index];
441
444 - if (local_block->is_ram_block) {
445 - /*
446 - * current_addr as passed in is an address in the local ram_addr_t
447 - * space, we need to translate this for the destination
448 - */
449 - reg->key.current_addr -= local_block->offset;
450 - reg->key.current_addr += rdma->dest_blocks[reg->current_index].offset;
451 - }
442 + /*
443 + * current_addr as passed in is an address in the local ram_addr_t
444 + * space, we need to translate this for the destination
445 + */
446 + reg->key.current_addr -= local_block->offset;
447 + reg->key.current_addr += rdma->dest_blocks[reg->current_index].offset;
448 reg->key.current_addr = htonll(reg->key.current_addr);
449 reg->current_index = htonl(reg->current_index);
450 reg->chunks = htonll(reg->chunks);
@@ -585,8 +581,6 @@ static void rdma_add_block(RDMAContext *rdma, const char *block_name,
581 bitmap_clear(block->unregister_bitmap, 0, block->nb_chunks);
582 block->remote_keys = g_new0(uint32_t, block->nb_chunks);
583
588 - block->is_ram_block = local->init ? false : true;
589 -
584 if (rdma->blockmap) {
585 g_hash_table_insert(rdma->blockmap, (void *)(uintptr_t)block_offset, block);
586 }
@@ -634,7 +628,6 @@ static void qemu_rdma_init_ram_blocks(RDMAContext *rdma)
628 trace_rdma_init_ram_blocks(local->nb_blocks);
629 rdma->dest_blocks = g_new0(RDMADestBlock,
630 rdma->local_ram_blocks.nb_blocks);
637 - local->init = true;
631 }
632
633 /*
@@ -1767,19 +1760,10 @@ retry:
1760 chunk = ram_chunk_index(block->local_host_addr,
1761 (uint8_t *)(uintptr_t)sge.addr);
1762 chunk_start = ram_chunk_start(block, chunk);
1763 + chunks = length / chunk_size;
1764
1771 - if (block->is_ram_block) {
1772 - chunks = length / chunk_size;
1773 -
1774 - if (chunks && ((length % chunk_size) == 0)) {
1775 - chunks--;
1776 - }
1777 - } else {
1778 - chunks = block->length / chunk_size;
1779 -
1780 - if (chunks && ((block->length % chunk_size) == 0)) {
1781 - chunks--;
1782 - }
1765 + if (chunks && ((length % chunk_size) == 0)) {
1766 + chunks--;
1767 }
1768
1769 trace_rdma_write_one_top(chunks + 1,
@@ -1804,7 +1788,7 @@ retry:
1788 }
1789 }
1790
1807 - if (!rdma->pin_all || !block->is_ram_block) {
1791 + if (!rdma->pin_all) {
1792 if (!block->remote_keys[chunk]) {
1793 /*
1794 * This chunk has not yet been registered, so first check to see
@@ -1853,11 +1837,7 @@ retry:
1837 * Otherwise, tell other side to register.
1838 */
1839 reg.current_index = current_index;
1856 - if (block->is_ram_block) {
1857 - reg.key.current_addr = current_addr;
1858 - } else {
1859 - reg.key.chunk = chunk;
1860 - }
1840 + reg.key.current_addr = current_addr;
1841 reg.chunks = chunks;
1842
1843 trace_rdma_write_one_sendreg(chunk, sge.length, current_index,
@@ -3408,30 +3388,17 @@ int rdma_registration_handle(QEMUFile *f)
3388 goto err;
3389 }
3390 block = &(rdma->local_ram_blocks.block[reg->current_index]);
3411 - if (block->is_ram_block) {
3412 - if (block->offset > reg->key.current_addr) {
3413 - error_report("rdma: bad register address for block %s"
3414 - " offset: %" PRIx64 " current_addr: %" PRIx64,
3415 - block->block_name, block->offset,
3416 - reg->key.current_addr);
3417 - goto err;
3418 - }
3419 - host_addr = (block->local_host_addr +
3420 - (reg->key.current_addr - block->offset));
3421 - chunk = ram_chunk_index(block->local_host_addr,
3422 - (uint8_t *) host_addr);
3423 - } else {
3424 - chunk = reg->key.chunk;
3425 - host_addr = block->local_host_addr +
3426 - (reg->key.chunk * migrate_rdma_chunk_size());
3427 - /* Check for particularly bad chunk value */
3428 - if (host_addr < (void *)block->local_host_addr) {
3429 - error_report("rdma: bad chunk for block %s"
3430 - " chunk: %" PRIx64,
3431 - block->block_name, reg->key.chunk);
3432 - goto err;
3433 - }
3391 + if (block->offset > reg->key.current_addr) {
3392 + error_report("rdma: bad register address for block %s"
3393 + " offset: %" PRIx64 " current_addr: %" PRIx64,
3394 + block->block_name, block->offset,
3395 + reg->key.current_addr);
3396 + goto err;
3397 }
3398 + host_addr = (block->local_host_addr +
3399 + (reg->key.current_addr - block->offset));
3400 + chunk = ram_chunk_index(block->local_host_addr,
3401 + (uint8_t *) host_addr);
3402 chunk_start = ram_chunk_start(block, chunk);
3403 chunk_end = ram_chunk_end(block, chunk + reg->chunks);
3404 /* avoid "-Waddress-of-packed-member" warning */