]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: TDX: Don't copy "cmd" back to userspace for KVM_TDX_CAPABILITIES
authorSean Christopherson <seanjc@google.com>
Thu, 30 Oct 2025 20:09:48 +0000 (13:09 -0700)
committerSean Christopherson <seanjc@google.com>
Wed, 5 Nov 2025 19:17:31 +0000 (11:17 -0800)
Don't copy the kvm_tdx_cmd structure back to userspace when handling
KVM_TDX_CAPABILITIES, as tdx_get_capabilities() doesn't modify hw_error or
any other fields.

Opportunistically hoist the call to tdx_get_capabilities() outside of the
kvm->lock critical section, as getting the capabilities doesn't touch the
VM in any way, e.g. doesn't even take @kvm.

Suggested-by: Kai Huang <kai.huang@intel.com>
Reviewed-by: Kai Huang <kai.huang@intel.com>
Reviewed-by: Yan Zhao <yan.y.zhao@intel.com>
Tested-by: Yan Zhao <yan.y.zhao@intel.com>
Tested-by: Kai Huang <kai.huang@intel.com>
Link: https://patch.msgid.link/20251030200951.3402865-26-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/vmx/tdx.c

index a4818d9acbd5bb5ced0943d48df68722705c9a2c..73842b762e5ff17eab55270f404d1b10020b1eb0 100644 (file)
@@ -2816,12 +2816,12 @@ int tdx_vm_ioctl(struct kvm *kvm, void __user *argp)
        if (r)
                return r;
 
+       if (tdx_cmd.id == KVM_TDX_CAPABILITIES)
+               return tdx_get_capabilities(&tdx_cmd);
+
        guard(mutex)(&kvm->lock);
 
        switch (tdx_cmd.id) {
-       case KVM_TDX_CAPABILITIES:
-               r = tdx_get_capabilities(&tdx_cmd);
-               break;
        case KVM_TDX_INIT_VM:
                r = tdx_td_init(kvm, &tdx_cmd);
                break;