[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 34/70] kvm/memory: Introduce the infrastructure to set the def
|
From: |
Xiaoyao Li |
|
Subject: |
[PATCH v3 34/70] kvm/memory: Introduce the infrastructure to set the default shared/private value |
|
Date: |
Wed, 15 Nov 2023 02:14:43 -0500 |
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 ++++++
system/memory.c | 13 +++++++++++++
3 files changed, 29 insertions(+)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index a92fff471b58..316690d113d0 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -1467,6 +1467,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 f780367ab1bd..bdc4b98efe70 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -246,6 +246,9 @@ typedef struct IOMMUTLBEvent {
/* RAM can be private that has kvm gmem backend */
#define RAM_GUEST_MEMFD (1 << 12)
+/* RAM is default private */
+#define RAM_DEFAULT_PRIVATE (1 << 13)
+
static inline void iommu_notifier_init(IOMMUNotifier *n, IOMMUNotify fn,
IOMMUNotifierFlag flags,
hwaddr start, hwaddr end,
@@ -1715,6 +1718,9 @@ bool memory_region_is_protected(MemoryRegion *mr);
*/
bool memory_region_has_guest_memfd(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/system/memory.c b/system/memory.c
index 69741d91bbb7..b0c58232b6f7 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -1867,6 +1867,19 @@ bool memory_region_has_guest_memfd(MemoryRegion *mr)
return mr->ram_block && mr->ram_block->guest_memfd >= 0;
}
+bool memory_region_is_default_private(MemoryRegion *mr)
+{
+ return memory_region_has_guest_memfd(mr) &&
+ (mr->ram_block->flags & RAM_DEFAULT_PRIVATE);
+}
+
+void memory_region_set_default_private(MemoryRegion *mr)
+{
+ if (memory_region_has_guest_memfd(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
- [PATCH v3 24/70] i386/kvm: Move architectural CPUID leaf generation to separate helper, (continued)
- [PATCH v3 24/70] i386/kvm: Move architectural CPUID leaf generation to separate helper, Xiaoyao Li, 2023/11/15
- [PATCH v3 25/70] kvm: Introduce kvm_arch_pre_create_vcpu(), Xiaoyao Li, 2023/11/15
- [PATCH v3 26/70] i386/tdx: Initialize TDX before creating TD vcpus, Xiaoyao Li, 2023/11/15
- [PATCH v3 27/70] i386/tdx: Add property sept-ve-disable for tdx-guest object, Xiaoyao Li, 2023/11/15
- [PATCH v3 28/70] i386/tdx: Make sept_ve_disable set by default, Xiaoyao Li, 2023/11/15
- [PATCH v3 29/70] i386/tdx: Wire CPU features up with attributes of TD guest, Xiaoyao Li, 2023/11/15
- [PATCH v3 30/70] i386/tdx: Validate TD attributes, Xiaoyao Li, 2023/11/15
- [PATCH v3 31/70] i386/tdx: Allows mrconfigid/mrowner/mrownerconfig for TDX_INIT_VM, Xiaoyao Li, 2023/11/15
- [PATCH v3 32/70] i386/tdx: Implement user specified tsc frequency, Xiaoyao Li, 2023/11/15
- [PATCH v3 33/70] i386/tdx: Set kvm_readonly_mem_enabled to false for TDX VM, Xiaoyao Li, 2023/11/15
- [PATCH v3 34/70] kvm/memory: Introduce the infrastructure to set the default shared/private value,
Xiaoyao Li <=
- [PATCH v3 35/70] i386/tdx: Make memory type private by default, Xiaoyao Li, 2023/11/15
- [PATCH v3 36/70] kvm/tdx: Don't complain when converting vMMIO region to shared, Xiaoyao Li, 2023/11/15
- [PATCH v3 37/70] kvm/tdx: Ignore memory conversion to shared of unassigned region, Xiaoyao Li, 2023/11/15
- [PATCH v3 38/70] i386/tdvf: Introduce function to parse TDVF metadata, Xiaoyao Li, 2023/11/15
- [PATCH v3 39/70] i386/tdx: Parse TDVF metadata for TDX VM, Xiaoyao Li, 2023/11/15
- [PATCH v3 40/70] i386/tdx: Skip BIOS shadowing setup, Xiaoyao Li, 2023/11/15
- [PATCH v3 41/70] i386/tdx: Don't initialize pc.rom for TDX VMs, Xiaoyao Li, 2023/11/15
- [PATCH v3 42/70] i386/tdx: Track mem_ptr for each firmware entry of TDVF, Xiaoyao Li, 2023/11/15
- [PATCH v3 43/70] i386/tdx: Track RAM entries for TDX VM, Xiaoyao Li, 2023/11/15
- [PATCH v3 44/70] headers: Add definitions from UEFI spec for volumes, resources, etc..., Xiaoyao Li, 2023/11/15