From: "Eugenio Pérez" <eperezma@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
"Gonglei (Arei)" <arei.gonglei@huawei.com>,
Cindy Lu <lulu@redhat.com>, Laurent Vivier <lvivier@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Parav Pandit <parav@mellanox.com>,
Zhu Lingshan <lingshan.zhu@intel.com>,
Gautam Dawar <gdawar@xilinx.com>,
Liuxiangdong <liuxiangdong5@huawei.com>,
Jason Wang <jasowang@redhat.com>,
Cornelia Huck <cohuck@redhat.com>, Eli Cohen <eli@mellanox.com>,
Stefano Garzarella <sgarzare@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Harpreet Singh Anand <hanand@xilinx.com>
Subject: [RFC 5/8] vdpa: Add vdpa memory listener
Date: Wed, 10 Aug 2022 20:42:17 +0200 [thread overview]
Message-ID: <20220810184220.2362292-6-eperezma@redhat.com> (raw)
In-Reply-To: <20220810184220.2362292-1-eperezma@redhat.com>
This enable net/vdpa to restart the full device when a migration is
started or stopped.
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
net/vhost-vdpa.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 87 insertions(+)
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index a035c89c34..4c6947feb8 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -21,6 +21,7 @@
#include "qemu/memalign.h"
#include "qemu/option.h"
#include "qapi/error.h"
+#include "exec/address-spaces.h"
#include <linux/vhost.h>
#include <sys/ioctl.h>
#include <err.h>
@@ -32,6 +33,8 @@
typedef struct VhostVDPAState {
NetClientState nc;
struct vhost_vdpa vhost_vdpa;
+ MemoryListener memory_listener;
+
VHostNetState *vhost_net;
/* Control commands shadow buffers */
@@ -110,6 +113,16 @@ static const uint64_t vdpa_svq_device_features =
#define VHOST_VDPA_NET_CVQ_PASSTHROUGH 0
#define VHOST_VDPA_NET_CVQ_ASID 1
+/*
+ * Vdpa memory listener must run before vhost one, so vhost_vdpa does not get
+ * _F_LOG_ALL without SVQ.
+ */
+#define VHOST_VDPA_NET_MEMORY_LISTENER_PRIORITY \
+ (VHOST_DEV_MEMORY_LISTENER_PRIORITY - 1)
+/* Check for underflow */
+QEMU_BUILD_BUG_ON(VHOST_DEV_MEMORY_LISTENER_PRIORITY <
+ VHOST_VDPA_NET_MEMORY_LISTENER_PRIORITY);
+
VHostNetState *vhost_vdpa_get_vhost_net(NetClientState *nc)
{
VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc);
@@ -172,6 +185,9 @@ static void vhost_vdpa_cleanup(NetClientState *nc)
qemu_vfree(s->cvq_cmd_out_buffer);
qemu_vfree(s->cvq_cmd_in_buffer);
+ if (dev->vq_index == 0) {
+ memory_listener_unregister(&s->memory_listener);
+ }
if (dev->vq_index + dev->nvqs == dev->vq_index_end) {
g_clear_pointer(&s->vhost_vdpa.iova_tree, vhost_iova_tree_delete);
}
@@ -224,6 +240,69 @@ static ssize_t vhost_vdpa_receive(NetClientState *nc, const uint8_t *buf,
return 0;
}
+static void vhost_vdpa_net_log_global_enable(MemoryListener *listener,
+ bool enable)
+{
+ VhostVDPAState *s = container_of(listener, VhostVDPAState,
+ memory_listener);
+ struct vhost_vdpa *v = &s->vhost_vdpa;
+ VirtIONet *n;
+ VirtIODevice *vdev;
+ int data_queue_pairs, cvq, r;
+ NetClientState *peer;
+
+ if (s->always_svq || s->log_enabled == enable) {
+ return;
+ }
+
+ s->log_enabled = enable;
+ vdev = v->dev->vdev;
+ n = VIRTIO_NET(vdev);
+ if (!n->vhost_started) {
+ return;
+ }
+
+ if (enable) {
+ ioctl(v->device_fd, VHOST_VDPA_SUSPEND);
+ }
+ data_queue_pairs = n->multiqueue ? n->max_queue_pairs : 1;
+ cvq = virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ) ?
+ n->max_ncs - n->max_queue_pairs : 0;
+ vhost_net_stop(vdev, n->nic->ncs, data_queue_pairs, cvq);
+
+ peer = s->nc.peer;
+ for (int i = 0; i < data_queue_pairs + cvq; i++) {
+ VhostVDPAState *vdpa_state;
+ NetClientState *nc;
+
+ if (i < data_queue_pairs) {
+ nc = qemu_get_peer(peer, i);
+ } else {
+ nc = qemu_get_peer(peer, n->max_queue_pairs);
+ }
+
+ vdpa_state = DO_UPCAST(VhostVDPAState, nc, nc);
+ vdpa_state->vhost_vdpa.listener_shadow_vq = enable;
+ vdpa_state->vhost_vdpa.shadow_vqs_enabled = enable;
+ vdpa_state->log_enabled = enable;
+ }
+
+ r = vhost_net_start(vdev, n->nic->ncs, data_queue_pairs, cvq);
+ if (unlikely(r < 0)) {
+ error_report("unable to start vhost net: %s(%d)", g_strerror(-r), -r);
+ }
+}
+
+static void vhost_vdpa_net_log_global_start(MemoryListener *listener)
+{
+ vhost_vdpa_net_log_global_enable(listener, true);
+}
+
+static void vhost_vdpa_net_log_global_stop(MemoryListener *listener)
+{
+ vhost_vdpa_net_log_global_enable(listener, false);
+}
+
static NetClientInfo net_vhost_vdpa_info = {
.type = NET_CLIENT_DRIVER_VHOST_VDPA,
.size = sizeof(VhostVDPAState),
@@ -413,6 +492,7 @@ static void vhost_vdpa_net_cvq_stop(NetClientState *nc)
assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA);
+ memory_listener_unregister(&s->memory_listener);
if (s->vhost_vdpa.shadow_vqs_enabled) {
vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, s->cvq_cmd_out_buffer);
vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, s->cvq_cmd_in_buffer);
@@ -671,6 +751,13 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
s->vhost_vdpa.shadow_vqs_enabled = svq;
s->vhost_vdpa.listener_shadow_vq = svq;
s->vhost_vdpa.iova_tree = iova_tree;
+ if (queue_pair_index == 0) {
+ s->memory_listener = (MemoryListener) {
+ .log_global_start = vhost_vdpa_net_log_global_start,
+ .log_global_stop = vhost_vdpa_net_log_global_stop,
+ };
+ memory_listener_register(&s->memory_listener, &address_space_memory);
+ }
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
next prev parent reply other threads:[~2022-08-10 18:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-10 18:42 [RFC 0/8] Dinamycally switch to vhost shadow virtqueues at vdpa net migration Eugenio Pérez
2022-08-10 18:42 ` [RFC 1/8] [NOTMERGE] Update linux headers Eugenio Pérez
2022-08-10 18:42 ` [RFC 2/8] vdpa: Extract get_backend_features from vhost_vdpa_get_as_num Eugenio Pérez
2022-08-10 18:42 ` [RFC 3/8] vhost: expose memory listener priority Eugenio Pérez
2022-08-10 18:42 ` [RFC 4/8] vdpa: Add log_enabled to VhostVDPAState Eugenio Pérez
2022-08-10 18:42 ` Eugenio Pérez [this message]
2022-08-19 6:28 ` [RFC 5/8] vdpa: Add vdpa memory listener Jason Wang
2022-08-19 8:30 ` Eugenio Perez Martin
2022-08-19 9:00 ` Jason Wang
2022-08-19 10:34 ` Eugenio Perez Martin
2022-08-23 3:58 ` Jason Wang
2022-11-09 15:41 ` Eugenio Perez Martin
2022-08-10 18:42 ` [RFC 6/8] vdpa: Negotiate _F_SUSPEND feature Eugenio Pérez
2022-08-10 18:42 ` [RFC 7/8] vdpa: Add feature_log member to vhost_vdpa Eugenio Pérez
2022-08-10 18:42 ` [RFC 8/8] vdpa: Conditionally expose _F_LOG in vhost_net devices Eugenio Pérez
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=20220810184220.2362292-6-eperezma@redhat.com \
--to=eperezma@redhat.com \
--cc=arei.gonglei@huawei.com \
--cc=cohuck@redhat.com \
--cc=eli@mellanox.com \
--cc=gdawar@xilinx.com \
--cc=hanand@xilinx.com \
--cc=jasowang@redhat.com \
--cc=lingshan.zhu@intel.com \
--cc=liuxiangdong5@huawei.com \
--cc=lulu@redhat.com \
--cc=lvivier@redhat.com \
--cc=mst@redhat.com \
--cc=parav@mellanox.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.com \
--cc=stefanha@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).