From patchwork Wed Apr 10 15:21:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luca Vizzarro X-Patchwork-Id: 139219 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id AC3A143E37; Wed, 10 Apr 2024 17:22:54 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3E3FB4069D; Wed, 10 Apr 2024 17:22:49 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mails.dpdk.org (Postfix) with ESMTP id AD2704021E; Wed, 10 Apr 2024 17:22:46 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E65891480; Wed, 10 Apr 2024 08:23:15 -0700 (PDT) Received: from localhost.localdomain (FVFG51LCQ05N.cambridge.arm.com [10.1.32.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 50C823F766; Wed, 10 Apr 2024 08:22:45 -0700 (PDT) From: Luca Vizzarro To: dev@dpdk.org Cc: luca.boccassi@gmail.com, paul.szczepanek@arm.com, nick.connolly@arm.com, Luca Vizzarro , stable@dpdk.org Subject: [PATCH 1/1] vhost: fix GCC 13 build error Date: Wed, 10 Apr 2024 16:21:01 +0100 Message-Id: <20240410152101.3211244-2-luca.vizzarro@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240410152101.3211244-1-luca.vizzarro@arm.com> References: <20240410152101.3211244-1-luca.vizzarro@arm.com> MIME-Version: 1.0 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 This patch resolves a build error with GCC 13 and arm/aarch32 as targets: In function ‘mbuf_to_desc’, inlined from ‘vhost_enqueue_async_packed’ at ../lib/vhost/virtio_net.c:1828:6, inlined from ‘virtio_dev_rx_async_packed’ at ../lib/vhost/virtio_net.c:1842:6, inlined from ‘virtio_dev_rx_async_submit_packed’ at ../lib/vhost/virtio_net.c:1900:7: ../lib/vhost/virtio_net.c:1159:18: error: ‘buf_vec[0].buf_addr’ may be used uninitialized [-Werror=maybe-uninitialized] 1159 | buf_addr = buf_vec[vec_idx].buf_addr; | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ ../lib/vhost/virtio_net.c:1160:18: error: ‘buf_vec[0].buf_iova’ may be used uninitialized [-Werror=maybe-uninitialized] 1160 | buf_iova = buf_vec[vec_idx].buf_iova; | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ ../lib/vhost/virtio_net.c:1161:35: error: ‘buf_vec[0].buf_len’ may be used uninitialized [-Werror=maybe-uninitialized] 1161 | buf_len = buf_vec[vec_idx].buf_len; | ~~~~~~~~~~~~~~~~^~~~~~~~ GCC complains about the possible runtime path where the while loop which fills buf_vec (in vhost_enqueue_async_packed) is not run. As a consequence it correctly thinks that buf_vec is not initialized while being accessed anyways. This scenario is actually very unlikely as the only way this can occur is if size has overflowed to 0. Meaning that the total packet length would be close to UINT64_MAX (or actually UINT32_MAX). At first glance, the code suggests that this may never happen as the type of size has been changed to 64-bit. For a 32-bit architecture such as arm (e.g. armv7-a) and aarch32, this still happens because the operand types (pkt->pkt_len and sizeof) are 32-bit wide, performing 32-bit arithmetic first (where the overflow can happen) and widening to 64-bit later. The proposed fix simply guarantees to the compiler that the scope which fills buf_vec is accessed at least once, while not disrupting the actual logic. This is based on the assumption that size will always be greater than 0, as suggested by the sizeof, and the packet length will never be as big as UINT32_MAX, and causing an overflow. Fixes: 873e8dad6f49 ("vhost: support packed ring in async datapath") Cc: stable@dpdk.org Signed-off-by: Luca Vizzarro Reviewed-by: Paul Szczepanek Reviewed-by: Nick Connolly Reviewed-by: Maxime Coquelin --- lib/vhost/virtio_net.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index 1359c5fb1f..6a2ca295f5 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -1935,7 +1935,7 @@ vhost_enqueue_async_packed(struct virtio_net *dev, else max_tries = 1; - while (size > 0) { + do { /* * if we tried all available ring items, and still * can't get enough buf, it means something abnormal @@ -1962,7 +1962,7 @@ vhost_enqueue_async_packed(struct virtio_net *dev, avail_idx += desc_count; if (avail_idx >= vq->size) avail_idx -= vq->size; - } + } while (size > 0); if (unlikely(mbuf_to_desc(dev, vq, pkt, buf_vec, nr_vec, *nr_buffers, true) < 0)) return -1;