[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250704175425.GM904431@ziepe.ca>
Date: Fri, 4 Jul 2025 14:54:25 -0300
From: Jason Gunthorpe <jgg@...pe.ca>
To: Benjamin Gaignard <benjamin.gaignard@...labora.com>
Cc: joro@...tes.org, will@...nel.org, robin.murphy@....com, robh@...nel.org,
krzk+dt@...nel.org, conor+dt@...nel.org, heiko@...ech.de,
nicolas.dufresne@...labora.com, iommu@...ts.linux.dev,
devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org,
linux-rockchip@...ts.infradead.org, kernel@...labora.com
Subject: Re: [PATCH v4 3/5] iommu: Add verisilicon IOMMU driver
On Mon, Jun 23, 2025 at 05:39:27PM +0200, Benjamin Gaignard wrote:
> The Verisilicon IOMMU hardware block can be found in combination
> with Verisilicon hardware video codecs (encoders or decoders) on
> different SoCs.
> Enable it will allow us to use non contiguous memory allocators
> for Verisilicon video codecs.
>
> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@...labora.com>
> ---
> change in version 4:
> - Kconfig dependencies
> - Fix the remarks done by Jason and Robin: locking, clocks, macros
> probing, pm_runtime, atomic allocation.
It broadly seems OK to me
Though I did notice this:
> +static struct iommu_domain *vsi_iommu_domain_alloc_paging(struct device *dev)
> +{
> + struct vsi_iommu *iommu = dev_iommu_priv_get(dev);
> + struct vsi_iommu_domain *vsi_domain;
> +
> + vsi_domain = kzalloc(sizeof(*vsi_domain), GFP_KERNEL);
> + if (!vsi_domain)
> + return NULL;
> +
> + vsi_domain->iommu = iommu;
So we store the iommu in the domain? And use the iommu->lock all over
the place
> +static int vsi_iommu_attach_device(struct iommu_domain *domain,
> + struct device *dev)
> +{
> + struct vsi_iommu *iommu = dev_iommu_priv_get(dev);
> + struct vsi_iommu_domain *vsi_domain = to_vsi_domain(domain);
> + unsigned long flags;
> + int ret = 0;
> +
> + ret = pm_runtime_resume_and_get(iommu->dev);
> + if (ret < 0)
> + return ret;
> +
> + spin_lock_irqsave(&iommu->lock, flags);
> + /* iommu already attached */
> + if (iommu->domain == domain)
> + goto unlock;
But here we don't check that the domain matches the iommu of dev.
This seems a bit weird to me, I didn't quite get why the domain uses
iommu->lock instead of just having its own per-domain lock?
But if it does use iommu->lock then this does need to prevent using
domains with the wrong iommu because the also use the wrong lock and
then this:
> +
> + vsi_iommu_enable(iommu, domain);
> + list_add_tail(&iommu->node, &vsi_domain->iommus);
Is not safe?
Jason
Powered by blists - more mailing lists