Skip to content

Commit

Permalink
vdpa: factor out vdpa_set_features_unlocked for vdpa internal use
Browse files Browse the repository at this point in the history
No functional change introduced. vdpa bus driver such as virtio_vdpa
or vhost_vdpa is not supposed to take care of the locking for core
by its own. The locked API vdpa_set_features should suffice the
bus driver's need.

Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
Reviewed-by: Eli Cohen <elic@nvidia.com>
Link: https://lore.kernel.org/r/1642206481-30721-2-git-send-email-si-wei.liu@oracle.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
  • Loading branch information
Si-Wei Liu authored and Michael S. Tsirkin committed Mar 4, 2022
1 parent 0e7174b commit e0077cc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion drivers/vdpa/vdpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ static void vdpa_get_config_unlocked(struct vdpa_device *vdev,
* If it does happen we assume a legacy guest.
*/
if (!vdev->features_valid)
vdpa_set_features(vdev, 0, true);
vdpa_set_features_unlocked(vdev, 0);
ops->get_config(vdev, offset, buf, len);
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/vhost/vdpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ static long vhost_vdpa_set_features(struct vhost_vdpa *v, u64 __user *featurep)
if (copy_from_user(&features, featurep, sizeof(features)))
return -EFAULT;

if (vdpa_set_features(vdpa, features, false))
if (vdpa_set_features(vdpa, features))
return -EINVAL;

return 0;
Expand Down
2 changes: 1 addition & 1 deletion drivers/virtio/virtio_vdpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ static int virtio_vdpa_finalize_features(struct virtio_device *vdev)
/* Give virtio_ring a chance to accept features. */
vring_transport_features(vdev);

return vdpa_set_features(vdpa, vdev->features, false);
return vdpa_set_features(vdpa, vdev->features);
}

static const char *virtio_vdpa_bus_name(struct virtio_device *vdev)
Expand Down
18 changes: 12 additions & 6 deletions include/linux/vdpa.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,18 +401,24 @@ static inline int vdpa_reset(struct vdpa_device *vdev)
return ret;
}

static inline int vdpa_set_features(struct vdpa_device *vdev, u64 features, bool locked)
static inline int vdpa_set_features_unlocked(struct vdpa_device *vdev, u64 features)
{
const struct vdpa_config_ops *ops = vdev->config;
int ret;

if (!locked)
mutex_lock(&vdev->cf_mutex);

vdev->features_valid = true;
ret = ops->set_driver_features(vdev, features);
if (!locked)
mutex_unlock(&vdev->cf_mutex);

return ret;
}

static inline int vdpa_set_features(struct vdpa_device *vdev, u64 features)
{
int ret;

mutex_lock(&vdev->cf_mutex);
ret = vdpa_set_features_unlocked(vdev, features);
mutex_unlock(&vdev->cf_mutex);

return ret;
}
Expand Down

0 comments on commit e0077cc

Please sign in to comment.