Skip to contentSkip to conversation

vhost-user: fix watcher need be removed when vhost-user hotplug

PATCH In review w00273186 3 participants 6 messages Jul 21, 2017 – Jul 23, 2017 Networking

lore
Share & tools
lore

w00273186

author
#0 lore raw

PATCH 1/1 vhost-user: fix watcher need be removed when vhost-user hotplug

From: Yunjian Wang <[email protected]>

"nc" is freed after hotplug vhost-user, but the watcher don't be removed. The QEMU crash when the watcher access the "nc" on socket disconnect.

    Program received signal SIGSEGV, Segmentation fault.
    #0  object_get_class (obj=obj@entry=0x2) at qom/object.c:750
    #1  0x00007f9bb4180da1 in qemu_chr_fe_disconnect (be=<optimized out>) at chardev/char-fe.c:372
    #2  0x00007f9bb40d1100 in net_vhost_user_watch (chan=<optimized out>, cond=<optimized out>, opaque=<optimized out>) at net/vhost-user.c:188
    #3  0x00007f9baf97f99a in g_main_context_dispatch () from /usr/lib64/libglib-2.0.so.0
    #4  0x00007f9bb41d7ebc in glib_pollfds_poll () at util/main-loop.c:213
    #5  os_host_main_loop_wait (timeout=<optimized out>) at util/main-loop.c:261
    #6  main_loop_wait (nonblocking=nonblocking@entry=0) at util/main-loop.c:515
    #7  0x00007f9bb3e266a7 in main_loop () at vl.c:1917
    #8  main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at vl.c:4786
---
 net/vhost-user.c | 4 ++++
 1 file changed, 4 insertions(+)
net/vhost-user.c +4 -0
index 36f32a2..c23927c 100644
@@ -151,6 +151,10 @@ static void vhost_user_cleanup(NetClientState *nc)
         s->vhost_net = NULL;
     }
     if (nc->queue_index == 0) {
+        if (s->watch) {
+            g_source_remove(s->watch);
+            s->watch = 0;
+        }
         qemu_chr_fe_deinit(&s->chr, true);
     }
 
Signature · 1 line
1.8.3.1
#1 lore raw

Hi

Quoted 6 lines · On Fri, Jul 21, 2017 at 7:18 AM w00273186 <[email protected]> wrote:

From: Yunjian Wang <[email protected]>

"nc" is freed after hotplug vhost-user, but the watcher don't be removed. The QEMU crash when the watcher access the "nc" on socket disconnect.

This is actually your 3rd iteration on the patch

Could your describe your changes since:
"[PATCH v2] vhost-user: fix watcher need be removed when vhost-user hotplug"

Thanks

Quoted 42 lines
    Program received signal SIGSEGV, Segmentation fault.
    #0  object_get_class (obj=obj@entry=0x2) at qom/object.c:750
    #1  0x00007f9bb4180da1 in qemu_chr_fe_disconnect (be=<optimized out>)
at chardev/char-fe.c:372
    #2  0x00007f9bb40d1100 in net_vhost_user_watch (chan=<optimized out>,
cond=<optimized out>, opaque=<optimized out>) at net/vhost-user.c:188
    #3  0x00007f9baf97f99a in g_main_context_dispatch () from

/usr/lib64/libglib-2.0.so.0
#4 0x00007f9bb41d7ebc in glib_pollfds_poll () at util/main-loop.c:213 #5 os_host_main_loop_wait (timeout=<optimized out>) at
util/main-loop.c:261
#6 main_loop_wait (nonblocking=nonblocking@entry=0) at
util/main-loop.c:515
#7 0x00007f9bb3e266a7 in main_loop () at vl.c:1917
#8 main (argc=<optimized out>, argv=<optimized out>, envp=<optimized
out>) at vl.c:4786

---
 net/vhost-user.c | 4 ++++
 1 file changed, 4 insertions(+)
net/vhost-user.c +4 -1
index 36f32a2..c23927c 100644
@@ -151,6 +151,10 @@ static void vhost_user_cleanup(NetClientState *nc)
         s->vhost_net = NULL;
     }
     if (nc->queue_index == 0) {
+        if (s->watch) {
+            g_source_remove(s->watch);
+            s->watch = 0;
+        }
         qemu_chr_fe_deinit(&s->chr, true);
     }
 
--

1.8.3.1

Quoted 1 line

--

Marc-André Lureau

#2 lore raw
Quoted 11 lines · Marc-André Lureau

Hi

On Fri, Jul 21, 2017 at 7:18 AM w00273186 <[email protected]> wrote:

From: Yunjian Wang <[email protected]>

"nc" is freed after hotplug vhost-user, but the watcher don't be removed. The QEMU crash when the watcher access the "nc" on socket disconnect.

Quoted 6 lines

This is actually your 3rd iteration on the patch

Could your describe your changes since:
"[PATCH v2] vhost-user: fix watcher need be removed when vhost-user hotplug"

Thanks

Yes but it's a 3-liner. That's way below the limit where you need detailed change history. Does the patch make sense to you?

Quoted 46 lines
        Program received signal SIGSEGV, Segmentation fault.
        #0  object_get_class (obj=obj@entry=0x2) at qom/object.c:750
        #1  0x00007f9bb4180da1 in qemu_chr_fe_disconnect (be=<optimized out>)
    at chardev/char-fe.c:372
        #2  0x00007f9bb40d1100 in net_vhost_user_watch (chan=<optimized out>,
    cond=<optimized out>, opaque=<optimized out>) at net/vhost-user.c:188
        #3  0x00007f9baf97f99a in g_main_context_dispatch () from /usr/lib64/
    libglib-2.0.so.0
        #4  0x00007f9bb41d7ebc in glib_pollfds_poll () at util/main-loop.c:213
        #5  os_host_main_loop_wait (timeout=<optimized out>) at util/
    main-loop.c:261
        #6  main_loop_wait (nonblocking=nonblocking@entry=0) at util/
    main-loop.c:515
        #7  0x00007f9bb3e266a7 in main_loop () at vl.c:1917
        #8  main (argc=<optimized out>, argv=<optimized out>, envp=<optimized
    out>) at vl.c:4786

    Signed-off-by: Yunjian Wang <[email protected]>
    ---
     net/vhost-user.c | 4 ++++
     1 file changed, 4 insertions(+)

    diff --git a/net/vhost-user.c b/net/vhost-user.c
    index 36f32a2..c23927c 100644
    --- a/net/vhost-user.c
    +++ b/net/vhost-user.c
    @@ -151,6 +151,10 @@ static void vhost_user_cleanup(NetClientState *nc)
             s->vhost_net = NULL;
         }
         if (nc->queue_index == 0) {
    +        if (s->watch) {
    +            g_source_remove(s->watch);
    +            s->watch = 0;
    +        }
             qemu_chr_fe_deinit(&s->chr, true);
         }

    --
    1.8.3.1

--
Marc-André Lureau

#3 lore raw
Quoted 16 lines · Michael S. Tsirkin
Quoted 3 lines · Marc-André Lureau

Hi

On Fri, Jul 21, 2017 at 7:18 AM w00273186 <[email protected]>

Quoted 4 lines · wrote:

From: Yunjian Wang <[email protected]>

"nc" is freed after hotplug vhost-user, but the watcher don't be

removed.

Quoted 6 lines

The QEMU crash when the watcher access the "nc" on socket disconnect.

This is actually your 3rd iteration on the patch

Quoted 10 lines
Quoted 2 lines

Could your describe your changes since:
"[PATCH v2] vhost-user: fix watcher need be removed when vhost-user

hotplug"

Quoted 2 lines

Thanks

Yes but it's a 3-liner. That's way below the limit where you need detailed change history. Does the patch make sense to you?

That's not all, the fact that he didn't come up with the same solution in the first place, and I didn't notice a problem either with the previous approach is enough to ask from some clarification on which approach is best, and I bet there is something to say.

Furthermore, we would really benefit from having repeatable cases for this kind of fixes.

Quoted 53 lines
Quoted 4 lines
        Program received signal SIGSEGV, Segmentation fault.
        #0  object_get_class (obj=obj@entry=0x2) at qom/object.c:750
        #1  0x00007f9bb4180da1 in qemu_chr_fe_disconnect (be=<optimized

out>)

Quoted 2 lines
    at chardev/char-fe.c:372
        #2  0x00007f9bb40d1100 in net_vhost_user_watch (chan=<optimized

out>,

Quoted 2 lines

cond=<optimized out>, opaque=<optimized out>) at net/vhost-user.c:188
#3 0x00007f9baf97f99a in g_main_context_dispatch () from

/usr/lib64/

Quoted 2 lines
    libglib-2.0.so.0
        #4  0x00007f9bb41d7ebc in glib_pollfds_poll () at

util/main-loop.c:213

Quoted 6 lines

#5 os_host_main_loop_wait (timeout=<optimized out>) at util/
main-loop.c:261
#6 main_loop_wait (nonblocking=nonblocking@entry=0) at util/
main-loop.c:515
#7 0x00007f9bb3e266a7 in main_loop () at vl.c:1917 #8 main (argc=<optimized out>, argv=<optimized out>,

envp=<optimized

Quoted 4 lines
    out>) at vl.c:4786

    Signed-off-by: Yunjian Wang <[email protected]>
    ---
Quoted 8 lines
     net/vhost-user.c | 4 ++++
     1 file changed, 4 insertions(+)

    diff --git a/net/vhost-user.c b/net/vhost-user.c
    index 36f32a2..c23927c 100644
    --- a/net/vhost-user.c
    +++ b/net/vhost-user.c
    @@ -151,6 +151,10 @@ static void vhost_user_cleanup(NetClientState

*nc)

Quoted 18 lines
             s->vhost_net = NULL;
         }
         if (nc->queue_index == 0) {
    +        if (s->watch) {
    +            g_source_remove(s->watch);
    +            s->watch = 0;
    +        }
             qemu_chr_fe_deinit(&s->chr, true);
         }

    --
    1.8.3.1

--
Marc-André Lureau

Signature · 1 line
Marc-André Lureau
#4 lore raw
Quoted 30 lines · Marc-André Lureau

On Sat, Jul 22, 2017 at 2:35 AM Michael S. Tsirkin <[email protected]> wrote:

    On Fri, Jul 21, 2017 at 11:19:04AM +0000, Marc-André Lureau wrote:
    > Hi
    >
    > On Fri, Jul 21, 2017 at 7:18 AM w00273186 <[email protected]> wrote:
    >
    >     From: Yunjian Wang <[email protected]>
    >
    >     "nc" is freed after hotplug vhost-user, but the watcher don't be
    removed.
    >     The QEMU crash when the watcher access the "nc" on socket disconnect.
    >
    >
    >
    > This is actually your 3rd iteration on the patch
    >
    > Could your describe your changes since:
    > "[PATCH v2] vhost-user: fix watcher need be removed when vhost-user
    hotplug"
    >
    > Thanks

    Yes but it's a 3-liner. That's way below the limit where you need
    detailed change history. Does the patch make sense to you?
Quoted 4 lines

That's not all, the fact that he didn't come up with the same solution in the first place, and I didn't notice a problem either with the previous approach is enough to ask from some clarification on which approach is best, and I bet there is something to say.

I'm rather confused. Looks like you were the one who asked for the change. Really we want to attract new contributors and a small bugfix like this seems like a very good way to start contributing. Changelog is already 3 times the size of the patch here. So I think we should just get the patch reviewed and applied if correct. Do you plan to review it?

Quoted 2 lines

Furthermore, we would really benefit from having repeatable cases for this kind of fixes.

I agree disconnect path is but tested adequately but I don't think we are at a point where we should be asking for testcases for every use after free bug that gets fixed.

Quoted 55 lines

Quoted 4 lines

         Program received signal SIGSEGV, Segmentation fault. #0  object_get_class (obj=obj@entry=0x2) at qom/object.c:750 #1  0x00007f9bb4180da1 in qemu_chr_fe_disconnect (be=<optimized

    out>)
    >     at chardev/char-fe.c:372
    >         #2  0x00007f9bb40d1100 in net_vhost_user_watch (chan=<optimized
    out>,
    >     cond=<optimized out>, opaque=<optimized out>) at net/vhost-user.c:188
    >         #3  0x00007f9baf97f99a in g_main_context_dispatch () from /usr/
    lib64/
    >     libglib-2.0.so.0
    >         #4  0x00007f9bb41d7ebc in glib_pollfds_poll () at util/
    main-loop.c:213
    >         #5  os_host_main_loop_wait (timeout=<optimized out>) at util/
    >     main-loop.c:261
    >         #6  main_loop_wait (nonblocking=nonblocking@entry=0) at util/
    >     main-loop.c:515
    >         #7  0x00007f9bb3e266a7 in main_loop () at vl.c:1917
    >         #8  main (argc=<optimized out>, argv=<optimized out>, envp=
    <optimized
    >     out>) at vl.c:4786
    >
    >     Signed-off-by: Yunjian Wang <[email protected]>
    >     ---
    >      net/vhost-user.c | 4 ++++
    >      1 file changed, 4 insertions(+)
    >
    >     diff --git a/net/vhost-user.c b/net/vhost-user.c
    >     index 36f32a2..c23927c 100644
    >     --- a/net/vhost-user.c
    >     +++ b/net/vhost-user.c
    >     @@ -151,6 +151,10 @@ static void vhost_user_cleanup(NetClientState
    *nc)
    >              s->vhost_net = NULL;
    >          }
    >          if (nc->queue_index == 0) {
    >     +        if (s->watch) {
    >     +            g_source_remove(s->watch);
    >     +            s->watch = 0;
    >     +        }
    >              qemu_chr_fe_deinit(&s->chr, true);
    >          }
    >
    >     --
    >     1.8.3.1
    >
    >
    >
    >
    > --
    > Marc-André Lureau
Quoted 2 lines

--
Marc-André Lureau

Why do you even bother including the patch if you use a client that corrupts both the patch and the commit log formatting? It's not a good example to give to new contributors and it doesn't align well with nit-picking about same commit log, in my eyes.

Signature · 1 line
MST
#5 lore raw

Hi

Quoted 36 lines · Michael S. Tsirkin
Quoted 30 lines · Marc-André Lureau

On Sat, Jul 22, 2017 at 2:35 AM Michael S. Tsirkin <[email protected]> wrote:

    On Fri, Jul 21, 2017 at 11:19:04AM +0000, Marc-André Lureau wrote:
    > Hi
    >
    > On Fri, Jul 21, 2017 at 7:18 AM w00273186 <[email protected]> wrote:
    >
    >     From: Yunjian Wang <[email protected]>
    >
    >     "nc" is freed after hotplug vhost-user, but the watcher don't be
    removed.
    >     The QEMU crash when the watcher access the "nc" on socket disconnect.
    >
    >
    >
    > This is actually your 3rd iteration on the patch
    >
    > Could your describe your changes since:
    > "[PATCH v2] vhost-user: fix watcher need be removed when vhost-user
    hotplug"
    >
    > Thanks

    Yes but it's a 3-liner. That's way below the limit where you need
    detailed change history. Does the patch make sense to you?
Quoted 4 lines

That's not all, the fact that he didn't come up with the same solution in the first place, and I didn't notice a problem either with the previous approach is enough to ask from some clarification on which approach is best, and I bet there is something to say.

Quoted 5 lines

I'm rather confused. Looks like you were the one who asked for the change. Really we want to attract new contributors and a small bugfix like this seems like a very good way to start contributing. Changelog is already 3 times the size of the patch here. So I think we should just get the patch reviewed and applied if correct. Do you plan to review it?

Indeed, but I totally forgot.

This situation wouldn't happen if:
- the patch was version v3
- the patch/mail would have been annotated after --- to quickly describe the change
- I had better memory...

Quoted 7 lines
Quoted 3 lines

Furthermore, we would really benefit from having repeatable cases for this kind of fixes.

I agree disconnect path is but tested adequately but I don't think we are at a point where we should be asking for testcases for every use after free bug that gets fixed.

Not to write a test case, but at least to document what triggered this path. Since Yunjian gave it in the previous reply, and I forgot that too, it would be best to have it in the commit message, agree?

Signature · 1 line
Marc-André Lureau