619821
From ba96da130a625a71b574c1bb9f6027e3b8d655ab Mon Sep 17 00:00:00 2001
619821
From: Paolo Bonzini <pbonzini@redhat.com>
619821
Date: Fri, 9 Jun 2017 11:43:59 +0200
619821
Subject: [PATCH 4/6] serial: reinstate watch after migration
619821
619821
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
619821
Message-id: <20170609114359.13036-4-pbonzini@redhat.com>
619821
Patchwork-id: 75566
619821
O-Subject: [RHEL7.4 qemu-kvm PATCH v2 3/3] serial: reinstate watch after migration
619821
Bugzilla: 1452067
619821
RH-Acked-by: David Hildenbrand <david@redhat.com>
619821
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
619821
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
619821
619821
Otherwise, a serial port can get stuck if it is migrated while flow control
619821
is in effect.
619821
619821
Tested-by: Bret Ketchum <bcketchum@gmail.com>
619821
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
619821
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
619821
(cherry picked from commit 9f34a35e0020b0b2b2e21c086a486d7dfd18df4f)
619821
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
619821
---
619821
 hw/char/serial.c | 29 +++++++++++++++++++++++++----
619821
 1 file changed, 25 insertions(+), 4 deletions(-)
619821
619821
diff --git a/hw/char/serial.c b/hw/char/serial.c
619821
index 0518a6f..820960b 100644
619821
--- a/hw/char/serial.c
619821
+++ b/hw/char/serial.c
619821
@@ -637,13 +637,34 @@ static int serial_post_load(void *opaque, int version_id)
619821
     if (version_id < 3) {
619821
         s->fcr_vmstate = 0;
619821
     }
619821
-    if (s->tsr_retry > MAX_XMIT_RETRY) {
619821
-        s->tsr_retry = MAX_XMIT_RETRY;
619821
-    }
619821
-
619821
     if (s->thr_ipending == -1) {
619821
         s->thr_ipending = ((s->iir & UART_IIR_ID) == UART_IIR_THRI);
619821
     }
619821
+
619821
+    if (s->tsr_retry > 0) {
619821
+        /* tsr_retry > 0 implies LSR.TEMT = 0 (transmitter not empty).  */
619821
+        if (s->lsr & UART_LSR_TEMT) {
619821
+            error_report("inconsistent state in serial device "
619821
+                         "(tsr empty, tsr_retry=%d", s->tsr_retry);
619821
+            return -1;
619821
+        }
619821
+
619821
+        if (s->tsr_retry > MAX_XMIT_RETRY) {
619821
+            s->tsr_retry = MAX_XMIT_RETRY;
619821
+        }
619821
+
619821
+        assert(s->watch_tag == 0);
619821
+        s->watch_tag = qemu_chr_fe_add_watch(s->chr, G_IO_OUT|G_IO_HUP,
619821
+                                             serial_watch_cb, s);
619821
+    } else {
619821
+        /* tsr_retry == 0 implies LSR.TEMT = 1 (transmitter empty).  */
619821
+        if (!(s->lsr & UART_LSR_TEMT)) {
619821
+            error_report("inconsistent state in serial device "
619821
+                         "(tsr not empty, tsr_retry=0");
619821
+            return -1;
619821
+        }
619821
+    }
619821
+
619821
     s->last_break_enable = (s->lcr >> 6) & 1;
619821
     /* Initialize fcr via setter to perform essential side-effects */
619821
     serial_write_fcr(s, s->fcr_vmstate);
619821
-- 
619821
1.8.3.1
619821