KVM: TDX: Skip updating CPU dirty logging request for TDs
authorPaolo Bonzini <pbonzini@redhat.com>
Wed, 19 Feb 2025 12:43:51 +0000 (07:43 -0500)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 14 Mar 2025 18:20:53 +0000 (14:20 -0400)
Wrap vmx_update_cpu_dirty_logging so as to ignore requests to update
CPU dirty logging for TDs, as basic TDX does not support the PML feature.
Invoking vmx_update_cpu_dirty_logging() for TDs would cause an incorrect
access to a kvm_vmx struct for a TDX VM, so block that before it happens.

Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/vmx/main.c

index ba3a23747bb1c57c1f087cfa3f94e7b4253e7960..ec8223ee9d286e509eb6e294c77e7849f8a63282 100644 (file)
@@ -129,6 +129,18 @@ static void vt_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
        vmx_vcpu_load(vcpu, cpu);
 }
 
+static void vt_update_cpu_dirty_logging(struct kvm_vcpu *vcpu)
+{
+       /*
+        * Basic TDX does not support feature PML. KVM does not enable PML in
+        * TD's VMCS, nor does it allocate or flush PML buffer for TDX.
+        */
+       if (WARN_ON_ONCE(is_td_vcpu(vcpu)))
+               return;
+
+       vmx_update_cpu_dirty_logging(vcpu);
+}
+
 static void vt_flush_tlb_all(struct kvm_vcpu *vcpu)
 {
        if (is_td_vcpu(vcpu)) {
@@ -322,7 +334,7 @@ struct kvm_x86_ops vt_x86_ops __initdata = {
        .check_intercept = vmx_check_intercept,
        .handle_exit_irqoff = vmx_handle_exit_irqoff,
 
-       .update_cpu_dirty_logging = vmx_update_cpu_dirty_logging,
+       .update_cpu_dirty_logging = vt_update_cpu_dirty_logging,
 
        .nested_ops = &vmx_nested_ops,