[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v1 07/40] i386/tdx: Introduce is_tdx_vm() helper and cache tdx_gu
From: |
Xiaoyao Li |
Subject: |
[PATCH v1 07/40] i386/tdx: Introduce is_tdx_vm() helper and cache tdx_guest object |
Date: |
Tue, 2 Aug 2022 15:47:17 +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 | 13 +++++++++++++
target/i386/kvm/tdx.h | 10 ++++++++++
2 files changed, 23 insertions(+)
diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c
index 89f81f7d7082..fdd6bec58758 100644
--- a/target/i386/kvm/tdx.c
+++ b/target/i386/kvm/tdx.c
@@ -20,8 +20,16 @@
#include "kvm_i386.h"
#include "tdx.h"
+static TdxGuest *tdx_guest;
+
static struct kvm_tdx_capabilities *tdx_caps;
+/* It's valid after kvm_confidential_guest_init()->kvm_tdx_init() */
+bool is_tdx_vm(void)
+{
+ return !!tdx_guest;
+}
+
enum tdx_ioctl_level{
TDX_PLATFORM_IOCTL,
TDX_VM_IOCTL,
@@ -108,10 +116,15 @@ static void get_tdx_capabilities(void)
int tdx_kvm_init(MachineState *ms, Error **errp)
{
+ TdxGuest *tdx = (TdxGuest *)object_dynamic_cast(OBJECT(ms->cgs),
+ TYPE_TDX_GUEST);
+
if (!tdx_caps) {
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
- [PATCH v1 01/40] *** HACK *** linux-headers: Update headers to pull in TDX API changes, (continued)
- [PATCH v1 01/40] *** HACK *** linux-headers: Update headers to pull in TDX API changes, Xiaoyao Li, 2022/08/02
- [PATCH v1 02/40] i386: Introduce tdx-guest object, Xiaoyao Li, 2022/08/02
- [PATCH v1 03/40] target/i386: Implement mc->kvm_type() to get VM type, Xiaoyao Li, 2022/08/02
- [PATCH v1 04/40] target/i386: Introduce kvm_confidential_guest_init(), Xiaoyao Li, 2022/08/02
- [PATCH v1 05/40] i386/tdx: Implement tdx_kvm_init() to initialize TDX VM context, Xiaoyao Li, 2022/08/02
- [PATCH v1 06/40] i386/tdx: Get tdx_capabilities via KVM_TDX_CAPABILITIES, Xiaoyao Li, 2022/08/02
- [PATCH v1 07/40] i386/tdx: Introduce is_tdx_vm() helper and cache tdx_guest object,
Xiaoyao Li <=
- [PATCH v1 08/40] i386/tdx: Adjust the supported CPUID based on TDX restrictions, Xiaoyao Li, 2022/08/02
- [PATCH v1 09/40] i386/tdx: Update tdx_fixed0/1 bits by tdx_caps.cpuid_config[], Xiaoyao Li, 2022/08/02
- [PATCH v1 12/40] i386/kvm: Move architectural CPUID leaf generation to separate helper, Xiaoyao Li, 2022/08/02
- [PATCH v1 10/40] i386/tdx: Integrate tdx_caps->xfam_fixed0/1 into tdx_cpuid_lookup, Xiaoyao Li, 2022/08/02