Skip to content

Commit

Permalink
vdpa: Sync calls set/get config/status with cf_mutex
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
elic307i authored and mstsirkin committed Jan 14, 2022
1 parent a7f46ba commit 73bc0db
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
19 changes: 19 additions & 0 deletions drivers/vdpa/vdpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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)
Expand Down
7 changes: 3 additions & 4 deletions drivers/vhost/vdpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,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;
Expand All @@ -164,7 +163,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
Expand All @@ -182,7 +181,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++)
Expand Down
3 changes: 1 addition & 2 deletions drivers/virtio/virtio_vdpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions include/linux/vdpa.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,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
Expand Down

0 comments on commit 73bc0db

Please sign in to comment.