From: David Marchand <david.marchand@redhat.com>
To: zhoumin <zhoumin@loongson.cn>,
"Xia, Chenbo" <chenbo.xia@intel.com>,
Maxime Coquelin <maxime.coquelin@redhat.com>
Cc: dev <dev@dpdk.org>, maobibo@loongson.cn
Subject: Re: [PATCH v1] vhost: fix build
Date: Thu, 25 Aug 2022 16:08:50 +0200 [thread overview]
Message-ID: <CAJFAV8zqmRFcAGxZPa4sK=c_sAFoTOZMSXf-Kb93UvboLdNscQ@mail.gmail.com> (raw)
In-Reply-To: <b64cde82-62c9-56df-4e71-411bd8b0a606@loongson.cn>
Hello,
On Thu, Aug 25, 2022 at 2:37 PM zhoumin <zhoumin@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
prev parent reply other threads:[~2022-08-25 14:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-22 7:42 Min Zhou
2022-08-24 0:45 ` zhoumin
2022-08-24 14:09 ` David Marchand
2022-08-25 12:36 ` zhoumin
2022-08-25 14:08 ` David Marchand [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAJFAV8zqmRFcAGxZPa4sK=c_sAFoTOZMSXf-Kb93UvboLdNscQ@mail.gmail.com' \
--to=david.marchand@redhat.com \
--cc=chenbo.xia@intel.com \
--cc=dev@dpdk.org \
--cc=maobibo@loongson.cn \
--cc=maxime.coquelin@redhat.com \
--cc=zhoumin@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).