From 5e8a3a77b69b1703068678a15e6f101438edba4f Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Tue, 7 Jan 2020 23:24:42 +0800 Subject: [PATCH] vhost: make SPDK internal vhost library can work compatible with live recovery We will not enable the live recovery feature for SPDK internal vhost library, so we unmask the protocol flag for internal vhost library. For the purpose to make it can be compiled with latest DPDK version, some mandatory APIs are required, so add them here. Change-Id: I34fab7ed90c86a0fb612852a47f6cadeb8a072f3 Signed-off-by: Changpeng Liu Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/482069 Community-CI: SPDK CI Jenkins Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- lib/rte_vhost/rte_vhost.h | 154 +++++++++++++++++++++++++++++++++++++- lib/rte_vhost/vhost.c | 28 +++++++ lib/vhost/vhost_blk.c | 4 + 3 files changed, 183 insertions(+), 3 deletions(-) diff --git a/lib/rte_vhost/rte_vhost.h b/lib/rte_vhost/rte_vhost.h index 05b69e17f..b1b7f2cd8 100644 --- a/lib/rte_vhost/rte_vhost.h +++ b/lib/rte_vhost/rte_vhost.h @@ -74,10 +74,50 @@ struct rte_vhost_memory { struct rte_vhost_mem_region regions[0]; }; +struct rte_vhost_inflight_desc_split { + uint8_t inflight; + uint8_t padding[5]; + uint16_t next; + uint64_t counter; +}; + +struct rte_vhost_inflight_info_split { + uint64_t features; + uint16_t version; + uint16_t desc_num; + uint16_t last_inflight_io; + uint16_t used_idx; + struct rte_vhost_inflight_desc_split desc[0]; +}; + +struct rte_vhost_resubmit_desc { + uint16_t index; + uint64_t counter; +}; + +struct rte_vhost_resubmit_info { + struct rte_vhost_resubmit_desc *resubmit_list; + uint16_t resubmit_num; +}; + +struct rte_vhost_ring_inflight { + struct rte_vhost_inflight_info_split *inflight_split; + struct rte_vhost_resubmit_info *resubmit_inflight; +}; + struct rte_vhost_vring { - struct vring_desc *desc; - struct vring_avail *avail; - struct vring_used *used; + union { + struct vring_desc *desc; + struct vring_packed_desc *desc_packed; + }; + union { + struct vring_avail *avail; + struct vring_packed_desc_event *driver_event; + }; + union { + struct vring_used *used; + struct vring_packed_desc_event *device_event; + }; uint64_t log_guest_addr; int callfd; @@ -484,4 +524,112 @@ int rte_vhost_get_vring_base(int vid, uint16_t queue_id, */ int rte_vhost_vring_call(int vid, uint16_t vring_idx); +/** + * Get guest inflight vring info, including inflight ring and resubmit list. + * + * @param vid + * vhost device ID + * @param vring_idx + * vring index + * @param vring + * the structure to hold the requested inflight vring info + * @return + * 0 on success, -1 on failure + */ +__rte_experimental +int +rte_vhost_get_vhost_ring_inflight(int vid, uint16_t vring_idx, + struct rte_vhost_ring_inflight *vring); + +/** + * Set split inflight descriptor. + * + * This function save descriptors that has been comsumed in available + * ring + * + * @param vid + * vhost device ID + * @param vring_idx + * vring index + * @param idx + * inflight entry index + * @return + * 0 on success, -1 on failure + */ +__rte_experimental +int +rte_vhost_set_inflight_desc_split(int vid, uint16_t vring_idx, + uint16_t idx); + +/** + * Save the head of list that the last batch of used descriptors. + * + * @param vid + * vhost device ID + * @param vring_idx + * vring index + * @param idx + * descriptor entry index + * @return + * 0 on success, -1 on failure + */ +__rte_experimental +int +rte_vhost_set_last_inflight_io_split(int vid, + uint16_t vring_idx, uint16_t idx); + +/** + * Clear the split inflight status. + * + * @param vid + * vhost device ID + * @param vring_idx + * vring index + * @param last_used_idx + * last used idx of used ring + * @param idx + * inflight entry index + * @return + * 0 on success, -1 on failure + */ +__rte_experimental +int +rte_vhost_clr_inflight_desc_split(int vid, uint16_t vring_idx, + uint16_t last_used_idx, uint16_t idx); + +/** + * Save the head of list that the last batch of used descriptors. + * + * @param vid + * vhost device ID + * @param vring_idx + * vring index + * @param idx + * descriptor entry index + * @return + * 0 on success, -1 on failure + */ +__rte_experimental +int +rte_vhost_set_last_inflight_io_split(int vid, + uint16_t vring_idx, uint16_t idx); + +/** + * Clear the split inflight status. + * + * @param vid + * vhost device ID + * @param vring_idx + * vring index + * @param last_used_idx + * last used idx of used ring + * @param idx + * inflight entry index + * @return + * 0 on success, -1 on failure + */ +__rte_experimental +int +rte_vhost_clr_inflight_desc_split(int vid, uint16_t vring_idx, + uint16_t last_used_idx, uint16_t idx); #endif /* _RTE_VHOST_H_ */ diff --git a/lib/rte_vhost/vhost.c b/lib/rte_vhost/vhost.c index d9c119f99..8e875c585 100644 --- a/lib/rte_vhost/vhost.c +++ b/lib/rte_vhost/vhost.c @@ -535,3 +535,31 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx) return -1; } + +int +rte_vhost_set_last_inflight_io_split(int vid, uint16_t vring_idx, + uint16_t idx) +{ + return 0; +} + +int +rte_vhost_clr_inflight_desc_split(int vid, uint16_t vring_idx, + uint16_t last_used_idx, uint16_t idx) +{ + return 0; +} + +int +rte_vhost_set_inflight_desc_split(int vid, uint16_t vring_idx, + uint16_t idx) +{ + return 0; +} + +int +rte_vhost_get_vhost_ring_inflight(int vid, uint16_t vring_idx, + struct rte_vhost_ring_inflight *vring) +{ + return 0; +} diff --git a/lib/vhost/vhost_blk.c b/lib/vhost/vhost_blk.c index 71b3e1c84..fe3dfaf5f 100644 --- a/lib/vhost/vhost_blk.c +++ b/lib/vhost/vhost_blk.c @@ -59,8 +59,12 @@ (1ULL << VIRTIO_BLK_F_BARRIER) | (1ULL << VIRTIO_BLK_F_SCSI)) /* Vhost-blk support protocol features */ +#ifndef SPDK_CONFIG_VHOST_INTERNAL_LIB #define SPDK_VHOST_BLK_PROTOCOL_FEATURES ((1ULL << VHOST_USER_PROTOCOL_F_CONFIG) | \ (1ULL << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) +#else +#define SPDK_VHOST_BLK_PROTOCOL_FEATURES (1ULL << VHOST_USER_PROTOCOL_F_CONFIG) +#endif struct spdk_vhost_blk_task { struct spdk_bdev_io *bdev_io;