9290838
From 90f23b109c482f23d04a943d1e41f79b33ce028a Mon Sep 17 00:00:00 2001
9290838
From: Michael Tokarev <mjt@tls.msk.ru>
9290838
Date: Wed, 19 Sep 2012 12:08:31 +0400
9290838
Subject: [PATCH] Revert "serial: fix retry logic"
9290838
9290838
This reverts commit 67c5322d7000fd105a926eec44bc1765b7d70bdd:
9290838
9290838
    I'm not sure if the retry logic has ever worked when not using FIFO mode.  I
9290838
    found this while writing a test case although code inspection confirms it is
9290838
    definitely broken.
9290838
9290838
    The TSR retry logic will never actually happen because it is guarded by an
9290838
    'if (s->tsr_rety > 0)' but this is the only place that can ever make the
9290838
    variable greater than zero.  That effectively makes the retry logic an 'if (0)
9290838
9290838
    I believe this is a typo and the intention was >= 0.  Once this is fixed thoug
9290838
    I see double transmits with my test case.  This is because in the non FIFO
9290838
    case, serial_xmit may get invoked while LSR.THRE is still high because the
9290838
    character was processed but the retransmit timer was still active.
9290838
9290838
    We can handle this by simply checking for LSR.THRE and returning early.  It's
9290838
    possible that the FIFO paths also need some attention.
9290838
9290838
    Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
9290838
    Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
9290838
9290838
Even if the previous logic was never worked, new logic breaks stuff -
9290838
namely,
9290838
9290838
 qemu -enable-kvm -nographic -kernel /boot/vmlinuz-$(uname -r) -append console=ttyS0 -serial pty
9290838
9290838
the above command will cause the virtual machine to stuck at startup
9290838
using 100% CPU till one connects to the pty and sends any char to it.
9290838
9290838
Note this is rather typical invocation for various headless virtual
9290838
machines by libvirt.
9290838
9290838
So revert this change for now, till a better solution will be found.
9290838
9290838
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
9290838
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
9290838
---
9290838
 hw/serial.c | 4 +---
9290838
 1 file changed, 1 insertion(+), 3 deletions(-)
9290838
9290838
diff --git a/hw/serial.c b/hw/serial.c
9290838
index 056d823..c9fccf7 100644
9290838
--- a/hw/serial.c
9290838
+++ b/hw/serial.c
9290838
@@ -327,8 +327,6 @@ static void serial_xmit(void *opaque)
9290838
             s->tsr = fifo_get(s,XMIT_FIFO);
9290838
             if (!s->xmit_fifo.count)
9290838
                 s->lsr |= UART_LSR_THRE;
9290838
-        } else if ((s->lsr & UART_LSR_THRE)) {
9290838
-            return;
9290838
         } else {
9290838
             s->tsr = s->thr;
9290838
             s->lsr |= UART_LSR_THRE;
9290838
@@ -340,7 +338,7 @@ static void serial_xmit(void *opaque)
9290838
         /* in loopback mode, say that we just received a char */
9290838
         serial_receive1(s, &s->tsr, 1);
9290838
     } else if (qemu_chr_fe_write(s->chr, &s->tsr, 1) != 1) {
9290838
-        if ((s->tsr_retry >= 0) && (s->tsr_retry <= MAX_XMIT_RETRY)) {
9290838
+        if ((s->tsr_retry > 0) && (s->tsr_retry <= MAX_XMIT_RETRY)) {
9290838
             s->tsr_retry++;
9290838
             qemu_mod_timer(s->transmit_timer,  new_xmit_ts + s->char_transmit_time);
9290838
             return;