[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 16/66] i386/tdx: Introduce is_tdx_vm() helper and cache tdx_gu
From: |
Xiaoyao Li |
Subject: |
[PATCH v4 16/66] i386/tdx: Introduce is_tdx_vm() helper and cache tdx_guest object |
Date: |
Wed, 24 Jan 2024 22:22:38 -0500 |
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>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Isaku Yamahata <isaku.yamahata@intel.com>
---
changes in v3:
- replace object_dynamic_cast with TDX_GUEST();
---
target/i386/kvm/tdx.c | 15 ++++++++++++++-
target/i386/kvm/tdx.h | 10 ++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c
index ad76abd58373..3c59b3b45419 100644
--- a/target/i386/kvm/tdx.c
+++ b/target/i386/kvm/tdx.c
@@ -21,8 +21,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_VM_IOCTL,
TDX_VCPU_IOCTL,
@@ -103,15 +111,20 @@ static int get_tdx_capabilities(Error **errp)
int tdx_kvm_init(MachineState *ms, Error **errp)
{
+ TdxGuest *tdx = TDX_GUEST(OBJECT(ms->cgs));
int r = 0;
ms->require_guest_memfd = true;
if (!tdx_caps) {
r = get_tdx_capabilities(errp);
+ if (r) {
+ return r;
+ }
}
- return r;
+ tdx_guest = tdx;
+ return 0;
}
/* tdx guest */
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.34.1
- [PATCH v4 08/66] kvm: handle KVM_EXIT_MEMORY_FAULT, (continued)
- [PATCH v4 08/66] kvm: handle KVM_EXIT_MEMORY_FAULT, Xiaoyao Li, 2024/01/24
- [PATCH v4 01/66] linux-headers: Update to Linux v6.8-rc1, Xiaoyao Li, 2024/01/24
- [PATCH v4 07/66] physmem: Introduce ram_block_discard_guest_memfd_range(), Xiaoyao Li, 2024/01/24
- [PATCH v4 10/66] *** HACK *** linux-headers: Update headers to pull in TDX API changes, Xiaoyao Li, 2024/01/24
- [PATCH v4 09/66] trace/kvm: Add trace for page convertion between shared and private, Xiaoyao Li, 2024/01/24
- [PATCH v4 12/66] target/i386: Implement mc->kvm_type() to get VM type, Xiaoyao Li, 2024/01/24
- [PATCH v4 11/66] i386: Introduce tdx-guest object, Xiaoyao Li, 2024/01/24
- [PATCH v4 13/66] target/i386: Introduce kvm_confidential_guest_init(), Xiaoyao Li, 2024/01/24
- [PATCH v4 15/66] i386/tdx: Get tdx_capabilities via KVM_TDX_CAPABILITIES, Xiaoyao Li, 2024/01/24
- [PATCH v4 14/66] i386/tdx: Implement tdx_kvm_init() to initialize TDX VM context, Xiaoyao Li, 2024/01/24
- [PATCH v4 16/66] i386/tdx: Introduce is_tdx_vm() helper and cache tdx_guest object,
Xiaoyao Li <=
- [PATCH v4 18/66] i386/tdx: Make Intel-PT unsupported for TD guest, Xiaoyao Li, 2024/01/24
- [PATCH v4 17/66] i386/tdx: Adjust the supported CPUID based on TDX restrictions, Xiaoyao Li, 2024/01/24
- [PATCH v4 19/66] i386/tdx: Update tdx_cpuid_lookup[].tdx_fixed0/1 by tdx_caps.cpuid_config[], Xiaoyao Li, 2024/01/24
- [PATCH v4 20/66] i386/tdx: Integrate tdx_caps->xfam_fixed0/1 into tdx_cpuid_lookup, Xiaoyao Li, 2024/01/24
- [PATCH v4 21/66] i386/tdx: Integrate tdx_caps->attrs_fixed0/1 to tdx_cpuid_lookup, Xiaoyao Li, 2024/01/24
- [PATCH v4 22/66] i386/kvm: Move architectural CPUID leaf generation to separate helper, Xiaoyao Li, 2024/01/24
- [PATCH v4 23/66] kvm: Introduce kvm_arch_pre_create_vcpu(), Xiaoyao Li, 2024/01/24
- [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