A recently added error path does not mark ring unused when exiting on OOM, which will lead to BUG on the next entry in debug builds. TODO: refactor code so we have START_USE and END_USE in the same function. Fixes: fc6d70f40b3d ("virtio_ring: check desc == NULL when using indirect with packed") Cc: "Xuan Zhuo" <xuanzhuo at linux.alibaba.com> Cc: Jiasheng Jiang <jiasheng at iscas.ac.cn> Signed-off-by: Michael S. Tsirkin <mst at redhat.com> --- drivers/virtio/virtio_ring.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 028b05d44546..962f1477b1fa 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -1197,8 +1197,10 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq, if (virtqueue_use_indirect(_vq, total_sg)) { err = virtqueue_add_indirect_packed(vq, sgs, total_sg, out_sgs, in_sgs, data, gfp); - if (err != -ENOMEM) + if (err != -ENOMEM) { + END_USE(vq); return err; + } /* fall back on direct */ } -- MST
On Thu, 6 Jan 2022 08:00:48 -0500, Michael S. Tsirkin <mst at redhat.com> wrote:> A recently added error path does not mark ring unused when exiting on > OOM, which will lead to BUG on the next entry in debug builds. > > TODO: refactor code so we have START_USE and END_USE in the same function. > > Fixes: fc6d70f40b3d ("virtio_ring: check desc == NULL when using indirect with packed") > Cc: "Xuan Zhuo" <xuanzhuo at linux.alibaba.com> > Cc: Jiasheng Jiang <jiasheng at iscas.ac.cn> > Signed-off-by: Michael S. Tsirkin <mst at redhat.com>LGTM Reviewed-by: Xuan Zhuo <xuanzhuo at linux.alibaba.com>> --- > drivers/virtio/virtio_ring.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index 028b05d44546..962f1477b1fa 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -1197,8 +1197,10 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq, > if (virtqueue_use_indirect(_vq, total_sg)) { > err = virtqueue_add_indirect_packed(vq, sgs, total_sg, out_sgs, > in_sgs, data, gfp); > - if (err != -ENOMEM) > + if (err != -ENOMEM) { > + END_USE(vq); > return err; > + } > > /* fall back on direct */ > } > -- > MST >
On Thu, Jan 6, 2022 at 9:00 PM Michael S. Tsirkin <mst at redhat.com> wrote:> > A recently added error path does not mark ring unused when exiting on > OOM, which will lead to BUG on the next entry in debug builds. > > TODO: refactor code so we have START_USE and END_USE in the same function. > > Fixes: fc6d70f40b3d ("virtio_ring: check desc == NULL when using indirect with packed") > Cc: "Xuan Zhuo" <xuanzhuo at linux.alibaba.com> > Cc: Jiasheng Jiang <jiasheng at iscas.ac.cn> > Signed-off-by: Michael S. Tsirkin <mst at redhat.com>Acked-by: Jason Wang <jasowang at redhat.com>> --- > drivers/virtio/virtio_ring.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index 028b05d44546..962f1477b1fa 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -1197,8 +1197,10 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq, > if (virtqueue_use_indirect(_vq, total_sg)) { > err = virtqueue_add_indirect_packed(vq, sgs, total_sg, out_sgs, > in_sgs, data, gfp); > - if (err != -ENOMEM) > + if (err != -ENOMEM) { > + END_USE(vq); > return err; > + } > > /* fall back on direct */ > } > -- > MST >