From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5C53606A322 for ; Thu, 3 Dec 2026 08:28:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=sxsvOvuD; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TCo+kGol DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: Message-ID:Date:References:In-Reply-To:Subject:Cc:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=2pzcTI+I2SCk1p9YyEQh8MKuiJr+7KGkgOmcrFr+vLc=; b=sxsvOvuDR6Tfn++jHpnpvTEYii K8aiuIWp0P262vNbK+JXwrgJdyD0/inYf47kSmZ4rLd5DSkXqkUlq6nELxRj2L3VHXQtJ1QAcKWzH KXsVrTM8rqE7zPBtic2KLY0jekPrWv8EIeHV7qQYbUMXSTvwsR+DmwPbEE9FP8kNI9uA3pQzWw/i7 KO6TSTtObsH+WQbK3LxNs2CEcIGx7xnFsttWdjTxf4JU2A0pYhfhiCj1BKqeXh6tA8ZvA2QJmWizB 4XKSoTCOJMth126xCwR3T24kXksZkkP2Oo1F6WJg45g8iDRgqWWKiOhJO21/HRLgFg/27cFY2S3qb hxAyA+pg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZ2Ae-0000000Dqnh-1lOS; Thu, 03 Dec 2026 08:28:04 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZ2Ac-0000000Dqn6-14u3 for linux-arm-kernel@lists.infradead.org; Thu, 03 Dec 2026 08:28:02 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id E7DAF40334; Thu, 3 Dec 2026 08:28:01 +0000 (UTC) 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-Archived-By: MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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