Skip to contentSkip to conversation

vhost-user-blk: Add support for backend reconnecting

PATCH Superseded [email protected] 4 participants 26 messages Jan 22, 2019 – Feb 5, 2019 Kbuild

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover vhost-user-blk: Add support for backend reconnecting

From: Xie Yongji <[email protected]>

This patchset is aimed at supporting qemu to reconnect vhost-user-blk backend after vhost-user-blk backend crash or restart.

The patch 1 introduces two new messages VHOST_USER_GET_INFLIGHT_FD and VHOST_USER_SET_INFLIGHT_FD to support support transferring shared buffer between qemu and backend.

The patch 2,3 are the corresponding libvhost-user patches of patch 1. Make libvhost-user support VHOST_USER_GET_INFLIGHT_FD and VHOST_USER_SET_INFLIGHT_FD.

The patch 4 allows vhost-user-blk to use the two new messages to get/set inflight buffer from/to backend.

The patch 5 supports vhost-user-blk to reconnect backend when connection closed.

The patch 6 introduces VHOST_USER_PROTOCOL_F_SLAVE_SHMFD to vhost-user-blk backend which is used to tell qemu that we support reconnecting now.

This series is based on Daniel P. Berrangé's patchset:

https://lists.gnu.org/archive/html/qemu-devel/2019-01/msg03344.html

To use it, we could start qemu with:

qemu-system-x86_64 \
        -chardev socket,id=char0,path=/path/vhost.socket,reconnect=1, \
        -device vhost-user-blk-pci,chardev=char0 \

and start vhost-user-blk backend with:

vhost-user-blk -b /path/file -s /path/vhost.socket

Then we can restart vhost-user-blk at any time during VM running.

V4 to V5:
- Drop patch that enables "nowait" option on client sockets
- Support resubmitting inflight I/O in order
- Make inflight I/O tracking more robust
- Remove align field and add queue size field in VhostUserInflight
- Document more details in vhost-user.txt

V3 to V4:
- Drop messages VHOST_USER_GET_SHM_SIZE and VHOST_USER_SET_SHM_FD
- Introduce two new messages VHOST_USER_GET_INFLIGHT_FD and VHOST_USER_SET_INFLIGHT_FD
- Allocate inflight buffer in backend rather than in qemu
- Document a recommended format for inflight buffer

V2 to V3:
- Using exisiting wait/nowait options to control connection on client sockets instead of introducing "disconnected" option.
- Support the case that vhost-user backend restart during initialzation of vhost-user-blk device.

V1 to V2:
- Introduce "disconnected" option for chardev instead of reuse "wait" option
- Support the case that QEMU starts before vhost-user backend
- Drop message VHOST_USER_SET_VRING_INFLIGHT
- Introduce two new messages VHOST_USER_GET_SHM_SIZE
and VHOST_USER_SET_SHM_FD

Xie Yongji (6):
vhost-user: Support transferring inflight buffer between qemu and
backend
libvhost-user: Introduce vu_queue_map_desc()
libvhost-user: Support tracking inflight I/O in shared memory
vhost-user-blk: Add support to get/set inflight buffer
vhost-user-blk: Add support to reconnect backend contrib/vhost-user-blk: enable inflight I/O tracking

 Makefile                                |   2 +-
 contrib/libvhost-user/libvhost-user.c   | 402 ++++++++++++++++++++----
 contrib/libvhost-user/libvhost-user.h   |  40 +++
 contrib/vhost-user-blk/vhost-user-blk.c |   3 +-
 docs/interop/vhost-user.txt             | 101 ++++++
 hw/block/vhost-user-blk.c               | 227 ++++++++++---
 hw/virtio/vhost-user.c                  | 110 +++++++
 hw/virtio/vhost.c                       | 105 +++++++
 include/hw/virtio/vhost-backend.h       |  10 +
 include/hw/virtio/vhost-user-blk.h      |   5 +
 include/hw/virtio/vhost.h               |  19 ++
 11 files changed, 925 insertions(+), 99 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v5 1/6 vhost-user: Support transferring inflight buffer between qemu and backend

From: Xie Yongji <[email protected]>

This patch introduces two new messages VHOST_USER_GET_INFLIGHT_FD and VHOST_USER_SET_INFLIGHT_FD to support transferring a shared buffer between qemu and backend.

Firstly, qemu uses VHOST_USER_GET_INFLIGHT_FD to get the shared buffer from backend. Then qemu should send it back through VHOST_USER_SET_INFLIGHT_FD each time we start vhost-user.

This shared buffer is used to track inflight I/O by backend. Qemu should clear it when vm reset.

---
 docs/interop/vhost-user.txt       | 101 +++++++++++++++++++++++++++
 hw/virtio/vhost-user.c            | 110 ++++++++++++++++++++++++++++++
 hw/virtio/vhost.c                 | 105 ++++++++++++++++++++++++++++
 include/hw/virtio/vhost-backend.h |  10 +++
 include/hw/virtio/vhost.h         |  19 ++++++
 5 files changed, 345 insertions(+)
docs/interop/vhost-user.txt +101 -0
index c2194711d9..fa470a8fe2 100644
@@ -142,6 +142,18 @@ Depending on the request type, payload can be:
    Offset: a 64-bit offset of this area from the start of the
        supplied file descriptor
 
+ * Inflight description
+   ---------------------------------------------------------------
+   | mmap size | mmap offset | version | num queues | queue size |
+   ---------------------------------------------------------------
+
+   mmap size: a 64-bit size of area to track inflight I/O
+   mmap offset: a 64-bit offset of this area from the start
+                of the supplied file descriptor
+   version: a 16-bit version of this area
+   num queues: a 16-bit number of virtqueues
+   queue size: a 16-bit size of virtqueues
+
 In QEMU the vhost-user message is implemented with the following struct:
 
 typedef struct VhostUserMsg {
@@ -157,6 +169,7 @@ typedef struct VhostUserMsg {
         struct vhost_iotlb_msg iotlb;
         VhostUserConfig config;
         VhostUserVringArea area;
+        VhostUserInflight inflight;
     };
 } QEMU_PACKED VhostUserMsg;
 
@@ -175,6 +188,7 @@ the ones that do:
  * VHOST_USER_GET_PROTOCOL_FEATURES
  * VHOST_USER_GET_VRING_BASE
  * VHOST_USER_SET_LOG_BASE (if VHOST_USER_PROTOCOL_F_LOG_SHMFD)
+ * VHOST_USER_GET_INFLIGHT_FD (if VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)
 
 [ Also see the section on REPLY_ACK protocol extension. ]
 
@@ -188,6 +202,7 @@ in the ancillary data:
  * VHOST_USER_SET_VRING_CALL
  * VHOST_USER_SET_VRING_ERR
  * VHOST_USER_SET_SLAVE_REQ_FD
+ * VHOST_USER_SET_INFLIGHT_FD (if VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)
 
 If Master is unable to send the full message or receives a wrong reply it will
 close the connection. An optional reconnection mechanism can be implemented.
@@ -382,6 +397,71 @@ If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated,
 slave can send file descriptors (at most 8 descriptors in each message)
 to master via ancillary data using this fd communication channel.
 
+Inflight I/O tracking
+---------------------
+
+To support reconnecting after restart or crash, slave may need to get
+and resubmit inflight I/O. If virtqueue is processed in order, we can
+easily achieve that by getting the inflight head-descriptor from avail ring.
+However, it can't work when we process descriptors out-of-order because
+some entries which store inflight head-descriptor in avail ring might be
+overrided by new entries. To solve this problem, slave need to allocate a
+buffer to track inflight head-descriptor and share it with master for
+persistent. VHOST_USER_GET_INFLIGHT_FD and VHOST_USER_SET_INFLIGHT_FD are
+used to transfer this buffer between master and slave. And the format of
+this buffer is described below:
+
+-------------------------------------------------------
+| queue0 region | queue1 region | ... | queueN region |
+-------------------------------------------------------
+
+N is the number of available virtqueues. Slave could get it from num queues
+field of VhostUserInflight.
+
+Queue region can be implemented as:
+
+typedef struct DescState {
+    uint8_t inuse;
+    uint8_t version;
+    uint16_t used_idx;
+    uint16_t avail_idx;
+    uint16_t reserved;
+} DescState;
+
+typedef struct QueueRegion {
+    uint8_t valid;
+    uint16_t desc_num;
+    DescState desc[0];
+} QueueRegion;
+
+The struct DescState is used to describe one head-descriptor's state. The
+fields have following meanings:
+
+    inuse: Indicate whether the descriptor is inuse or not.
+
+    version: Indicate whether we have an atomic update to used ring and
+    inflight buffer when slave crash at that point. This field should be
+    increased by one before and after this two updates. An odd version
+    indicates an in-progress update.
+
+    used_idx: Store old index of used ring before we update used ring and
+    inflight buffer so that slave can know whether an odd version inflight
+    head-descriptor in inflight buffer is processed or not.
+
+    avail_idx: Used to preserve the descriptor's order in avail ring so that
+    slave can resubmit descriptors in order.
+
+    reserved: Reserved for future use.
+
+An array of struct DescState is maintained to track all head-descriptors' state
+in queue region. The desc_num is the number of those head-descriptors which is
+also equal to the queue size of the virtqueue. Slave could get it from queue size
+field of VhostUserInflight. The valid field is used to specify whether the region
+is valid or not. Slave can use it to detect whether vm is reset because qemu will
+clear the buffer when the reset happens.
+
+Note that slave should align each region to cache line size.
+
 Protocol features
 -----------------
 
@@ -397,6 +477,7 @@ Protocol features
 #define VHOST_USER_PROTOCOL_F_CONFIG         9
 #define VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD  10
 #define VHOST_USER_PROTOCOL_F_HOST_NOTIFIER  11
+#define VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD 12
 
 Master message types
 --------------------
@@ -761,6 +842,26 @@ Master message types
       was previously sent.
       The value returned is an error indication; 0 is success.
 
+ * VHOST_USER_GET_INFLIGHT_FD
+      Id: 31
+      Equivalent ioctl: N/A
+      Master payload: inflight description
+
+      When VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD protocol feature has been
+      successfully negotiated, this message is submitted by master to get
+      a shared buffer from slave. The shared buffer will be used to track
+      inflight I/O by slave. QEMU should clear it when vm reset.
+
+ * VHOST_USER_SET_INFLIGHT_FD
+      Id: 32
+      Equivalent ioctl: N/A
+      Master payload: inflight description
+
+      When VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD protocol feature has been
+      successfully negotiated, this message is submitted by master to send
+      the shared inflight buffer back to slave so that slave could get
+      inflight I/O after a crash or restart.
+
 Slave message types
 -------------------
 
hw/virtio/vhost-user.c +110 -0

144 lines not on this page · raw message

hw/virtio/vhost.c +105 -0

111 lines not on this page · raw message

include/hw/virtio/vhost-backend.h +10 -0
index 81283ec50f..d6632a18e6 100644
@@ -25,6 +25,7 @@ typedef enum VhostSetConfigType {
     VHOST_SET_CONFIG_TYPE_MIGRATION = 1,
 } VhostSetConfigType;
 
+struct vhost_inflight;
 struct vhost_dev;
 struct vhost_log;
 struct vhost_memory;
@@ -104,6 +105,13 @@ typedef int (*vhost_crypto_close_session_op)(struct vhost_dev *dev,
 typedef bool (*vhost_backend_mem_section_filter_op)(struct vhost_dev *dev,
                                                 MemoryRegionSection *section);
 
+typedef int (*vhost_get_inflight_fd_op)(struct vhost_dev *dev,
+                                        uint16_t queue_size,
+                                        struct vhost_inflight *inflight);
+
+typedef int (*vhost_set_inflight_fd_op)(struct vhost_dev *dev,
+                                        struct vhost_inflight *inflight);
+
 typedef struct VhostOps {
     VhostBackendType backend_type;
     vhost_backend_init vhost_backend_init;
@@ -142,6 +150,8 @@ typedef struct VhostOps {
     vhost_crypto_create_session_op vhost_crypto_create_session;
     vhost_crypto_close_session_op vhost_crypto_close_session;
     vhost_backend_mem_section_filter_op vhost_backend_mem_section_filter;
+    vhost_get_inflight_fd_op vhost_get_inflight_fd;
+    vhost_set_inflight_fd_op vhost_set_inflight_fd;
 } VhostOps;
 
 extern const VhostOps user_ops;
include/hw/virtio/vhost.h +19 -0
index a7f449fa87..f44f93f54a 100644
@@ -7,6 +7,16 @@
 #include "exec/memory.h"
 
 /* Generic structures common for any vhost based device. */
+
+struct vhost_inflight {
+    int fd;
+    void *addr;
+    uint64_t size;
+    uint64_t offset;
+    uint16_t version;
+    uint16_t queue_size;
+};
+
 struct vhost_virtqueue {
     int kick;
     int call;
@@ -120,4 +130,13 @@ int vhost_dev_set_config(struct vhost_dev *dev, const uint8_t *data,
  */
 void vhost_dev_set_config_notifier(struct vhost_dev *dev,
                                    const VhostDevConfigOps *ops);
+
+void vhost_dev_reset_inflight(struct vhost_inflight *inflight);
+void vhost_dev_free_inflight(struct vhost_inflight *inflight);
+void vhost_dev_save_inflight(struct vhost_inflight *inflight, QEMUFile *f);
+int vhost_dev_load_inflight(struct vhost_inflight *inflight, QEMUFile *f);
+int vhost_dev_set_inflight(struct vhost_dev *dev,
+                           struct vhost_inflight *inflight);
+int vhost_dev_get_inflight(struct vhost_dev *dev, uint16_t queue_size,
+                           struct vhost_inflight *inflight);
 #endif
Signature · 1 line
2.17.1
#2 lore raw

Re: [Qemu-devel] [PATCH v5 1/6] vhost-user: Support transferring inflight buffer between qemu and backend

Quoted 20 lines · On Tue, Jan 22, 2019 at 04:31:47PM +0800, [email protected] wrote:
docs/interop/vhost-user.txt +20 -0
+typedef struct DescState {
+    uint8_t inuse;
+    uint8_t version;
+    uint16_t used_idx;
+    uint16_t avail_idx;
+    uint16_t reserved;
+} DescState;
+
+typedef struct QueueRegion {
+    uint8_t valid;
+    uint16_t desc_num;
+    DescState desc[0];
+} QueueRegion;
+
+The struct DescState is used to describe one head-descriptor's state. The
+fields have following meanings:
+
+    inuse: Indicate whether the descriptor is inuse or not.
+
+    version: Indicate whether we have an atomic update to used ring and

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 452

Quoted 10 lines
docs/interop/vhost-user.txt +10 -0
+    inflight buffer when slave crash at that point. This field should be
+    increased by one before and after this two updates. An odd version
+    indicates an in-progress update.
+
+    used_idx: Store old index of used ring before we update used ring and
+    inflight buffer so that slave can know whether an odd version inflight
+    head-descriptor in inflight buffer is processed or not.
+
+    avail_idx: Used to preserve the descriptor's order in avail ring so that
+    slave can resubmit descriptors in order.

Will a completely new "packed vring" inflight shm layout be necessary to support the packed vring layout in VIRTIO 1.1?

https://docs.oasis-open.org/virtio/virtio/v1.1/csprd01/virtio-v1.1-csprd01.html#x1-610007

#3 lore raw

Re: [Qemu-devel] [PATCH v5 1/6] vhost-user: Support transferring inflight buffer between qemu and backend

Quoted 11 lines · Stefan Hajnoczi

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 432

Quoted 10 lines · On Tue, Jan 22, 2019 at 04:31:47PM +0800, [email protected] wrote:
docs/interop/vhost-user.txt +10 -0
+typedef struct DescState {
+    uint8_t inuse;
+    uint8_t version;
+    uint16_t used_idx;
+    uint16_t avail_idx;
+    uint16_t reserved;
+} DescState;
+
+typedef struct QueueRegion {
+    uint8_t valid;

what's this?

Quoted 1 line
Quoted 1 line

+ uint16_t desc_num;

there's padding before this field. Pls make it explicit.

Quoted 7 lines

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 440

Quoted 7 lines
docs/interop/vhost-user.txt +7 -0
+    DescState desc[0];
+} QueueRegion;
+
+The struct DescState is used to describe one head-descriptor's state. The
+fields have following meanings:
+
+    inuse: Indicate whether the descriptor is inuse or not.

inuse by what?

Quoted 5 lines

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 445

Quoted 5 lines
docs/interop/vhost-user.txt +5 -0
+
+    version: Indicate whether we have an atomic update to used ring and
+    inflight buffer when slave crash at that point. This field should be
+    increased by one before and after this two updates. An odd version
+    indicates an in-progress update.

I'm not sure I understand what does the above say. Also does this require two atomics? Seems pretty expensive. And why is it called version?

Quoted 4 lines

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 449

Quoted 4 lines
docs/interop/vhost-user.txt +4 -0
+
+    used_idx: Store old index of used ring before we update used ring and
+    inflight buffer so that slave can know whether an odd version inflight
+    head-descriptor in inflight buffer is processed or not.

Here too.

Quoted 3 lines

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 452

Quoted 3 lines
docs/interop/vhost-user.txt +3 -0
+
+    avail_idx: Used to preserve the descriptor's order in avail ring so that
+    slave can resubmit descriptors in order.

Why would that be necessary?

Quoted 5 lines

Will a completely new "packed vring" inflight shm layout be necessary to support the packed vring layout in VIRTIO 1.1?

https://docs.oasis-open.org/virtio/virtio/v1.1/csprd01/virtio-v1.1-csprd01.html#x1-610007

Probably.

Signature · 1 line
MST
author
#4 lore raw

Re: [Qemu-devel] [PATCH v5 1/6] vhost-user: Support transferring inflight buffer between qemu and backend

Quoted 16 lines · Michael S. Tsirkin
Quoted 11 lines · Stefan Hajnoczi

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 432

Quoted 10 lines · On Tue, Jan 22, 2019 at 04:31:47PM +0800, [email protected] wrote:
docs/interop/vhost-user.txt +10 -0
+typedef struct DescState {
+    uint8_t inuse;
+    uint8_t version;
+    uint16_t used_idx;
+    uint16_t avail_idx;
+    uint16_t reserved;
+} DescState;
+
+typedef struct QueueRegion {
+    uint8_t valid;

what's this?

We can use this to check whether this buffer is reset by qemu.

Quoted 4 lines
Quoted 1 line
Quoted 1 line

+ uint16_t desc_num;

there's padding before this field. Pls make it explicit.

Will do it.

Quoted 10 lines
Quoted 7 lines

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 440

Quoted 7 lines
docs/interop/vhost-user.txt +7 -0
+    DescState desc[0];
+} QueueRegion;
+
+The struct DescState is used to describe one head-descriptor's state. The
+fields have following meanings:
+
+    inuse: Indicate whether the descriptor is inuse or not.

inuse by what?

Maybe inflight is better?

Quoted 10 lines
Quoted 5 lines

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 445

Quoted 5 lines
docs/interop/vhost-user.txt +5 -0
+
+    version: Indicate whether we have an atomic update to used ring and
+    inflight buffer when slave crash at that point. This field should be
+    increased by one before and after this two updates. An odd version
+    indicates an in-progress update.

I'm not sure I understand what does the above say. Also does this require two atomics? Seems pretty expensive. And why is it called version?

Quoted 7 lines
Quoted 4 lines

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 449

Quoted 4 lines
docs/interop/vhost-user.txt +4 -0
+
+    used_idx: Store old index of used ring before we update used ring and
+    inflight buffer so that slave can know whether an odd version inflight
+    head-descriptor in inflight buffer is processed or not.

Here too.

Sorry, the above description may be not clear. This two fields are used to indicate whether we have an in-progress update to used ring and inflight buffer. If slave crash before the update to used_ring and after the update to inflight buffer, the version should be odd and used_idx should be equal to used_ring.idx. Then we need to roll back the update to inflight buffer. As for the name of the version filed, actually I didn't find a good one, so I just copy it from struct kvm_steal_time...

Quoted 6 lines
Quoted 3 lines

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 452

Quoted 3 lines
docs/interop/vhost-user.txt +3 -0
+
+    avail_idx: Used to preserve the descriptor's order in avail ring so that
+    slave can resubmit descriptors in order.

Why would that be necessary?

Maybe some devices will be able to use it to preserve order after reconnecting in future?

Quoted 8 lines
Quoted 5 lines

Will a completely new "packed vring" inflight shm layout be necessary to support the packed vring layout in VIRTIO 1.1?

https://docs.oasis-open.org/virtio/virtio/v1.1/csprd01/virtio-v1.1-csprd01.html#x1-610007

Probably.

How about supporting packed virtqueue in guest driver?

Thanks,
Yongji

#5 lore raw

Re: [Qemu-devel] [PATCH v5 1/6] vhost-user: Support transferring inflight buffer between qemu and backend

Quoted 18 lines · Yongji Xie
Quoted 16 lines · Michael S. Tsirkin
Quoted 11 lines · Stefan Hajnoczi

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 432

Quoted 10 lines · On Tue, Jan 22, 2019 at 04:31:47PM +0800, [email protected] wrote:
docs/interop/vhost-user.txt +10 -0
+typedef struct DescState {
+    uint8_t inuse;
+    uint8_t version;
+    uint16_t used_idx;
+    uint16_t avail_idx;
+    uint16_t reserved;
+} DescState;
+
+typedef struct QueueRegion {
+    uint8_t valid;

what's this?

Quoted 1 line

We can use this to check whether this buffer is reset by qemu.

I'd use version here. Document that it's 1 currently. Or do we want feature flags so we can support downgrades too?

Quoted 51 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

+ uint16_t desc_num;

there's padding before this field. Pls make it explicit.

Will do it.

Quoted 10 lines
Quoted 7 lines

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 440

Quoted 7 lines
docs/interop/vhost-user.txt +7 -0
+    DescState desc[0];
+} QueueRegion;
+
+The struct DescState is used to describe one head-descriptor's state. The
+fields have following meanings:
+
+    inuse: Indicate whether the descriptor is inuse or not.

inuse by what?

Maybe inflight is better?

Quoted 10 lines
Quoted 5 lines

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 445

Quoted 5 lines
docs/interop/vhost-user.txt +5 -0
+
+    version: Indicate whether we have an atomic update to used ring and
+    inflight buffer when slave crash at that point. This field should be
+    increased by one before and after this two updates. An odd version
+    indicates an in-progress update.

I'm not sure I understand what does the above say. Also does this require two atomics? Seems pretty expensive. And why is it called version?

Quoted 7 lines
Quoted 4 lines

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 449

Quoted 4 lines
docs/interop/vhost-user.txt +4 -0
+
+    used_idx: Store old index of used ring before we update used ring and
+    inflight buffer so that slave can know whether an odd version inflight
+    head-descriptor in inflight buffer is processed or not.

Here too.

Sorry, the above description may be not clear. This two fields are used to indicate whether we have an in-progress update to used ring and inflight buffer. If slave crash before the update to used_ring and after the update to inflight buffer, the version should be odd and used_idx should be equal to used_ring.idx. Then we need to roll back the update to inflight buffer. As for the name of the version filed, actually I didn't find a good one, so I just copy it from struct kvm_steal_time...

Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
docs/interop/vhost-user.txt +3 -0
+
+    avail_idx: Used to preserve the descriptor's order in avail ring so that
+    slave can resubmit descriptors in order.
Quoted 5 lines
Quoted 2 lines

Why would that be necessary?

Maybe some devices will be able to use it to preserve order after reconnecting in future?

If buffers are used in order then old entries in the ring are not overwritten so inflight tracking is not necessary. This is exactly the case with vhost user net today.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Will a completely new "packed vring" inflight shm layout be necessary to support the packed vring layout in VIRTIO 1.1?

https://docs.oasis-open.org/virtio/virtio/v1.1/csprd01/virtio-v1.1-csprd01.html#x1-610007

Quoted 7 lines
Quoted 2 lines

Probably.

How about supporting packed virtqueue in guest driver?

Thanks,
Yongji

Depends on the guest right? Linux has it:

commit f959a128fe83090981add69aadc87a4e496e9369

Author: Tiwei Bie <[email protected]>
Date:   Wed Nov 21 18:03:30 2018 +0800

virtio_ring: advertize packed ring layout

Signature · 1 line
MST
author
#6 lore raw

Re: [Qemu-devel] [PATCH v5 1/6] vhost-user: Support transferring inflight buffer between qemu and backend

Quoted 20 lines · Michael S. Tsirkin
Quoted 18 lines · Yongji Xie
Quoted 16 lines · Michael S. Tsirkin
Quoted 11 lines · Stefan Hajnoczi

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 432

Quoted 10 lines · On Tue, Jan 22, 2019 at 04:31:47PM +0800, [email protected] wrote:
docs/interop/vhost-user.txt +10 -0
+typedef struct DescState {
+    uint8_t inuse;
+    uint8_t version;
+    uint16_t used_idx;
+    uint16_t avail_idx;
+    uint16_t reserved;
+} DescState;
+
+typedef struct QueueRegion {
+    uint8_t valid;

what's this?

Quoted 4 lines
Quoted 1 line

We can use this to check whether this buffer is reset by qemu.

I'd use version here. Document that it's 1 currently.

If we put version into the shared buffer, QEMU will reset it when vm reset. Then if backend restart at the same time, the version of this buffer will be lost. So I still let QEMU maintain it and send it back through message's payload.

Quoted 2 lines

Or do we want feature flags so we can support downgrades too?

We faced the same problem that the feature flags will be lost if QEMU do not maintain it. So maybe we should put this into message's payload?

Quoted 55 lines
Quoted 55 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

+ uint16_t desc_num;

there's padding before this field. Pls make it explicit.

Will do it.

Quoted 10 lines
Quoted 7 lines

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 440

Quoted 7 lines
docs/interop/vhost-user.txt +7 -0
+    DescState desc[0];
+} QueueRegion;
+
+The struct DescState is used to describe one head-descriptor's state. The
+fields have following meanings:
+
+    inuse: Indicate whether the descriptor is inuse or not.

inuse by what?

Maybe inflight is better?

Quoted 10 lines
Quoted 5 lines

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 445

Quoted 5 lines
docs/interop/vhost-user.txt +5 -0
+
+    version: Indicate whether we have an atomic update to used ring and
+    inflight buffer when slave crash at that point. This field should be
+    increased by one before and after this two updates. An odd version
+    indicates an in-progress update.

I'm not sure I understand what does the above say. Also does this require two atomics? Seems pretty expensive. And why is it called version?

Quoted 7 lines
Quoted 4 lines

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 449

Quoted 4 lines
docs/interop/vhost-user.txt +4 -0
+
+    used_idx: Store old index of used ring before we update used ring and
+    inflight buffer so that slave can know whether an odd version inflight
+    head-descriptor in inflight buffer is processed or not.

Here too.

Sorry, the above description may be not clear. This two fields are used to indicate whether we have an in-progress update to used ring and inflight buffer. If slave crash before the update to used_ring and after the update to inflight buffer, the version should be odd and used_idx should be equal to used_ring.idx. Then we need to roll back the update to inflight buffer. As for the name of the version filed, actually I didn't find a good one, so I just copy it from struct kvm_steal_time...

Quoted 6 lines
Quoted 3 lines

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 452

Quoted 3 lines
docs/interop/vhost-user.txt +3 -0
+
+    avail_idx: Used to preserve the descriptor's order in avail ring so that
+    slave can resubmit descriptors in order.

Why would that be necessary?

Quoted 7 lines
Quoted 2 lines

Maybe some devices will be able to use it to preserve order after reconnecting in future?

If buffers are used in order then old entries in the ring are not overwritten so inflight tracking is not necessary. This is exactly the case with vhost user net today.

OK, looks reasonable to me.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

Will a completely new "packed vring" inflight shm layout be necessary to support the packed vring layout in VIRTIO 1.1?

https://docs.oasis-open.org/virtio/virtio/v1.1/csprd01/virtio-v1.1-csprd01.html#x1-610007

Probably.

Quoted 7 lines
Quoted 4 lines

How about supporting packed virtqueue in guest driver?

Thanks,
Yongji

Depends on the guest right? Linux has it:

Sorry, actually I mean I prefer to support inflight tracking for packed virtqueue in guest driver. This feature is only used by legacy virtio 1.0 or virtio 0.9 device. What do you think about it?

Thanks,
Yongji

#7 lore raw

Re: [Qemu-devel] [PATCH v5 1/6] vhost-user: Support transferring inflight buffer between qemu and backend

Quoted 24 lines · Yongji Xie
Quoted 23 lines · Michael S. Tsirkin
Quoted 19 lines · Yongji Xie
Quoted 16 lines · Michael S. Tsirkin
Quoted 11 lines · Stefan Hajnoczi

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 432

Quoted 10 lines · On Tue, Jan 22, 2019 at 04:31:47PM +0800, [email protected] wrote:
docs/interop/vhost-user.txt +10 -0
+typedef struct DescState {
+    uint8_t inuse;
+    uint8_t version;
+    uint16_t used_idx;
+    uint16_t avail_idx;
+    uint16_t reserved;
+} DescState;
+
+typedef struct QueueRegion {
+    uint8_t valid;

what's this?

We can use this to check whether this buffer is reset by qemu.

Quoted 6 lines
Quoted 1 line

I'd use version here. Document that it's 1 currently.

If we put version into the shared buffer, QEMU will reset it when vm reset. Then if backend restart at the same time, the version of this buffer will be lost. So I still let QEMU maintain it and send it back through message's payload.

I don't get it. If it's reset there's no contents. If there's no contents then who cares what the version is?

Quoted 6 lines
Quoted 2 lines

Or do we want feature flags so we can support downgrades too?

We faced the same problem that the feature flags will be lost if QEMU do not maintain it. So maybe we should put this into message's payload?

I don't understand why we care. We only maintain inflight so we don't need to reset the device. if device is reset we don't need to maintain them at all.

Quoted 82 lines
Quoted 55 lines
Quoted 55 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

+ uint16_t desc_num;

there's padding before this field. Pls make it explicit.

Will do it.

Quoted 10 lines
Quoted 7 lines

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 440

Quoted 7 lines
docs/interop/vhost-user.txt +7 -0
+    DescState desc[0];
+} QueueRegion;
+
+The struct DescState is used to describe one head-descriptor's state. The
+fields have following meanings:
+
+    inuse: Indicate whether the descriptor is inuse or not.

inuse by what?

Maybe inflight is better?

Quoted 10 lines
Quoted 5 lines

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 445

Quoted 5 lines
docs/interop/vhost-user.txt +5 -0
+
+    version: Indicate whether we have an atomic update to used ring and
+    inflight buffer when slave crash at that point. This field should be
+    increased by one before and after this two updates. An odd version
+    indicates an in-progress update.

I'm not sure I understand what does the above say. Also does this require two atomics? Seems pretty expensive. And why is it called version?

Quoted 7 lines
Quoted 4 lines

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 449

Quoted 4 lines
docs/interop/vhost-user.txt +4 -0
+
+    used_idx: Store old index of used ring before we update used ring and
+    inflight buffer so that slave can know whether an odd version inflight
+    head-descriptor in inflight buffer is processed or not.

Here too.

Sorry, the above description may be not clear. This two fields are used to indicate whether we have an in-progress update to used ring and inflight buffer. If slave crash before the update to used_ring and after the update to inflight buffer, the version should be odd and used_idx should be equal to used_ring.idx. Then we need to roll back the update to inflight buffer. As for the name of the version filed, actually I didn't find a good one, so I just copy it from struct kvm_steal_time...

Quoted 6 lines
Quoted 3 lines

docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 452

Quoted 3 lines
docs/interop/vhost-user.txt +3 -0
+
+    avail_idx: Used to preserve the descriptor's order in avail ring so that
+    slave can resubmit descriptors in order.

Why would that be necessary?

Quoted 7 lines
Quoted 2 lines

Maybe some devices will be able to use it to preserve order after reconnecting in future?

If buffers are used in order then old entries in the ring are not overwritten so inflight tracking is not necessary. This is exactly the case with vhost user net today.

OK, looks reasonable to me.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

Will a completely new "packed vring" inflight shm layout be necessary to support the packed vring layout in VIRTIO 1.1?

https://docs.oasis-open.org/virtio/virtio/v1.1/csprd01/virtio-v1.1-csprd01.html#x1-610007

Probably.

Quoted 7 lines
Quoted 4 lines

How about supporting packed virtqueue in guest driver?

Thanks,
Yongji

Depends on the guest right? Linux has it:

Quoted 6 lines

Sorry, actually I mean I prefer to support inflight tracking for packed virtqueue in guest driver. This feature is only used by legacy virtio 1.0 or virtio 0.9 device. What do you think about it?

Thanks,
Yongji

I don't see what does one have to do with the other. Either we do or we don't want to do it without downtime and retries. If we don't mind resets then let's do it by making guest changes.

Signature · 1 line
MST
author
#8 lore raw

Re: [Qemu-devel] [PATCH v5 1/6] vhost-user: Support transferring inflight buffer between qemu and backend

Quoted 28 lines · Michael S. Tsirkin
Quoted 26 lines · Yongji Xie
Quoted 24 lines · Michael S. Tsirkin
Quoted 18 lines · Yongji Xie
Quoted 16 lines · Michael S. Tsirkin
Quoted 11 lines · Stefan Hajnoczi

Review

Quoted 10 lines · On Tue, Jan 22, 2019 at 04:31:47PM +0800, [email protected] wrote:
(quoted diff) +10 -0
+typedef struct DescState {
+    uint8_t inuse;
+    uint8_t version;
+    uint16_t used_idx;
+    uint16_t avail_idx;
+    uint16_t reserved;
+} DescState;
+
+typedef struct QueueRegion {
+    uint8_t valid;

what's this?

Quoted 1 line

We can use this to check whether this buffer is reset by qemu.

I'd use version here. Document that it's 1 currently.

Quoted 8 lines
Quoted 4 lines

If we put version into the shared buffer, QEMU will reset it when vm reset. Then if backend restart at the same time, the version of this buffer will be lost. So I still let QEMU maintain it and send it back through message's payload.

I don't get it. If it's reset there's no contents. If there's no contents then who cares what the version is?

What I thought before is that we should not update the buffer when vm reset. But now seems like it's unnecessary. I will update this patch as you said. Thank you!

Quoted 97 lines
Quoted 6 lines
Quoted 2 lines

Or do we want feature flags so we can support downgrades too?

We faced the same problem that the feature flags will be lost if QEMU do not maintain it. So maybe we should put this into message's payload?

I don't understand why we care. We only maintain inflight so we don't need to reset the device. if device is reset we don't need to maintain them at all.

Quoted 86 lines
Quoted 55 lines
Quoted 55 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

+ uint16_t desc_num;

there's padding before this field. Pls make it explicit.

Will do it.

Quoted 10 lines
Quoted 7 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+    DescState desc[0];
+} QueueRegion;
+
+The struct DescState is used to describe one head-descriptor's state. The
+fields have following meanings:
+
+    inuse: Indicate whether the descriptor is inuse or not.

inuse by what?

Maybe inflight is better?

Quoted 10 lines
Quoted 5 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+
+    version: Indicate whether we have an atomic update to used ring and
+    inflight buffer when slave crash at that point. This field should be
+    increased by one before and after this two updates. An odd version
+    indicates an in-progress update.

I'm not sure I understand what does the above say. Also does this require two atomics? Seems pretty expensive. And why is it called version?

Quoted 7 lines
Quoted 4 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+
+    used_idx: Store old index of used ring before we update used ring and
+    inflight buffer so that slave can know whether an odd version inflight
+    head-descriptor in inflight buffer is processed or not.

Here too.

Sorry, the above description may be not clear. This two fields are used to indicate whether we have an in-progress update to used ring and inflight buffer. If slave crash before the update to used_ring and after the update to inflight buffer, the version should be odd and used_idx should be equal to used_ring.idx. Then we need to roll back the update to inflight buffer. As for the name of the version filed, actually I didn't find a good one, so I just copy it from struct kvm_steal_time...

Quoted 6 lines
Quoted 3 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+
+    avail_idx: Used to preserve the descriptor's order in avail ring so that
+    slave can resubmit descriptors in order.

Why would that be necessary?

Quoted 7 lines
Quoted 2 lines

Maybe some devices will be able to use it to preserve order after reconnecting in future?

If buffers are used in order then old entries in the ring are not overwritten so inflight tracking is not necessary. This is exactly the case with vhost user net today.

OK, looks reasonable to me.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

Will a completely new "packed vring" inflight shm layout be necessary to support the packed vring layout in VIRTIO 1.1?

https://docs.oasis-open.org/virtio/virtio/v1.1/csprd01/virtio-v1.1-csprd01.html#x1-610007

Probably.

Quoted 7 lines
Quoted 4 lines

How about supporting packed virtqueue in guest driver?

Thanks,
Yongji

Depends on the guest right? Linux has it:

Sorry, actually I mean I prefer to support inflight tracking for packed virtqueue in guest driver. This feature is only used by legacy virtio 1.0 or virtio 0.9 device. What do you think about it?

Quoted 7 lines
Quoted 2 lines

Thanks,
Yongji

I don't see what does one have to do with the other. Either we do or we don't want to do it without downtime and retries. If we don't mind resets then let's do it by making guest changes.

OK, I see. But seems like now we don't support packed virtqueue in qemu. Is it better to do that in a splited patchset? Add packed virtqueue implenment in contrib/libvhost-user.c, then document the inflight I/O tracking behavior.

Thanks,
Yongji

#9 lore raw

Re: [Qemu-devel] [PATCH v5 1/6] vhost-user: Support transferring inflight buffer between qemu and backend

Quoted 147 lines · Yongji Xie
Quoted 28 lines · Michael S. Tsirkin
Quoted 26 lines · Yongji Xie
Quoted 24 lines · Michael S. Tsirkin
Quoted 18 lines · Yongji Xie
Quoted 16 lines · Michael S. Tsirkin
Quoted 11 lines · Stefan Hajnoczi

Review

Quoted 10 lines · On Tue, Jan 22, 2019 at 04:31:47PM +0800, [email protected] wrote:
(quoted diff) +10 -0
+typedef struct DescState {
+    uint8_t inuse;
+    uint8_t version;
+    uint16_t used_idx;
+    uint16_t avail_idx;
+    uint16_t reserved;
+} DescState;
+
+typedef struct QueueRegion {
+    uint8_t valid;

what's this?

Quoted 1 line

We can use this to check whether this buffer is reset by qemu.

I'd use version here. Document that it's 1 currently.

Quoted 8 lines
Quoted 4 lines

If we put version into the shared buffer, QEMU will reset it when vm reset. Then if backend restart at the same time, the version of this buffer will be lost. So I still let QEMU maintain it and send it back through message's payload.

I don't get it. If it's reset there's no contents. If there's no contents then who cares what the version is?

What I thought before is that we should not update the buffer when vm reset. But now seems like it's unnecessary. I will update this patch as you said. Thank you!

Quoted 97 lines
Quoted 6 lines
Quoted 2 lines

Or do we want feature flags so we can support downgrades too?

We faced the same problem that the feature flags will be lost if QEMU do not maintain it. So maybe we should put this into message's payload?

I don't understand why we care. We only maintain inflight so we don't need to reset the device. if device is reset we don't need to maintain them at all.

Quoted 86 lines
Quoted 55 lines
Quoted 55 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

+ uint16_t desc_num;

there's padding before this field. Pls make it explicit.

Will do it.

Quoted 10 lines
Quoted 7 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+    DescState desc[0];
+} QueueRegion;
+
+The struct DescState is used to describe one head-descriptor's state. The
+fields have following meanings:
+
+    inuse: Indicate whether the descriptor is inuse or not.

inuse by what?

Maybe inflight is better?

Quoted 10 lines
Quoted 5 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+
+    version: Indicate whether we have an atomic update to used ring and
+    inflight buffer when slave crash at that point. This field should be
+    increased by one before and after this two updates. An odd version
+    indicates an in-progress update.

I'm not sure I understand what does the above say. Also does this require two atomics? Seems pretty expensive. And why is it called version?

Quoted 7 lines
Quoted 4 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+
+    used_idx: Store old index of used ring before we update used ring and
+    inflight buffer so that slave can know whether an odd version inflight
+    head-descriptor in inflight buffer is processed or not.

Here too.

Sorry, the above description may be not clear. This two fields are used to indicate whether we have an in-progress update to used ring and inflight buffer. If slave crash before the update to used_ring and after the update to inflight buffer, the version should be odd and used_idx should be equal to used_ring.idx. Then we need to roll back the update to inflight buffer. As for the name of the version filed, actually I didn't find a good one, so I just copy it from struct kvm_steal_time...

Quoted 6 lines
Quoted 3 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+
+    avail_idx: Used to preserve the descriptor's order in avail ring so that
+    slave can resubmit descriptors in order.

Why would that be necessary?

Quoted 7 lines
Quoted 2 lines

Maybe some devices will be able to use it to preserve order after reconnecting in future?

If buffers are used in order then old entries in the ring are not overwritten so inflight tracking is not necessary. This is exactly the case with vhost user net today.

OK, looks reasonable to me.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

Will a completely new "packed vring" inflight shm layout be necessary to support the packed vring layout in VIRTIO 1.1?

https://docs.oasis-open.org/virtio/virtio/v1.1/csprd01/virtio-v1.1-csprd01.html#x1-610007

Probably.

Quoted 7 lines
Quoted 4 lines

How about supporting packed virtqueue in guest driver?

Thanks,
Yongji

Depends on the guest right? Linux has it:

Sorry, actually I mean I prefer to support inflight tracking for packed virtqueue in guest driver. This feature is only used by legacy virtio 1.0 or virtio 0.9 device. What do you think about it?

Quoted 7 lines
Quoted 2 lines

Thanks,
Yongji

I don't see what does one have to do with the other. Either we do or we don't want to do it without downtime and retries. If we don't mind resets then let's do it by making guest changes.

Quoted 7 lines

OK, I see. But seems like now we don't support packed virtqueue in qemu. Is it better to do that in a splited patchset? Add packed virtqueue implenment in contrib/libvhost-user.c, then document the inflight I/O tracking behavior.

Thanks,
Yongji

it's just documentation so it does not have to depend on actual code.

author
#10 lore raw

Re: [Qemu-devel] [PATCH v5 1/6] vhost-user: Support transferring inflight buffer between qemu and backend

Quoted 154 lines · Michael S. Tsirkin
Quoted 152 lines · Yongji Xie
Quoted 28 lines · Michael S. Tsirkin
Quoted 26 lines · Yongji Xie
Quoted 24 lines · Michael S. Tsirkin
Quoted 18 lines · Yongji Xie
Quoted 16 lines · Michael S. Tsirkin
Quoted 11 lines · Stefan Hajnoczi

Review

Quoted 10 lines · On Tue, Jan 22, 2019 at 04:31:47PM +0800, [email protected] wrote:
(quoted diff) +10 -0
+typedef struct DescState {
+    uint8_t inuse;
+    uint8_t version;
+    uint16_t used_idx;
+    uint16_t avail_idx;
+    uint16_t reserved;
+} DescState;
+
+typedef struct QueueRegion {
+    uint8_t valid;

what's this?

Quoted 1 line

We can use this to check whether this buffer is reset by qemu.

I'd use version here. Document that it's 1 currently.

Quoted 8 lines
Quoted 4 lines

If we put version into the shared buffer, QEMU will reset it when vm reset. Then if backend restart at the same time, the version of this buffer will be lost. So I still let QEMU maintain it and send it back through message's payload.

I don't get it. If it's reset there's no contents. If there's no contents then who cares what the version is?

What I thought before is that we should not update the buffer when vm reset. But now seems like it's unnecessary. I will update this patch as you said. Thank you!

Quoted 97 lines
Quoted 6 lines
Quoted 2 lines

Or do we want feature flags so we can support downgrades too?

We faced the same problem that the feature flags will be lost if QEMU do not maintain it. So maybe we should put this into message's payload?

I don't understand why we care. We only maintain inflight so we don't need to reset the device. if device is reset we don't need to maintain them at all.

Quoted 86 lines
Quoted 55 lines
Quoted 55 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

+ uint16_t desc_num;

there's padding before this field. Pls make it explicit.

Will do it.

Quoted 10 lines
Quoted 7 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+    DescState desc[0];
+} QueueRegion;
+
+The struct DescState is used to describe one head-descriptor's state. The
+fields have following meanings:
+
+    inuse: Indicate whether the descriptor is inuse or not.

inuse by what?

Maybe inflight is better?

Quoted 10 lines
Quoted 5 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+
+    version: Indicate whether we have an atomic update to used ring and
+    inflight buffer when slave crash at that point. This field should be
+    increased by one before and after this two updates. An odd version
+    indicates an in-progress update.

I'm not sure I understand what does the above say. Also does this require two atomics? Seems pretty expensive. And why is it called version?

Quoted 7 lines
Quoted 4 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+
+    used_idx: Store old index of used ring before we update used ring and
+    inflight buffer so that slave can know whether an odd version inflight
+    head-descriptor in inflight buffer is processed or not.

Here too.

Sorry, the above description may be not clear. This two fields are used to indicate whether we have an in-progress update to used ring and inflight buffer. If slave crash before the update to used_ring and after the update to inflight buffer, the version should be odd and used_idx should be equal to used_ring.idx. Then we need to roll back the update to inflight buffer. As for the name of the version filed, actually I didn't find a good one, so I just copy it from struct kvm_steal_time...

Quoted 6 lines
Quoted 3 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+
+    avail_idx: Used to preserve the descriptor's order in avail ring so that
+    slave can resubmit descriptors in order.

Why would that be necessary?

Quoted 7 lines
Quoted 2 lines

Maybe some devices will be able to use it to preserve order after reconnecting in future?

If buffers are used in order then old entries in the ring are not overwritten so inflight tracking is not necessary. This is exactly the case with vhost user net today.

OK, looks reasonable to me.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

Will a completely new "packed vring" inflight shm layout be necessary to support the packed vring layout in VIRTIO 1.1?

https://docs.oasis-open.org/virtio/virtio/v1.1/csprd01/virtio-v1.1-csprd01.html#x1-610007

Probably.

Quoted 7 lines
Quoted 4 lines

How about supporting packed virtqueue in guest driver?

Thanks,
Yongji

Depends on the guest right? Linux has it:

Sorry, actually I mean I prefer to support inflight tracking for packed virtqueue in guest driver. This feature is only used by legacy virtio 1.0 or virtio 0.9 device. What do you think about it?

Quoted 7 lines
Quoted 2 lines

Thanks,
Yongji

I don't see what does one have to do with the other. Either we do or we don't want to do it without downtime and retries. If we don't mind resets then let's do it by making guest changes.

OK, I see. But seems like now we don't support packed virtqueue in qemu. Is it better to do that in a splited patchset? Add packed virtqueue implenment in contrib/libvhost-user.c, then document the inflight I/O tracking behavior.

Quoted 5 lines
Quoted 2 lines

Thanks,
Yongji

it's just documentation so it does not have to depend on actual code.

I get it.

Thanks,
Yongji

#11 lore raw

PATCH v5 2/6 libvhost-user: Introduce vu_queue_map_desc()

In reply to [email protected]

From: Xie Yongji <[email protected]>

Introduce vu_queue_map_desc() which should be
independent with vu_queue_pop();

---
 contrib/libvhost-user/libvhost-user.c | 88 ++++++++++++++++-----------
 1 file changed, 51 insertions(+), 37 deletions(-)
contrib/libvhost-user/libvhost-user.c +51 -37
index a6b46cdc03..23bd52264c 100644
@@ -1853,49 +1853,20 @@ virtqueue_alloc_element(size_t sz,
     return elem;
 }
 
-void *
-vu_queue_pop(VuDev *dev, VuVirtq *vq, size_t sz)
+static void *
+vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned int idx, size_t sz)
 {
-    unsigned int i, head, max, desc_len;
+    struct vring_desc *desc = vq->vring.desc;
     uint64_t desc_addr, read_len;
+    unsigned int desc_len;
+    unsigned int max = vq->vring.num;
+    unsigned int i = idx;
     VuVirtqElement *elem;
-    unsigned out_num, in_num;
+    unsigned int out_num = 0, in_num = 0;
     struct iovec iov[VIRTQUEUE_MAX_SIZE];
     struct vring_desc desc_buf[VIRTQUEUE_MAX_SIZE];
-    struct vring_desc *desc;
     int rc;
 
-    if (unlikely(dev->broken) ||
-        unlikely(!vq->vring.avail)) {
-        return NULL;
-    }
-
-    if (vu_queue_empty(dev, vq)) {
-        return NULL;
-    }
-    /* Needed after virtio_queue_empty(), see comment in
-     * virtqueue_num_heads(). */
-    smp_rmb();
-
-    /* When we start there are none of either input nor output. */
-    out_num = in_num = 0;
-
-    max = vq->vring.num;
-    if (vq->inuse >= vq->vring.num) {
-        vu_panic(dev, "Virtqueue size exceeded");
-        return NULL;
-    }
-
-    if (!virtqueue_get_head(dev, vq, vq->last_avail_idx++, &head)) {
-        return NULL;
-    }
-
-    if (vu_has_feature(dev, VIRTIO_RING_F_EVENT_IDX)) {
-        vring_set_avail_event(vq, vq->last_avail_idx);
-    }
-
-    i = head;
-    desc = vq->vring.desc;
     if (desc[i].flags & VRING_DESC_F_INDIRECT) {
         if (desc[i].len % sizeof(struct vring_desc)) {
             vu_panic(dev, "Invalid size for indirect buffer table");
@@ -1947,12 +1918,13 @@ vu_queue_pop(VuDev *dev, VuVirtq *vq, size_t sz)
     } while (rc == VIRTQUEUE_READ_DESC_MORE);
 
     if (rc == VIRTQUEUE_READ_DESC_ERROR) {
+        vu_panic(dev, "read descriptor error");
         return NULL;
     }
 
     /* Now copy what we have collected and mapped */
     elem = virtqueue_alloc_element(sz, out_num, in_num);
-    elem->index = head;
+    elem->index = idx;
     for (i = 0; i < out_num; i++) {
         elem->out_sg[i] = iov[i];
     }
@@ -1960,6 +1932,48 @@ vu_queue_pop(VuDev *dev, VuVirtq *vq, size_t sz)
         elem->in_sg[i] = iov[out_num + i];
     }
 
+    return elem;
+}
+
+void *
+vu_queue_pop(VuDev *dev, VuVirtq *vq, size_t sz)
+{
+    unsigned int head;
+    VuVirtqElement *elem;
+
+    if (unlikely(dev->broken) ||
+        unlikely(!vq->vring.avail)) {
+        return NULL;
+    }
+
+    if (vu_queue_empty(dev, vq)) {
+        return NULL;
+    }
+    /*
+     * Needed after virtio_queue_empty(), see comment in
+     * virtqueue_num_heads().
+     */
+    smp_rmb();
+
+    if (vq->inuse >= vq->vring.num) {
+        vu_panic(dev, "Virtqueue size exceeded");
+        return NULL;
+    }
+
+    if (!virtqueue_get_head(dev, vq, vq->last_avail_idx++, &head)) {
+        return NULL;
+    }
+
+    if (vu_has_feature(dev, VIRTIO_RING_F_EVENT_IDX)) {
+        vring_set_avail_event(vq, vq->last_avail_idx);
+    }
+
+    elem = vu_queue_map_desc(dev, vq, head, sz);
+
+    if (!elem) {
+        return NULL;
+    }
+
     vq->inuse++;
 
     return elem;
Signature · 1 line
2.17.1
#12 lore raw

PATCH v5 3/6 libvhost-user: Support tracking inflight I/O in shared memory

In reply to [email protected]

From: Xie Yongji <[email protected]>

This patch adds support for VHOST_USER_GET_INFLIGHT_FD and VHOST_USER_SET_INFLIGHT_FD message to set/get shared buffer to/from qemu. Then backend can track inflight I/O in this buffer.

---
 Makefile                              |   2 +-
 contrib/libvhost-user/libvhost-user.c | 314 ++++++++++++++++++++++++--
 contrib/libvhost-user/libvhost-user.h |  40 ++++
 3 files changed, 335 insertions(+), 21 deletions(-)
Makefile +1 -1
index dccba1dca2..3f3a5ace66 100644
@@ -474,7 +474,7 @@ Makefile: $(version-obj-y)
 # Build libraries
 
 libqemuutil.a: $(util-obj-y) $(trace-obj-y) $(stub-obj-y)
-libvhost-user.a: $(libvhost-user-obj-y)
+libvhost-user.a: $(libvhost-user-obj-y) $(util-obj-y) $(stub-obj-y)
 
 ######################################################################
 
contrib/libvhost-user/libvhost-user.c +294 -20

408 lines not on this page · raw message

contrib/libvhost-user/libvhost-user.h +40 -0
index 4aa55b4d2d..a244342129 100644
@@ -53,6 +53,7 @@ enum VhostUserProtocolFeature {
     VHOST_USER_PROTOCOL_F_CONFIG = 9,
     VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD = 10,
     VHOST_USER_PROTOCOL_F_HOST_NOTIFIER = 11,
+    VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD = 12,
 
     VHOST_USER_PROTOCOL_F_MAX
 };
@@ -91,6 +92,8 @@ typedef enum VhostUserRequest {
     VHOST_USER_POSTCOPY_ADVISE  = 28,
     VHOST_USER_POSTCOPY_LISTEN  = 29,
     VHOST_USER_POSTCOPY_END     = 30,
+    VHOST_USER_GET_INFLIGHT_FD = 31,
+    VHOST_USER_SET_INFLIGHT_FD = 32,
     VHOST_USER_MAX
 } VhostUserRequest;
 
@@ -138,6 +141,14 @@ typedef struct VhostUserVringArea {
     uint64_t offset;
 } VhostUserVringArea;
 
+typedef struct VhostUserInflight {
+    uint64_t mmap_size;
+    uint64_t mmap_offset;
+    uint16_t version;
+    uint16_t num_queues;
+    uint16_t queue_size;
+} VhostUserInflight;
+
 #if defined(_WIN32)
 # define VU_PACKED __attribute__((gcc_struct, packed))
 #else
@@ -163,6 +174,7 @@ typedef struct VhostUserMsg {
         VhostUserLog log;
         VhostUserConfig config;
         VhostUserVringArea area;
+        VhostUserInflight inflight;
     } payload;
 
     int fds[VHOST_MEMORY_MAX_NREGIONS];
@@ -234,9 +246,29 @@ typedef struct VuRing {
     uint32_t flags;
 } VuRing;
 
+typedef struct VuDescState {
+    uint8_t inuse;
+    uint8_t version;
+    uint16_t used_idx;
+    uint16_t avail_idx;
+    uint16_t reserved;
+} VuDescState;
+
+typedef struct VuVirtqInflight {
+    uint8_t valid;
+    uint16_t desc_num;
+    VuDescState desc[0];
+} VuVirtqInflight;
+
 typedef struct VuVirtq {
     VuRing vring;
 
+    VuVirtqInflight *inflight;
+
+    uint16_t inflight_desc[VIRTQUEUE_MAX_SIZE];
+
+    uint16_t inflight_num;
+
     /* Next head to pop */
     uint16_t last_avail_idx;
 
@@ -279,11 +311,19 @@ typedef void (*vu_set_watch_cb) (VuDev *dev, int fd, int condition,
                                  vu_watch_cb cb, void *data);
 typedef void (*vu_remove_watch_cb) (VuDev *dev, int fd);
 
+typedef struct VuDevInflightInfo {
+    int fd;
+    void *addr;
+    uint64_t size;
+    uint16_t version;
+} VuDevInflightInfo;
+
 struct VuDev {
     int sock;
     uint32_t nregions;
     VuDevRegion regions[VHOST_MEMORY_MAX_NREGIONS];
     VuVirtq vq[VHOST_MAX_NR_VIRTQUEUE];
+    VuDevInflightInfo inflight_info;
     int log_call_fd;
     int slave_fd;
     uint64_t log_size;
Signature · 1 line
2.17.1
#13 lore raw

Re: [Qemu-devel] [PATCH v5 3/6] libvhost-user: Support tracking inflight I/O in shared memory

Quoted 29 lines · On 2019/1/22 下午4:31, [email protected] wrote:
contrib/libvhost-user/libvhost-user.c +29 -0
+static int
+vu_queue_inflight_get(VuDev *dev, VuVirtq *vq, int desc_idx)
+{
+    if (!has_feature(dev->protocol_features,
+        VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
+        return 0;
+    }
+
+    if (unlikely(!vq->inflight)) {
+        return -1;
+    }
+
+    vq->inflight->desc[desc_idx].inuse = 1;
+
+    vq->inflight->desc[desc_idx].avail_idx = vq->last_avail_idx;
+
+    return 0;
+}
+
+static int
+vu_queue_inflight_pre_put(VuDev *dev, VuVirtq *vq, int desc_idx)
+{
+    if (!has_feature(dev->protocol_features,
+        VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
+        return 0;
+    }
+
+    if (unlikely(!vq->inflight)) {
+        return -1;

contrib/libvhost-user/libvhost-user.c vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned int idx, size_t sz) · line 2178

Quoted 10 lines
contrib/libvhost-user/libvhost-user.c +10 -0
+    }
+
+    vq->inflight->desc[desc_idx].used_idx = vq->used_idx;
+
+    barrier();
+
+    vq->inflight->desc[desc_idx].version++;
+
+    return 0;
+}

You probably need WRITE_ONCE() semantic (e.g volatile) to make sure the value reach memory.

Thanks

#14 lore raw

Re: [Qemu-devel] [PATCH v5 3/6] libvhost-user: Support tracking inflight I/O in shared memory

Quoted 46 lines · Jason Wang
Quoted 29 lines · On 2019/1/22 下午4:31, [email protected] wrote:
contrib/libvhost-user/libvhost-user.c +29 -0
+static int
+vu_queue_inflight_get(VuDev *dev, VuVirtq *vq, int desc_idx)
+{
+    if (!has_feature(dev->protocol_features,
+        VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
+        return 0;
+    }
+
+    if (unlikely(!vq->inflight)) {
+        return -1;
+    }
+
+    vq->inflight->desc[desc_idx].inuse = 1;
+
+    vq->inflight->desc[desc_idx].avail_idx = vq->last_avail_idx;
+
+    return 0;
+}
+
+static int
+vu_queue_inflight_pre_put(VuDev *dev, VuVirtq *vq, int desc_idx)
+{
+    if (!has_feature(dev->protocol_features,
+        VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
+        return 0;
+    }
+
+    if (unlikely(!vq->inflight)) {
+        return -1;

contrib/libvhost-user/libvhost-user.c vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned int idx, size_t sz) · line 2178

Quoted 10 lines
contrib/libvhost-user/libvhost-user.c +10 -0
+    }
+
+    vq->inflight->desc[desc_idx].used_idx = vq->used_idx;
+
+    barrier();
+
+    vq->inflight->desc[desc_idx].version++;
+
+    return 0;
+}

You probably need WRITE_ONCE() semantic (e.g volatile) to make sure the value reach memory.

Quoted 2 lines

Thanks

WRITE_ONCE is literally volatile + dependency memory barrier. So unless compiler is a very agressive one, it does not buy you much.

Signature · 1 line
MST
#15 lore raw

Re: [Qemu-devel] [PATCH v5 3/6] libvhost-user: Support tracking inflight I/O in shared memory

Quoted 45 lines · Michael S. Tsirkin
Quoted 44 lines · Jason Wang
Quoted 29 lines · On 2019/1/22 下午4:31, [email protected] wrote:
contrib/libvhost-user/libvhost-user.c +29 -0
+static int
+vu_queue_inflight_get(VuDev *dev, VuVirtq *vq, int desc_idx)
+{
+    if (!has_feature(dev->protocol_features,
+        VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
+        return 0;
+    }
+
+    if (unlikely(!vq->inflight)) {
+        return -1;
+    }
+
+    vq->inflight->desc[desc_idx].inuse = 1;
+
+    vq->inflight->desc[desc_idx].avail_idx = vq->last_avail_idx;
+
+    return 0;
+}
+
+static int
+vu_queue_inflight_pre_put(VuDev *dev, VuVirtq *vq, int desc_idx)
+{
+    if (!has_feature(dev->protocol_features,
+        VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
+        return 0;
+    }
+
+    if (unlikely(!vq->inflight)) {
+        return -1;

contrib/libvhost-user/libvhost-user.c vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned int idx, size_t sz) · line 2178

Quoted 10 lines
contrib/libvhost-user/libvhost-user.c +10 -0
+    }
+
+    vq->inflight->desc[desc_idx].used_idx = vq->used_idx;
+
+    barrier();
+
+    vq->inflight->desc[desc_idx].version++;
+
+    return 0;
+}

You probably need WRITE_ONCE() semantic (e.g volatile) to make sure the value reach memory.

Quoted 5 lines
Quoted 2 lines

Thanks

WRITE_ONCE is literally volatile + dependency memory barrier. So unless compiler is a very agressive one, it does not buy you much.

Well, since version is increased twice, if compiler decide the inline both vu_queue_inflight_pre_put() and vu_queue_inflight_post_put(), can we make sure it always generate instructions that write to memory instead of registers?

Thanks

author
#16 lore raw

Re: [Qemu-devel] [PATCH v5 3/6] libvhost-user: Support tracking inflight I/O in shared memory

In reply to Jason Wang
Quoted 38 lines · Jason Wang
Quoted 35 lines · On 2019/1/22 下午4:31, [email protected] wrote:
contrib/libvhost-user/libvhost-user.c +35 -0
+static int
+vu_queue_inflight_get(VuDev *dev, VuVirtq *vq, int desc_idx)
+{
+    if (!has_feature(dev->protocol_features,
+        VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
+        return 0;
+    }
+
+    if (unlikely(!vq->inflight)) {
+        return -1;
+    }
+
+    vq->inflight->desc[desc_idx].inuse = 1;
+
+    vq->inflight->desc[desc_idx].avail_idx = vq->last_avail_idx;
+
+    return 0;
+}
+
+static int
+vu_queue_inflight_pre_put(VuDev *dev, VuVirtq *vq, int desc_idx)
+{
+    if (!has_feature(dev->protocol_features,
+        VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
+        return 0;
+    }
+
+    if (unlikely(!vq->inflight)) {
+        return -1;
+    }
+
+    vq->inflight->desc[desc_idx].used_idx = vq->used_idx;
+
+    barrier();
+
Quoted 9 lines

contrib/libvhost-user/libvhost-user.c vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned int idx, size_t sz) · line 2178

Quoted 4 lines
contrib/libvhost-user/libvhost-user.c +4 -0
+    vq->inflight->desc[desc_idx].version++;
+
+    return 0;
+}

You probably need WRITE_ONCE() semantic (e.g volatile) to make sure the value reach memory.

Is it enough to declare those variables as volatile?

Thanks,
Yongji

#17 lore raw

Re: [Qemu-devel] [PATCH v5 3/6] libvhost-user: Support tracking inflight I/O in shared memory

Quoted 46 lines · Yongji Xie
Quoted 36 lines · Jason Wang
Quoted 34 lines · On 2019/1/22 下午4:31, [email protected] wrote:
contrib/libvhost-user/libvhost-user.c +34 -0
+static int
+vu_queue_inflight_get(VuDev *dev, VuVirtq *vq, int desc_idx)
+{
+    if (!has_feature(dev->protocol_features,
+        VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
+        return 0;
+    }
+
+    if (unlikely(!vq->inflight)) {
+        return -1;
+    }
+
+    vq->inflight->desc[desc_idx].inuse = 1;
+
+    vq->inflight->desc[desc_idx].avail_idx = vq->last_avail_idx;
+
+    return 0;
+}
+
+static int
+vu_queue_inflight_pre_put(VuDev *dev, VuVirtq *vq, int desc_idx)
+{
+    if (!has_feature(dev->protocol_features,
+        VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
+        return 0;
+    }
+
+    if (unlikely(!vq->inflight)) {
+        return -1;
+    }
+
+    vq->inflight->desc[desc_idx].used_idx = vq->used_idx;
+
+    barrier();
Quoted 9 lines

contrib/libvhost-user/libvhost-user.c vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned int idx, size_t sz) · line 2178

Quoted 5 lines
contrib/libvhost-user/libvhost-user.c +5 -0
+
+    vq->inflight->desc[desc_idx].version++;
+
+    return 0;
+}

You probably need WRITE_ONCE() semantic (e.g volatile) to make sure the value reach memory.

Quoted 4 lines

Is it enough to declare those variables as volatile?

Thanks,
Yongji

I think so.

Thanks

author
#18 lore raw

Re: [Qemu-devel] [PATCH v5 3/6] libvhost-user: Support tracking inflight I/O in shared memory

In reply to Jason Wang
Quoted 38 lines · Jason Wang
Quoted 35 lines · On 2019/1/22 下午4:31, [email protected] wrote:
contrib/libvhost-user/libvhost-user.c +35 -0
+static int
+vu_queue_inflight_get(VuDev *dev, VuVirtq *vq, int desc_idx)
+{
+    if (!has_feature(dev->protocol_features,
+        VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
+        return 0;
+    }
+
+    if (unlikely(!vq->inflight)) {
+        return -1;
+    }
+
+    vq->inflight->desc[desc_idx].inuse = 1;
+
+    vq->inflight->desc[desc_idx].avail_idx = vq->last_avail_idx;
+
+    return 0;
+}
+
+static int
+vu_queue_inflight_pre_put(VuDev *dev, VuVirtq *vq, int desc_idx)
+{
+    if (!has_feature(dev->protocol_features,
+        VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
+        return 0;
+    }
+
+    if (unlikely(!vq->inflight)) {
+        return -1;
+    }
+
+    vq->inflight->desc[desc_idx].used_idx = vq->used_idx;
+
+    barrier();
+
Quoted 9 lines

contrib/libvhost-user/libvhost-user.c vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned int idx, size_t sz) · line 2178

Quoted 4 lines
contrib/libvhost-user/libvhost-user.c +4 -0
+    vq->inflight->desc[desc_idx].version++;
+
+    return 0;
+}

You probably need WRITE_ONCE() semantic (e.g volatile) to make sure the value reach memory.

The cache line should have been flushed during crash. So we can see the correct value when backend reconnecting. If so, compile barrier should be enough here, right?

Thanks,
Yongji

#19 lore raw

Re: [Qemu-devel] [PATCH v5 3/6] libvhost-user: Support tracking inflight I/O in shared memory

Quoted 46 lines · Yongji Xie
Quoted 36 lines · Jason Wang
Quoted 34 lines · On 2019/1/22 下午4:31, [email protected] wrote:
contrib/libvhost-user/libvhost-user.c +34 -0
+static int
+vu_queue_inflight_get(VuDev *dev, VuVirtq *vq, int desc_idx)
+{
+    if (!has_feature(dev->protocol_features,
+        VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
+        return 0;
+    }
+
+    if (unlikely(!vq->inflight)) {
+        return -1;
+    }
+
+    vq->inflight->desc[desc_idx].inuse = 1;
+
+    vq->inflight->desc[desc_idx].avail_idx = vq->last_avail_idx;
+
+    return 0;
+}
+
+static int
+vu_queue_inflight_pre_put(VuDev *dev, VuVirtq *vq, int desc_idx)
+{
+    if (!has_feature(dev->protocol_features,
+        VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
+        return 0;
+    }
+
+    if (unlikely(!vq->inflight)) {
+        return -1;
+    }
+
+    vq->inflight->desc[desc_idx].used_idx = vq->used_idx;
+
+    barrier();
Quoted 9 lines

contrib/libvhost-user/libvhost-user.c vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned int idx, size_t sz) · line 2178

Quoted 5 lines
contrib/libvhost-user/libvhost-user.c +5 -0
+
+    vq->inflight->desc[desc_idx].version++;
+
+    return 0;
+}

You probably need WRITE_ONCE() semantic (e.g volatile) to make sure the value reach memory.

Quoted 3 lines

The cache line should have been flushed during crash. So we can see the correct value when backend reconnecting. If so, compile barrier should be enough here, right?

Maybe I worry too much but it's not about flushing cache, but about whether or not compiler can generate mov to memory instead of mov to registers.

Thanks

Quoted 3 lines

Thanks,
Yongji

author
#20 lore raw

Re: [Qemu-devel] [PATCH v5 3/6] libvhost-user: Support tracking inflight I/O in shared memory

Quoted 49 lines · Jason Wang
Quoted 46 lines · Yongji Xie
Quoted 45 lines · Jason Wang
Quoted 29 lines · On 2019/1/22 下午4:31, [email protected] wrote:
contrib/libvhost-user/libvhost-user.c +29 -0
+static int
+vu_queue_inflight_get(VuDev *dev, VuVirtq *vq, int desc_idx)
+{
+    if (!has_feature(dev->protocol_features,
+        VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
+        return 0;
+    }
+
+    if (unlikely(!vq->inflight)) {
+        return -1;
+    }
+
+    vq->inflight->desc[desc_idx].inuse = 1;
+
+    vq->inflight->desc[desc_idx].avail_idx = vq->last_avail_idx;
+
+    return 0;
+}
+
+static int
+vu_queue_inflight_pre_put(VuDev *dev, VuVirtq *vq, int desc_idx)
+{
+    if (!has_feature(dev->protocol_features,
+        VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
+        return 0;
+    }
+
+    if (unlikely(!vq->inflight)) {
+        return -1;

contrib/libvhost-user/libvhost-user.c vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned int idx, size_t sz) · line 2178

Quoted 10 lines
contrib/libvhost-user/libvhost-user.c +10 -0
+    }
+
+    vq->inflight->desc[desc_idx].used_idx = vq->used_idx;
+
+    barrier();
+
+    vq->inflight->desc[desc_idx].version++;
+
+    return 0;
+}

You probably need WRITE_ONCE() semantic (e.g volatile) to make sure the value reach memory.

Quoted 9 lines
Quoted 3 lines

The cache line should have been flushed during crash. So we can see the correct value when backend reconnecting. If so, compile barrier should be enough here, right?

Maybe I worry too much but it's not about flushing cache, but about whether or not compiler can generate mov to memory instead of mov to registers.

OK, I see. I will declare those variables as volatile in v6. Thank you.

Thanks,
Yongji

#21 lore raw

PATCH v5 4/6 vhost-user-blk: Add support to get/set inflight buffer

In reply to [email protected]

From: Xie Yongji <[email protected]>

This patch adds support for vhost-user-blk device to get/set inflight buffer from/to backend.

---
 hw/block/vhost-user-blk.c          | 26 ++++++++++++++++++++++++++
 include/hw/virtio/vhost-user-blk.h |  1 +
 2 files changed, 27 insertions(+)
hw/block/vhost-user-blk.c +26 -0
index c3af28fad4..1f899ac1c0 100644
@@ -126,6 +126,13 @@ static void vhost_user_blk_start(VirtIODevice *vdev)
     }
 
     s->dev.acked_features = vdev->guest_features;
+
+    ret = vhost_dev_set_inflight(&s->dev, s->inflight);
+    if (ret < 0) {
+        error_report("Error set inflight: %d", -ret);
+        goto err_guest_notifiers;
+    }
+
     ret = vhost_dev_start(&s->dev, vdev);
     if (ret < 0) {
         error_report("Error starting vhost: %d", -ret);
@@ -245,6 +252,13 @@ static void vhost_user_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
     }
 }
 
+static void vhost_user_blk_reset(VirtIODevice *vdev)
+{
+    VHostUserBlk *s = VHOST_USER_BLK(vdev);
+
+    vhost_dev_reset_inflight(s->inflight);
+}
+
 static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
@@ -285,6 +299,8 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
                          vhost_user_blk_handle_output);
     }
 
+    s->inflight = g_new0(struct vhost_inflight, 1);
+
     s->dev.nvqs = s->num_queues;
     s->dev.vqs = g_new(struct vhost_virtqueue, s->dev.nvqs);
     s->dev.vq_index = 0;
@@ -311,12 +327,19 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
         s->blkcfg.num_queues = s->num_queues;
     }
 
+    ret = vhost_dev_get_inflight(&s->dev, s->queue_size, s->inflight);
+    if (ret < 0) {
+        error_setg(errp, "vhost-user-blk: get inflight failed");
+        goto vhost_err;
+    }
+
     return;
 
 vhost_err:
     vhost_dev_cleanup(&s->dev);
 virtio_err:
     g_free(vqs);
+    g_free(s->inflight);
     virtio_cleanup(vdev);
 
     vhost_user_cleanup(user);
@@ -332,7 +355,9 @@ static void vhost_user_blk_device_unrealize(DeviceState *dev, Error **errp)
 
     vhost_user_blk_set_status(vdev, 0);
     vhost_dev_cleanup(&s->dev);
+    vhost_dev_free_inflight(s->inflight);
     g_free(vqs);
+    g_free(s->inflight);
     virtio_cleanup(vdev);
 
     if (s->vhost_user) {
@@ -382,6 +407,7 @@ static void vhost_user_blk_class_init(ObjectClass *klass, void *data)
     vdc->set_config = vhost_user_blk_set_config;
     vdc->get_features = vhost_user_blk_get_features;
     vdc->set_status = vhost_user_blk_set_status;
+    vdc->reset = vhost_user_blk_reset;
 }
 
 static const TypeInfo vhost_user_blk_info = {
include/hw/virtio/vhost-user-blk.h +1 -0
index d52944aeeb..445516604a 100644
@@ -36,6 +36,7 @@ typedef struct VHostUserBlk {
     uint32_t queue_size;
     uint32_t config_wce;
     struct vhost_dev dev;
+    struct vhost_inflight *inflight;
     VhostUserState *vhost_user;
 } VHostUserBlk;
 
Signature · 1 line
2.17.1
#22 lore raw

PATCH v5 5/6 vhost-user-blk: Add support to reconnect backend

In reply to [email protected]

From: Xie Yongji <[email protected]>

Since we now support the message VHOST_USER_GET_INFLIGHT_FD and VHOST_USER_SET_INFLIGHT_FD. The backend is able to restart safely because it can track inflight I/O in shared memory. This patch allows qemu to reconnect the backend after connection closed.

---
 hw/block/vhost-user-blk.c          | 209 +++++++++++++++++++++++------
 include/hw/virtio/vhost-user-blk.h |   4 +
 2 files changed, 169 insertions(+), 44 deletions(-)
hw/block/vhost-user-blk.c +165 -44
index 1f899ac1c0..0fab7b1d2f 100644
@@ -101,7 +101,7 @@ const VhostDevConfigOps blk_ops = {
     .vhost_dev_config_notifier = vhost_user_blk_handle_config_change,
 };
 
-static void vhost_user_blk_start(VirtIODevice *vdev)
+static int vhost_user_blk_start(VirtIODevice *vdev)
 {
     VHostUserBlk *s = VHOST_USER_BLK(vdev);
     BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
@@ -110,13 +110,13 @@ static void vhost_user_blk_start(VirtIODevice *vdev)
 
     if (!k->set_guest_notifiers) {
         error_report("binding does not support guest notifiers");
-        return;
+        return -ENOSYS;
     }
 
     ret = vhost_dev_enable_notifiers(&s->dev, vdev);
     if (ret < 0) {
         error_report("Error enabling host notifiers: %d", -ret);
-        return;
+        return ret;
     }
 
     ret = k->set_guest_notifiers(qbus->parent, s->dev.nvqs, true);
@@ -147,12 +147,13 @@ static void vhost_user_blk_start(VirtIODevice *vdev)
         vhost_virtqueue_mask(&s->dev, vdev, i, false);
     }
 
-    return;
+    return ret;
 
 err_guest_notifiers:
     k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false);
 err_host_notifiers:
     vhost_dev_disable_notifiers(&s->dev, vdev);
+    return ret;
 }
 
 static void vhost_user_blk_stop(VirtIODevice *vdev)
@@ -171,7 +172,6 @@ static void vhost_user_blk_stop(VirtIODevice *vdev)
     ret = k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false);
     if (ret < 0) {
         error_report("vhost guest notifier cleanup failed: %d", ret);
-        return;
     }
 
     vhost_dev_disable_notifiers(&s->dev, vdev);
@@ -181,21 +181,43 @@ static void vhost_user_blk_set_status(VirtIODevice *vdev, uint8_t status)
 {
     VHostUserBlk *s = VHOST_USER_BLK(vdev);
     bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
+    int ret;
 
     if (!vdev->vm_running) {
         should_start = false;
     }
 
-    if (s->dev.started == should_start) {
+    if (s->should_start == should_start) {
+        return;
+    }
+
+    if (!s->connected || s->dev.started == should_start) {
+        s->should_start = should_start;
         return;
     }
 
     if (should_start) {
-        vhost_user_blk_start(vdev);
+        s->should_start = true;
+        /*
+         * make sure vhost_user_blk_handle_output() ignores fake
+         * guest kick by vhost_dev_enable_notifiers()
+         */
+        barrier();
+        ret = vhost_user_blk_start(vdev);
+        if (ret < 0) {
+            error_report("vhost-user-blk: vhost start failed: %s",
+                         strerror(-ret));
+            qemu_chr_fe_disconnect(&s->chardev);
+        }
     } else {
         vhost_user_blk_stop(vdev);
+        /*
+         * make sure vhost_user_blk_handle_output() ignore fake
+         * guest kick by vhost_dev_disable_notifiers()
+         */
+        barrier();
+        s->should_start = false;
     }
-
 }
 
 static uint64_t vhost_user_blk_get_features(VirtIODevice *vdev,
@@ -225,13 +247,22 @@ static uint64_t vhost_user_blk_get_features(VirtIODevice *vdev,
 static void vhost_user_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
 {
     VHostUserBlk *s = VHOST_USER_BLK(vdev);
-    int i;
+    int i, ret;
 
     if (!(virtio_host_has_feature(vdev, VIRTIO_F_VERSION_1) &&
         !virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1))) {
         return;
     }
 
+    if (s->should_start) {
+        return;
+    }
+    s->should_start = true;
+
+    if (!s->connected) {
+        return;
+    }
+
     if (s->dev.started) {
         return;
     }
@@ -239,7 +270,13 @@ static void vhost_user_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
     /* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start
      * vhost here instead of waiting for .set_status().
      */
-    vhost_user_blk_start(vdev);
+    ret = vhost_user_blk_start(vdev);
+    if (ret < 0) {
+        error_report("vhost-user-blk: vhost start failed: %s",
+                     strerror(-ret));
+        qemu_chr_fe_disconnect(&s->chardev);
+        return;
+    }
 
     /* Kick right away to begin processing requests already in vring */
     for (i = 0; i < s->dev.nvqs; i++) {
@@ -259,13 +296,106 @@ static void vhost_user_blk_reset(VirtIODevice *vdev)
     vhost_dev_reset_inflight(s->inflight);
 }
 
+static int vhost_user_blk_connect(DeviceState *dev)
+{
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+    VHostUserBlk *s = VHOST_USER_BLK(vdev);
+    int ret = 0;
+
+    if (s->connected) {
+        return 0;
+    }
+    s->connected = true;
+
+    s->dev.nvqs = s->num_queues;
+    s->dev.vqs = s->vqs;
+    s->dev.vq_index = 0;
+    s->dev.backend_features = 0;
+
+    vhost_dev_set_config_notifier(&s->dev, &blk_ops);
+
+    ret = vhost_dev_init(&s->dev, s->vhost_user, VHOST_BACKEND_TYPE_USER, 0);
+    if (ret < 0) {
+        error_report("vhost-user-blk: vhost initialization failed: %s",
+                     strerror(-ret));
+        return ret;
+    }
+
+    /* restore vhost state */
+    if (s->should_start) {
+        ret = vhost_user_blk_start(vdev);
+        if (ret < 0) {
+            error_report("vhost-user-blk: vhost start failed: %s",
+                         strerror(-ret));
+            return ret;
+        }
+    }
+
+    return 0;
+}
+
+static void vhost_user_blk_disconnect(DeviceState *dev)
+{
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+    VHostUserBlk *s = VHOST_USER_BLK(vdev);
+
+    if (!s->connected) {
+        return;
+    }
+    s->connected = false;
+
+    if (s->dev.started) {
+        vhost_user_blk_stop(vdev);
+    }
+
+    vhost_dev_cleanup(&s->dev);
+}
+
+static gboolean vhost_user_blk_watch(GIOChannel *chan, GIOCondition cond,
+                                     void *opaque)
+{
+    DeviceState *dev = opaque;
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+    VHostUserBlk *s = VHOST_USER_BLK(vdev);
+
+    qemu_chr_fe_disconnect(&s->chardev);
+
+    return true;
+}
+
+static void vhost_user_blk_event(void *opaque, int event)
+{
+    DeviceState *dev = opaque;
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+    VHostUserBlk *s = VHOST_USER_BLK(vdev);
+
+    switch (event) {
+    case CHR_EVENT_OPENED:
+        if (vhost_user_blk_connect(dev) < 0) {
+            qemu_chr_fe_disconnect(&s->chardev);
+            return;
+        }
+        s->watch = qemu_chr_fe_add_watch(&s->chardev, G_IO_HUP,
+                                         vhost_user_blk_watch, dev);
+        break;
+    case CHR_EVENT_CLOSED:
+        vhost_user_blk_disconnect(dev);
+        if (s->watch) {
+            g_source_remove(s->watch);
+            s->watch = 0;
+        }
+        break;
+    }
+}
+
+
 static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     VHostUserBlk *s = VHOST_USER_BLK(vdev);
     VhostUserState *user;
-    struct vhost_virtqueue *vqs = NULL;
     int i, ret;
+    Error *err = NULL;
 
     if (!s->chardev.chr) {
         error_setg(errp, "vhost-user-blk: chardev is mandatory");
@@ -300,27 +430,28 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
     }
 
     s->inflight = g_new0(struct vhost_inflight, 1);
-
-    s->dev.nvqs = s->num_queues;
-    s->dev.vqs = g_new(struct vhost_virtqueue, s->dev.nvqs);
-    s->dev.vq_index = 0;
-    s->dev.backend_features = 0;
-    vqs = s->dev.vqs;
-
-    vhost_dev_set_config_notifier(&s->dev, &blk_ops);
-
-    ret = vhost_dev_init(&s->dev, s->vhost_user, VHOST_BACKEND_TYPE_USER, 0);
-    if (ret < 0) {
-        error_setg(errp, "vhost-user-blk: vhost initialization failed: %s",
-                   strerror(-ret));
-        goto virtio_err;
-    }
+    s->vqs = g_new(struct vhost_virtqueue, s->num_queues);
+    s->watch = 0;
+    s->should_start = false;
+    s->connected = false;
+
+    qemu_chr_fe_set_handlers(&s->chardev,  NULL, NULL, vhost_user_blk_event,
+                             NULL, (void *)dev, NULL, true);
+
+reconnect:
+    do {
+        if (qemu_chr_fe_wait_connected(&s->chardev, &err) < 0) {
+            error_report_err(err);
+            err = NULL;
+            sleep(1);
+        }
+    } while (!s->connected);
 
     ret = vhost_dev_get_config(&s->dev, (uint8_t *)&s->blkcfg,
-                              sizeof(struct virtio_blk_config));
+                               sizeof(struct virtio_blk_config));
     if (ret < 0) {
-        error_setg(errp, "vhost-user-blk: get block config failed");
-        goto vhost_err;
+        error_report("vhost-user-blk: get block config failed");
+        goto reconnect;
     }
 
     if (s->blkcfg.num_queues != s->num_queues) {
@@ -329,34 +460,24 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
 
     ret = vhost_dev_get_inflight(&s->dev, s->queue_size, s->inflight);
     if (ret < 0) {
-        error_setg(errp, "vhost-user-blk: get inflight failed");
-        goto vhost_err;
+        error_report("vhost-user-blk: get inflight failed");
+        goto reconnect;
     }
 
     return;
-
-vhost_err:
-    vhost_dev_cleanup(&s->dev);
-virtio_err:
-    g_free(vqs);
-    g_free(s->inflight);
-    virtio_cleanup(vdev);
-
-    vhost_user_cleanup(user);
-    g_free(user);
-    s->vhost_user = NULL;
 }
 
 static void vhost_user_blk_device_unrealize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     VHostUserBlk *s = VHOST_USER_BLK(dev);
-    struct vhost_virtqueue *vqs = s->dev.vqs;
 
     vhost_user_blk_set_status(vdev, 0);
+    qemu_chr_fe_set_handlers(&s->chardev,  NULL, NULL, NULL,
+                             NULL, NULL, NULL, false);
     vhost_dev_cleanup(&s->dev);
     vhost_dev_free_inflight(s->inflight);
-    g_free(vqs);
+    g_free(s->vqs);
     g_free(s->inflight);
     virtio_cleanup(vdev);
 
include/hw/virtio/vhost-user-blk.h +4 -0
index 445516604a..4849aa5eb5 100644
@@ -38,6 +38,10 @@ typedef struct VHostUserBlk {
     struct vhost_dev dev;
     struct vhost_inflight *inflight;
     VhostUserState *vhost_user;
+    struct vhost_virtqueue *vqs;
+    guint watch;
+    bool should_start;
+    bool connected;
 } VHostUserBlk;
 
 #endif
Signature · 1 line
2.17.1
#23 lore raw

PATCH v5 6/6 contrib/vhost-user-blk: enable inflight I/O tracking

In reply to [email protected]

From: Xie Yongji <[email protected]>

This patch enables inflight I/O tracking for vhost-user-blk backend so that we could restart it safely.

---
 contrib/vhost-user-blk/vhost-user-blk.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
contrib/vhost-user-blk/vhost-user-blk.c +2 -1
index 858221ad95..8cc033946a 100644
@@ -327,7 +327,8 @@ vub_get_features(VuDev *dev)
 static uint64_t
 vub_get_protocol_features(VuDev *dev)
 {
-    return 1ull << VHOST_USER_PROTOCOL_F_CONFIG;
+    return 1ull << VHOST_USER_PROTOCOL_F_CONFIG |
+           1ull << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD;
 }
 
 static int
Signature · 1 line
2.17.1
#24 lore raw
In reply to [email protected]
Quoted 38 lines · On 2019/1/22 下午4:31, [email protected] wrote:

From: Xie Yongji <[email protected]>

This patchset is aimed at supporting qemu to reconnect vhost-user-blk backend after vhost-user-blk backend crash or restart.

The patch 1 introduces two new messages VHOST_USER_GET_INFLIGHT_FD and VHOST_USER_SET_INFLIGHT_FD to support support transferring shared buffer between qemu and backend.

The patch 2,3 are the corresponding libvhost-user patches of patch 1. Make libvhost-user support VHOST_USER_GET_INFLIGHT_FD and VHOST_USER_SET_INFLIGHT_FD.

The patch 4 allows vhost-user-blk to use the two new messages to get/set inflight buffer from/to backend.

The patch 5 supports vhost-user-blk to reconnect backend when connection closed.

The patch 6 introduces VHOST_USER_PROTOCOL_F_SLAVE_SHMFD to vhost-user-blk backend which is used to tell qemu that we support reconnecting now.

This series is based on Daniel P. Berrangé's patchset:

https://lists.gnu.org/archive/html/qemu-devel/2019-01/msg03344.html

To use it, we could start qemu with:

qemu-system-x86_64 \
         -chardev socket,id=char0,path=/path/vhost.socket,reconnect=1, \
         -device vhost-user-blk-pci,chardev=char0 \

and start vhost-user-blk backend with:

vhost-user-blk -b /path/file -s /path/vhost.socket

Quoted 8 lines

Then we can restart vhost-user-blk at any time during VM running.

V4 to V5:
- Drop patch that enables "nowait" option on client sockets
- Support resubmitting inflight I/O in order
- Make inflight I/O tracking more robust
- Remove align field and add queue size field in VhostUserInflight
- Document more details in vhost-user.txt

I'm still not convinced about this approach. If the maintainer decide to merge, at least two things needs to be added besides the correctness of the code:

- you need prove that this approach can work for packed ring

-  an unit-test to test the crash during logging in-flight descriptor.

Thanks

Quoted 44 lines

V3 to V4:
- Drop messages VHOST_USER_GET_SHM_SIZE and VHOST_USER_SET_SHM_FD
- Introduce two new messages VHOST_USER_GET_INFLIGHT_FD and VHOST_USER_SET_INFLIGHT_FD
- Allocate inflight buffer in backend rather than in qemu
- Document a recommended format for inflight buffer

V2 to V3:
- Using exisiting wait/nowait options to control connection on client sockets instead of introducing "disconnected" option.
- Support the case that vhost-user backend restart during initialzation of vhost-user-blk device.

V1 to V2:
- Introduce "disconnected" option for chardev instead of reuse "wait" option
- Support the case that QEMU starts before vhost-user backend
- Drop message VHOST_USER_SET_VRING_INFLIGHT
- Introduce two new messages VHOST_USER_GET_SHM_SIZE
and VHOST_USER_SET_SHM_FD

Xie Yongji (6):
vhost-user: Support transferring inflight buffer between qemu and
backend
libvhost-user: Introduce vu_queue_map_desc()
libvhost-user: Support tracking inflight I/O in shared memory
vhost-user-blk: Add support to get/set inflight buffer
vhost-user-blk: Add support to reconnect backend contrib/vhost-user-blk: enable inflight I/O tracking

  Makefile                                |   2 +-
  contrib/libvhost-user/libvhost-user.c   | 402 ++++++++++++++++++++----
  contrib/libvhost-user/libvhost-user.h   |  40 +++
  contrib/vhost-user-blk/vhost-user-blk.c |   3 +-
  docs/interop/vhost-user.txt             | 101 ++++++
  hw/block/vhost-user-blk.c               | 227 ++++++++++---
  hw/virtio/vhost-user.c                  | 110 +++++++
  hw/virtio/vhost.c                       | 105 +++++++
  include/hw/virtio/vhost-backend.h       |  10 +
  include/hw/virtio/vhost-user-blk.h      |   5 +
  include/hw/virtio/vhost.h               |  19 ++
  11 files changed, 925 insertions(+), 99 deletions(-)
#25 lore raw
Quoted 50 lines · Jason Wang
Quoted 38 lines · On 2019/1/22 下午4:31, [email protected] wrote:

From: Xie Yongji <[email protected]>

This patchset is aimed at supporting qemu to reconnect vhost-user-blk backend after vhost-user-blk backend crash or restart.

The patch 1 introduces two new messages VHOST_USER_GET_INFLIGHT_FD and VHOST_USER_SET_INFLIGHT_FD to support support transferring shared buffer between qemu and backend.

The patch 2,3 are the corresponding libvhost-user patches of patch 1. Make libvhost-user support VHOST_USER_GET_INFLIGHT_FD and VHOST_USER_SET_INFLIGHT_FD.

The patch 4 allows vhost-user-blk to use the two new messages to get/set inflight buffer from/to backend.

The patch 5 supports vhost-user-blk to reconnect backend when connection closed.

The patch 6 introduces VHOST_USER_PROTOCOL_F_SLAVE_SHMFD to vhost-user-blk backend which is used to tell qemu that we support reconnecting now.

This series is based on Daniel P. Berrangé's patchset:

https://lists.gnu.org/archive/html/qemu-devel/2019-01/msg03344.html

To use it, we could start qemu with:

qemu-system-x86_64 \
         -chardev socket,id=char0,path=/path/vhost.socket,reconnect=1, \
         -device vhost-user-blk-pci,chardev=char0 \

and start vhost-user-blk backend with:

vhost-user-blk -b /path/file -s /path/vhost.socket

Quoted 8 lines

Then we can restart vhost-user-blk at any time during VM running.

V4 to V5:
- Drop patch that enables "nowait" option on client sockets
- Support resubmitting inflight I/O in order
- Make inflight I/O tracking more robust
- Remove align field and add queue size field in VhostUserInflight
- Document more details in vhost-user.txt

Quoted 5 lines

I'm still not convinced about this approach. If the maintainer decide to merge, at least two things needs to be added besides the correctness of the code:

- you need prove that this approach can work for packed ring

Or rather document how it's used.

Quoted 3 lines

-  an unit-test to test the crash during logging in-flight descriptor.

Thanks

For contrib/vhost-user-blk? Well I don't think it's used by unit tests right now, it is? So it's a worthwhile goal but not necessarily a requirement for any specific patch I think.

Quoted 45 lines
Quoted 45 lines

V3 to V4:
- Drop messages VHOST_USER_GET_SHM_SIZE and VHOST_USER_SET_SHM_FD
- Introduce two new messages VHOST_USER_GET_INFLIGHT_FD and VHOST_USER_SET_INFLIGHT_FD
- Allocate inflight buffer in backend rather than in qemu
- Document a recommended format for inflight buffer

V2 to V3:
- Using exisiting wait/nowait options to control connection on client sockets instead of introducing "disconnected" option.
- Support the case that vhost-user backend restart during initialzation of vhost-user-blk device.

V1 to V2:
- Introduce "disconnected" option for chardev instead of reuse "wait" option
- Support the case that QEMU starts before vhost-user backend
- Drop message VHOST_USER_SET_VRING_INFLIGHT
- Introduce two new messages VHOST_USER_GET_SHM_SIZE
and VHOST_USER_SET_SHM_FD

Xie Yongji (6):
vhost-user: Support transferring inflight buffer between qemu and
backend
libvhost-user: Introduce vu_queue_map_desc()
libvhost-user: Support tracking inflight I/O in shared memory
vhost-user-blk: Add support to get/set inflight buffer
vhost-user-blk: Add support to reconnect backend contrib/vhost-user-blk: enable inflight I/O tracking

  Makefile                                |   2 +-
  contrib/libvhost-user/libvhost-user.c   | 402 ++++++++++++++++++++----
  contrib/libvhost-user/libvhost-user.h   |  40 +++
  contrib/vhost-user-blk/vhost-user-blk.c |   3 +-
  docs/interop/vhost-user.txt             | 101 ++++++
  hw/block/vhost-user-blk.c               | 227 ++++++++++---
  hw/virtio/vhost-user.c                  | 110 +++++++
  hw/virtio/vhost.c                       | 105 +++++++
  include/hw/virtio/vhost-backend.h       |  10 +
  include/hw/virtio/vhost-user-blk.h      |   5 +
  include/hw/virtio/vhost.h               |  19 ++
  11 files changed, 925 insertions(+), 99 deletions(-)