Skip to content

Commit a127c5b

Browse files
jasowangmstsirkin
authored andcommitted
vhost-vdpa: fix backend feature ioctls
Commit 653055b ("vhost-vdpa: support get/set backend features") introduces two malfunction backend features ioctls: 1) the ioctls was blindly added to vring ioctl instead of vdpa device ioctl 2) vhost_set_backend_features() was called when dev mutex has already been held which will lead a deadlock This patch fixes the above issues. Cc: Eli Cohen <elic@nvidia.com> Reported-by: Zhu Lingshan <lingshan.zhu@intel.com> Fixes: 653055b ("vhost-vdpa: support get/set backend features") Signed-off-by: Jason Wang <jasowang@redhat.com> Link: https://lore.kernel.org/r/20200907104343.31141-1-jasowang@redhat.com Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 71c548c commit a127c5b

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

drivers/vhost/vdpa.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,6 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
353353
struct vdpa_callback cb;
354354
struct vhost_virtqueue *vq;
355355
struct vhost_vring_state s;
356-
u64 __user *featurep = argp;
357-
u64 features;
358356
u32 idx;
359357
long r;
360358

@@ -381,18 +379,6 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
381379

382380
vq->last_avail_idx = vq_state.avail_index;
383381
break;
384-
case VHOST_GET_BACKEND_FEATURES:
385-
features = VHOST_VDPA_BACKEND_FEATURES;
386-
if (copy_to_user(featurep, &features, sizeof(features)))
387-
return -EFAULT;
388-
return 0;
389-
case VHOST_SET_BACKEND_FEATURES:
390-
if (copy_from_user(&features, featurep, sizeof(features)))
391-
return -EFAULT;
392-
if (features & ~VHOST_VDPA_BACKEND_FEATURES)
393-
return -EOPNOTSUPP;
394-
vhost_set_backend_features(&v->vdev, features);
395-
return 0;
396382
}
397383

398384
r = vhost_vring_ioctl(&v->vdev, cmd, argp);
@@ -440,8 +426,20 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
440426
struct vhost_vdpa *v = filep->private_data;
441427
struct vhost_dev *d = &v->vdev;
442428
void __user *argp = (void __user *)arg;
429+
u64 __user *featurep = argp;
430+
u64 features;
443431
long r;
444432

433+
if (cmd == VHOST_SET_BACKEND_FEATURES) {
434+
r = copy_from_user(&features, featurep, sizeof(features));
435+
if (r)
436+
return r;
437+
if (features & ~VHOST_VDPA_BACKEND_FEATURES)
438+
return -EOPNOTSUPP;
439+
vhost_set_backend_features(&v->vdev, features);
440+
return 0;
441+
}
442+
445443
mutex_lock(&d->mutex);
446444

447445
switch (cmd) {
@@ -476,6 +474,10 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
476474
case VHOST_VDPA_SET_CONFIG_CALL:
477475
r = vhost_vdpa_set_config_call(v, argp);
478476
break;
477+
case VHOST_GET_BACKEND_FEATURES:
478+
features = VHOST_VDPA_BACKEND_FEATURES;
479+
r = copy_to_user(featurep, &features, sizeof(features));
480+
break;
479481
default:
480482
r = vhost_dev_ioctl(&v->vdev, cmd, argp);
481483
if (r == -ENOIOCTLCMD)

0 commit comments

Comments
 (0)