[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v1 11/12] virtio-mem: Set the RamDiscardManager for the RAM memor
From: |
David Hildenbrand |
Subject: |
[PATCH v1 11/12] virtio-mem: Set the RamDiscardManager for the RAM memory region earlier |
Date: |
Wed, 27 Oct 2021 14:45:30 +0200 |
Let's set the RamDiscardManager earlier, logically before we expose the
RAM memory region to the system. This is a preparation for further changes
and is logically cleaner: before we expose the RAM memory region to
migration code, make sure we have the RamDiscardManager setup.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
hw/virtio/virtio-mem.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c
index 0f5eae4a7e..1e29706798 100644
--- a/hw/virtio/virtio-mem.c
+++ b/hw/virtio/virtio-mem.c
@@ -773,16 +773,17 @@ static void virtio_mem_device_realize(DeviceState *dev,
Error **errp)
sizeof(struct virtio_mem_config));
vmem->vq = virtio_add_queue(vdev, 128, virtio_mem_handle_request);
- host_memory_backend_set_mapped(vmem->memdev, true);
- vmstate_register_ram(&vmem->memdev->mr, DEVICE(vmem));
- qemu_register_reset(virtio_mem_system_reset, vmem);
-
/*
- * Set ourselves as RamDiscardManager before the plug handler maps the
- * memory region and exposes it via an address space.
+ * Set ourselves as RamDiscardManager before we expose the memory region
+ * to the system (e.g., marking the RAMBlock migratable, mapping the
+ * region).
*/
memory_region_set_ram_discard_manager(&vmem->memdev->mr,
RAM_DISCARD_MANAGER(vmem));
+
+ host_memory_backend_set_mapped(vmem->memdev, true);
+ vmstate_register_ram(&vmem->memdev->mr, DEVICE(vmem));
+ qemu_register_reset(virtio_mem_system_reset, vmem);
}
static void virtio_mem_device_unrealize(DeviceState *dev)
@@ -790,14 +791,10 @@ static void virtio_mem_device_unrealize(DeviceState *dev)
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
VirtIOMEM *vmem = VIRTIO_MEM(dev);
- /*
- * The unplug handler unmapped the memory region, it cannot be
- * found via an address space anymore. Unset ourselves.
- */
- memory_region_set_ram_discard_manager(&vmem->memdev->mr, NULL);
qemu_unregister_reset(virtio_mem_system_reset, vmem);
vmstate_unregister_ram(&vmem->memdev->mr, DEVICE(vmem));
host_memory_backend_set_mapped(vmem->memdev, false);
+ memory_region_set_ram_discard_manager(&vmem->memdev->mr, NULL);
virtio_del_queue(vdev, 0);
virtio_cleanup(vdev);
g_free(vmem->bitmap);
--
2.31.1
- [PATCH v1 00/12] virtio-mem: Expose device memory via multiple memslots, David Hildenbrand, 2021/10/27
- [PATCH v1 01/12] kvm: Return number of free memslots, David Hildenbrand, 2021/10/27
- [PATCH v1 04/12] vhost: Don't merge unmergeable memory sections, David Hildenbrand, 2021/10/27
- [PATCH v1 03/12] memory: Allow for marking memory region aliases unmergeable, David Hildenbrand, 2021/10/27
- [PATCH v1 02/12] vhost: Return number of free memslots, David Hildenbrand, 2021/10/27
- [PATCH v1 05/12] memory-device: Move memory_device_check_addable() directly into memory_device_pre_plug(), David Hildenbrand, 2021/10/27
- [PATCH v1 06/12] memory-device: Generalize memory_device_used_region_size(), David Hildenbrand, 2021/10/27
- [PATCH v1 08/12] vhost: Respect reserved memslots for memory devices when realizing a vhost device, David Hildenbrand, 2021/10/27
- [PATCH v1 07/12] memory-device: Support memory devices that dynamically consume multiple memslots, David Hildenbrand, 2021/10/27
- [PATCH v1 10/12] virtio-mem: Fix typo in virito_mem_intersect_memory_section() function name, David Hildenbrand, 2021/10/27
- [PATCH v1 11/12] virtio-mem: Set the RamDiscardManager for the RAM memory region earlier,
David Hildenbrand <=
- [PATCH v1 12/12] virtio-mem: Expose device memory via multiple memslots, David Hildenbrand, 2021/10/27
- [PATCH v1 09/12] memory: Drop mapping check from memory_region_get_ram_discard_manager(), David Hildenbrand, 2021/10/27