[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 33/66] i386/tdx: Make memory type private by default
From: |
Xiaoyao Li |
Subject: |
[PATCH v4 33/66] i386/tdx: Make memory type private by default |
Date: |
Wed, 24 Jan 2024 22:22:55 -0500 |
By default (due to the recent UPM change), restricted memory attribute is
shared. Convert the memory region from shared to private at the memory
slot creation time.
add kvm region registering function to check the flag
and convert the region, and add memory listener to TDX guest code to set
the flag to the possible memory region.
Without this patch
- Secure-EPT violation on private area
- KVM_MEMORY_FAULT EXIT (kvm -> qemu)
- qemu converts the 4K page from shared to private
- Resume VCPU execution
- Secure-EPT violation again
- KVM resolves EPT Violation
This also prevents huge page because page conversion is done at 4K
granularity. Although it's possible to merge 4K private mapping into
2M large page, it slows guest boot.
With this patch
- After memory slot creation, convert the region from private to shared
- Secure-EPT violation on private area.
- KVM resolves EPT Violation
Originated-from: Isaku Yamahata <isaku.yamahata@intel.com>
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
include/exec/memory.h | 1 +
target/i386/kvm/tdx.c | 20 ++++++++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 7229fcc0415f..f25959f6d30f 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -850,6 +850,7 @@ struct IOMMUMemoryRegion {
#define MEMORY_LISTENER_PRIORITY_MIN 0
#define MEMORY_LISTENER_PRIORITY_ACCEL 10
#define MEMORY_LISTENER_PRIORITY_DEV_BACKEND 10
+#define MEMORY_LISTENER_PRIORITY_ACCEL_HIGH 20
/**
* struct MemoryListener: callbacks structure for updates to the physical
memory map
diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c
index 7b250d80bc1d..f892551821ce 100644
--- a/target/i386/kvm/tdx.c
+++ b/target/i386/kvm/tdx.c
@@ -19,6 +19,7 @@
#include "standard-headers/asm-x86/kvm_para.h"
#include "sysemu/kvm.h"
#include "sysemu/sysemu.h"
+#include "exec/address-spaces.h"
#include "hw/i386/x86.h"
#include "kvm_i386.h"
@@ -621,6 +622,19 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp)
return 0;
}
+static void tdx_guest_region_add(MemoryListener *listener,
+ MemoryRegionSection *section)
+{
+ memory_region_set_default_private(section->mr);
+}
+
+static MemoryListener tdx_memory_listener = {
+ .name = TYPE_TDX_GUEST,
+ .region_add = tdx_guest_region_add,
+ /* Higher than KVM memory listener = 10. */
+ .priority = MEMORY_LISTENER_PRIORITY_ACCEL_HIGH,
+};
+
static bool tdx_guest_get_sept_ve_disable(Object *obj, Error **errp)
{
TdxGuest *tdx = TDX_GUEST(obj);
@@ -695,6 +709,12 @@ OBJECT_DEFINE_TYPE_WITH_INTERFACES(TdxGuest,
static void tdx_guest_init(Object *obj)
{
TdxGuest *tdx = TDX_GUEST(obj);
+ static bool memory_listener_registered = false;
+
+ if (!memory_listener_registered) {
+ memory_listener_register(&tdx_memory_listener, &address_space_memory);
+ memory_listener_registered = true;
+ }
qemu_mutex_init(&tdx->lock);
--
2.34.1
- [PATCH v4 24/66] i386/tdx: Initialize TDX before creating TD vcpus, (continued)
- [PATCH v4 24/66] i386/tdx: Initialize TDX before creating TD vcpus, Xiaoyao Li, 2024/01/24
- [PATCH v4 25/66] i386/tdx: Add property sept-ve-disable for tdx-guest object, Xiaoyao Li, 2024/01/24
- [PATCH v4 27/66] i386/tdx: Wire CPU features up with attributes of TD guest, Xiaoyao Li, 2024/01/24
- [PATCH v4 28/66] i386/tdx: Validate TD attributes, Xiaoyao Li, 2024/01/24
- [PATCH v4 26/66] i386/tdx: Make sept_ve_disable set by default, Xiaoyao Li, 2024/01/24
- [PATCH v4 29/66] i386/tdx: Support user configurable mrconfigid/mrowner/mrownerconfig, Xiaoyao Li, 2024/01/24
- [PATCH v4 30/66] i386/tdx: Implement user specified tsc frequency, Xiaoyao Li, 2024/01/24
- [PATCH v4 31/66] i386/tdx: Set kvm_readonly_mem_enabled to false for TDX VM, Xiaoyao Li, 2024/01/24
- [PATCH v4 32/66] kvm/memory: Introduce the infrastructure to set the default shared/private value, Xiaoyao Li, 2024/01/24
- [PATCH v4 34/66] kvm/tdx: Don't complain when converting vMMIO region to shared, Xiaoyao Li, 2024/01/24
- [PATCH v4 33/66] i386/tdx: Make memory type private by default,
Xiaoyao Li <=
- [PATCH v4 36/66] i386/tdvf: Introduce function to parse TDVF metadata, Xiaoyao Li, 2024/01/24
- [PATCH v4 35/66] kvm/tdx: Ignore memory conversion to shared of unassigned region, Xiaoyao Li, 2024/01/24
- [PATCH v4 37/66] i386/tdx: Parse TDVF metadata for TDX VM, Xiaoyao Li, 2024/01/24
- [PATCH v4 38/66] i386/tdx: Skip BIOS shadowing setup, Xiaoyao Li, 2024/01/24
- [PATCH v4 39/66] i386/tdx: Don't initialize pc.rom for TDX VMs, Xiaoyao Li, 2024/01/24
- [PATCH v4 40/66] i386/tdx: Track mem_ptr for each firmware entry of TDVF, Xiaoyao Li, 2024/01/24
- [PATCH v4 42/66] headers: Add definitions from UEFI spec for volumes, resources, etc..., Xiaoyao Li, 2024/01/24
- [PATCH v4 41/66] i386/tdx: Track RAM entries for TDX VM, Xiaoyao Li, 2024/01/24