[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v2 12/21] kvm/memory: Introduce the infrastructure to set the
From: |
Xiaoyao Li |
Subject: |
[RFC PATCH v2 12/21] kvm/memory: Introduce the infrastructure to set the default shared/private value |
Date: |
Wed, 13 Sep 2023 23:51:08 -0400 |
Introduce new flag RAM_DEFAULT_PRIVATE for RAMBlock. It's used to
indicate the default attribute, private or not.
Set the RAM range to private explicitly when it's default private.
Originated-from: Isaku Yamahata <isaku.yamahata@intel.com>
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
accel/kvm/kvm-all.c | 10 ++++++++++
include/exec/memory.h | 6 ++++++
softmmu/memory.c | 13 +++++++++++++
3 files changed, 29 insertions(+)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index eeccc6317fa9..7e32ee83b258 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -1487,6 +1487,16 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml,
strerror(-err));
abort();
}
+
+ if (memory_region_is_default_private(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;
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 4b8486ca3632..2c738b5dc420 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -238,6 +238,9 @@ typedef struct IOMMUTLBEvent {
/* RAM can be private that has kvm gmem backend */
#define RAM_KVM_GMEM (1 << 10)
+/* RAM is default private */
+#define RAM_DEFAULT_PRIVATE (1 << 11)
+
static inline void iommu_notifier_init(IOMMUNotifier *n, IOMMUNotify fn,
IOMMUNotifierFlag flags,
hwaddr start, hwaddr end,
@@ -1684,6 +1687,9 @@ bool memory_region_is_protected(MemoryRegion *mr);
*/
bool memory_region_has_gmem_fd(MemoryRegion *mr);
+void memory_region_set_default_private(MemoryRegion *mr);
+bool memory_region_is_default_private(MemoryRegion *mr);
+
/**
* memory_region_get_iommu: check whether a memory region is an iommu
*
diff --git a/softmmu/memory.c b/softmmu/memory.c
index e69a5f96d5d1..dc5d0d7703b5 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -1851,6 +1851,19 @@ bool memory_region_has_gmem_fd(MemoryRegion *mr)
return mr->ram_block && mr->ram_block->gmem_fd >= 0;
}
+bool memory_region_is_default_private(MemoryRegion *mr)
+{
+ return memory_region_has_gmem_fd(mr) &&
+ (mr->ram_block->flags & RAM_DEFAULT_PRIVATE);
+}
+
+void memory_region_set_default_private(MemoryRegion *mr)
+{
+ if (memory_region_has_gmem_fd(mr)) {
+ mr->ram_block->flags |= RAM_DEFAULT_PRIVATE;
+ }
+}
+
uint8_t memory_region_get_dirty_log_mask(MemoryRegion *mr)
{
uint8_t mask = mr->dirty_log_mask;
--
2.34.1
- [RFC PATCH v2 02/21] RAMBlock: Add support of KVM private gmem, (continued)
- [RFC PATCH v2 02/21] RAMBlock: Add support of KVM private gmem, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 03/21] HostMem: Add private property and associate it with RAM_KVM_GMEM, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 04/21] memory: Introduce memory_region_has_gmem_fd(), Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 05/21] kvm: Enable KVM_SET_USER_MEMORY_REGION2 for memslot, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 06/21] i386: Add support for sw-protected-vm object, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 07/21] i386/pc: Drop pc_machine_kvm_type(), Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 08/21] target/i386: Implement mc->kvm_type() to get VM type, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 09/21] target/i386: Introduce kvm_confidential_guest_init(), Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 10/21] i386/kvm: Implement kvm_sw_protected_vm_init() for sw-protcted-vm specific functions, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 11/21] kvm: Introduce support for memory_attributes, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 12/21] kvm/memory: Introduce the infrastructure to set the default shared/private value,
Xiaoyao Li <=
- [RFC PATCH v2 13/21] i386/kvm: Set memory to default private for KVM_X86_SW_PROTECTED_VM, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 14/21] physmem: replace function name with __func__ in ram_block_discard_range(), Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 15/21] physmem: extract ram_block_discard_range_fd() from ram_block_discard_range(), Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 17/21] kvm: handle KVM_EXIT_MEMORY_FAULT, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 16/21] physmem: Introduce ram_block_convert_range(), Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 18/21] trace/kvm: Add trace for page convertion between shared and private, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 19/21] pci-host/q35: Move PAM initialization above SMRAM initialization, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 20/21] q35: Introduce smm_ranges property for q35-pci-host, Xiaoyao Li, 2023/09/13
- [RFC PATCH v2 21/21] i386: Disable SMM mode for X86_SW_PROTECTED_VM, Xiaoyao Li, 2023/09/13
- Re: [RFC PATCH v2 00/21] QEMU gmem implemention, David Hildenbrand, 2023/09/14