[PATCH v10 13/18] PCI/TSM: Add helpers to look up and reference a device's TSM
Aneesh Kumar K.V
aneesh.kumar at kernel.org
Thu Dec 3 00:27:49 PST 2026
Baolu Lu <baolu.lu at linux.intel.com> 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) <aneesh.kumar at kernel.org>
>> ---
>> 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
More information about the linux-arm-kernel
mailing list