Merge tag 'driver-core-5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / drivers / vdpa / vdpa.c
index 2ff7de5e6b2f096000d0885bce7c6889b9f95d54..ebf2f363fbe7864febece8072af5fee1e3493d76 100644 (file)
@@ -23,9 +23,9 @@ static DEFINE_IDA(vdpa_index_ida);
 
 void vdpa_set_status(struct vdpa_device *vdev, u8 status)
 {
-       mutex_lock(&vdev->cf_mutex);
+       down_write(&vdev->cf_lock);
        vdev->config->set_status(vdev, status);
-       mutex_unlock(&vdev->cf_mutex);
+       up_write(&vdev->cf_lock);
 }
 EXPORT_SYMBOL(vdpa_set_status);
 
@@ -77,32 +77,11 @@ static ssize_t driver_override_store(struct device *dev,
                                     const char *buf, size_t count)
 {
        struct vdpa_device *vdev = dev_to_vdpa(dev);
-       const char *driver_override, *old;
-       char *cp;
+       int ret;
 
-       /* We need to keep extra room for a newline */
-       if (count >= (PAGE_SIZE - 1))
-               return -EINVAL;
-
-       driver_override = kstrndup(buf, count, GFP_KERNEL);
-       if (!driver_override)
-               return -ENOMEM;
-
-       cp = strchr(driver_override, '\n');
-       if (cp)
-               *cp = '\0';
-
-       device_lock(dev);
-       old = vdev->driver_override;
-       if (strlen(driver_override)) {
-               vdev->driver_override = driver_override;
-       } else {
-               kfree(driver_override);
-               vdev->driver_override = NULL;
-       }
-       device_unlock(dev);
-
-       kfree(old);
+       ret = driver_set_override(dev, &vdev->driver_override, buf, count);
+       if (ret)
+               return ret;
 
        return count;
 }
@@ -148,7 +127,6 @@ static void vdpa_release_dev(struct device *d)
                ops->free(vdev);
 
        ida_simple_remove(&vdpa_index_ida, vdev->index);
-       mutex_destroy(&vdev->cf_mutex);
        kfree(vdev->driver_override);
        kfree(vdev);
 }
@@ -159,6 +137,8 @@ static void vdpa_release_dev(struct device *d)
  * initialized but before registered.
  * @parent: the parent device
  * @config: the bus operations that is supported by this device
+ * @ngroups: number of groups supported by this device
+ * @nas: number of address spaces supported by this device
  * @size: size of the parent structure that contains private data
  * @name: name of the vdpa device; optional.
  * @use_va: indicate whether virtual address must be used by this device
@@ -171,6 +151,7 @@ static void vdpa_release_dev(struct device *d)
  */
 struct vdpa_device *__vdpa_alloc_device(struct device *parent,
                                        const struct vdpa_config_ops *config,
+                                       unsigned int ngroups, unsigned int nas,
                                        size_t size, const char *name,
                                        bool use_va)
 {
@@ -203,6 +184,8 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent,
        vdev->config = config;
        vdev->features_valid = false;
        vdev->use_va = use_va;
+       vdev->ngroups = ngroups;
+       vdev->nas = nas;
 
        if (name)
                err = dev_set_name(&vdev->dev, "%s", name);
@@ -211,7 +194,7 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent,
        if (err)
                goto err_name;
 
-       mutex_init(&vdev->cf_mutex);
+       init_rwsem(&vdev->cf_lock);
        device_initialize(&vdev->dev);
 
        return vdev;
@@ -407,9 +390,9 @@ static void vdpa_get_config_unlocked(struct vdpa_device *vdev,
 void vdpa_get_config(struct vdpa_device *vdev, unsigned int offset,
                     void *buf, unsigned int len)
 {
-       mutex_lock(&vdev->cf_mutex);
+       down_read(&vdev->cf_lock);
        vdpa_get_config_unlocked(vdev, offset, buf, len);
-       mutex_unlock(&vdev->cf_mutex);
+       up_read(&vdev->cf_lock);
 }
 EXPORT_SYMBOL_GPL(vdpa_get_config);
 
@@ -423,9 +406,9 @@ EXPORT_SYMBOL_GPL(vdpa_get_config);
 void vdpa_set_config(struct vdpa_device *vdev, unsigned int offset,
                     const void *buf, unsigned int length)
 {
-       mutex_lock(&vdev->cf_mutex);
+       down_write(&vdev->cf_lock);
        vdev->config->set_config(vdev, offset, buf, length);
-       mutex_unlock(&vdev->cf_mutex);
+       up_write(&vdev->cf_lock);
 }
 EXPORT_SYMBOL_GPL(vdpa_set_config);
 
@@ -866,7 +849,7 @@ vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid,
        u8 status;
        int err;
 
-       mutex_lock(&vdev->cf_mutex);
+       down_read(&vdev->cf_lock);
        status = vdev->config->get_status(vdev);
        if (!(status & VIRTIO_CONFIG_S_FEATURES_OK)) {
                NL_SET_ERR_MSG_MOD(extack, "Features negotiation not completed");
@@ -903,14 +886,14 @@ vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid,
        if (err)
                goto msg_err;
 
-       mutex_unlock(&vdev->cf_mutex);
+       up_read(&vdev->cf_lock);
        genlmsg_end(msg, hdr);
        return 0;
 
 msg_err:
        genlmsg_cancel(msg, hdr);
 out:
-       mutex_unlock(&vdev->cf_mutex);
+       up_read(&vdev->cf_lock);
        return err;
 }
 
@@ -954,7 +937,7 @@ static int vendor_stats_fill(struct vdpa_device *vdev, struct sk_buff *msg,
 {
        int err;
 
-       mutex_lock(&vdev->cf_mutex);
+       down_read(&vdev->cf_lock);
        if (!vdev->config->get_vendor_vq_stats) {
                err = -EOPNOTSUPP;
                goto out;
@@ -962,7 +945,7 @@ static int vendor_stats_fill(struct vdpa_device *vdev, struct sk_buff *msg,
 
        err = vdpa_fill_stats_rec(vdev, msg, info, index);
 out:
-       mutex_unlock(&vdev->cf_mutex);
+       up_read(&vdev->cf_lock);
        return err;
 }