Quellcode durchsuchen

kvm/memory: Make memory type private by default if it has guest memfd backend

KVM side leaves the memory to shared by default, which may incur the
overhead of paging conversion on the first visit of each page. Because
the expectation is that page is likely to private for the VMs that
require private memory (has guest memfd).

Explicitly set the memory to private when memory region has valid
guest memfd backend.

Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Signed-off-by: Michael Roth <michael.roth@amd.com>
Message-ID: <20240320083945.991426-16-michael.roth@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Xiaoyao Li vor 1 Jahr
Ursprung
Commit
bd3bcf6962
1 geänderte Dateien mit 10 neuen und 0 gelöschten Zeilen
  1. 10 0
      accel/kvm/kvm-all.c

+ 10 - 0
accel/kvm/kvm-all.c

@@ -1431,6 +1431,16 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml,
                     strerror(-err));
                     strerror(-err));
             abort();
             abort();
         }
         }
+
+        if (memory_region_has_guest_memfd(mr)) {
+            err = kvm_set_memory_attributes_private(start_addr, slot_size);
+            if (err) {
+                error_report("%s: failed to set memory attribute private: %s",
+                             __func__, strerror(-err));
+                exit(1);
+            }
+        }
+
         start_addr += slot_size;
         start_addr += slot_size;
         ram_start_offset += slot_size;
         ram_start_offset += slot_size;
         ram += slot_size;
         ram += slot_size;