[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 21/26] kvm/memory: Make memory type private by default if it has
From: |
Paolo Bonzini |
Subject: |
[PATCH 21/26] kvm/memory: Make memory type private by default if it has guest memfd backend |
Date: |
Fri, 22 Mar 2024 19:11:11 +0100 |
From: Xiaoyao Li <xiaoyao.li@intel.com>
KVM side leaves the memory to shared by default, while 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>
---
accel/kvm/kvm-all.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 7fbaf31cbaf..56b17cbd8aa 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -1430,6 +1430,16 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml,
strerror(-err));
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\n",
+ __func__, strerror(-err));
+ exit(1);
+ }
+ }
+
start_addr += slot_size;
ram_start_offset += slot_size;
ram += slot_size;
--
2.44.0
- [PATCH 16/26] target/i386: SEV: use KVM_SEV_INIT2 if possible, (continued)
- [PATCH 16/26] target/i386: SEV: use KVM_SEV_INIT2 if possible, Paolo Bonzini, 2024/03/22
- [PATCH 17/26] trace/kvm: Split address space and slot id in trace_kvm_set_user_memory(), Paolo Bonzini, 2024/03/22
- [PATCH 20/26] kvm: Enable KVM_SET_USER_MEMORY_REGION2 for memslot, Paolo Bonzini, 2024/03/22
- [PATCH 18/26] kvm: Introduce support for memory_attributes, Paolo Bonzini, 2024/03/22
- [PATCH 19/26] RAMBlock: Add support of KVM private guest memfd, Paolo Bonzini, 2024/03/22
- [PATCH 15/26] target/i386: Implement mc->kvm_type() to get VM type, Paolo Bonzini, 2024/03/22
- [PATCH 21/26] kvm/memory: Make memory type private by default if it has guest memfd backend,
Paolo Bonzini <=
- [PATCH 22/26] HostMem: Add mechanism to opt in kvm guest memfd via MachineState, Paolo Bonzini, 2024/03/22
- [PATCH 23/26] RAMBlock: make guest_memfd require uncoordinated discard, Paolo Bonzini, 2024/03/22
- [PATCH 24/26] physmem: Introduce ram_block_discard_guest_memfd_range(), Paolo Bonzini, 2024/03/22
- [PATCH 25/26] kvm: handle KVM_EXIT_MEMORY_FAULT, Paolo Bonzini, 2024/03/22
- [PATCH 26/26] i386/kvm: Move architectural CPUID leaf generation to separate helper, Paolo Bonzini, 2024/03/22