Skip to contentSkip to conversation

vdpa: add two ioctl commands to support generic vDPA

RFC Superseded Longpeng(Mike) 2 participants 9 messages Jan 17, 2022 – Mar 10, 2022

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover vdpa: add two ioctl commands to support generic vDPA

From: Longpeng <[email protected]>

To support generic vdpa deivce[1], we need add the following ioctls:
- GET_CONFIG_SIZE: the size of the virtio config space (Patch 1)
- GET_VQS_COUNT: the count of virtqueues that exposed (Patch 2)

Patch 3 supports ctrl vq for vdpasim_net, then guys can test the generic vDPA device on the vdpasim_net/blk.

[1] https://lore.kernel.org/all/[email protected]/

Longpeng (3):
vdpa: support exposing the config size to userspace
vdpa: support exposing the count of vqs to userspace
vdpasim_net: control virtqueue support

 drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 83 +++++++++++++++++++++++++++-
 drivers/vhost/vdpa.c                 | 30 ++++++++++
 include/uapi/linux/vhost.h           |  7 +++
 3 files changed, 118 insertions(+), 2 deletions(-)
Signature · 1 line
2.23.0
#1 lore raw

RFC 1/3 vdpa: support exposing the config size to userspace

From: Longpeng <[email protected]>

- GET_CONFIG_SIZE: the size of the virtio config space

---
 drivers/vhost/vdpa.c       | 17 +++++++++++++++++
 include/uapi/linux/vhost.h |  4 ++++
 2 files changed, 21 insertions(+)
drivers/vhost/vdpa.c +17 -0
index 29cced1cd277..1eea14a4ea56 100644
@@ -355,6 +355,20 @@ static long vhost_vdpa_get_iova_range(struct vhost_vdpa *v, u32 __user *argp)
 	return 0;
 }
 
+static long vhost_vdpa_get_config_size(struct vhost_vdpa *v, u32 __user *argp)
+{
+	struct vdpa_device *vdpa = v->vdpa;
+	const struct vdpa_config_ops *ops = vdpa->config;
+	u32 size;
+
+	size = ops->get_config_size(vdpa);
+
+	if (copy_to_user(argp, &size, sizeof(size)))
+		return -EFAULT;
+
+	return 0;
+}
+
 static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
 				   void __user *argp)
 {
@@ -492,6 +506,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
 	case VHOST_VDPA_GET_IOVA_RANGE:
 		r = vhost_vdpa_get_iova_range(v, argp);
 		break;
+	case VHOST_VDPA_GET_CONFIG_SIZE:
+		r = vhost_vdpa_get_config_size(v, argp);
+		break;
 	default:
 		r = vhost_dev_ioctl(&v->vdev, cmd, argp);
 		if (r == -ENOIOCTLCMD)
include/uapi/linux/vhost.h +4 -0
index c998860d7bbc..bc74e95a273a 100644
@@ -150,4 +150,8 @@
 /* Get the valid iova range */
 #define VHOST_VDPA_GET_IOVA_RANGE	_IOR(VHOST_VIRTIO, 0x78, \
 					     struct vhost_vdpa_iova_range)
+
+/* Get the config size */
+#define VHOST_VDPA_GET_CONFIG_SIZE	_IOR(VHOST_VIRTIO, 0x79, __u32)
+
 #endif
Signature · 1 line
2.23.0
#3 lore raw

RFC 2/3 vdpa: support exposing the count of vqs to userspace

In reply to Longpeng(Mike)

From: Longpeng <[email protected]>

- GET_VQS_COUNT: the count of virtqueues that exposed

---
 drivers/vhost/vdpa.c       | 13 +++++++++++++
 include/uapi/linux/vhost.h |  3 +++
 2 files changed, 16 insertions(+)
drivers/vhost/vdpa.c +13 -0
index 1eea14a4ea56..c1074278fc6b 100644
@@ -369,6 +369,16 @@ static long vhost_vdpa_get_config_size(struct vhost_vdpa *v, u32 __user *argp)
 	return 0;
 }
 
+static long vhost_vdpa_get_vqs_count(struct vhost_vdpa *v, u32 __user *argp)
+{
+	struct vdpa_device *vdpa = v->vdpa;
+
+	if (copy_to_user(argp, &vdpa->nvqs, sizeof(vdpa->nvqs)))
+		return -EFAULT;
+
+	return 0;
+}
+
 static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
 				   void __user *argp)
 {
@@ -509,6 +519,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
 	case VHOST_VDPA_GET_CONFIG_SIZE:
 		r = vhost_vdpa_get_config_size(v, argp);
 		break;
+	case VHOST_VDPA_GET_VQS_COUNT:
+		r = vhost_vdpa_get_vqs_count(v, argp);
+		break;
 	default:
 		r = vhost_dev_ioctl(&v->vdev, cmd, argp);
 		if (r == -ENOIOCTLCMD)
include/uapi/linux/vhost.h +3 -0
index bc74e95a273a..5d99e7c242a2 100644
@@ -154,4 +154,7 @@
 /* Get the config size */
 #define VHOST_VDPA_GET_CONFIG_SIZE	_IOR(VHOST_VIRTIO, 0x79, __u32)
 
+/* Get the count of all virtqueues */
+#define VHOST_VDPA_GET_VQS_COUNT	_IOR(VHOST_VIRTIO, 0x80, __u32)
+
 #endif
Signature · 1 line
2.23.0
#7 lore raw

RFC 3/3 vdpasim_net: control virtqueue support

In reply to Longpeng(Mike)

From: Longpeng <[email protected]>

Introduces the control virtqueue support for vdpasim_net, based on Jason's RFC [1].

[1] https://patchwork.kernel.org/project/kvm/patch/[email protected]/

---
 drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 83 +++++++++++++++++++++++++++-
 1 file changed, 81 insertions(+), 2 deletions(-)
drivers/vdpa/vdpa_sim/vdpa_sim_net.c +81 -2
index 76dd24abc791..e9e388fd3cff 100644
@@ -26,9 +26,85 @@
 #define DRV_LICENSE  "GPL v2"
 
 #define VDPASIM_NET_FEATURES	(VDPASIM_FEATURES | \
-				 (1ULL << VIRTIO_NET_F_MAC))
+				 (1ULL << VIRTIO_NET_F_MAC) | \
+				 (1ULL << VIRTIO_NET_F_CTRL_VQ) | \
+				 (1ULL << VIRTIO_NET_F_CTRL_MAC_ADDR))
 
-#define VDPASIM_NET_VQ_NUM	2
+#define VDPASIM_NET_VQ_NUM	3
+
+virtio_net_ctrl_ack vdpasim_net_handle_ctrl_mac(struct vdpasim *vdpasim,
+						u8 cmd)
+{
+	struct vdpasim_virtqueue *cvq = &vdpasim->vqs[2];
+	virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
+	struct virtio_net_config *config = vdpasim->config;
+	size_t read;
+
+	switch (cmd) {
+	case VIRTIO_NET_CTRL_MAC_ADDR_SET:
+		read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->out_iov,
+					     (void *)config->mac, ETH_ALEN);
+		if (read == ETH_ALEN)
+			status = VIRTIO_NET_OK;
+		break;
+	default:
+		break;
+	}
+
+	return status;
+}
+
+static void vdpasim_net_handle_cvq(struct vdpasim *vdpasim)
+{
+	struct vdpasim_virtqueue *cvq = &vdpasim->vqs[2];
+	virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
+	struct virtio_net_ctrl_hdr ctrl;
+	size_t read, write;
+	int err;
+
+	if (!(vdpasim->features & (1ULL << VIRTIO_NET_F_CTRL_VQ)))
+		return;
+
+	if (!cvq->ready)
+		return;
+
+	while (true) {
+		err = vringh_getdesc_iotlb(&cvq->vring, &cvq->out_iov, &cvq->in_iov,
+					   &cvq->head, GFP_ATOMIC);
+		if (err <= 0)
+			break;
+
+		read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->in_iov, &ctrl,
+					     sizeof(ctrl));
+		if (read != sizeof(ctrl))
+			break;
+
+		switch (ctrl.class) {
+		case VIRTIO_NET_CTRL_MAC:
+			status = vdpasim_net_handle_ctrl_mac(vdpasim, ctrl.cmd);
+			break;
+		default:
+			break;
+		}
+
+		/* Make sure data is wrote before advancing index */
+		smp_wmb();
+
+		write = vringh_iov_push_iotlb(&cvq->vring, &cvq->out_iov,
+					      &status, sizeof (status));
+		vringh_complete_iotlb(&cvq->vring, cvq->head, write);
+		vringh_kiov_cleanup(&cvq->in_iov);
+		vringh_kiov_cleanup(&cvq->out_iov);
+
+		/* Make sure used is visible before rasing the interrupt. */
+		smp_wmb();
+
+		local_bh_disable();
+		if (vringh_need_notify_iotlb(&cvq->vring) > 0)
+			vringh_notify(&cvq->vring);
+		local_bh_enable();
+	}
+}
 
 static void vdpasim_net_work(struct work_struct *work)
 {
@@ -42,6 +118,9 @@ static void vdpasim_net_work(struct work_struct *work)
 
 	spin_lock(&vdpasim->lock);
 
+	/* process ctrl vq first */
+	vdpasim_net_handle_cvq(vdpasim);
+
 	if (!(vdpasim->status & VIRTIO_CONFIG_S_DRIVER_OK))
 		goto out;
 
Signature · 1 line
2.23.0
#2 lore raw

Re: [RFC 1/3] vdpa: support exposing the config size to userspace

In reply to Longpeng(Mike)
Quoted 3 lines · Longpeng(Mike)

From: Longpeng <[email protected]>

- GET_CONFIG_SIZE: the size of the virtio config space

I think we need to be verbose here. And it would be better to quote what spec said:

"

The device MUST allow reading of any device-specific configuration field before FEATURES_OK is set by the driver. This includes fields which are conditional on feature bits, as long as those feature bits are offered by the device.

"

I guess the size should contain the conditional on features bits.

(Or maybe we need to tweak the comment for get_config_size as well).

Other looks good.

Thanks

Quoted 47 lines
---
  drivers/vhost/vdpa.c       | 17 +++++++++++++++++
  include/uapi/linux/vhost.h |  4 ++++
  2 files changed, 21 insertions(+)
drivers/vhost/vdpa.c +17 -0
index 29cced1cd277..1eea14a4ea56 100644
@@ -355,6 +355,20 @@ static long vhost_vdpa_get_iova_range(struct vhost_vdpa *v, u32 __user *argp)
  	return 0;
  }
 
+static long vhost_vdpa_get_config_size(struct vhost_vdpa *v, u32 __user *argp)
+{
+	struct vdpa_device *vdpa = v->vdpa;
+	const struct vdpa_config_ops *ops = vdpa->config;
+	u32 size;
+
+	size = ops->get_config_size(vdpa);
+
+	if (copy_to_user(argp, &size, sizeof(size)))
+		return -EFAULT;
+
+	return 0;
+}
+
  static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
  				   void __user *argp)
  {
@@ -492,6 +506,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
  	case VHOST_VDPA_GET_IOVA_RANGE:
  		r = vhost_vdpa_get_iova_range(v, argp);
  		break;
+	case VHOST_VDPA_GET_CONFIG_SIZE:
+		r = vhost_vdpa_get_config_size(v, argp);
+		break;
  	default:
  		r = vhost_dev_ioctl(&v->vdev, cmd, argp);
  		if (r == -ENOIOCTLCMD)
include/uapi/linux/vhost.h +0 -0
index c998860d7bbc..bc74e95a273a 100644

include/uapi/linux/vhost.h line 157

Quoted 8 lines
include/uapi/linux/vhost.h +4 -0
@@ -150,4 +150,8 @@
  /* Get the valid iova range */
  #define VHOST_VDPA_GET_IOVA_RANGE	_IOR(VHOST_VIRTIO, 0x78, \
  					     struct vhost_vdpa_iova_range)
+
+/* Get the config size */
+#define VHOST_VDPA_GET_CONFIG_SIZE	_IOR(VHOST_VIRTIO, 0x79, __u32)
+
  #endif

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#4 lore raw

Re: [RFC 2/3] vdpa: support exposing the count of vqs to userspace

In reply to Longpeng(Mike)
Quoted 15 lines · Longpeng(Mike)

From: Longpeng <[email protected]>

- GET_VQS_COUNT: the count of virtqueues that exposed

---
  drivers/vhost/vdpa.c       | 13 +++++++++++++
  include/uapi/linux/vhost.h |  3 +++
  2 files changed, 16 insertions(+)
drivers/vhost/vdpa.c +0 -0
index 1eea14a4ea56..c1074278fc6b 100644

drivers/vhost/vdpa.c static long vhost_vdpa_get_config_size(struct vhost_vdpa *v, u32 __user *argp) · line 374

Quoted 6 lines
drivers/vhost/vdpa.c +3 -0
@@ -369,6 +369,16 @@ static long vhost_vdpa_get_config_size(struct vhost_vdpa *v, u32 __user *argp)
  	return 0;
  }
 
+static long vhost_vdpa_get_vqs_count(struct vhost_vdpa *v, u32 __user *argp)
+{
+	struct vdpa_device *vdpa = v->vdpa;

While at it, I think it's better to change vdpa->nvqs to use u32?

Thanks

Quoted 25 lines
drivers/vhost/vdpa.c +10 -0
+
+	if (copy_to_user(argp, &vdpa->nvqs, sizeof(vdpa->nvqs)))
+		return -EFAULT;
+
+	return 0;
+}
+
  static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
  				   void __user *argp)
  {
@@ -509,6 +519,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
  	case VHOST_VDPA_GET_CONFIG_SIZE:
  		r = vhost_vdpa_get_config_size(v, argp);
  		break;
+	case VHOST_VDPA_GET_VQS_COUNT:
+		r = vhost_vdpa_get_vqs_count(v, argp);
+		break;
  	default:
  		r = vhost_dev_ioctl(&v->vdev, cmd, argp);
  		if (r == -ENOIOCTLCMD)
include/uapi/linux/vhost.h +0 -0
index bc74e95a273a..5d99e7c242a2 100644

include/uapi/linux/vhost.h line 160

Quoted 7 lines
include/uapi/linux/vhost.h +3 -0
@@ -154,4 +154,7 @@
  /* Get the config size */
  #define VHOST_VDPA_GET_CONFIG_SIZE	_IOR(VHOST_VIRTIO, 0x79, __u32)
 
+/* Get the count of all virtqueues */
+#define VHOST_VDPA_GET_VQS_COUNT	_IOR(VHOST_VIRTIO, 0x80, __u32)
+
  #endif

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#8 lore raw

Re: [RFC 3/3] vdpasim_net: control virtqueue support

In reply to Longpeng(Mike)
Quoted 6 lines · Longpeng(Mike)

From: Longpeng <[email protected]>

Introduces the control virtqueue support for vdpasim_net, based on Jason's RFC [1].

[1] https://patchwork.kernel.org/project/kvm/patch/[email protected]/

I'd expect to implement the receive filter as well[1]. This gives us a chance to test this.

Thanks

[1] https://lkml.org/lkml/2020/9/23/1269

Quoted 99 lines
---
  drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 83 +++++++++++++++++++++++++++-
  1 file changed, 81 insertions(+), 2 deletions(-)
drivers/vdpa/vdpa_sim/vdpa_sim_net.c +78 -2
index 76dd24abc791..e9e388fd3cff 100644
@@ -26,9 +26,85 @@
  #define DRV_LICENSE  "GPL v2"
 
  #define VDPASIM_NET_FEATURES	(VDPASIM_FEATURES | \
-				 (1ULL << VIRTIO_NET_F_MAC))
+				 (1ULL << VIRTIO_NET_F_MAC) | \
+				 (1ULL << VIRTIO_NET_F_CTRL_VQ) | \
+				 (1ULL << VIRTIO_NET_F_CTRL_MAC_ADDR))
 
-#define VDPASIM_NET_VQ_NUM	2
+#define VDPASIM_NET_VQ_NUM	3
+
+virtio_net_ctrl_ack vdpasim_net_handle_ctrl_mac(struct vdpasim *vdpasim,
+						u8 cmd)
+{
+	struct vdpasim_virtqueue *cvq = &vdpasim->vqs[2];
+	virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
+	struct virtio_net_config *config = vdpasim->config;
+	size_t read;
+
+	switch (cmd) {
+	case VIRTIO_NET_CTRL_MAC_ADDR_SET:
+		read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->out_iov,
+					     (void *)config->mac, ETH_ALEN);
+		if (read == ETH_ALEN)
+			status = VIRTIO_NET_OK;
+		break;
+	default:
+		break;
+	}
+
+	return status;
+}
+
+static void vdpasim_net_handle_cvq(struct vdpasim *vdpasim)
+{
+	struct vdpasim_virtqueue *cvq = &vdpasim->vqs[2];
+	virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
+	struct virtio_net_ctrl_hdr ctrl;
+	size_t read, write;
+	int err;
+
+	if (!(vdpasim->features & (1ULL << VIRTIO_NET_F_CTRL_VQ)))
+		return;
+
+	if (!cvq->ready)
+		return;
+
+	while (true) {
+		err = vringh_getdesc_iotlb(&cvq->vring, &cvq->out_iov, &cvq->in_iov,
+					   &cvq->head, GFP_ATOMIC);
+		if (err <= 0)
+			break;
+
+		read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->in_iov, &ctrl,
+					     sizeof(ctrl));
+		if (read != sizeof(ctrl))
+			break;
+
+		switch (ctrl.class) {
+		case VIRTIO_NET_CTRL_MAC:
+			status = vdpasim_net_handle_ctrl_mac(vdpasim, ctrl.cmd);
+			break;
+		default:
+			break;
+		}
+
+		/* Make sure data is wrote before advancing index */
+		smp_wmb();
+
+		write = vringh_iov_push_iotlb(&cvq->vring, &cvq->out_iov,
+					      &status, sizeof (status));
+		vringh_complete_iotlb(&cvq->vring, cvq->head, write);
+		vringh_kiov_cleanup(&cvq->in_iov);
+		vringh_kiov_cleanup(&cvq->out_iov);
+
+		/* Make sure used is visible before rasing the interrupt. */
+		smp_wmb();
+
+		local_bh_disable();
+		if (vringh_need_notify_iotlb(&cvq->vring) > 0)
+			vringh_notify(&cvq->vring);
+		local_bh_enable();
+	}
+}
 
  static void vdpasim_net_work(struct work_struct *work)
  {

drivers/vdpa/vdpa_sim/vdpa_sim_net.c static void vdpasim_net_work(struct work_struct *work) · line 126

Quoted 9 lines
drivers/vdpa/vdpa_sim/vdpa_sim_net.c +3 -0
@@ -42,6 +118,9 @@ static void vdpasim_net_work(struct work_struct *work)
 
  	spin_lock(&vdpasim->lock);
 
+	/* process ctrl vq first */
+	vdpasim_net_handle_cvq(vdpasim);
+
  	if (!(vdpasim->status & VIRTIO_CONFIG_S_DRIVER_OK))
  		goto out;
 

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#5 lore raw

RE: [RFC 2/3] vdpa: support exposing the count of vqs to userspace

In reply to Jason Wang

Hi Jason,

Quoted 33 lines

-----Original Message-----
From: Jason Wang [mailto:[email protected]]
Sent: Tuesday, January 18, 2022 11:08 AM
To: Longpeng (Mike, Cloud Infrastructure Service Product Dept.) <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Gonglei (Arei) <[email protected]>; Yechuan <[email protected]>; Huangzhichao <[email protected]>
Subject: Re: [RFC 2/3] vdpa: support exposing the count of vqs to userspace

drivers/vhost/vdpa.c static long vhost_vdpa_get_config_size(struct vhost_vdpa

Quoted 15 lines · Longpeng(Mike)

From: Longpeng <[email protected]>

- GET_VQS_COUNT: the count of virtqueues that exposed

---
  drivers/vhost/vdpa.c       | 13 +++++++++++++
  include/uapi/linux/vhost.h |  3 +++
  2 files changed, 16 insertions(+)
drivers/vhost/vdpa.c +0 -0
index 1eea14a4ea56..c1074278fc6b 100644
@@ -369,6 +369,16 @@ static long vhost_vdpa_get_config_size(struct vhost_vdpa

*v, u32 __user *argp)

Quoted 3 lines
drivers/vhost/vdpa.c +0 -0
  	return 0;
  }
 
Quoted 7 lines

drivers/vhost/vdpa.c static long vhost_vdpa_get_config_size(struct vhost_vdpa *v, u32 __user *argp) · line 374

Quoted 3 lines
drivers/vhost/vdpa.c +3 -0
+static long vhost_vdpa_get_vqs_count(struct vhost_vdpa *v, u32 __user *argp)
+{
+	struct vdpa_device *vdpa = v->vdpa;

While at it, I think it's better to change vdpa->nvqs to use u32?

struct vhost_vdpa {
    ...
	int nvqs;
    ...
};
struct vdpa_device {
    ...
	int nvqs;
    ...
};

I think we should change both to u32?

Quoted 35 lines

Thanks

Quoted 32 lines
drivers/vhost/vdpa.c +10 -0
+
+	if (copy_to_user(argp, &vdpa->nvqs, sizeof(vdpa->nvqs)))
+		return -EFAULT;
+
+	return 0;
+}
+
  static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
  				   void __user *argp)
  {
@@ -509,6 +519,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
  	case VHOST_VDPA_GET_CONFIG_SIZE:
  		r = vhost_vdpa_get_config_size(v, argp);
  		break;
+	case VHOST_VDPA_GET_VQS_COUNT:
+		r = vhost_vdpa_get_vqs_count(v, argp);
+		break;
  	default:
  		r = vhost_dev_ioctl(&v->vdev, cmd, argp);
  		if (r == -ENOIOCTLCMD)
include/uapi/linux/vhost.h +3 -0
index bc74e95a273a..5d99e7c242a2 100644
@@ -154,4 +154,7 @@
  /* Get the config size */
  #define VHOST_VDPA_GET_CONFIG_SIZE	_IOR(VHOST_VIRTIO, 0x79, __u32)
 
+/* Get the count of all virtqueues */
+#define VHOST_VDPA_GET_VQS_COUNT	_IOR(VHOST_VIRTIO, 0x80, __u32)
+
  #endif
#6 lore raw

Re: [RFC 2/3] vdpa: support exposing the count of vqs to userspace

Quoted 52 lines · Cloud Infrastructure Service Product Dept.)

Hi Jason,

Quoted 11 lines

-----Original Message-----
From: Jason Wang [mailto:[email protected]]
Sent: Tuesday, January 18, 2022 11:08 AM
To: Longpeng (Mike, Cloud Infrastructure Service Product Dept.) <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Gonglei (Arei) <[email protected]>; Yechuan <[email protected]>; Huangzhichao <[email protected]>
Subject: Re: [RFC 2/3] vdpa: support exposing the count of vqs to

userspace

Quoted 13 lines · Longpeng(Mike)
Quoted 10 lines

From: Longpeng <[email protected]>

- GET_VQS_COUNT: the count of virtqueues that exposed

---
  drivers/vhost/vdpa.c       | 13 +++++++++++++
  include/uapi/linux/vhost.h |  3 +++
  2 files changed, 16 insertions(+)
Quoted 5 lines

drivers/vhost/vdpa.c static long vhost_vdpa_get_config_size(struct

Quoted 5 lines
drivers/vhost/vdpa.c +0 -0
index 1eea14a4ea56..c1074278fc6b 100644
@@ -369,6 +369,16 @@ static long vhost_vdpa_get_config_size(struct

vhost_vdpa

Quoted 5 lines

*v, u32 __user *argp)

Quoted 4 lines
drivers/vhost/vdpa.c +1 -0
    return 0;
  }
 
+static long vhost_vdpa_get_vqs_count(struct vhost_vdpa *v, u32 __user

*argp)

Quoted 6 lines

drivers/vhost/vdpa.c static long vhost_vdpa_get_config_size(struct vhost_vdpa *v, u32 __user *argp) · line 374

Quoted 2 lines
drivers/vhost/vdpa.c +2 -0
+{
+   struct vdpa_device *vdpa = v->vdpa;

While at it, I think it's better to change vdpa->nvqs to use u32?

struct vhost_vdpa {
    ...
        int nvqs;
    ...
};
Quoted 8 lines
struct vdpa_device {
    ...
        int nvqs;
    ...
};

I think we should change both to u32?

Yes.

Thanks

Quoted 36 lines
Quoted 5 lines

Thanks

Quoted 8 lines

drivers/vhost/vdpa.c static long vhost_vdpa_get_config_size(struct vhost_vdpa *v, u32 __user *argp)

Quoted 8 lines
drivers/vhost/vdpa.c +7 -0
+
+   if (copy_to_user(argp, &vdpa->nvqs, sizeof(vdpa->nvqs)))
+           return -EFAULT;
+
+   return 0;
+}
+
  static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned

int cmd,

Quoted 3 lines

drivers/vhost/vdpa.c static long vhost_vdpa_unlocked_ioctl(struct file

Quoted 3 lines
drivers/vhost/vdpa.c +0 -0
                               void __user *argp)
  {
@@ -509,6 +519,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file

*filep,

Quoted 8 lines
Quoted 8 lines
drivers/vhost/vdpa.c +3 -0
    case VHOST_VDPA_GET_CONFIG_SIZE:
            r = vhost_vdpa_get_config_size(v, argp);
            break;
+   case VHOST_VDPA_GET_VQS_COUNT:
+           r = vhost_vdpa_get_vqs_count(v, argp);
+           break;
    default:
            r = vhost_dev_ioctl(&v->vdev, cmd, argp);
Quoted 8 lines

include/uapi/linux/vhost.h line 155

Quoted 8 lines
drivers/vhost/vdpa.c +0 -0
            if (r == -ENOIOCTLCMD)
include/uapi/linux/vhost.h +0 -0
index bc74e95a273a..5d99e7c242a2 100644
@@ -154,4 +154,7 @@
  /* Get the config size */
  #define VHOST_VDPA_GET_CONFIG_SIZE        _IOR(VHOST_VIRTIO, 0x79,

__u32)

Quoted 1 line
Quoted 1 line
Quoted 6 lines
Quoted 4 lines

include/uapi/linux/vhost.h line 160

Quoted 4 lines
include/uapi/linux/vhost.h +3 -0
+/* Get the count of all virtqueues */
+#define VHOST_VDPA_GET_VQS_COUNT   _IOR(VHOST_VIRTIO, 0x80, __u32)
+
  #endif

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization