diff mbox

vhost-user: fix crash when chardev-remove

Message ID 32da9f1f.9022.1598ccf96ce.Coremail.h158309@126.com
State New
Headers show

Commit Message

黄淮 Jan. 11, 2017, 9:15 a.m. UTC
From: Huai Huang<h158309@126.com>



@@ -192,7 +195,8 @@ static gboolean net_vhost_user_watch(GIOChannel *chan, GIOCondition cond,
 {
     VhostUserState *s = opaque;


-    qemu_chr_disconnect(s->chr);
+    if (s->chr)
+        qemu_chr_disconnect(s->chr);


     return FALSE;
 }

Comments

Marc-André Lureau Jan. 11, 2017, 3:02 p.m. UTC | #1
Hi

On Wed, Jan 11, 2017 at 3:32 PM 黄淮 <h158309@126.com> wrote:

> From: Huai Huang<h158309@126.com>
>
>
>
Could you describe a bit more the crash and provide a backtrace?


> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> index f2d49ad..4037cf4 100644
> --- a/hw/net/vhost_net.c
> +++ b/hw/net/vhost_net.c
> @@ -412,7 +412,6 @@ VHostNetState *get_vhost_net(NetClientState *nc)
>          break;
>      case NET_CLIENT_DRIVER_VHOST_USER:
>          vhost_net = vhost_user_get_vhost_net(nc);
> -        assert(vhost_net);
>

This was recently added, in commit
1a5b68cee8a2b165ffd61b2e0641a4da3990f242.

How is it related?

I remember the rest of the vhost-user code expected get_vhost_net() to be
non-null, did that change?

         break;
>      default:
>          break;
> diff --git a/net/vhost-user.c b/net/vhost-user.c
> index b0595f8..4e54478 100644
> --- a/net/vhost-user.c
> +++ b/net/vhost-user.c
> @@ -160,7 +160,10 @@ static void vhost_user_cleanup(NetClientState *nc)
>          qemu_chr_fe_release(s->chr);
>          s->chr = NULL;
>      }
> -
> +    if (s->watch) {
> +        g_source_remove(s->watch);
> +        s->watch = 0;
> +    }
>

Hmm, the socket didn't send a CLOSED event on remove?


>      qemu_purge_queued_packets(nc);
>  }
>
>
> @@ -192,7 +195,8 @@ static gboolean net_vhost_user_watch(GIOChannel *chan,
> GIOCondition cond,
>  {
>      VhostUserState *s = opaque;
>
>
> -    qemu_chr_disconnect(s->chr);
> +    if (s->chr)
> +        qemu_chr_disconnect(s->chr);
>

that looks outdated,

which version of qemu did you tested and patched?

thanks

>
>
>      return FALSE;
>  }
diff mbox

Patch

diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index f2d49ad..4037cf4 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -412,7 +412,6 @@  VHostNetState *get_vhost_net(NetClientState *nc)
         break;
     case NET_CLIENT_DRIVER_VHOST_USER:
         vhost_net = vhost_user_get_vhost_net(nc);
-        assert(vhost_net);
         break;
     default:
         break;
diff --git a/net/vhost-user.c b/net/vhost-user.c
index b0595f8..4e54478 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -160,7 +160,10 @@  static void vhost_user_cleanup(NetClientState *nc)
         qemu_chr_fe_release(s->chr);
         s->chr = NULL;
     }
-
+    if (s->watch) {
+        g_source_remove(s->watch);
+        s->watch = 0;
+    }
     qemu_purge_queued_packets(nc);
 }