mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-17 05:45:20 +00:00
vhost: add helper to parse userspace vring state/file
The next patches add new vhost worker ioctls which will need to get a vhost_virtqueue from a userspace struct which specifies the vq's index. This moves the vhost_vring_ioctl code to do this to a helper so it can be shared. Signed-off-by: Mike Christie <michael.christie@oracle.com> Message-Id: <20230626232307.97930-14-michael.christie@oracle.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
27eca18911
commit
cef25866f4
@ -599,6 +599,27 @@ free_worker:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int vhost_get_vq_from_user(struct vhost_dev *dev, void __user *argp,
|
||||||
|
struct vhost_virtqueue **vq, u32 *id)
|
||||||
|
{
|
||||||
|
u32 __user *idxp = argp;
|
||||||
|
u32 idx;
|
||||||
|
long r;
|
||||||
|
|
||||||
|
r = get_user(idx, idxp);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
if (idx >= dev->nvqs)
|
||||||
|
return -ENOBUFS;
|
||||||
|
|
||||||
|
idx = array_index_nospec(idx, dev->nvqs);
|
||||||
|
|
||||||
|
*vq = dev->vqs[idx];
|
||||||
|
*id = idx;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Caller should have device mutex */
|
/* Caller should have device mutex */
|
||||||
long vhost_dev_set_owner(struct vhost_dev *dev)
|
long vhost_dev_set_owner(struct vhost_dev *dev)
|
||||||
{
|
{
|
||||||
@ -1618,21 +1639,15 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg
|
|||||||
struct file *eventfp, *filep = NULL;
|
struct file *eventfp, *filep = NULL;
|
||||||
bool pollstart = false, pollstop = false;
|
bool pollstart = false, pollstop = false;
|
||||||
struct eventfd_ctx *ctx = NULL;
|
struct eventfd_ctx *ctx = NULL;
|
||||||
u32 __user *idxp = argp;
|
|
||||||
struct vhost_virtqueue *vq;
|
struct vhost_virtqueue *vq;
|
||||||
struct vhost_vring_state s;
|
struct vhost_vring_state s;
|
||||||
struct vhost_vring_file f;
|
struct vhost_vring_file f;
|
||||||
u32 idx;
|
u32 idx;
|
||||||
long r;
|
long r;
|
||||||
|
|
||||||
r = get_user(idx, idxp);
|
r = vhost_get_vq_from_user(d, argp, &vq, &idx);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
if (idx >= d->nvqs)
|
|
||||||
return -ENOBUFS;
|
|
||||||
|
|
||||||
idx = array_index_nospec(idx, d->nvqs);
|
|
||||||
vq = d->vqs[idx];
|
|
||||||
|
|
||||||
if (ioctl == VHOST_SET_VRING_NUM ||
|
if (ioctl == VHOST_SET_VRING_NUM ||
|
||||||
ioctl == VHOST_SET_VRING_ADDR) {
|
ioctl == VHOST_SET_VRING_ADDR) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user