Currently memory attribute conversions are followed up by other bookkeeping tasks like discarding unused memory or issuing iommufd notifications. Move these tasks to a separate post-conversions helper to better compartmentalize and track these tasks, and in doing so lay the groundwork for a pre-conversion helper which will be needed in the future. Signed-off-by: Michael Roth --- accel/kvm/kvm-all.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index bf81a19423..b6a3839055 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -3437,20 +3437,26 @@ static int kvm_convert_section(MemoryRegionSection *section, bool to_private) { hwaddr start = section->offset_within_address_space; hwaddr size = int128_get64(section->size); - MemoryRegion *mr = section->mr; - ram_addr_t offset; - RAMBlock *rb; - void *addr; - int ret = -EINVAL; + int ret; if (to_private) { ret = kvm_set_memory_attributes_private(start, size); } else { ret = kvm_set_memory_attributes_shared(start, size); } - if (ret) { - return ret; - } + + return ret; +} + +static int kvm_post_convert_section(MemoryRegionSection *section, bool to_private) +{ + hwaddr start = section->offset_within_address_space; + hwaddr size = int128_get64(section->size); + MemoryRegion *mr = section->mr; + ram_addr_t offset; + RAMBlock *rb; + void *addr; + int ret; addr = memory_region_get_ram_ptr(mr) + section->offset_within_region; rb = qemu_ram_block_from_host(addr, false, &offset); @@ -3525,6 +3531,12 @@ int kvm_convert_memory(hwaddr start, hwaddr size, bool to_private) } ret = kvm_convert_section(§ion, to_private); + if (ret) { + memory_region_unref(section.mr); + break; + } + + ret = kvm_post_convert_section(§ion, to_private); memory_region_unref(section.mr); if (ret) { -- 2.43.0