KVM: TDX: Add methods to ignore VMX preemption timer
authorIsaku Yamahata <isaku.yamahata@intel.com>
Thu, 27 Feb 2025 01:20:15 +0000 (09:20 +0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 14 Mar 2025 18:20:57 +0000 (14:20 -0400)
TDX doesn't support VMX preemption timer.  Implement access methods for VMM
to ignore VMX preemption timer.

Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com>
Message-ID: <20250227012021.1778144-15-binbin.wu@linux.intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/vmx/main.c

index 0b9e4ede6143f037720d7c01113a6b0c0473c5d3..2e5798d03423f4e88ad33d6b135535f3a4c0a8d9 100644 (file)
@@ -786,6 +786,27 @@ static int vt_set_identity_map_addr(struct kvm *kvm, u64 ident_addr)
        return vmx_set_identity_map_addr(kvm, ident_addr);
 }
 
+#ifdef CONFIG_X86_64
+static int vt_set_hv_timer(struct kvm_vcpu *vcpu, u64 guest_deadline_tsc,
+                             bool *expired)
+{
+       /* VMX-preemption timer isn't available for TDX. */
+       if (is_td_vcpu(vcpu))
+               return -EINVAL;
+
+       return vmx_set_hv_timer(vcpu, guest_deadline_tsc, expired);
+}
+
+static void vt_cancel_hv_timer(struct kvm_vcpu *vcpu)
+{
+       /* VMX-preemption timer can't be set.  See vt_set_hv_timer(). */
+       if (is_td_vcpu(vcpu))
+               return;
+
+       vmx_cancel_hv_timer(vcpu);
+}
+#endif
+
 static int vt_mem_enc_ioctl(struct kvm *kvm, void __user *argp)
 {
        if (!is_td(kvm))
@@ -941,8 +962,8 @@ struct kvm_x86_ops vt_x86_ops __initdata = {
        .pi_start_assignment = vmx_pi_start_assignment,
 
 #ifdef CONFIG_X86_64
-       .set_hv_timer = vmx_set_hv_timer,
-       .cancel_hv_timer = vmx_cancel_hv_timer,
+       .set_hv_timer = vt_set_hv_timer,
+       .cancel_hv_timer = vt_cancel_hv_timer,
 #endif
 
        .setup_mce = vmx_setup_mce,