@@ -11,6 +11,47 @@
#include "vmcs.h"
#include "vmx.h"
#include "x86.h"
+#include "tdx.h"
+
+#ifdef CONFIG_KVM_INTEL_TDX
+#define VT_BUILD_VMCS_HELPERS(type, bits, tdbits) \
+static __always_inline type vmread##bits(struct kvm_vcpu *vcpu, \
+ unsigned long field) \
+{ \
+ if (unlikely(is_td_vcpu(vcpu))) { \
+ if (KVM_BUG_ON(!is_debug_td(vcpu), vcpu->kvm)) \
+ return 0; \
+ return td_vmcs_read##tdbits(to_tdx(vcpu), field); \
+ } \
+ return vmcs_read##bits(field); \
+} \
+static __always_inline void vmwrite##bits(struct kvm_vcpu *vcpu, \
+ unsigned long field, type value) \
+{ \
+ if (unlikely(is_td_vcpu(vcpu))) { \
+ if (KVM_BUG_ON(!is_debug_td(vcpu), vcpu->kvm)) \
+ return; \
+ return td_vmcs_write##tdbits(to_tdx(vcpu), field, value); \
+ } \
+ vmcs_write##bits(field, value); \
+}
+#else
+#define VT_BUILD_VMCS_HELPERS(type, bits, tdbits) \
+static __always_inline type vmread##bits(struct kvm_vcpu *vcpu, \
+ unsigned long field) \
+{ \
+ return vmcs_read##bits(field); \
+} \
+static __always_inline void vmwrite##bits(struct kvm_vcpu *vcpu, \
+ unsigned long field, type value) \
+{ \
+ vmcs_write##bits(field, value); \
+}
+#endif /* CONFIG_KVM_INTEL_TDX */
+VT_BUILD_VMCS_HELPERS(u16, 16, 16);
+VT_BUILD_VMCS_HELPERS(u32, 32, 32);
+VT_BUILD_VMCS_HELPERS(u64, 64, 64);
+VT_BUILD_VMCS_HELPERS(unsigned long, l, 64);
void vmx_handle_interrupt_nmi_irqoff(struct kvm_vcpu *vcpu, u32 intr_info);