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 E1D69606A32F for ; Thu, 3 Dec 2026 04:45:26 +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=QQFE992P; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=KG+oiZwU 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-Transfer-Encoding: Content-Type:In-Reply-To:From:References:To:Subject:Cc:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=9mGbNjxWjcLOgHk41zyVH7DEi6IxmqQ5Q6yQzWU1CCw=; b=QQFE992P9zvqXl eoNKaVDCb5aQFnYWMn784maQV4SMYkqz1WLbY9s2yMpIKatuNJnwx3gtR6RjWF7wYBAsmoCCSHw+K tAJCQqbukqbAPb/fRKEEqO+5QWCHLWjDyxGKSmXGp44LCPYXmIGq+wYH/h5FRc1ms9sF+7Fulwcwo 33b9Ne54mOKRTtZxH+91fWRT08EJXY1ZXz0ILMoRLdMd+9EZXgES/cnqy2hfPekWkmfhYD0IDkoST jIWlgdObvu913Ewr612VL+MkdU3WQ1IWelrYmNHhjlXDsK6gTjKnHjH690yAx7SUxJbrOjYKokjS3 qClRunZzFFXswe9uXHYQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYyh1-0000000DXB0-32tr; Thu, 03 Dec 2026 04:45:15 +0000 Received: from mgamail.intel.com ([198.175.65.10]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYygz-0000000DXAc-1CFH for linux-arm-kernel@lists.infradead.org; Thu, 03 Dec 2026 04:45:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796273114; x=1827809114; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=9mGbNjxWjcLOgHk41zyVH7DEi6IxmqQ5Q6yQzWU1CCw=; b=KG+oiZwUQOgpipT7yvSfQBZcwIs4sHTMbXklmlnUohvPRWpkrGp7ksBx zM1C/X5OvdUovei2VhE3U+hx8Am4R4Z+ag1JN3PJ0zXDkPvlt9r49TKmC eUkEjRg5iJmbkasWOtYlAH4Y9HHB/BEJ70rZUVRNRLW5l9sPV12qLBDqL Lo2r859vFQq6s1WM2Xw+R1KYzJ+/LI+YkQl1yhkZNZMRa9H8uP8EWVf40 gwQ5/pR05+Kal0CkciYsuRR1rWuQmG5iB3qWmNZ1bKAAqkTDyLb1QayTZ EEBL5Azz3EMJ2oKYAfYnrjF2huvymN0rFV1pzth912Hugu6dIKqeRcud5 A==; X-CSE-ConnectionGUID: 9yf2fEgwSHS0HObPHfl69Q== X-CSE-MsgGUID: VMelnWtvQAaIQQOWXdiDgg== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5156179" X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="5156179" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 20:45:13 -0800 X-CSE-ConnectionGUID: LztfK1CuQfm7o+iyQSMWZA== X-CSE-MsgGUID: p8NFyf6OQ2ejwAtJ7wcu9A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="13745634" Received: from unknown (HELO [10.238.1.144]) ([10.238.1.144]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 20:45:05 -0800 Message-ID: Date: Thu, 3 Dec 2026 12:45:02 +0800 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird 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 To: "Aneesh Kumar K.V (Arm)" , linux-coco@lists.linux.dev References: <20261125081121.379481-1-aneesh.kumar@kernel.org> <20261125081121.379481-14-aneesh.kumar@kernel.org> Content-Language: en-US From: Baolu Lu In-Reply-To: <20261125081121.379481-14-aneesh.kumar@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261202_204513_368402_70E237D2 X-CRM114-Status: GOOD ( 25.09 ) X-Spam-Score: -4.2 (----) 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.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 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 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. > + * 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:". > + */ > +struct tsm_dev *tsm_get_device(struct device *dev) > +{ > + if (!dev_is_pci(dev)) > + return NULL; > + > + return pci_tsm_get_device(to_pci_dev(dev)); > +} > +EXPORT_SYMBOL_GPL(tsm_get_device); > + > +void tsm_put_device(struct tsm_dev *tsm_dev) > +{ > + struct module *owner; > + > + if (!tsm_dev) > + return; > + > + owner = tsm_dev->pci_ops->owner; > + put_device(&tsm_dev->dev); > + module_put(owner); > +} > +EXPORT_SYMBOL_GPL(tsm_put_device); > + > static int match_id(struct device *dev, const void *data) > { > struct tsm_dev *tsm_dev = container_of(dev, struct tsm_dev, dev); [...] Thanks, baolu