From nobody Wed May 1 07:49:27 2024 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 Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511162159407850.5914295374563; Sun, 19 Nov 2017 23:15:59 -0800 (PST) Received: from localhost ([::1]:55717 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eGgIv-0000c2-Tk for importer@patchew.org; Mon, 20 Nov 2017 02:15:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50712) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eGgHr-0000AE-Sy for qemu-devel@nongnu.org; Mon, 20 Nov 2017 02:14:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eGgHo-0004D6-MA for qemu-devel@nongnu.org; Mon, 20 Nov 2017 02:14:35 -0500 Received: from ozlabs.org ([103.22.144.67]:46477) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eGgHn-0004Cj-Vo; Mon, 20 Nov 2017 02:14:32 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 3ygKhz43J6z9s5L; Mon, 20 Nov 2017 18:14:27 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1511162067; bh=0c50c0d8U5oIL+eEWLVR7Ki6Lk1ajm5jt1xhBEENOLM=; h=From:To:Cc:Subject:Date:From; b=GwD0UrQ92YC48odGe0LBVJV0ea7Yf7MvETBJHSygX5yc9oLvT8+5Z9ByWznRk1vC9 64yRk20+DuZF6bWW5zJIFD19rRUwDrmOFIrq61WxMTAG6M7v7RedwsgW0Q3+Uipdw5 yOVbxjV9GKDZb5LLTo5Hl5BlLVqvYRAYTsesktGw= From: David Gibson To: lvivier@redhat.com, paulus@samba.org, groug@kaod.org Date: Mon, 20 Nov 2017 18:14:23 +1100 Message-Id: <20171120071423.11693-1-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.14.3 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] [PATCH] 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: qemu-ppc@nongnu.org, qemu-devel@nongnu.org, David Gibson 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" 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: Greg Kurz Reviewed-by: Thomas Huth --- 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..a95e5e91a7 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 *b= uf, int max) =20 while ((n < max) && (dev->out !=3D dev->in)) { buf[n++] =3D 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] =3D=3D '\r') { + if (n < max) { + buf[n++] =3D '\0'; + } else { + /* No room for the extra \0, roll back and try again + * next time */ + dev->out--; + n--; + break; + } + } } =20 qemu_chr_fe_accept_input(&dev->chardev); --=20 2.14.3