Skip to contentSkip to conversation

migration: use parameters.mode in cpr_state_save

PATCH In review Steve Sistare 3 participants 5 messages Feb 5, 2025 – Feb 14, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 migration: use parameters.mode in cpr_state_save

qmp_migrate guarantees that cpr_channel is not null for MIG_MODE_CPR_TRANSFER when cpr_state_save is called:

    qmp_migrate()
        if (s->parameters.mode == MIG_MODE_CPR_TRANSFER && !cpr_channel) {
            return;
        }
        cpr_state_save(cpr_channel)

but cpr_state_save checks for mode differently before using channel, and Coverity cannot infer that they are equivalent in outgoing QEMU, and warns that channel may be NULL:

    cpr_state_save(channel)
        MigMode mode = migrate_mode();
        if (mode == MIG_MODE_CPR_TRANSFER) {
            f = cpr_transfer_output(channel, errp);

To make Coverity happy, use parameters.mode in cpr_state_save.

Resolves: Coverity CID 1590980

---
 migration/cpr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
migration/cpr.c +2 -1
index 584b0b9..7f20bd5 100644
@@ -8,6 +8,7 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "migration/cpr.h"
+#include "migration/migration.h"
 #include "migration/misc.h"
 #include "migration/options.h"
 #include "migration/qemu-file.h"
@@ -132,7 +133,7 @@ int cpr_state_save(MigrationChannel *channel, Error **errp)
 {
     int ret;
     QEMUFile *f;
-    MigMode mode = migrate_mode();
+    MigMode mode = migrate_get_current()->parameters.mode;
 
     trace_cpr_state_save(MigMode_str(mode));
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 40 lines · Steve Sistare

qmp_migrate guarantees that cpr_channel is not null for MIG_MODE_CPR_TRANSFER when cpr_state_save is called:

    qmp_migrate()
        if (s->parameters.mode == MIG_MODE_CPR_TRANSFER && !cpr_channel) {
            return;
        }
        cpr_state_save(cpr_channel)

but cpr_state_save checks for mode differently before using channel, and Coverity cannot infer that they are equivalent in outgoing QEMU, and warns that channel may be NULL:

    cpr_state_save(channel)
        MigMode mode = migrate_mode();
        if (mode == MIG_MODE_CPR_TRANSFER) {
            f = cpr_transfer_output(channel, errp);

To make Coverity happy, use parameters.mode in cpr_state_save.

Resolves: Coverity CID 1590980

---
 migration/cpr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
migration/cpr.c +1 -0
index 584b0b9..7f20bd5 100644
@@ -8,6 +8,7 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "migration/cpr.h"
+#include "migration/migration.h"
 #include "migration/misc.h"
 #include "migration/options.h"
 #include "migration/qemu-file.h"

migration/cpr.c int cpr_state_save(MigrationChannel *channel, Error **errp) · line 136

Quoted 5 lines
migration/cpr.c +1 -1
@@ -132,7 +133,7 @@ int cpr_state_save(MigrationChannel *channel, Error **errp)
 {
     int ret;
     QEMUFile *f;
-    MigMode mode = migrate_mode();
+    MigMode mode = migrate_get_current()->parameters.mode;

Are we sure this can make coverity happy?

Another more straightforward change is caching migrate mode in qmp_migrate() and also check that before invoking cpr_state_save().

Thanks,

Quoted 6 lines
migration/cpr.c +0 -0
     trace_cpr_state_save(MigMode_str(mode));
 
Signature · 1 line
1.8.3.1
Signature · 1 line
Peter Xu
#2 lore raw
Quoted 40 lines · Peter Xu
Quoted 39 lines · Steve Sistare

qmp_migrate guarantees that cpr_channel is not null for MIG_MODE_CPR_TRANSFER when cpr_state_save is called:

     qmp_migrate()
         if (s->parameters.mode == MIG_MODE_CPR_TRANSFER && !cpr_channel) {
             return;
         }
         cpr_state_save(cpr_channel)

but cpr_state_save checks for mode differently before using channel, and Coverity cannot infer that they are equivalent in outgoing QEMU, and warns that channel may be NULL:

     cpr_state_save(channel)
         MigMode mode = migrate_mode();
         if (mode == MIG_MODE_CPR_TRANSFER) {
             f = cpr_transfer_output(channel, errp);

To make Coverity happy, use parameters.mode in cpr_state_save.

Resolves: Coverity CID 1590980

---
  migration/cpr.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
migration/cpr.c +1 -0
index 584b0b9..7f20bd5 100644
@@ -8,6 +8,7 @@
  #include "qemu/osdep.h"
  #include "qapi/error.h"
  #include "migration/cpr.h"
+#include "migration/migration.h"
  #include "migration/misc.h"
  #include "migration/options.h"
  #include "migration/qemu-file.h"
Quoted 8 lines

migration/cpr.c int cpr_state_save(MigrationChannel *channel, Error **errp) · line 136

Quoted 6 lines
migration/cpr.c +1 -1
@@ -132,7 +133,7 @@ int cpr_state_save(MigrationChannel *channel, Error **errp)
  {
      int ret;
      QEMUFile *f;
-    MigMode mode = migrate_mode();
+    MigMode mode = migrate_get_current()->parameters.mode;

Are we sure this can make coverity happy?

It should, based on Peter Maydell's analysis, but I would appreciate if he could apply and test the fix.

Quoted 2 lines

Another more straightforward change is caching migrate mode in qmp_migrate() and also check that before invoking cpr_state_save().

Surely anyone would consider my one-line change to be straight forward.

- Steve

Quoted 6 lines
Quoted 5 lines
migration/cpr.c +0 -0
      trace_cpr_state_save(MigMode_str(mode));
 
Signature · 1 line
1.8.3.1
#3 lore raw
Quoted 50 lines · Steven Sistare
Quoted 40 lines · Peter Xu
Quoted 39 lines · Steve Sistare

qmp_migrate guarantees that cpr_channel is not null for MIG_MODE_CPR_TRANSFER when cpr_state_save is called:

     qmp_migrate()
         if (s->parameters.mode == MIG_MODE_CPR_TRANSFER && !cpr_channel) { return;
         }
         cpr_state_save(cpr_channel)

but cpr_state_save checks for mode differently before using channel, and Coverity cannot infer that they are equivalent in outgoing QEMU, and warns that channel may be NULL:

     cpr_state_save(channel)
         MigMode mode = migrate_mode();
         if (mode == MIG_MODE_CPR_TRANSFER) { f = cpr_transfer_output(channel, errp);

To make Coverity happy, use parameters.mode in cpr_state_save.

Resolves: Coverity CID 1590980

---
  migration/cpr.c | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
migration/cpr.c +1 -0
index 584b0b9..7f20bd5 100644
@@ -8,6 +8,7 @@
   #include "qemu/osdep.h"
   #include "qapi/error.h"
   #include "migration/cpr.h"
+#include "migration/migration.h"
   #include "migration/misc.h"
   #include "migration/options.h"
   #include "migration/qemu-file.h"
Quoted 8 lines

migration/cpr.c int cpr_state_save(MigrationChannel *channel, Error **errp) · line 136

Quoted 6 lines
migration/cpr.c +1 -1
@@ -132,7 +133,7 @@ int cpr_state_save(MigrationChannel *channel, Error **errp)
   {
       int ret;
       QEMUFile *f;
-    MigMode mode = migrate_mode();
+    MigMode mode = migrate_get_current()->parameters.mode;

Are we sure this can make coverity happy?

Quoted 7 lines

It should, based on Peter Maydell's analysis, but I would appreciate if he could apply and test the fix.

Quoted 2 lines

Another more straightforward change is caching migrate mode in qmp_migrate() and also check that before invoking cpr_state_save().

Surely anyone would consider my one-line change to be straight forward.

Given that Coverity complains about channel, and not mode, this is the most direct fix:

----------------------------------------

migration/cpr.c +1 -0
index 59644e8..224b6ff 100644
@@ -160,6 +160,7 @@ int cpr_state_save(MigrationChannel *channel, Error **errp)
     trace_cpr_state_save(MigMode_str(mode));
 
     if (mode == MIG_MODE_CPR_TRANSFER) {
+        g_assert(channel);
         f = cpr_transfer_output(channel, errp);
     } else {
         return 0;

-------------------------------

- Steve

#4 lore raw
Quoted 69 lines · Steven Sistare
Quoted 50 lines · Steven Sistare
Quoted 40 lines · Peter Xu
Quoted 39 lines · Steve Sistare

qmp_migrate guarantees that cpr_channel is not null for MIG_MODE_CPR_TRANSFER when cpr_state_save is called:

     qmp_migrate()
         if (s->parameters.mode == MIG_MODE_CPR_TRANSFER && !cpr_channel) { return;
         }
         cpr_state_save(cpr_channel)

but cpr_state_save checks for mode differently before using channel, and Coverity cannot infer that they are equivalent in outgoing QEMU, and warns that channel may be NULL:

     cpr_state_save(channel)
         MigMode mode = migrate_mode();
         if (mode == MIG_MODE_CPR_TRANSFER) { f = cpr_transfer_output(channel, errp);

To make Coverity happy, use parameters.mode in cpr_state_save.

Resolves: Coverity CID 1590980

---
  migration/cpr.c | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
migration/cpr.c +1 -0
index 584b0b9..7f20bd5 100644
@@ -8,6 +8,7 @@
   #include "qemu/osdep.h"
   #include "qapi/error.h"
   #include "migration/cpr.h"
+#include "migration/migration.h"
   #include "migration/misc.h"
   #include "migration/options.h"
   #include "migration/qemu-file.h"
Quoted 8 lines

migration/cpr.c int cpr_state_save(MigrationChannel *channel, Error **errp) · line 136

Quoted 6 lines
migration/cpr.c +1 -1
@@ -132,7 +133,7 @@ int cpr_state_save(MigrationChannel *channel, Error **errp)
   {
       int ret;
       QEMUFile *f;
-    MigMode mode = migrate_mode();
+    MigMode mode = migrate_get_current()->parameters.mode;

Are we sure this can make coverity happy?

Quoted 7 lines

It should, based on Peter Maydell's analysis, but I would appreciate if he could apply and test the fix.

Quoted 2 lines

Another more straightforward change is caching migrate mode in qmp_migrate() and also check that before invoking cpr_state_save().

Surely anyone would consider my one-line change to be straight forward.

Given that Coverity complains about channel, and not mode, this is the most direct fix:

----------------------------------------

migration/cpr.c +0 -0
index 59644e8..224b6ff 100644

migration/cpr.c int cpr_state_save(MigrationChannel *channel, Error **errp)

Quoted 10 lines
migration/cpr.c +1 -2
@@ -160,6 +160,7 @@ int cpr_state_save(MigrationChannel *channel, Error **errp)
      trace_cpr_state_save(MigMode_str(mode));
 
      if (mode == MIG_MODE_CPR_TRANSFER) {
+        g_assert(channel);
          f = cpr_transfer_output(channel, errp);
      } else {
          return 0;
-------------------------------
 
- Steve

Queueing this^ version. Thanks