]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
vdpa: Sync calls set/get config/status with cf_mutex
authorEli Cohen <elic@nvidia.com>
Wed, 5 Jan 2022 11:46:35 +0000 (13:46 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 19 Jan 2026 12:09:34 +0000 (13:09 +0100)
[ Upstream commit 73bc0dbb591baea322a7319c735e5f6c7dba9cfb ]

Add wrappers to get/set status and protect these operations with
cf_mutex to serialize these operations with respect to get/set config
operations.

Signed-off-by: Eli Cohen <elic@nvidia.com>
Link: https://lore.kernel.org/r/20220105114646.577224-4-elic@nvidia.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Stable-dep-of: e40b6abe0b12 ("virtio_vdpa: fix misleading return in void function")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/vdpa/vdpa.c
drivers/vhost/vdpa.c
drivers/virtio/virtio_vdpa.c
include/linux/vdpa.h

index b12fc70510bb7e91ce180a2c80396dcb828240f9..58eb448bf5b0c2b52aa504823db2fcf9c33f4af0 100644 (file)
@@ -22,6 +22,25 @@ static LIST_HEAD(mdev_head);
 static DEFINE_MUTEX(vdpa_dev_mutex);
 static DEFINE_IDA(vdpa_index_ida);
 
+u8 vdpa_get_status(struct vdpa_device *vdev)
+{
+       u8 status;
+
+       mutex_lock(&vdev->cf_mutex);
+       status = vdev->config->get_status(vdev);
+       mutex_unlock(&vdev->cf_mutex);
+       return status;
+}
+EXPORT_SYMBOL(vdpa_get_status);
+
+void vdpa_set_status(struct vdpa_device *vdev, u8 status)
+{
+       mutex_lock(&vdev->cf_mutex);
+       vdev->config->set_status(vdev, status);
+       mutex_unlock(&vdev->cf_mutex);
+}
+EXPORT_SYMBOL(vdpa_set_status);
+
 static struct genl_family vdpa_nl_family;
 
 static int vdpa_dev_probe(struct device *d)
index 0f61ca0598b71c197ce6e758e8a5512fea5820b0..802c84e296e21d60dc01b4344c392b7dd286da88 100644 (file)
@@ -143,10 +143,9 @@ static long vhost_vdpa_get_device_id(struct vhost_vdpa *v, u8 __user *argp)
 static long vhost_vdpa_get_status(struct vhost_vdpa *v, u8 __user *statusp)
 {
        struct vdpa_device *vdpa = v->vdpa;
-       const struct vdpa_config_ops *ops = vdpa->config;
        u8 status;
 
-       status = ops->get_status(vdpa);
+       status = vdpa_get_status(vdpa);
 
        if (copy_to_user(statusp, &status, sizeof(status)))
                return -EFAULT;
@@ -165,7 +164,7 @@ static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp)
        if (copy_from_user(&status, statusp, sizeof(status)))
                return -EFAULT;
 
-       status_old = ops->get_status(vdpa);
+       status_old = vdpa_get_status(vdpa);
 
        /*
         * Userspace shouldn't remove status bits unless reset the
@@ -183,7 +182,7 @@ static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp)
                if (ret)
                        return ret;
        } else
-               ops->set_status(vdpa, status);
+               vdpa_set_status(vdpa, status);
 
        if ((status & VIRTIO_CONFIG_S_DRIVER_OK) && !(status_old & VIRTIO_CONFIG_S_DRIVER_OK))
                for (i = 0; i < nvqs; i++)
index b5ab5f59f96ac61baf774067abf23abf90c86469..a85a10d65973f347481adadaab8ed5c0a51801b8 100644 (file)
@@ -91,9 +91,8 @@ static u8 virtio_vdpa_get_status(struct virtio_device *vdev)
 static void virtio_vdpa_set_status(struct virtio_device *vdev, u8 status)
 {
        struct vdpa_device *vdpa = vd_get_vdpa(vdev);
-       const struct vdpa_config_ops *ops = vdpa->config;
 
-       return ops->set_status(vdpa, status);
+       return vdpa_set_status(vdpa, status);
 }
 
 static void virtio_vdpa_reset(struct virtio_device *vdev)
index d26f5777f30f71f6ae48d8a61f42a8380004c18c..c0c8ed2c62fd8b90bd64b0190f10912fe7bc872e 100644 (file)
@@ -394,6 +394,9 @@ void vdpa_get_config(struct vdpa_device *vdev, unsigned int offset,
                     void *buf, unsigned int len);
 void vdpa_set_config(struct vdpa_device *dev, unsigned int offset,
                     const void *buf, unsigned int length);
+u8 vdpa_get_status(struct vdpa_device *vdev);
+void vdpa_set_status(struct vdpa_device *vdev, u8 status);
+
 /**
  * struct vdpa_mgmtdev_ops - vdpa device ops
  * @dev_add: Add a vdpa device using alloc and register