Skip to content

Commit a61280d

Browse files
Longpengmstsirkin
authored andcommitted
vdpa: support exposing the config size to userspace
- GET_CONFIG_SIZE: return the size of the virtio config space. The size contains the fields which are conditional on feature bits. Acked-by: Jason Wang <jasowang@redhat.com> Signed-off-by: Longpeng <longpeng2@huawei.com> Link: https://lore.kernel.org/r/20220315032553.455-2-longpeng2@huawei.com Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
1 parent f1781be commit a61280d

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

drivers/vhost/vdpa.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,20 @@ static long vhost_vdpa_get_iova_range(struct vhost_vdpa *v, u32 __user *argp)
358358
return 0;
359359
}
360360

361+
static long vhost_vdpa_get_config_size(struct vhost_vdpa *v, u32 __user *argp)
362+
{
363+
struct vdpa_device *vdpa = v->vdpa;
364+
const struct vdpa_config_ops *ops = vdpa->config;
365+
u32 size;
366+
367+
size = ops->get_config_size(vdpa);
368+
369+
if (copy_to_user(argp, &size, sizeof(size)))
370+
return -EFAULT;
371+
372+
return 0;
373+
}
374+
361375
static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
362376
void __user *argp)
363377
{
@@ -495,6 +509,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
495509
case VHOST_VDPA_GET_IOVA_RANGE:
496510
r = vhost_vdpa_get_iova_range(v, argp);
497511
break;
512+
case VHOST_VDPA_GET_CONFIG_SIZE:
513+
r = vhost_vdpa_get_config_size(v, argp);
514+
break;
498515
default:
499516
r = vhost_dev_ioctl(&v->vdev, cmd, argp);
500517
if (r == -ENOIOCTLCMD)

include/linux/vdpa.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ struct vdpa_map_file {
207207
* @reset: Reset device
208208
* @vdev: vdpa device
209209
* Returns integer: success (0) or error (< 0)
210-
* @get_config_size: Get the size of the configuration space
210+
* @get_config_size: Get the size of the configuration space includes
211+
* fields that are conditional on feature bits.
211212
* @vdev: vdpa device
212213
* Returns size_t: configuration size
213214
* @get_config: Read from device specific configuration space

include/uapi/linux/vhost.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,8 @@
150150
/* Get the valid iova range */
151151
#define VHOST_VDPA_GET_IOVA_RANGE _IOR(VHOST_VIRTIO, 0x78, \
152152
struct vhost_vdpa_iova_range)
153+
154+
/* Get the config size */
155+
#define VHOST_VDPA_GET_CONFIG_SIZE _IOR(VHOST_VIRTIO, 0x79, __u32)
156+
153157
#endif

0 commit comments

Comments
 (0)