diff mbox series

[RFC,2/4] vDPA: support ioctl VHOST_GET/SET_VRING_ENDIAN

Message ID 20220901101601.61420-3-lingshan.zhu@intel.com (mailing list archive)
State RFC
Headers show
Series vDPA: support VHOST_GET/SET_VRING_ENDIAN | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Zhu, Lingshan Sept. 1, 2022, 10:15 a.m. UTC
This commit add ioctl VHOST_GET_VRING_ENDIAN and
VHOST_SET_VRING_ENDIAN support for vhost_vdpa.

So that QEMU can be aware of the endian-ness of the vDPA device.

Signed-off-by: Zhu Lingshan <lingshan.zhu@intel.com>
---
 drivers/vhost/vdpa.c | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index 166044642fd5..084fbf04c6bb 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -547,11 +547,41 @@  static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
 
 		vq->last_avail_idx = vq_state.split.avail_index;
 		break;
-	}
+	case VHOST_SET_VRING_ENDIAN:
+		if (!ops->set_vq_endian)
+			return -EOPNOTSUPP;
+
+		if (copy_from_user(&s, argp, sizeof(s)))
+			return -EFAULT;
+
+		if (s.num != VHOST_VRING_LITTLE_ENDIAN &&
+		    s.num != VHOST_VRING_BIG_ENDIAN)
+			return -EINVAL;
+
+		if (ops->get_status(vdpa) & VIRTIO_CONFIG_S_DRIVER_OK)
+			return -EFAULT;
+
+		r = ops->set_vq_endian(vdpa, s.index, s.num);
+		if (r)
+			return -EFAULT;
+
+		return 0;
+	case VHOST_GET_VRING_ENDIAN:
+		if (!ops->get_vq_endian)
+			return -EOPNOTSUPP;
+
+		s.index = idx;
+		s.num = ops->get_vq_endian(vdpa, idx);
+
+		if (copy_to_user(argp, &s, sizeof(s)))
+			return -EFAULT;
+
+		return 0;
 
 	r = vhost_vring_ioctl(&v->vdev, cmd, argp);
 	if (r)
 		return r;
+	}
 
 	switch (cmd) {
 	case VHOST_SET_VRING_ADDR: