[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 4/6] memory: Register the RamDiscardManager instance upon gue
From: |
Chenyi Qiang |
Subject: |
[RFC PATCH 4/6] memory: Register the RamDiscardManager instance upon guest_memfd creation |
Date: |
Thu, 25 Jul 2024 03:21:13 -0400 |
Instantiate a new guest_memfd_manager object and register it in the
target MemoryRegion. From this point, other subsystems such as VFIO can
register their listeners in guest_memfd_manager and receive conversion
events through RamDiscardManager.
Signed-off-by: Chenyi Qiang <chenyi.qiang@intel.com>
---
system/physmem.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/system/physmem.c b/system/physmem.c
index 33d09f7571..98072ae246 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -53,6 +53,7 @@
#include "sysemu/hostmem.h"
#include "sysemu/hw_accel.h"
#include "sysemu/xen-mapcache.h"
+#include "sysemu/guest-memfd-manager.h"
#include "trace/trace-root.h"
#ifdef CONFIG_FALLOCATE_PUNCH_HOLE
@@ -1861,6 +1862,12 @@ static void ram_block_add(RAMBlock *new_block, Error
**errp)
qemu_mutex_unlock_ramlist();
goto out_free;
}
+
+ GuestMemfdManager *gmm =
GUEST_MEMFD_MANAGER(object_new(TYPE_GUEST_MEMFD_MANAGER));
+ GuestMemfdManagerClass *gmmc = GUEST_MEMFD_MANAGER_GET_CLASS(gmm);
+ g_assert(new_block->mr);
+ gmmc->realize(OBJECT(gmm), new_block->mr, new_block->mr->size);
+ memory_region_set_ram_discard_manager(gmm->mr,
RAM_DISCARD_MANAGER(gmm));
}
new_ram_size = MAX(old_ram_size,
@@ -2118,6 +2125,8 @@ static void reclaim_ramblock(RAMBlock *block)
if (block->guest_memfd >= 0) {
close(block->guest_memfd);
+ g_assert(block->mr);
+ object_unref(OBJECT(block->mr->rdm));
ram_block_discard_require(false);
}
--
2.43.5
- [RFC PATCH 0/6] Enable shared device assignment, Chenyi Qiang, 2024/07/25
- [RFC PATCH 1/6] guest_memfd: Introduce an object to manage the guest-memfd with RamDiscardManager, Chenyi Qiang, 2024/07/25
- [RFC PATCH 2/6] guest_memfd: Introduce a helper to notify the shared/private state change, Chenyi Qiang, 2024/07/25
- [RFC PATCH 3/6] KVM: Notify the state change via RamDiscardManager helper during shared/private conversion, Chenyi Qiang, 2024/07/25
- [RFC PATCH 4/6] memory: Register the RamDiscardManager instance upon guest_memfd creation,
Chenyi Qiang <=
- [RFC PATCH 5/6] guest-memfd: Default to discarded (private) in guest_memfd_manager, Chenyi Qiang, 2024/07/25
- [RFC PATCH 6/6] RAMBlock: make guest_memfd require coordinate discard, Chenyi Qiang, 2024/07/25
- Re: [RFC PATCH 0/6] Enable shared device assignment, David Hildenbrand, 2024/07/25
- Re: [RFC PATCH 0/6] Enable shared device assignment, Chenyi Qiang, 2024/07/26