From nobody Mon Feb 9 18:45:19 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.zoho.com; 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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487259483907980.6655155144978; Thu, 16 Feb 2017 07:38:03 -0800 (PST) Received: from localhost ([::1]:47380 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceO89-0006en-H6 for importer@patchew.org; Thu, 16 Feb 2017 10:38:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51742) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceN6Q-0003ad-2V for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:32:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceN6P-00082n-7A for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:32:10 -0500 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:36680) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ceN6P-00082d-0U for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:32:09 -0500 Received: by mail-wr0-x242.google.com with SMTP id z61so1487307wrc.3 for ; Thu, 16 Feb 2017 06:32:08 -0800 (PST) Received: from 640k.lan (94-39-187-56.adsl-ull.clienti.tiscali.it. [94.39.187.56]) by smtp.gmail.com with ESMTPSA id g5sm9203365wrd.0.2017.02.16.06.32.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Feb 2017 06:32:07 -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 :mime-version:content-transfer-encoding; bh=Wxhew6z1gCaxtFCLCACx16w++ibxtQWx/mkRf0cMQ0E=; b=orN0DktkzqKvrRasSzpLGhA5AaZKwIriT1NJ5+YXyqQKre2bIEpNv1TIcx454uKTjY 3w7oJsIke0qWo/WZ8H/5GLKbmoo23IHZLCSQ2uWa1xcZu8j1PnurpdRLOdNLmW76IxVq 9ravQxand6WIBHdiqDHwHccRynD5lio1k5jbngcMjNZrUPV6Ge96guqY0A7M4HOmc1HN eDWeSkL5btnenBayth3OBs3hRKjQafEcuzD4+sHuPZn2V7HOl661c1Bkbzgsy9ct8blO yGb0DOy3f8maAHfogBHl3oj+nKyAqdndbiloIGVUt3k1AWeRVZFXXGFtnLzjixLa23iw UsLw== 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:mime-version:content-transfer-encoding; bh=Wxhew6z1gCaxtFCLCACx16w++ibxtQWx/mkRf0cMQ0E=; b=Pu3Ut6LR66VK+ObLjbaGstP7RE/fX15cxTIH8k+rk2EFzvToCZvjPm7A+EldYgVhDn Xq1ZCVTbxurxg7gsaE9ZyeWvshqpz2f+CfFZhmN/Irar7wJJ7PBAQvzcVqMxekNdc0De qelHNclSJQ9rdvkJF/PukoFihTLaqtroxC/xcg1IBxAm7tQOS1McVxM1l6jv4E660LNg NtaAg68PsVF/jXk08lbBYGOC2mxxs2JeliYzWS4fHRgR4s3Xt7eRryPn1/hVK+2qVWL1 wIZ4IcnIps4YoP+CDf5H7s1h56woAiip7+P/fl/YTywPskcqY5oyLzo7qKoYlR7jUN3f MSeA== X-Gm-Message-State: AMke39msPBwGhnBSXuWaV5vdI9DKHsBIjGhxx3lAv6FJy2TKSi9Mwyb25sN9G5sysQN3fQ== X-Received: by 10.223.163.142 with SMTP id l14mr156190wrb.35.1487255527855; Thu, 16 Feb 2017 06:32:07 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 16 Feb 2017 15:31:29 +0100 Message-Id: <1487255507-106654-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1487255507-106654-1-git-send-email-pbonzini@redhat.com> References: <1487255507-106654-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c0c::242 Subject: [Qemu-devel] [PULL 05/23] qemu-char: socket backend: disconnect on write error 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: "Denis V. Lunev" , Anton Nefedov , =?UTF-8?q?Marc-Andr=C3=83=C2=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Anton Nefedov Socket backend read handler should normally perform a disconnect, however the read handler may not get a chance to run if the frontend is not ready (qemu_chr_be_can_write() =3D=3D 0). This means that in virtio-serial frontend case if - the host has disconnected (giving EPIPE on socket write) - and the guest has disconnected (-> frontend not ready -> backend will not read) - and there is still data (frontend->backend) to flush (has to be a really tricky timing but nevertheless, we have observed the case in production) This results in virtio-serial trying to flush this data continiously forming a busy loop. Solution: react on write error in the socket write handler. errno is not reliable after qio_channel_writev_full(), so we may not get the exact EPIPE, so disconnect on any error but QIO_CHANNEL_ERR_BLOCK which io_channel_send_full() converts to errno EAGAIN. We must not disconnect right away though, there still may be data to read (see 4bf1cb0). Signed-off-by: Anton Nefedov Signed-off-by: Denis V. Lunev CC: Paolo Bonzini CC: Daniel P. Berrange CC: Marc-Andr=C3=83=C2=A9 Lureau Message-Id: <1486045589-8074-1-git-send-email-den@openvz.org> Signed-off-by: Paolo Bonzini --- chardev/char-socket.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 4068dc5..865c527 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -97,6 +97,9 @@ static gboolean tcp_chr_accept(QIOChannel *chan, GIOCondition cond, void *opaque); =20 +static int tcp_chr_read_poll(void *opaque); +static void tcp_chr_disconnect(Chardev *chr); + /* Called with chr_write_lock held. */ static int tcp_chr_write(Chardev *chr, const uint8_t *buf, int len) { @@ -114,6 +117,13 @@ static int tcp_chr_write(Chardev *chr, const uint8_t *= buf, int len) s->write_msgfds_num =3D 0; } =20 + if (ret < 0 && errno !=3D EAGAIN) { + if (tcp_chr_read_poll(chr) <=3D 0) { + tcp_chr_disconnect(chr); + return len; + } /* else let the read handler finish it properly */ + } + return ret; } else { /* XXX: indicate an error ? */ --=20 1.8.3.1