From nobody Tue May 7 13:19:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=ozlabs.org ARC-Seal: i=1; a=rsa-sha256; t=1564547871; cv=none; d=zoho.com; s=zohoarc; b=fM2rZhLjV93jzjKwbaYvg+jQXm9TkXAPrmXU1pFQRDXQ7B3IcK8lbzFmukgdKVs6EbAvg2BXIVVnlDCuRTl6S2usKu1QpwhgfM0eyXGkSuz7yYIWImecwmwZ1qfmHuZP56l622HPxcEmS48V2wRm2pZ1Uv3N7iEukdNJjHO5ctw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564547871; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=dDRs3BPuXWtoks3jhAxYsINo4OcHDW+SUtDbSzX5yOE=; b=i2n9hDzyxDoHKBsee0IZEj0K1fMR3YhvWrIQnD9EwTkWbKoEgFzgbLqrE+bkuuxeyQEG+wXTf+b7Gjy+uEpvNwvceiJ3tJFmQL42OVEodolm6lvmo1IfYsSeLK3+c6hgXVL+vNcEAVXYiRxSEpxiQ7ZTrTEZRK9Oc+xR/yt87cE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 156454787135328.859445289691166; Tue, 30 Jul 2019 21:37:51 -0700 (PDT) Received: from localhost ([::1]:37918 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsgMw-0000Y1-Vy for importer@patchew.org; Wed, 31 Jul 2019 00:37:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47545) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsgMU-0008TI-OT for qemu-devel@nongnu.org; Wed, 31 Jul 2019 00:37:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsgMT-0005Tm-60 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 00:37:14 -0400 Received: from ozlabs.org ([203.11.71.1]:40625) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hsgMS-00056I-AJ; Wed, 31 Jul 2019 00:37:13 -0400 Received: by ozlabs.org (Postfix, from userid 1003) id 45z0y52tY9z9sBF; Wed, 31 Jul 2019 14:37:01 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1564547821; bh=vx2RT6qoZjZbe3n1PLLehcFhxntjm5MZuNilM0hjAwQ=; h=Date:From:To:Cc:Subject:From; b=dJBAV1liTtOH5z70Yxfu8MIb4QtF8aOEDrkr2CxcTrTHLUJvrMUbRZvPNjF15PUSw 5dL4wXvzumgVqMxML7vH79HdSdlCJeq6bdka6jez2pbZ6VvaWgiiGS326eFuIV/9+g yRxBd0C9b3IExVY7pBUzBzvDDX+OCbQQ4no1FYnfHmzLzjtE1aDbDjA+UDWSVyul+o K8S2RPv/NN5vOQ+X56PiiQr6Mx/VHdq4dwL2zWjMBc1wfWpy0e+Nu/oREWpWZ0ZmDM g/JKOmrQrbPKNu5//bHXdZ5klv9ECLgvyljoV4bkKBdT1a11t+lrFel1ALN6CRznIp /rGIW9y95X1yA== Date: Wed, 31 Jul 2019 14:36:54 +1000 From: Paul Mackerras To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org Message-ID: <20190731043653.shdi5sizjp4t65op@oak.ozlabs.ibm.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 203.11.71.1 Subject: [Qemu-devel] [PATCH] spapr: Implement better workaround in spapr-vty device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Linux guest kernels have code which scans the string of characters returned from the H_GET_TERM_CHAR hypercall and removes any \0 character which comes immediately after a \r character. This is to work around a bug which was present in some ancient versions of PowerVM. In order to avoid the corruption of the console byte stream that this introduced, commit 6c3bc244d3cb ("spapr: Implement bug in spapr-vty device to be compatible with PowerVM") added a workaround which adds a \0 character after every \r character. Unfortunately, this corrupts the console byte stream for those operating systems, such as AIX, which don't remove the null bytes. We can avoid triggering the Linux kernel workaround if we avoid returning a buffer which contains a \0 after a \r. We can do that by breaking out of the loop in vty_getchars() if we are about to insert a \0 and the previous character in the buffer is a \r. That means we return the characters up to the \r for the current H_GET_TERM_CHAR, and the characters starting with the \0 for the next one. With this workaround, we don't insert any spurious characters and we avoid triggering the Linux kernel workaround, so the guest will receive an uncorrupted stream whether or not they have the workaround. Fixes: 6c3bc244d3cb ("spapr: Implement bug in spapr-vty device to be compat= ible with PowerVM") Signed-off-by: Paul Mackerras --- hw/char/spapr_vty.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/hw/char/spapr_vty.c b/hw/char/spapr_vty.c index 617303dbaf..65a7c2ffbd 100644 --- a/hw/char/spapr_vty.c +++ b/hw/char/spapr_vty.c @@ -57,25 +57,19 @@ static int vty_getchars(SpaprVioDevice *sdev, uint8_t *= buf, int max) int n =3D 0; =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; - } + /* + * Long ago, PowerVM's vty implementation had a bug where it + * inserted a \0 after every \r going to the guest. Existing + * guests have a workaround for this which removes every \0 + * immediately following a \r. To avoid triggering this + * workaround, we stop before inserting a \0 if the preceding + * character in the output buffer is a \r. + */ + if (n > 0 && (buf[n - 1] =3D=3D '\r') && + (dev->buf[dev->out % VTERM_BUFSIZE] =3D=3D '\0')) { + break; } + buf[n++] =3D dev->buf[dev->out++ % VTERM_BUFSIZE]; } =20 qemu_chr_fe_accept_input(&dev->chardev); --=20 2.11.0