[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1646817741.6086373-5-xuanzhuo@linux.alibaba.com>
Date: Wed, 9 Mar 2022 17:22:21 +0800
From: Xuan Zhuo <xuanzhuo@...ux.alibaba.com>
To: Jason Wang <jasowang@...hat.com>
Cc: Jeff Dike <jdike@...toit.com>, Richard Weinberger <richard@....at>,
Anton Ivanov <anton.ivanov@...bridgegreys.com>,
"Michael S. Tsirkin" <mst@...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>,
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,
virtualization@...ts.linux-foundation.org, netdev@...r.kernel.org
Subject: Re: [PATCH v7 08/26] virtio_ring: extract the logic of freeing vring
On Wed, 9 Mar 2022 15:51:13 +0800, Jason Wang <jasowang@...hat.com> wrote:
>
> 在 2022/3/8 下午8:35, Xuan Zhuo 写道:
> > Introduce vring_free() to free the vring of vq.
> >
> > Prevent double free by setting vq->reset.
> >
> > Signed-off-by: Xuan Zhuo <xuanzhuo@...ux.alibaba.com>
> > ---
> > drivers/virtio/virtio_ring.c | 25 ++++++++++++++++++++-----
> > include/linux/virtio.h | 8 ++++++++
> > 2 files changed, 28 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> > index b5a9bf4f45b3..e0422c04c903 100644
> > --- a/drivers/virtio/virtio_ring.c
> > +++ b/drivers/virtio/virtio_ring.c
> > @@ -2442,14 +2442,10 @@ struct virtqueue *vring_new_virtqueue(unsigned int index,
> > }
> > EXPORT_SYMBOL_GPL(vring_new_virtqueue);
> >
> > -void vring_del_virtqueue(struct virtqueue *_vq)
> > +static void __vring_free(struct virtqueue *_vq)
> > {
> > struct vring_virtqueue *vq = to_vvq(_vq);
> >
> > - spin_lock(&vq->vq.vdev->vqs_list_lock);
> > - list_del(&_vq->list);
> > - spin_unlock(&vq->vq.vdev->vqs_list_lock);
> > -
> > if (vq->we_own_ring) {
> > if (vq->packed_ring) {
> > vring_free_queue(vq->vq.vdev,
> > @@ -2480,6 +2476,25 @@ void vring_del_virtqueue(struct virtqueue *_vq)
> > kfree(vq->split.desc_state);
> > kfree(vq->split.desc_extra);
> > }
> > +}
> > +
> > +static void vring_free(struct virtqueue *vq)
> > +{
> > + __vring_free(vq);
> > + vq->reset = VIRTIO_VQ_RESET_STEP_VRING_RELEASE;
> > +}
> > +
> > +void vring_del_virtqueue(struct virtqueue *_vq)
> > +{
> > + struct vring_virtqueue *vq = to_vvq(_vq);
> > +
> > + spin_lock(&vq->vq.vdev->vqs_list_lock);
> > + list_del(&_vq->list);
> > + spin_unlock(&vq->vq.vdev->vqs_list_lock);
> > +
> > + if (_vq->reset != VIRTIO_VQ_RESET_STEP_VRING_RELEASE)
> > + __vring_free(_vq);
> > +
> > kfree(vq);
> > }
> > EXPORT_SYMBOL_GPL(vring_del_virtqueue);
> > diff --git a/include/linux/virtio.h b/include/linux/virtio.h
> > index d59adc4be068..e3714e6db330 100644
> > --- a/include/linux/virtio.h
> > +++ b/include/linux/virtio.h
> > @@ -10,6 +10,13 @@
> > #include <linux/mod_devicetable.h>
> > #include <linux/gfp.h>
> >
> > +enum virtio_vq_reset_step {
> > + VIRTIO_VQ_RESET_STEP_NONE,
> > + VIRTIO_VQ_RESET_STEP_DEVICE,
> > + VIRTIO_VQ_RESET_STEP_VRING_RELEASE,
> > + VIRTIO_VQ_RESET_STEP_VRING_ATTACH,
> > +};
>
>
> This part looks not related to the subject.
>
> And it needs detail documentation on this.
>
> But I wonder how useful it is, anyway we can check the reset status via
> transport specific way and in the future we may want to do more than
> just resizing (e.g PASID).
I will try and remove it from here.
Thanks.
>
> Thanks
>
>
> > +
> > /**
> > * virtqueue - a queue to register buffers for sending or receiving.
> > * @list: the chain of virtqueues for this device
> > @@ -33,6 +40,7 @@ struct virtqueue {
> > unsigned int num_free;
> > unsigned int num_max;
> > void *priv;
> > + enum virtio_vq_reset_step reset;
> > };
> >
> > int virtqueue_add_outbuf(struct virtqueue *vq,
>
Powered by blists - more mailing lists