[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/7] KVM: Notify the state change event during shared/private con
From: |
Chenyi Qiang |
Subject: |
[PATCH 4/7] KVM: Notify the state change event during shared/private conversion |
Date: |
Fri, 13 Dec 2024 15:08:46 +0800 |
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(+)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 52425af534..38f41a98a5 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -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()) {
/*
diff --git a/include/sysemu/guest-memfd-manager.h
b/include/sysemu/guest-memfd-manager.h
index f4b175529b..9dc4e0346d 100644
--- a/include/sysemu/guest-memfd-manager.h
+++ b/include/sysemu/guest-memfd-manager.h
@@ -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
--
2.43.5
- [PATCH 0/7] Enable shared device assignment, Chenyi Qiang, 2024/12/13
- [PATCH 1/7] memory: Export a helper to get intersection of a MemoryRegionSection with a given range, Chenyi Qiang, 2024/12/13
- [PATCH 2/7] guest_memfd: Introduce an object to manage the guest-memfd with RamDiscardManager, Chenyi Qiang, 2024/12/13
- [PATCH 3/7] guest_memfd: Introduce a callback to notify the shared/private state change, Chenyi Qiang, 2024/12/13
- [PATCH 5/7] memory: Register the RamDiscardManager instance upon guest_memfd creation, Chenyi Qiang, 2024/12/13
- [PATCH 4/7] KVM: Notify the state change event during shared/private conversion,
Chenyi Qiang <=
- [PATCH 6/7] RAMBlock: make guest_memfd require coordinate discard, Chenyi Qiang, 2024/12/13
- [RFC PATCH 7/7] memory: Add a new argument to indicate the request attribute in RamDismcardManager helpers, Chenyi Qiang, 2024/12/13