[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YwjauaF1sTP6l2j9@nvidia.com>
Date: Fri, 26 Aug 2022 11:37:45 -0300
From: Jason Gunthorpe <jgg@...dia.com>
To: Lu Baolu <baolu.lu@...ux.intel.com>
Cc: Joerg Roedel <joro@...tes.org>,
Christoph Hellwig <hch@...radead.org>,
Bjorn Helgaas <bhelgaas@...gle.com>,
Kevin Tian <kevin.tian@...el.com>,
Ashok Raj <ashok.raj@...el.com>, Will Deacon <will@...nel.org>,
Robin Murphy <robin.murphy@....com>,
Jean-Philippe Brucker <jean-philippe@...aro.com>,
Dave Jiang <dave.jiang@...el.com>,
Fenghua Yu <fenghua.yu@...el.com>,
Vinod Koul <vkoul@...nel.org>,
Eric Auger <eric.auger@...hat.com>,
Liu Yi L <yi.l.liu@...el.com>,
Jacob jun Pan <jacob.jun.pan@...el.com>,
Zhangfei Gao <zhangfei.gao@...aro.org>,
Zhu Tony <tony.zhu@...el.com>, iommu@...ts.linux.dev,
linux-pci@...r.kernel.org, linux-kernel@...r.kernel.org,
Jean-Philippe Brucker <jean-philippe@...aro.org>
Subject: Re: [PATCH v12 05/17] iommu: Add attach/detach_dev_pasid iommu
interface
On Fri, Aug 26, 2022 at 08:11:29PM +0800, Lu Baolu wrote:
> + * iommu_get_domain_for_dev_pasid() - Retrieve domain for @pasid of @dev
> + * @dev: the queried device
> + * @pasid: the pasid of the device
> + * @type: matched domain type, 0 for any match
> + *
> + * This is a variant of iommu_get_domain_for_dev(). It returns the existing
> + * domain attached to pasid of a device. It's only for internal use of the
> + * IOMMU subsystem.
If it is only for external use then why is it exported?
I would add something like:
Callers must hold a lock around this function, and both
iommu_attach/detach_dev_pasid() whenever a domain of type is being
manipulated. This API does not internally resolve races with
attach/detach.
> + * detaching from the device PASID.
> + *
> + * Return: attached domain on success, NULL otherwise.
> + */
> +struct iommu_domain *iommu_get_domain_for_dev_pasid(struct device *dev,
> + ioasid_t pasid,
> + unsigned int type)
> +{
> + struct iommu_domain *domain;
> + struct iommu_group *group;
> +
> + group = iommu_group_get(dev);
> + if (!group)
> + return NULL;
> + /*
> + * The xarray protects its internal state with RCU. Hence the domain
> + * obtained is either NULL or fully formed.
> + */
This has nothing to do with RCU
xa_lock() is used to ensure that the domain pointer remains valid
while we check the type since it blocks concurrent xa_erase().
Jason
Powered by blists - more mailing lists