]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommu/amd: Convert dev_data lock from spinlock to mutex
authorVasant Hegde <vasant.hegde@amd.com>
Wed, 30 Oct 2024 06:35:53 +0000 (06:35 +0000)
committerJoerg Roedel <jroedel@suse.de>
Wed, 30 Oct 2024 10:06:45 +0000 (11:06 +0100)
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>
drivers/iommu/amd/amd_iommu_types.h
drivers/iommu/amd/iommu.c

index f44de5f316257546c86dca5f88f46b21cf7fe68b..fdb0357e0bb91afb5a0bb72dabe73552dcf95b1b 100644 (file)
@@ -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 */
index 4426e68de8086c525c7238665c6f462c55acbf3a..599aae889be887fd3e45aea7709b364825f129a7 100644 (file)
@@ -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;
 }