qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Yajun Wu <yajunw@nvidia.com>
To: <qemu-devel@nongnu.org>, <jasowang@redhat.com>, <mst@redhat.com>,
	<yajunw@nvidia.com>
Cc: Avihai Horon <avihaih@nvidia.com>, Jiri Pirko <jiri@nvidia.com>
Subject: [RFC PATCH 1/5] vhost-user: Add presetup protocol feature and op
Date: Mon, 18 Sep 2023 12:49:28 +0800	[thread overview]
Message-ID: <20230918044932.1433744-2-yajunw@nvidia.com> (raw)
In-Reply-To: <20230918044932.1433744-1-yajunw@nvidia.com>

This patch implements VHOST_USER_PROTOCOL_F_PRESETUP protocol feature
and VHOST_USER_PRESETUP, so that the backend can know the beginning
and completion of the early setup phase for the virtio device.

Unlike the regular device state load, which occurs in the VM stop
phase, this pre-setup takes place in the live migration setup stage.

Signed-off-by: Yajun Wu <yajunw@nvidia.com>
Reviewed-by: Avihai Horon <avihaih@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
---
 docs/interop/vhost-user.rst       | 10 ++++++++++
 hw/virtio/vhost-user.c            | 30 ++++++++++++++++++++++++++++++
 include/hw/virtio/vhost-backend.h |  3 +++
 3 files changed, 43 insertions(+)

diff --git a/docs/interop/vhost-user.rst b/docs/interop/vhost-user.rst
index 5a070adbc1..70b8e2694c 100644
--- a/docs/interop/vhost-user.rst
+++ b/docs/interop/vhost-user.rst
@@ -885,6 +885,7 @@ Protocol features
   #define VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS  15
   #define VHOST_USER_PROTOCOL_F_STATUS               16
   #define VHOST_USER_PROTOCOL_F_XEN_MMAP             17
+  #define VHOST_USER_PROTOCOL_F_PRESETUP             18
 
 Front-end message types
 -----------------------
@@ -1440,6 +1441,15 @@ Front-end message types
   query the back-end for its device status as defined in the Virtio
   specification.
 
+``VHOST_USER_PRESETUP``
+  :id: 41
+  :equivalent ioctl: N/A
+  :request payload: ``u64``
+  :reply payload: N/A
+
+  When the ``VHOST_USER_PROTOCOL_F_PRESETUP`` protocol feature has been
+  successfully negotiated, this message is submitted by the front-end to
+  indicate start or end early setup. Value 1 means start, 2 means end.
 
 Back-end message types
 ----------------------
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 8dcf049d42..71018d06c1 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -74,6 +74,8 @@ enum VhostUserProtocolFeature {
     /* Feature 14 reserved for VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS. */
     VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS = 15,
     VHOST_USER_PROTOCOL_F_STATUS = 16,
+    /* Feature 17 reserved for VHOST_USER_PROTOCOL_F_XEN_MMAP. */
+    VHOST_USER_PROTOCOL_F_PRESETUP = 18,
     VHOST_USER_PROTOCOL_F_MAX
 };
 
@@ -121,6 +123,7 @@ typedef enum VhostUserRequest {
     VHOST_USER_REM_MEM_REG = 38,
     VHOST_USER_SET_STATUS = 39,
     VHOST_USER_GET_STATUS = 40,
+    VHOST_USER_PRESETUP = 41,
     VHOST_USER_MAX
 } VhostUserRequest;
 
@@ -132,6 +135,11 @@ typedef enum VhostUserBackendRequest {
     VHOST_USER_BACKEND_MAX
 }  VhostUserBackendRequest;
 
+typedef enum VhostUserPresetupState {
+    VHOST_USER_PRESETUP_START = 1,
+    VHOST_USER_PRESETUP_END = 2,
+} VhostUserPresetupState;
+
 typedef struct VhostUserMemoryRegion {
     uint64_t guest_phys_addr;
     uint64_t memory_size;
@@ -2741,6 +2749,27 @@ static void vhost_user_reset_status(struct vhost_dev *dev)
     }
 }
 
+static int vhost_user_set_presetup_state(struct vhost_dev *dev, bool start)
+{
+    if (start) {
+        return vhost_user_set_u64(dev, VHOST_USER_PRESETUP,
+                                  VHOST_USER_PRESETUP_START, false);
+    } else {
+        return vhost_user_set_u64(dev, VHOST_USER_PRESETUP,
+                                  VHOST_USER_PRESETUP_END, false);
+    }
+}
+
+static int vhost_user_presetup(struct vhost_dev *dev, bool start)
+{
+    if (!virtio_has_feature(dev->protocol_features,
+                            VHOST_USER_PROTOCOL_F_PRESETUP)) {
+        return -ENOTSUP;
+    }
+
+    return vhost_user_set_presetup_state(dev, start);
+}
+
 const VhostOps user_ops = {
         .backend_type = VHOST_BACKEND_TYPE_USER,
         .vhost_backend_init = vhost_user_backend_init,
@@ -2777,4 +2806,5 @@ const VhostOps user_ops = {
         .vhost_set_inflight_fd = vhost_user_set_inflight_fd,
         .vhost_dev_start = vhost_user_dev_start,
         .vhost_reset_status = vhost_user_reset_status,
+        .vhost_presetup = vhost_user_presetup,
 };
diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h
index 31a251a9f5..00dd532df9 100644
--- a/include/hw/virtio/vhost-backend.h
+++ b/include/hw/virtio/vhost-backend.h
@@ -133,6 +133,8 @@ typedef int (*vhost_set_config_call_op)(struct vhost_dev *dev,
 
 typedef void (*vhost_reset_status_op)(struct vhost_dev *dev);
 
+typedef int (*vhost_presetup_op)(struct vhost_dev *dev, bool start);
+
 typedef struct VhostOps {
     VhostBackendType backend_type;
     vhost_backend_init vhost_backend_init;
@@ -181,6 +183,7 @@ typedef struct VhostOps {
     vhost_force_iommu_op vhost_force_iommu;
     vhost_set_config_call_op vhost_set_config_call;
     vhost_reset_status_op vhost_reset_status;
+    vhost_presetup_op vhost_presetup;
 } VhostOps;
 
 int vhost_backend_update_device_iotlb(struct vhost_dev *dev,
-- 
2.27.0



  reply	other threads:[~2023-09-18  4:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-18  4:49 [RFC PATCH 0/5] virtio-net: Introduce LM early load Yajun Wu
2023-09-18  4:49 ` Yajun Wu [this message]
2023-09-18  4:49 ` [RFC PATCH 2/5] vhost: Add support for presetup Yajun Wu
2023-12-22 18:46   ` Eugenio Perez Martin
2023-09-18  4:49 ` [RFC PATCH 3/5] vhost-net: " Yajun Wu
2023-09-18  4:49 ` [RFC PATCH 4/5] virtio: Add VMState for early load Yajun Wu
2023-12-22 17:36   ` Eugenio Perez Martin
2023-09-18  4:49 ` [RFC PATCH 5/5] virtio-net: Introduce LM " Yajun Wu
2023-12-22 18:58   ` Eugenio Perez Martin
2023-10-17  7:32 ` [RFC PATCH 0/5] " Yajun Wu
2023-10-17 16:47 ` Eugenio Perez Martin
2023-10-18  6:40   ` Yajun Wu
2023-10-19 15:00     ` Eugenio Perez Martin
2023-12-22 19:07       ` Eugenio Perez Martin

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=20230918044932.1433744-2-yajunw@nvidia.com \
    --to=yajunw@nvidia.com \
    --cc=avihaih@nvidia.com \
    --cc=jasowang@redhat.com \
    --cc=jiri@nvidia.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).