bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
To: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	bpf@vger.kernel.org
Subject: [PATCH v5 05/22] virtio_ring: queue_reset: split: support enable reset queue
Date: Mon, 14 Feb 2022 16:13:59 +0800	[thread overview]
Message-ID: <20220214081416.117695-6-xuanzhuo@linux.alibaba.com> (raw)
In-Reply-To: <20220214081416.117695-1-xuanzhuo@linux.alibaba.com>

The purpose of this patch is to make vring split support re-enable reset
vq.

Based on whether the incoming vq passed by vring_setup_virtqueue() is
NULL or not, distinguish whether it is a normal create virtqueue or
re-enable a reset queue.

When re-enable a reset queue, reuse the original callback, name,
indirect.

Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
---
 drivers/virtio/virtio_ring.c | 52 +++++++++++++++++++++++++-----------
 1 file changed, 37 insertions(+), 15 deletions(-)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 9cfbe45ab286..4639e1643c78 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -198,6 +198,16 @@ struct vring_virtqueue {
 #endif
 };
 
+static int __vring_init_virtqueue(struct virtqueue *_vq,
+				  unsigned int index,
+				  struct vring vring,
+				  struct virtio_device *vdev,
+				  bool weak_barriers,
+				  bool context,
+				  bool (*notify)(struct virtqueue *),
+				  void (*callback)(struct virtqueue *),
+				  const char *name,
+				  bool reset);
 
 /*
  * Helpers.
@@ -925,9 +935,9 @@ static struct virtqueue *vring_create_virtqueue_split(
 	bool context,
 	bool (*notify)(struct virtqueue *),
 	void (*callback)(struct virtqueue *),
-	const char *name)
+	const char *name,
+	struct virtqueue *vq)
 {
-	struct virtqueue *vq;
 	void *queue = NULL;
 	dma_addr_t dma_addr;
 	size_t queue_size_in_bytes;
@@ -964,12 +974,17 @@ static struct virtqueue *vring_create_virtqueue_split(
 	queue_size_in_bytes = vring_size(num, vring_align);
 	vring_init(&vring, num, queue, vring_align);
 
-	vq = __vring_new_virtqueue(index, vring, vdev, weak_barriers, context,
-				   notify, callback, name);
 	if (!vq) {
-		vring_free_queue(vdev, queue_size_in_bytes, queue,
-				 dma_addr);
-		return NULL;
+		vq = __vring_new_virtqueue(index, vring, vdev, weak_barriers,
+					   context, notify, callback, name);
+		if (!vq)
+			goto err;
+
+	} else {
+		if (__vring_init_virtqueue(vq, index, vring, vdev,
+					   weak_barriers, context, notify,
+					   callback, name, true))
+			goto err;
 	}
 
 	to_vvq(vq)->split.queue_dma_addr = dma_addr;
@@ -977,6 +992,9 @@ static struct virtqueue *vring_create_virtqueue_split(
 	to_vvq(vq)->we_own_ring = true;
 
 	return vq;
+err:
+	vring_free_queue(vdev, queue_size_in_bytes, queue, dma_addr);
+	return NULL;
 }
 
 
@@ -2177,14 +2195,20 @@ static int __vring_init_virtqueue(struct virtqueue *_vq,
 				  bool context,
 				  bool (*notify)(struct virtqueue *),
 				  void (*callback)(struct virtqueue *),
-				  const char *name)
+				  const char *name,
+				  bool reset)
 {
 	struct vring_virtqueue *vq = to_vvq(_vq);
 
+	if (!reset) {
+		vq->vq.callback = callback;
+		vq->vq.name = name;
+		vq->indirect = virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC) &&
+			!context;
+	}
+
 	vq->packed_ring = false;
-	vq->vq.callback = callback;
 	vq->vq.vdev = vdev;
-	vq->vq.name = name;
 	vq->vq.num_free = vring.num;
 	vq->vq.index = index;
 	vq->we_own_ring = false;
@@ -2200,8 +2224,6 @@ static int __vring_init_virtqueue(struct virtqueue *_vq,
 	vq->last_add_time_valid = false;
 #endif
 
-	vq->indirect = virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC) &&
-		!context;
 	vq->event = virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX);
 
 	if (virtio_has_feature(vdev, VIRTIO_F_ORDER_PLATFORM))
@@ -2215,7 +2237,7 @@ static int __vring_init_virtqueue(struct virtqueue *_vq,
 	vq->split.avail_idx_shadow = 0;
 
 	/* No callback?  Tell other side not to bother us. */
-	if (!callback) {
+	if (!vq->vq.callback) {
 		vq->split.avail_flags_shadow |= VRING_AVAIL_F_NO_INTERRUPT;
 		if (!vq->event)
 			vq->split.vring.avail->flags = cpu_to_virtio16(vdev,
@@ -2267,7 +2289,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,
 		return NULL;
 
 	err = __vring_init_virtqueue(&vq->vq, index, vring, vdev, weak_barriers,
-				     context, notify, callback, name);
+				     context, notify, callback, name, false);
 
 	if (err) {
 		kfree(vq);
@@ -2299,7 +2321,7 @@ struct virtqueue *vring_setup_virtqueue(
 
 	return vring_create_virtqueue_split(index, num, vring_align,
 			vdev, weak_barriers, may_reduce_num,
-			context, notify, callback, name);
+			context, notify, callback, name, vq);
 }
 EXPORT_SYMBOL_GPL(vring_setup_virtqueue);
 
-- 
2.31.0


  parent reply	other threads:[~2022-02-14  8:14 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-14  8:13 [PATCH v5 00/22] virtio pci support VIRTIO_F_RING_RESET Xuan Zhuo
2022-02-14  8:13 ` [PATCH v5 01/22] virtio_pci: struct virtio_pci_common_cfg add queue_notify_data Xuan Zhuo
2022-02-14  8:13 ` [PATCH v5 02/22] virtio: queue_reset: add VIRTIO_F_RING_RESET Xuan Zhuo
2022-02-14  8:13 ` [PATCH v5 03/22] virtio_ring: queue_reset: add function vring_setup_virtqueue() Xuan Zhuo
2022-02-14  8:13 ` [PATCH v5 04/22] virtio_ring: queue_reset: split: add __vring_init_virtqueue() Xuan Zhuo
2022-02-14  8:13 ` Xuan Zhuo [this message]
2022-02-14  8:14 ` [PATCH v5 06/22] virtio_ring: queue_reset: packed: support enable reset queue Xuan Zhuo
2022-02-16  4:14   ` Jason Wang
2022-02-14  8:14 ` [PATCH v5 07/22] virtio_ring: queue_reset: extract the release function of the vq ring Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 08/22] virtio_ring: queue_reset: add vring_release_virtqueue() Xuan Zhuo
2022-02-16  4:14   ` Jason Wang
2022-02-14  8:14 ` [PATCH v5 09/22] virtio: queue_reset: struct virtio_config_ops add callbacks for queue_reset Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 10/22] virtio_pci: queue_reset: update struct virtio_pci_common_cfg and option functions Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 11/22] virtio_pci: queue_reset: release vq by vp_dev->vqs Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 12/22] virtio_pci: queue_reset: setup_vq() support vring_setup_virtqueue() Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 13/22] virtio_pci: queue_reset: reserve vq->priv for re-enable queue Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 14/22] virtio_pci: queue_reset: support VIRTIO_F_RING_RESET Xuan Zhuo
2022-02-16  4:14   ` Jason Wang
2022-02-16  8:03     ` Xuan Zhuo
2022-02-17  7:25       ` Jason Wang
2022-02-14  8:14 ` [PATCH v5 15/22] virtio: queue_reset: add helper Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 16/22] virtio_net: split free_unused_bufs() Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 17/22] virtio_net: support rx/tx queue reset Xuan Zhuo
2022-02-16  4:14   ` Jason Wang
2022-02-16  7:56     ` Xuan Zhuo
2022-02-16  8:35       ` Michael S. Tsirkin
2022-02-16  8:42         ` Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 18/22] virtio: add helper virtqueue_get_vring_max_size() Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 19/22] virtio: add helper virtio_set_max_ring_num() Xuan Zhuo
2022-02-16  4:14   ` Jason Wang
2022-02-16  7:54     ` Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 20/22] virtio_net: set the default max ring num Xuan Zhuo
2022-02-16  4:14   ` Jason Wang
2022-02-16  7:46     ` Xuan Zhuo
2022-02-17  7:21       ` Jason Wang
2022-02-17  9:30         ` Xuan Zhuo
2022-02-21  3:40           ` Jason Wang
2022-02-21  7:00             ` Jason Wang
2022-02-14  8:14 ` [PATCH v5 21/22] virtio_net: get max ring size by virtqueue_get_vring_max_size() Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 22/22] virtio_net: support set_ringparam Xuan Zhuo
2022-02-16  4:14   ` Jason Wang
2022-02-16  7:21     ` Xuan Zhuo

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=20220214081416.117695-6-xuanzhuo@linux.alibaba.com \
    --to=xuanzhuo@linux.alibaba.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=hawk@kernel.org \
    --cc=jasowang@redhat.com \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.org \
    /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).