qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/5] Guest announce feature emulation using Shadow VirtQueue
@ 2022-10-18 15:53 Eugenio Pérez
  2022-10-18 15:53 ` [RFC PATCH 1/5] vdpa: Save emulated features list in vhost_vdpa Eugenio Pérez
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Eugenio Pérez @ 2022-10-18 15:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: Si-Wei Liu, Laurent Vivier, Eli Cohen, Gautam Dawar,
	Michael S. Tsirkin, Zhu Lingshan, Harpreet Singh Anand,
	Liuxiangdong, Cindy Lu, Parav Pandit, Stefano Garzarella,
	Jason Wang

A gratuitous ARP is recommended after a live migration to reduce the amount of
time needed by the network links to be aware of the new location. A hypervisor
may not have the knowledge of the guest network configuration, and this is
especially true on passthrough devices, so its simpler to ask the guest to
do it.

However, the device control part of this feature can be totally emulated by
qemu and shadow virtqueue, not needing any special feature from the actual
vdpa device.

Sending as RFC for the moment as VIRTIO_NET_F_STATUS is also needed for the
guest to access the status of virtio net config to check if an announcement
is needed.

Eugenio Pérez (5):
  vdpa: Save emulated features list in vhost_vdpa
  vdpa: Remove shadow CVQ command check
  vdpa: handle VIRTIO_NET_CTRL_ANNOUNCE in
    vhost_vdpa_net_handle_ctrl_avail
  vhost_net: return VIRTIO_NET_S_ANNOUNCE is device model has it set
  vdpa: Offer VIRTIO_NET_F_GUEST_ANNOUNCE feature if SVQ is enabled

 include/hw/virtio/vhost-vdpa.h |  2 +
 hw/net/vhost_net.c             | 30 ++++++++++++++-
 hw/virtio/vhost-vdpa.c         |  8 ++--
 net/vhost-vdpa.c               | 70 +++++++++-------------------------
 4 files changed, 54 insertions(+), 56 deletions(-)

-- 
2.31.1




^ permalink raw reply	[flat|nested] 6+ messages in thread

* [RFC PATCH 1/5] vdpa: Save emulated features list in vhost_vdpa
  2022-10-18 15:53 [RFC PATCH 0/5] Guest announce feature emulation using Shadow VirtQueue Eugenio Pérez
@ 2022-10-18 15:53 ` Eugenio Pérez
  2022-10-18 15:53 ` [RFC PATCH 2/5] vdpa: Remove shadow CVQ command check Eugenio Pérez
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eugenio Pérez @ 2022-10-18 15:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: Si-Wei Liu, Laurent Vivier, Eli Cohen, Gautam Dawar,
	Michael S. Tsirkin, Zhu Lingshan, Harpreet Singh Anand,
	Liuxiangdong, Cindy Lu, Parav Pandit, Stefano Garzarella,
	Jason Wang

At this moment only _F_LOG is added there.

However future patches add features that depend on the kind of device.
In particular, only net devices can add VIRTIO_F_GUEST_ANNOUNCE. So
let's allow vhost_vdpa creator to set custom emulated device features.

Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
 include/hw/virtio/vhost-vdpa.h | 2 ++
 hw/virtio/vhost-vdpa.c         | 8 ++++----
 net/vhost-vdpa.c               | 4 ++++
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h
index 1111d85643..50083e1e3b 100644
--- a/include/hw/virtio/vhost-vdpa.h
+++ b/include/hw/virtio/vhost-vdpa.h
@@ -31,6 +31,8 @@ typedef struct vhost_vdpa {
     bool iotlb_batch_begin_sent;
     MemoryListener listener;
     struct vhost_vdpa_iova_range iova_range;
+    /* VirtIO device features that can be emulated by qemu */
+    uint64_t added_features;
     uint64_t acked_features;
     bool shadow_vqs_enabled;
     /* IOVA mapping used by the Shadow Virtqueue */
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index 7468e44b87..ddb5e29288 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -660,8 +660,8 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev,
 
         v->acked_features = features;
 
-        /* We must not ack _F_LOG if SVQ is enabled */
-        features &= ~BIT_ULL(VHOST_F_LOG_ALL);
+        /* Do not ack features emulated by qemu */
+        features &= ~v->added_features;
     }
 
     trace_vhost_vdpa_set_features(dev, features);
@@ -1244,8 +1244,8 @@ static int vhost_vdpa_get_features(struct vhost_dev *dev,
     int ret = vhost_vdpa_get_dev_features(dev, features);
 
     if (ret == 0 && v->shadow_vqs_enabled) {
-        /* Add SVQ logging capabilities */
-        *features |= BIT_ULL(VHOST_F_LOG_ALL);
+        /* Add emulated capabilities */
+        *features |= v->added_features;
     }
 
     return ret;
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index 4bc3fd01a8..787e34ed99 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -600,6 +600,10 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
     s->vhost_vdpa.index = queue_pair_index;
     s->vhost_vdpa.shadow_vqs_enabled = svq;
     s->vhost_vdpa.iova_tree = iova_tree;
+    if (svq) {
+        /* Add SVQ logging capabilities */
+        s->vhost_vdpa.added_features |= BIT_ULL(VHOST_F_LOG_ALL);
+    }
     if (!is_datapath) {
         s->cvq_cmd_out_buffer = qemu_memalign(qemu_real_host_page_size(),
                                             vhost_vdpa_net_cvq_cmd_page_len());
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RFC PATCH 2/5] vdpa: Remove shadow CVQ command check
  2022-10-18 15:53 [RFC PATCH 0/5] Guest announce feature emulation using Shadow VirtQueue Eugenio Pérez
  2022-10-18 15:53 ` [RFC PATCH 1/5] vdpa: Save emulated features list in vhost_vdpa Eugenio Pérez
@ 2022-10-18 15:53 ` Eugenio Pérez
  2022-10-18 15:53 ` [RFC PATCH 3/5] vdpa: handle VIRTIO_NET_CTRL_ANNOUNCE in vhost_vdpa_net_handle_ctrl_avail Eugenio Pérez
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eugenio Pérez @ 2022-10-18 15:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: Si-Wei Liu, Laurent Vivier, Eli Cohen, Gautam Dawar,
	Michael S. Tsirkin, Zhu Lingshan, Harpreet Singh Anand,
	Liuxiangdong, Cindy Lu, Parav Pandit, Stefano Garzarella,
	Jason Wang

The guest will see undefined behavior if it issue not negotiate
commands, bit it is expected somehow.

Simplify code deleting this check.

Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
 net/vhost-vdpa.c | 48 ------------------------------------------------
 1 file changed, 48 deletions(-)

diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index 787e34ed99..19d4dbe94a 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -462,48 +462,6 @@ static NetClientInfo net_vhost_vdpa_cvq_info = {
     .check_peer_type = vhost_vdpa_check_peer_type,
 };
 
-/**
- * Do not forward commands not supported by SVQ. Otherwise, the device could
- * accept it and qemu would not know how to update the device model.
- */
-static bool vhost_vdpa_net_cvq_validate_cmd(const void *out_buf, size_t len)
-{
-    struct virtio_net_ctrl_hdr ctrl;
-
-    if (unlikely(len < sizeof(ctrl))) {
-        qemu_log_mask(LOG_GUEST_ERROR,
-                      "%s: invalid legnth of out buffer %zu\n", __func__, len);
-        return false;
-    }
-
-    memcpy(&ctrl, out_buf, sizeof(ctrl));
-    switch (ctrl.class) {
-    case VIRTIO_NET_CTRL_MAC:
-        switch (ctrl.cmd) {
-        case VIRTIO_NET_CTRL_MAC_ADDR_SET:
-            return true;
-        default:
-            qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid mac cmd %u\n",
-                          __func__, ctrl.cmd);
-        };
-        break;
-    case VIRTIO_NET_CTRL_MQ:
-        switch (ctrl.cmd) {
-        case VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET:
-            return true;
-        default:
-            qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid mq cmd %u\n",
-                          __func__, ctrl.cmd);
-        };
-        break;
-    default:
-        qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid control class %u\n",
-                      __func__, ctrl.class);
-    };
-
-    return false;
-}
-
 /**
  * Validate and copy control virtqueue commands.
  *
@@ -527,16 +485,10 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq,
         .iov_len = sizeof(status),
     };
     ssize_t dev_written = -EINVAL;
-    bool ok;
 
     out.iov_len = iov_to_buf(elem->out_sg, elem->out_num, 0,
                              s->cvq_cmd_out_buffer,
                              vhost_vdpa_net_cvq_cmd_len());
-    ok = vhost_vdpa_net_cvq_validate_cmd(s->cvq_cmd_out_buffer, out.iov_len);
-    if (unlikely(!ok)) {
-        goto out;
-    }
-
     dev_written = vhost_vdpa_net_cvq_add(s, out.iov_len, sizeof(status));
     if (unlikely(dev_written < 0)) {
         goto out;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RFC PATCH 3/5] vdpa: handle VIRTIO_NET_CTRL_ANNOUNCE in vhost_vdpa_net_handle_ctrl_avail
  2022-10-18 15:53 [RFC PATCH 0/5] Guest announce feature emulation using Shadow VirtQueue Eugenio Pérez
  2022-10-18 15:53 ` [RFC PATCH 1/5] vdpa: Save emulated features list in vhost_vdpa Eugenio Pérez
  2022-10-18 15:53 ` [RFC PATCH 2/5] vdpa: Remove shadow CVQ command check Eugenio Pérez
@ 2022-10-18 15:53 ` Eugenio Pérez
  2022-10-18 15:53 ` [RFC PATCH 4/5] vhost_net: return VIRTIO_NET_S_ANNOUNCE is device model has it set Eugenio Pérez
  2022-10-18 15:53 ` [RFC PATCH 5/5] vdpa: Offer VIRTIO_NET_F_GUEST_ANNOUNCE feature if SVQ is enabled Eugenio Pérez
  4 siblings, 0 replies; 6+ messages in thread
From: Eugenio Pérez @ 2022-10-18 15:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: Si-Wei Liu, Laurent Vivier, Eli Cohen, Gautam Dawar,
	Michael S. Tsirkin, Zhu Lingshan, Harpreet Singh Anand,
	Liuxiangdong, Cindy Lu, Parav Pandit, Stefano Garzarella,
	Jason Wang

Since this capability is emulated by qemu shadowed CVQ cannot forward it
to the device. Process all that command within qemu.

Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
 net/vhost-vdpa.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index 19d4dbe94a..2a52672b44 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -489,9 +489,18 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq,
     out.iov_len = iov_to_buf(elem->out_sg, elem->out_num, 0,
                              s->cvq_cmd_out_buffer,
                              vhost_vdpa_net_cvq_cmd_len());
-    dev_written = vhost_vdpa_net_cvq_add(s, out.iov_len, sizeof(status));
-    if (unlikely(dev_written < 0)) {
-        goto out;
+    if (*(uint8_t *)s->cvq_cmd_out_buffer == VIRTIO_NET_CTRL_ANNOUNCE) {
+        /*
+         * Guest announce capability is emulated by qemu, so dont forward to
+         * the device.
+         */
+        dev_written = sizeof(status);
+        *s->status = VIRTIO_NET_OK;
+    } else {
+        dev_written = vhost_vdpa_net_cvq_add(s, out.iov_len, sizeof(status));
+        if (unlikely(dev_written < 0)) {
+            goto out;
+        }
     }
 
     if (unlikely(dev_written < sizeof(status))) {
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RFC PATCH 4/5] vhost_net: return VIRTIO_NET_S_ANNOUNCE is device model has it set
  2022-10-18 15:53 [RFC PATCH 0/5] Guest announce feature emulation using Shadow VirtQueue Eugenio Pérez
                   ` (2 preceding siblings ...)
  2022-10-18 15:53 ` [RFC PATCH 3/5] vdpa: handle VIRTIO_NET_CTRL_ANNOUNCE in vhost_vdpa_net_handle_ctrl_avail Eugenio Pérez
@ 2022-10-18 15:53 ` Eugenio Pérez
  2022-10-18 15:53 ` [RFC PATCH 5/5] vdpa: Offer VIRTIO_NET_F_GUEST_ANNOUNCE feature if SVQ is enabled Eugenio Pérez
  4 siblings, 0 replies; 6+ messages in thread
From: Eugenio Pérez @ 2022-10-18 15:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: Si-Wei Liu, Laurent Vivier, Eli Cohen, Gautam Dawar,
	Michael S. Tsirkin, Zhu Lingshan, Harpreet Singh Anand,
	Liuxiangdong, Cindy Lu, Parav Pandit, Stefano Garzarella,
	Jason Wang

Temporal, as this affects other vhost backends and we must check status
feature first.

Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
 hw/net/vhost_net.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index d28f8b974b..46da037aac 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -117,7 +117,35 @@ uint64_t vhost_net_get_features(struct vhost_net *net, uint64_t features)
 int vhost_net_get_config(struct vhost_net *net,  uint8_t *config,
                          uint32_t config_len)
 {
-    return vhost_dev_get_config(&net->dev, config, config_len, NULL);
+    VirtIODevice *vdev;
+    VirtIONet *n;
+    int r = vhost_dev_get_config(&net->dev, config, config_len, NULL);
+
+    if (unlikely(r != 0)) {
+        return r;
+    }
+
+    if (config_len < endof(struct virtio_net_config, status)) {
+        return 0;
+    }
+
+    /*
+     * TODO: To check for VIRTIO_NET_F_STATUS too.
+     * TODO: Perform this only if vhost_vdpa.
+     */
+    vdev = net->dev.vdev;
+    if (!vdev) {
+        /* Device is starting */
+        return 0;
+    }
+    if (!(net->dev.acked_features & BIT_ULL(VIRTIO_NET_F_GUEST_ANNOUNCE))) {
+        return 0;
+    }
+
+    n = VIRTIO_NET(vdev);
+    ((struct virtio_net_config *)config)->status |=
+                                           (n->status & VIRTIO_NET_S_ANNOUNCE);
+    return 0;
 }
 int vhost_net_set_config(struct vhost_net *net, const uint8_t *data,
                          uint32_t offset, uint32_t size, uint32_t flags)
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RFC PATCH 5/5] vdpa: Offer VIRTIO_NET_F_GUEST_ANNOUNCE feature if SVQ is enabled
  2022-10-18 15:53 [RFC PATCH 0/5] Guest announce feature emulation using Shadow VirtQueue Eugenio Pérez
                   ` (3 preceding siblings ...)
  2022-10-18 15:53 ` [RFC PATCH 4/5] vhost_net: return VIRTIO_NET_S_ANNOUNCE is device model has it set Eugenio Pérez
@ 2022-10-18 15:53 ` Eugenio Pérez
  4 siblings, 0 replies; 6+ messages in thread
From: Eugenio Pérez @ 2022-10-18 15:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: Si-Wei Liu, Laurent Vivier, Eli Cohen, Gautam Dawar,
	Michael S. Tsirkin, Zhu Lingshan, Harpreet Singh Anand,
	Liuxiangdong, Cindy Lu, Parav Pandit, Stefano Garzarella,
	Jason Wang

Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
 net/vhost-vdpa.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index 2a52672b44..14a265e30a 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -564,6 +564,9 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
     if (svq) {
         /* Add SVQ logging capabilities */
         s->vhost_vdpa.added_features |= BIT_ULL(VHOST_F_LOG_ALL);
+
+        /* We can emulate guest announce shadowing CVQ */
+        s->vhost_vdpa.added_features |= BIT_ULL(VIRTIO_NET_F_GUEST_ANNOUNCE);
     }
     if (!is_datapath) {
         s->cvq_cmd_out_buffer = qemu_memalign(qemu_real_host_page_size(),
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-10-18 16:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-18 15:53 [RFC PATCH 0/5] Guest announce feature emulation using Shadow VirtQueue Eugenio Pérez
2022-10-18 15:53 ` [RFC PATCH 1/5] vdpa: Save emulated features list in vhost_vdpa Eugenio Pérez
2022-10-18 15:53 ` [RFC PATCH 2/5] vdpa: Remove shadow CVQ command check Eugenio Pérez
2022-10-18 15:53 ` [RFC PATCH 3/5] vdpa: handle VIRTIO_NET_CTRL_ANNOUNCE in vhost_vdpa_net_handle_ctrl_avail Eugenio Pérez
2022-10-18 15:53 ` [RFC PATCH 4/5] vhost_net: return VIRTIO_NET_S_ANNOUNCE is device model has it set Eugenio Pérez
2022-10-18 15:53 ` [RFC PATCH 5/5] vdpa: Offer VIRTIO_NET_F_GUEST_ANNOUNCE feature if SVQ is enabled Eugenio Pérez

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).