[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220308123518.33800-11-xuanzhuo@linux.alibaba.com>
Date: Tue, 8 Mar 2022 20:35:02 +0800
From: Xuan Zhuo <xuanzhuo@...ux.alibaba.com>
To: virtualization@...ts.linux-foundation.org, netdev@...r.kernel.org
Cc: Jeff Dike <jdike@...toit.com>, Richard Weinberger <richard@....at>,
Anton Ivanov <anton.ivanov@...bridgegreys.com>,
"Michael S. Tsirkin" <mst@...hat.com>,
Jason Wang <jasowang@...hat.com>,
"David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Hans de Goede <hdegoede@...hat.com>,
Mark Gross <markgross@...nel.org>,
Vadim Pasternak <vadimp@...dia.com>,
Bjorn Andersson <bjorn.andersson@...aro.org>,
Mathieu Poirier <mathieu.poirier@...aro.org>,
Cornelia Huck <cohuck@...hat.com>,
Halil Pasic <pasic@...ux.ibm.com>,
Heiko Carstens <hca@...ux.ibm.com>,
Vasily Gorbik <gor@...ux.ibm.com>,
Christian Borntraeger <borntraeger@...ux.ibm.com>,
Alexander Gordeev <agordeev@...ux.ibm.com>,
Sven Schnelle <svens@...ux.ibm.com>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Jesper Dangaard Brouer <hawk@...nel.org>,
John Fastabend <john.fastabend@...il.com>,
Johannes Berg <johannes.berg@...el.com>,
Vincent Whitchurch <vincent.whitchurch@...s.com>,
Xuan Zhuo <xuanzhuo@...ux.alibaba.com>,
linux-um@...ts.infradead.org, platform-driver-x86@...r.kernel.org,
linux-remoteproc@...r.kernel.org, linux-s390@...r.kernel.org,
kvm@...r.kernel.org, bpf@...r.kernel.org
Subject: [PATCH v7 10/26] virtio_ring: packed: implement virtqueue_reset_vring_packed()
virtio ring supports reset.
Queue reset is divided into several stages.
1. notify device queue reset
2. vring release
3. attach new vring
4. notify device queue re-enable
After the first step is completed, the vring reset operation can be
performed. If the newly set vring num does not change, then just reset
the vq related value.
Otherwise, the vring will be released and the vring will be reallocated.
And the vring will be attached to the vq. If this process fails, the
function will exit, and the state of the vq will be the vring release
state. You can call this function again to reallocate the vring.
Signed-off-by: Xuan Zhuo <xuanzhuo@...ux.alibaba.com>
---
drivers/virtio/virtio_ring.c | 46 ++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 148fb1fd3d5a..5afcbabcfb1e 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -1886,6 +1886,8 @@ static int vring_virtqueue_attach_packed(struct vring_virtqueue *vq,
static void vring_virtqueue_init_packed(struct vring_virtqueue *vq,
struct virtio_device *vdev)
{
+ vq->vq.reset = VIRTIO_VQ_RESET_STEP_NONE;
+
vq->we_own_ring = true;
vq->broken = false;
vq->last_used_idx = 0;
@@ -1969,6 +1971,50 @@ static struct virtqueue *vring_create_virtqueue_packed(
return NULL;
}
+static int virtqueue_reset_vring_packed(struct virtqueue *_vq, u32 num)
+{
+ struct vring_virtqueue *vq = to_vvq(_vq);
+ struct virtio_device *vdev = _vq->vdev;
+ struct vring_packed vring;
+ int err;
+
+ if (num > _vq->num_max)
+ return -E2BIG;
+
+ switch (vq->vq.reset) {
+ case VIRTIO_VQ_RESET_STEP_NONE:
+ return -ENOENT;
+
+ case VIRTIO_VQ_RESET_STEP_VRING_ATTACH:
+ case VIRTIO_VQ_RESET_STEP_DEVICE:
+ if (vq->packed.vring.num == num || !num)
+ break;
+
+ vring_free(_vq);
+
+ fallthrough;
+
+ case VIRTIO_VQ_RESET_STEP_VRING_RELEASE:
+ if (!num)
+ num = vq->packed.vring.num;
+
+ err = vring_create_vring_packed(&vring, vdev, num);
+ if (err)
+ return -ENOMEM;
+
+ err = vring_virtqueue_attach_packed(vq, &vring, vdev);
+ if (err) {
+ vring_free_vring_packed(&vring, vdev);
+ return -ENOMEM;
+ }
+ }
+
+ vring_virtqueue_init_packed(vq, vdev);
+ vq->vq.reset = VIRTIO_VQ_RESET_STEP_VRING_ATTACH;
+
+ return 0;
+}
+
/*
* Generic functions and exported symbols.
--
2.31.0
Powered by blists - more mailing lists