From: Jason Gunthorpe <jgg@nvidia.com>
To: "Aneesh Kumar K.V" <aneesh.kumar@kernel.org>
Cc: sashiko-reviews@lists.linux.dev, iommu@lists.linux.dev,
kvm@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v7 13/16] iommufd/viommu: Select vIOMMU operations before allocation
Date: Tue, 13 Oct 2026 09:33:59 -0300 [thread overview]
Message-ID: <20261013123359.GS13920@nvidia.com> (raw)
In-Reply-To: <yq5aik36q819.fsf@kernel.org>
On Tue, Oct 13, 2026 at 02:41:46PM +0530, Aneesh Kumar K.V wrote:
> Jason Gunthorpe <jgg@nvidia.com> writes:
>
> > On Mon, Oct 12, 2026 at 03:07:57PM +0530, Aneesh Kumar K.V wrote:
> >> > Currently, amd_iommufd_get_viommu_ops() unconditionally returns the ops
> >> > structure without checking the type argument. If a user requests an arbitrary
> >> > type like IOMMU_VIOMMU_TYPE_ARM_SMMUV3 on an AMD device, the core iommufd
> >> > framework might track the vIOMMU under a mismatched architectural type
> >> > identifier.
> >> >
> >> > The ARM and selftest backends appear to validate this argument against their
> >> > supported hardware types before returning the operations.
> >> >
> >>
> >> No vIOMMU type has been added for any IOMMU other than Arm. The
> >> documentation also considers IOMMU_VIOMMU_TYPE_DEFAULT reserved.
> >
> > This is a bug in the AMD driver we need to fix, send a patch? It
> > should only accept DEFAULT, not every type.
> >
>
> But the comment says "Reserved"
>
> * @IOMMU_VIOMMU_TYPE_DEFAULT: Reserved for future use
>
> What is unclear is what using that type on Arm means. Does it imply
> IOMMU_VIOMMU_TYPE_ARM_SMMUV3?.
It fails
Probably thats the better answer, AMD should just always fail until
they get their type added.
> >> >> diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c
> >> >> index f3d5b5a7eb4a4..e95138ae71d5b 100644
> >> >> --- a/drivers/iommu/iommufd/viommu.c
> >> >> +++ b/drivers/iommu/iommufd/viommu.c
> >> > [ ... ]
> >> >> @@ -103,16 +105,12 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd)
> >> >> */
> >> >> viommu->iommu_dev = iommu_dev;
> >> >>
> >> >> - rc = ops->viommu_init(viommu, hwpt_paging->common.domain,
> >> >> + rc = ops->viommu_init(viommu, idev->dev,
> >> >> + hwpt_paging->common.domain,
> >> >> user_data.len ? &user_data : NULL);
> >> >
> >> > [Severity: Critical]
> >> > Is there a missing check to ensure the domain is owned by the same driver
> >> > before passing it to viommu_init?
> >>
> >> The viommu_init callback needs to perform this check. For example, the
> >> Arm implementation does:
> >
> > No, the check is missing. If a domain is being used then the core code
> > needs to check it, not the driver.
> >
> > When the ops is first obtained it should be checked along with the
> > domain to be sure it is compatible.
> >
> > The NULL parent domain on the TSM path should be enforced in the core
> > code since there is nothing to check there.
> >
>
> So, if IOMMUFD_VIOMMU_NO_HWPT is not set, the HWPT must have been
> created with IOMMU_HWPT_ALLOC_NEST_PARENT, and its domain owner must
> match iommu_dev->ops?
And the tsm flow must have IOMMUFD_VIOMMU_NO_HWPT
> Something like:
>
> idev = iommufd_get_device(ucmd, cmd->dev_id);
> iommu_dev = iommufd_device_get_iommu_dev(idev);
>
> if (ops->flags & IOMMUFD_VIOMMU_NO_HWPT) {
> if (cmd->hwpt_id) {
> rc = -EINVAL;
> goto out_put_idev;
> }
> } else {
> hwpt_paging = iommufd_get_hwpt_paging(ucmd, cmd->hwpt_id);
> if (IS_ERR(hwpt_paging)) {
> rc = PTR_ERR(hwpt_paging);
> goto out_put_idev;
> }
> if (!hwpt_paging->nest_parent || !iommu_dev ||
> hwpt_paging->common.domain->owner != iommu_dev->ops) {
> rc = -EINVAL;
> goto out_put_hwpt;
This only works if the ops came from a real iommu driver.
Jason
next prev parent reply other threads:[~2026-10-13 12:34 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 5:59 [PATCH v7 00/16] iommufd: vIOMMUs and TSM guest requests for confidential guests Aneesh Kumar K.V (Arm)
2026-10-08 5:59 ` [PATCH v7 01/16] KVM: Introduce file_to_kvm_<arch>() infrastructure Aneesh Kumar K.V (Arm)
2026-10-08 6:11 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 02/16] KVM: Add file back-pointer to struct kvm Aneesh Kumar K.V (Arm)
2026-10-08 6:16 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 03/16] KVM: x86: Use file_to_kvm_x86() in SEV Aneesh Kumar K.V (Arm)
2026-10-08 6:07 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 04/16] KVM/vfio: Use file-based reference counting for KVM Aneesh Kumar K.V (Arm)
2026-10-08 6:27 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 05/16] KVM: Restrict kvm_get_kvm/kvm_put_kvm export to internal KVM modules Aneesh Kumar K.V (Arm)
2026-10-08 6:08 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 06/16] KVM: Remove unused file_is_kvm Aneesh Kumar K.V (Arm)
2026-10-08 6:06 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 07/16] iommufd/device: Associate KVM file pointer with iommufd_device Aneesh Kumar K.V (Arm)
2026-10-08 6:20 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 08/16] iommufd/viommu: Keep a reference to the KVM file Aneesh Kumar K.V (Arm)
2026-10-08 6:10 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 09/16] tsm: Remove the device from lookup before PCI teardown Aneesh Kumar K.V (Arm)
2026-10-08 6:15 ` sashiko-bot
2026-10-12 9:14 ` Aneesh Kumar K.V
2026-10-12 13:01 ` Jason Gunthorpe
2026-10-13 8:49 ` Aneesh Kumar K.V
2026-10-13 11:57 ` Jason Gunthorpe
2026-10-08 5:59 ` [PATCH v7 10/16] iommufd: Add the vdevice TSM request ioctl Aneesh Kumar K.V (Arm)
2026-10-08 6:10 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 11/16] PCI/TSM: Remove the legacy guest request interface Aneesh Kumar K.V (Arm)
2026-10-08 6:11 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 12/16] PCI/TSM: Add vIOMMU-bound contexts for vdevices Aneesh Kumar K.V (Arm)
2026-10-08 6:18 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 13/16] iommufd/viommu: Select vIOMMU operations before allocation Aneesh Kumar K.V (Arm)
2026-10-08 6:27 ` sashiko-bot
2026-10-12 9:37 ` Aneesh Kumar K.V
2026-10-12 13:05 ` Jason Gunthorpe
2026-10-13 9:11 ` Aneesh Kumar K.V
2026-10-13 12:33 ` Jason Gunthorpe [this message]
2026-10-08 5:59 ` [PATCH v7 14/16] iommufd/viommu: Allow PCI TSM backends to provide vIOMMU operations Aneesh Kumar K.V (Arm)
2026-10-08 6:19 ` sashiko-bot
2026-10-12 9:55 ` Aneesh Kumar K.V
2026-10-08 5:59 ` [PATCH v7 15/16] iommufd: Allow vIOMMUs without a parent HWPT Aneesh Kumar K.V (Arm)
2026-10-08 6:24 ` sashiko-bot
2026-10-08 5:59 ` [PATCH v7 16/16] PCI/TSM: wait for vdevice contexts before removing a DSM Aneesh Kumar K.V (Arm)
2026-10-08 6:25 ` sashiko-bot
2026-10-12 20:34 ` Bjorn Helgaas
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=20261013123359.GS13920@nvidia.com \
--to=jgg@nvidia.com \
--cc=aneesh.kumar@kernel.org \
--cc=iommu@lists.linux.dev \
--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