* [PATCH] virtio_ring: check desc == NULL when packed and indirect
@ 2021-09-27 3:06 Xuan Zhuo
2021-09-27 3:20 ` Jason Wang
2021-09-27 9:36 ` Michael S. Tsirkin
0 siblings, 2 replies; 5+ messages in thread
From: Xuan Zhuo @ 2021-09-27 3:06 UTC (permalink / raw)
To: virtualization; +Cc: David S. Miller, Tiwei Bie, Michael S. Tsirkin
In the case of packed, use indirect desc, since desc is allocated by
kmalloc_array(), we should check whether its return value is NULL.
Fixes: 1ce9e6055fa ("virtio_ring: introduce packed ring support")
Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
---
drivers/virtio/virtio_ring.c | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index dd95dfd85e98..7dd381eae725 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -1050,21 +1050,20 @@ static struct vring_packed_desc *alloc_indirect_packed(unsigned int total_sg,
}
static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
- struct scatterlist *sgs[],
- unsigned int total_sg,
- unsigned int out_sgs,
- unsigned int in_sgs,
- void *data,
- gfp_t gfp)
+ struct scatterlist *sgs[],
+ struct vring_packed_desc *desc,
+ unsigned int total_sg,
+ unsigned int out_sgs,
+ unsigned int in_sgs,
+ void *data,
+ gfp_t gfp)
{
- struct vring_packed_desc *desc;
struct scatterlist *sg;
unsigned int i, n, err_idx;
u16 head, id;
dma_addr_t addr;
head = vq->packed.next_avail_idx;
- desc = alloc_indirect_packed(total_sg, gfp);
if (unlikely(vq->vq.num_free < 1)) {
pr_debug("Can't add buf len 1 - avail = 0\n");
@@ -1191,9 +1190,15 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,
BUG_ON(total_sg == 0);
- if (virtqueue_use_indirect(_vq, total_sg))
- return virtqueue_add_indirect_packed(vq, sgs, total_sg,
- out_sgs, in_sgs, data, gfp);
+ if (virtqueue_use_indirect(_vq, total_sg)) {
+ desc = alloc_indirect_packed(total_sg, gfp);
+ if (desc) {
+ return virtqueue_add_indirect_packed(vq, sgs, desc,
+ total_sg,
+ out_sgs, in_sgs,
+ data, gfp);
+ }
+ }
head = vq->packed.next_avail_idx;
avail_used_flags = vq->packed.avail_used_flags;
--
2.31.0
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] virtio_ring: check desc == NULL when packed and indirect
2021-09-27 3:06 [PATCH] virtio_ring: check desc == NULL when packed and indirect Xuan Zhuo
@ 2021-09-27 3:20 ` Jason Wang
2021-09-27 3:25 ` Xuan Zhuo
2021-09-27 9:36 ` Michael S. Tsirkin
1 sibling, 1 reply; 5+ messages in thread
From: Jason Wang @ 2021-09-27 3:20 UTC (permalink / raw)
To: Xuan Zhuo; +Cc: Michael S. Tsirkin, David S. Miller, Tiwei Bie, virtualization
On Mon, Sep 27, 2021 at 11:06 AM Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote:
>
> In the case of packed, use indirect desc, since desc is allocated by
> kmalloc_array(), we should check whether its return value is NULL.
>
> Fixes: 1ce9e6055fa ("virtio_ring: introduce packed ring support")
> Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> ---
> drivers/virtio/virtio_ring.c | 27 ++++++++++++++++-----------
> 1 file changed, 16 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index dd95dfd85e98..7dd381eae725 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -1050,21 +1050,20 @@ static struct vring_packed_desc *alloc_indirect_packed(unsigned int total_sg,
> }
>
> static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
> - struct scatterlist *sgs[],
> - unsigned int total_sg,
> - unsigned int out_sgs,
> - unsigned int in_sgs,
> - void *data,
> - gfp_t gfp)
> + struct scatterlist *sgs[],
> + struct vring_packed_desc *desc,
> + unsigned int total_sg,
> + unsigned int out_sgs,
> + unsigned int in_sgs,
> + void *data,
> + gfp_t gfp)
It looks to me the style changes are mixed with bug fix here.
> {
> - struct vring_packed_desc *desc;
> struct scatterlist *sg;
> unsigned int i, n, err_idx;
> u16 head, id;
> dma_addr_t addr;
>
> head = vq->packed.next_avail_idx;
> - desc = alloc_indirect_packed(total_sg, gfp);
>
> if (unlikely(vq->vq.num_free < 1)) {
> pr_debug("Can't add buf len 1 - avail = 0\n");
> @@ -1191,9 +1190,15 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,
>
> BUG_ON(total_sg == 0);
>
> - if (virtqueue_use_indirect(_vq, total_sg))
> - return virtqueue_add_indirect_packed(vq, sgs, total_sg,
> - out_sgs, in_sgs, data, gfp);
> + if (virtqueue_use_indirect(_vq, total_sg)) {
> + desc = alloc_indirect_packed(total_sg, gfp);
> + if (desc) {
> + return virtqueue_add_indirect_packed(vq, sgs, desc,
> + total_sg,
> + out_sgs, in_sgs,
> + data, gfp);
> + }
> + }
Any reason that we can't fix virtqueue_add_indirect_packed()? It can
help to reduce the changeset and ease the backport.
Thanks
>
> head = vq->packed.next_avail_idx;
> avail_used_flags = vq->packed.avail_used_flags;
> --
> 2.31.0
>
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] virtio_ring: check desc == NULL when packed and indirect
2021-09-27 3:20 ` Jason Wang
@ 2021-09-27 3:25 ` Xuan Zhuo
2021-09-27 3:43 ` Jason Wang
0 siblings, 1 reply; 5+ messages in thread
From: Xuan Zhuo @ 2021-09-27 3:25 UTC (permalink / raw)
To: Jason Wang; +Cc: Michael S. Tsirkin, David S. Miller, Tiwei Bie, virtualization
On Mon, 27 Sep 2021 11:20:16 +0800, Jason Wang <jasowang@redhat.com> wrote:
> On Mon, Sep 27, 2021 at 11:06 AM Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote:
> >
> > In the case of packed, use indirect desc, since desc is allocated by
> > kmalloc_array(), we should check whether its return value is NULL.
> >
> > Fixes: 1ce9e6055fa ("virtio_ring: introduce packed ring support")
> > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > ---
> > drivers/virtio/virtio_ring.c | 27 ++++++++++++++++-----------
> > 1 file changed, 16 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> > index dd95dfd85e98..7dd381eae725 100644
> > --- a/drivers/virtio/virtio_ring.c
> > +++ b/drivers/virtio/virtio_ring.c
> > @@ -1050,21 +1050,20 @@ static struct vring_packed_desc *alloc_indirect_packed(unsigned int total_sg,
> > }
> >
> > static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
> > - struct scatterlist *sgs[],
> > - unsigned int total_sg,
> > - unsigned int out_sgs,
> > - unsigned int in_sgs,
> > - void *data,
> > - gfp_t gfp)
> > + struct scatterlist *sgs[],
> > + struct vring_packed_desc *desc,
> > + unsigned int total_sg,
> > + unsigned int out_sgs,
> > + unsigned int in_sgs,
> > + void *data,
> > + gfp_t gfp)
>
> It looks to me the style changes are mixed with bug fix here.
I will make a separate patch for the next version.
>
> > {
> > - struct vring_packed_desc *desc;
> > struct scatterlist *sg;
> > unsigned int i, n, err_idx;
> > u16 head, id;
> > dma_addr_t addr;
> >
> > head = vq->packed.next_avail_idx;
> > - desc = alloc_indirect_packed(total_sg, gfp);
> >
> > if (unlikely(vq->vq.num_free < 1)) {
> > pr_debug("Can't add buf len 1 - avail = 0\n");
> > @@ -1191,9 +1190,15 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,
> >
> > BUG_ON(total_sg == 0);
> >
> > - if (virtqueue_use_indirect(_vq, total_sg))
> > - return virtqueue_add_indirect_packed(vq, sgs, total_sg,
> > - out_sgs, in_sgs, data, gfp);
> > + if (virtqueue_use_indirect(_vq, total_sg)) {
> > + desc = alloc_indirect_packed(total_sg, gfp);
> > + if (desc) {
> > + return virtqueue_add_indirect_packed(vq, sgs, desc,
> > + total_sg,
> > + out_sgs, in_sgs,
> > + data, gfp);
> > + }
> > + }
>
> Any reason that we can't fix virtqueue_add_indirect_packed()? It can
> help to reduce the changeset and ease the backport.
The purpose of this is to fall back to not using indirect when
alloc_indirect_packed returns NULL.
If we check the return value of alloc_indirect_packed() in
virtqueue_add_indirect_packed(), then MUST check the error returned by
virtqueue_add_indirect_packed() to determine whether to fall back to the mode
that does not use indirect.
Thanks.
>
> Thanks
>
> >
> > head = vq->packed.next_avail_idx;
> > avail_used_flags = vq->packed.avail_used_flags;
> > --
> > 2.31.0
> >
>
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] virtio_ring: check desc == NULL when packed and indirect
2021-09-27 3:25 ` Xuan Zhuo
@ 2021-09-27 3:43 ` Jason Wang
0 siblings, 0 replies; 5+ messages in thread
From: Jason Wang @ 2021-09-27 3:43 UTC (permalink / raw)
To: Xuan Zhuo; +Cc: Michael S. Tsirkin, David S. Miller, Tiwei Bie, virtualization
On Mon, Sep 27, 2021 at 11:29 AM Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote:
>
> On Mon, 27 Sep 2021 11:20:16 +0800, Jason Wang <jasowang@redhat.com> wrote:
> > On Mon, Sep 27, 2021 at 11:06 AM Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote:
> > >
> > > In the case of packed, use indirect desc, since desc is allocated by
> > > kmalloc_array(), we should check whether its return value is NULL.
> > >
> > > Fixes: 1ce9e6055fa ("virtio_ring: introduce packed ring support")
> > > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > > ---
> > > drivers/virtio/virtio_ring.c | 27 ++++++++++++++++-----------
> > > 1 file changed, 16 insertions(+), 11 deletions(-)
> > >
> > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> > > index dd95dfd85e98..7dd381eae725 100644
> > > --- a/drivers/virtio/virtio_ring.c
> > > +++ b/drivers/virtio/virtio_ring.c
> > > @@ -1050,21 +1050,20 @@ static struct vring_packed_desc *alloc_indirect_packed(unsigned int total_sg,
> > > }
> > >
> > > static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
> > > - struct scatterlist *sgs[],
> > > - unsigned int total_sg,
> > > - unsigned int out_sgs,
> > > - unsigned int in_sgs,
> > > - void *data,
> > > - gfp_t gfp)
> > > + struct scatterlist *sgs[],
> > > + struct vring_packed_desc *desc,
> > > + unsigned int total_sg,
> > > + unsigned int out_sgs,
> > > + unsigned int in_sgs,
> > > + void *data,
> > > + gfp_t gfp)
> >
> > It looks to me the style changes are mixed with bug fix here.
>
>
> I will make a separate patch for the next version.
Please make it a patch on top of the fix to ease the backport.
>
> >
> > > {
> > > - struct vring_packed_desc *desc;
> > > struct scatterlist *sg;
> > > unsigned int i, n, err_idx;
> > > u16 head, id;
> > > dma_addr_t addr;
> > >
> > > head = vq->packed.next_avail_idx;
> > > - desc = alloc_indirect_packed(total_sg, gfp);
> > >
> > > if (unlikely(vq->vq.num_free < 1)) {
> > > pr_debug("Can't add buf len 1 - avail = 0\n");
> > > @@ -1191,9 +1190,15 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,
> > >
> > > BUG_ON(total_sg == 0);
> > >
> > > - if (virtqueue_use_indirect(_vq, total_sg))
> > > - return virtqueue_add_indirect_packed(vq, sgs, total_sg,
> > > - out_sgs, in_sgs, data, gfp);
> > > + if (virtqueue_use_indirect(_vq, total_sg)) {
> > > + desc = alloc_indirect_packed(total_sg, gfp);
> > > + if (desc) {
> > > + return virtqueue_add_indirect_packed(vq, sgs, desc,
> > > + total_sg,
> > > + out_sgs, in_sgs,
> > > + data, gfp);
> > > + }
> > > + }
> >
> > Any reason that we can't fix virtqueue_add_indirect_packed()? It can
> > help to reduce the changeset and ease the backport.
>
> The purpose of this is to fall back to not using indirect when
> alloc_indirect_packed returns NULL.
>
> If we check the return value of alloc_indirect_packed() in
> virtqueue_add_indirect_packed(), then MUST check the error returned by
> virtqueue_add_indirect_packed() to determine whether to fall back to the mode
> that does not use indirect.
Right, this aligns the behaviour of the split path. But please
describe this in the commit log.
Thanks
>
> Thanks.
>
> >
> > Thanks
> >
> > >
> > > head = vq->packed.next_avail_idx;
> > > avail_used_flags = vq->packed.avail_used_flags;
> > > --
> > > 2.31.0
> > >
> >
>
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] virtio_ring: check desc == NULL when packed and indirect
2021-09-27 3:06 [PATCH] virtio_ring: check desc == NULL when packed and indirect Xuan Zhuo
2021-09-27 3:20 ` Jason Wang
@ 2021-09-27 9:36 ` Michael S. Tsirkin
1 sibling, 0 replies; 5+ messages in thread
From: Michael S. Tsirkin @ 2021-09-27 9:36 UTC (permalink / raw)
To: Xuan Zhuo; +Cc: David S. Miller, Tiwei Bie, virtualization
On Mon, Sep 27, 2021 at 11:06:18AM +0800, Xuan Zhuo wrote:
> In the case of packed, use indirect desc, since desc is allocated by
> kmalloc_array(), we should check whether its return value is NULL.
>
> Fixes: 1ce9e6055fa ("virtio_ring: introduce packed ring support")
> Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> ---
> drivers/virtio/virtio_ring.c | 27 ++++++++++++++++-----------
> 1 file changed, 16 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index dd95dfd85e98..7dd381eae725 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -1050,21 +1050,20 @@ static struct vring_packed_desc *alloc_indirect_packed(unsigned int total_sg,
> }
>
> static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
> - struct scatterlist *sgs[],
> - unsigned int total_sg,
> - unsigned int out_sgs,
> - unsigned int in_sgs,
> - void *data,
> - gfp_t gfp)
> + struct scatterlist *sgs[],
> + struct vring_packed_desc *desc,
> + unsigned int total_sg,
> + unsigned int out_sgs,
> + unsigned int in_sgs,
> + void *data,
> + gfp_t gfp)
> {
> - struct vring_packed_desc *desc;
> struct scatterlist *sg;
> unsigned int i, n, err_idx;
> u16 head, id;
> dma_addr_t addr;
>
> head = vq->packed.next_avail_idx;
> - desc = alloc_indirect_packed(total_sg, gfp);
>
> if (unlikely(vq->vq.num_free < 1)) {
> pr_debug("Can't add buf len 1 - avail = 0\n");
> @@ -1191,9 +1190,15 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,
>
> BUG_ON(total_sg == 0);
>
> - if (virtqueue_use_indirect(_vq, total_sg))
> - return virtqueue_add_indirect_packed(vq, sgs, total_sg,
> - out_sgs, in_sgs, data, gfp);
> + if (virtqueue_use_indirect(_vq, total_sg)) {
> + desc = alloc_indirect_packed(total_sg, gfp);
> + if (desc) {
> + return virtqueue_add_indirect_packed(vq, sgs, desc,
> + total_sg,
> + out_sgs, in_sgs,
> + data, gfp);
> + }
Eschew {} for a single statement if conditions pls.
> + }
>
> head = vq->packed.next_avail_idx;
> avail_used_flags = vq->packed.avail_used_flags;
> --
> 2.31.0
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-09-27 9:36 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-27 3:06 [PATCH] virtio_ring: check desc == NULL when packed and indirect Xuan Zhuo
2021-09-27 3:20 ` Jason Wang
2021-09-27 3:25 ` Xuan Zhuo
2021-09-27 3:43 ` Jason Wang
2021-09-27 9:36 ` Michael S. Tsirkin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.