All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] net/virtio: fixes for failover
@ 2019-11-20 14:38 Jens Freimann
  2019-11-20 14:38 ` [PATCH v2 1/4] net/virtio: fix dev_unplug_pending Jens Freimann
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Jens Freimann @ 2019-11-20 14:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, jasowang, dgilbert, mst

This series fixes bugs found by coverity and one reported by David
Gilbert.

Jens Freimann (4):
  net/virtio: fix dev_unplug_pending
  net/virtio: return early when failover primary alread added
  net/virtio: avoid passing NULL to qdev_set_parent_bus
  net/virtio: return error when device_opts arg is NULL

 hw/net/virtio-net.c | 58 +++++++++++++++++++++++++++++----------------
 migration/savevm.c  |  3 ++-
 2 files changed, 40 insertions(+), 21 deletions(-)

-- 
2.21.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/4] net/virtio: fix dev_unplug_pending
  2019-11-20 14:38 [PATCH v2 0/4] net/virtio: fixes for failover Jens Freimann
@ 2019-11-20 14:38 ` Jens Freimann
  2019-11-20 14:38 ` [PATCH v2 2/4] net/virtio: return early when failover primary alread added Jens Freimann
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Jens Freimann @ 2019-11-20 14:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, jasowang, dgilbert, mst

.dev_unplug_pending is set up by virtio-net code indepent of failover
support was set for the device or not. This gives a wrong result when
we check for existing primary devices in migration code.

Fix this by actually calling dev_unplug_pending() instead of just
checking if the function pointer was set. When the feature was not
negotiated dev_unplug_pending() will always return false. This prevents
us from going into the wait-unplug state when there's no primary device
present.

Fixes: 9711cd0dfc3f ("net/virtio: add failover support")
Signed-off-by: Jens Freimann <jfreimann@redhat.com>
Reported-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/net/virtio-net.c | 3 +++
 migration/savevm.c  | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 97a5113f7e..946039c0dc 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -3124,6 +3124,9 @@ static bool primary_unplug_pending(void *opaque)
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     VirtIONet *n = VIRTIO_NET(vdev);
 
+    if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_STANDBY)) {
+        return false;
+    }
     return n->primary_dev ? n->primary_dev->pending_deleted_event : false;
 }
 
diff --git a/migration/savevm.c b/migration/savevm.c
index 966a9c3bdb..a71b930b91 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -1119,7 +1119,8 @@ int qemu_savevm_nr_failover_devices(void)
     int n = 0;
 
     QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
-        if (se->vmsd && se->vmsd->dev_unplug_pending) {
+        if (se->vmsd && se->vmsd->dev_unplug_pending &&
+            se->vmsd->dev_unplug_pending(se->opaque)) {
             n++;
         }
     }
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/4] net/virtio: return early when failover primary alread added
  2019-11-20 14:38 [PATCH v2 0/4] net/virtio: fixes for failover Jens Freimann
  2019-11-20 14:38 ` [PATCH v2 1/4] net/virtio: fix dev_unplug_pending Jens Freimann
@ 2019-11-20 14:38 ` Jens Freimann
  2019-11-20 14:38 ` [PATCH v2 3/4] net/virtio: avoid passing NULL to qdev_set_parent_bus Jens Freimann
  2019-11-20 14:38 ` [PATCH v2 4/4] net/virtio: return error when device_opts arg is NULL Jens Freimann
  3 siblings, 0 replies; 7+ messages in thread
From: Jens Freimann @ 2019-11-20 14:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, jasowang, dgilbert, mst

Bail out when primary device was already added before.
This avoids printing a wrong warning message during reboot.

Fixes: 9711cd0dfc3f ("net/virtio: add failover support")
Signed-off-by: Jens Freimann <jfreimann@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/net/virtio-net.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 946039c0dc..ac4d19109e 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -759,6 +759,10 @@ static void failover_add_primary(VirtIONet *n, Error **errp)
 {
     Error *err = NULL;
 
+    if (n->primary_dev) {
+        return;
+    }
+
     n->primary_device_opts = qemu_opts_find(qemu_find_opts("device"),
             n->primary_device_id);
     if (n->primary_device_opts) {
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 3/4] net/virtio: avoid passing NULL to qdev_set_parent_bus
  2019-11-20 14:38 [PATCH v2 0/4] net/virtio: fixes for failover Jens Freimann
  2019-11-20 14:38 ` [PATCH v2 1/4] net/virtio: fix dev_unplug_pending Jens Freimann
  2019-11-20 14:38 ` [PATCH v2 2/4] net/virtio: return early when failover primary alread added Jens Freimann
@ 2019-11-20 14:38 ` Jens Freimann
  2019-11-20 15:04   ` Michael S. Tsirkin
  2019-11-20 14:38 ` [PATCH v2 4/4] net/virtio: return error when device_opts arg is NULL Jens Freimann
  3 siblings, 1 reply; 7+ messages in thread
From: Jens Freimann @ 2019-11-20 14:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, jasowang, dgilbert, mst

Make sure we don't pass NULL to qdev_set_parent_bus(). Also simplify
code a bit and fix a typo.
This fixes CID 1407224.

Fixes: 9711cd0dfc3f ("net/virtio: add failover support")
Signed-off-by: Jens Freimann <jfreimann@redhat.com>
---
 hw/net/virtio-net.c | 42 +++++++++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 17 deletions(-)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index ac4d19109e..78f1e4e87c 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -2805,25 +2805,33 @@ static bool failover_replug_primary(VirtIONet *n, Error **errp)
         n->primary_device_opts = qemu_opts_from_qdict(
                 qemu_find_opts("device"),
                 n->primary_device_dict, errp);
-    }
-    if (n->primary_device_opts) {
-        if (n->primary_dev) {
-            n->primary_bus = n->primary_dev->parent_bus;
-        }
-        qdev_set_parent_bus(n->primary_dev, n->primary_bus);
-        n->primary_should_be_hidden = false;
-        qemu_opt_set_bool(n->primary_device_opts,
-                "partially_hotplugged", true, errp);
-        hotplug_ctrl = qdev_get_hotplug_handler(n->primary_dev);
-        if (hotplug_ctrl) {
-            hotplug_handler_pre_plug(hotplug_ctrl, n->primary_dev, errp);
-            hotplug_handler_plug(hotplug_ctrl, n->primary_dev, errp);
+        if (!n->primary_device_opts) {
+            error_setg(errp, "virtio_net: couldn't find primary device opts");
+            goto out;
         }
-        if (!n->primary_dev) {
+    }
+    if (!n->primary_dev) {
             error_setg(errp, "virtio_net: couldn't find primary device");
-        }
+            goto out;
     }
-    return *errp != NULL;
+
+    n->primary_bus = n->primary_dev->parent_bus;
+    if (!n->primary_bus) {
+        error_setg(errp, "virtio_net: couldn't find primary bus");
+        goto out;
+    }
+    qdev_set_parent_bus(n->primary_dev, n->primary_bus);
+    n->primary_should_be_hidden = false;
+    qemu_opt_set_bool(n->primary_device_opts,
+                      "partially_hotplugged", true, errp);
+    hotplug_ctrl = qdev_get_hotplug_handler(n->primary_dev);
+    if (hotplug_ctrl) {
+        hotplug_handler_pre_plug(hotplug_ctrl, n->primary_dev, errp);
+        hotplug_handler_plug(hotplug_ctrl, n->primary_dev, errp);
+    }
+
+out:
+    return *errp == NULL;
 }
 
 static void virtio_net_handle_migration_primary(VirtIONet *n,
@@ -2852,7 +2860,7 @@ static void virtio_net_handle_migration_primary(VirtIONet *n,
             warn_report("couldn't unplug primary device");
         }
     } else if (migration_has_failed(s)) {
-        /* We already unplugged the device let's plugged it back */
+        /* We already unplugged the device let's plug it back */
         if (!failover_replug_primary(n, &err)) {
             if (err) {
                 error_report_err(err);
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 4/4] net/virtio: return error when device_opts arg is NULL
  2019-11-20 14:38 [PATCH v2 0/4] net/virtio: fixes for failover Jens Freimann
                   ` (2 preceding siblings ...)
  2019-11-20 14:38 ` [PATCH v2 3/4] net/virtio: avoid passing NULL to qdev_set_parent_bus Jens Freimann
@ 2019-11-20 14:38 ` Jens Freimann
  3 siblings, 0 replies; 7+ messages in thread
From: Jens Freimann @ 2019-11-20 14:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, jasowang, dgilbert, mst

This fixes CID 1407222.

Fixes: 9711cd0dfc3f ("net/virtio: add failover support")
Signed-off-by: Jens Freimann <jfreimann@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/net/virtio-net.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 78f1e4e87c..600c6e164f 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -2880,9 +2880,12 @@ static int virtio_net_primary_should_be_hidden(DeviceListener *listener,
             QemuOpts *device_opts)
 {
     VirtIONet *n = container_of(listener, VirtIONet, primary_listener);
-    bool match_found;
-    bool hide;
+    bool match_found = false;
+    bool hide = false;
 
+    if (!device_opts) {
+        return -1;
+    }
     n->primary_device_dict = qemu_opts_to_qdict(device_opts,
             n->primary_device_dict);
     if (n->primary_device_dict) {
@@ -2890,7 +2893,7 @@ static int virtio_net_primary_should_be_hidden(DeviceListener *listener,
         n->standby_id = g_strdup(qdict_get_try_str(n->primary_device_dict,
                     "failover_pair_id"));
     }
-    if (device_opts && g_strcmp0(n->standby_id, n->netclient_name) == 0) {
+    if (g_strcmp0(n->standby_id, n->netclient_name) == 0) {
         match_found = true;
     } else {
         match_found = false;
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 3/4] net/virtio: avoid passing NULL to qdev_set_parent_bus
  2019-11-20 14:38 ` [PATCH v2 3/4] net/virtio: avoid passing NULL to qdev_set_parent_bus Jens Freimann
@ 2019-11-20 15:04   ` Michael S. Tsirkin
  2019-11-20 15:22     ` Jens Freimann
  0 siblings, 1 reply; 7+ messages in thread
From: Michael S. Tsirkin @ 2019-11-20 15:04 UTC (permalink / raw)
  To: Jens Freimann; +Cc: peter.maydell, jasowang, qemu-devel, dgilbert

On Wed, Nov 20, 2019 at 03:38:58PM +0100, Jens Freimann wrote:
> Make sure we don't pass NULL to qdev_set_parent_bus(). Also simplify
> code a bit and fix a typo.
> This fixes CID 1407224.
> 
> Fixes: 9711cd0dfc3f ("net/virtio: add failover support")
> Signed-off-by: Jens Freimann <jfreimann@redhat.com>

patch itself is ok I think

Reviewed-by: Michael S. Tsirkin <mst@redhat.com>

but some questions on the commit log

> ---
>  hw/net/virtio-net.c | 42 +++++++++++++++++++++++++-----------------
>  1 file changed, 25 insertions(+), 17 deletions(-)
> 
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index ac4d19109e..78f1e4e87c 100644
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -2805,25 +2805,33 @@ static bool failover_replug_primary(VirtIONet *n, Error **errp)
>          n->primary_device_opts = qemu_opts_from_qdict(
>                  qemu_find_opts("device"),
>                  n->primary_device_dict, errp);
> -    }
> -    if (n->primary_device_opts) {
> -        if (n->primary_dev) {
> -            n->primary_bus = n->primary_dev->parent_bus;
> -        }
> -        qdev_set_parent_bus(n->primary_dev, n->primary_bus);
> -        n->primary_should_be_hidden = false;
> -        qemu_opt_set_bool(n->primary_device_opts,
> -                "partially_hotplugged", true, errp);
> -        hotplug_ctrl = qdev_get_hotplug_handler(n->primary_dev);
> -        if (hotplug_ctrl) {
> -            hotplug_handler_pre_plug(hotplug_ctrl, n->primary_dev, errp);
> -            hotplug_handler_plug(hotplug_ctrl, n->primary_dev, errp);
> +        if (!n->primary_device_opts) {
> +            error_setg(errp, "virtio_net: couldn't find primary device opts");
> +            goto out;
>          }
> -        if (!n->primary_dev) {
> +    }
> +    if (!n->primary_dev) {
>              error_setg(errp, "virtio_net: couldn't find primary device");
> -        }
> +            goto out;
>      }
> -    return *errp != NULL;
> +
> +    n->primary_bus = n->primary_dev->parent_bus;
> +    if (!n->primary_bus) {
> +        error_setg(errp, "virtio_net: couldn't find primary bus");
> +        goto out;
> +    }
> +    qdev_set_parent_bus(n->primary_dev, n->primary_bus);
> +    n->primary_should_be_hidden = false;
> +    qemu_opt_set_bool(n->primary_device_opts,
> +                      "partially_hotplugged", true, errp);
> +    hotplug_ctrl = qdev_get_hotplug_handler(n->primary_dev);
> +    if (hotplug_ctrl) {
> +        hotplug_handler_pre_plug(hotplug_ctrl, n->primary_dev, errp);
> +        hotplug_handler_plug(hotplug_ctrl, n->primary_dev, errp);
> +    }
> +
> +out:
> +    return *errp == NULL;
>  }
>  
>  static void virtio_net_handle_migration_primary(VirtIONet *n,

So the logic actually was inverted here? Then ... how did this work?
and how was it tested?
Also, pls mention the change in the commit log.

> @@ -2852,7 +2860,7 @@ static void virtio_net_handle_migration_primary(VirtIONet *n,
>              warn_report("couldn't unplug primary device");
>          }
>      } else if (migration_has_failed(s)) {
> -        /* We already unplugged the device let's plugged it back */
> +        /* We already unplugged the device let's plug it back */
>          if (!failover_replug_primary(n, &err)) {
>              if (err) {
>                  error_report_err(err);
> -- 
> 2.21.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 3/4] net/virtio: avoid passing NULL to qdev_set_parent_bus
  2019-11-20 15:04   ` Michael S. Tsirkin
@ 2019-11-20 15:22     ` Jens Freimann
  0 siblings, 0 replies; 7+ messages in thread
From: Jens Freimann @ 2019-11-20 15:22 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: peter.maydell, jasowang, qemu-devel, dgilbert

On Wed, Nov 20, 2019 at 10:04:01AM -0500, Michael S. Tsirkin wrote:
>On Wed, Nov 20, 2019 at 03:38:58PM +0100, Jens Freimann wrote:
>> Make sure we don't pass NULL to qdev_set_parent_bus(). Also simplify
>> code a bit and fix a typo.
>> This fixes CID 1407224.
>>
>> Fixes: 9711cd0dfc3f ("net/virtio: add failover support")
>> Signed-off-by: Jens Freimann <jfreimann@redhat.com>
>
>patch itself is ok I think
>
>Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
>
>but some questions on the commit log
>
>> ---
>>  hw/net/virtio-net.c | 42 +++++++++++++++++++++++++-----------------
>>  1 file changed, 25 insertions(+), 17 deletions(-)
>>
>> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
>> index ac4d19109e..78f1e4e87c 100644
>> --- a/hw/net/virtio-net.c
>> +++ b/hw/net/virtio-net.c
>> @@ -2805,25 +2805,33 @@ static bool failover_replug_primary(VirtIONet *n, Error **errp)
>>          n->primary_device_opts = qemu_opts_from_qdict(
>>                  qemu_find_opts("device"),
>>                  n->primary_device_dict, errp);
>> -    }
>> -    if (n->primary_device_opts) {
>> -        if (n->primary_dev) {
>> -            n->primary_bus = n->primary_dev->parent_bus;
>> -        }
>> -        qdev_set_parent_bus(n->primary_dev, n->primary_bus);
>> -        n->primary_should_be_hidden = false;
>> -        qemu_opt_set_bool(n->primary_device_opts,
>> -                "partially_hotplugged", true, errp);
>> -        hotplug_ctrl = qdev_get_hotplug_handler(n->primary_dev);
>> -        if (hotplug_ctrl) {
>> -            hotplug_handler_pre_plug(hotplug_ctrl, n->primary_dev, errp);
>> -            hotplug_handler_plug(hotplug_ctrl, n->primary_dev, errp);
>> +        if (!n->primary_device_opts) {
>> +            error_setg(errp, "virtio_net: couldn't find primary device opts");
>> +            goto out;
>>          }
>> -        if (!n->primary_dev) {
>> +    }
>> +    if (!n->primary_dev) {
>>              error_setg(errp, "virtio_net: couldn't find primary device");
>> -        }
>> +            goto out;
>>      }
>> -    return *errp != NULL;
>> +
>> +    n->primary_bus = n->primary_dev->parent_bus;
>> +    if (!n->primary_bus) {
>> +        error_setg(errp, "virtio_net: couldn't find primary bus");
>> +        goto out;
>> +    }
>> +    qdev_set_parent_bus(n->primary_dev, n->primary_bus);
>> +    n->primary_should_be_hidden = false;
>> +    qemu_opt_set_bool(n->primary_device_opts,
>> +                      "partially_hotplugged", true, errp);
>> +    hotplug_ctrl = qdev_get_hotplug_handler(n->primary_dev);
>> +    if (hotplug_ctrl) {
>> +        hotplug_handler_pre_plug(hotplug_ctrl, n->primary_dev, errp);
>> +        hotplug_handler_plug(hotplug_ctrl, n->primary_dev, errp);
>> +    }
>> +
>> +out:
>> +    return *errp == NULL;
>>  }
>>
>>  static void virtio_net_handle_migration_primary(VirtIONet *n,
>
>So the logic actually was inverted here? Then ... how did this work?
>and how was it tested?

It did not work and I missed the error in my test output. I tested it
now manually by migrating and then cancelling. Device was added back
to source VM successfully.

Will sent new version with better patch description.

Thanks!

regards
Jens



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-11-20 15:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-20 14:38 [PATCH v2 0/4] net/virtio: fixes for failover Jens Freimann
2019-11-20 14:38 ` [PATCH v2 1/4] net/virtio: fix dev_unplug_pending Jens Freimann
2019-11-20 14:38 ` [PATCH v2 2/4] net/virtio: return early when failover primary alread added Jens Freimann
2019-11-20 14:38 ` [PATCH v2 3/4] net/virtio: avoid passing NULL to qdev_set_parent_bus Jens Freimann
2019-11-20 15:04   ` Michael S. Tsirkin
2019-11-20 15:22     ` Jens Freimann
2019-11-20 14:38 ` [PATCH v2 4/4] net/virtio: return error when device_opts arg is NULL Jens Freimann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.