From patchwork Thu Apr 24 17:10:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 4053041 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B50C89F271 for ; Thu, 24 Apr 2014 17:10:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C230420306 for ; Thu, 24 Apr 2014 17:10:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BFAA520320 for ; Thu, 24 Apr 2014 17:10:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758749AbaDXRKT (ORCPT ); Thu, 24 Apr 2014 13:10:19 -0400 Received: from fw-tnat.austin.arm.com ([217.140.110.23]:42362 "EHLO collaborate-mta1.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932553AbaDXRKQ (ORCPT ); Thu, 24 Apr 2014 13:10:16 -0400 Received: from e102391-lin.cambridge.arm.com (e102391-lin.cambridge.arm.com [10.1.209.166]) by collaborate-mta1.arm.com (Postfix) with ESMTP id 895C613FC94; Thu, 24 Apr 2014 12:10:10 -0500 (CDT) From: Marc Zyngier To: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: Will Deacon , Pekka Enberg Subject: [PATCH 3/4] kvmtool: Fix handling of POLLHUP when --tty is used Date: Thu, 24 Apr 2014 18:10:05 +0100 Message-Id: <1398359406-31650-4-git-send-email-marc.zyngier@arm.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1398359406-31650-1-git-send-email-marc.zyngier@arm.com> References: <1398359406-31650-1-git-send-email-marc.zyngier@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The --tty option allows the redirection of a console (serial or virtio) to a pseudo-terminal. As long as the slave port of this pseudo-terminal is not opened by another process, a poll() call on the master port will return POLLHUP in the .event field. This confuses the virtio console code, as term_readable() returns a positive value, indicating that something is available, while the call to term_getc_iov will fail. The fix is to check for the presence of the POLLIN flag in the .event field. Note that this is only a partial fix, as kvmtool will still consume vast amounts of CPU resource by spinning like crazy until the slave port is actually opened. Signed-off-by: Marc Zyngier --- tools/kvm/term.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/kvm/term.c b/tools/kvm/term.c index 5c3e543..214f5e2 100644 --- a/tools/kvm/term.c +++ b/tools/kvm/term.c @@ -89,8 +89,10 @@ bool term_readable(int term) .events = POLLIN, .revents = 0, }; + int err; - return poll(&pollfd, 1, 0) > 0; + err = poll(&pollfd, 1, 0); + return (err > 0 && (pollfd.revents & POLLIN)); } static void *term_poll_thread_loop(void *param)