[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v7 41/52] i386/tdx: Implement adjust_cpuid_features() for TDX
From: |
Xiaoyao Li |
Subject: |
[PATCH v7 41/52] i386/tdx: Implement adjust_cpuid_features() for TDX |
Date: |
Fri, 24 Jan 2025 08:20:37 -0500 |
1. QEMU's support for Intel PT is borken in general, thus doesn't
support for TDX.
2. Only limited KVM PV features are supported for TD guest.
3. Drop the AMD specific bits that are reserved on Intel platform.
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
target/i386/kvm/tdx.c | 44 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c
index dcbbe350ec91..9bdb9d795952 100644
--- a/target/i386/kvm/tdx.c
+++ b/target/i386/kvm/tdx.c
@@ -30,6 +30,8 @@
#include "kvm_i386.h"
#include "tdx.h"
+#include "standard-headers/asm-x86/kvm_para.h"
+
#define TDX_MIN_TSC_FREQUENCY_KHZ (100 * 1000)
#define TDX_MAX_TSC_FREQUENCY_KHZ (10 * 1000 * 1000)
@@ -42,6 +44,14 @@
TDX_TD_ATTRIBUTES_PKS | \
TDX_TD_ATTRIBUTES_PERFMON)
+#define TDX_SUPPORTED_KVM_FEATURES ((1U << KVM_FEATURE_NOP_IO_DELAY) | \
+ (1U << KVM_FEATURE_PV_UNHALT) | \
+ (1U << KVM_FEATURE_PV_TLB_FLUSH) | \
+ (1U << KVM_FEATURE_PV_SEND_IPI) | \
+ (1U << KVM_FEATURE_POLL_CONTROL) | \
+ (1U << KVM_FEATURE_PV_SCHED_YIELD) | \
+ (1U << KVM_FEATURE_MSI_EXT_DEST_ID))
+
static TdxGuest *tdx_guest;
static struct kvm_tdx_capabilities *tdx_caps;
@@ -430,6 +440,39 @@ static void tdx_cpu_instance_init(X86ConfidentialGuest
*cg, CPUState *cpu)
x86cpu->enable_cpuid_0x1f = true;
}
+static uint32_t tdx_adjust_cpuid_features(X86ConfidentialGuest *cg,
+ uint32_t feature, uint32_t index,
+ int reg, uint32_t value)
+{
+ switch (feature) {
+ case 0x7:
+ if (index == 0 && reg == R_EBX) {
+ /* QEMU Intel PT support is broken */
+ value &= ~CPUID_7_0_EBX_INTEL_PT;
+ }
+ break;
+ case 0x40000001:
+ if (reg == R_EAX) {
+ value &= TDX_SUPPORTED_KVM_FEATURES;
+ }
+ break;
+ case 0x80000001:
+ if (reg == R_EDX) {
+ value &= ~CPUID_EXT2_AMD_ALIASES;
+ }
+ break;
+ case 0x80000008:
+ if (reg == R_EBX) {
+ value &= CPUID_8000_0008_EBX_WBNOINVD;
+ }
+ break;
+ default:
+ break;
+ }
+
+ return value;
+}
+
static int tdx_validate_attributes(TdxGuest *tdx, Error **errp)
{
if ((tdx->attributes & ~tdx_caps->supported_attrs)) {
@@ -789,4 +832,5 @@ static void tdx_guest_class_init(ObjectClass *oc, void
*data)
klass->kvm_init = tdx_kvm_init;
x86_klass->kvm_type = tdx_kvm_type;
x86_klass->cpu_instance_init = tdx_cpu_instance_init;
+ x86_klass->adjust_cpuid_features = tdx_adjust_cpuid_features;
}
--
2.34.1
- [PATCH v7 36/52] i386/tdx: Don't synchronize guest tsc for TDs, (continued)
- [PATCH v7 36/52] i386/tdx: Don't synchronize guest tsc for TDs, Xiaoyao Li, 2025/01/24
- [PATCH v7 37/52] i386/tdx: Only configure MSR_IA32_UCODE_REV in kvm_init_msrs() for TDs, Xiaoyao Li, 2025/01/24
- [PATCH v7 38/52] i386/apic: Skip kvm_apic_put() for TDX, Xiaoyao Li, 2025/01/24
- [PATCH v7 25/52] i386/tdx: Finalize TDX VM, Xiaoyao Li, 2025/01/24
- [PATCH v7 28/52] i386/tdx: Wire TDX_REPORT_FATAL_ERROR with GuestPanic facility, Xiaoyao Li, 2025/01/24
- [PATCH v7 27/52] i386/tdx: Handle KVM_SYSTEM_EVENT_TDX_FATAL, Xiaoyao Li, 2025/01/24
- [PATCH v7 32/52] i386/tdx: Force exposing CPUID 0x1f, Xiaoyao Li, 2025/01/24
- [PATCH v7 34/52] i386/tdx: Disable SMM for TDX VMs, Xiaoyao Li, 2025/01/24
- [PATCH v7 39/52] cpu: Don't set vcpu_dirty when guest_state_protected, Xiaoyao Li, 2025/01/24
- [PATCH v7 42/52] i386/tdx: Apply TDX fixed0 and fixed1 information to supported CPUIDs, Xiaoyao Li, 2025/01/24
- [PATCH v7 41/52] i386/tdx: Implement adjust_cpuid_features() for TDX,
Xiaoyao Li <=
- [PATCH v7 49/52] i386/tdx: Don't treat SYSCALL as unavailable, Xiaoyao Li, 2025/01/24
- [PATCH v7 43/52] i386/tdx: Mask off CPUID bits by unsupported TD Attributes, Xiaoyao Li, 2025/01/24
- [PATCH v7 44/52] i386/cpu: Move CPUID_XSTATE_XSS_MASK to header file and introduce CPUID_XSTATE_MASK, Xiaoyao Li, 2025/01/24
- [PATCH v7 46/52] i386/tdx: Mark the configurable bit not reported by KVM as unsupported, Xiaoyao Li, 2025/01/24
- [PATCH v7 40/52] i386/cgs: Rename *mask_cpuid_features() to *adjust_cpuid_features(), Xiaoyao Li, 2025/01/24
- [PATCH v7 45/52] i386/tdx: Mask off CPUID bits by unsupported XFAM, Xiaoyao Li, 2025/01/24
- [PATCH v7 47/52] i386/cgs: Introduce x86_confidential_guest_check_features(), Xiaoyao Li, 2025/01/24
- [PATCH v7 50/52] i386/tdx: Make invtsc default on, Xiaoyao Li, 2025/01/24
- [PATCH v7 51/52] i386/tdx: Validate phys_bits against host value, Xiaoyao Li, 2025/01/24