<div dir="ltr">Thank you!<div>But it looks like libvirtd daemon stream module still has bug lead to process segfault if applied this patch(if not, it will lead libvirtd deadlock).I have got the cause, but it seems difficult to fix it with present codes。</div><div>Bug reproduce:</div><div>1. add sleep(3) in daemonStreamFilter() so it is easily to get the point, as follows</div><div>  static int<br>daemonStreamFilter(virNetServerClientPtr client,<br>                   virNetMessagePtr msg,<br>                   void *opaque)<br>{<br>    daemonClientStream *stream = opaque;<br>    int ret = 0;<br>    static int first = 1;<br><br>//    if (first) {<br>//        notify_force_console();<br>//        VIR_ERROR("notify force console to break this client down!client: %p", client);<br>//        sleep(30);<br>//        VIR_ERROR("sleep 10 finished");<br>//    }<br>    VIR_ERROR("stream: %p, filter_id: %d", stream, stream->filterID);<br>    virObjectUnlock(client);<br>    sleep(3);<br>    virMutexLock(&stream->priv->lock);<br>    virObjectLock(client);<br></div><div>2. build the libvirtd with new code, then replace the libvirtd</div><div>3. use virsh console to open a vm's console tty, then just input many chars in the console</div><div>4. open new terminal, then use virsh console --force to break the previous client, then you'll got libvirtd segfault</div><div><br></div><div>it looks because when daemonStreamEvent() with para events as VIR_STREAM_EVENT_ERROR  is called, it will remove stream and free stream,</div><div>but daemonStreamFilter still waiting stream->priv->lock mutex, thus cause invalid memory access</div><div><br></div><div>To fix this, I think the most effective and clean way is to drop client->priv->lock elements, just use client object lock。But for current code, it's not easy to do that。</div><div>also, a workaroud scheme is  to add a big lock, but is ugly and low efficient。</div><div><br></div><div>Any good ideas?</div><div><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Michal Privoznik <<a href="mailto:mprivozn@redhat.com">mprivozn@redhat.com</a>> 于2019年11月19日周二 下午11:41写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 11/19/19 12:39 PM, LanceLiu wrote:<br>
> (gdb) thread 23<br>
> [Switching to thread 23 (Thread 0x7fbb54810700 (LWP 296966))]<br>
> (gdb) bt<br>
>      at rpc/virnetserverclient.c:1503<br>
>      client=client@entry=0x5641d20e20a0, msg=0x7fbb08003ab0, rerr=rerr@entry=0x7fbb5480f7b0, procedure=201,<br>
>      type=type@entry=3, serial=9) at rpc/virnetserverprogram.c:173<br>
>      msg=<optimized out>, rerr=rerr@entry=0x7fbb5480f7b0, procedure=<optimized out>, serial=<optimized out>)<br>
>      at rpc/virnetserverprogram.c:222<br>
>      opaque=opaque@entry=0x5641d20e20a0) at stream.c:246<br>
>      force=force@entry=true) at conf/virchrdev.c:386<br>
>      at qemu/qemu_driver.c:16188<br>
>      st=st@entry=0x7fbb08008fc0, flags=1) at libvirt-domain.c:9363<br>
>      rerr=0x7fbb5480fc10, msg=<optimized out>, client=0x5641d20e4e80) at remote_dispatch.h:8540<br>
>      rerr=0x7fbb5480fc10, args=0x7fbb08005eb0, ret=<optimized out>) at remote_dispatch.h:8505<br>
>      server=0x5641d20be420, prog=0x5641d20da580) at rpc/virnetserverprogram.c:437<br>
>      msg=0x5641d20e9a20) at rpc/virnetserverprogram.c:307<br>
>      srv=0x5641d20be420) at rpc/virnetserver.c:148<br>
> ---Type <return> to continue, or q <return> to quit---<br>
> <br>
> (gdb) thread 26<br>
> [Switching to thread 26 (Thread 0x7fbb87a378c0 (LWP 295636))]<br>
> (gdb) bt<br>
>      at stream.c:286<br>
>      at rpc/virnetserverclient.c:1247<br>
>      at rpc/virnetserverclient.c:1457<br>
>      at util/vireventpoll.c:508<br>
> <br>
> Signed-off-by: LanceLiu <<a href="mailto:liu.lance.89@gmail.com" target="_blank">liu.lance.89@gmail.com</a>><br>
> ---<br>
>   src/remote/remote_daemon_stream.c | 4 +++-<br>
>   1 file changed, 3 insertions(+), 1 deletion(-)<br>
> <br>
> diff --git a/src/remote/remote_daemon_stream.c b/src/remote/remote_daemon_stream.c<br>
> index 1f6e783..b27348f 100644<br>
> --- a/src/remote/remote_daemon_stream.c<br>
> +++ b/src/remote/remote_daemon_stream.c<br>
> @@ -284,14 +284,16 @@ daemonStreamEvent(virStreamPtr st, int events, void *opaque)<br>
>    * -1 on fatal client error<br>
>    */<br>
>   static int<br>
> -daemonStreamFilter(virNetServerClientPtr client ATTRIBUTE_UNUSED,<br>
> +daemonStreamFilter(virNetServerClientPtr client,<br>
<br>
This does not look rebased onto current git HEAD ;-) "Luckily", the <br>
problem you're fixing is still there.<br>
<br>
>                      virNetMessagePtr msg,<br>
>                      void *opaque)<br>
>   {<br>
>       daemonClientStream *stream = opaque;<br>
>       int ret = 0;<br>
>   <br>
> +    virObjectUnlock(client);<br>
>       virMutexLock(&stream->priv->lock);<br>
> +    virObjectLock(client);<br>
>   <br>
>       if (msg->header.type != VIR_NET_STREAM &&<br>
>           msg->header.type != VIR_NET_STREAM_HOLE)<br>
> <br>
<br>
I've reworded the commit message, put a comment to <br>
virNetServerClientFilterFunc() typedef, ACKed and pushed.<br>
<br>
Congratulations on your first libvirt contribution!<br>
<br>
Michal<br>
<br>
</blockquote></div>