vhost: compilation fix for GCC-12

Message ID 20220901084943.3075710-1-amitprakashs@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series vhost: compilation fix for GCC-12 |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Testing success Testing PASS

Commit Message

Amit Prakash Shukla Sept. 1, 2022, 8:49 a.m. UTC
  ../lib/vhost/virtio_net.c:941:35: error:
		'buf_vec[0].buf_len' may be used uninitialized
		[-Werror=maybe-uninitialized]
  941 |         buf_len = buf_vec[vec_idx].buf_len;
      |                   ~~~~~~~~~~~~~~~~^~~~~~~~
../lib/vhost/virtio_net.c: In function 'virtio_dev_rx_packed':
../lib/vhost/virtio_net.c:1285:27: note: 'buf_vec' declared here
 1285 |         struct buf_vector buf_vec[BUF_VECTOR_MAX];
      |                           ^~~~~~~
cc1: all warnings being treated as errors

Fixes: 93520085efda ("vhost: add packed ring single enqueue")
Cc: stable@dpdk.org

Signed-off-by: Amit Prakash Shukla <amitprakashs@marvell.com>
---
 lib/vhost/virtio_net.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
  

Comments

Ruifeng Wang Sept. 2, 2022, 7:23 a.m. UTC | #1
> -----Original Message-----
> From: Amit Prakash Shukla <amitprakashs@marvell.com>
> Sent: Thursday, September 1, 2022 4:50 PM
> To: Maxime Coquelin <maxime.coquelin@redhat.com>; Chenbo Xia <chenbo.xia@intel.com>
> Cc: dev@dpdk.org; jerinj@marvell.com; stable@dpdk.org; Amit Prakash Shukla
> <amitprakashs@marvell.com>
> Subject: [PATCH] vhost: compilation fix for GCC-12
> 
> ../lib/vhost/virtio_net.c:941:35: error:
> 		'buf_vec[0].buf_len' may be used uninitialized
> 		[-Werror=maybe-uninitialized]
>   941 |         buf_len = buf_vec[vec_idx].buf_len;
>       |                   ~~~~~~~~~~~~~~~~^~~~~~~~
> ../lib/vhost/virtio_net.c: In function 'virtio_dev_rx_packed':
> ../lib/vhost/virtio_net.c:1285:27: note: 'buf_vec' declared here
>  1285 |         struct buf_vector buf_vec[BUF_VECTOR_MAX];
>       |                           ^~~~~~~
> cc1: all warnings being treated as errors
> 
> Fixes: 93520085efda ("vhost: add packed ring single enqueue")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Amit Prakash Shukla <amitprakashs@marvell.com>
> ---
>  lib/vhost/virtio_net.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index b3d954aab4..0220bc923c
> 100644
> --- a/lib/vhost/virtio_net.c
> +++ b/lib/vhost/virtio_net.c
> @@ -1069,6 +1069,12 @@ vhost_enqueue_single_packed(struct virtio_net *dev,
>  	else
>  		max_tries = 1;
> 
> +	/* To avoid GCC-12 warning.
> +	 * GCC-12 is not evaluating sizeof at compile time.
Is this a compiler behavior change against previous versions?
I tried to find some clue from gcc-12 doc but got nothing. Can you point me to any material?

> +	 */
> +	if (unlikely(size == 0))
> +		return -1;
> +
>  	while (size > 0) {
Change 'while(){}' to 'do{}while()' can be a simpler solution. What do you think?

Thanks.

>  		/*
>  		 * if we tried all available ring items, and still @@ -1574,6 +1580,12 @@
> vhost_enqueue_async_packed(struct virtio_net *dev,
>  	else
>  		max_tries = 1;
> 
> +	/* To avoid GCC-12 warning.
> +	 * GCC-12 is not evaluating sizeof at compile time.
> +	 */
> +	if (unlikely(size == 0))
> +		return -1;
> +
>  	while (size > 0) {
>  		/*
>  		 * if we tried all available ring items, and still
> --
> 2.25.1
  
Amit Prakash Shukla Sept. 2, 2022, 11:57 a.m. UTC | #2
Thanks Ruifeng for the code review and feedback. Please find my response inline.

> -----Original Message-----
> From: Ruifeng Wang <Ruifeng.Wang@arm.com>
> Sent: Friday, September 2, 2022 12:54 PM
> To: Amit Prakash Shukla <amitprakashs@marvell.com>; Maxime Coquelin
> <maxime.coquelin@redhat.com>; Chenbo Xia <chenbo.xia@intel.com>
> Cc: dev@dpdk.org; Jerin Jacob Kollanukkaran <jerinj@marvell.com>;
> stable@dpdk.org; nd <nd@arm.com>
> Subject: [EXT] RE: [PATCH] vhost: compilation fix for GCC-12
> 
> External Email
> 
> ----------------------------------------------------------------------
> > -----Original Message-----
> > From: Amit Prakash Shukla <amitprakashs@marvell.com>
> > Sent: Thursday, September 1, 2022 4:50 PM
> > To: Maxime Coquelin <maxime.coquelin@redhat.com>; Chenbo Xia
> > <chenbo.xia@intel.com>
> > Cc: dev@dpdk.org; jerinj@marvell.com; stable@dpdk.org; Amit Prakash
> > Shukla <amitprakashs@marvell.com>
> > Subject: [PATCH] vhost: compilation fix for GCC-12
> >
> > ../lib/vhost/virtio_net.c:941:35: error:
> > 		'buf_vec[0].buf_len' may be used uninitialized
> > 		[-Werror=maybe-uninitialized]
> >   941 |         buf_len = buf_vec[vec_idx].buf_len;
> >       |                   ~~~~~~~~~~~~~~~~^~~~~~~~
> > ../lib/vhost/virtio_net.c: In function 'virtio_dev_rx_packed':
> > ../lib/vhost/virtio_net.c:1285:27: note: 'buf_vec' declared here
> >  1285 |         struct buf_vector buf_vec[BUF_VECTOR_MAX];
> >       |                           ^~~~~~~
> > cc1: all warnings being treated as errors
> >
> > Fixes: 93520085efda ("vhost: add packed ring single enqueue")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Amit Prakash Shukla <amitprakashs@marvell.com>
> > ---
> >  lib/vhost/virtio_net.c | 12 ++++++++++++
> >  1 file changed, 12 insertions(+)
> >
> > diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index
> > b3d954aab4..0220bc923c
> > 100644
> > --- a/lib/vhost/virtio_net.c
> > +++ b/lib/vhost/virtio_net.c
> > @@ -1069,6 +1069,12 @@ vhost_enqueue_single_packed(struct virtio_net
> *dev,
> >  	else
> >  		max_tries = 1;
> >
> > +	/* To avoid GCC-12 warning.
> > +	 * GCC-12 is not evaluating sizeof at compile time.
> Is this a compiler behavior change against previous versions?
> I tried to find some clue from gcc-12 doc but got nothing. Can you point me to
> any material?
Apologies for the wrong wordings in the comment. In the comment I mean, it seems like 
point at which sizeof gets evaluated during compilation has changed. I am not sure on it though.
I too could not find documentation regarding the same.

> 
> > +	 */
> > +	if (unlikely(size == 0))
> > +		return -1;
> > +
> >  	while (size > 0) {
> Change 'while(){}' to 'do{}while()' can be a simpler solution. What do you
> think?
I agree, solution suggested by you is better than the one in patch. I will make the suggested
changes as part of v2. Thanks.

> 
> Thanks.
> 
> >  		/*
> >  		 * if we tried all available ring items, and still @@ -1574,6
> > +1580,12 @@ vhost_enqueue_async_packed(struct virtio_net *dev,
> >  	else
> >  		max_tries = 1;
> >
> > +	/* To avoid GCC-12 warning.
> > +	 * GCC-12 is not evaluating sizeof at compile time.
> > +	 */
> > +	if (unlikely(size == 0))
> > +		return -1;
> > +
> >  	while (size > 0) {
> >  		/*
> >  		 * if we tried all available ring items, and still
> > --
> > 2.25.1
  

Patch

diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index b3d954aab4..0220bc923c 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -1069,6 +1069,12 @@  vhost_enqueue_single_packed(struct virtio_net *dev,
 	else
 		max_tries = 1;
 
+	/* To avoid GCC-12 warning.
+	 * GCC-12 is not evaluating sizeof at compile time.
+	 */
+	if (unlikely(size == 0))
+		return -1;
+
 	while (size > 0) {
 		/*
 		 * if we tried all available ring items, and still
@@ -1574,6 +1580,12 @@  vhost_enqueue_async_packed(struct virtio_net *dev,
 	else
 		max_tries = 1;
 
+	/* To avoid GCC-12 warning.
+	 * GCC-12 is not evaluating sizeof at compile time.
+	 */
+	if (unlikely(size == 0))
+		return -1;
+
 	while (size > 0) {
 		/*
 		 * if we tried all available ring items, and still