[PATCH v12 034/106] KVM: x86/mmu: Require TDP MMU and mmio caching for TDX

From: isaku . yamahata
Date: Mon Feb 27 2023 - 03:26:15 EST


From: Isaku Yamahata <isaku.yamahata@xxxxxxxxx>

As TDP MMU is becoming main stream than the legacy MMU, the legacy MMU
support for TDX isn't implemented. TDX requires KVM mmio caching. Disable
TDX support when TDP MMU or mmio caching aren't supported.

Signed-off-by: Isaku Yamahata <isaku.yamahata@xxxxxxxxx>
---
arch/x86/kvm/mmu/mmu.c | 1 +
arch/x86/kvm/vmx/main.c | 6 ++++++
2 files changed, 7 insertions(+)

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 898f36f2d84a..a6b0b53634e8 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -99,6 +99,7 @@ module_param_named(flush_on_reuse, force_flush_and_sync_on_reuse, bool, 0644);
* If the hardware supports that we don't need to do shadow paging.
*/
bool tdp_enabled = false;
+EXPORT_SYMBOL_GPL(tdp_enabled);

bool __ro_after_init tdp_mmu_allowed;

diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c
index fa0590e37ec1..0cd85c96ed84 100644
--- a/arch/x86/kvm/vmx/main.c
+++ b/arch/x86/kvm/vmx/main.c
@@ -2,6 +2,7 @@
#include <linux/moduleparam.h>

#include "x86_ops.h"
+#include "mmu.h"
#include "vmx.h"
#include "nested.h"
#include "pmu.h"
@@ -38,6 +39,11 @@ static __init int vt_hardware_setup(void)

enable_tdx = enable_tdx && !tdx_hardware_setup(&vt_x86_ops);

+ /* TDX requires KVM TDP MMU and MMIO caching. */
+ if (enable_tdx && (!tdp_enabled || !enable_mmio_caching)) {
+ enable_tdx = false;
+ pr_warn_ratelimited("tdp mmu and mmio caching need to be enabled.\n");
+ }
return 0;
}

--
2.25.1