RE: [PATCH v3 02/15] iommu: Add device-centric DMA ownership interfaces

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> From: Jason Gunthorpe <jgg@xxxxxxxxxx>
> Sent: Wednesday, October 26, 2022 2:12 AM
> 
> From: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
> 
> These complement the group interfaces and are for use by VFIO. The main

s/VFIO/iommufd/

> difference is that multiple devices in the same group can all share the
> ownership by passing the same ownership pointer.
> 
> Move the common code into shared functions.
> 
> Signed-off-by: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
> Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
> ---
>  drivers/iommu/iommu.c | 116 +++++++++++++++++++++++++++++++++-------
> --
>  include/linux/iommu.h |  13 +++++
>  2 files changed, 104 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index 65a3b3d886dc00..e34dde68ae2b0d 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -3148,14 +3148,33 @@ static int
> __iommu_group_alloc_blocking_domain(struct iommu_group *group)
>  	return 0;
>  }
> 
> +static int __iommu_take_dma_ownership(struct iommu_group *group, void
> *owner)
> +{
> +	int ret;
> +
> +	if (group->domain && group->domain != group->default_domain)
> +		return  -EBUSY;

remove the space before -EBUSY

> +int iommu_device_claim_dma_owner(struct device *dev, void *owner)
>  {
> -	int ret;
> +	struct iommu_group *group = iommu_group_get(dev);
> +	int ret = 0;
> +
> +	if (!group)
> +		return -ENODEV;
> 
>  	mutex_lock(&group->mutex);
> -	if (WARN_ON(!group->owner_cnt || !group->owner))
> +	if (group->owner_cnt) {
> +		if (group->owner != owner) {
> +			ret = -EPERM;
> +			goto unlock_out;
> +		}

check owner!=NULL otherwise this call may inadvertently succeed
if the caller assigns a NULL owner while the group has already been
grabbed by a kernel driver.





[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux