diff mbox series

[RFC,v4,5/5] vdpa: Support setting vring_base for packed svq

Message ID 20241205203430.76251-6-sahilcdq@proton.me (mailing list archive)
State New
Headers show
Series Add packed virtqueue to shadow virtqueue | expand

Commit Message

Sahil Siddiq Dec. 5, 2024, 8:34 p.m. UTC
Linux commit 1225c216d954 ("vp_vdpa: allow set vq state to initial
state after reset") enabled the vp_vdpa driver to set the vq state to
the device's initial state. This works differently for split and packed
vqs.

With shadow virtqueues enabled, vhost-vdpa sets the vring base using
the VHOST_SET_VRING_BASE ioctl. The payload (vhost_vring_state)
differs for split and packed vqs. The implementation in QEMU currently
uses the payload required for split vqs (i.e., the num field of
vhost_vring_state is set to 0). The kernel throws EOPNOTSUPP when this
payload is used with packed vqs.

This patch sets the num field in the payload appropriately so vhost-vdpa
(with the vp_vdpa driver) can use packed svqs.

Link: https://lists.nongnu.org/archive/html/qemu-devel/2024-10/msg05106.html
Link: https://lore.kernel.org/r/20210602021536.39525-4-jasowang@redhat.com
Link: 1225c216d954 ("vp_vdpa: allow set vq state to initial state after reset")
Signed-off-by: Sahil Siddiq <sahilcdq@proton.me>
Acked-by: Eugenio PĂ©rez <eperezma@redhat.com>
---
Changes v3 -> v4:
- New commit.
- vhost-vdpa.c
  (vhost_vdpa_svq_setup): Add comment.

 hw/virtio/vhost-vdpa.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff mbox series

Patch

diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index 97ed569792..3e32874ce9 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -1252,6 +1252,19 @@  static bool vhost_vdpa_svq_setup(struct vhost_dev *dev,
     };
     int r;
 
+    /* In Linux, the upper 16 bits of s.num is encoded as
+       the last used idx while the lower 16 bits is encoded
+       as the last avail idx when using packed vqs. The most
+       significant bit for each idx represents the counter
+       and should be set in both cases while the remaining
+       bits are cleared. */
+    if (virtio_vdev_has_feature(dev->vdev, VIRTIO_F_RING_PACKED)) {
+        uint32_t last_avail_idx = 0 | (1 << VRING_PACKED_EVENT_F_WRAP_CTR);
+        uint32_t last_used_idx = 0 | (1 << VRING_PACKED_EVENT_F_WRAP_CTR);
+
+        s.num = (last_used_idx << 16) | last_avail_idx;
+    }
+
     r = vhost_vdpa_set_dev_vring_base(dev, &s);
     if (unlikely(r)) {
         error_setg_errno(errp, -r, "Cannot set vring base");