@@ -48,6 +48,7 @@
#include "kvm-cpus.h"
#include "sysemu/dirtylimit.h"
#include "qemu/range.h"
+#include "sysemu/guest-memfd-manager.h"
#include "hw/boards.h"
#include "sysemu/stats.h"
@@ -3080,6 +3081,9 @@ 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);
+ guest_memfd_manager_state_change(GUEST_MEMFD_MANAGER(mr->rdm), offset,
+ size, to_private);
+
if (to_private) {
if (rb->page_size != qemu_real_host_page_size()) {
/*
@@ -46,4 +46,19 @@ struct GuestMemfdManagerClass {
bool shared_to_private);
};
+static inline int guest_memfd_manager_state_change(GuestMemfdManager *gmm, uint64_t offset,
+ uint64_t size, bool shared_to_private)
+{
+ GuestMemfdManagerClass *klass;
+
+ g_assert(gmm);
+ klass = GUEST_MEMFD_MANAGER_GET_CLASS(gmm);
+
+ if (klass->state_change) {
+ return klass->state_change(gmm, offset, size, shared_to_private);
+ }
+
+ return 0;
+}
+
#endif
Introduce a helper to trigger the state_change() callback of the class. Once exit to userspace to convert the page from private to shared or vice versa at runtime, notify the event via the helper so that other registered subsystems like VFIO can be notified. Signed-off-by: Chenyi Qiang <chenyi.qiang@intel.com> --- accel/kvm/kvm-all.c | 4 ++++ include/sysemu/guest-memfd-manager.h | 15 +++++++++++++++ 2 files changed, 19 insertions(+)