if (ret)
return ret;
+ return enable_tdx ? tdx_hardware_setup() : 0;
+}
+
+static void vt_hardware_unsetup(void)
+{
if (enable_tdx)
- tdx_hardware_setup();
+ tdx_hardware_unsetup();
- return 0;
+ vmx_hardware_unsetup();
}
static int vt_vm_init(struct kvm *kvm)
.check_processor_compatibility = vmx_check_processor_compat,
- .hardware_unsetup = vmx_hardware_unsetup,
+ .hardware_unsetup = vt_op(hardware_unsetup),
.enable_virtualization_cpu = vmx_enable_virtualization_cpu,
.disable_virtualization_cpu = vt_op(disable_virtualization_cpu),
static void __exit vt_exit(void)
{
kvm_exit();
- tdx_cleanup();
vmx_exit();
}
module_exit(vt_exit);
if (r)
return r;
- /* tdx_init() has been taken */
- r = tdx_bringup();
- if (r)
- goto err_tdx_bringup;
-
/*
* TDX and VMX have different vCPU structures. Calculate the
* maximum size/align so that kvm_init() can use the larger
return 0;
err_kvm_init:
- tdx_cleanup();
-err_tdx_bringup:
vmx_exit();
return r;
}
return PG_LEVEL_4K;
}
-static int __init __tdx_bringup(void)
+void tdx_hardware_unsetup(void)
+{
+ misc_cg_set_capacity(MISC_CG_RES_TDX, 0);
+}
+
+static int __init __tdx_hardware_setup(void)
{
const struct tdx_sys_info_td_conf *td_conf;
int i;
return 0;
}
-int __init tdx_bringup(void)
+int __init tdx_hardware_setup(void)
{
int r, i;
goto success_disable_tdx;
}
- r = __tdx_bringup();
+ r = __tdx_hardware_setup();
if (r) {
/*
* Disable TDX only but don't fail to load module if the TDX
*/
if (r == -ENODEV)
goto success_disable_tdx;
- }
-
- return r;
-
-success_disable_tdx:
- enable_tdx = 0;
- return 0;
-}
-
-void tdx_cleanup(void)
-{
- if (!enable_tdx)
- return;
- misc_cg_set_capacity(MISC_CG_RES_TDX, 0);
-}
+ return r;
+ }
-void __init tdx_hardware_setup(void)
-{
KVM_SANITY_CHECK_VM_STRUCT_SIZE(kvm_tdx);
- /*
- * Note, if the TDX module can't be loaded, KVM TDX support will be
- * disabled but KVM will continue loading (see tdx_bringup()).
- */
vt_x86_ops.vm_size = max_t(unsigned int, vt_x86_ops.vm_size, sizeof(struct kvm_tdx));
vt_x86_ops.link_external_spt = tdx_sept_link_private_spt;
vt_x86_ops.free_external_spt = tdx_sept_free_private_spt;
vt_x86_ops.remove_external_spte = tdx_sept_remove_private_spte;
vt_x86_ops.protected_apic_has_interrupt = tdx_protected_apic_has_interrupt;
+ return 0;
+
+success_disable_tdx:
+ enable_tdx = 0;
+ return 0;
}
#ifdef CONFIG_KVM_INTEL_TDX
#include "common.h"
-void tdx_hardware_setup(void);
-int tdx_bringup(void);
-void tdx_cleanup(void);
+int tdx_hardware_setup(void);
+void tdx_hardware_unsetup(void);
extern bool enable_tdx;
TDX_BUILD_TDVPS_ACCESSORS(64, STATE_NON_ARCH, state_non_arch);
#else
-static inline int tdx_bringup(void) { return 0; }
-static inline void tdx_cleanup(void) {}
-
#define enable_tdx 0
struct kvm_tdx {