Hello, On Thu, Aug 25, 2022 at 2:37 PM zhoumin <zhou...@loongson.cn> wrote: > > > > I had seen a similar warning during 22.07 when cross compiling but did > > not investigate much. > > The patch that I had written at the time was: > > > > diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c > > index 35fa4670fd..9446e33aa7 100644 > > --- a/lib/vhost/virtio_net.c > > +++ b/lib/vhost/virtio_net.c > > @@ -1153,7 +1153,7 @@ mbuf_to_desc(struct virtio_net *dev, struct > > vhost_virtqueue *vq, > > struct virtio_net_hdr_mrg_rxbuf tmp_hdr, *hdr = NULL; > > struct vhost_async *async = vq->async; > > > > - if (unlikely(m == NULL)) > > + if (unlikely(m == NULL || nr_vec == 0)) > > return -1; > > > > buf_addr = buf_vec[vec_idx].buf_addr; > > > > > > Could you see if this fixes your issue? > > > > If it is the case, it may be worth better understanding what bothers > > the compiler in the current code. > > > > > I have verified that the solution you proposed here is effective. It can > eliminate the GCC warning. But I don't know what this change means for > the compiler. > > From the programmer's point of view, we can know the binding relationship > between the `nr_vec` variable and the `buf_vec` array. we can use > "nr_vec == 0" to determine the validity of the `buf_vec[0]`. But, I'm not > sure if the compiler knows about it. I cannot explain from the GCC's point > of view why this modification can eliminate the warning. > > However, in terms of correctness, this modification is very reasonable > because > the `buf_vec[0]` would be invalid if the `nr_vec` variable equals to > zero. In > this case, the function should return. > > In addition, we can see that the `buf_vec` array are also used in function > desc_to_mbuf() from the above calling relationships. Do you think it is > necessary to add a similar check to this function? like this:
Maxime, Chenbo, can you have a look? Thanks! > > diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c > index 9446e33aa7..99233f1759 100644 > --- a/lib/vhost/virtio_net.c > +++ b/lib/vhost/virtio_net.c > @@ -2673,6 +2673,9 @@ desc_to_mbuf(struct virtio_net *dev, struct > vhost_virtqueue *vq, > struct vhost_async *async = vq->async; > struct async_inflight_info *pkts_info; > > + if (unlikely(nr_vec == 0)) > + return -1; > + > buf_addr = buf_vec[vec_idx].buf_addr; > buf_iova = buf_vec[vec_idx].buf_iova; > buf_len = buf_vec[vec_idx].buf_len; > > I expect this compilation warning can be resolved. Because LoongArch > cross-compile tools must be based on GCC 12.1 and this compilation warning > will cause LoongArch CI job to fail. Agreed. -- David Marchand