Blame SOURCES/kvm-spapr-Implement-bug-in-spapr-vty-device-to-be-compat.patch

4a2fec
From ea460580ae8d4910bddac476b25eb31c04b4e54c Mon Sep 17 00:00:00 2001
4a2fec
From: David Gibson <dgibson@redhat.com>
4a2fec
Date: Mon, 27 Nov 2017 04:56:27 +0100
4a2fec
Subject: [PATCH 5/7] spapr: Implement bug in spapr-vty device to be compatible
4a2fec
 with PowerVM
4a2fec
4a2fec
RH-Author: David Gibson <dgibson@redhat.com>
4a2fec
Message-id: <20171127045627.20341-1-dgibson@redhat.com>
4a2fec
Patchwork-id: 77896
4a2fec
O-Subject: [RHEL-7.5 qemu-kvm-rhev PATCH] spapr: Implement bug in spapr-vty device to be compatible with PowerVM
4a2fec
Bugzilla: 1495090
4a2fec
RH-Acked-by: Thomas Huth <thuth@redhat.com>
4a2fec
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
4a2fec
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
4a2fec
From: David Gibson <david@gibson.dropbear.id.au>
4a2fec
4a2fec
The spapr-vty device implements the PAPR defined virtual console,
4a2fec
which is also implemented by IBM's proprietary PowerVM hypervisor.
4a2fec
4a2fec
PowerVM's implementation has a bug where it inserts an extra \0 after
4a2fec
every \r going to the guest.  Because of that Linux's guest side
4a2fec
driver has a workaround which strips \0 characters that appear
4a2fec
immediately after a \r.
4a2fec
4a2fec
That means that when running under qemu, sending a binary stream from
4a2fec
host to guest via spapr-vty which happens to include a \r\0 sequence
4a2fec
will get corrupted by that workaround.
4a2fec
4a2fec
To deal with that, this patch duplicates PowerVM's bug, inserting an
4a2fec
extra \0 after each \r.  Ugly, but the best option available.
4a2fec
4a2fec
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4a2fec
Reviewed-by: Thomas Huth <thuth@redhat.com>
4a2fec
Reviewed-by: Greg Kurz <groug@kaod.org>
4a2fec
(cherry picked from commit 6c3bc244d3cbdc5545504fda4fae0238ec36a3c0)
4a2fec
4a2fec
Testing: Verified that when transferring a file (raw) through
4a2fec
         spapr-vty device, '\r\0' sequences are no longer mangled.
4a2fec
4a2fec
Signed-off-by: David Gibson <dgibson@redhat.com>
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 hw/char/spapr_vty.c | 18 ++++++++++++++++++
4a2fec
 1 file changed, 18 insertions(+)
4a2fec
4a2fec
diff --git a/hw/char/spapr_vty.c b/hw/char/spapr_vty.c
4a2fec
index 0fa416c..6748334 100644
4a2fec
--- a/hw/char/spapr_vty.c
4a2fec
+++ b/hw/char/spapr_vty.c
4a2fec
@@ -58,6 +58,24 @@ static int vty_getchars(VIOsPAPRDevice *sdev, uint8_t *buf, int max)
4a2fec
 
4a2fec
     while ((n < max) && (dev->out != dev->in)) {
4a2fec
         buf[n++] = dev->buf[dev->out++ % VTERM_BUFSIZE];
4a2fec
+
4a2fec
+        /* PowerVM's vty implementation has a bug where it inserts a
4a2fec
+         * \0 after every \r going to the guest.  Existing guests have
4a2fec
+         * a workaround for this which removes every \0 immediately
4a2fec
+         * following a \r, so here we make ourselves bug-for-bug
4a2fec
+         * compatible, so that the guest won't drop a real \0-after-\r
4a2fec
+         * that happens to occur in a binary stream. */
4a2fec
+        if (buf[n - 1] == '\r') {
4a2fec
+            if (n < max) {
4a2fec
+                buf[n++] = '\0';
4a2fec
+            } else {
4a2fec
+                /* No room for the extra \0, roll back and try again
4a2fec
+                 * next time */
4a2fec
+                dev->out--;
4a2fec
+                n--;
4a2fec
+                break;
4a2fec
+            }
4a2fec
+        }
4a2fec
     }
4a2fec
 
4a2fec
     qemu_chr_fe_accept_input(&dev->chardev);
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec