]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
s390/ap: Rename mutex ap_perms_mutex to ap_attr_mutex
authorHarald Freudenberger <freude@linux.ibm.com>
Wed, 19 Nov 2025 15:27:37 +0000 (16:27 +0100)
committerHeiko Carstens <hca@linux.ibm.com>
Mon, 24 Nov 2025 10:43:06 +0000 (11:43 +0100)
The mutex ap_perms_mutex was already used not only for protection
of the struct ap_perms ap_perms variable but also for an consistent
update of the AP bus sysfs attributes apmask and aqmask.

So rename this mutex to ap_attr_mutex which better reflects the
current use. This is also a preparation for an upcoming patch which
will use this mutex to lock updates on a new sysfs attribute.

Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Holger Dengler <dengler@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
drivers/s390/crypto/ap_bus.c
drivers/s390/crypto/ap_bus.h
drivers/s390/crypto/vfio_ap_ops.c
drivers/s390/crypto/zcrypt_api.c

index 2dbfd8886038d38c2ddb4c9519709df9ad89a425..3781b970fe619d9516781c8b2782fac976bbab53 100644 (file)
@@ -86,8 +86,12 @@ DEFINE_SPINLOCK(ap_queues_lock);
 /* Default permissions (ioctl, card and domain masking) */
 struct ap_perms ap_perms;
 EXPORT_SYMBOL(ap_perms);
-DEFINE_MUTEX(ap_perms_mutex);
-EXPORT_SYMBOL(ap_perms_mutex);
+/*
+ * Mutex for consistent read and write of the ap_perms struct
+ * and the ap bus sysfs attributes apmask and aqmask.
+ */
+DEFINE_MUTEX(ap_attr_mutex);
+EXPORT_SYMBOL(ap_attr_mutex);
 
 /* # of bindings complete since init */
 static atomic64_t ap_bindings_complete_count = ATOMIC64_INIT(0);
@@ -871,10 +875,10 @@ static int __ap_revise_reserved(struct device *dev, void *dummy)
                                }
                        }
                } else {
-                       mutex_lock(&ap_perms_mutex);
+                       mutex_lock(&ap_attr_mutex);
                        devres = test_bit_inv(card, ap_perms.apm) &&
                                test_bit_inv(queue, ap_perms.aqm);
-                       mutex_unlock(&ap_perms_mutex);
+                       mutex_unlock(&ap_attr_mutex);
                        drvres = to_ap_drv(dev->driver)->flags
                                & AP_DRIVER_FLAG_DEFAULT;
                        if (!!devres != !!drvres) {
@@ -902,7 +906,7 @@ static void ap_bus_revise_bindings(void)
  * @card: the APID of the adapter card to check
  * @queue: the APQI of the queue to check
  *
- * Note: the ap_perms_mutex must be locked by the caller of this function.
+ * Note: the ap_attr_mutex must be locked by the caller of this function.
  *
  * Return: an int specifying whether the AP adapter is reserved for the host (1)
  *        or not (0).
@@ -944,7 +948,7 @@ EXPORT_SYMBOL(ap_owned_by_def_drv);
  * @apm: a bitmap specifying a set of APIDs comprising the APQNs to check
  * @aqm: a bitmap specifying a set of APQIs comprising the APQNs to check
  *
- * Note: the ap_perms_mutex must be locked by the caller of this function.
+ * Note: the ap_attr_mutex must be locked by the caller of this function.
  *
  * Return: an int specifying whether each APQN is reserved for the host (1) or
  *        not (0)
@@ -987,10 +991,10 @@ static int ap_device_probe(struct device *dev)
                                   ap_drv->driver.name))
                                goto out;
                } else {
-                       mutex_lock(&ap_perms_mutex);
+                       mutex_lock(&ap_attr_mutex);
                        devres = test_bit_inv(card, ap_perms.apm) &&
                                test_bit_inv(queue, ap_perms.aqm);
-                       mutex_unlock(&ap_perms_mutex);
+                       mutex_unlock(&ap_attr_mutex);
                        drvres = ap_drv->flags & AP_DRIVER_FLAG_DEFAULT;
                        if (!!devres != !!drvres)
                                goto out;
@@ -1483,12 +1487,12 @@ static ssize_t apmask_show(const struct bus_type *bus, char *buf)
 {
        int rc;
 
-       if (mutex_lock_interruptible(&ap_perms_mutex))
+       if (mutex_lock_interruptible(&ap_attr_mutex))
                return -ERESTARTSYS;
        rc = sysfs_emit(buf, "0x%016lx%016lx%016lx%016lx\n",
                        ap_perms.apm[0], ap_perms.apm[1],
                        ap_perms.apm[2], ap_perms.apm[3]);
-       mutex_unlock(&ap_perms_mutex);
+       mutex_unlock(&ap_attr_mutex);
 
        return rc;
 }
@@ -1547,7 +1551,7 @@ static ssize_t apmask_store(const struct bus_type *bus, const char *buf,
        int rc, changes = 0;
        DECLARE_BITMAP(newapm, AP_DEVICES);
 
-       if (mutex_lock_interruptible(&ap_perms_mutex))
+       if (mutex_lock_interruptible(&ap_attr_mutex))
                return -ERESTARTSYS;
 
        rc = ap_parse_bitmap_str(buf, ap_perms.apm, AP_DEVICES, newapm);
@@ -1559,7 +1563,7 @@ static ssize_t apmask_store(const struct bus_type *bus, const char *buf,
                rc = apmask_commit(newapm);
 
 done:
-       mutex_unlock(&ap_perms_mutex);
+       mutex_unlock(&ap_attr_mutex);
        if (rc)
                return rc;
 
@@ -1577,12 +1581,12 @@ static ssize_t aqmask_show(const struct bus_type *bus, char *buf)
 {
        int rc;
 
-       if (mutex_lock_interruptible(&ap_perms_mutex))
+       if (mutex_lock_interruptible(&ap_attr_mutex))
                return -ERESTARTSYS;
        rc = sysfs_emit(buf, "0x%016lx%016lx%016lx%016lx\n",
                        ap_perms.aqm[0], ap_perms.aqm[1],
                        ap_perms.aqm[2], ap_perms.aqm[3]);
-       mutex_unlock(&ap_perms_mutex);
+       mutex_unlock(&ap_attr_mutex);
 
        return rc;
 }
@@ -1641,7 +1645,7 @@ static ssize_t aqmask_store(const struct bus_type *bus, const char *buf,
        int rc, changes = 0;
        DECLARE_BITMAP(newaqm, AP_DOMAINS);
 
-       if (mutex_lock_interruptible(&ap_perms_mutex))
+       if (mutex_lock_interruptible(&ap_attr_mutex))
                return -ERESTARTSYS;
 
        rc = ap_parse_bitmap_str(buf, ap_perms.aqm, AP_DOMAINS, newaqm);
@@ -1653,7 +1657,7 @@ static ssize_t aqmask_store(const struct bus_type *bus, const char *buf,
                rc = aqmask_commit(newaqm);
 
 done:
-       mutex_unlock(&ap_perms_mutex);
+       mutex_unlock(&ap_attr_mutex);
        if (rc)
                return rc;
 
@@ -2524,14 +2528,14 @@ static void __init ap_perms_init(void)
        if (apm_str) {
                memset(&ap_perms.apm, 0, sizeof(ap_perms.apm));
                ap_parse_mask_str(apm_str, ap_perms.apm, AP_DEVICES,
-                                 &ap_perms_mutex);
+                                 &ap_attr_mutex);
        }
 
        /* aqm kernel parameter string */
        if (aqm_str) {
                memset(&ap_perms.aqm, 0, sizeof(ap_perms.aqm));
                ap_parse_mask_str(aqm_str, ap_perms.aqm, AP_DOMAINS,
-                                 &ap_perms_mutex);
+                                 &ap_attr_mutex);
        }
 }
 
index 9d54a6c5d50a91d67b4e94c4657e6a1901e9159d..2b8804fc68b45bec270b4f7112a7eef880486031 100644 (file)
@@ -281,7 +281,7 @@ struct ap_perms {
 };
 
 extern struct ap_perms ap_perms;
-extern struct mutex ap_perms_mutex;
+extern struct mutex ap_attr_mutex;
 
 /*
  * Get ap_queue device for this qid.
index eb5ff49f6fe7de1d301a2d4740ce0f346579f610..48da32ad04938939d125e76d3f59a59d2d3c4883 100644 (file)
@@ -968,7 +968,7 @@ static int vfio_ap_mdev_verify_no_sharing(struct ap_matrix_mdev *assignee,
  *
  * Return: One of the following values:
  * o the error returned from the ap_apqn_in_matrix_owned_by_def_drv() function,
- *   most likely -EBUSY indicating the ap_perms_mutex lock is already held.
+ *   most likely -EBUSY indicating the ap_attr_mutex lock is already held.
  * o EADDRNOTAVAIL if an APQN assigned to @matrix_mdev is reserved for the
  *                zcrypt default driver.
  * o EADDRINUSE if an APQN assigned to @matrix_mdev is assigned to another mdev
@@ -1079,7 +1079,7 @@ static ssize_t assign_adapter_store(struct device *dev,
        DECLARE_BITMAP(apm_filtered, AP_DEVICES);
        struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
 
-       mutex_lock(&ap_perms_mutex);
+       mutex_lock(&ap_attr_mutex);
        get_update_locks_for_mdev(matrix_mdev);
 
        ret = kstrtoul(buf, 0, &apid);
@@ -1114,7 +1114,7 @@ static ssize_t assign_adapter_store(struct device *dev,
        ret = count;
 done:
        release_update_locks_for_mdev(matrix_mdev);
-       mutex_unlock(&ap_perms_mutex);
+       mutex_unlock(&ap_attr_mutex);
 
        return ret;
 }
@@ -1303,7 +1303,7 @@ static ssize_t assign_domain_store(struct device *dev,
        DECLARE_BITMAP(apm_filtered, AP_DEVICES);
        struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
 
-       mutex_lock(&ap_perms_mutex);
+       mutex_lock(&ap_attr_mutex);
        get_update_locks_for_mdev(matrix_mdev);
 
        ret = kstrtoul(buf, 0, &apqi);
@@ -1338,7 +1338,7 @@ static ssize_t assign_domain_store(struct device *dev,
        ret = count;
 done:
        release_update_locks_for_mdev(matrix_mdev);
-       mutex_unlock(&ap_perms_mutex);
+       mutex_unlock(&ap_attr_mutex);
 
        return ret;
 }
@@ -1718,7 +1718,7 @@ static ssize_t ap_config_store(struct device *dev, struct device_attribute *attr
                return -ENOMEM;
        rest = newbuf;
 
-       mutex_lock(&ap_perms_mutex);
+       mutex_lock(&ap_attr_mutex);
        get_update_locks_for_mdev(matrix_mdev);
 
        /* Save old state */
@@ -1779,7 +1779,7 @@ static ssize_t ap_config_store(struct device *dev, struct device_attribute *attr
        }
 out:
        release_update_locks_for_mdev(matrix_mdev);
-       mutex_unlock(&ap_perms_mutex);
+       mutex_unlock(&ap_attr_mutex);
        kfree(newbuf);
        return rc;
 }
index 351934f818dedce094d89cd4e4b756cf63aecff9..de93a953d38059ef3a1ab30047b365a8e04782f9 100644 (file)
@@ -162,7 +162,7 @@ static ssize_t ioctlmask_show(struct device *dev,
        struct zcdn_device *zcdndev = to_zcdn_dev(dev);
        int i, n;
 
-       if (mutex_lock_interruptible(&ap_perms_mutex))
+       if (mutex_lock_interruptible(&ap_attr_mutex))
                return -ERESTARTSYS;
 
        n = sysfs_emit(buf, "0x");
@@ -170,7 +170,7 @@ static ssize_t ioctlmask_show(struct device *dev,
                n += sysfs_emit_at(buf, n, "%016lx", zcdndev->perms.ioctlm[i]);
        n += sysfs_emit_at(buf, n, "\n");
 
-       mutex_unlock(&ap_perms_mutex);
+       mutex_unlock(&ap_attr_mutex);
 
        return n;
 }
@@ -183,7 +183,7 @@ static ssize_t ioctlmask_store(struct device *dev,
        struct zcdn_device *zcdndev = to_zcdn_dev(dev);
 
        rc = ap_parse_mask_str(buf, zcdndev->perms.ioctlm,
-                              AP_IOCTLS, &ap_perms_mutex);
+                              AP_IOCTLS, &ap_attr_mutex);
        if (rc)
                return rc;
 
@@ -199,7 +199,7 @@ static ssize_t apmask_show(struct device *dev,
        struct zcdn_device *zcdndev = to_zcdn_dev(dev);
        int i, n;
 
-       if (mutex_lock_interruptible(&ap_perms_mutex))
+       if (mutex_lock_interruptible(&ap_attr_mutex))
                return -ERESTARTSYS;
 
        n = sysfs_emit(buf, "0x");
@@ -207,7 +207,7 @@ static ssize_t apmask_show(struct device *dev,
                n += sysfs_emit_at(buf, n, "%016lx", zcdndev->perms.apm[i]);
        n += sysfs_emit_at(buf, n, "\n");
 
-       mutex_unlock(&ap_perms_mutex);
+       mutex_unlock(&ap_attr_mutex);
 
        return n;
 }
@@ -220,7 +220,7 @@ static ssize_t apmask_store(struct device *dev,
        struct zcdn_device *zcdndev = to_zcdn_dev(dev);
 
        rc = ap_parse_mask_str(buf, zcdndev->perms.apm,
-                              AP_DEVICES, &ap_perms_mutex);
+                              AP_DEVICES, &ap_attr_mutex);
        if (rc)
                return rc;
 
@@ -236,7 +236,7 @@ static ssize_t aqmask_show(struct device *dev,
        struct zcdn_device *zcdndev = to_zcdn_dev(dev);
        int i, n;
 
-       if (mutex_lock_interruptible(&ap_perms_mutex))
+       if (mutex_lock_interruptible(&ap_attr_mutex))
                return -ERESTARTSYS;
 
        n = sysfs_emit(buf, "0x");
@@ -244,7 +244,7 @@ static ssize_t aqmask_show(struct device *dev,
                n += sysfs_emit_at(buf, n, "%016lx", zcdndev->perms.aqm[i]);
        n += sysfs_emit_at(buf, n, "\n");
 
-       mutex_unlock(&ap_perms_mutex);
+       mutex_unlock(&ap_attr_mutex);
 
        return n;
 }
@@ -257,7 +257,7 @@ static ssize_t aqmask_store(struct device *dev,
        struct zcdn_device *zcdndev = to_zcdn_dev(dev);
 
        rc = ap_parse_mask_str(buf, zcdndev->perms.aqm,
-                              AP_DOMAINS, &ap_perms_mutex);
+                              AP_DOMAINS, &ap_attr_mutex);
        if (rc)
                return rc;
 
@@ -273,7 +273,7 @@ static ssize_t admask_show(struct device *dev,
        struct zcdn_device *zcdndev = to_zcdn_dev(dev);
        int i, n;
 
-       if (mutex_lock_interruptible(&ap_perms_mutex))
+       if (mutex_lock_interruptible(&ap_attr_mutex))
                return -ERESTARTSYS;
 
        n = sysfs_emit(buf, "0x");
@@ -281,7 +281,7 @@ static ssize_t admask_show(struct device *dev,
                n += sysfs_emit_at(buf, n, "%016lx", zcdndev->perms.adm[i]);
        n += sysfs_emit_at(buf, n, "\n");
 
-       mutex_unlock(&ap_perms_mutex);
+       mutex_unlock(&ap_attr_mutex);
 
        return n;
 }
@@ -294,7 +294,7 @@ static ssize_t admask_store(struct device *dev,
        struct zcdn_device *zcdndev = to_zcdn_dev(dev);
 
        rc = ap_parse_mask_str(buf, zcdndev->perms.adm,
-                              AP_DOMAINS, &ap_perms_mutex);
+                              AP_DOMAINS, &ap_attr_mutex);
        if (rc)
                return rc;
 
@@ -370,7 +370,7 @@ static int zcdn_create(const char *name)
        int i, rc = 0;
        struct zcdn_device *zcdndev;
 
-       if (mutex_lock_interruptible(&ap_perms_mutex))
+       if (mutex_lock_interruptible(&ap_attr_mutex))
                return -ERESTARTSYS;
 
        /* check if device node with this name already exists */
@@ -425,7 +425,7 @@ static int zcdn_create(const char *name)
                        __func__, MAJOR(devt), MINOR(devt));
 
 unlockout:
-       mutex_unlock(&ap_perms_mutex);
+       mutex_unlock(&ap_attr_mutex);
        return rc;
 }
 
@@ -434,7 +434,7 @@ static int zcdn_destroy(const char *name)
        int rc = 0;
        struct zcdn_device *zcdndev;
 
-       if (mutex_lock_interruptible(&ap_perms_mutex))
+       if (mutex_lock_interruptible(&ap_attr_mutex))
                return -ERESTARTSYS;
 
        /* try to find this zcdn device */
@@ -452,7 +452,7 @@ static int zcdn_destroy(const char *name)
        device_unregister(&zcdndev->device);
 
 unlockout:
-       mutex_unlock(&ap_perms_mutex);
+       mutex_unlock(&ap_attr_mutex);
        return rc;
 }
 
@@ -462,7 +462,7 @@ static void zcdn_destroy_all(void)
        dev_t devt;
        struct zcdn_device *zcdndev;
 
-       mutex_lock(&ap_perms_mutex);
+       mutex_lock(&ap_attr_mutex);
        for (i = 0; i < ZCRYPT_MAX_MINOR_NODES; i++) {
                devt = MKDEV(MAJOR(zcrypt_devt), MINOR(zcrypt_devt) + i);
                zcdndev = find_zcdndev_by_devt(devt);
@@ -471,7 +471,7 @@ static void zcdn_destroy_all(void)
                        device_unregister(&zcdndev->device);
                }
        }
-       mutex_unlock(&ap_perms_mutex);
+       mutex_unlock(&ap_attr_mutex);
 }
 
 /*
@@ -508,11 +508,11 @@ static int zcrypt_open(struct inode *inode, struct file *filp)
        if (filp->f_inode->i_cdev == &zcrypt_cdev) {
                struct zcdn_device *zcdndev;
 
-               if (mutex_lock_interruptible(&ap_perms_mutex))
+               if (mutex_lock_interruptible(&ap_attr_mutex))
                        return -ERESTARTSYS;
                zcdndev = find_zcdndev_by_devt(filp->f_inode->i_rdev);
                /* find returns a reference, no get_device() needed */
-               mutex_unlock(&ap_perms_mutex);
+               mutex_unlock(&ap_attr_mutex);
                if (zcdndev)
                        perms = &zcdndev->perms;
        }
@@ -532,9 +532,9 @@ static int zcrypt_release(struct inode *inode, struct file *filp)
        if (filp->f_inode->i_cdev == &zcrypt_cdev) {
                struct zcdn_device *zcdndev;
 
-               mutex_lock(&ap_perms_mutex);
+               mutex_lock(&ap_attr_mutex);
                zcdndev = find_zcdndev_by_devt(filp->f_inode->i_rdev);
-               mutex_unlock(&ap_perms_mutex);
+               mutex_unlock(&ap_attr_mutex);
                if (zcdndev) {
                        /* 2 puts here: one for find, one for open */
                        put_device(&zcdndev->device);