Split vring resize supports reusing the original buffer. The split vring resize function implemented earlier uses the method of letting the upper layer recycle all the buffers. This commit will first try to re-put it to the new vring in the order submitted to the old vring. The remaining buffers that cannot be submitted to the new vring will be called the recycle callback to release. Signed-off-by: Xuan Zhuo <xuanzhuo@xxxxxxxxxxxxxxxxx> --- drivers/virtio/virtio_ring.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 02d4ffcc0a3b..fa4270e8c009 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -1281,11 +1281,13 @@ static struct virtqueue *vring_create_virtqueue_split( return vq; } -static int virtqueue_resize_split(struct virtqueue *_vq, u32 num) +static int virtqueue_resize_split(struct virtqueue *_vq, u32 num, + void (*recycle)(struct virtqueue *vq, void *buf)) { + struct vring_virtqueue_split vring = {}, vring_old = {}; struct vring_virtqueue *vq = to_vvq(_vq); - struct vring_virtqueue_split vring = {}; struct virtio_device *vdev = _vq->vdev; + void *buf; int err; err = vring_alloc_queue_split(&vring, vdev, num, vq->split.vring_align, @@ -1299,15 +1301,26 @@ static int virtqueue_resize_split(struct virtqueue *_vq, u32 num) goto err; } - vring_free(&vq->vq); + virtqueue_vring_detach_split(vq, &vring_old); virtqueue_init(vq, vring.vring.num); virtqueue_vring_attach_split(vq, &vring); virtqueue_vring_init_split(vq); + vring_reuse_bufs_split(vq, &vring_old, recycle); + vring_free_split(&vring_old, vdev); + return 0; err: + /* + * In the case of failure to create vring, do not try to reuse the + * original buffer. Because the probability of this situation is not + * high, but we have to introduce new logic. + */ + while ((buf = virtqueue_detach_unused_buf(&vq->vq))) + recycle(&vq->vq, buf); + virtqueue_reinit_split(vq); return -ENOMEM; } @@ -2747,7 +2760,7 @@ int virtqueue_resize(struct virtqueue *_vq, u32 num, if (packed) err = virtqueue_resize_packed(_vq, num); else - err = virtqueue_resize_split(_vq, num); + err = virtqueue_resize_split(_vq, num, recycle); if (vdev->config->enable_reset_vq(_vq)) return -EBUSY; -- 2.31.0 _______________________________________________ Virtualization mailing list Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx https://lists.linuxfoundation.org/mailman/listinfo/virtualization