From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by dpdk.org (Postfix) with ESMTP id 1E3D81B57D for ; Thu, 25 Apr 2019 13:10:59 +0200 (CEST) Received: by mail-pf1-f195.google.com with SMTP id 188so10998507pfd.8 for ; Thu, 25 Apr 2019 04:10:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ivlnbkURQhMCM3dO/y8Kuw8/yN+eMsHx6jzxz0Tv9CI=; b=fUAyuYMVZ1wnqqhYwbR+82xCZjIPW5STBsNJnp+wTvSORxnZYp2gjUDtdpbgMy4mdJ /8J9ig/KNUOL3PFrtF3yyYC508eaWOwi4W6Xc9HOi+fim6h968oY9By9mvnW3TQHXKI+ v/8XzzjDXMqO2fCwQnC7dObnBLNfX5StCUiBUtxzvu8amXDuqF+PvuApYCiXYawOHcVL /SF2pBQO+AX/CWORAgd0ja+9pRdr5uV4cKIEN5fkj5DdoiSEZU/iKRKA9GV9oSZJe4Ip jGYTQS7PNXm1PSRFXiJKC9ENSV7ifEZUSbLndkcD4Oj4wZcHlhEBD7pND/7d5OJoEE64 NLYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ivlnbkURQhMCM3dO/y8Kuw8/yN+eMsHx6jzxz0Tv9CI=; b=QYK7xa9pT8pvhvf6dQE11W3P16kKdD8hNd3ALAd83uFWcXOVj9PSH+K1sHdvagHMvW D1Axhlqa7L32gpxvVKJYglKUinesfgUmM6mBz3e9mkICC7218NKgjpee+7Bh1v/WJNqZ J8YoB0NS7oh2FoPhcyvyhoexmSKaCFR2X5e7FNsm37fHDyAm5Ogw8DaCaHmAS42f5l1a UNbUgI89MVRDUS5pDkah/mFR7Uth10HMBaei2wZcajzwD9dbAp2kSvmc5hDp9VXVse1E Z600lOkVjAn77QmvYdGow2n9t8HLk3YBsgWFUxodMMeX7xgiiTcczipie9YRc7Yu4+6I iyEw== X-Gm-Message-State: APjAAAX+AvzOW1qTMk9r7hUqIAGtov8TrZOeisHzuLERq7Nm2UiXQ8gJ 2uUcKZxT/heGFpUtbO4BK4U= X-Google-Smtp-Source: APXvYqzy9p8uII/secV5TSv82lx90SUUEZSKmx68jhIpokRgrDMG6mSfQJIJBTS/D6euQ3e3qlSLbA== X-Received: by 2002:a63:d349:: with SMTP id u9mr34626611pgi.83.1556190657905; Thu, 25 Apr 2019 04:10:57 -0700 (PDT) Received: from host.localdomain.localdomain (144.34.199.178.16clouds.com. [144.34.199.178]) by smtp.gmail.com with ESMTPSA id f8sm1043311pfk.88.2019.04.25.04.10.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Apr 2019 04:10:57 -0700 (PDT) From: Li Lin To: tiwei.bie@intel.com, maxime.coquelin@redhat.com, zhihong.wang@intel.com Cc: dev@dpdk.org, dariusz.stojaczyk@intel.com, changpeng.liu@intel.com, james.r.harris@intel.com, lilin24 , Ni Xun , Zhang Yu Date: Thu, 25 Apr 2019 07:10:33 -0400 Message-Id: <1556190633-8099-1-git-send-email-chuckylinchuckylin@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1556179018-7865-1-git-send-email-chuckylinchuckylin@gmail.com> References: <1556179018-7865-1-git-send-email-chuckylinchuckylin@gmail.com> Subject: [dpdk-dev] [PATCH v2] vhost: support inflight share memory protocol feature X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Apr 2019 11:10:59 -0000 From: lilin24 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 process inflight I/O when backend reconnect. Signed-off-by: lilin24 Signed-off-by: Ni Xun Signed-off-by: Zhang Yu --- lib/librte_vhost/rte_vhost.h | 54 +++++++++ lib/librte_vhost/vhost.c | 45 ++++++++ lib/librte_vhost/vhost.h | 12 ++ lib/librte_vhost/vhost_user.c | 249 ++++++++++++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost_user.h | 16 ++- 5 files changed, 374 insertions(+), 2 deletions(-) diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h index d2c0c93..73acc79 100644 --- a/lib/librte_vhost/rte_vhost.h +++ b/lib/librte_vhost/rte_vhost.h @@ -71,6 +71,10 @@ #define VHOST_USER_PROTOCOL_F_HOST_NOTIFIER 11 #endif +#ifndef VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD +#define VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD 12 +#endif + /** Indicate whether protocol features negotiation is supported. */ #ifndef VHOST_USER_F_PROTOCOL_FEATURES #define VHOST_USER_F_PROTOCOL_FEATURES 30 @@ -98,12 +102,27 @@ struct rte_vhost_memory { struct rte_vhost_mem_region regions[]; }; +typedef struct VhostUserInflightEntry { + uint8_t inflight; +} VhostUserInflightEntry; + +typedef struct VhostInflightInfo { + uint16_t version; + uint16_t last_inflight_io; + uint16_t used_idx; + VhostUserInflightEntry desc[0]; +} VhostInflightInfo; + struct rte_vhost_vring { struct vring_desc *desc; struct vring_avail *avail; struct vring_used *used; uint64_t log_guest_addr; + VhostInflightInfo *inflight; + uint16_t *inflight_reqs; + uint16_t inflight_cnt; + /** Deprecated, use rte_vhost_vring_call() instead. */ int callfd; @@ -632,6 +651,41 @@ int rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx, int rte_vhost_vring_call(int vid, uint16_t vring_idx); /** + * set inflight flag for a entry. + * + * @param vring + * the structure to hold the requested vring info + * @param idx + * inflight entry index + */ +void rte_vhost_set_inflight(struct rte_vhost_vring *vring, + uint16_t idx); + +/** + * step 1 of clear inflight flag for a entry. + * + * @param vring + * the structure to hold the requested vring info + * @param idx + * inflight entry index + */ +void rte_vhost_clear_inflight_begin(struct rte_vhost_vring *vring, + uint16_t idx); + +/** + * step 2 of clear inflight flag for a entry. + * + * @param vring + * the structure to hold the requested vring info + * @param last_used_idx + * next free used_idx + * @param idx + * inflight entry index + */ +void rte_vhost_clear_inflight_end(struct rte_vhost_vring *vring, + uint16_t last_used_idx, uint16_t idx); + +/** * Get vhost RX queue avail count. * * @param vid diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 163f459..ba5537c 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -76,6 +76,8 @@ close(vq->callfd); if (vq->kickfd >= 0) close(vq->kickfd); + if (vq->inflight) + vq->inflight = NULL; } /* @@ -589,6 +591,14 @@ vring->kickfd = vq->kickfd; vring->size = vq->size; + vring->inflight = vq->inflight; + + vring->inflight_reqs = vq->inflight_reqs; + vq->inflight_reqs = NULL; + + vring->inflight_cnt = vq->inflight_cnt; + vq->inflight_cnt = 0; + return 0; } @@ -617,6 +627,41 @@ return 0; } +void +rte_vhost_set_inflight(struct rte_vhost_vring *vring, uint16_t idx) +{ + VhostInflightInfo *inflight = vring->inflight; + if (unlikely(!inflight)) + return; + inflight->desc[idx].inflight = 1; +} + +void +rte_vhost_clear_inflight_begin(struct rte_vhost_vring *vring, uint16_t idx) +{ + VhostInflightInfo *inflight = vring->inflight; + + if (unlikely(!inflight)) + return; + + inflight->last_inflight_io = idx; +} + +void +rte_vhost_clear_inflight_end(struct rte_vhost_vring *vring, + uint16_t last_used_idx, uint16_t idx) +{ + VhostInflightInfo *inflight = vring->inflight; + + if (unlikely(!inflight)) + return; + + rte_compiler_barrier(); + inflight->desc[idx].inflight = 0; + rte_compiler_barrier(); + inflight->used_idx = last_used_idx; +} + uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id) { diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index e9138df..2ab9d68 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -128,6 +128,11 @@ struct vhost_virtqueue { /* Physical address of used ring, for logging */ uint64_t log_guest_addr; + /* Inflight share memory info */ + VhostInflightInfo *inflight; + uint16_t *inflight_reqs; + uint16_t inflight_cnt; + uint16_t nr_zmbuf; uint16_t zmbuf_size; uint16_t last_zmbuf_idx; @@ -286,6 +291,12 @@ struct guest_page { uint64_t size; }; +typedef struct VuDevInflightInfo { + int fd; + void *addr; + uint64_t size; +} VuDevInflightInfo; + /** * Device structure contains all configuration information relating * to the device. @@ -303,6 +314,7 @@ struct virtio_net { uint32_t nr_vring; int dequeue_zero_copy; struct vhost_virtqueue *virtqueue[VHOST_MAX_QUEUE_PAIRS * 2]; + VuDevInflightInfo inflight_info; #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ) char ifname[IF_NAME_SZ]; uint64_t log_size; diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index c9e29ec..ca937e2 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -31,6 +31,8 @@ #include #include #include +#include +#include #ifdef RTE_LIBRTE_VHOST_NUMA #include #endif @@ -49,6 +51,14 @@ #define VIRTIO_MIN_MTU 68 #define VIRTIO_MAX_MTU 65535 +#define INFLIGHT_ALIGNMENT 64 +#define INFLIGHT_VERSION 0xabcd + +#define CLOEXEC 0x0001U + +#define ALIGN_DOWN(n, m) ((n) / (m) * (m)) +#define ALIGN_UP(n, m) ALIGN_DOWN((n) + (m) - 1, (m)) + static const char *vhost_message_str[VHOST_USER_MAX] = { [VHOST_USER_NONE] = "VHOST_USER_NONE", [VHOST_USER_GET_FEATURES] = "VHOST_USER_GET_FEATURES", @@ -78,6 +88,8 @@ [VHOST_USER_POSTCOPY_ADVISE] = "VHOST_USER_POSTCOPY_ADVISE", [VHOST_USER_POSTCOPY_LISTEN] = "VHOST_USER_POSTCOPY_LISTEN", [VHOST_USER_POSTCOPY_END] = "VHOST_USER_POSTCOPY_END", + [VHOST_USER_GET_INFLIGHT_FD] = "VHOST_USER_GET_INFLIGHT_FD", + [VHOST_USER_SET_INFLIGHT_FD] = "VHOST_USER_SET_INFLIGHT_FD", }; static int send_vhost_reply(int sockfd, struct VhostUserMsg *msg); @@ -160,6 +172,16 @@ dev->log_addr = 0; } + if (dev->inflight_info.addr) { + munmap(dev->inflight_info.addr, dev->inflight_info.size); + dev->inflight_info.addr = NULL; + } + + if (dev->inflight_info.fd > 0) { + close(dev->inflight_info.fd); + dev->inflight_info.fd = -1; + } + if (dev->slave_req_fd >= 0) { close(dev->slave_req_fd); dev->slave_req_fd = -1; @@ -1165,6 +1187,184 @@ return 1; } +static int mem_create(const char *name, unsigned int flags) +{ +#ifdef __NR_memfd_create + return syscall(__NR_memfd_create, name, flags); +#else + return -1; +#endif +} + +void *inflight_mem_alloc(const char *name, size_t size, int *fd) +{ + void *ptr; + int mfd = -1; + char fname[20] = "/tmp/memfd-XXXXXX"; + + *fd = -1; + mfd = mem_create(name, CLOEXEC); + if (mfd != -1) { + if (ftruncate(mfd, size) == -1) { + RTE_LOG(ERR, VHOST_CONFIG, + "ftruncate fail for alloc inflight buffer\n"); + close(mfd); + return NULL; + } + } else { + mfd = mkstemp(fname); + unlink(fname); + + if (mfd == -1) { + RTE_LOG(ERR, VHOST_CONFIG, + "mkstemp fail for alloc inflight buffer\n"); + return NULL; + } + + if (ftruncate(mfd, size) == -1) { + RTE_LOG(ERR, VHOST_CONFIG, + "ftruncate fail for alloc inflight buffer\n"); + close(mfd); + return NULL; + } + } + + ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd, 0); + if (ptr == MAP_FAILED) { + RTE_LOG(ERR, VHOST_CONFIG, + "mmap fail for alloc inflight buffer\n"); + close(mfd); + return NULL; + } + + *fd = mfd; + return ptr; +} + +static uint32_t get_pervq_shm_size(uint16_t queue_size) +{ + return ALIGN_UP(sizeof(VhostUserInflightEntry) * queue_size + + sizeof(uint16_t) * 3, INFLIGHT_ALIGNMENT); +} + +static int +vhost_user_get_inflight_fd(struct virtio_net **pdev, VhostUserMsg *msg, + int main_fd __rte_unused) +{ + int fd; + uint64_t mmap_size; + void *addr; + uint16_t num_queues, queue_size; + struct virtio_net *dev = *pdev; + + if (msg->size != sizeof(msg->payload.inflight)) { + RTE_LOG(ERR, VHOST_CONFIG, + "Invalid get_inflight_fd message size is %d", + msg->size); + msg->payload.inflight.mmap_size = 0; + return 0; + } + + num_queues = msg->payload.inflight.num_queues; + queue_size = msg->payload.inflight.queue_size; + + RTE_LOG(INFO, VHOST_CONFIG, "get_inflight_fd num_queues: %u\n", + msg->payload.inflight.num_queues); + RTE_LOG(INFO, VHOST_CONFIG, "get_inflight_fd queue_size: %u\n", + msg->payload.inflight.queue_size); + mmap_size = num_queues * get_pervq_shm_size(queue_size); + + addr = inflight_mem_alloc("vhost-inflight", mmap_size, &fd); + if (!addr) { + RTE_LOG(ERR, VHOST_CONFIG, "Failed to alloc vhost inflight area"); + msg->payload.inflight.mmap_size = 0; + return 0; + } + memset(addr, 0, mmap_size); + + dev->inflight_info.addr = addr; + dev->inflight_info.size = msg->payload.inflight.mmap_size = mmap_size; + dev->inflight_info.fd = msg->fds[0] = fd; + msg->payload.inflight.mmap_offset = 0; + msg->fd_num = 1; + + RTE_LOG(INFO, VHOST_CONFIG, + "send inflight mmap_size: %lu\n", + msg->payload.inflight.mmap_size); + RTE_LOG(INFO, VHOST_CONFIG, + "send inflight mmap_offset: %lu\n", + msg->payload.inflight.mmap_offset); + RTE_LOG(INFO, VHOST_CONFIG, + "send inflight fd: %d\n", msg->fds[0]); + + return RTE_VHOST_MSG_RESULT_REPLY; +} + +static int +vhost_user_set_inflight_fd(struct virtio_net **pdev, VhostUserMsg *msg, + int main_fd __rte_unused) +{ + int fd, i; + uint64_t mmap_size, mmap_offset; + uint16_t num_queues, queue_size; + uint32_t pervq_inflight_size; + void *rc; + struct vhost_virtqueue *vq; + struct virtio_net *dev = *pdev; + + fd = msg->fds[0]; + if (msg->size != sizeof(msg->payload.inflight) || fd < 0) { + RTE_LOG(ERR, VHOST_CONFIG, "Invalid set_inflight_fd message size is %d,fd is %d\n", + msg->size, fd); + return -1; + } + + mmap_size = msg->payload.inflight.mmap_size; + mmap_offset = msg->payload.inflight.mmap_offset; + num_queues = msg->payload.inflight.num_queues; + queue_size = msg->payload.inflight.queue_size; + pervq_inflight_size = get_pervq_shm_size(queue_size); + + RTE_LOG(INFO, VHOST_CONFIG, + "set_inflight_fd mmap_size: %lu\n", mmap_size); + RTE_LOG(INFO, VHOST_CONFIG, + "set_inflight_fd mmap_offset: %lu\n", mmap_offset); + RTE_LOG(INFO, VHOST_CONFIG, + "set_inflight_fd num_queues: %u\n", num_queues); + RTE_LOG(INFO, VHOST_CONFIG, + "set_inflight_fd queue_size: %u\n", queue_size); + RTE_LOG(INFO, VHOST_CONFIG, + "set_inflight_fd fd: %d\n", fd); + RTE_LOG(INFO, VHOST_CONFIG, + "set_inflight_fd pervq_inflight_size: %d\n", + pervq_inflight_size); + + if (dev->inflight_info.addr) + munmap(dev->inflight_info.addr, dev->inflight_info.size); + + rc = mmap(0, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, + fd, mmap_offset); + if (rc == MAP_FAILED) { + RTE_LOG(ERR, VHOST_CONFIG, "failed to mmap share memory.\n"); + return -1; + } + + if (dev->inflight_info.fd) + close(dev->inflight_info.fd); + + dev->inflight_info.fd = fd; + dev->inflight_info.addr = rc; + dev->inflight_info.size = mmap_size; + + for (i = 0; i < num_queues; i++) { + vq = dev->virtqueue[i]; + vq->inflight = (VhostInflightInfo *)rc; + rc = (void *)((char *)rc + pervq_inflight_size); + } + + return RTE_VHOST_MSG_RESULT_OK; +} + static int vhost_user_set_vring_call(struct virtio_net **pdev, struct VhostUserMsg *msg, int main_fd __rte_unused) @@ -1202,6 +1402,47 @@ static int vhost_user_set_vring_err(struct virtio_net **pdev __rte_unused, } static int +vhost_check_queue_inflights(struct vhost_virtqueue *vq) +{ + struct vring_used *used = vq->used; + uint16_t i = 0; + + if ((!vq->inflight)) + return RTE_VHOST_MSG_RESULT_ERR; + + if (!vq->inflight->version) { + vq->inflight->version = INFLIGHT_VERSION; + return RTE_VHOST_MSG_RESULT_OK; + } + + vq->inflight_reqs = calloc(vq->size, sizeof(uint16_t)); + if (!vq->inflight_reqs) { + RTE_LOG(ERR, VHOST_CONFIG, "Failed to allocate memory for inflight reqs.\n"); + return RTE_VHOST_MSG_RESULT_ERR; + } + + if (vq->inflight->used_idx != used->idx) { + vq->inflight->desc[vq->inflight->last_inflight_io].inflight = 0; + rte_compiler_barrier(); + vq->inflight->used_idx = used->idx; + } + + for (i = 0; i < vq->size; i++) { + if (vq->inflight->desc[i].inflight == 1) + vq->inflight_reqs[vq->inflight_cnt++] = i; + } + + if (!vq->inflight_cnt) { + free(vq->inflight_reqs); + vq->inflight_reqs = NULL; + } + + vq->last_avail_idx += vq->inflight_cnt; + + return RTE_VHOST_MSG_RESULT_OK; +} + +static int vhost_user_set_vring_kick(struct virtio_net **pdev, struct VhostUserMsg *msg, int main_fd __rte_unused) { @@ -1242,6 +1483,12 @@ static int vhost_user_set_vring_err(struct virtio_net **pdev __rte_unused, close(vq->kickfd); vq->kickfd = file.fd; + if (vhost_check_queue_inflights(vq)) { + RTE_LOG(ERR, VHOST_CONFIG, + "Failed to inflights for vq: %d\n", file.index); + return RTE_VHOST_MSG_RESULT_ERR; + } + return RTE_VHOST_MSG_RESULT_OK; } @@ -1762,6 +2009,8 @@ typedef int (*vhost_message_handler_t)(struct virtio_net **pdev, [VHOST_USER_POSTCOPY_ADVISE] = vhost_user_set_postcopy_advise, [VHOST_USER_POSTCOPY_LISTEN] = vhost_user_set_postcopy_listen, [VHOST_USER_POSTCOPY_END] = vhost_user_postcopy_end, + [VHOST_USER_GET_INFLIGHT_FD] = vhost_user_get_inflight_fd, + [VHOST_USER_SET_INFLIGHT_FD] = vhost_user_set_inflight_fd, }; diff --git a/lib/librte_vhost/vhost_user.h b/lib/librte_vhost/vhost_user.h index 2a650fe..35f969b 100644 --- a/lib/librte_vhost/vhost_user.h +++ b/lib/librte_vhost/vhost_user.h @@ -23,7 +23,8 @@ (1ULL << VHOST_USER_PROTOCOL_F_CRYPTO_SESSION) | \ (1ULL << VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD) | \ (1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER) | \ - (1ULL << VHOST_USER_PROTOCOL_F_PAGEFAULT)) + (1ULL << VHOST_USER_PROTOCOL_F_PAGEFAULT) | \ + (1ULL << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) typedef enum VhostUserRequest { VHOST_USER_NONE = 0, @@ -54,7 +55,9 @@ VHOST_USER_POSTCOPY_ADVISE = 28, VHOST_USER_POSTCOPY_LISTEN = 29, VHOST_USER_POSTCOPY_END = 30, - VHOST_USER_MAX = 31 + VHOST_USER_GET_INFLIGHT_FD = 31, + VHOST_USER_SET_INFLIGHT_FD = 32, + VHOST_USER_MAX = 33 } VhostUserRequest; typedef enum VhostUserSlaveRequest { @@ -112,6 +115,13 @@ 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 VhostUserMsg { union { uint32_t master; /* a VhostUserRequest value */ @@ -131,6 +141,7 @@ struct vhost_vring_addr addr; VhostUserMemory memory; VhostUserLog log; + VhostUserInflight inflight; struct vhost_iotlb_msg iotlb; VhostUserCryptoSessionParam crypto_session; VhostUserVringArea area; @@ -148,6 +159,7 @@ /* vhost_user.c */ int vhost_user_msg_handler(int vid, int fd); int vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm); +void *inflight_mem_alloc(const char *name, size_t size, int *fd); /* socket.c */ int read_fd_message(int sockfd, char *buf, int buflen, int *fds, int max_fds, -- 1.8.3.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 0B317A05D3 for ; Thu, 25 Apr 2019 13:11:01 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BE5D71B57F; Thu, 25 Apr 2019 13:11:00 +0200 (CEST) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by dpdk.org (Postfix) with ESMTP id 1E3D81B57D for ; Thu, 25 Apr 2019 13:10:59 +0200 (CEST) Received: by mail-pf1-f195.google.com with SMTP id 188so10998507pfd.8 for ; Thu, 25 Apr 2019 04:10:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ivlnbkURQhMCM3dO/y8Kuw8/yN+eMsHx6jzxz0Tv9CI=; b=fUAyuYMVZ1wnqqhYwbR+82xCZjIPW5STBsNJnp+wTvSORxnZYp2gjUDtdpbgMy4mdJ /8J9ig/KNUOL3PFrtF3yyYC508eaWOwi4W6Xc9HOi+fim6h968oY9By9mvnW3TQHXKI+ v/8XzzjDXMqO2fCwQnC7dObnBLNfX5StCUiBUtxzvu8amXDuqF+PvuApYCiXYawOHcVL /SF2pBQO+AX/CWORAgd0ja+9pRdr5uV4cKIEN5fkj5DdoiSEZU/iKRKA9GV9oSZJe4Ip jGYTQS7PNXm1PSRFXiJKC9ENSV7ifEZUSbLndkcD4Oj4wZcHlhEBD7pND/7d5OJoEE64 NLYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ivlnbkURQhMCM3dO/y8Kuw8/yN+eMsHx6jzxz0Tv9CI=; b=QYK7xa9pT8pvhvf6dQE11W3P16kKdD8hNd3ALAd83uFWcXOVj9PSH+K1sHdvagHMvW D1Axhlqa7L32gpxvVKJYglKUinesfgUmM6mBz3e9mkICC7218NKgjpee+7Bh1v/WJNqZ J8YoB0NS7oh2FoPhcyvyhoexmSKaCFR2X5e7FNsm37fHDyAm5Ogw8DaCaHmAS42f5l1a UNbUgI89MVRDUS5pDkah/mFR7Uth10HMBaei2wZcajzwD9dbAp2kSvmc5hDp9VXVse1E Z600lOkVjAn77QmvYdGow2n9t8HLk3YBsgWFUxodMMeX7xgiiTcczipie9YRc7Yu4+6I iyEw== X-Gm-Message-State: APjAAAX+AvzOW1qTMk9r7hUqIAGtov8TrZOeisHzuLERq7Nm2UiXQ8gJ 2uUcKZxT/heGFpUtbO4BK4U= X-Google-Smtp-Source: APXvYqzy9p8uII/secV5TSv82lx90SUUEZSKmx68jhIpokRgrDMG6mSfQJIJBTS/D6euQ3e3qlSLbA== X-Received: by 2002:a63:d349:: with SMTP id u9mr34626611pgi.83.1556190657905; Thu, 25 Apr 2019 04:10:57 -0700 (PDT) Received: from host.localdomain.localdomain (144.34.199.178.16clouds.com. [144.34.199.178]) by smtp.gmail.com with ESMTPSA id f8sm1043311pfk.88.2019.04.25.04.10.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Apr 2019 04:10:57 -0700 (PDT) From: Li Lin To: tiwei.bie@intel.com, maxime.coquelin@redhat.com, zhihong.wang@intel.com Cc: dev@dpdk.org, dariusz.stojaczyk@intel.com, changpeng.liu@intel.com, james.r.harris@intel.com, lilin24 , Ni Xun , Zhang Yu Date: Thu, 25 Apr 2019 07:10:33 -0400 Message-Id: <1556190633-8099-1-git-send-email-chuckylinchuckylin@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1556179018-7865-1-git-send-email-chuckylinchuckylin@gmail.com> References: <1556179018-7865-1-git-send-email-chuckylinchuckylin@gmail.com> Subject: [dpdk-dev] [PATCH v2] vhost: support inflight share memory protocol feature X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Content-Type: text/plain; charset="UTF-8" Message-ID: <20190425111033.FDwvJWVPzyHpip-LucYjG_H0CsXiKAk6mxuWR_-3bY0@z> From: lilin24 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 process inflight I/O when backend reconnect. Signed-off-by: lilin24 Signed-off-by: Ni Xun Signed-off-by: Zhang Yu --- lib/librte_vhost/rte_vhost.h | 54 +++++++++ lib/librte_vhost/vhost.c | 45 ++++++++ lib/librte_vhost/vhost.h | 12 ++ lib/librte_vhost/vhost_user.c | 249 ++++++++++++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost_user.h | 16 ++- 5 files changed, 374 insertions(+), 2 deletions(-) diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h index d2c0c93..73acc79 100644 --- a/lib/librte_vhost/rte_vhost.h +++ b/lib/librte_vhost/rte_vhost.h @@ -71,6 +71,10 @@ #define VHOST_USER_PROTOCOL_F_HOST_NOTIFIER 11 #endif +#ifndef VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD +#define VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD 12 +#endif + /** Indicate whether protocol features negotiation is supported. */ #ifndef VHOST_USER_F_PROTOCOL_FEATURES #define VHOST_USER_F_PROTOCOL_FEATURES 30 @@ -98,12 +102,27 @@ struct rte_vhost_memory { struct rte_vhost_mem_region regions[]; }; +typedef struct VhostUserInflightEntry { + uint8_t inflight; +} VhostUserInflightEntry; + +typedef struct VhostInflightInfo { + uint16_t version; + uint16_t last_inflight_io; + uint16_t used_idx; + VhostUserInflightEntry desc[0]; +} VhostInflightInfo; + struct rte_vhost_vring { struct vring_desc *desc; struct vring_avail *avail; struct vring_used *used; uint64_t log_guest_addr; + VhostInflightInfo *inflight; + uint16_t *inflight_reqs; + uint16_t inflight_cnt; + /** Deprecated, use rte_vhost_vring_call() instead. */ int callfd; @@ -632,6 +651,41 @@ int rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx, int rte_vhost_vring_call(int vid, uint16_t vring_idx); /** + * set inflight flag for a entry. + * + * @param vring + * the structure to hold the requested vring info + * @param idx + * inflight entry index + */ +void rte_vhost_set_inflight(struct rte_vhost_vring *vring, + uint16_t idx); + +/** + * step 1 of clear inflight flag for a entry. + * + * @param vring + * the structure to hold the requested vring info + * @param idx + * inflight entry index + */ +void rte_vhost_clear_inflight_begin(struct rte_vhost_vring *vring, + uint16_t idx); + +/** + * step 2 of clear inflight flag for a entry. + * + * @param vring + * the structure to hold the requested vring info + * @param last_used_idx + * next free used_idx + * @param idx + * inflight entry index + */ +void rte_vhost_clear_inflight_end(struct rte_vhost_vring *vring, + uint16_t last_used_idx, uint16_t idx); + +/** * Get vhost RX queue avail count. * * @param vid diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 163f459..ba5537c 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -76,6 +76,8 @@ close(vq->callfd); if (vq->kickfd >= 0) close(vq->kickfd); + if (vq->inflight) + vq->inflight = NULL; } /* @@ -589,6 +591,14 @@ vring->kickfd = vq->kickfd; vring->size = vq->size; + vring->inflight = vq->inflight; + + vring->inflight_reqs = vq->inflight_reqs; + vq->inflight_reqs = NULL; + + vring->inflight_cnt = vq->inflight_cnt; + vq->inflight_cnt = 0; + return 0; } @@ -617,6 +627,41 @@ return 0; } +void +rte_vhost_set_inflight(struct rte_vhost_vring *vring, uint16_t idx) +{ + VhostInflightInfo *inflight = vring->inflight; + if (unlikely(!inflight)) + return; + inflight->desc[idx].inflight = 1; +} + +void +rte_vhost_clear_inflight_begin(struct rte_vhost_vring *vring, uint16_t idx) +{ + VhostInflightInfo *inflight = vring->inflight; + + if (unlikely(!inflight)) + return; + + inflight->last_inflight_io = idx; +} + +void +rte_vhost_clear_inflight_end(struct rte_vhost_vring *vring, + uint16_t last_used_idx, uint16_t idx) +{ + VhostInflightInfo *inflight = vring->inflight; + + if (unlikely(!inflight)) + return; + + rte_compiler_barrier(); + inflight->desc[idx].inflight = 0; + rte_compiler_barrier(); + inflight->used_idx = last_used_idx; +} + uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id) { diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index e9138df..2ab9d68 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -128,6 +128,11 @@ struct vhost_virtqueue { /* Physical address of used ring, for logging */ uint64_t log_guest_addr; + /* Inflight share memory info */ + VhostInflightInfo *inflight; + uint16_t *inflight_reqs; + uint16_t inflight_cnt; + uint16_t nr_zmbuf; uint16_t zmbuf_size; uint16_t last_zmbuf_idx; @@ -286,6 +291,12 @@ struct guest_page { uint64_t size; }; +typedef struct VuDevInflightInfo { + int fd; + void *addr; + uint64_t size; +} VuDevInflightInfo; + /** * Device structure contains all configuration information relating * to the device. @@ -303,6 +314,7 @@ struct virtio_net { uint32_t nr_vring; int dequeue_zero_copy; struct vhost_virtqueue *virtqueue[VHOST_MAX_QUEUE_PAIRS * 2]; + VuDevInflightInfo inflight_info; #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ) char ifname[IF_NAME_SZ]; uint64_t log_size; diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index c9e29ec..ca937e2 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -31,6 +31,8 @@ #include #include #include +#include +#include #ifdef RTE_LIBRTE_VHOST_NUMA #include #endif @@ -49,6 +51,14 @@ #define VIRTIO_MIN_MTU 68 #define VIRTIO_MAX_MTU 65535 +#define INFLIGHT_ALIGNMENT 64 +#define INFLIGHT_VERSION 0xabcd + +#define CLOEXEC 0x0001U + +#define ALIGN_DOWN(n, m) ((n) / (m) * (m)) +#define ALIGN_UP(n, m) ALIGN_DOWN((n) + (m) - 1, (m)) + static const char *vhost_message_str[VHOST_USER_MAX] = { [VHOST_USER_NONE] = "VHOST_USER_NONE", [VHOST_USER_GET_FEATURES] = "VHOST_USER_GET_FEATURES", @@ -78,6 +88,8 @@ [VHOST_USER_POSTCOPY_ADVISE] = "VHOST_USER_POSTCOPY_ADVISE", [VHOST_USER_POSTCOPY_LISTEN] = "VHOST_USER_POSTCOPY_LISTEN", [VHOST_USER_POSTCOPY_END] = "VHOST_USER_POSTCOPY_END", + [VHOST_USER_GET_INFLIGHT_FD] = "VHOST_USER_GET_INFLIGHT_FD", + [VHOST_USER_SET_INFLIGHT_FD] = "VHOST_USER_SET_INFLIGHT_FD", }; static int send_vhost_reply(int sockfd, struct VhostUserMsg *msg); @@ -160,6 +172,16 @@ dev->log_addr = 0; } + if (dev->inflight_info.addr) { + munmap(dev->inflight_info.addr, dev->inflight_info.size); + dev->inflight_info.addr = NULL; + } + + if (dev->inflight_info.fd > 0) { + close(dev->inflight_info.fd); + dev->inflight_info.fd = -1; + } + if (dev->slave_req_fd >= 0) { close(dev->slave_req_fd); dev->slave_req_fd = -1; @@ -1165,6 +1187,184 @@ return 1; } +static int mem_create(const char *name, unsigned int flags) +{ +#ifdef __NR_memfd_create + return syscall(__NR_memfd_create, name, flags); +#else + return -1; +#endif +} + +void *inflight_mem_alloc(const char *name, size_t size, int *fd) +{ + void *ptr; + int mfd = -1; + char fname[20] = "/tmp/memfd-XXXXXX"; + + *fd = -1; + mfd = mem_create(name, CLOEXEC); + if (mfd != -1) { + if (ftruncate(mfd, size) == -1) { + RTE_LOG(ERR, VHOST_CONFIG, + "ftruncate fail for alloc inflight buffer\n"); + close(mfd); + return NULL; + } + } else { + mfd = mkstemp(fname); + unlink(fname); + + if (mfd == -1) { + RTE_LOG(ERR, VHOST_CONFIG, + "mkstemp fail for alloc inflight buffer\n"); + return NULL; + } + + if (ftruncate(mfd, size) == -1) { + RTE_LOG(ERR, VHOST_CONFIG, + "ftruncate fail for alloc inflight buffer\n"); + close(mfd); + return NULL; + } + } + + ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd, 0); + if (ptr == MAP_FAILED) { + RTE_LOG(ERR, VHOST_CONFIG, + "mmap fail for alloc inflight buffer\n"); + close(mfd); + return NULL; + } + + *fd = mfd; + return ptr; +} + +static uint32_t get_pervq_shm_size(uint16_t queue_size) +{ + return ALIGN_UP(sizeof(VhostUserInflightEntry) * queue_size + + sizeof(uint16_t) * 3, INFLIGHT_ALIGNMENT); +} + +static int +vhost_user_get_inflight_fd(struct virtio_net **pdev, VhostUserMsg *msg, + int main_fd __rte_unused) +{ + int fd; + uint64_t mmap_size; + void *addr; + uint16_t num_queues, queue_size; + struct virtio_net *dev = *pdev; + + if (msg->size != sizeof(msg->payload.inflight)) { + RTE_LOG(ERR, VHOST_CONFIG, + "Invalid get_inflight_fd message size is %d", + msg->size); + msg->payload.inflight.mmap_size = 0; + return 0; + } + + num_queues = msg->payload.inflight.num_queues; + queue_size = msg->payload.inflight.queue_size; + + RTE_LOG(INFO, VHOST_CONFIG, "get_inflight_fd num_queues: %u\n", + msg->payload.inflight.num_queues); + RTE_LOG(INFO, VHOST_CONFIG, "get_inflight_fd queue_size: %u\n", + msg->payload.inflight.queue_size); + mmap_size = num_queues * get_pervq_shm_size(queue_size); + + addr = inflight_mem_alloc("vhost-inflight", mmap_size, &fd); + if (!addr) { + RTE_LOG(ERR, VHOST_CONFIG, "Failed to alloc vhost inflight area"); + msg->payload.inflight.mmap_size = 0; + return 0; + } + memset(addr, 0, mmap_size); + + dev->inflight_info.addr = addr; + dev->inflight_info.size = msg->payload.inflight.mmap_size = mmap_size; + dev->inflight_info.fd = msg->fds[0] = fd; + msg->payload.inflight.mmap_offset = 0; + msg->fd_num = 1; + + RTE_LOG(INFO, VHOST_CONFIG, + "send inflight mmap_size: %lu\n", + msg->payload.inflight.mmap_size); + RTE_LOG(INFO, VHOST_CONFIG, + "send inflight mmap_offset: %lu\n", + msg->payload.inflight.mmap_offset); + RTE_LOG(INFO, VHOST_CONFIG, + "send inflight fd: %d\n", msg->fds[0]); + + return RTE_VHOST_MSG_RESULT_REPLY; +} + +static int +vhost_user_set_inflight_fd(struct virtio_net **pdev, VhostUserMsg *msg, + int main_fd __rte_unused) +{ + int fd, i; + uint64_t mmap_size, mmap_offset; + uint16_t num_queues, queue_size; + uint32_t pervq_inflight_size; + void *rc; + struct vhost_virtqueue *vq; + struct virtio_net *dev = *pdev; + + fd = msg->fds[0]; + if (msg->size != sizeof(msg->payload.inflight) || fd < 0) { + RTE_LOG(ERR, VHOST_CONFIG, "Invalid set_inflight_fd message size is %d,fd is %d\n", + msg->size, fd); + return -1; + } + + mmap_size = msg->payload.inflight.mmap_size; + mmap_offset = msg->payload.inflight.mmap_offset; + num_queues = msg->payload.inflight.num_queues; + queue_size = msg->payload.inflight.queue_size; + pervq_inflight_size = get_pervq_shm_size(queue_size); + + RTE_LOG(INFO, VHOST_CONFIG, + "set_inflight_fd mmap_size: %lu\n", mmap_size); + RTE_LOG(INFO, VHOST_CONFIG, + "set_inflight_fd mmap_offset: %lu\n", mmap_offset); + RTE_LOG(INFO, VHOST_CONFIG, + "set_inflight_fd num_queues: %u\n", num_queues); + RTE_LOG(INFO, VHOST_CONFIG, + "set_inflight_fd queue_size: %u\n", queue_size); + RTE_LOG(INFO, VHOST_CONFIG, + "set_inflight_fd fd: %d\n", fd); + RTE_LOG(INFO, VHOST_CONFIG, + "set_inflight_fd pervq_inflight_size: %d\n", + pervq_inflight_size); + + if (dev->inflight_info.addr) + munmap(dev->inflight_info.addr, dev->inflight_info.size); + + rc = mmap(0, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, + fd, mmap_offset); + if (rc == MAP_FAILED) { + RTE_LOG(ERR, VHOST_CONFIG, "failed to mmap share memory.\n"); + return -1; + } + + if (dev->inflight_info.fd) + close(dev->inflight_info.fd); + + dev->inflight_info.fd = fd; + dev->inflight_info.addr = rc; + dev->inflight_info.size = mmap_size; + + for (i = 0; i < num_queues; i++) { + vq = dev->virtqueue[i]; + vq->inflight = (VhostInflightInfo *)rc; + rc = (void *)((char *)rc + pervq_inflight_size); + } + + return RTE_VHOST_MSG_RESULT_OK; +} + static int vhost_user_set_vring_call(struct virtio_net **pdev, struct VhostUserMsg *msg, int main_fd __rte_unused) @@ -1202,6 +1402,47 @@ static int vhost_user_set_vring_err(struct virtio_net **pdev __rte_unused, } static int +vhost_check_queue_inflights(struct vhost_virtqueue *vq) +{ + struct vring_used *used = vq->used; + uint16_t i = 0; + + if ((!vq->inflight)) + return RTE_VHOST_MSG_RESULT_ERR; + + if (!vq->inflight->version) { + vq->inflight->version = INFLIGHT_VERSION; + return RTE_VHOST_MSG_RESULT_OK; + } + + vq->inflight_reqs = calloc(vq->size, sizeof(uint16_t)); + if (!vq->inflight_reqs) { + RTE_LOG(ERR, VHOST_CONFIG, "Failed to allocate memory for inflight reqs.\n"); + return RTE_VHOST_MSG_RESULT_ERR; + } + + if (vq->inflight->used_idx != used->idx) { + vq->inflight->desc[vq->inflight->last_inflight_io].inflight = 0; + rte_compiler_barrier(); + vq->inflight->used_idx = used->idx; + } + + for (i = 0; i < vq->size; i++) { + if (vq->inflight->desc[i].inflight == 1) + vq->inflight_reqs[vq->inflight_cnt++] = i; + } + + if (!vq->inflight_cnt) { + free(vq->inflight_reqs); + vq->inflight_reqs = NULL; + } + + vq->last_avail_idx += vq->inflight_cnt; + + return RTE_VHOST_MSG_RESULT_OK; +} + +static int vhost_user_set_vring_kick(struct virtio_net **pdev, struct VhostUserMsg *msg, int main_fd __rte_unused) { @@ -1242,6 +1483,12 @@ static int vhost_user_set_vring_err(struct virtio_net **pdev __rte_unused, close(vq->kickfd); vq->kickfd = file.fd; + if (vhost_check_queue_inflights(vq)) { + RTE_LOG(ERR, VHOST_CONFIG, + "Failed to inflights for vq: %d\n", file.index); + return RTE_VHOST_MSG_RESULT_ERR; + } + return RTE_VHOST_MSG_RESULT_OK; } @@ -1762,6 +2009,8 @@ typedef int (*vhost_message_handler_t)(struct virtio_net **pdev, [VHOST_USER_POSTCOPY_ADVISE] = vhost_user_set_postcopy_advise, [VHOST_USER_POSTCOPY_LISTEN] = vhost_user_set_postcopy_listen, [VHOST_USER_POSTCOPY_END] = vhost_user_postcopy_end, + [VHOST_USER_GET_INFLIGHT_FD] = vhost_user_get_inflight_fd, + [VHOST_USER_SET_INFLIGHT_FD] = vhost_user_set_inflight_fd, }; diff --git a/lib/librte_vhost/vhost_user.h b/lib/librte_vhost/vhost_user.h index 2a650fe..35f969b 100644 --- a/lib/librte_vhost/vhost_user.h +++ b/lib/librte_vhost/vhost_user.h @@ -23,7 +23,8 @@ (1ULL << VHOST_USER_PROTOCOL_F_CRYPTO_SESSION) | \ (1ULL << VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD) | \ (1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER) | \ - (1ULL << VHOST_USER_PROTOCOL_F_PAGEFAULT)) + (1ULL << VHOST_USER_PROTOCOL_F_PAGEFAULT) | \ + (1ULL << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) typedef enum VhostUserRequest { VHOST_USER_NONE = 0, @@ -54,7 +55,9 @@ VHOST_USER_POSTCOPY_ADVISE = 28, VHOST_USER_POSTCOPY_LISTEN = 29, VHOST_USER_POSTCOPY_END = 30, - VHOST_USER_MAX = 31 + VHOST_USER_GET_INFLIGHT_FD = 31, + VHOST_USER_SET_INFLIGHT_FD = 32, + VHOST_USER_MAX = 33 } VhostUserRequest; typedef enum VhostUserSlaveRequest { @@ -112,6 +115,13 @@ 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 VhostUserMsg { union { uint32_t master; /* a VhostUserRequest value */ @@ -131,6 +141,7 @@ struct vhost_vring_addr addr; VhostUserMemory memory; VhostUserLog log; + VhostUserInflight inflight; struct vhost_iotlb_msg iotlb; VhostUserCryptoSessionParam crypto_session; VhostUserVringArea area; @@ -148,6 +159,7 @@ /* vhost_user.c */ int vhost_user_msg_handler(int vid, int fd); int vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm); +void *inflight_mem_alloc(const char *name, size_t size, int *fd); /* socket.c */ int read_fd_message(int sockfd, char *buf, int buflen, int *fds, int max_fds, -- 1.8.3.1