From nobody Tue Feb 10 05:45:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517860213768702.223094979058; Mon, 5 Feb 2018 11:50:13 -0800 (PST) Received: from localhost ([::1]:54900 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eimmF-0006q4-SR for importer@patchew.org; Mon, 05 Feb 2018 14:50:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44844) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eimSP-0004aZ-2V for qemu-devel@nongnu.org; Mon, 05 Feb 2018 14:29:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eimSN-00053h-Qg for qemu-devel@nongnu.org; Mon, 05 Feb 2018 14:29:37 -0500 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:36858) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eimSN-00053U-Iy for qemu-devel@nongnu.org; Mon, 05 Feb 2018 14:29:35 -0500 Received: by mail-wm0-x241.google.com with SMTP id f3so28130267wmc.1 for ; Mon, 05 Feb 2018 11:29:35 -0800 (PST) Received: from 640k.lan ([82.84.122.246]) by smtp.gmail.com with ESMTPSA id g8sm20029891wra.18.2018.02.05.11.29.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Feb 2018 11:29:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=+sm1uQmd1WeyEGpmgDszGRfkjxoF5elWYX7UmQxRAtU=; b=anCU4ycmHzsr18Pe1hXto0K0WEwuxoOF7iSBidDn+0YX99SN7CLAPJiUskB1a4Dv4P hANUghnWkzIYSBIbQbSGWxzOqBsovA486cSYVDNeqd4JTWwpfMa2THocfhZIS65CIH94 Fx83jxE6KGLAuC7+HC3BZqSe+2zpoZz1No+gRb4FmZfKnSNDiMMH6pNMefnj1vn3wYej lnnC56Qw0ouRQ++IP/ronNLIZbScbRfFiNkK4xFBnCIEoBAxgyhS8TRDydzagUJfT8Mn ThFx2CsBP5lLeBo5MvGDrxsS5qyv87nkl1Iw97AhH5LnSRN7uIMv2f5WqUiZAq7NWEcb jfpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=+sm1uQmd1WeyEGpmgDszGRfkjxoF5elWYX7UmQxRAtU=; b=Z/Dwp8TVc7mLN2xeNSliix6qsF1ko33FdHc8tf0LZtCUA2I0ObBitESSxJLUmzBg6Z Czr5UHdhs2LFMsupV+/pT5bsvr56vjBIJ45pGH6mKLUwjBFD00kKgZu5SednnMJ9ZxnB RotP+aT4Zu6dtQxPSg67pIQZWzmCLWU3ncZLzacw1panj3CciQF6zKTj9olAUOMVyhXX pKLss80Q5xAYCyxdPddvNrtp6JpfVEu2F2XDhPEzC3W5LGrTlJ6Q33AlzEPDXlDQsmO9 a+pHb6F6IHB30C1pCOVG9a8AJWMdKBin4G1t8DMQOLAxB87DbXVayiwRNq2JHy05aqw/ TfIw== X-Gm-Message-State: APf1xPBikDMu7CImaKDumcJcig/9xhtb9cF9t3Un3b384ZUOB/YGUB8z +uGgMOqF4ntJNNkuHPi/cgbiE1lz X-Google-Smtp-Source: AH8x224yX8B2mrSqbmXyd2+D6RKpWVY/9zGG3Nq7PIjmjUXbUNa/gqPf6AlImMi1dgn0v4yB6VuOpA== X-Received: by 10.28.220.66 with SMTP id t63mr307349wmg.100.1517858974142; Mon, 05 Feb 2018 11:29:34 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 5 Feb 2018 20:28:39 +0100 Message-Id: <1517858941-5538-26-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1517858941-5538-1-git-send-email-pbonzini@redhat.com> References: <1517858941-5538-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PULL 25/47] chardev/char-socket: add POLLHUP handler X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Klim Kireev Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Klim Kireev The following behavior was observed for QEMU configured by libvirt to use guest agent as usual for the guests without virtio-serial driver (Windows or the guest remaining in BIOS stage). In QEMU on first connect to listen character device socket the listen socket is removed from poll just after the accept(). virtio_serial_guest_ready() returns 0 and the descriptor of the connected Unix socket is removed from poll and it will not be present in poll() until the guest will initialize the driver and change the state of the serial to "guest connected". In libvirt connect() to guest agent is performed on restart and is run under VM state lock. Connect() is blocking and can wait forever. In this case libvirt can not perform ANY operation on that VM. The bug can be easily reproduced this way: Terminal 1: qemu-system-x86_64 -m 512 -device pci-serial,chardev=3Dserial1 -chardev soc= ket,id=3Dserial1,path=3D/tmp/console.sock,server,nowait (virtio-serial and isa-serial also fit) Terminal 2: minicom -D unix\#/tmp/console.sock (type something and press enter) C-a x (to exit) Do 3 times: minicom -D unix\#/tmp/console.sock C-a x It needs 4 connections, because the first one is accepted by QEMU, then two= are queued by the kernel, and the 4th blocks. The problem is that QEMU doesn't add a read watcher after succesful read until the guest device wants to acquire recieved data, so I propose to install a separate pullhup watcher regardless of whether the device waits for data or not. Signed-off-by: Klim Kireev Message-Id: <20180125135129.9305-1-klim.kireev@virtuozzo.com> Signed-off-by: Paolo Bonzini --- chardev/char-socket.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 77cdf48..a340af6 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -42,6 +42,7 @@ typedef struct { QIOChannel *ioc; /* Client I/O channel */ QIOChannelSocket *sioc; /* Client master channel */ QIONetListener *listener; + GSource *hup_source; QCryptoTLSCreds *tls_creds; int connected; int max_size; @@ -352,6 +353,12 @@ static void tcp_chr_free_connection(Chardev *chr) s->read_msgfds_num =3D 0; } =20 + if (s->hup_source !=3D NULL) { + g_source_destroy(s->hup_source); + g_source_unref(s->hup_source); + s->hup_source =3D NULL; + } + tcp_set_msgfds(chr, NULL, 0); remove_fd_in_watch(chr); object_unref(OBJECT(s->sioc)); @@ -455,6 +462,15 @@ static gboolean tcp_chr_read(QIOChannel *chan, GIOCond= ition cond, void *opaque) return TRUE; } =20 +static gboolean tcp_chr_hup(QIOChannel *channel, + GIOCondition cond, + void *opaque) +{ + Chardev *chr =3D CHARDEV(opaque); + tcp_chr_disconnect(chr); + return G_SOURCE_REMOVE; +} + static int tcp_chr_sync_read(Chardev *chr, const uint8_t *buf, int len) { SocketChardev *s =3D SOCKET_CHARDEV(chr); @@ -528,6 +544,12 @@ static void tcp_chr_connect(void *opaque) tcp_chr_read, chr, chr->gcontext); } + + s->hup_source =3D qio_channel_create_watch(s->ioc, G_IO_HUP); + g_source_set_callback(s->hup_source, (GSourceFunc)tcp_chr_hup, + chr, NULL); + g_source_attach(s->hup_source, chr->gcontext); + qemu_chr_be_event(chr, CHR_EVENT_OPENED); } =20 --=20 1.8.3.1