[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v3 07/36] i386/tdx: Introduce is_tdx_vm() helper and cache td
From: |
Xiaoyao Li |
Subject: |
[RFC PATCH v3 07/36] i386/tdx: Introduce is_tdx_vm() helper and cache tdx_guest object |
Date: |
Thu, 17 Mar 2022 21:58:44 +0800 |
It will need special handling for TDX VMs all around the QEMU.
Introduce is_tdx_vm() helper to query if it's a TDX VM.
Cache tdx_guest object thus no need to cast from ms->cgs every time.
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
target/i386/kvm/tdx.c | 10 ++++++++++
target/i386/kvm/tdx.h | 10 ++++++++++
2 files changed, 20 insertions(+)
diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c
index bed337e5ba18..846511b299f4 100644
--- a/target/i386/kvm/tdx.c
+++ b/target/i386/kvm/tdx.c
@@ -19,6 +19,14 @@
#include "hw/i386/x86.h"
#include "tdx.h"
+static TdxGuest *tdx_guest;
+
+/* It's valid after kvm_confidential_guest_init()->kvm_tdx_init() */
+bool is_tdx_vm(void)
+{
+ return !!tdx_guest;
+}
+
enum tdx_ioctl_level{
TDX_VM_IOCTL,
TDX_VCPU_IOCTL,
@@ -97,6 +105,8 @@ int tdx_kvm_init(MachineState *ms, Error **errp)
get_tdx_capabilities();
}
+ tdx_guest = tdx;
+
return 0;
}
diff --git a/target/i386/kvm/tdx.h b/target/i386/kvm/tdx.h
index c8a23d95258d..4036ca2f3f99 100644
--- a/target/i386/kvm/tdx.h
+++ b/target/i386/kvm/tdx.h
@@ -1,6 +1,10 @@
#ifndef QEMU_I386_TDX_H
#define QEMU_I386_TDX_H
+#ifndef CONFIG_USER_ONLY
+#include CONFIG_DEVICES /* CONFIG_TDX */
+#endif
+
#include "exec/confidential-guest-support.h"
#define TYPE_TDX_GUEST "tdx-guest"
@@ -16,6 +20,12 @@ typedef struct TdxGuest {
uint64_t attributes; /* TD attributes */
} TdxGuest;
+#ifdef CONFIG_TDX
+bool is_tdx_vm(void);
+#else
+#define is_tdx_vm() 0
+#endif /* CONFIG_TDX */
+
int tdx_kvm_init(MachineState *ms, Error **errp);
#endif /* QEMU_I386_TDX_H */
--
2.27.0
- [RFC PATCH v3 00/36] TDX QEMU support, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 03/36] target/i386: Implement mc->kvm_type() to get VM type, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 05/36] i386/tdx: Implement tdx_kvm_init() to initialize TDX VM context, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 01/36] *** HACK *** linux-headers: Update headers to pull in TDX API changes, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 06/36] i386/tdx: Get tdx_capabilities via KVM_TDX_CAPABILITIES, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 07/36] i386/tdx: Introduce is_tdx_vm() helper and cache tdx_guest object,
Xiaoyao Li <=
- [RFC PATCH v3 04/36] target/i386: Introduce kvm_confidential_guest_init(), Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 02/36] i386: Introduce tdx-guest object, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 08/36] i386/tdx: Adjust get_supported_cpuid() for TDX VM, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 09/36] KVM: Introduce kvm_arch_pre_create_vcpu(), Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 10/36] i386/kvm: Move architectural CPUID leaf generation to separate helper, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 11/36] i386/tdx: Initialize TDX before creating TD vcpus, Xiaoyao Li, 2022/03/17