From patchwork Wed Nov 22 04:48:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 840258 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.b="kRniz3uF"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yhVNc39xWz9s1h for ; Wed, 22 Nov 2017 15:49:20 +1100 (AEDT) Received: from localhost ([::1]:37831 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHMyM-000676-IL for incoming@patchwork.ozlabs.org; Tue, 21 Nov 2017 23:49:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60382) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHMxW-0005wl-46 for qemu-devel@nongnu.org; Tue, 21 Nov 2017 23:48:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eHMxT-00037t-2E for qemu-devel@nongnu.org; Tue, 21 Nov 2017 23:48:26 -0500 Received: from ozlabs.org ([103.22.144.67]:52801) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eHMxS-000365-9j; Tue, 21 Nov 2017 23:48:22 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 3yhVMP1kvpz9sBZ; Wed, 22 Nov 2017 15:48:17 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1511326097; bh=2N5x1LDOs04EGaCFdwl+G+0g+ewme+f9L+XYhJs9Wo8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kRniz3uF5bXyyhzVwNuKA2oXvrj6BJof/iLzRqUSBwpaojjkfLiQtC1BdecU8+3rx 0/Z6JgI54XoD5WxEXZ/z4+mQw+yGp5F0QVGKY05MfQ1wgkvhM0epwpYK6m197NBoa4 btO/PAFFvJzmk2+KSZXvYs82FPQ+BD7QLZ5ODuBk= From: David Gibson To: peter.maydell@linaro.org Date: Wed, 22 Nov 2017 15:48:13 +1100 Message-Id: <20171122044814.3001-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171122044814.3001-1-david@gibson.dropbear.id.au> References: <20171122044814.3001-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PULL 2/3] spapr: Implement bug in spapr-vty device to be compatible with PowerVM 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: lvivier@redhat.com, qemu-devel@nongnu.org, agraf@suse.de, groug@kaod.org, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The spapr-vty device implements the PAPR defined virtual console, which is also implemented by IBM's proprietary PowerVM hypervisor. PowerVM's implementation has a bug where it inserts an extra \0 after every \r going to the guest. Because of that Linux's guest side driver has a workaround which strips \0 characters that appear immediately after a \r. That means that when running under qemu, sending a binary stream from host to guest via spapr-vty which happens to include a \r\0 sequence will get corrupted by that workaround. To deal with that, this patch duplicates PowerVM's bug, inserting an extra \0 after each \r. Ugly, but the best option available. Signed-off-by: David Gibson Reviewed-by: Thomas Huth Reviewed-by: Greg Kurz --- hw/char/spapr_vty.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/hw/char/spapr_vty.c b/hw/char/spapr_vty.c index 0fa416ca6b..6748334ded 100644 --- a/hw/char/spapr_vty.c +++ b/hw/char/spapr_vty.c @@ -58,6 +58,24 @@ static int vty_getchars(VIOsPAPRDevice *sdev, uint8_t *buf, int max) while ((n < max) && (dev->out != dev->in)) { buf[n++] = dev->buf[dev->out++ % VTERM_BUFSIZE]; + + /* PowerVM's vty implementation has a bug where it inserts a + * \0 after every \r going to the guest. Existing guests have + * a workaround for this which removes every \0 immediately + * following a \r, so here we make ourselves bug-for-bug + * compatible, so that the guest won't drop a real \0-after-\r + * that happens to occur in a binary stream. */ + if (buf[n - 1] == '\r') { + if (n < max) { + buf[n++] = '\0'; + } else { + /* No room for the extra \0, roll back and try again + * next time */ + dev->out--; + n--; + break; + } + } } qemu_chr_fe_accept_input(&dev->chardev);