105 lines
2.9 KiB
Diff
105 lines
2.9 KiB
Diff
From af03f2b600e6d02d86b21cc25bbeeaa35d104cfc Mon Sep 17 00:00:00 2001
|
|
From: Paolo Bonzini <pbonzini@redhat.com>
|
|
Date: Fri, 18 Jul 2025 18:03:45 +0200
|
|
Subject: [PATCH 035/115] i386/tdx: Introduce is_tdx_vm() helper and cache
|
|
tdx_guest object
|
|
|
|
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
|
|
RH-MergeRequest: 391: TDX support, including attestation and device assignment
|
|
RH-Jira: RHEL-15710 RHEL-20798 RHEL-49728
|
|
RH-Acked-by: Yash Mankad <None>
|
|
RH-Acked-by: Peter Xu <peterx@redhat.com>
|
|
RH-Acked-by: David Hildenbrand <david@redhat.com>
|
|
RH-Commit: [35/115] 8e84ea1bc7eaf07ccfd915601b471cd75d01bf90 (bonzini/rhel-qemu-kvm)
|
|
|
|
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>
|
|
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
|
|
Link: https://lore.kernel.org/r/20250508150002.689633-7-xiaoyao.li@intel.com
|
|
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
(cherry picked from commit 1619d0e45be0d1e48a46d80963b4e77dc1b000a2)
|
|
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
---
|
|
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 c67be5e618..16f67e18ae 100644
|
|
--- a/target/i386/kvm/tdx.c
|
|
+++ b/target/i386/kvm/tdx.c
|
|
@@ -18,8 +18,16 @@
|
|
#include "kvm_i386.h"
|
|
#include "tdx.h"
|
|
|
|
+static TdxGuest *tdx_guest;
|
|
+
|
|
static struct kvm_tdx_capabilities *tdx_caps;
|
|
|
|
+/* Valid after kvm_arch_init()->confidential_guest_kvm_init()->tdx_kvm_init() */
|
|
+bool is_tdx_vm(void)
|
|
+{
|
|
+ return !!tdx_guest;
|
|
+}
|
|
+
|
|
enum tdx_ioctl_level {
|
|
TDX_VM_IOCTL,
|
|
TDX_VCPU_IOCTL,
|
|
@@ -117,15 +125,20 @@ static int get_tdx_capabilities(Error **errp)
|
|
|
|
static int tdx_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
|
|
{
|
|
+ TdxGuest *tdx = TDX_GUEST(cgs);
|
|
int r = 0;
|
|
|
|
kvm_mark_guest_state_protected();
|
|
|
|
if (!tdx_caps) {
|
|
r = get_tdx_capabilities(errp);
|
|
+ if (r) {
|
|
+ return r;
|
|
+ }
|
|
}
|
|
|
|
- return r;
|
|
+ tdx_guest = tdx;
|
|
+ return 0;
|
|
}
|
|
|
|
static int tdx_kvm_type(X86ConfidentialGuest *cg)
|
|
diff --git a/target/i386/kvm/tdx.h b/target/i386/kvm/tdx.h
|
|
index f3b7253361..de8ae91961 100644
|
|
--- a/target/i386/kvm/tdx.h
|
|
+++ b/target/i386/kvm/tdx.h
|
|
@@ -3,6 +3,10 @@
|
|
#ifndef QEMU_I386_TDX_H
|
|
#define QEMU_I386_TDX_H
|
|
|
|
+#ifndef CONFIG_USER_ONLY
|
|
+#include CONFIG_DEVICES /* CONFIG_TDX */
|
|
+#endif
|
|
+
|
|
#include "confidential-guest.h"
|
|
|
|
#define TYPE_TDX_GUEST "tdx-guest"
|
|
@@ -18,4 +22,10 @@ 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 */
|
|
+
|
|
#endif /* QEMU_I386_TDX_H */
|
|
--
|
|
2.50.1
|
|
|