KVM: TDX: Get TDX global information
authorKai Huang <kai.huang@intel.com>
Wed, 30 Oct 2024 19:00:15 +0000 (12:00 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 14 Mar 2025 18:20:50 +0000 (14:20 -0400)
KVM will need to consult some essential TDX global information to create
and run TDX guests.  Get the global information after initializing TDX.

Signed-off-by: Kai Huang <kai.huang@intel.com>
Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Message-ID: <20241030190039.77971-3-rick.p.edgecombe@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/vmx/tdx.c

index 3c089ed3b8431a5c5c3970b21c3070b2bb1c8cf6..b74a50e8d086c6780466117f0d84701610520e06 100644 (file)
@@ -13,6 +13,8 @@ module_param_named(tdx, enable_tdx, bool, 0444);
 
 static enum cpuhp_state tdx_cpuhp_state;
 
+static const struct tdx_sys_info *tdx_sysinfo;
+
 static int tdx_online_cpu(unsigned int cpu)
 {
        unsigned long flags;
@@ -92,11 +94,20 @@ static int __init __tdx_bringup(void)
        if (r)
                goto tdx_bringup_err;
 
+       /* Get TDX global information for later use */
+       tdx_sysinfo = tdx_get_sysinfo();
+       if (WARN_ON_ONCE(!tdx_sysinfo)) {
+               r = -EINVAL;
+               goto get_sysinfo_err;
+       }
+
        /*
         * Leave hardware virtualization enabled after TDX is enabled
         * successfully.  TDX CPU hotplug depends on this.
         */
        return 0;
+get_sysinfo_err:
+       __tdx_cleanup();
 tdx_bringup_err:
        kvm_disable_virtualization();
        return r;