[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v2 11/44] i386/tdx: Implement user specified tsc frequency
From: |
isaku . yamahata |
Subject: |
[RFC PATCH v2 11/44] i386/tdx: Implement user specified tsc frequency |
Date: |
Wed, 7 Jul 2021 17:54:41 -0700 |
From: Xiaoyao Li <xiaoyao.li@intel.com>
Reuse -cpu,tsc-frequency= to get user wanted tsc frequency and pass it
to KVM_TDX_INIT_VM.
Besides, sanity check the tsc frequency to be in the legal range and
legal granularity (required by SEAM module).
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
---
target/i386/kvm/kvm.c | 8 ++++++++
target/i386/kvm/tdx.c | 16 ++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index ecb1714920..be0b96b120 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -763,6 +763,14 @@ static int kvm_arch_set_tsc_khz(CPUState *cs)
int r, cur_freq;
bool set_ioctl = false;
+ /*
+ * TD guest's TSC is immutable, it cannot be set/changed via
+ * KVM_SET_TSC_KHZ, but only be initialized via KVM_TDX_INIT_VM
+ */
+ if (vm_type == KVM_X86_TDX_VM) {
+ return 0;
+ }
+
if (!env->tsc_khz) {
return 0;
}
diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c
index e8c70f241d..c50a0dcf11 100644
--- a/target/i386/kvm/tdx.c
+++ b/target/i386/kvm/tdx.c
@@ -29,6 +29,8 @@
#define TDX1_TD_ATTRIBUTE_DEBUG BIT_ULL(0)
#define TDX1_TD_ATTRIBUTE_PERFMON BIT_ULL(63)
+#define TDX1_MIN_TSC_FREQUENCY_KHZ (100 * 1000)
+#define TDX1_MAX_TSC_FREQUENCY_KHZ (10 * 1000 * 1000)
bool kvm_has_tdx(KVMState *s)
{
@@ -91,6 +93,19 @@ void tdx_pre_create_vcpu(CPUState *cpu)
exit(1);
}
+ if (env->tsc_khz && (env->tsc_khz < TDX1_MIN_TSC_FREQUENCY_KHZ ||
+ env->tsc_khz > TDX1_MAX_TSC_FREQUENCY_KHZ)) {
+ error_report("Invalid TSC %ld KHz, must specify cpu_frequecy between
[%d, %d] kHz\n",
+ env->tsc_khz, TDX1_MIN_TSC_FREQUENCY_KHZ,
+ TDX1_MAX_TSC_FREQUENCY_KHZ);
+ exit(1);
+ }
+
+ if (env->tsc_khz % (25 * 1000)) {
+ error_report("Invalid TSC %ld KHz, it must be multiple of 25MHz\n",
env->tsc_khz);
+ exit(1);
+ }
+
qemu_mutex_lock(&tdx->lock);
if (tdx->initialized) {
goto out;
@@ -103,6 +118,7 @@ void tdx_pre_create_vcpu(CPUState *cpu)
cpuid_data.cpuid.padding = 0;
init_vm.max_vcpus = ms->smp.cpus;
+ init_vm.tsc_khz = env->tsc_khz;
init_vm.attributes = 0;
init_vm.attributes |= tdx->debug ? TDX1_TD_ATTRIBUTE_DEBUG : 0;
init_vm.attributes |= x86cpu->enable_pmu ? TDX1_TD_ATTRIBUTE_PERFMON : 0;
--
2.25.1
- [RFC PATCH v2 32/44] tdx: add kvm_tdx_enabled() accessor for later use, (continued)
- [RFC PATCH v2 32/44] tdx: add kvm_tdx_enabled() accessor for later use, isaku . yamahata, 2021/07/07
- [RFC PATCH v2 12/44] target/i386/tdx: Finalize the TD's measurement when machine is done, isaku . yamahata, 2021/07/07
- [RFC PATCH v2 35/44] ioapic: add property to disable level interrupt, isaku . yamahata, 2021/07/07
- [RFC PATCH v2 38/44] hw/i386: plug eoi_intercept_unsupported to ioapic, isaku . yamahata, 2021/07/07
- [RFC PATCH v2 04/44] vl: Introduce machine_init_done_late notifier, isaku . yamahata, 2021/07/07
- [RFC PATCH v2 08/44] i386/kvm: Skip KVM_X86_SETUP_MCE for TDX guests, isaku . yamahata, 2021/07/07
- [RFC PATCH v2 17/44] i386/tdx: Add definitions for TDVF metadata, isaku . yamahata, 2021/07/07
- [RFC PATCH v2 11/44] i386/tdx: Implement user specified tsc frequency,
isaku . yamahata <=
- [RFC PATCH v2 36/44] hw/i386: add eoi_intercept_unsupported member to X86MachineState, isaku . yamahata, 2021/07/07
- [RFC PATCH v2 07/44] i386/kvm: Squash getting/putting guest state for TDX VMs, isaku . yamahata, 2021/07/07
- [RFC PATCH v2 14/44] i386/tdx: Frame in the call for KVM_TDX_INIT_VCPU, isaku . yamahata, 2021/07/07
- [RFC PATCH v2 16/44] hw/i386: Add definitions from UEFI spec for volumes, resources, etc..., isaku . yamahata, 2021/07/07
- [RFC PATCH v2 37/44] hw/i386: add option to forcibly report edge trigger in acpi tables, isaku . yamahata, 2021/07/07
- [RFC PATCH v2 39/44] ioapic: add property to disallow SMI delivery mode, isaku . yamahata, 2021/07/07
- [RFC PATCH v2 34/44] target/i386/tdx: set reboot action to shutdown when tdx, isaku . yamahata, 2021/07/07
- [RFC PATCH v2 06/44] hw/i386: Introduce kvm-type for TDX guest, isaku . yamahata, 2021/07/07