From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796286482; b=Oazs13mqBCl239ObCs8ngXc/bthqTi6WmxQQ6b6ETBOpbXckUajNyQ5MU+bd/bWMr4AT gIClcgDuEGXEr3pafCEtN63+VukfWt2zZOcmKyEl19zPXdatfoGbZSplmwVmybNAuncJp hczg9TuggY18qRIw0b2U2Sj2BiMkszjs6iifGXprLofxvPkAZi8grLNt+s4XwHpBkWIjI VInKpg2eTjP+cCOv/K6wYNgq/YFN8PRdx1cgUfGtucDEwQDNBZZ1i6g+EALx8mZ1a2dj5 veJD9AXdG8FIK/yLqDRDdSJthI7P3Zmnn4b/7gmTxOoEL4174m2V+sp8nOQta3b4d/Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796286482; h=Received:DKIM-Signature:X-Mailer:From:To:Cc:Subject:In-Reply-To: References:Date:Message-ID:MIME-Version:Content-Type; bh=2pzcTI+I2SCk1p9YyEQh8MKuiJr+7KGkgOmcrFr+vLc=; b=GdkaIktwawODTXI3wnA+2XHS6m3jwU0SdPbFQhLl00yyyA2BObdaX6vLt62hNJUSEz3T hEGaI1OjpX/aza60hLBvE8l3Pg8zIMq5kC3Xl4FHfrSg2V4RzeColyX8k5gYsvmsLoljd ECYFtpKY7l3tmXNECZ68udojsGwx3/syMyV6zWsmmXry8/ft2L5KHFllo8ucNrs9jcu9K O2IaXnT8/T4AFc/AUv4pOKf4oNbOpLP1/G6jOxqM9lLAb1/qMxMiJfmxr8sFOCrcBB1zy yKQqjHy6x2knqr8LkDeTSyib7aOXil5o4IzZ2vVzW3qxPEY1KkwxvC0nZ+1KWOow53w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TCo+kGol; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 467D4606A322; Thu, 3 Dec 2026 08:28:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TCo+kGol Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCF4E1F000C1; Thu, 3 Dec 2026 08:27:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796286481; bh=2pzcTI+I2SCk1p9YyEQh8MKuiJr+7KGkgOmcrFr+vLc=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=TCo+kGol5UgiysPolJMuUMRbLry0OjVVAQuKXBMIM/ORonKGaGA121BNSH3Si2f77 w0jEu6mHlZRJUEr2oLkZVgEjFdRaeDQSgbbGUgIzAlHrwRw3JgYHtMCl2hr+bniIuD utvM4z2LzKA089DOldsFBudR1Ld0trElq6LlneRs87dQWv6KVpuANioOfyHc23x4PM rOIiZ2TmFbMMn/8SSvkRddUQLUe48m5eL+NFrqc70O36+mWmajCbFtqTRKW4Jvg607 wlhOCu9WNn3/yQtl0yZqYmvmJGIhJXhiPv4vyzKf2m7t5vPIiZTn3RMoeUfZjU6a/7 IbWCZRmszbArQ== X-Mailer: emacs 31.1 (via feedmail 11-beta-1 I) From: Aneesh Kumar K.V To: Baolu Lu , linux-coco@lists.linux.dev Cc: baolu.lu@linux.intel.com, Alex Williamson , Alexey Kardashevskiy , Bjorn Helgaas , Catalin Marinas , Jacob Pan , Jason Gunthorpe , Joerg Roedel , Jonathan Cameron , Jonathan Hunter , Kevin Tian , Krishna Reddy , Lukas Wunner , Nicolin Chen , Robin Murphy , Samuel Ortiz , Shameer Kolothum , Steven Price , Suravee Suthikulpanit , Suzuki K Poulose , Thierry Reding , Vasant Hegde , Will Deacon , Xu Yilun , Ashish Kalra , Herbert Xu , Jonathan Cameron , Tom Lendacky , kvm@vger.kernel.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-tegra@vger.kernel.org, patches@lists.linux.dev Subject: Re: [PATCH v10 13/18] PCI/TSM: Add helpers to look up and reference a device's TSM In-Reply-To: References: <20261125081121.379481-1-aneesh.kumar@kernel.org> <20261125081121.379481-14-aneesh.kumar@kernel.org> Date: Thu, 03 Dec 2026 13:57:49 +0530 Message-ID: X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain Baolu Lu writes: > On 11/25/2026 4:11 PM, Aneesh Kumar K.V (Arm) wrote: >> Add tsm_get_device() to find and reference the TSM attached to a device, >> using pci_tsm_get_device() for PCI devices. Resolve the PCI association >> under pci_tsm_rwsem and acquire TSM device and backend module >> references. Return NULL when no TSM is attached and an error if the >> module cannot be pinned. >> >> Add tsm_put_device() to release the device reference before the module >> reference, since the final device put may call into the backend module. >> >> Set the AMD SEV TSM operations owner to THIS_MODULE so lookup pins the >> module implementing its callbacks. >> >> Following patch lets IOMMUFD use vIOMMU operations implemented by the >> selected device's TSM. vIOMMU allocation must look up that TSM to find >> its operations. The vIOMMU keeps the TSM device and module references >> until it is destroyed, so the TSM allocation cannot be freed and its >> callback code cannot be unloaded while the vIOMMU can still call it. >> >> Signed-off-by: Aneesh Kumar K.V (Arm) >> --- >> drivers/crypto/ccp/sev-dev-tsm.c | 1 + >> drivers/pci/tsm.c | 19 +++++++++++++++++++ >> drivers/virt/coco/tsm-core.c | 32 ++++++++++++++++++++++++++++++++ >> include/linux/pci-tsm.h | 10 ++++++++++ >> include/linux/tsm.h | 19 +++++++++++++++++++ >> 5 files changed, 81 insertions(+) >> > > [...] > >> diff --git a/drivers/virt/coco/tsm-core.c b/drivers/virt/coco/tsm-core.c >> index bf09bb4546de..4f735c628ec3 100644 >> --- a/drivers/virt/coco/tsm-core.c >> +++ b/drivers/virt/coco/tsm-core.c >> @@ -16,6 +16,38 @@ static const struct class tsm_class = { >> }; >> static DEFINE_IDA(tsm_ida); >> >> +/** >> + * tsm_get_device() - Pin the TSM attached to a device >> + * @dev: device whose TSM is to be pinned >> + * >> + * A successful lookup takes a TSM device reference and pins the backend >> + * module. Release both with tsm_put_device(). The TSM must remain registered >> + * while the module is pinned. > > How can a caller enforce "the TSM must remain registered while the > module is pinned"? This should be guaranteed by the TSM core, not a > requirement on the caller. > The last patch implements that. > >> + * Return: NULL if no TSM is attached, an error if the module >> + * cannot be pinned, or the TSM device associated with the pinned backend. > > Nit: a blank line before "Return:". > -aneesh