Skip to contentSkip to conversation

virtio-net: failover: add missing remove_migration_state_change_notifier()

PATCH In review Laurent Vivier 5 participants 8 messages Apr 27, 2021 – May 6, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-net: failover: add missing remove_migration_state_change_notifier()

In the failover case configuration, virtio_net_device_realize() uses an add_migration_state_change_notifier() to add a state notifier, but this notifier is not removed by the unrealize function when the virtio-net card is unplugged.

If the card is unplugged and a migration is started, the notifier is called and as it is not valid anymore QEMU crashes.

This patch fixes the problem by adding the remove_migration_state_change_notifier() in virtio_net_device_unrealize().

The problem can be reproduced with:

  $ qemu-system-x86_64 -enable-kvm -m 1g -M q35 \
    -device pcie-root-port,slot=4,id=root1 \
    -device pcie-root-port,slot=5,id=root2 \
    -device virtio-net-pci,id=net1,mac=52:54:00:6f:55:cc,failover=on,bus=root1 \
    -monitor stdio disk.qcow2
  (qemu) device_del net1
  (qemu) migrate "exec:gzip -c > STATEFILE.gz"

Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault. 0x0000000000000000 in ?? ()
(gdb) bt
#0 0x0000000000000000 in ()
#1 0x0000555555d726d7 in notifier_list_notify (...)

      at .../util/notify.c:39
  #2  0x0000555555842c1a in migrate_fd_connect (...)
      at .../migration/migration.c:3975
  #3  0x0000555555950f7d in migration_channel_connect (...)
      error@entry=0x0) at .../migration/channel.c:107
  #4  0x0000555555910922 in exec_start_outgoing_migration (...)
      at .../migration/exec.c:42
---
 hw/net/virtio-net.c | 1 +
 1 file changed, 1 insertion(+)
hw/net/virtio-net.c +1 -0
index 66b9ff451185..914051feb75b 100644
@@ -3373,6 +3373,7 @@ static void virtio_net_device_unrealize(DeviceState *dev)
 
     if (n->failover) {
         device_listener_unregister(&n->primary_listener);
+        remove_migration_state_change_notifier(&n->migration_state);
     }
 
     max_queues = n->multiqueue ? n->max_queues : 1;
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 34 lines · * Laurent Vivier ([email protected]) wrote:

In the failover case configuration, virtio_net_device_realize() uses an add_migration_state_change_notifier() to add a state notifier, but this notifier is not removed by the unrealize function when the virtio-net card is unplugged.

If the card is unplugged and a migration is started, the notifier is called and as it is not valid anymore QEMU crashes.

This patch fixes the problem by adding the remove_migration_state_change_notifier() in virtio_net_device_unrealize().

The problem can be reproduced with:

  $ qemu-system-x86_64 -enable-kvm -m 1g -M q35 \
    -device pcie-root-port,slot=4,id=root1 \
    -device pcie-root-port,slot=5,id=root2 \
    -device virtio-net-pci,id=net1,mac=52:54:00:6f:55:cc,failover=on,bus=root1 \
    -monitor stdio disk.qcow2
  (qemu) device_del net1
  (qemu) migrate "exec:gzip -c > STATEFILE.gz"

Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault. 0x0000000000000000 in ?? ()
(gdb) bt
#0 0x0000000000000000 in ()
#1 0x0000555555d726d7 in notifier_list_notify (...)

      at .../util/notify.c:39
  #2  0x0000555555842c1a in migrate_fd_connect (...)
      at .../migration/migration.c:3975
  #3  0x0000555555950f7d in migration_channel_connect (...)
      error@entry=0x0) at .../migration/channel.c:107
  #4  0x0000555555910922 in exec_start_outgoing_migration (...)
      at .../migration/exec.c:42
Quoted 2 lines

Yep, I think that's OK.

Quoted 19 lines
---
 hw/net/virtio-net.c | 1 +
 1 file changed, 1 insertion(+)
hw/net/virtio-net.c +1 -0
index 66b9ff451185..914051feb75b 100644
@@ -3373,6 +3373,7 @@ static void virtio_net_device_unrealize(DeviceState *dev)
 
     if (n->failover) {
         device_listener_unregister(&n->primary_listener);
+        remove_migration_state_change_notifier(&n->migration_state);
     }
 
     max_queues = n->multiqueue ? n->max_queues : 1;
Signature · 1 line
2.30.2
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#2 lore raw
Quoted 35 lines · Dr. David Alan Gilbert
Quoted 34 lines · * Laurent Vivier ([email protected]) wrote:

In the failover case configuration, virtio_net_device_realize() uses an add_migration_state_change_notifier() to add a state notifier, but this notifier is not removed by the unrealize function when the virtio-net card is unplugged.

If the card is unplugged and a migration is started, the notifier is called and as it is not valid anymore QEMU crashes.

This patch fixes the problem by adding the remove_migration_state_change_notifier() in virtio_net_device_unrealize().

The problem can be reproduced with:

  $ qemu-system-x86_64 -enable-kvm -m 1g -M q35 \
    -device pcie-root-port,slot=4,id=root1 \
    -device pcie-root-port,slot=5,id=root2 \
    -device virtio-net-pci,id=net1,mac=52:54:00:6f:55:cc,failover=on,bus=root1 \
    -monitor stdio disk.qcow2
  (qemu) device_del net1
  (qemu) migrate "exec:gzip -c > STATEFILE.gz"

Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault. 0x0000000000000000 in ?? ()
(gdb) bt
#0 0x0000000000000000 in ()
#1 0x0000555555d726d7 in notifier_list_notify (...)

      at .../util/notify.c:39
  #2  0x0000555555842c1a in migrate_fd_connect (...)
      at .../migration/migration.c:3975
  #3  0x0000555555950f7d in migration_channel_connect (...)
      error@entry=0x0) at .../migration/channel.c:107
  #4  0x0000555555910922 in exec_start_outgoing_migration (...)
      at .../migration/exec.c:42
Quoted 4 lines
Quoted 2 lines

Yep, I think that's OK.

IIUC HMP device_del ends calling device_finalize(), and per Igor's explanation of qdev transition states:
https://www.mail-archive.com/[email protected]/msg661853.html
I'd expect this to be done in instance_init/instance_finalize, but since 'failover' is a virtio_net_properties, the callbacks has to be registered in the realize() function, thus unregistered in unrealize().

Mentioning it is in realize/unrealize due to 'failover' being a property:

Quoted 21 lines
Quoted 19 lines
---
 hw/net/virtio-net.c | 1 +
 1 file changed, 1 insertion(+)
hw/net/virtio-net.c +1 -0
index 66b9ff451185..914051feb75b 100644
@@ -3373,6 +3373,7 @@ static void virtio_net_device_unrealize(DeviceState *dev)
 
     if (n->failover) {
         device_listener_unregister(&n->primary_listener);
+        remove_migration_state_change_notifier(&n->migration_state);
     }
 
     max_queues = n->multiqueue ? n->max_queues : 1;
Signature · 1 line
2.30.2
Reviewed-by
#3 lore raw
In reply to Dr. David Alan Gilbert
Quoted 35 lines · Dr. David Alan Gilbert
Quoted 34 lines · * Laurent Vivier ([email protected]) wrote:

In the failover case configuration, virtio_net_device_realize() uses an add_migration_state_change_notifier() to add a state notifier, but this notifier is not removed by the unrealize function when the virtio-net card is unplugged.

If the card is unplugged and a migration is started, the notifier is called and as it is not valid anymore QEMU crashes.

This patch fixes the problem by adding the remove_migration_state_change_notifier() in virtio_net_device_unrealize().

The problem can be reproduced with:

  $ qemu-system-x86_64 -enable-kvm -m 1g -M q35 \
    -device pcie-root-port,slot=4,id=root1 \
    -device pcie-root-port,slot=5,id=root2 \
    -device virtio-net-pci,id=net1,mac=52:54:00:6f:55:cc,failover=on,bus=root1 \
    -monitor stdio disk.qcow2
  (qemu) device_del net1
  (qemu) migrate "exec:gzip -c > STATEFILE.gz"

Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault. 0x0000000000000000 in ?? ()
(gdb) bt
#0 0x0000000000000000 in ()
#1 0x0000555555d726d7 in notifier_list_notify (...)

      at .../util/notify.c:39
  #2  0x0000555555842c1a in migrate_fd_connect (...)
      at .../migration/migration.c:3975
  #3  0x0000555555950f7d in migration_channel_connect (...)
      error@entry=0x0) at .../migration/channel.c:107
  #4  0x0000555555910922 in exec_start_outgoing_migration (...)
      at .../migration/exec.c:42
Quoted 7 lines
Quoted 2 lines

Yep, I think that's OK.

net stuff so I expect Jason will merge this ...

Quoted 21 lines
Quoted 19 lines
---
 hw/net/virtio-net.c | 1 +
 1 file changed, 1 insertion(+)
hw/net/virtio-net.c +1 -0
index 66b9ff451185..914051feb75b 100644
@@ -3373,6 +3373,7 @@ static void virtio_net_device_unrealize(DeviceState *dev)
 
     if (n->failover) {
         device_listener_unregister(&n->primary_listener);
+        remove_migration_state_change_notifier(&n->migration_state);
     }
 
     max_queues = n->multiqueue ? n->max_queues : 1;
Signature · 1 line
2.30.2
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#4 lore raw
Quoted 38 lines · Michael S. Tsirkin
Quoted 37 lines · Dr. David Alan Gilbert
Quoted 36 lines · * Laurent Vivier ([email protected]) wrote:

In the failover case configuration, virtio_net_device_realize() uses an add_migration_state_change_notifier() to add a state notifier, but this notifier is not removed by the unrealize function when the virtio-net card is unplugged.

If the card is unplugged and a migration is started, the notifier is called and as it is not valid anymore QEMU crashes.

This patch fixes the problem by adding the remove_migration_state_change_notifier() in virtio_net_device_unrealize().

The problem can be reproduced with:

   $ qemu-system-x86_64 -enable-kvm -m 1g -M q35 \
     -device pcie-root-port,slot=4,id=root1 \
     -device pcie-root-port,slot=5,id=root2 \
     -device virtio-net-pci,id=net1,mac=52:54:00:6f:55:cc,failover=on,bus=root1 \
     -monitor stdio disk.qcow2
   (qemu) device_del net1
   (qemu) migrate "exec:gzip -c > STATEFILE.gz"
   Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault.
   0x0000000000000000 in ?? ()
   (gdb) bt
   #0  0x0000000000000000 in  ()
   #1  0x0000555555d726d7 in notifier_list_notify (...)
       at .../util/notify.c:39
   #2  0x0000555555842c1a in migrate_fd_connect (...)
       at .../migration/migration.c:3975
   #3  0x0000555555950f7d in migration_channel_connect (...)
       error@entry=0x0) at .../migration/channel.c:107
   #4  0x0000555555910922 in exec_start_outgoing_migration (...)
       at .../migration/exec.c:42
Quoted 7 lines
Quoted 4 lines

Yep, I think that's OK.

net stuff so I expect Jason will merge this ...

Ok, I've queued this.

Thanks

Quoted 23 lines
Quoted 22 lines
Quoted 20 lines
---
  hw/net/virtio-net.c | 1 +
  1 file changed, 1 insertion(+)
hw/net/virtio-net.c +1 -0
index 66b9ff451185..914051feb75b 100644
@@ -3373,6 +3373,7 @@ static void virtio_net_device_unrealize(DeviceState *dev)
 
      if (n->failover) {
          device_listener_unregister(&n->primary_listener);
+        remove_migration_state_change_notifier(&n->migration_state);
      }
 
      max_queues = n->multiqueue ? n->max_queues : 1;
Signature · 1 line
2.30.2
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#5 lore raw
Quoted 43 lines · Jason Wang
Quoted 41 lines · Michael S. Tsirkin
Quoted 40 lines · Dr. David Alan Gilbert
Quoted 34 lines · * Laurent Vivier ([email protected]) wrote:

In the failover case configuration, virtio_net_device_realize() uses an add_migration_state_change_notifier() to add a state notifier, but this notifier is not removed by the unrealize function when the virtio-net card is unplugged.

If the card is unplugged and a migration is started, the notifier is called and as it is not valid anymore QEMU crashes.

This patch fixes the problem by adding the remove_migration_state_change_notifier() in virtio_net_device_unrealize().

The problem can be reproduced with:

   $ qemu-system-x86_64 -enable-kvm -m 1g -M q35 \
     -device pcie-root-port,slot=4,id=root1 \
     -device pcie-root-port,slot=5,id=root2 \
     -device virtio-net-pci,id=net1,mac=52:54:00:6f:55:cc,failover=on,bus=root1 \
     -monitor stdio disk.qcow2
   (qemu) device_del net1
   (qemu) migrate "exec:gzip -c > STATEFILE.gz"

   Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault. 0x0000000000000000 in ?? ()
   (gdb) bt
   #0  0x0000000000000000 in  ()
   #1  0x0000555555d726d7 in notifier_list_notify (...)
       at .../util/notify.c:39
   #2  0x0000555555842c1a in migrate_fd_connect (...)
       at .../migration/migration.c:3975
   #3  0x0000555555950f7d in migration_channel_connect (...) error@entry=0x0) at .../migration/channel.c:107
   #4  0x0000555555910922 in exec_start_outgoing_migration (...) at .../migration/exec.c:42

Quoted 2 lines

Yep, I think that's OK.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

net stuff so I expect Jason will merge this ...

Ok, I've queued this.

Thank you.

Any idea when the PR will be sent?

Thanks,
Laurent

#6 lore raw
Quoted 44 lines · Laurent Vivier
Quoted 43 lines · Jason Wang
Quoted 42 lines · Michael S. Tsirkin
Quoted 41 lines · Dr. David Alan Gilbert
Quoted 34 lines · * Laurent Vivier ([email protected]) wrote:

In the failover case configuration, virtio_net_device_realize() uses an add_migration_state_change_notifier() to add a state notifier, but this notifier is not removed by the unrealize function when the virtio-net card is unplugged.

If the card is unplugged and a migration is started, the notifier is called and as it is not valid anymore QEMU crashes.

This patch fixes the problem by adding the remove_migration_state_change_notifier() in virtio_net_device_unrealize().

The problem can be reproduced with:

    $ qemu-system-x86_64 -enable-kvm -m 1g -M q35 \
      -device pcie-root-port,slot=4,id=root1 \
      -device pcie-root-port,slot=5,id=root2 \
      -device virtio-net-pci,id=net1,mac=52:54:00:6f:55:cc,failover=on,bus=root1 \
      -monitor stdio disk.qcow2
    (qemu) device_del net1
    (qemu) migrate "exec:gzip -c > STATEFILE.gz"

   Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault. 0x0000000000000000 in ?? ()
   (gdb) bt
   #0  0x0000000000000000 in  ()
   #1  0x0000555555d726d7 in notifier_list_notify (...)

        at .../util/notify.c:39
    #2  0x0000555555842c1a in migrate_fd_connect (...)
        at .../migration/migration.c:3975
    #3  0x0000555555950f7d in migration_channel_connect (...)
        error@entry=0x0) at .../migration/channel.c:107
    #4  0x0000555555910922 in exec_start_outgoing_migration (...)
        at .../migration/exec.c:42
Quoted 2 lines

Yep, I think that's OK.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

net stuff so I expect Jason will merge this ...

Ok, I've queued this.

Thank you.

Any idea when the PR will be sent?

I would be no later than the end of this week. I plan to merge RSS so I want to have some basic for that.

Thanks

Quoted 4 lines

Thanks,
Laurent

Acked-by on v1 1/1
#7 lore raw
In reply to Laurent Vivier
Quoted 34 lines · Laurent Vivier

In the failover case configuration, virtio_net_device_realize() uses an add_migration_state_change_notifier() to add a state notifier, but this notifier is not removed by the unrealize function when the virtio-net card is unplugged.

If the card is unplugged and a migration is started, the notifier is called and as it is not valid anymore QEMU crashes.

This patch fixes the problem by adding the remove_migration_state_change_notifier() in virtio_net_device_unrealize().

The problem can be reproduced with:

   $ qemu-system-x86_64 -enable-kvm -m 1g -M q35 \
     -device pcie-root-port,slot=4,id=root1 \
     -device pcie-root-port,slot=5,id=root2 \
     -device virtio-net-pci,id=net1,mac=52:54:00:6f:55:cc,failover=on,bus=root1 \
     -monitor stdio disk.qcow2
   (qemu) device_del net1
   (qemu) migrate "exec:gzip -c > STATEFILE.gz"
   Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault.
   0x0000000000000000 in ?? ()
   (gdb) bt
   #0  0x0000000000000000 in  ()
   #1  0x0000555555d726d7 in notifier_list_notify (...)
       at .../util/notify.c:39
   #2  0x0000555555842c1a in migrate_fd_connect (...)
       at .../migration/migration.c:3975
   #3  0x0000555555950f7d in migration_channel_connect (...)
       error@entry=0x0) at .../migration/channel.c:107
   #4  0x0000555555910922 in exec_start_outgoing_migration (...)
       at .../migration/exec.c:42
Quoted 2 lines

This should be added to stable I guess.

Thanks

Quoted 16 lines
---
  hw/net/virtio-net.c | 1 +
  1 file changed, 1 insertion(+)
hw/net/virtio-net.c +1 -0
index 66b9ff451185..914051feb75b 100644
@@ -3373,6 +3373,7 @@ static void virtio_net_device_unrealize(DeviceState *dev)
 
      if (n->failover) {
          device_listener_unregister(&n->primary_listener);
+        remove_migration_state_change_notifier(&n->migration_state);
      }
 
      max_queues = n->multiqueue ? n->max_queues : 1;