Skip to content

Commit 7b3c9d3

Browse files
hegdevasantgregkh
authored andcommitted
iommu/amd: Convert dev_data lock from spinlock to mutex
[ Upstream commit e843aed ] 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> Stable-dep-of: faad224 ("iommu/amd: Fix clone_alias() to use the original device's devid") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 84bb17c commit 7b3c9d3

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

drivers/iommu/amd/amd_iommu_types.h

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

843843
struct list_head list; /* For domain->dev_list */
844844
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
@@ -225,7 +225,7 @@ static struct iommu_dev_data *alloc_dev_data(struct amd_iommu *iommu, u16 devid)
225225
if (!dev_data)
226226
return NULL;
227227

228-
spin_lock_init(&dev_data->lock);
228+
mutex_init(&dev_data->mutex);
229229
dev_data->devid = devid;
230230
ratelimit_default_init(&dev_data->rs);
231231

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

2132-
spin_lock(&dev_data->lock);
2132+
mutex_lock(&dev_data->mutex);
21332133

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

21572157
out:
2158-
spin_unlock(&dev_data->lock);
2158+
mutex_unlock(&dev_data->mutex);
21592159

21602160
return ret;
21612161
}
@@ -2171,7 +2171,7 @@ static void detach_device(struct device *dev)
21712171
bool ppr = dev_data->ppr;
21722172
unsigned long flags;
21732173

2174-
spin_lock(&dev_data->lock);
2174+
mutex_lock(&dev_data->mutex);
21752175

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

22112211
out:
2212-
spin_unlock(&dev_data->lock);
2212+
mutex_unlock(&dev_data->mutex);
22132213

22142214
/* Remove IOPF handler */
22152215
if (ppr)
@@ -2486,9 +2486,9 @@ static int blocked_domain_attach_device(struct iommu_domain *domain,
24862486
detach_device(dev);
24872487

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

24932493
return 0;
24942494
}

0 commit comments

Comments
 (0)