diff options
| author | Chenyi Qiang <chenyi.qiang@intel.com> | 2025-06-12 16:27:46 +0800 |
|---|---|---|
| committer | Peter Xu <peterx@redhat.com> | 2025-06-23 16:03:59 -0400 |
| commit | 2fde3fb916079ee0ff0fc26d9446c813b1d5cc28 (patch) | |
| tree | 27ffec7704fa6ab01c8b84de5b705d65855274af /accel/kvm/kvm-all.c | |
| parent | 5d6483edaa9232d8f3709f68c8eab4bc2033fb70 (diff) | |
| download | focaccia-qemu-2fde3fb916079ee0ff0fc26d9446c813b1d5cc28.tar.gz focaccia-qemu-2fde3fb916079ee0ff0fc26d9446c813b1d5cc28.zip | |
physmem: Support coordinated discarding of RAM with guest_memfd
A new field, attributes, was introduced in RAMBlock to link to a RamBlockAttributes object, which centralizes all guest_memfd related information (such as fd and status bitmap) within a RAMBlock. Create and initialize the RamBlockAttributes object upon ram_block_add(). Meanwhile, register the object in the target RAMBlock's MemoryRegion. After that, guest_memfd-backed RAMBlock is associated with the RamDiscardManager interface, and the users can execute RamDiscardManager specific handling. For example, VFIO will register the RamDiscardListener and get notifications when the state_change() helper invokes. As coordinate discarding of RAM with guest_memfd is now supported, only block uncoordinated discard. Tested-by: Alexey Kardashevskiy <aik@amd.com> Reviewed-by: Alexey Kardashevskiy <aik@amd.com> Acked-by: David Hildenbrand <david@redhat.com> Signed-off-by: Chenyi Qiang <chenyi.qiang@intel.com> Link: https://lore.kernel.org/r/20250612082747.51539-6-chenyi.qiang@intel.com Signed-off-by: Peter Xu <peterx@redhat.com>
Diffstat (limited to 'accel/kvm/kvm-all.c')
| -rw-r--r-- | accel/kvm/kvm-all.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index a31778341c..d095d1b98f 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -3091,6 +3091,15 @@ int kvm_convert_memory(hwaddr start, hwaddr size, bool to_private) addr = memory_region_get_ram_ptr(mr) + section.offset_within_region; rb = qemu_ram_block_from_host(addr, false, &offset); + ret = ram_block_attributes_state_change(RAM_BLOCK_ATTRIBUTES(mr->rdm), + offset, size, to_private); + if (ret) { + error_report("Failed to notify the listener the state change of " + "(0x%"HWADDR_PRIx" + 0x%"HWADDR_PRIx") to %s", + start, size, to_private ? "private" : "shared"); + goto out_unref; + } + if (to_private) { if (rb->page_size != qemu_real_host_page_size()) { /* |