From patchwork Mon Sep 12 03:36:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kangjie Xu X-Patchwork-Id: 116182 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 0E6EEA00C5; Mon, 12 Sep 2022 05:37:04 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 850AF427FF; Mon, 12 Sep 2022 05:36:55 +0200 (CEST) Received: from out199-5.us.a.mail.aliyun.com (out199-5.us.a.mail.aliyun.com [47.90.199.5]) by mails.dpdk.org (Postfix) with ESMTP id 132E7400D4 for ; Mon, 12 Sep 2022 05:36:53 +0200 (CEST) X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R171e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=ay29a033018045170; MF=kangjie.xu@linux.alibaba.com; NM=1; PH=DS; RN=7; SR=0; TI=SMTPD_---0VPNZKqD_1662953808; Received: from localhost(mailfrom:kangjie.xu@linux.alibaba.com fp:SMTPD_---0VPNZKqD_1662953808) by smtp.aliyun-inc.com; Mon, 12 Sep 2022 11:36:49 +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, jasowang@redhat.com, mst@redhat.com Subject: [PATCH v3 1/2] vhost: destroy device when all vqs are inactive Date: Mon, 12 Sep 2022 11:36:46 +0800 Message-Id: <0383bb821dd65d8511a91e9f13b193230be59557.1662952732.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 We change the behavior of vhost_user_get_vring_base(). Previosly, destroying a virtqueue will cause the whole device to be destroyed. The behavior is not specified in the vhost-user protocol. Thus, we refactor this part. The device will be destroyed only when all virtqueues in the device are going to be destroyed. This helps us to simplify the implementation when resetting a virtqueue. Signed-off-by: Kangjie Xu Signed-off-by: Xuan Zhuo --- lib/vhost/vhost_user.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c index 4ad28bac45..a9f0709f94 100644 --- a/lib/vhost/vhost_user.c +++ b/lib/vhost/vhost_user.c @@ -2088,10 +2088,16 @@ vhost_user_get_vring_base(struct virtio_net **pdev, { struct virtio_net *dev = *pdev; struct vhost_virtqueue *vq = dev->virtqueue[ctx->msg.payload.state.index]; + uint32_t i, num_live_vring = 0; uint64_t val; - /* We have to stop the queue (virtio) if it is running. */ - vhost_destroy_device_notify(dev); + /* Stop the device when vq is the last active queue */ + for (i = 0; i < dev->nr_vring; i++) + if (dev->virtqueue[i]->access_ok) + num_live_vring++; + + if (num_live_vring == 1 && vq->access_ok) + vhost_destroy_device_notify(dev); dev->flags &= ~VIRTIO_DEV_READY; dev->flags &= ~VIRTIO_DEV_VDPA_CONFIGURED; From patchwork Mon Sep 12 03:36:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kangjie Xu X-Patchwork-Id: 116183 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 67E16A00C5; Mon, 12 Sep 2022 05:37:08 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6C1324281B; Mon, 12 Sep 2022 05:36:57 +0200 (CEST) Received: from out30-57.freemail.mail.aliyun.com (out30-57.freemail.mail.aliyun.com [115.124.30.57]) by mails.dpdk.org (Postfix) with ESMTP id B959440A89 for ; Mon, 12 Sep 2022 05:36:54 +0200 (CEST) X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R131e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=ay29a033018045176; MF=kangjie.xu@linux.alibaba.com; NM=1; PH=DS; RN=7; SR=0; TI=SMTPD_---0VPNZKqY_1662953809; Received: from localhost(mailfrom:kangjie.xu@linux.alibaba.com fp:SMTPD_---0VPNZKqY_1662953809) by smtp.aliyun-inc.com; Mon, 12 Sep 2022 11:36:50 +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, jasowang@redhat.com, mst@redhat.com Subject: [PATCH v3 2/2] vhost: support VIRTIO_F_RING_RESET for vhost-user Date: Mon, 12 Sep 2022 11:36:47 +0800 Message-Id: <5a9722d0d3890403280805e6173a2d1e9db8f777.1662952732.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 {