diff mbox series

[RFC,1/1] kvm/kvm-all.c: implement KVM_SET_USER_MEMORY_REGION_LIST ioctl

Message ID 20220909110034.740282-2-eesposit@redhat.com (mailing list archive)
State New, archived
Headers show
Series accel/kvm: implement KVM_SET_USER_MEMORY_REGION_LIST | expand

Commit Message

Emanuele Giuseppe Esposito Sept. 9, 2022, 11 a.m. UTC
Instead of sending memslot updates in each callback, kvm listener
already takes care of sending them in the commit phase, as multiple
ioctls.

Using the new KVM_SET_USER_MEMORY_REGION_LIST, we just need a single
call containing all memory regions to update.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
 accel/kvm/kvm-all.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 9780f3d2da..6a7f7b4567 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -1547,30 +1547,25 @@  static void kvm_commit(MemoryListener *listener)
     KVMMemoryListener *kml = container_of(listener, KVMMemoryListener,
                                           listener);
     KVMState *s = kvm_state;
-    int i;
+    int i, ret;
 
     for (i = 0; i < kml->mem_array.list->nent; i++) {
         struct kvm_userspace_memory_region_entry *mem;
-        int ret;
 
         mem = &kml->mem_array.list->entries[i];
 
-        /*
-         * Note that mem is struct kvm_userspace_memory_region_entry, while the
-         * kernel expects a kvm_userspace_memory_region, so it will currently
-         * ignore mem->invalidate_slot and mem->padding.
-         */
-        ret = kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, mem);
-
         trace_kvm_set_user_memory(mem->slot, mem->flags, mem->guest_phys_addr,
                                   mem->memory_size, mem->userspace_addr, 0);
+    }
 
-        if (ret < 0) {
-            error_report("%s: KVM_SET_USER_MEMORY_REGION failed, slot=%d,"
-                         " start=0x%" PRIx64 ": %s",
-                         __func__, mem->slot,
-                         (uint64_t)mem->memory_size, strerror(errno));
-        }
+    ret = kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION_LIST, kml->mem_array.list);
+
+    if (ret < 0) {
+        error_report("%s: KVM_SET_USER_MEMORY_REGION_LIST failed, size=0x%"
+                     PRIx64 " flags=0x%" PRIx64 ": %s",
+                     __func__, (uint64_t)kml->mem_array.list->nent,
+                     (uint64_t)kml->mem_array.list->flags,
+                     strerror(errno));
     }
 
     kml->mem_array.list->nent = 0;