DPDK patches and discussions
 help / color / mirror / Atom feed
From: Kangjie Xu <kangjie.xu@linux.alibaba.com>
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	[thread overview]
Message-ID: <0383bb821dd65d8511a91e9f13b193230be59557.1662952732.git.kangjie.xu@linux.alibaba.com> (raw)
In-Reply-To: <cover.1662952732.git.kangjie.xu@linux.alibaba.com>

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 <kangjie.xu@linux.alibaba.com>
Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
---
 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;
-- 
2.32.0


  reply	other threads:[~2022-09-12  3:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-12  3:36 [PATCH v3 0/2] vhost: support VIRTIO_F_RING_RESET for vhost-user Kangjie Xu
2022-09-12  3:36 ` Kangjie Xu [this message]
2022-10-11 16:44   ` [PATCH v3 1/2] vhost: destroy device when all vqs are inactive Maxime Coquelin
2024-04-29 16:27     ` Stephen Hemminger
2024-04-30  3:43       ` Xuan Zhuo
2022-09-12  3:36 ` [PATCH v3 2/2] vhost: support VIRTIO_F_RING_RESET for vhost-user Kangjie Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0383bb821dd65d8511a91e9f13b193230be59557.1662952732.git.kangjie.xu@linux.alibaba.com \
    --to=kangjie.xu@linux.alibaba.com \
    --cc=chenbo.xia@intel.com \
    --cc=dev@dpdk.org \
    --cc=hengqi@linux.alibaba.com \
    --cc=jasowang@redhat.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=mst@redhat.com \
    --cc=xuanzhuo@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).