Commit e843aedb authored by Vasant Hegde's avatar Vasant Hegde Committed by Joerg Roedel
Browse files

iommu/amd: Convert dev_data lock from spinlock to mutex



Currently in attach device path it takes dev_data->spinlock. But as per
design attach device path can sleep. Also if device is PRI capable then
it adds device to IOMMU fault handler queue which takes mutex. Hence
currently PRI enablement is done outside dev_data lock.

Covert dev_data lock from spinlock to mutex so that it follows the
design and also PRI enablement can be done properly.

Signed-off-by: default avatarVasant Hegde <vasant.hegde@amd.com>
Reviewed-by: default avatarJoerg Roedel <jroedel@suse.de>
Reviewed-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/20241030063556.6104-10-vasant.hegde@amd.com


Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 4b18ef84
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -836,7 +836,7 @@ struct devid_map {
 */
struct iommu_dev_data {
	/*Protect against attach/detach races */
	spinlock_t lock;
	struct mutex mutex;

	struct list_head list;		  /* For domain->dev_list */
	struct llist_node dev_data_list;  /* For global dev_data_list */
+7 −7
Original line number Diff line number Diff line
@@ -210,7 +210,7 @@ static struct iommu_dev_data *alloc_dev_data(struct amd_iommu *iommu, u16 devid)
	if (!dev_data)
		return NULL;

	spin_lock_init(&dev_data->lock);
	mutex_init(&dev_data->mutex);
	dev_data->devid = devid;
	ratelimit_default_init(&dev_data->rs);

@@ -2092,7 +2092,7 @@ static int attach_device(struct device *dev,
	struct amd_iommu *iommu = get_amd_iommu_from_dev_data(dev_data);
	int ret = 0;

	spin_lock(&dev_data->lock);
	mutex_lock(&dev_data->mutex);

	if (dev_data->domain != NULL) {
		ret = -EBUSY;
@@ -2118,7 +2118,7 @@ static int attach_device(struct device *dev,
	}

out:
	spin_unlock(&dev_data->lock);
	mutex_unlock(&dev_data->mutex);

	return ret;
}
@@ -2134,7 +2134,7 @@ static void detach_device(struct device *dev)
	bool ppr = dev_data->ppr;
	unsigned long flags;

	spin_lock(&dev_data->lock);
	mutex_lock(&dev_data->mutex);

	/*
	 * First check if the device is still attached. It might already
@@ -2172,7 +2172,7 @@ static void detach_device(struct device *dev)
	pdom_detach_iommu(iommu, domain);

out:
	spin_unlock(&dev_data->lock);
	mutex_unlock(&dev_data->mutex);

	/* Remove IOPF handler */
	if (ppr)
@@ -2470,9 +2470,9 @@ static int blocked_domain_attach_device(struct iommu_domain *domain,
		detach_device(dev);

	/* Clear DTE and flush the entry */
	spin_lock(&dev_data->lock);
	mutex_lock(&dev_data->mutex);
	dev_update_dte(dev_data, false);
	spin_unlock(&dev_data->lock);
	mutex_unlock(&dev_data->mutex);

	return 0;
}