Skip to contentSkip to conversation

vdpa: fix gcc cvq_isolated uninitialized variable warning

PATCH In review Stefan Hajnoczi 5 participants 6 messages Sep 11, 2023 – Sep 15, 2023 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vdpa: fix gcc cvq_isolated uninitialized variable warning

gcc 13.2.1 emits the following warning:

net/vhost-vdpa.c: In function ‘net_vhost_vdpa_init.constprop’:
net/vhost-vdpa.c:1394:25: error: ‘cvq_isolated’ may be used uninitialized [-Werror=maybe-uninitialized]

   1394 |         s->cvq_isolated = cvq_isolated;
        |         ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
  net/vhost-vdpa.c:1355:9: note: ‘cvq_isolated’ was declared here
   1355 |     int cvq_isolated;
        |         ^~~~~~~~~~~~

cc1: all warnings being treated as errors

Cc Eugenio Pérez <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
Cc Jason Wang <[email protected]>
---
 net/vhost-vdpa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/vhost-vdpa.c +1 -1
index 34202ca009..7eaee841aa 100644
@@ -1352,7 +1352,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
     VhostVDPAState *s;
     int ret = 0;
     assert(name);
-    int cvq_isolated;
+    int cvq_isolated = 0;
 
     if (is_datapath) {
         nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device,
Signature · 1 line
2.41.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 24 lines · Stefan Hajnoczi

gcc 13.2.1 emits the following warning:

net/vhost-vdpa.c: In function ‘net_vhost_vdpa_init.constprop’:

   net/vhost-vdpa.c:1394:25: error: ‘cvq_isolated’ may be used uninitialized [-Werror=maybe-uninitialized]
    1394 |         s->cvq_isolated = cvq_isolated;
         |         ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
   net/vhost-vdpa.c:1355:9: note: ‘cvq_isolated’ was declared here
    1355 |     int cvq_isolated;
         |         ^~~~~~~~~~~~
   cc1: all warnings being treated as errors
Cc Eugenio Pérez <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
Cc Jason Wang <[email protected]>
---
  net/vhost-vdpa.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/vhost-vdpa.c +0 -0
index 34202ca009..7eaee841aa 100644

net/vhost-vdpa.c static NetClientState *net_vhost_vdpa_init(NetClientState *peer, · line 1358

Quoted 8 lines
net/vhost-vdpa.c +1 -1
@@ -1352,7 +1352,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
      VhostVDPAState *s;
      int ret = 0;
      assert(name);
-    int cvq_isolated;
+    int cvq_isolated = 0;
 
      if (is_datapath) {
          nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device,

Alternatively:

-- >8 --

net/vhost-vdpa.c +1 -2
index 34202ca009..218fe0c305 100644
@@ -1352,13 +1352,12 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
     VhostVDPAState *s;
     int ret = 0;
     assert(name);
-    int cvq_isolated;
 
     if (is_datapath) {
         nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device,
                                  name);
     } else {
-        cvq_isolated = vhost_vdpa_probe_cvq_isolation(vdpa_device_fd, features,
+        int cvq_isolated = vhost_vdpa_probe_cvq_isolation(vdpa_device_fd, features,
                                                       queue_pair_index 

* 2,

                                                       errp);
         if (unlikely(cvq_isolated < 0)) {

@@ -1391,7 +1390,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,

         s->vhost_vdpa.shadow_vq_ops = &vhost_vdpa_net_svq_ops;
         s->vhost_vdpa.shadow_vq_ops_opaque = s;

- s->cvq_isolated = cvq_isolated;
+ s->cvq_isolated = true;

---

Whichever you prefer:

#2 lore raw
Quoted 62 lines · Philippe Mathieu-Daudé
Quoted 24 lines · Stefan Hajnoczi

gcc 13.2.1 emits the following warning:

net/vhost-vdpa.c: In function ‘net_vhost_vdpa_init.constprop’:

   net/vhost-vdpa.c:1394:25: error: ‘cvq_isolated’ may be used uninitialized [-Werror=maybe-uninitialized]
    1394 |         s->cvq_isolated = cvq_isolated;
         |         ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
   net/vhost-vdpa.c:1355:9: note: ‘cvq_isolated’ was declared here
    1355 |     int cvq_isolated;
         |         ^~~~~~~~~~~~
   cc1: all warnings being treated as errors
Cc Eugenio Pérez <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
Cc Jason Wang <[email protected]>
---
  net/vhost-vdpa.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/vhost-vdpa.c +0 -0
index 34202ca009..7eaee841aa 100644

net/vhost-vdpa.c static NetClientState *net_vhost_vdpa_init(NetClientState *peer, · line 1358

Quoted 8 lines
net/vhost-vdpa.c +1 -1
@@ -1352,7 +1352,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
      VhostVDPAState *s;
      int ret = 0;
      assert(name);
-    int cvq_isolated;
+    int cvq_isolated = 0;
 
      if (is_datapath) {
          nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device,

Alternatively:

-- >8 --

net/vhost-vdpa.c +1 -2
index 34202ca009..218fe0c305 100644
@@ -1352,13 +1352,12 @@ static NetClientState
 *net_vhost_vdpa_init(NetClientState *peer,
      VhostVDPAState *s;
      int ret = 0;
      assert(name);
-    int cvq_isolated;
 
      if (is_datapath) {
          nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device,
                                   name);
      } else {
-        cvq_isolated = vhost_vdpa_probe_cvq_isolation(vdpa_device_fd,
 features,
+        int cvq_isolated =
 vhost_vdpa_probe_cvq_isolation(vdpa_device_fd, features,

queue_pair_index
* 2,

                                                        errp);
          if (unlikely(cvq_isolated < 0)) {

net/vhost-vdpa.c static NetClientState · line 1394

Quoted 6 lines
net/vhost-vdpa.c +1 -1
@@ -1391,7 +1390,7 @@ static NetClientState
 *net_vhost_vdpa_init(NetClientState *peer,
 
          s->vhost_vdpa.shadow_vq_ops = &vhost_vdpa_net_svq_ops;
          s->vhost_vdpa.shadow_vq_ops_opaque = s;
-        s->cvq_isolated = cvq_isolated;
+        s->cvq_isolated = true;

This is incorrect because the return value of vhost_vdpa_probe_cvq_isolation() is -errno for errors, 0 for no cvq isolation, and 1 for cvq isolation. A variable is still needed to distinguish between no cvq isolation and cvq isolation.

Quoted 8 lines
net/vhost-vdpa.c +0 -1
---
 

Whichever you prefer:

#3 lore raw
Quoted 65 lines · Stefan Hajnoczi
Quoted 64 lines · Philippe Mathieu-Daudé
Quoted 24 lines · Stefan Hajnoczi

gcc 13.2.1 emits the following warning:

net/vhost-vdpa.c: In function ‘net_vhost_vdpa_init.constprop’:
net/vhost-vdpa.c:1394:25: error: ‘cvq_isolated’ may be used uninitialized [-Werror=maybe-uninitialized]
1394 | s->cvq_isolated = cvq_isolated;
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
net/vhost-vdpa.c:1355:9: note: ‘cvq_isolated’ was declared here
1355 | int cvq_isolated;
| ^~~~~~~~~~~~
cc1: all warnings being treated as errors

Cc Eugenio Pérez <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
Cc Jason Wang <[email protected]>
---
   net/vhost-vdpa.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
net/vhost-vdpa.c +0 -0
index 34202ca009..7eaee841aa 100644

net/vhost-vdpa.c static NetClientState *net_vhost_vdpa_init(NetClientState *peer, · line 1358

Quoted 8 lines
net/vhost-vdpa.c +1 -1
@@ -1352,7 +1352,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
       VhostVDPAState *s;
       int ret = 0;
       assert(name);
-    int cvq_isolated;
+    int cvq_isolated = 0;
 
       if (is_datapath) {
           nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device,

Alternatively:

-- >8 --

net/vhost-vdpa.c +1 -2
index 34202ca009..218fe0c305 100644
@@ -1352,13 +1352,12 @@ static NetClientState
 *net_vhost_vdpa_init(NetClientState *peer,
       VhostVDPAState *s;
       int ret = 0;
       assert(name);
-    int cvq_isolated;
 
       if (is_datapath) {
           nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device,
                                    name);
       } else {
-        cvq_isolated = vhost_vdpa_probe_cvq_isolation(vdpa_device_fd,
 features,
+        int cvq_isolated =
 vhost_vdpa_probe_cvq_isolation(vdpa_device_fd, features,

queue_pair_index
* 2,

                                                         errp);
           if (unlikely(cvq_isolated < 0)) {
net/vhost-vdpa.c +0 -0
@@ -1391,7 +1390,7 @@ static NetClientState
 *net_vhost_vdpa_init(NetClientState *peer,
 
Quoted 9 lines

net/vhost-vdpa.c static NetClientState · line 1394

Quoted 4 lines
net/vhost-vdpa.c +1 -1
           s->vhost_vdpa.shadow_vq_ops = &vhost_vdpa_net_svq_ops;
           s->vhost_vdpa.shadow_vq_ops_opaque = s;
-        s->cvq_isolated = cvq_isolated;
+        s->cvq_isolated = true;

This is incorrect because the return value of vhost_vdpa_probe_cvq_isolation() is -errno for errors, 0 for no cvq isolation, and 1 for cvq isolation. A variable is still needed to distinguish between no cvq isolation and cvq isolation.

Oh, I was expecting a boolean for a field named 'cvq_isolated', my bad. R-b stands for your patch.

Regards,

Phil.

Quoted 9 lines
Quoted 9 lines
net/vhost-vdpa.c +0 -1
---
 

Whichever you prefer:

Acked-by on v1 1/1
#4 lore raw
In reply to Stefan Hajnoczi
Quoted 12 lines · Stefan Hajnoczi

gcc 13.2.1 emits the following warning:

net/vhost-vdpa.c: In function ‘net_vhost_vdpa_init.constprop’:
net/vhost-vdpa.c:1394:25: error: ‘cvq_isolated’ may be used uninitialized [-Werror=maybe-uninitialized]

   1394 |         s->cvq_isolated = cvq_isolated;
        |         ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
  net/vhost-vdpa.c:1355:9: note: ‘cvq_isolated’ was declared here
   1355 |     int cvq_isolated;
        |         ^~~~~~~~~~~~

cc1: all warnings being treated as errors

I think GCC is evaluating the case where (queue_pair_index == 0 && !is_datapath), which should be not possible.

If it is useful we can refactor the conditionals so we don't need the variable at that level of the function. If not,

Thanks!

Quoted 24 lines
Cc Eugenio Pérez <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
Cc Jason Wang <[email protected]>
---
 net/vhost-vdpa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/vhost-vdpa.c +1 -2
index 34202ca009..7eaee841aa 100644
@@ -1352,7 +1352,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
     VhostVDPAState *s;
     int ret = 0;
     assert(name);
-    int cvq_isolated;
+    int cvq_isolated = 0;
 
     if (is_datapath) {
         nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device,
--

2.41.0

Acked-by on v1 1/1
#5 lore raw
In reply to Stefan Hajnoczi
Quoted 10 lines · Stefan Hajnoczi

gcc 13.2.1 emits the following warning:

net/vhost-vdpa.c: In function ‘net_vhost_vdpa_init.constprop’:
net/vhost-vdpa.c:1394:25: error: ‘cvq_isolated’ may be used uninitialized [-Werror=maybe-uninitialized]

   1394 |         s->cvq_isolated = cvq_isolated;
        |         ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
  net/vhost-vdpa.c:1355:9: note: ‘cvq_isolated’ was declared here
   1355 |     int cvq_isolated;
        |         ^~~~~~~~~~~~
Quoted 6 lines

cc1: all warnings being treated as errors

Cc Eugenio Pérez <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
Cc Jason Wang <[email protected]>

Thanks

Quoted 20 lines
---
 net/vhost-vdpa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/vhost-vdpa.c +1 -2
index 34202ca009..7eaee841aa 100644
@@ -1352,7 +1352,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
     VhostVDPAState *s;
     int ret = 0;
     assert(name);
-    int cvq_isolated;
+    int cvq_isolated = 0;
 
     if (is_datapath) {
         nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device,
--

2.41.0