From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.10 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796273114; b=jFinkQORPgOdDiDkESFpu/lQ8AOHVK2EDeXaYq+eHJrx7QmJEzPsSv/EdmcV+rJFy1Wh LiZWCuRtmUp9qKnfCUS1Oe5IrRsD1l6GOdhwqTpjJBv3zcKQdHyCGBvCtzXkLPPSVn4fF tcYD3YchscyEq6ScqHZvuFstcuqZI7LiwO+ee3BzkK64jZhZsLaIFIriIJBKZ+keEnq/I MigTqEfc/atqlboFK9SIdHReXE970iKSn3tn2rtdCPajjSxpQ+ghhhCacbL6hxetAZ9no kvgABLE/fRZWLT8JutRvpBxlPuIAK+vwrVAM0DwxikT6uoLuc+OaXNpXZwNvJM/VPzw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796273114; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Message-ID:Date: MIME-Version:User-Agent:Cc:Subject:To:References:Content-Language: From:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=9mGbNjxWjcLOgHk41zyVH7DEi6IxmqQ5Q6yQzWU1CCw=; b=hXOfzgEGaNA2ReX8RaA1+vSEuidWBv/T8GKXqlU3/BvEu7CYHQiwNAk9nQmzkHfU3AGi V8xp/xTZ18TyibwsayWbyloCBYSsY5UtzXf66NBHU9vMgjsRJp61eqBWGXRjoMg60s7QD bRmpPP6leLZ5+C1dTVVE8j/nivJSrdKEJ+Q17QLREVQco5h1NGrW/jUyPZGSeryTLYDOG ZEVJYHJSQSlSg1MCmI00outwLOVVt2v6ouc5EDDPjgj1cmrWWj6l8GvjC6quypXeA+t0R 9Z2ZtPYKrqs9FCkTKyf1TJ9nAy4nQgR7hDW6QnkWDujjE/VxCx7SZwT1ti2D+C3IVeg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=KG+oiZwU; arc=none smtp.remote-ip=198.175.65.10 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A98B606A330; Thu, 3 Dec 2026 04:45:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2A98B606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; 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; 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: QctQgXLqQzmnepqZS8ALjA== X-CSE-MsgGUID: py7QFsZcSRizN/o8kfYFRQ== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5156171" X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="5156171" 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-Mailing-List: linux-tegra@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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