Skip to content

Commit e843aed

Browse files
hegdevasantjoergroedel
authored andcommitted
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: Vasant Hegde <vasant.hegde@amd.com> Reviewed-by: Joerg Roedel <jroedel@suse.de> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/20241030063556.6104-10-vasant.hegde@amd.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 4b18ef8 commit e843aed

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

drivers/iommu/amd/amd_iommu_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ struct devid_map {
836836
*/
837837
struct iommu_dev_data {
838838
/*Protect against attach/detach races */
839-
spinlock_t lock;
839+
struct mutex mutex;
840840

841841
struct list_head list; /* For domain->dev_list */
842842
struct llist_node dev_data_list; /* For global dev_data_list */

drivers/iommu/amd/iommu.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static struct iommu_dev_data *alloc_dev_data(struct amd_iommu *iommu, u16 devid)
210210
if (!dev_data)
211211
return NULL;
212212

213-
spin_lock_init(&dev_data->lock);
213+
mutex_init(&dev_data->mutex);
214214
dev_data->devid = devid;
215215
ratelimit_default_init(&dev_data->rs);
216216

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

2095-
spin_lock(&dev_data->lock);
2095+
mutex_lock(&dev_data->mutex);
20962096

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

21202120
out:
2121-
spin_unlock(&dev_data->lock);
2121+
mutex_unlock(&dev_data->mutex);
21222122

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

2137-
spin_lock(&dev_data->lock);
2137+
mutex_lock(&dev_data->mutex);
21382138

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

21742174
out:
2175-
spin_unlock(&dev_data->lock);
2175+
mutex_unlock(&dev_data->mutex);
21762176

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

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

24772477
return 0;
24782478
}

0 commit comments

Comments
 (0)