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

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