From patchwork Mon Sep 5 03:48:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kangjie Xu X-Patchwork-Id: 115831 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 501F8A0556; Mon, 5 Sep 2022 05:48:23 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7495D427ED; Mon, 5 Sep 2022 05:48:13 +0200 (CEST) Received: from out30-43.freemail.mail.aliyun.com (out30-43.freemail.mail.aliyun.com [115.124.30.43]) by mails.dpdk.org (Postfix) with ESMTP id 12B2540697 for ; Mon, 5 Sep 2022 05:48:09 +0200 (CEST) X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R441e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=ay29a033018046059; MF=kangjie.xu@linux.alibaba.com; NM=1; PH=DS; RN=7; SR=0; TI=SMTPD_---0VOK7-vD_1662349686; Received: from localhost(mailfrom:kangjie.xu@linux.alibaba.com fp:SMTPD_---0VOK7-vD_1662349686) by smtp.aliyun-inc.com; Mon, 05 Sep 2022 11:48:07 +0800 From: Kangjie Xu To: maxime.coquelin@redhat.com, chenbo.xia@intel.com Cc: dev@dpdk.org, xuanzhuo@linux.alibaba.com, hengqi@linux.alibaba.com, jasonwang@redhat.com, mst@redhat.com Subject: [PATCH v2 1/2] vhost: support VIRTIO_F_RING_RESET for vhost-user Date: Mon, 5 Sep 2022 11:48:04 +0800 Message-Id: <41bd4cb5a38827f3b8550e2fd5ab52bf5135d0e0.1662347861.git.kangjie.xu@linux.alibaba.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add VIRTIO_F_RING_RESET, which indicates that the driver can reset a queue individually. The feature is added to virtio-spec 1.2. The relevant information is in https://github.com/oasis-tcs/virtio-spec/issues/124 Signed-off-by: Kangjie Xu Signed-off-by: Xuan Zhuo --- lib/vhost/vhost.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h index 40fac3b7c6..76461a3406 100644 --- a/lib/vhost/vhost.h +++ b/lib/vhost/vhost.h @@ -376,6 +376,11 @@ struct vhost_msg { #define VIRTIO_F_VERSION_1 32 #endif +/* This feature indicates that the driver can reset a queue individually. */ +#ifndef VIRTIO_F_RING_RESET +#define VIRTIO_F_RING_RESET 40 +#endif + /* Declare packed ring related bits for older kernels */ #ifndef VIRTIO_F_RING_PACKED @@ -438,7 +443,8 @@ struct vring_packed_desc_event { (1ULL << VIRTIO_NET_F_MTU) | \ (1ULL << VIRTIO_F_IN_ORDER) | \ (1ULL << VIRTIO_F_IOMMU_PLATFORM) | \ - (1ULL << VIRTIO_F_RING_PACKED)) + (1ULL << VIRTIO_F_RING_PACKED) | \ + (1ULL << VIRTIO_F_RING_RESET)) struct guest_page { From patchwork Mon Sep 5 03:48:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kangjie Xu X-Patchwork-Id: 115830 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B4682A0556; Mon, 5 Sep 2022 05:48:17 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A960D40E5A; Mon, 5 Sep 2022 05:48:12 +0200 (CEST) Received: from out30-43.freemail.mail.aliyun.com (out30-43.freemail.mail.aliyun.com [115.124.30.43]) by mails.dpdk.org (Postfix) with ESMTP id 91A34400D4 for ; Mon, 5 Sep 2022 05:48:10 +0200 (CEST) X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R121e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=ay29a033018045168; MF=kangjie.xu@linux.alibaba.com; NM=1; PH=DS; RN=7; SR=0; TI=SMTPD_---0VOK6FgW_1662349687; Received: from localhost(mailfrom:kangjie.xu@linux.alibaba.com fp:SMTPD_---0VOK6FgW_1662349687) by smtp.aliyun-inc.com; Mon, 05 Sep 2022 11:48:08 +0800 From: Kangjie Xu To: maxime.coquelin@redhat.com, chenbo.xia@intel.com Cc: dev@dpdk.org, xuanzhuo@linux.alibaba.com, hengqi@linux.alibaba.com, jasonwang@redhat.com, mst@redhat.com Subject: [PATCH v2 2/2] vhost: introduce VHOST_USER_RESET_VRING Date: Mon, 5 Sep 2022 11:48:05 +0800 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org To support the reset operation for an individual virtqueue, we introduce a new message VHOST_USER_RESET_VRING. When the feature VIRTIO_F_RING_RESET feature has been successfully negotiated, This message is submitted by the front-end to reset an individual virtqueue to initial states in the back-end. The reply is needed to ensure that the reset operation is complete. Signed-off-by: Kangjie Xu Signed-off-by: Xuan Zhuo --- lib/vhost/vhost.c | 2 +- lib/vhost/vhost.h | 1 + lib/vhost/vhost_user.c | 27 ++++++++++++++++++++++++++- lib/vhost/vhost_user.h | 1 + 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 60cb05a0ff..215a1ca355 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -610,7 +610,7 @@ init_vring_queue(struct virtio_net *dev, uint32_t vring_idx) vhost_user_iotlb_init(dev, vring_idx); } -static void +void reset_vring_queue(struct virtio_net *dev, uint32_t vring_idx) { struct vhost_virtqueue *vq; diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h index 76461a3406..eccb52842d 100644 --- a/lib/vhost/vhost.h +++ b/lib/vhost/vhost.h @@ -791,6 +791,7 @@ get_device(int vid) int vhost_new_device(void); void cleanup_device(struct virtio_net *dev, int destroy); +void reset_vring_queue(struct virtio_net *dev, uint32_t vring_idx); void reset_device(struct virtio_net *dev); void vhost_destroy_device(int); void vhost_destroy_device_notify(struct virtio_net *dev); diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c index 4ad28bac45..5f7743d9d9 100644 --- a/lib/vhost/vhost_user.c +++ b/lib/vhost/vhost_user.c @@ -2771,6 +2771,30 @@ vhost_user_set_status(struct virtio_net **pdev, return RTE_VHOST_MSG_RESULT_OK; } +static int +vhost_user_reset_vring(struct virtio_net **pdev, + struct vhu_msg_context *ctx __rte_unused, + int main_fd __rte_unused) +{ + struct virtio_net *dev = *pdev; + int index = (int)ctx->msg.payload.state.index; + + VHOST_LOG_CONFIG(dev->ifname, INFO, "reset queue: queue idx: %d\n", index); + + if (!(dev->features & (1ULL << VIRTIO_F_RING_RESET))) { + return RTE_VHOST_MSG_RESULT_ERR; + } + + dev->virtqueue[index]->enabled = false; + reset_vring_queue(dev, index); + + ctx->msg.payload.state.num = 0; + ctx->msg.size = sizeof(ctx->msg.payload.u64); + ctx->fd_num = 0; + + return RTE_VHOST_MSG_RESULT_REPLY; +} + #define VHOST_MESSAGE_HANDLERS \ VHOST_MESSAGE_HANDLER(VHOST_USER_NONE, NULL, false) \ VHOST_MESSAGE_HANDLER(VHOST_USER_GET_FEATURES, vhost_user_get_features, false) \ @@ -2803,7 +2827,8 @@ VHOST_MESSAGE_HANDLER(VHOST_USER_POSTCOPY_END, vhost_user_postcopy_end, false) \ VHOST_MESSAGE_HANDLER(VHOST_USER_GET_INFLIGHT_FD, vhost_user_get_inflight_fd, false) \ VHOST_MESSAGE_HANDLER(VHOST_USER_SET_INFLIGHT_FD, vhost_user_set_inflight_fd, true) \ VHOST_MESSAGE_HANDLER(VHOST_USER_SET_STATUS, vhost_user_set_status, false) \ -VHOST_MESSAGE_HANDLER(VHOST_USER_GET_STATUS, vhost_user_get_status, false) +VHOST_MESSAGE_HANDLER(VHOST_USER_GET_STATUS, vhost_user_get_status, false) \ +VHOST_MESSAGE_HANDLER(VHOST_USER_RESET_VRING, vhost_user_reset_vring, false) #define VHOST_MESSAGE_HANDLER(id, handler, accepts_fd) \ [id] = { #id, handler, accepts_fd }, diff --git a/lib/vhost/vhost_user.h b/lib/vhost/vhost_user.h index 8ecca68597..51cb2fc74a 100644 --- a/lib/vhost/vhost_user.h +++ b/lib/vhost/vhost_user.h @@ -60,6 +60,7 @@ typedef enum VhostUserRequest { VHOST_USER_SET_INFLIGHT_FD = 32, VHOST_USER_SET_STATUS = 39, VHOST_USER_GET_STATUS = 40, + VHOST_USER_RESET_VRING = 41 } VhostUserRequest; typedef enum VhostUserSlaveRequest {