From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 594E0A0545; Thu, 25 Aug 2022 16:09:07 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 465EA4282D; Thu, 25 Aug 2022 16:09:07 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id E9A4A415D7 for ; Thu, 25 Aug 2022 16:09:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661436544; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FGAGglOQV9e8w+XtkQNnTrMnVD36p2IIr9a9bgfl8E4=; b=MCGY6ZWX6LtXBtApvHC8fDwNDxD0UQAr2N9KR0VndcQara70Dzi/uJ0DdBj6MiUZQEk2De Ik0akfQklp2x9R4SjjwM9fFslpzDL1QoMnjstlyjFMqMFK/PY+in1mzVLLNHGVH0rBicwX bHvOOtxKGRDml4stpLagDtFEOgXp2oM= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-588-gEtC20PzN2SAJuCBVfOq4w-1; Thu, 25 Aug 2022 10:09:03 -0400 X-MC-Unique: gEtC20PzN2SAJuCBVfOq4w-1 Received: by mail-lj1-f200.google.com with SMTP id x10-20020a2ea98a000000b00261b06603cfso4121876ljq.17 for ; Thu, 25 Aug 2022 07:09:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=FGAGglOQV9e8w+XtkQNnTrMnVD36p2IIr9a9bgfl8E4=; b=mIddh0FpKLTRcMUsB56zNAsvY6hmn5Ck8i/hkV7SnNrJbwD2Wd7v2SadZCqhF5SrYs Of6Pjg2juHf/63Wi4UdK7Vic6/KlY+cpG5u+jhBAux2bFydXGF87GSUeefyj7dTpH6Y6 CZx5OFA6q8JCbP1uY2ZqMKP5wsSvBArDN0uH4bmv5f3eatuXa7yhICyTHm9halaOMG/s 1zFPQCF8k61BAdUypANdHV85xOH+0X7D+YPu+a6rpSqmZBvOhFTdcrAsiNRlphuquX2m LVvUx6Q/+V9kX0PF1iyo2K4FMszoayKx669VPUQKWC0yDphI/IFbEF+avxnzJ3o/PgPj 1GMw== X-Gm-Message-State: ACgBeo1+7QADEDmakmAwYK3dWIITWfbY/IoNU5M2bwj711KUH8HiVuF1 nOjG5SG+93QT39ybQgmaztbb8RgWvE1zVfDaWuAs9aup74X4a5txxaZkQEPdPX5hDZVjDsOsyHb clhgW3Z47Zx+QxAFtvvc= X-Received: by 2002:a2e:8541:0:b0:261:b44b:1a8b with SMTP id u1-20020a2e8541000000b00261b44b1a8bmr1247667ljj.46.1661436541920; Thu, 25 Aug 2022 07:09:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR7P+2ufMz/17MOwySBodvCZTJ/v4QW1rC4hwnLvK8sHrS5d64o2VGcO1HOjvEJJokXNUcemDJnsc2pd1K33z/U= X-Received: by 2002:a2e:8541:0:b0:261:b44b:1a8b with SMTP id u1-20020a2e8541000000b00261b44b1a8bmr1247663ljj.46.1661436541710; Thu, 25 Aug 2022 07:09:01 -0700 (PDT) MIME-Version: 1.0 References: <20220822074233.209414-1-zhoumin@loongson.cn> In-Reply-To: From: David Marchand Date: Thu, 25 Aug 2022 16:08:50 +0200 Message-ID: Subject: Re: [PATCH v1] vhost: fix build To: zhoumin , "Xia, Chenbo" , Maxime Coquelin Cc: dev , maobibo@loongson.cn X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Hello, On Thu, Aug 25, 2022 at 2:37 PM zhoumin 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