Re: [PATCH 06/11] iommu: Expose group variants of dma ownership interfaces
From: Christoph Hellwig <hch@infradead.org>
Date: 2021-11-15 13:28:11
Also in:
linux-iommu, linux-pci, lkml
On Mon, Nov 15, 2021 at 10:05:47AM +0800, Lu Baolu wrote:
The vfio needs to set DMA_OWNER_USER for the entire group when attaching
The vfio subsystem? driver?
it to a vfio container. So expose group variants of setting/releasing dma ownership for this purpose. This also exposes the helper iommu_group_dma_owner_unclaimed() for vfio report to userspace if the group is viable to user assignment, for
.. for vfio to report .. ?
void iommu_device_release_dma_owner(struct device *dev, enum iommu_dma_owner owner); +int iommu_group_set_dma_owner(struct iommu_group *group, enum iommu_dma_owner owner, + struct file *user_file); +void iommu_group_release_dma_owner(struct iommu_group *group, enum iommu_dma_owner owner);
Pleae avoid all these overly long lines.
+static inline int iommu_group_set_dma_owner(struct iommu_group *group,
+ enum iommu_dma_owner owner,
+ struct file *user_file)
+{
+ return -EINVAL;
+}
+
+static inline void iommu_group_release_dma_owner(struct iommu_group *group,
+ enum iommu_dma_owner owner)
+{
+}
+
+static inline bool iommu_group_dma_owner_unclaimed(struct iommu_group *group)
+{
+ return false;
+}Why do we need these stubs? All potential callers should already require CONFIG_IOMMU_API? Same for the helpers added in patch 1, btw.
+ mutex_lock(&group->mutex); + ret = __iommu_group_set_dma_owner(group, owner, user_file); + mutex_unlock(&group->mutex);
+ mutex_lock(&group->mutex); + __iommu_group_release_dma_owner(group, owner); + mutex_unlock(&group->mutex);
Unless I'm missing something (just skipping over the patches), the existing callers also take the lock just around these calls, so we don't really need the __-prefixed lowlevel helpers.
+ mutex_lock(&group->mutex); + owner = group->dma_owner; + mutex_unlock(&group->mutex);
No need for a lock to read a single scalar.
+ + return owner == DMA_OWNER_NONE; +} +EXPORT_SYMBOL_GPL(iommu_group_dma_owner_unclaimed);