Skip to content

Commit 73bc0db

Browse files
elic307imstsirkin
authored andcommitted
vdpa: Sync calls set/get config/status with cf_mutex
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent a7f46ba commit 73bc0db

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

drivers/vdpa/vdpa.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,25 @@ static LIST_HEAD(mdev_head);
2121
static DEFINE_MUTEX(vdpa_dev_mutex);
2222
static DEFINE_IDA(vdpa_index_ida);
2323

24+
u8 vdpa_get_status(struct vdpa_device *vdev)
25+
{
26+
u8 status;
27+
28+
mutex_lock(&vdev->cf_mutex);
29+
status = vdev->config->get_status(vdev);
30+
mutex_unlock(&vdev->cf_mutex);
31+
return status;
32+
}
33+
EXPORT_SYMBOL(vdpa_get_status);
34+
35+
void vdpa_set_status(struct vdpa_device *vdev, u8 status)
36+
{
37+
mutex_lock(&vdev->cf_mutex);
38+
vdev->config->set_status(vdev, status);
39+
mutex_unlock(&vdev->cf_mutex);
40+
}
41+
EXPORT_SYMBOL(vdpa_set_status);
42+
2443
static struct genl_family vdpa_nl_family;
2544

2645
static int vdpa_dev_probe(struct device *d)

drivers/vhost/vdpa.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,9 @@ static long vhost_vdpa_get_device_id(struct vhost_vdpa *v, u8 __user *argp)
142142
static long vhost_vdpa_get_status(struct vhost_vdpa *v, u8 __user *statusp)
143143
{
144144
struct vdpa_device *vdpa = v->vdpa;
145-
const struct vdpa_config_ops *ops = vdpa->config;
146145
u8 status;
147146

148-
status = ops->get_status(vdpa);
147+
status = vdpa_get_status(vdpa);
149148

150149
if (copy_to_user(statusp, &status, sizeof(status)))
151150
return -EFAULT;
@@ -164,7 +163,7 @@ static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp)
164163
if (copy_from_user(&status, statusp, sizeof(status)))
165164
return -EFAULT;
166165

167-
status_old = ops->get_status(vdpa);
166+
status_old = vdpa_get_status(vdpa);
168167

169168
/*
170169
* Userspace shouldn't remove status bits unless reset the
@@ -182,7 +181,7 @@ static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp)
182181
if (ret)
183182
return ret;
184183
} else
185-
ops->set_status(vdpa, status);
184+
vdpa_set_status(vdpa, status);
186185

187186
if ((status & VIRTIO_CONFIG_S_DRIVER_OK) && !(status_old & VIRTIO_CONFIG_S_DRIVER_OK))
188187
for (i = 0; i < nvqs; i++)

drivers/virtio/virtio_vdpa.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ static u8 virtio_vdpa_get_status(struct virtio_device *vdev)
9191
static void virtio_vdpa_set_status(struct virtio_device *vdev, u8 status)
9292
{
9393
struct vdpa_device *vdpa = vd_get_vdpa(vdev);
94-
const struct vdpa_config_ops *ops = vdpa->config;
9594

96-
return ops->set_status(vdpa, status);
95+
return vdpa_set_status(vdpa, status);
9796
}
9897

9998
static void virtio_vdpa_reset(struct virtio_device *vdev)

include/linux/vdpa.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ void vdpa_get_config(struct vdpa_device *vdev, unsigned int offset,
408408
void *buf, unsigned int len);
409409
void vdpa_set_config(struct vdpa_device *dev, unsigned int offset,
410410
const void *buf, unsigned int length);
411+
u8 vdpa_get_status(struct vdpa_device *vdev);
412+
void vdpa_set_status(struct vdpa_device *vdev, u8 status);
413+
411414
/**
412415
* struct vdpa_mgmtdev_ops - vdpa device ops
413416
* @dev_add: Add a vdpa device using alloc and register

0 commit comments

Comments
 (0)