vhost-user-blk: Add support for backend reconnecting
v6 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 transferring shared buffer between qemu and backend.
The patch 2 deletes some redundant check in contrib/libvhost-user.c.
The patch 3,4 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 5 allows vhost-user-blk to use the two new messages to get/set inflight buffer from/to backend.
The patch 6 supports vhost-user-blk to reconnect backend when connection closed.
The patch 7 introduces VHOST_USER_PROTOCOL_F_SLAVE_SHMFD to vhost-user-blk backend which is used to tell qemu that we support reconnecting now.
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.
V5 to V6:
- Document the layout in inflight buffer for packed virtqueue
- Rework the layout in inflight buffer for split virtqueue
- Remove version field in VhostUserInflight
- Add a patch to remove some redundant check in contrib/libvhost-user.c
- Document more details in vhost-user.txt
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 (7):
vhost-user: Support transferring inflight buffer between qemu and
backend
libvhost-user: Remove unnecessary FD flag check for event file
descriptors
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 | 400 ++++++++++++++++++++---- contrib/libvhost-user/libvhost-user.h | 58 ++++ contrib/vhost-user-blk/vhost-user-blk.c | 3 +- docs/interop/vhost-user.txt | 264 ++++++++++++++++ hw/block/vhost-user-blk.c | 229 +++++++++++--- hw/virtio/vhost-user.c | 107 +++++++ hw/virtio/vhost.c | 96 ++++++ include/hw/virtio/vhost-backend.h | 10 + include/hw/virtio/vhost-user-blk.h | 5 + include/hw/virtio/vhost.h | 18 ++ 11 files changed, 1084 insertions(+), 108 deletions(-)
Signature · 1 line
2.17.1
PATCH v6 1/7 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 retrieve a new one when vm reset.
--- docs/interop/vhost-user.txt | 264 ++++++++++++++++++++++++++++++ hw/virtio/vhost-user.c | 107 ++++++++++++ hw/virtio/vhost.c | 96 +++++++++++ include/hw/virtio/vhost-backend.h | 10 ++ include/hw/virtio/vhost.h | 18 ++ 5 files changed, 495 insertions(+)
docs/interop/vhost-user.txt +264 -0
@@ -142,6 +142,17 @@ 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 | 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 + 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 +168,7 @@ typedef struct VhostUserMsg { struct vhost_iotlb_msg iotlb; VhostUserConfig config; VhostUserVringArea area; + VhostUserInflight inflight; }; } QEMU_PACKED VhostUserMsg;
@@ -175,6 +187,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 +201,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 +396,235 @@ 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 resubmit +inflight I/Os. If virtqueue is processed in order, we can easily achieve +that by getting the inflight descriptors from descriptor table (split virtqueue) +or descriptor ring (packed virtqueue). However, it can't work when we process +descriptors out-of-order because some entries which store the information of +inflight descriptors in available ring (split virtqueue) or descriptor +ring (packed virtqueue) might be overrided by new entries. To solve this +problem, slave need to allocate an extra buffer to store this information of inflight +descriptors 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. + +For split virtqueue, queue region can be implemented as: + +typedef struct DescStateSplit { + /* Indicate whether this descriptor is inflight or not. + * Only available for head-descriptor. */ + uint8_t inflight; + + /* Padding */ + uint8_t padding; + + /* Link to the last processed entry */ + uint16_t next; +} DescStateSplit; + +typedef struct QueueRegionSplit { + /* The feature flags of this region. Now it's initialized to 0. */ + uint64_t features; + + /* The version of this region. It's 1 currently. + * Zero value indicates an uninitialized buffer */ + uint16_t version; + + /* The size of DescStateSplit array. It's equal to the virtqueue + * size. Slave could get it from queue size field of VhostUserInflight. */ + uint16_t desc_num; + + /* The head of processed DescStateSplit entry list */ + uint16_t process_head; + + /* Storing the idx value of used ring */ + uint16_t used_idx; + + /* Used to track the state of each descriptor in descriptor table */ + DescStateSplit desc[0]; +} QueueRegionSplit; + +To track inflight I/O, the queue region should be processed as follows: + +When receiving available buffers from the driver: + + 1. Get the next available head-descriptor index from available ring, i + + 2. Set desc[i].inflight to 1 + +When supplying used buffers to the driver: + + 1. Get corresponding used head-descriptor index, i + + 2. Set desc[i].next to process_head + + 3. Set process_head to i + + 4. Steps 1,2,3 may be performed repeatedly if batching is possible + + 5. Increase the idx value of used ring by the size of the batch + + 6. Set the inflight field of each DescStateSplit entry in the batch to 0 + + 7. Set used_idx to the idx value of used ring + +When reconnecting: + + 1. If the value of used_idx does not match the idx value of used ring, + + (a) Subtract the value of used_idx from the idx value of used ring to get + the number of in-progress DescStateSplit entries + + (b) Set the inflight field of the in-progress DescStateSplit entries which + start from process_head to 0 + + (c) Set used_idx to the idx value of used ring + + 2. Resubmit each inflight DescStateSplit entry + +For packed virtqueue, queue region can be implemented as: + +typedef struct DescStatePacked { + /* Indicate whether this descriptor is inflight or not. + * Only available for head-descriptor. */ + uint8_t inflight; + + /* Padding */ + uint8_t padding; + + /* Link to the next free entry */ + uint16_t next; + + /* Link to the last entry of descriptor list. + * Only available for head-descriptor. */ + uint16_t last; + + /* The length of descriptor list. + * Only available for head-descriptor. */ + uint16_t num; + + /* The buffer id */ + uint16_t id; + + /* The descriptor flags */ + uint16_t flags; + + /* The buffer length */ + uint32_t len; + + /* The buffer address */ + uint64_t addr; +} DescStatePacked; + +typedef struct QueueRegionPacked { + /* The feature flags of this region. Now it's initialized to 0. */ + uint64_t features; + + /* The version of this region. It's 1 currently. + * Zero value indicates an uninitialized buffer */ + uint16_t version; + + /* The size of DescStatePacked array. It's equal to the virtqueue + * size. Slave could get it from queue size field of VhostUserInflight. */ + uint16_t desc_num; + + /* The head of free DescStatePacked entry list */ + uint16_t free_head; + + /* The old head of free DescStatePacked entry list */ + uint16_t old_free_head; + + /* The used index of descriptor ring */ + uint16_t used_idx; + + /* The old used index of descriptor ring */ + uint16_t old_used_idx; + + /* Device ring wrap counter */ + uint8_t used_wrap_counter; + + /* The old device ring wrap counter */ + uint8_t old_used_wrap_counter; + + /* Padding */ + uint8_t padding[7]; + + /* Used to track the state of each descriptor fetched from descriptor ring */ + DescStatePacked desc[0]; +} QueueRegionPacked; + +To track inflight I/O, the queue region should be processed as follows: + +When receiving available buffers from the driver: + + 1. Get the next available descriptor entry from descriptor ring, d + + 2. If d is head descriptor, + + (a) Set desc[old_free_head].num to 0 + + (b) Set desc[old_free_head].inflight to 1 + + 3. If d is last descriptor, set desc[old_free_head].last to free_head + + 4. Increase desc[old_free_head].num by 1 + + 5. Set desc[free_head].addr, desc[free_head].len, desc[free_head].flags, + desc[free_head].id to d.addr, d.len, d.flags, d.id + + 6. Set free_head to desc[free_head].next + + 7. If d is last descriptor, set old_free_head to free_head + +When supplying used buffers to the driver: + + 1. Get corresponding used head-descriptor entry from descriptor ring, d + + 2. Get corresponding DescStatePacked entry, e + + 3. Set desc[e.last].next to free_head + + 4. Set free_head to the index of e + + 5. Steps 1,2,3,4 may be performed repeatedly if batching is possible + + 6. Increase used_idx by the size of the batch and update used_wrap_counter if needed + + 7. Update d.flags + + 8. Set the inflight field of each head DescStatePacked entry in the batch to 0 + + 9. Set old_free_head, old_used_idx, old_used_wrap_counter to free_head, used_idx, + used_wrap_counter + +When reconnecting: + + 1. If used_idx does not match old_used_idx, + + (a) Get the next descriptor ring entry through old_used_idx, d + + (b) Use old_used_wrap_counter to calculate the available flags + + (c) If d.flags is not equal to the calculated flags value, set old_free_head, + old_used_idx, old_used_wrap_counter to free_head, used_idx, used_wrap_counter + + 2. Set free_head, used_idx, used_wrap_counter to old_free_head, old_used_idx, + old_used_wrap_counter + + 3. Set the inflight field of each free DescStatePacked entry to 0 + + 4. Resubmit each inflight DescStatePacked entry + Protocol features -----------------
@@ -397,6 +640,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 +1005,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 retrieve a new one 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 +107 -0
141 lines not on this page · raw message
hw/virtio/vhost.c +96 -0
102 lines not on this page · raw message
include/hw/virtio/vhost-backend.h +10 -0
@@ -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 +18 -0
@@ -7,6 +7,15 @@#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 queue_size; +}; +struct vhost_virtqueue {int kick;int call;
@@ -120,4 +129,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
Re: [Qemu-devel] [PATCH v6 1/7] vhost-user: Support transferring inflight buffer between qemu and backend
Quoted 121 lines · On Mon, Feb 18, 2019 at 06:27:42PM +0800, [email protected] wrote:
From: Xie Yongji <[email protected]>
This patch introduces two new messages
VHOST_USER_GET_INFLIGHT_FDandVHOST_USER_SET_INFLIGHT_FDto support transferring a shared buffer between qemu and backend.Firstly, qemu uses
VHOST_USER_GET_INFLIGHT_FDto get the shared buffer from backend. Then qemu should send it back throughVHOST_USER_SET_INFLIGHT_FDeach time we start vhost-user.This shared buffer is used to track inflight I/O by backend. Qemu should retrieve a new one when vm reset.
Signed-off-by Xie Yongji <[email protected]>Signed-off-by Chai Wen <[email protected]>Signed-off-by Zhang Yu <[email protected]>--- docs/interop/vhost-user.txt | 264 ++++++++++++++++++++++++++++++ hw/virtio/vhost-user.c | 107 ++++++++++++ hw/virtio/vhost.c | 96 +++++++++++ include/hw/virtio/vhost-backend.h | 10 ++ include/hw/virtio/vhost.h | 18 ++ 5 files changed, 495 insertions(+)docs/interop/vhost-user.txt +61
-0@@ -142,6 +142,17 @@ 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 | 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 + 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 +168,7 @@ typedef struct VhostUserMsg { struct vhost_iotlb_msg iotlb; VhostUserConfig config; VhostUserVringArea area; + VhostUserInflight inflight; }; } QEMU_PACKED VhostUserMsg;@@ -175,6 +187,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 +201,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 +396,235 @@ 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 resubmit +inflight I/Os. If virtqueue is processed in order, we can easily achieve +that by getting the inflight descriptors from descriptor table (split virtqueue) +or descriptor ring (packed virtqueue). However, it can't work when we process +descriptors out-of-order because some entries which store the information of +inflight descriptors in available ring (split virtqueue) or descriptor +ring (packed virtqueue) might be overrided by new entries. To solve this +problem, slave need to allocate an extra buffer to store this information of inflight +descriptors 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. + +For split virtqueue, queue region can be implemented as: + +typedef struct DescStateSplit { + /* Indicate whether this descriptor is inflight or not. + * Only available for head-descriptor. */ + uint8_t inflight; + + /* Padding */ + uint8_t padding; + + /* Link to the last processed entry */ + uint16_t next; +} DescStateSplit; + +typedef struct QueueRegionSplit { + /* The feature flags of this region. Now it's initialized to 0. */ + uint64_t features; + + /* The version of this region. It's 1 currently. + * Zero value indicates an uninitialized buffer */ + uint16_t version; + + /* The size of DescStateSplit array. It's equal to the virtqueue + * size. Slave could get it from queue size field of VhostUserInflight. */ + uint16_t desc_num;
docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 455
Quoted 10 lines
docs/interop/vhost-user.txt +10
-0+ + /* The head of processed DescStateSplit entry list */ + uint16_t process_head; + + /* Storing the idx value of used ring */ + uint16_t used_idx; + + /* Used to track the state of each descriptor in descriptor table */ + DescStateSplit desc[0]; +} QueueRegionSplit;
What is the endian-ness of multibyte fields?
Quoted 28 lines
docs/interop/vhost-user.txt +28
-0+ +To track inflight I/O, the queue region should be processed as follows: + +When receiving available buffers from the driver: + + 1. Get the next available head-descriptor index from available ring, i + + 2. Set desc[i].inflight to 1 + +When supplying used buffers to the driver: + + 1. Get corresponding used head-descriptor index, i + + 2. Set desc[i].next to process_head + + 3. Set process_head to i + + 4. Steps 1,2,3 may be performed repeatedly if batching is possible + + 5. Increase the idx value of used ring by the size of the batch + + 6. Set the inflight field of each DescStateSplit entry in the batch to 0 + + 7. Set used_idx to the idx value of used ring + +When reconnecting: + + 1. If the value of used_idx does not match the idx value of used ring,
docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 493
Quoted 10 lines
docs/interop/vhost-user.txt +10
-0+ + (a) Subtract the value of used_idx from the idx value of used ring to get + the number of in-progress DescStateSplit entries + + (b) Set the inflight field of the in-progress DescStateSplit entries which + start from process_head to 0 + + (c) Set used_idx to the idx value of used ring + + 2. Resubmit each inflight DescStateSplit entry
I re-read a couple of time and I still don't understand what it says.
For simplicity consider split ring. So we want a list of heads that are outstanding. Fair enough. Now device finishes a head. What now? I needs to drop head from the list. But list is unidirectional (just next, no prev). So how can you drop an entry from the middle?
Quoted 22 lines
docs/interop/vhost-user.txt +22
-0+For packed virtqueue, queue region can be implemented as: + +typedef struct DescStatePacked { + /* Indicate whether this descriptor is inflight or not. + * Only available for head-descriptor. */ + uint8_t inflight; + + /* Padding */ + uint8_t padding; + + /* Link to the next free entry */ + uint16_t next; + + /* Link to the last entry of descriptor list. + * Only available for head-descriptor. */ + uint16_t last; + + /* The length of descriptor list. + * Only available for head-descriptor. */ + uint16_t num; + + /* The buffer id */
docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 526
Quoted 10 lines
docs/interop/vhost-user.txt +10
-0+ uint16_t id; + + /* The descriptor flags */ + uint16_t flags; + + /* The buffer length */ + uint32_t len; + + /* The buffer address */ + uint64_t addr;
Do we want an extra u64 here to make it a power of two?
Quoted 468 lines
docs/interop/vhost-user.txt +122
-0+} DescStatePacked; + +typedef struct QueueRegionPacked { + /* The feature flags of this region. Now it's initialized to 0. */ + uint64_t features; + + /* The version of this region. It's 1 currently. + * Zero value indicates an uninitialized buffer */ + uint16_t version; + + /* The size of DescStatePacked array. It's equal to the virtqueue + * size. Slave could get it from queue size field of VhostUserInflight. */ + uint16_t desc_num; + + /* The head of free DescStatePacked entry list */ + uint16_t free_head; + + /* The old head of free DescStatePacked entry list */ + uint16_t old_free_head; + + /* The used index of descriptor ring */ + uint16_t used_idx; + + /* The old used index of descriptor ring */ + uint16_t old_used_idx; + + /* Device ring wrap counter */ + uint8_t used_wrap_counter; + + /* The old device ring wrap counter */ + uint8_t old_used_wrap_counter; + + /* Padding */ + uint8_t padding[7]; + + /* Used to track the state of each descriptor fetched from descriptor ring */ + DescStatePacked desc[0]; +} QueueRegionPacked; + +To track inflight I/O, the queue region should be processed as follows: + +When receiving available buffers from the driver: + + 1. Get the next available descriptor entry from descriptor ring, d + + 2. If d is head descriptor, + + (a) Set desc[old_free_head].num to 0 + + (b) Set desc[old_free_head].inflight to 1 + + 3. If d is last descriptor, set desc[old_free_head].last to free_head + + 4. Increase desc[old_free_head].num by 1 + + 5. Set desc[free_head].addr, desc[free_head].len, desc[free_head].flags, + desc[free_head].id to d.addr, d.len, d.flags, d.id + + 6. Set free_head to desc[free_head].next + + 7. If d is last descriptor, set old_free_head to free_head + +When supplying used buffers to the driver: + + 1. Get corresponding used head-descriptor entry from descriptor ring, d + + 2. Get corresponding DescStatePacked entry, e + + 3. Set desc[e.last].next to free_head + + 4. Set free_head to the index of e + + 5. Steps 1,2,3,4 may be performed repeatedly if batching is possible + + 6. Increase used_idx by the size of the batch and update used_wrap_counter if needed + + 7. Update d.flags + + 8. Set the inflight field of each head DescStatePacked entry in the batch to 0 + + 9. Set old_free_head, old_used_idx, old_used_wrap_counter to free_head, used_idx, + used_wrap_counter + +When reconnecting: + + 1. If used_idx does not match old_used_idx, + + (a) Get the next descriptor ring entry through old_used_idx, d + + (b) Use old_used_wrap_counter to calculate the available flags + + (c) If d.flags is not equal to the calculated flags value, set old_free_head, + old_used_idx, old_used_wrap_counter to free_head, used_idx, used_wrap_counter + + 2. Set free_head, used_idx, used_wrap_counter to old_free_head, old_used_idx, + old_used_wrap_counter + + 3. Set the inflight field of each free DescStatePacked entry to 0 + + 4. Resubmit each inflight DescStatePacked entry + Protocol features -----------------@@ -397,6 +640,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 +1005,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 retrieve a new one 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 +107
-0@@ -52,6 +52,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 };@@ -89,6 +90,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;@@ -147,6 +150,13 @@ typedef struct VhostUserVringArea {uint64_t offset; } VhostUserVringArea; +typedef struct VhostUserInflight { +uint64_t mmap_size; +uint64_t mmap_offset; +uint16_t num_queues; +uint16_t queue_size; +}VhostUserInflight ; + typedef struct { VhostUserRequest request;@@ -169,6 +179,7 @@ typedef union {VhostUserConfig config;VhostUserCryptoSession session;VhostUserVringArea area; +VhostUserInflight inflight; } VhostUserPayload; typedef struct VhostUserMsg {@@ -1739,6 +1750,100 @@ static bool vhost_user_mem_section_filter(struct vhost_dev *dev,return result; } +static int vhost_user_get_inflight_fd (struct vhost_dev *dev, +uint16_t queue_size, +struct vhost_inflight *inflight) +{ +void *addr; +int fd; +struct vhost_user *u = dev->opaque; +CharBackend *chr = u->user->chr; +VhostUserMsg msg = { + .hdr.request =VHOST_USER_GET_INFLIGHT_FD , + .hdr.flags =VHOST_USER_VERSION , + .payload.inflight.num_queues = dev->nvqs, + .payload.inflight.queue_size = queue_size, + .hdr.size =sizeof (msg.payload.inflight), + }; + +if (!virtio_has_feature (dev->protocol_features, +VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD )) { +return 0 ; + } + +if (vhost_user_write (dev, &msg,NULL ,0 ) <0 ) { +return -1 ; + } + +if (vhost_user_read (dev, &msg) <0 ) { +return -1 ; + } + +if (msg.hdr.request !=VHOST_USER_GET_INFLIGHT_FD ) { +error_report ("Received unexpected msg type. " +"Expected %d received %d" , +VHOST_USER_GET_INFLIGHT_FD , msg.hdr.request); +return -1 ; + } + +if (msg.hdr.size !=sizeof (msg.payload.inflight)) { +error_report ("Received bad msg size." ); +return -1 ; + } + +if (!msg.payload.inflight.mmap_size) { +return 0 ; + } + + fd =qemu_chr_fe_get_msgfd (chr); +if (fd <0 ) { +error_report ("Failed to get mem fd" ); +return -1 ; + } + + addr =mmap (0 , msg.payload.inflight.mmap_size,PROT_READ |PROT_WRITE , +MAP_SHARED , fd, msg.payload.inflight.mmap_offset); + +if (addr ==MAP_FAILED ) { +error_report ("Failed to mmap mem fd" ); +close (fd); +return -1 ; + } + + inflight->addr = addr; + inflight->fd = fd; + inflight->size = msg.payload.inflight.mmap_size; + inflight->offset = msg.payload.inflight.mmap_offset; + inflight->queue_size = queue_size; + +return 0 ; +} + +static int vhost_user_set_inflight_fd (struct vhost_dev *dev, +struct vhost_inflight *inflight) +{ +VhostUserMsg msg = { + .hdr.request =VHOST_USER_SET_INFLIGHT_FD , + .hdr.flags =VHOST_USER_VERSION , + .payload.inflight.mmap_size = inflight->size, + .payload.inflight.mmap_offset = inflight->offset, + .payload.inflight.num_queues = dev->nvqs, + .payload.inflight.queue_size = inflight->queue_size, + .hdr.size =sizeof (msg.payload.inflight), + }; + +if (!virtio_has_feature (dev->protocol_features, +VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD )) { +return 0 ; + } + +if (vhost_user_write (dev, &msg, &inflight->fd,1 ) <0 ) { +return -1 ; + } + +return 0 ; +} +VhostUserState *vhost_user_init (void ) { VhostUserState *user = g_new0(struct VhostUserState, 1);@@ -1790,4 +1895,6 @@ const VhostOps user_ops = { .vhost_crypto_create_session = vhost_user_crypto_create_session, .vhost_crypto_close_session = vhost_user_crypto_close_session, .vhost_backend_mem_section_filter = vhost_user_mem_section_filter, + .vhost_get_inflight_fd = vhost_user_get_inflight_fd, + .vhost_set_inflight_fd = vhost_user_set_inflight_fd, };hw/virtio/vhost.c +96
-0@@ -1481,6 +1481,102 @@ void vhost_dev_set_config_notifier(struct vhost_dev *hdev, hdev->config_ops = ops; } +void vhost_dev_free_inflight (struct vhost_inflight *inflight) +{ +if (inflight->addr) { +qemu_memfd_free (inflight->addr, inflight->size, inflight->fd); + inflight->addr =NULL ; + inflight->fd =-1 ; + } +} + +static int vhost_dev_resize_inflight (struct vhost_inflight *inflight, +uint64_t new_size) +{ +Error *err =NULL ; +int fd =-1 ; +void *addr =qemu_memfd_alloc ("vhost-inflight" , new_size, +F_SEAL_GROW |F_SEAL_SHRINK |F_SEAL_SEAL , + &fd, &err); + +if (err) { +error_report_err (err); +return -1 ; + } + +vhost_dev_free_inflight (inflight); + inflight->offset =0 ; + inflight->addr = addr; + inflight->fd = fd; + inflight->size = new_size; + +return 0 ; +} + +void vhost_dev_save_inflight (struct vhost_inflight *inflight,QEMUFile *f) +{ +if (inflight->addr) { +qemu_put_be64 (f, inflight->size); +qemu_put_be16 (f, inflight->queue_size); +qemu_put_buffer (f, inflight->addr, inflight->size); + }else { +qemu_put_be64 (f,0 ); + } +} + +int vhost_dev_load_inflight (struct vhost_inflight *inflight,QEMUFile *f) +{ +uint64_t size; + + size =qemu_get_be64 (f); +if (!size) { +return 0 ; + } + +if (inflight->size != size) { +if (vhost_dev_resize_inflight (inflight, size)) { +return -1 ; + } + } + inflight->queue_size =qemu_get_be16 (f); + +qemu_get_buffer (f, inflight->addr, size); + +return 0 ; +} + +int vhost_dev_set_inflight (struct vhost_dev *dev, +struct vhost_inflight *inflight) +{ +int r; + +if (dev->vhost_ops->vhost_set_inflight_fd && inflight->addr) { + r = dev->vhost_ops->vhost_set_inflight_fd (dev, inflight); +if (r) { +VHOST_OPS_DEBUG ("vhost_set_inflight_fd failed" ); +return -errno; + } + } + +return 0 ; +} + +int vhost_dev_get_inflight (struct vhost_dev *dev,uint16_t queue_size, +struct vhost_inflight *inflight) +{ +int r; + +if (dev->vhost_ops->vhost_get_inflight_fd) { + r = dev->vhost_ops->vhost_get_inflight_fd (dev, queue_size, inflight); +if (r) { +VHOST_OPS_DEBUG ("vhost_get_inflight_fd failed" ); +return -errno; + } + } + +return 0 ; +} +/* Host notifiers must be enabled at this point. */ int vhost_dev_start (struct vhost_dev *hdev,VirtIODevice *vdev) {include/hw/virtio/vhost-backend.h +10
-0@@ -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 +18
-0@@ -7,6 +7,15 @@#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 queue_size; +}; +struct vhost_virtqueue {int kick;int call;@@ -120,4 +129,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
Re: [Qemu-devel] [PATCH v6 1/7] vhost-user: Support transferring inflight buffer between qemu and backend
Quoted 128 lines · Michael S. Tsirkin
Quoted 126 lines · On Mon, Feb 18, 2019 at 06:27:42PM +0800, [email protected] wrote:
From: Xie Yongji <[email protected]>
This patch introduces two new messages
VHOST_USER_GET_INFLIGHT_FDandVHOST_USER_SET_INFLIGHT_FDto support transferring a shared buffer between qemu and backend.Firstly, qemu uses
VHOST_USER_GET_INFLIGHT_FDto get the shared buffer from backend. Then qemu should send it back throughVHOST_USER_SET_INFLIGHT_FDeach time we start vhost-user.This shared buffer is used to track inflight I/O by backend. Qemu should retrieve a new one when vm reset.
Signed-off-by Xie Yongji <[email protected]>Signed-off-by Chai Wen <[email protected]>Signed-off-by Zhang Yu <[email protected]>--- docs/interop/vhost-user.txt | 264 ++++++++++++++++++++++++++++++ hw/virtio/vhost-user.c | 107 ++++++++++++ hw/virtio/vhost.c | 96 +++++++++++ include/hw/virtio/vhost-backend.h | 10 ++ include/hw/virtio/vhost.h | 18 ++ 5 files changed, 495 insertions(+)docs/interop/vhost-user.txt +66
-0@@ -142,6 +142,17 @@ 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 | 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 + 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 +168,7 @@ typedef struct VhostUserMsg { struct vhost_iotlb_msg iotlb; VhostUserConfig config; VhostUserVringArea area; + VhostUserInflight inflight; }; } QEMU_PACKED VhostUserMsg;@@ -175,6 +187,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 +201,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 +396,235 @@ 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 resubmit +inflight I/Os. If virtqueue is processed in order, we can easily achieve +that by getting the inflight descriptors from descriptor table (split virtqueue) +or descriptor ring (packed virtqueue). However, it can't work when we process +descriptors out-of-order because some entries which store the information of +inflight descriptors in available ring (split virtqueue) or descriptor +ring (packed virtqueue) might be overrided by new entries. To solve this +problem, slave need to allocate an extra buffer to store this information of inflight +descriptors 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. + +For split virtqueue, queue region can be implemented as: + +typedef struct DescStateSplit { + /* Indicate whether this descriptor is inflight or not. + * Only available for head-descriptor. */ + uint8_t inflight; + + /* Padding */ + uint8_t padding; + + /* Link to the last processed entry */ + uint16_t next; +} DescStateSplit; + +typedef struct QueueRegionSplit { + /* The feature flags of this region. Now it's initialized to 0. */ + uint64_t features; + + /* The version of this region. It's 1 currently. + * Zero value indicates an uninitialized buffer */ + uint16_t version; + + /* The size of DescStateSplit array. It's equal to the virtqueue + * size. Slave could get it from queue size field of VhostUserInflight. */ + uint16_t desc_num; + + /* The head of processed DescStateSplit entry list */ + uint16_t process_head; + + /* Storing the idx value of used ring */
Quoted 9 lines
docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 455
Quoted 5 lines
docs/interop/vhost-user.txt +5
-0+ uint16_t used_idx; + + /* Used to track the state of each descriptor in descriptor table */ + DescStateSplit desc[0]; +} QueueRegionSplit;What is the endian-ness of multibyte fields?
Native endian is OK here. Right?
Quoted 42 lines
Quoted 29 lines
docs/interop/vhost-user.txt +28
-0+ +To track inflight I/O, the queue region should be processed as follows: + +When receiving available buffers from the driver: + + 1. Get the next available head-descriptor index from available ring, i + + 2. Set desc[i].inflight to 1 + +When supplying used buffers to the driver: + + 1. Get corresponding used head-descriptor index, i + + 2. Set desc[i].next to process_head + + 3. Set process_head to i + + 4. Steps 1,2,3 may be performed repeatedly if batching is possible + + 5. Increase the idx value of used ring by the size of the batch + + 6. Set the inflight field of each DescStateSplit entry in the batch to 0 + + 7. Set used_idx to the idx value of used ring + +When reconnecting: + + 1. If the value of used_idx does not match the idx value of used ring,docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 493
Quoted 10 lines
docs/interop/vhost-user.txt +10
-0+ + (a) Subtract the value of used_idx from the idx value of used ring to get + the number of in-progress DescStateSplit entries + + (b) Set the inflight field of the in-progress DescStateSplit entries which + start from process_head to 0 + + (c) Set used_idx to the idx value of used ring + + 2. Resubmit each inflight DescStateSplit entryI re-read a couple of time and I still don't understand what it says.
Quoted 5 lines
For simplicity consider split ring. So we want a list of heads that are outstanding. Fair enough. Now device finishes a head. What now? I needs to drop head from the list. But list is unidirectional (just next, no prev). So how can you drop an entry from the middle?
The process_head is only used when slave crash between increasing the idx value of used ring and updating used_idx. We use it to find the in-progress DescStateSplit entries before the crash and complete them when reconnecting. Make sure guest and slave have the same view for inflight I/Os.
In other case, the inflight field is enough to track inflight I/O. When reconnecting, we go through all DescStateSplit entries and re-submit the entry whose inflight field is equal to 1.
Quoted 26 lines
Quoted 26 lines
docs/interop/vhost-user.txt +26
-0+For packed virtqueue, queue region can be implemented as: + +typedef struct DescStatePacked { + /* Indicate whether this descriptor is inflight or not. + * Only available for head-descriptor. */ + uint8_t inflight; + + /* Padding */ + uint8_t padding; + + /* Link to the next free entry */ + uint16_t next; + + /* Link to the last entry of descriptor list. + * Only available for head-descriptor. */ + uint16_t last; + + /* The length of descriptor list. + * Only available for head-descriptor. */ + uint16_t num; + + /* The buffer id */ + uint16_t id; + + /* The descriptor flags */ + uint16_t flags;
Quoted 9 lines
docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 526
Quoted 6 lines
docs/interop/vhost-user.txt +6
-0+ + /* The buffer length */ + uint32_t len; + + /* The buffer address */ + uint64_t addr;Do we want an extra u64 here to make it a power of two?
Looks good to me.
Thanks,
Yongji
Re: [Qemu-devel] [PATCH v6 1/7] vhost-user: Support transferring inflight buffer between qemu and backend
Quoted 47 lines · Yongji Xie
Quoted 41 lines
Quoted 28 lines
docs/interop/vhost-user.txt +28
-0+ +To track inflight I/O, the queue region should be processed as follows: + +When receiving available buffers from the driver: + + 1. Get the next available head-descriptor index from available ring, i + + 2. Set desc[i].inflight to 1 + +When supplying used buffers to the driver: + + 1. Get corresponding used head-descriptor index, i + + 2. Set desc[i].next to process_head + + 3. Set process_head to i + + 4. Steps 1,2,3 may be performed repeatedly if batching is possible + + 5. Increase the idx value of used ring by the size of the batch + + 6. Set the inflight field of each DescStateSplit entry in the batch to 0 + + 7. Set used_idx to the idx value of used ring + +When reconnecting: + + 1. If the value of used_idx does not match the idx value of used ring,docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 493
Quoted 10 lines
docs/interop/vhost-user.txt +10
-0+ + (a) Subtract the value of used_idx from the idx value of used ring to get + the number of in-progress DescStateSplit entries + + (b) Set the inflight field of the in-progress DescStateSplit entries which + start from process_head to 0 + + (c) Set used_idx to the idx value of used ring + + 2. Resubmit each inflight DescStateSplit entryI re-read a couple of time and I still don't understand what it says.
Quoted 5 lines
For simplicity consider split ring. So we want a list of heads that are outstanding. Fair enough. Now device finishes a head. What now? I needs to drop head from the list. But list is unidirectional (just next, no prev). So how can you drop an entry from the middle?
Quoted 6 lines
The
process_headis only used when slave crash between increasing the idx value of used ring and updatingused_idx. We use it to find the in-progress DescStateSplit entries before the crash and complete them when reconnecting. Make sure guest and slave have the same view for inflight I/Os.
But I don't understand how does the described process help do it?
Quoted 3 lines
In other case, the inflight field is enough to track inflight I/O. When reconnecting, we go through all DescStateSplit entries and re-submit the entry whose inflight field is equal to 1.
What I don't understand is how do we know the order in which they have to be resubmitted. Reordering operations would be a big problem, won't it?
Let's say I fetch descriptors A, B, C and start processing. how does memory look?
Now I finished B and marked it used. How does memory look?
I also wonder how do you address a crash between marking descriptor used and clearing inflight. Will you redo the descriptor? Is it always safe? What if it's a write?
Re: [Qemu-devel] [PATCH v6 1/7] vhost-user: Support transferring inflight buffer between qemu and backend
Quoted 49 lines · Michael S. Tsirkin
Quoted 47 lines · Yongji Xie
Quoted 46 lines
Quoted 28 lines
docs/interop/vhost-user.txt +28
-0+ +To track inflight I/O, the queue region should be processed as follows: + +When receiving available buffers from the driver: + + 1. Get the next available head-descriptor index from available ring, i + + 2. Set desc[i].inflight to 1 + +When supplying used buffers to the driver: + + 1. Get corresponding used head-descriptor index, i + + 2. Set desc[i].next to process_head + + 3. Set process_head to i + + 4. Steps 1,2,3 may be performed repeatedly if batching is possible + + 5. Increase the idx value of used ring by the size of the batch + + 6. Set the inflight field of each DescStateSplit entry in the batch to 0 + + 7. Set used_idx to the idx value of used ring + +When reconnecting: + + 1. If the value of used_idx does not match the idx value of used ring,docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 493
Quoted 10 lines
docs/interop/vhost-user.txt +10
-0+ + (a) Subtract the value of used_idx from the idx value of used ring to get + the number of in-progress DescStateSplit entries + + (b) Set the inflight field of the in-progress DescStateSplit entries which + start from process_head to 0 + + (c) Set used_idx to the idx value of used ring + + 2. Resubmit each inflight DescStateSplit entryI re-read a couple of time and I still don't understand what it says.
For simplicity consider split ring. So we want a list of heads that are outstanding. Fair enough. Now device finishes a head. What now? I needs to drop head from the list. But list is unidirectional (just next, no prev). So how can you drop an entry from the middle?
Quoted 9 lines
Quoted 6 lines
The
process_headis only used when slave crash between increasing the idx value of used ring and updatingused_idx. We use it to find the in-progress DescStateSplit entries before the crash and complete them when reconnecting. Make sure guest and slave have the same view for inflight I/Os.But I don't understand how does the described process help do it?
For example, we need to submit descriptors A, B, C to driver in a batch.
Firstly, we will link those descriptors like:
process_head->A->B->C (A)
Then, we need to update idx value of used vring to mark those descriptors as used:
_vring.used->idx += 3 (B)
At last, clear the inflight field of those descriptors and update used_idx field:
A.inflight = 0; B.inflight = 0; C.inflight = 0; (C)
used_idx = _vring.used->idx; (D)
After (B), guest can consume the descriptors A,B,C. So we must make sure the inflight field of A,B,C is cleared when reconnecting to avoid re-submitting used descriptor. If slave crash during (C), the inflight field of A,B,C may be incorrect. To detect that case, we can see whether used_idx matches _vring.used->idx. And through process_head, we can get the in-progress descriptors A,B,C and clear their inflight field again when reconnecting.
Quoted 9 lines
Quoted 4 lines
In other case, the inflight field is enough to track inflight I/O. When reconnecting, we go through all DescStateSplit entries and re-submit the entry whose inflight field is equal to 1.
What I don't understand is how do we know the order in which they have to be resubmitted. Reordering operations would be a big problem, won't it?
In previous patch, I record avail_idx for each DescStateSplit entry to preserve the order. Is it useful to fix this?
Quoted 3 lines
Let's say I fetch descriptors A, B, C and start processing. how does memory look?
A.inflight = 1, C.inflight = 1, B.inflight = 1
Quoted 3 lines
Now I finished B and marked it used. How does memory look?
A.inflight = 1, C.inflight = 1, B.inflight = 0, process_head = B
Quoted 5 lines
I also wonder how do you address a crash between marking descriptor used and clearing inflight. Will you redo the descriptor? Is it always safe? What if it's a write?
It's safe. We can get the in-progess descriptors through process_head and clear their inflight field when reconnecting.
Thanks,
Yongji
Re: [Qemu-devel] [PATCH v6 1/7] vhost-user: Support transferring inflight buffer between qemu and backend
Quoted 103 lines · Yongji Xie
Quoted 49 lines · Michael S. Tsirkin
Quoted 47 lines · Yongji Xie
Quoted 46 lines
Quoted 28 lines
docs/interop/vhost-user.txt +28
-0+ +To track inflight I/O, the queue region should be processed as follows: + +When receiving available buffers from the driver: + + 1. Get the next available head-descriptor index from available ring, i + + 2. Set desc[i].inflight to 1 + +When supplying used buffers to the driver: + + 1. Get corresponding used head-descriptor index, i + + 2. Set desc[i].next to process_head + + 3. Set process_head to i + + 4. Steps 1,2,3 may be performed repeatedly if batching is possible + + 5. Increase the idx value of used ring by the size of the batch + + 6. Set the inflight field of each DescStateSplit entry in the batch to 0 + + 7. Set used_idx to the idx value of used ring + +When reconnecting: + + 1. If the value of used_idx does not match the idx value of used ring,docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 493
Quoted 10 lines
docs/interop/vhost-user.txt +10
-0+ + (a) Subtract the value of used_idx from the idx value of used ring to get + the number of in-progress DescStateSplit entries + + (b) Set the inflight field of the in-progress DescStateSplit entries which + start from process_head to 0 + + (c) Set used_idx to the idx value of used ring + + 2. Resubmit each inflight DescStateSplit entryI re-read a couple of time and I still don't understand what it says.
For simplicity consider split ring. So we want a list of heads that are outstanding. Fair enough. Now device finishes a head. What now? I needs to drop head from the list. But list is unidirectional (just next, no prev). So how can you drop an entry from the middle?
Quoted 9 lines
Quoted 6 lines
The
process_headis only used when slave crash between increasing the idx value of used ring and updatingused_idx. We use it to find the in-progress DescStateSplit entries before the crash and complete them when reconnecting. Make sure guest and slave have the same view for inflight I/Os.But I don't understand how does the described process help do it?
For example, we need to submit descriptors A, B, C to driver in a batch.
Firstly, we will link those descriptors like:
process_head->A->B->C(A)Then, we need to update idx value of used vring to mark those descriptors as used:
_vring.used->idx+= 3 (B)At last, clear the inflight field of those descriptors and update
used_idxfield:A.inflight = 0; B.inflight = 0; C.inflight = 0; (C)
used_idx=_vring.used->idx; (D)After (B), guest can consume the descriptors A,B,C. So we must make sure the inflight field of A,B,C is cleared when reconnecting to avoid re-submitting used descriptor. If slave crash during (C), the inflight field of A,B,C may be incorrect. To detect that case, we can see whether
used_idxmatches_vring.used->idx. And throughprocess_head, we can get the in-progress descriptors A,B,C and clear their inflight field again when reconnecting.Quoted 9 lines
Quoted 4 lines
In other case, the inflight field is enough to track inflight I/O. When reconnecting, we go through all DescStateSplit entries and re-submit the entry whose inflight field is equal to 1.
What I don't understand is how do we know the order in which they have to be resubmitted. Reordering operations would be a big problem, won't it?
In previous patch, I record
avail_idxfor each DescStateSplit entry to preserve the order. Is it useful to fix this?Quoted 3 lines
Let's say I fetch descriptors A, B, C and start processing. how does memory look?
Quoted 7 lines
A.inflight = 1, C.inflight = 1, B.inflight = 1
Quoted 3 lines
Now I finished B and marked it used. How does memory look?
A.inflight = 1, C.inflight = 1, B.inflight = 0,
process_head= B
OK. And we have
process_head->B->process_head
?
Now if there is a reconnect, I want to submit A and then C, correct? How do I know that from this picture? How do I know to start with A? It's not on the list anymore...
Quoted 11 lines
Quoted 5 lines
I also wonder how do you address a crash between marking descriptor used and clearing inflight. Will you redo the descriptor? Is it always safe? What if it's a write?
It's safe. We can get the in-progess descriptors through
process_headand clear their inflight field when reconnecting.Thanks,
Yongji
Re: [Qemu-devel] [PATCH v6 1/7] vhost-user: Support transferring inflight buffer between qemu and backend
Quoted 115 lines · Michael S. Tsirkin
Quoted 103 lines · Yongji Xie
Quoted 49 lines · Michael S. Tsirkin
Quoted 47 lines · Yongji Xie
Quoted 46 lines
Quoted 28 lines
docs/interop/vhost-user.txt +28
-0+ +To track inflight I/O, the queue region should be processed as follows: + +When receiving available buffers from the driver: + + 1. Get the next available head-descriptor index from available ring, i + + 2. Set desc[i].inflight to 1 + +When supplying used buffers to the driver: + + 1. Get corresponding used head-descriptor index, i + + 2. Set desc[i].next to process_head + + 3. Set process_head to i + + 4. Steps 1,2,3 may be performed repeatedly if batching is possible + + 5. Increase the idx value of used ring by the size of the batch + + 6. Set the inflight field of each DescStateSplit entry in the batch to 0 + + 7. Set used_idx to the idx value of used ring + +When reconnecting: + + 1. If the value of used_idx does not match the idx value of used ring,docs/interop/vhost-user.txt If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated, · line 493
Quoted 10 lines
docs/interop/vhost-user.txt +10
-0+ + (a) Subtract the value of used_idx from the idx value of used ring to get + the number of in-progress DescStateSplit entries + + (b) Set the inflight field of the in-progress DescStateSplit entries which + start from process_head to 0 + + (c) Set used_idx to the idx value of used ring + + 2. Resubmit each inflight DescStateSplit entryI re-read a couple of time and I still don't understand what it says.
For simplicity consider split ring. So we want a list of heads that are outstanding. Fair enough. Now device finishes a head. What now? I needs to drop head from the list. But list is unidirectional (just next, no prev). So how can you drop an entry from the middle?
Quoted 9 lines
Quoted 6 lines
The
process_headis only used when slave crash between increasing the idx value of used ring and updatingused_idx. We use it to find the in-progress DescStateSplit entries before the crash and complete them when reconnecting. Make sure guest and slave have the same view for inflight I/Os.But I don't understand how does the described process help do it?
For example, we need to submit descriptors A, B, C to driver in a batch.
Firstly, we will link those descriptors like:
process_head->A->B->C(A)Then, we need to update idx value of used vring to mark those descriptors as used:
_vring.used->idx+= 3 (B)At last, clear the inflight field of those descriptors and update
used_idxfield:A.inflight = 0; B.inflight = 0; C.inflight = 0; (C)
used_idx=_vring.used->idx; (D)After (B), guest can consume the descriptors A,B,C. So we must make sure the inflight field of A,B,C is cleared when reconnecting to avoid re-submitting used descriptor. If slave crash during (C), the inflight field of A,B,C may be incorrect. To detect that case, we can see whether
used_idxmatches_vring.used->idx. And throughprocess_head, we can get the in-progress descriptors A,B,C and clear their inflight field again when reconnecting.Quoted 9 lines
Quoted 4 lines
In other case, the inflight field is enough to track inflight I/O. When reconnecting, we go through all DescStateSplit entries and re-submit the entry whose inflight field is equal to 1.
What I don't understand is how do we know the order in which they have to be resubmitted. Reordering operations would be a big problem, won't it?
In previous patch, I record
avail_idxfor each DescStateSplit entry to preserve the order. Is it useful to fix this?Quoted 3 lines
Let's say I fetch descriptors A, B, C and start processing. how does memory look?
Quoted 7 lines
A.inflight = 1, C.inflight = 1, B.inflight = 1
Quoted 3 lines
Now I finished B and marked it used. How does memory look?
A.inflight = 1, C.inflight = 1, B.inflight = 0,
process_head= BOK. And we have
Quoted 8 lines
process_head->B->process_head?
Now if there is a reconnect, I want to submit A and then C, correct? How do I know that from this picture? How do I know to start with A? It's not on the list anymore...
We can go through all DescStateSplit entries (track all descriptors in Descriptor Table), then we can find A and C are inflight entry by its inflight field. And if we want to resubmit them in order (submit A and then C), we need to introduce a timestamp for each DescStateSplit entry to preserve the order when we fetch them from driver. Something like:
When receiving available buffers from the driver:
1. Get the next available head-descriptor index from available ring, i
2. desc[i].timestamp = avail_idx++;
3. Set desc[i].inflight to 1
Thanks,
Yongji
Re: [Qemu-devel] [PATCH v6 1/7] vhost-user: Support transferring inflight buffer between qemu and backend
Quoted 134 lines · Yongji Xie
Quoted 115 lines · Michael S. Tsirkin
Quoted 103 lines · Yongji Xie
Quoted 49 lines · Michael S. Tsirkin
Quoted 47 lines · Yongji Xie
Quoted 46 lines
Quoted 28 lines
(quoted diff) +28
-0+ +To track inflight I/O, the queue region should be processed as follows: + +When receiving available buffers from the driver: + + 1. Get the next available head-descriptor index from available ring, i + + 2. Set desc[i].inflight to 1 + +When supplying used buffers to the driver: + + 1. Get corresponding used head-descriptor index, i + + 2. Set desc[i].next to process_head + + 3. Set process_head to i + + 4. Steps 1,2,3 may be performed repeatedly if batching is possible + + 5. Increase the idx value of used ring by the size of the batch + + 6. Set the inflight field of each DescStateSplit entry in the batch to 0 + + 7. Set used_idx to the idx value of used ring + +When reconnecting: + + 1. If the value of used_idx does not match the idx value of used ring,Review
Quoted 10 lines
(quoted diff) +10
-0+ + (a) Subtract the value of used_idx from the idx value of used ring to get + the number of in-progress DescStateSplit entries + + (b) Set the inflight field of the in-progress DescStateSplit entries which + start from process_head to 0 + + (c) Set used_idx to the idx value of used ring + + 2. Resubmit each inflight DescStateSplit entryI re-read a couple of time and I still don't understand what it says.
For simplicity consider split ring. So we want a list of heads that are outstanding. Fair enough. Now device finishes a head. What now? I needs to drop head from the list. But list is unidirectional (just next, no prev). So how can you drop an entry from the middle?
Quoted 9 lines
Quoted 6 lines
The
process_headis only used when slave crash between increasing the idx value of used ring and updatingused_idx. We use it to find the in-progress DescStateSplit entries before the crash and complete them when reconnecting. Make sure guest and slave have the same view for inflight I/Os.But I don't understand how does the described process help do it?
For example, we need to submit descriptors A, B, C to driver in a batch.
Firstly, we will link those descriptors like:
process_head->A->B->C(A)Then, we need to update idx value of used vring to mark those descriptors as used:
_vring.used->idx+= 3 (B)At last, clear the inflight field of those descriptors and update
used_idxfield:A.inflight = 0; B.inflight = 0; C.inflight = 0; (C)
used_idx=_vring.used->idx; (D)After (B), guest can consume the descriptors A,B,C. So we must make sure the inflight field of A,B,C is cleared when reconnecting to avoid re-submitting used descriptor. If slave crash during (C), the inflight field of A,B,C may be incorrect. To detect that case, we can see whether
used_idxmatches_vring.used->idx. And throughprocess_head, we can get the in-progress descriptors A,B,C and clear their inflight field again when reconnecting.Quoted 9 lines
Quoted 4 lines
In other case, the inflight field is enough to track inflight I/O. When reconnecting, we go through all DescStateSplit entries and re-submit the entry whose inflight field is equal to 1.
What I don't understand is how do we know the order in which they have to be resubmitted. Reordering operations would be a big problem, won't it?
In previous patch, I record
avail_idxfor each DescStateSplit entry to preserve the order. Is it useful to fix this?Quoted 3 lines
Let's say I fetch descriptors A, B, C and start processing. how does memory look?
Quoted 7 lines
A.inflight = 1, C.inflight = 1, B.inflight = 1
Quoted 3 lines
Now I finished B and marked it used. How does memory look?
A.inflight = 1, C.inflight = 1, B.inflight = 0,
process_head= BOK. And we have
Quoted 8 lines
process_head->B->process_head?
Now if there is a reconnect, I want to submit A and then C, correct? How do I know that from this picture? How do I know to start with A? It's not on the list anymore...
We can go through all DescStateSplit entries (track all descriptors in Descriptor Table), then we can find A and C are inflight entry by its inflight field. And if we want to resubmit them in order (submit A and then C), we need to introduce a timestamp for each DescStateSplit entry to preserve the order when we fetch them from driver. Something like:
When receiving available buffers from the driver:
Quoted 8 lines
1. Get the next available head-descriptor index from available ring, i
2. desc[i].timestamp = avail_idx++;
3. Set desc[i].inflight to 1
Thanks,
Yongji
OK I guess a 64 bit counter would be fine for that.
In order seems critical for storage right? Reordering write would seem to lead to data corruption.
But now I don't understand what does the next field do. So it so you can maintain a freelist within a statically allocated array?
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH v6 1/7] vhost-user: Support transferring inflight buffer between qemu and backend
Quoted 142 lines · Michael S. Tsirkin
Quoted 140 lines · Yongji Xie
Quoted 115 lines · Michael S. Tsirkin
Quoted 103 lines · Yongji Xie
Quoted 49 lines · Michael S. Tsirkin
Quoted 47 lines · Yongji Xie
Quoted 46 lines
Quoted 28 lines
(quoted diff) +28
-0+ +To track inflight I/O, the queue region should be processed as follows: + +When receiving available buffers from the driver: + + 1. Get the next available head-descriptor index from available ring, i + + 2. Set desc[i].inflight to 1 + +When supplying used buffers to the driver: + + 1. Get corresponding used head-descriptor index, i + + 2. Set desc[i].next to process_head + + 3. Set process_head to i + + 4. Steps 1,2,3 may be performed repeatedly if batching is possible + + 5. Increase the idx value of used ring by the size of the batch + + 6. Set the inflight field of each DescStateSplit entry in the batch to 0 + + 7. Set used_idx to the idx value of used ring + +When reconnecting: + + 1. If the value of used_idx does not match the idx value of used ring,Review
Quoted 10 lines
(quoted diff) +10
-0+ + (a) Subtract the value of used_idx from the idx value of used ring to get + the number of in-progress DescStateSplit entries + + (b) Set the inflight field of the in-progress DescStateSplit entries which + start from process_head to 0 + + (c) Set used_idx to the idx value of used ring + + 2. Resubmit each inflight DescStateSplit entryI re-read a couple of time and I still don't understand what it says.
For simplicity consider split ring. So we want a list of heads that are outstanding. Fair enough. Now device finishes a head. What now? I needs to drop head from the list. But list is unidirectional (just next, no prev). So how can you drop an entry from the middle?
Quoted 9 lines
Quoted 6 lines
The
process_headis only used when slave crash between increasing the idx value of used ring and updatingused_idx. We use it to find the in-progress DescStateSplit entries before the crash and complete them when reconnecting. Make sure guest and slave have the same view for inflight I/Os.But I don't understand how does the described process help do it?
For example, we need to submit descriptors A, B, C to driver in a batch.
Firstly, we will link those descriptors like:
process_head->A->B->C(A)Then, we need to update idx value of used vring to mark those descriptors as used:
_vring.used->idx+= 3 (B)At last, clear the inflight field of those descriptors and update
used_idxfield:A.inflight = 0; B.inflight = 0; C.inflight = 0; (C)
used_idx=_vring.used->idx; (D)After (B), guest can consume the descriptors A,B,C. So we must make sure the inflight field of A,B,C is cleared when reconnecting to avoid re-submitting used descriptor. If slave crash during (C), the inflight field of A,B,C may be incorrect. To detect that case, we can see whether
used_idxmatches_vring.used->idx. And throughprocess_head, we can get the in-progress descriptors A,B,C and clear their inflight field again when reconnecting.Quoted 9 lines
Quoted 4 lines
In other case, the inflight field is enough to track inflight I/O. When reconnecting, we go through all DescStateSplit entries and re-submit the entry whose inflight field is equal to 1.
What I don't understand is how do we know the order in which they have to be resubmitted. Reordering operations would be a big problem, won't it?
In previous patch, I record
avail_idxfor each DescStateSplit entry to preserve the order. Is it useful to fix this?Quoted 3 lines
Let's say I fetch descriptors A, B, C and start processing. how does memory look?
Quoted 7 lines
A.inflight = 1, C.inflight = 1, B.inflight = 1
Quoted 3 lines
Now I finished B and marked it used. How does memory look?
A.inflight = 1, C.inflight = 1, B.inflight = 0,
process_head= BOK. And we have
Quoted 8 lines
process_head->B->process_head?
Now if there is a reconnect, I want to submit A and then C, correct? How do I know that from this picture? How do I know to start with A? It's not on the list anymore...
We can go through all DescStateSplit entries (track all descriptors in Descriptor Table), then we can find A and C are inflight entry by its inflight field. And if we want to resubmit them in order (submit A and then C), we need to introduce a timestamp for each DescStateSplit entry to preserve the order when we fetch them from driver. Something like:
When receiving available buffers from the driver:
1. Get the next available head-descriptor index from available ring, i
2. desc[i].timestamp = avail_idx++;
3. Set desc[i].inflight to 1
Quoted 8 lines
Quoted 2 lines
Thanks,
YongjiOK I guess a 64 bit counter would be fine for that.
In order seems critical for storage right? Reordering write would seem to lead to data corruption.
Actually I'm not sure. If we care about the order, we should not do access to one block until another access to the same block is completed?
Quoted 4 lines
But now I don't understand what does the next field do. So it so you can maintain a freelist within a statically allocated array?
Yes, we can use it to maintain a list. The head of the list is process_head. This list is only used when we want to submit descriptors in a batch. All descriptors in this batch are linked to the list. Then if we crash between marking those descriptors used and clearing their inflight field. We need to find those in-progress descriptors. The list will be helpful to achieve that. If no batch for submitting, the next field can be removed.
Thanks,
Yongji
PATCH v6 2/7 libvhost-user: Remove unnecessary FD flag check for event file descriptors
In reply to [email protected]From: Xie Yongji <[email protected]>
The vu_check_queue_msg_file() has checked the FD flag. So let's delete the redundant check after it.
--- contrib/libvhost-user/libvhost-user.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
contrib/libvhost-user/libvhost-user.c +4 -10
@@ -907,10 +907,8 @@ vu_set_vring_kick_exec(VuDev *dev, VhostUserMsg *vmsg) dev->vq[index].kick_fd =-1 ; } -if (!(vmsg->payload.u64 &VHOST_USER_VRING_NOFD_MASK )) { - dev->vq[index].kick_fd = vmsg->fds[0 ]; -DPRINT ("Got kick_fd: %d for vq: %d\n" , vmsg->fds[0 ], index); - } + dev->vq[index].kick_fd = vmsg->fds[0 ]; +DPRINT ("Got kick_fd: %d for vq: %d\n" , vmsg->fds[0 ], index); dev->vq[index].started = true;if (dev->iface->queue_set_started) {
@@ -995,9 +993,7 @@ vu_set_vring_call_exec(VuDev *dev, VhostUserMsg *vmsg) dev->vq[index].call_fd =-1 ; } -if (!(vmsg->payload.u64 &VHOST_USER_VRING_NOFD_MASK )) { - dev->vq[index].call_fd = vmsg->fds[0 ]; - } + dev->vq[index].call_fd = vmsg->fds[0 ];DPRINT ("Got call_fd: %d for vq: %d\n" , vmsg->fds[0 ], index);
@@ -1020,9 +1016,7 @@ vu_set_vring_err_exec(VuDev *dev, VhostUserMsg *vmsg) dev->vq[index].err_fd =-1 ; } -if (!(vmsg->payload.u64 &VHOST_USER_VRING_NOFD_MASK )) { - dev->vq[index].err_fd = vmsg->fds[0 ]; - } + dev->vq[index].err_fd = vmsg->fds[0 ];return false; }
Signature · 1 line
2.17.1
PATCH v6 3/7 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
@@ -1847,49 +1847,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" );
@@ -1941,12 +1912,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]; }
@@ -1954,6 +1926,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
PATCH v6 4/7 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 | 300 ++++++++++++++++++++++++-- contrib/libvhost-user/libvhost-user.h | 58 +++++ 3 files changed, 339 insertions(+), 21 deletions(-)
Makefile +1 -1
@@ -477,7 +477,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 +280 -20
400 lines not on this page · raw message
contrib/libvhost-user/libvhost-user.h +58 -0
102 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v6 5/7 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 | 28 ++++++++++++++++++++++++++++ include/hw/virtio/vhost-user-blk.h | 1 + 2 files changed, 29 insertions(+)
hw/block/vhost-user-blk.c +28 -0
@@ -128,6 +128,21 @@ static void vhost_user_blk_start(VirtIODevice *vdev) } s->dev.acked_features = vdev->guest_features; + +if (!s->inflight->addr) { + ret =vhost_dev_get_inflight (&s->dev, s->queue_size, s->inflight); +if (ret <0 ) { +error_report ("Error get inflight: %d" , -ret); + goto err_guest_notifiers; + } + } + + 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);
@@ -249,6 +264,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_free_inflight (s->inflight); +} +static void vhost_user_blk_device_realize (DeviceState *dev,Error **errp) {VirtIODevice *vdev =VIRTIO_DEVICE (dev);
@@ -289,6 +311,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 ;
@@ -321,6 +345,7 @@ vhost_err:vhost_dev_cleanup (&s->dev); virtio_err:g_free (vqs); +g_free (s->inflight);virtio_cleanup (vdev);vhost_user_cleanup (user);
@@ -336,7 +361,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) {
@@ -386,6 +413,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
@@ -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
PATCH v6 6/7 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 | 205 +++++++++++++++++++++++------ include/hw/virtio/vhost-user-blk.h | 4 + 2 files changed, 167 insertions(+), 42 deletions(-)
hw/block/vhost-user-blk.c +163 -42
@@ -103,7 +103,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)));
@@ -112,13 +112,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);
@@ -157,12 +157,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)
@@ -181,7 +182,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);
@@ -191,21 +191,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,
@@ -237,13 +259,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 ; }
@@ -251,7 +282,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++) {
@@ -271,13 +308,106 @@ static void vhost_user_blk_reset(VirtIODevice *vdev)vhost_dev_free_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" );
@@ -312,27 +442,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) {
@@ -340,29 +471,19 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) }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
@@ -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
PATCH v6 7/7 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
@@ -398,7 +398,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
Quoted 32 lines · On Mon, Feb 18, 2019 at 06:27:41PM +0800, [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_FDandVHOST_USER_SET_INFLIGHT_FDto support transferring shared buffer between qemu and backend.The patch 2 deletes some redundant check in
contrib/libvhost-user.c.The patch 3,4 are the corresponding libvhost-user patches of patch 1. Make libvhost-user support
VHOST_USER_GET_INFLIGHT_FDandVHOST_USER_SET_INFLIGHT_FD.The patch 5 allows vhost-user-blk to use the two new messages to get/set inflight buffer from/to backend.
The patch 6 supports vhost-user-blk to reconnect backend when connection closed.
The patch 7 introduces
VHOST_USER_PROTOCOL_F_SLAVE_SHMFDto vhost-user-blk backend which is used to tell qemu that we support reconnecting now.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 \
Quoted 5 lines
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.
Sorry is [email protected] also an address that belongs to Xie Yongji?
If not we need a signed off by from that address'
owner as well.
Thanks!
Quoted 62 lines
V5 to V6:
- Document the layout in inflight buffer for packed virtqueue
- Rework the layout in inflight buffer for split virtqueue
- Remove version field in VhostUserInflight
- Add a patch to remove some redundant check incontrib/libvhost-user.c
- Document more details in vhost-user.txtV4 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.txtV3 to V4:
- Drop messagesVHOST_USER_GET_SHM_SIZEandVHOST_USER_SET_SHM_FD
- Introduce two new messagesVHOST_USER_GET_INFLIGHT_FDandVHOST_USER_SET_INFLIGHT_FD
- Allocate inflight buffer in backend rather than in qemu
- Document a recommended format for inflight bufferV2 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 messageVHOST_USER_SET_VRING_INFLIGHT
- Introduce two new messagesVHOST_USER_GET_SHM_SIZE
andVHOST_USER_SET_SHM_FDXie Yongji (7):
vhost-user: Support transferring inflight buffer between qemu and
backend
libvhost-user: Remove unnecessary FD flag check for event file
descriptors
libvhost-user: Introducevu_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 trackingMakefile | 2 +- contrib/libvhost-user/libvhost-user.c | 400 ++++++++++++++++++++---- contrib/libvhost-user/libvhost-user.h | 58 ++++ contrib/vhost-user-blk/vhost-user-blk.c | 3 +- docs/interop/vhost-user.txt | 264 ++++++++++++++++ hw/block/vhost-user-blk.c | 229 +++++++++++--- hw/virtio/vhost-user.c | 107 +++++++ hw/virtio/vhost.c | 96 ++++++ include/hw/virtio/vhost-backend.h | 10 + include/hw/virtio/vhost-user-blk.h | 5 + include/hw/virtio/vhost.h | 18 ++ 11 files changed, 1084 insertions(+), 108 deletions(-)Signature · 1 line
2.17.1
Quoted 34 lines · Michael S. Tsirkin
Quoted 32 lines · On Mon, Feb 18, 2019 at 06:27:41PM +0800, [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_FDandVHOST_USER_SET_INFLIGHT_FDto support transferring shared buffer between qemu and backend.The patch 2 deletes some redundant check in
contrib/libvhost-user.c.The patch 3,4 are the corresponding libvhost-user patches of patch 1. Make libvhost-user support
VHOST_USER_GET_INFLIGHT_FDandVHOST_USER_SET_INFLIGHT_FD.The patch 5 allows vhost-user-blk to use the two new messages to get/set inflight buffer from/to backend.
The patch 6 supports vhost-user-blk to reconnect backend when connection closed.
The patch 7 introduces
VHOST_USER_PROTOCOL_F_SLAVE_SHMFDto vhost-user-blk backend which is used to tell qemu that we support reconnecting now.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 \
Quoted 9 lines
Quoted 5 lines
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.
Sorry is [email protected] also an address that belongs to Xie Yongji?
Yes, that's also my email address.
Thanks,
Yongji