From: Aneesh Kumar K.V <aneesh.kumar@kernel.org>
To: sashiko-reviews@lists.linux.dev
Cc: kvm@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v10 15/18] iommufd/viommu: Allow PCI TSM backends to provide vIOMMU operations
Date: Wed, 25 Nov 2026 16:25:01 +0530 [thread overview]
Message-ID: <yq5acxrt9o56.fsf@kernel.org> (raw)
In-Reply-To: <sashiko-outbox-232909@kernel.org>
sashiko-bot@kernel.org writes:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Low] iommufd: mix of __free() and goto error handling in
> iommufd_viommu_alloc_ioctl()
> --
>
> commit c23c0e750868729bcf5c18f6b9904e0a5d226915
> Author: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
>
> iommufd/viommu: Allow PCI TSM backends to provide vIOMMU operations
>
> This commit allows VIOMMU_ALLOC to query PCI TSM backends for vIOMMU
> operations before falling back to the physical IOMMU driver, and tracks
> TSM-backed vIOMMU instances in struct iommufd_viommu.
>
>> diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c
>> index dab499d24c453..909ef86f39a98 100644
>> --- a/drivers/iommu/iommufd/viommu.c
>> +++ b/drivers/iommu/iommufd/viommu.c
> [ ... ]
>> @@ -44,20 +48,38 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd)
>> if (IS_ERR(idev))
>> return PTR_ERR(idev);
>>
>> - iommu_dev = iommufd_device_get_iommu_dev(idev);
>> - if (!iommu_dev) {
>> - rc = -EOPNOTSUPP;
>> + struct tsm_dev *tsm_dev __free(tsm_put_device) = tsm_get_device(idev->dev);
>> + if (IS_ERR(tsm_dev)) {
>> + rc = PTR_ERR(tsm_dev);
>> goto out_put_idev;
>> }
>> - if (!iommu_dev->ops->get_viommu_ops) {
>> - rc = -EOPNOTSUPP;
>> +
>> + if (tsm_dev)
>> + ops = tsm_viommu_get_ops(tsm_dev, idev->dev, cmd->type);
>> + else
>> + ops = NULL;
>> +
>> + if (IS_ERR(ops)) {
>> + rc = PTR_ERR(ops);
>> goto out_put_idev;
>> }
>> - ops = iommu_dev->ops->get_viommu_ops(idev->dev, cmd->type);
>> +
>> if (!ops) {
>> - rc = -EOPNOTSUPP;
>> - goto out_put_idev;
>> + tsm_put_device(no_free_ptr(tsm_dev));
>> +
>> + iommu_dev = iommufd_device_get_iommu_dev(idev);
>> + if (!iommu_dev || !iommu_dev->ops->get_viommu_ops) {
>> + rc = -EOPNOTSUPP;
>> + goto out_put_idev;
>> + }
>> +
>> + ops = iommu_dev->ops->get_viommu_ops(idev->dev, cmd->type);
>> + if (!ops) {
>> + rc = -EOPNOTSUPP;
>> + goto out_put_idev;
>> + }
>> }
>
> [Severity: Low]
> This isn't a bug, but iommufd_viommu_alloc_ioctl() mixes a scope-based
> __free(tsm_put_device) variable with goto-based error handling
> (out_put_hwpt and out_put_idev), which violates the kernel Cleanup API
> convention and causes out_put_idev to release idev before tsm_dev is
> released at function exit. Could tsm_dev be released via a goto label or
> all resources in this function converted to __free()?
>
I fixed this in a separate patch but missed folding in the change. I
will fold it into the next revision.
-aneesh
next prev parent reply other threads:[~2026-11-25 10:55 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 8:11 [PATCH v10 00/18] iommufd: TSM-backed virtual IOMMUs for confidential guests Aneesh Kumar K.V (Arm)
2026-11-25 8:11 ` [PATCH v10 01/18] MAINTAINERS: Update TSM file coverage and repository Aneesh Kumar K.V (Arm)
2026-11-25 8:11 ` [PATCH v10 02/18] virt: coco: tsm: Require PCI operations when registering a TSM Aneesh Kumar K.V (Arm)
2026-11-25 8:11 ` [PATCH v10 03/18] virt: coco: tsm: Remove the device from lookup before PCI teardown Aneesh Kumar K.V (Arm)
2026-11-25 8:11 ` [PATCH v10 04/18] virt: coco: tsm: Complete PCI registration before publishing the device Aneesh Kumar K.V (Arm)
2026-11-25 8:11 ` [PATCH v10 05/18] virt: coco: tsm: Register the TSM class before device drivers Aneesh Kumar K.V (Arm)
2026-11-25 8:25 ` sashiko-bot
2026-11-25 8:11 ` [PATCH v10 06/18] iommufd/device: Associate KVM file pointer with iommufd_device Aneesh Kumar K.V (Arm)
2026-11-25 8:11 ` [PATCH v10 07/18] iommufd/viommu: Keep a reference to the KVM file Aneesh Kumar K.V (Arm)
2026-11-25 8:11 ` [PATCH v10 08/18] iommufd: Add a vDEVICE operation ioctl framework Aneesh Kumar K.V (Arm)
2026-11-25 8:11 ` [PATCH v10 09/18] PCI/TSM: Remove the legacy guest request interface Aneesh Kumar K.V (Arm)
2026-11-25 8:11 ` [PATCH v10 10/18] PCI/TSM: Add helpers to prevent disconnect while in use Aneesh Kumar K.V (Arm)
2026-11-25 8:11 ` [PATCH v10 11/18] PCI/TSM: Remove the legacy bind and unbind interface Aneesh Kumar K.V (Arm)
2026-11-25 8:11 ` [PATCH v10 12/18] iommufd/viommu: Select vIOMMU operations before allocation Aneesh Kumar K.V (Arm)
2026-11-25 8:28 ` sashiko-bot
2026-11-25 8:11 ` [PATCH v10 13/18] PCI/TSM: Add helpers to look up and reference a device's TSM Aneesh Kumar K.V (Arm)
2026-11-25 8:11 ` [PATCH v10 14/18] iommufd/viommu: Identify physical IOMMU backing with a tag Aneesh Kumar K.V (Arm)
2026-11-25 8:11 ` [PATCH v10 15/18] iommufd/viommu: Allow PCI TSM backends to provide vIOMMU operations Aneesh Kumar K.V (Arm)
2026-11-25 8:33 ` sashiko-bot
2026-11-25 10:55 ` Aneesh Kumar K.V [this message]
2026-11-25 8:11 ` [PATCH v10 16/18] iommufd/viommu: Allow vIOMMUs without a parent HWPT Aneesh Kumar K.V (Arm)
2026-11-25 8:11 ` [PATCH v10 17/18] PCI/TSM: Wait for DSM users before removing PF0 Aneesh Kumar K.V (Arm)
2026-11-25 8:11 ` [PATCH v10 18/18] PCI/TSM: Wait for vIOMMUs to release the TSM before unregistering Aneesh Kumar K.V (Arm)
2026-11-25 8:43 ` sashiko-bot
2026-11-25 10:53 ` Aneesh Kumar K.V
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=yq5acxrt9o56.fsf@kernel.org \
--to=aneesh.kumar@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox