[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aQAQLzxyGFooGtNV@google.com>
Date: Mon, 27 Oct 2025 17:37:03 -0700
From: Sean Christopherson <seanjc@...gle.com>
To: Kai Huang <kai.huang@...el.com>
Cc: "chenhuacai@...nel.org" <chenhuacai@...nel.org>, "frankja@...ux.ibm.com" <frankja@...ux.ibm.com>,
"maz@...nel.org" <maz@...nel.org>, "borntraeger@...ux.ibm.com" <borntraeger@...ux.ibm.com>,
"pjw@...nel.org" <pjw@...nel.org>, "aou@...s.berkeley.edu" <aou@...s.berkeley.edu>,
"kas@...nel.org" <kas@...nel.org>, "maobibo@...ngson.cn" <maobibo@...ngson.cn>,
"pbonzini@...hat.com" <pbonzini@...hat.com>, "maddy@...ux.ibm.com" <maddy@...ux.ibm.com>,
"palmer@...belt.com" <palmer@...belt.com>, "imbrenda@...ux.ibm.com" <imbrenda@...ux.ibm.com>,
"zhaotianrui@...ngson.cn" <zhaotianrui@...ngson.cn>, "anup@...infault.org" <anup@...infault.org>,
"oliver.upton@...ux.dev" <oliver.upton@...ux.dev>, "kvm@...r.kernel.org" <kvm@...r.kernel.org>,
"linux-coco@...ts.linux.dev" <linux-coco@...ts.linux.dev>, Yan Y Zhao <yan.y.zhao@...el.com>,
"michael.roth@....com" <michael.roth@....com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>, Ira Weiny <ira.weiny@...el.com>,
"loongarch@...ts.linux.dev" <loongarch@...ts.linux.dev>,
"binbin.wu@...ux.intel.com" <binbin.wu@...ux.intel.com>,
"ackerleytng@...gle.com" <ackerleytng@...gle.com>, "kvmarm@...ts.linux.dev" <kvmarm@...ts.linux.dev>,
"kvm-riscv@...ts.infradead.org" <kvm-riscv@...ts.infradead.org>, Vishal Annapurve <vannapurve@...gle.com>,
"linuxppc-dev@...ts.ozlabs.org" <linuxppc-dev@...ts.ozlabs.org>,
Rick P Edgecombe <rick.p.edgecombe@...el.com>,
"linux-mips@...r.kernel.org" <linux-mips@...r.kernel.org>,
"linux-arm-kernel@...ts.infradead.org" <linux-arm-kernel@...ts.infradead.org>,
"linux-riscv@...ts.infradead.org" <linux-riscv@...ts.infradead.org>, "x86@...nel.org" <x86@...nel.org>
Subject: Re: [PATCH v3 24/25] KVM: TDX: Guard VM state transitions with "all"
the locks
On Tue, Oct 28, 2025, Kai Huang wrote:
> On Thu, 2025-10-16 at 17:32 -0700, Sean Christopherson wrote:
> > @@ -2781,8 +2827,6 @@ int tdx_vm_ioctl(struct kvm *kvm, void __user *argp)
> > if (r)
> > return r;
> >
> > - guard(mutex)(&kvm->lock);
> > -
> > switch (tdx_cmd.id) {
> > case KVM_TDX_CAPABILITIES:
> > r = tdx_get_capabilities(&tdx_cmd);
>
> IIRC, this patch removes grabbing the kvm->lock in tdx_vm_ioctl() but only
> adds the "big hammer" to tdx_td_init() and tdx_td_finalize(), so the
> tdx_get_capabilities() lost holding the kvm->lock.
Ooh, yeah, nice catch, that is indeed silly and unnecessary churn.
> As replied earlier, I think we can just hold the "big hammer" in
> tdx_vm_ioctl()?
Actually, I think we can have our cake and eat it too. With this slotted in as
a prep patch, the big hammer can land directly in tdx_vm_ioctl(), without any
change in functionality for KVM_TDX_CAPABILITIES.
--
From: Sean Christopherson <seanjc@...gle.com>
Date: Mon, 27 Oct 2025 17:32:34 -0700
Subject: [PATCH] KVM: TDX: Don't copy "cmd" back to userspace for
KVM_TDX_CAPABILITIES
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@...el.com>
Signed-off-by: Sean Christopherson <seanjc@...gle.com>
---
arch/x86/kvm/vmx/tdx.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
index 1642da9c1fa9..43c0c3f6a8c0 100644
--- a/arch/x86/kvm/vmx/tdx.c
+++ b/arch/x86/kvm/vmx/tdx.c
@@ -2807,12 +2807,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;
base-commit: 672537233b8da2c29dca7154bf3a3211af7f6128
--
Powered by blists - more mailing lists