qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

io/channel-websock: handle continuous reads without any data

According to the current implementation of websocket protocol in QEMU,
qio_channel_websock_handshake_io tries to read handshake from the
channel to start communication over socket. But this approach
doesn't cover scenario when socket was closed while handshaking.
Therefore, if G_IO_IN is caught and qio_channel_read returns zero,
error has to be set and connection has to be done.

Such behaviour causes 100% CPU load in main QEMU loop, because main loop
poll continues to receive and handle G_IO_IN events from websocket.

Step to reproduce 100% CPU load:
1) start qemu with the simplest configuration
$ qemu -vnc [::1]:1,websocket=7500
2) open any vnc listener (which doesn't follow websocket
protocol)
$ vncviewer :7500
3) kill listener
4) qemu main thread eats 100% CPU

Signed-off-by: Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>

authored by

Edgar Kaziakhmedov and committed by
Daniel P. Berrangé
a46ded1d 28bb0a59

+5 -2
+5 -2
io/channel-websock.c
··· 499 499 error_setg(errp, 500 500 "End of headers not found in first 4096 bytes"); 501 501 return 1; 502 - } else { 503 - return 0; 502 + } else if (ret == 0) { 503 + error_setg(errp, 504 + "End of headers not found before connection closed"); 505 + return -1; 504 506 } 507 + return 0; 505 508 } 506 509 *handshake_end = '\0'; 507 510