qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Sahil Siddiq <icegambit91@gmail.com>
To: eperezma@redhat.com, sgarzare@redhat.com
Cc: mst@redhat.com, qemu-devel@nongnu.org, Sahil Siddiq <sahilcdq@proton.me>
Subject: [RFC v4 5/5] vdpa: Support setting vring_base for packed svq
Date: Fri,  6 Dec 2024 02:04:30 +0530	[thread overview]
Message-ID: <20241205203430.76251-6-sahilcdq@proton.me> (raw)
In-Reply-To: <20241205203430.76251-1-sahilcdq@proton.me>

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 --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");
-- 
2.47.0



  parent reply	other threads:[~2024-12-05 20:35 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-05 20:34 [RFC v4 0/5] Add packed virtqueue to shadow virtqueue Sahil Siddiq
2024-12-05 20:34 ` [RFC v4 1/5] vhost: Refactor vhost_svq_add_split Sahil Siddiq
2024-12-10  8:40   ` Eugenio Perez Martin
2024-12-05 20:34 ` [RFC v4 2/5] vhost: Write descriptors to packed svq Sahil Siddiq
2024-12-10  8:54   ` Eugenio Perez Martin
2024-12-11 15:58     ` Sahil Siddiq
2024-12-05 20:34 ` [RFC v4 3/5] vhost: Data structure changes to support packed vqs Sahil Siddiq
2024-12-10  8:55   ` Eugenio Perez Martin
2024-12-11 15:59     ` Sahil Siddiq
2024-12-05 20:34 ` [RFC v4 4/5] vdpa: Allocate memory for svq and map them to vdpa Sahil Siddiq
2024-12-05 20:34 ` Sahil Siddiq [this message]
2024-12-10  9:27 ` [RFC v4 0/5] Add packed virtqueue to shadow virtqueue Eugenio Perez Martin
2024-12-11 15:57   ` Sahil Siddiq
2024-12-15 17:27   ` Sahil Siddiq
2024-12-16  8:39     ` Eugenio Perez Martin
2024-12-17  5:45       ` Sahil Siddiq
2024-12-17  7:50         ` Eugenio Perez Martin
2024-12-19 19:37           ` Sahil Siddiq
2024-12-20  6:58             ` Eugenio Perez Martin
2025-01-03 13:06               ` Sahil Siddiq
2025-01-07  8:05                 ` Eugenio Perez Martin
2025-01-19  6:37                   ` Sahil Siddiq
2025-01-21 16:37                     ` Eugenio Perez Martin
2025-01-24  5:46                       ` Sahil Siddiq
2025-01-24  7:34                         ` Eugenio Perez Martin
2025-01-31  5:04                           ` Sahil Siddiq
2025-01-31  6:57                             ` Eugenio Perez Martin
2025-02-04 12:49                               ` Sahil Siddiq
2025-02-04 18:10                                 ` Eugenio Perez Martin
2025-02-04 18:15                                   ` Eugenio Perez Martin
2025-02-06  5:26                                   ` Sahil Siddiq
2025-02-06  7:12                                     ` Eugenio Perez Martin
2025-02-06 15:17                                       ` Sahil Siddiq
2025-02-10 10:58                                         ` Sahil Siddiq
2025-02-10 14:23                                           ` Eugenio Perez Martin
2025-02-10 16:25                                             ` Sahil Siddiq
2025-02-11  7:57                                               ` Eugenio Perez Martin
2025-03-06  5:25                                                 ` Sahil Siddiq
2025-03-06  7:23                                                   ` Eugenio Perez Martin
2025-03-24 13:54                                                     ` Sahil Siddiq

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241205203430.76251-6-sahilcdq@proton.me \
    --to=icegambit91@gmail.com \
    --cc=eperezma@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sahilcdq@proton.me \
    --cc=sgarzare@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).