patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: Luca Vizzarro <luca.vizzarro@arm.com>, dev@dpdk.org
Cc: luca.boccassi@gmail.com, paul.szczepanek@arm.com,
	nick.connolly@arm.com, stable@dpdk.org
Subject: Re: [PATCH 1/1] vhost: fix GCC 13 build error
Date: Thu, 25 Apr 2024 15:44:37 +0200	[thread overview]
Message-ID: <c3421da2-7394-45d3-b77d-b215882585a1@redhat.com> (raw)
In-Reply-To: <20240410152101.3211244-2-luca.vizzarro@arm.com>



On 4/10/24 17:21, Luca Vizzarro wrote:
> 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;
>        |         ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
> <snip>
> ../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;
>        |         ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
> <snip>
> ../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 <luca.vizzarro@arm.com>
> Reviewed-by: Paul Szczepanek <paul.szczepanek@arm.com>
> Reviewed-by: Nick Connolly <nick.connolly@arm.com>
> ---
>   lib/vhost/virtio_net.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime


  reply	other threads:[~2024-04-25 13:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-10 15:21 [PATCH 0/1] fix GCC 13 build errors on 32-bit targets Luca Vizzarro
2024-04-10 15:21 ` [PATCH 1/1] vhost: fix GCC 13 build error Luca Vizzarro
2024-04-25 13:44   ` Maxime Coquelin [this message]
2024-06-12  8:29 ` [PATCH 0/1] fix GCC 13 build errors on 32-bit targets Maxime Coquelin

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=c3421da2-7394-45d3-b77d-b215882585a1@redhat.com \
    --to=maxime.coquelin@redhat.com \
    --cc=dev@dpdk.org \
    --cc=luca.boccassi@gmail.com \
    --cc=luca.vizzarro@arm.com \
    --cc=nick.connolly@arm.com \
    --cc=paul.szczepanek@arm.com \
    --cc=stable@dpdk.org \
    /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).