Skip to contentSkip to conversation

qemu serial: lost tx irqs (affectig FreeBSD's new uart(4) driver)

Qemu-devel Applied Juergen Lock 5 participants 10 messages Sep 11, 2009 – Sep 24, 2009

lore
Share & tools
lore
#0 lore raw

Hi!

I got a report of FreeBSD guest's new uart(4) driver misbehaving in
qemu again(?) (output stopping for no apparent reason), and now found out the problem is tx irqs (UART_IIR_THRI) are getting lost because serial_update_irq() checks for the rx condtion,

	... if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR))
first before checking for the tx irq condition,
	... if ((s->ier & UART_IER_THRI) && s->thr_ipending)

which at least in this case (FreeBSD 8 guest after doing
set console="comconsole"
at the loader prompt or when simply echo'ing text to /dev/ttyu0 or typing to the serial port from cu(1) on a `regular' vga console) causes the second condition (.. && s->thr_ipending) to be never reached anymore, or only after a very long delay. Moving that condition up so it is checked first like this,

Index: qemu/hw/serial.c
@@ -189,7 +188,9 @@ static void serial_update_irq(SerialStat

 {
     uint8_t tmp_iir = UART_IIR_NO_INT;

- if ((s->ier & UART_IER_RLSI) && (s->lsr & UART_LSR_INT_ANY)) {
+ if ((s->ier & UART_IER_THRI) && s->thr_ipending) {
+ tmp_iir = UART_IIR_THRI;

+    } else if ((s->ier & UART_IER_RLSI) && (s->lsr & UART_LSR_INT_ANY)) {
         tmp_iir = UART_IIR_RLSI;
     } else if ((s->ier & UART_IER_RDI) && s->timeout_ipending) {
         /* Note that(s->ier & UART_IER_RDI) can mask this interrupt,
@@ -202,8 +203,6 @@ static void serial_update_irq(SerialStat
         } else if (s->recv_fifo.count >= s->recv_fifo.itl) {
            tmp_iir = UART_IIR_RDI;
         }
-    } else if ((s->ier & UART_IER_THRI) && s->thr_ipending) {
-        tmp_iir = UART_IIR_THRI;
     } else if ((s->ier & UART_IER_MSI) && (s->msr & UART_MSR_ANY_DELTA)) {
         tmp_iir = UART_IIR_MSI;
     }

...fixes the issue for me, but I'm not 100% sure if this might cause rx irqs to come (too?) late when a guest keeps sending while its receiving at the same time. Anyone care to comment? :)

Thanx,
Juergen

#1 lore raw

Hi,

Quoted 4 lines · Juergen Lock

...fixes the issue for me, but I'm not 100% sure if this might cause rx irqs to come (too?) late when a guest keeps sending while its receiving at the same time.  Anyone care to comment? :)

Your patch fix the issue for me too.

Thanks a lot's Juergen !

Regards,

Olivier

#2 lore raw
In reply to Juergen Lock
Quoted 39 lines · Juergen Lock

Hi!

I got a report of FreeBSD guest's new uart(4) driver misbehaving in
qemu again(?) (output stopping for no apparent reason), and now found out the problem is tx irqs (UART_IIR_THRI) are getting lost because serial_update_irq() checks for the rx condtion,

	... if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR))
first before checking for the tx irq condition,
	... if ((s->ier & UART_IER_THRI) && s->thr_ipending)

which at least in this case (FreeBSD 8 guest after doing
set console="comconsole"
at the loader prompt or when simply echo'ing text to /dev/ttyu0 or typing to the serial port from cu(1) on a `regular' vga console) causes the second condition (.. && s->thr_ipending) to be never reached anymore, or only after a very long delay. Moving that condition up so it is checked first like this,

Index: qemu/hw/serial.c

(quoted diff) +3 -3
@@ -189,7 +188,9 @@ static void serial_update_irq(SerialStat
 {
     uint8_t tmp_iir = UART_IIR_NO_INT;
 
-    if ((s->ier & UART_IER_RLSI) && (s->lsr & UART_LSR_INT_ANY)) {
+    if ((s->ier & UART_IER_THRI) && s->thr_ipending) {
+        tmp_iir = UART_IIR_THRI;
+    } else if ((s->ier & UART_IER_RLSI) && (s->lsr & UART_LSR_INT_ANY)) {
         tmp_iir = UART_IIR_RLSI;
     } else if ((s->ier & UART_IER_RDI) && s->timeout_ipending) {
         /* Note that(s->ier & UART_IER_RDI) can mask this interrupt,
@@ -202,8 +203,6 @@ static void serial_update_irq(SerialStat
         } else if (s->recv_fifo.count >= s->recv_fifo.itl) {
            tmp_iir = UART_IIR_RDI;
         }
-    } else if ((s->ier & UART_IER_THRI) && s->thr_ipending) {
-        tmp_iir = UART_IIR_THRI;
     } else if ((s->ier & UART_IER_MSI) && (s->msr & UART_MSR_ANY_DELTA)) {
         tmp_iir = UART_IIR_MSI;
     }
Quoted 3 lines

...fixes the issue for me, but I'm not 100% sure if this might cause rx irqs to come (too?) late when a guest keeps sending while its receiving at the same time. Anyone care to comment? :)

The reordering violates the 16550A spec in that RX event overrules TX in the IRQ status register. Maybe something else is wrong but it's not the ordering in serial_update_irq.

Jan

#3 lore raw
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Juergen Lock

Hi!

I got a report of FreeBSD guest's new uart(4) driver misbehaving in
qemu again(?) (output stopping for no apparent reason), and now found out the problem is tx irqs (UART_IIR_THRI) are getting lost because serial_update_irq() checks for the rx condtion,

	... if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR))
first before checking for the tx irq condition,
	... if ((s->ier & UART_IER_THRI) && s->thr_ipending)

which at least in this case (FreeBSD 8 guest after doing
set console="comconsole"
at the loader prompt or when simply echo'ing text to /dev/ttyu0 or typing to the serial port from cu(1) on a `regular' vga console) causes the second condition (.. && s->thr_ipending) to be never reached anymore, or only after a very long delay. Moving that condition up so it is checked first like this,

Index: qemu/hw/serial.c

(quoted diff) +3 -3
@@ -189,7 +188,9 @@ static void serial_update_irq(SerialStat
 {
     uint8_t tmp_iir = UART_IIR_NO_INT;
 
-    if ((s->ier & UART_IER_RLSI) && (s->lsr & UART_LSR_INT_ANY)) {
+    if ((s->ier & UART_IER_THRI) && s->thr_ipending) {
+        tmp_iir = UART_IIR_THRI;
+    } else if ((s->ier & UART_IER_RLSI) && (s->lsr & UART_LSR_INT_ANY)) {
         tmp_iir = UART_IIR_RLSI;
     } else if ((s->ier & UART_IER_RDI) && s->timeout_ipending) {
         /* Note that(s->ier & UART_IER_RDI) can mask this interrupt,
@@ -202,8 +203,6 @@ static void serial_update_irq(SerialStat
         } else if (s->recv_fifo.count >= s->recv_fifo.itl) {
            tmp_iir = UART_IIR_RDI;
         }
-    } else if ((s->ier & UART_IER_THRI) && s->thr_ipending) {
-        tmp_iir = UART_IIR_THRI;
     } else if ((s->ier & UART_IER_MSI) && (s->msr & UART_MSR_ANY_DELTA)) {
         tmp_iir = UART_IIR_MSI;
     }
Quoted 7 lines
Quoted 3 lines

...fixes the issue for me, but I'm not 100% sure if this might cause rx irqs to come (too?) late when a guest keeps sending while its receiving at the same time. Anyone care to comment? :)

The reordering violates the 16550A spec in that RX event overrules TX in the IRQ status register. Maybe something else is wrong but it's not the ordering in serial_update_irq.

Well one problem seems to be the rx condition,
... if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR))
is not enough to trigger an irq, yet still causes the following conditions not to be checked anymore at all. And ideed, fixing that seems to get my FreeBSD 8 guest back to working order as well:

Index: qemu/hw/serial.c
@@ -196,12 +195,10 @@ static void serial_update_irq(SerialStat
* this is not in the specification but is observed on existing
* hardware. */
tmp_iir = UART_IIR_CTI;
- } else if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR)) {
- if (!(s->fcr & UART_FCR_FE)) {
- tmp_iir = UART_IIR_RDI;
- } else if (s->recv_fifo.count >= s->recv_fifo.itl) {
- tmp_iir = UART_IIR_RDI;
- }
+ } else if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR) &&
+ (!(s->fcr & UART_FCR_FE) ||
+ s->recv_fifo.count >= s->recv_fifo.itl)) {

+        tmp_iir = UART_IIR_RDI;
     } else if ((s->ier & UART_IER_THRI) && s->thr_ipending) {
         tmp_iir = UART_IIR_THRI;
     } else if ((s->ier & UART_IER_MSI) && (s->msr & UART_MSR_ANY_DELTA)) {
Acked-by
#4 lore raw
Quoted 73 lines · Juergen Lock
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Juergen Lock

Hi!

I got a report of FreeBSD guest's new uart(4) driver misbehaving in
qemu again(?) (output stopping for no apparent reason), and now found out the problem is tx irqs (UART_IIR_THRI) are getting lost because serial_update_irq() checks for the rx condtion,

	... if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR))
first before checking for the tx irq condition,
	... if ((s->ier & UART_IER_THRI) && s->thr_ipending)

which at least in this case (FreeBSD 8 guest after doing
set console="comconsole"
at the loader prompt or when simply echo'ing text to /dev/ttyu0 or typing to the serial port from cu(1) on a `regular' vga console) causes the second condition (.. && s->thr_ipending) to be never reached anymore, or only after a very long delay. Moving that condition up so it is checked first like this,

Index: qemu/hw/serial.c

(quoted diff) +3 -3
@@ -189,7 +188,9 @@ static void serial_update_irq(SerialStat
 {
     uint8_t tmp_iir = UART_IIR_NO_INT;
 
-    if ((s->ier & UART_IER_RLSI) && (s->lsr & UART_LSR_INT_ANY)) {
+    if ((s->ier & UART_IER_THRI) && s->thr_ipending) {
+        tmp_iir = UART_IIR_THRI;
+    } else if ((s->ier & UART_IER_RLSI) && (s->lsr & UART_LSR_INT_ANY)) {
         tmp_iir = UART_IIR_RLSI;
     } else if ((s->ier & UART_IER_RDI) && s->timeout_ipending) {
         /* Note that(s->ier & UART_IER_RDI) can mask this interrupt,
@@ -202,8 +203,6 @@ static void serial_update_irq(SerialStat
         } else if (s->recv_fifo.count >= s->recv_fifo.itl) {
            tmp_iir = UART_IIR_RDI;
         }
-    } else if ((s->ier & UART_IER_THRI) && s->thr_ipending) {
-        tmp_iir = UART_IIR_THRI;
     } else if ((s->ier & UART_IER_MSI) && (s->msr & UART_MSR_ANY_DELTA)) {
         tmp_iir = UART_IIR_MSI;
     }
Quoted 6 lines
Quoted 3 lines

...fixes the issue for me, but I'm not 100% sure if this might cause rx irqs to come (too?) late when a guest keeps sending while its receiving at the same time. Anyone care to comment? :)

The reordering violates the 16550A spec in that RX event overrules TX in the IRQ status register. Maybe something else is wrong but it's not the ordering in serial_update_irq.

Well one problem seems to be the rx condition,
... if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR))
is not enough to trigger an irq, yet still causes the following conditions not to be checked anymore at all. And ideed, fixing that seems to get my FreeBSD 8 guest back to working order as well:

Index: qemu/hw/serial.c

(quoted diff) +4 -6
@@ -196,12 +195,10 @@ static void serial_update_irq(SerialStat
          * this is not in the specification but is observed on existing
          * hardware.  */
         tmp_iir = UART_IIR_CTI;
-    } else if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR)) {
-        if (!(s->fcr & UART_FCR_FE)) {
-           tmp_iir = UART_IIR_RDI;
-        } else if (s->recv_fifo.count >= s->recv_fifo.itl) {
-           tmp_iir = UART_IIR_RDI;
-        }
+    } else if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR) &&
+               (!(s->fcr & UART_FCR_FE) ||
+                s->recv_fifo.count >= s->recv_fifo.itl)) {
+        tmp_iir = UART_IIR_RDI;
     } else if ((s->ier & UART_IER_THRI) && s->thr_ipending) {
         tmp_iir = UART_IIR_THRI;
     } else if ((s->ier & UART_IER_MSI) && (s->msr & UART_MSR_ANY_DELTA)) {
Quoted 1 line

Yep, that does make sense!

But I also but Stefano on CC as he introduced the logic above.

Jan

#5 lore raw
In reply to Juergen Lock
Quoted 5 lines · Juergen Lock

Well one problem seems to be the rx condition,
... if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR))
is not enough to trigger an irq, yet still causes the following conditions not to be checked anymore at all. And ideed, fixing that seems to get my FreeBSD 8 guest back to working order as well:

Good spot!
The fix also seems correct to me.

Quoted 22 lines

Index: qemu/hw/serial.c

(quoted diff) +4 -6
@@ -196,12 +195,10 @@ static void serial_update_irq(SerialStat
          * this is not in the specification but is observed on existing
          * hardware.  */
         tmp_iir = UART_IIR_CTI;
-    } else if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR)) {
-        if (!(s->fcr & UART_FCR_FE)) {
-           tmp_iir = UART_IIR_RDI;
-        } else if (s->recv_fifo.count >= s->recv_fifo.itl) {
-           tmp_iir = UART_IIR_RDI;
-        }
+    } else if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR) &&
+               (!(s->fcr & UART_FCR_FE) ||
+                s->recv_fifo.count >= s->recv_fifo.itl)) {
+        tmp_iir = UART_IIR_RDI;
     } else if ((s->ier & UART_IER_THRI) && s->thr_ipending) {
         tmp_iir = UART_IIR_THRI;
     } else if ((s->ier & UART_IER_MSI) && (s->msr & UART_MSR_ANY_DELTA)) {
#6 lore raw
In reply to Juergen Lock
Quoted 49 lines · Juergen Lock
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Juergen Lock

Hi!

I got a report of FreeBSD guest's new uart(4) driver misbehaving in
qemu again(?) (output stopping for no apparent reason), and now found out the problem is tx irqs (UART_IIR_THRI) are getting lost because serial_update_irq() checks for the rx condtion,

	... if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR))
first before checking for the tx irq condition,
	... if ((s->ier & UART_IER_THRI) && s->thr_ipending)

which at least in this case (FreeBSD 8 guest after doing
set console="comconsole"
at the loader prompt or when simply echo'ing text to /dev/ttyu0 or typing to the serial port from cu(1) on a `regular' vga console) causes the second condition (.. && s->thr_ipending) to be never reached anymore, or only after a very long delay. Moving that condition up so it is checked first like this,

Index: qemu/hw/serial.c

(quoted diff) +3 -3
@@ -189,7 +188,9 @@ static void serial_update_irq(SerialStat
 {
     uint8_t tmp_iir = UART_IIR_NO_INT;
 
-    if ((s->ier & UART_IER_RLSI) && (s->lsr & UART_LSR_INT_ANY)) {
+    if ((s->ier & UART_IER_THRI) && s->thr_ipending) {
+        tmp_iir = UART_IIR_THRI;
+    } else if ((s->ier & UART_IER_RLSI) && (s->lsr & UART_LSR_INT_ANY)) {
         tmp_iir = UART_IIR_RLSI;
     } else if ((s->ier & UART_IER_RDI) && s->timeout_ipending) {
         /* Note that(s->ier & UART_IER_RDI) can mask this interrupt,
@@ -202,8 +203,6 @@ static void serial_update_irq(SerialStat
         } else if (s->recv_fifo.count >= s->recv_fifo.itl) {
            tmp_iir = UART_IIR_RDI;
         }
-    } else if ((s->ier & UART_IER_THRI) && s->thr_ipending) {
-        tmp_iir = UART_IIR_THRI;
     } else if ((s->ier & UART_IER_MSI) && (s->msr & UART_MSR_ANY_DELTA)) {
         tmp_iir = UART_IIR_MSI;
     }
Quoted 7 lines
Quoted 3 lines

...fixes the issue for me, but I'm not 100% sure if this might cause rx irqs to come (too?) late when a guest keeps sending while its receiving at the same time. Anyone care to comment? :)

The reordering violates the 16550A spec in that RX event overrules TX in the IRQ status register. Maybe something else is wrong but it's not the ordering in serial_update_irq.

Quoted 5 lines

Well one problem seems to be the rx condition,
... if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR))
is not enough to trigger an irq, yet still causes the following conditions not to be checked anymore at all. And ideed, fixing that seems to get my FreeBSD 8 guest back to working order as well:

Applied. In the future, could you please make sure to send patches with a correct unified headers?

Quoted 23 lines

Index: qemu/hw/serial.c

(quoted diff) +4 -6
@@ -196,12 +195,10 @@ static void serial_update_irq(SerialStat
          * this is not in the specification but is observed on existing
          * hardware.  */
         tmp_iir = UART_IIR_CTI;
-    } else if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR)) {
-        if (!(s->fcr & UART_FCR_FE)) {
-           tmp_iir = UART_IIR_RDI;
-        } else if (s->recv_fifo.count >= s->recv_fifo.itl) {
-           tmp_iir = UART_IIR_RDI;
-        }
+    } else if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR) &&
+               (!(s->fcr & UART_FCR_FE) ||
+                s->recv_fifo.count >= s->recv_fifo.itl)) {
+        tmp_iir = UART_IIR_RDI;
     } else if ((s->ier & UART_IER_THRI) && s->thr_ipending) {
         tmp_iir = UART_IIR_THRI;
     } else if ((s->ier & UART_IER_MSI) && (s->msr & UART_MSR_ANY_DELTA)) {
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#7 lore raw

In article <[email protected]> you write:

Quoted 50 lines · Juergen Lock
Quoted 49 lines · Jan Kiszka
Quoted 47 lines
Quoted 39 lines · Juergen Lock

Hi!

I got a report of FreeBSD guest's new uart(4) driver misbehaving in
qemu again(?) (output stopping for no apparent reason), and now found out the problem is tx irqs (UART_IIR_THRI) are getting lost because serial_update_irq() checks for the rx condtion,

	... if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR))
first before checking for the tx irq condition,
	... if ((s->ier & UART_IER_THRI) && s->thr_ipending)

which at least in this case (FreeBSD 8 guest after doing
set console="comconsole"
at the loader prompt or when simply echo'ing text to /dev/ttyu0 or typing to the serial port from cu(1) on a `regular' vga console) causes the second condition (.. && s->thr_ipending) to be never reached anymore, or only after a very long delay. Moving that condition up so it is checked first like this,

Index: qemu/hw/serial.c

(quoted diff) +3 -3
@@ -189,7 +188,9 @@ static void serial_update_irq(SerialStat
 {
     uint8_t tmp_iir = UART_IIR_NO_INT;
 
-    if ((s->ier & UART_IER_RLSI) && (s->lsr & UART_LSR_INT_ANY)) {
+    if ((s->ier & UART_IER_THRI) && s->thr_ipending) {
+        tmp_iir = UART_IIR_THRI;
+    } else if ((s->ier & UART_IER_RLSI) && (s->lsr & UART_LSR_INT_ANY)) {
         tmp_iir = UART_IIR_RLSI;
     } else if ((s->ier & UART_IER_RDI) && s->timeout_ipending) {
         /* Note that(s->ier & UART_IER_RDI) can mask this interrupt,
@@ -202,8 +203,6 @@ static void serial_update_irq(SerialStat
         } else if (s->recv_fifo.count >= s->recv_fifo.itl) {
            tmp_iir = UART_IIR_RDI;
         }
-    } else if ((s->ier & UART_IER_THRI) && s->thr_ipending) {
-        tmp_iir = UART_IIR_THRI;
     } else if ((s->ier & UART_IER_MSI) && (s->msr & UART_MSR_ANY_DELTA)) {
         tmp_iir = UART_IIR_MSI;
     }
Quoted 3 lines

...fixes the issue for me, but I'm not 100% sure if this might cause rx irqs to come (too?) late when a guest keeps sending while its receiving at the same time. Anyone care to comment? :)

The reordering violates the 16550A spec in that RX event overrules TX in the IRQ status register. Maybe something else is wrong but it's not the ordering in serial_update_irq.

Quoted 8 lines
Quoted 5 lines

Well one problem seems to be the rx condition,
... if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR))
is not enough to trigger an irq, yet still causes the following conditions not to be checked anymore at all. And ideed, fixing that seems to get my FreeBSD 8 guest back to working order as well:

Applied. In the future, could you please make sure to send patches with a correct unified headers?

Alright, if thats is what you guys prefer... (I just didn't want to break the thread.)

Anyway, I guess this is also material for the stable branch(es)?
(I just saw 0.11.0 has already been tagged but not announced yet, and another patch merged to the same branch after that, maybe the tag can still be slided if this is possible with git?)

Thanx,
Juergen

#8 lore raw
Quoted 57 lines · Juergen Lock

In article <[email protected]> you write:

Quoted 56 lines · Juergen Lock
Quoted 54 lines · Jan Kiszka
Quoted 40 lines
Quoted 39 lines · Juergen Lock

Hi!

I got a report of FreeBSD guest's new uart(4) driver misbehaving in
qemu again(?) (output stopping for no apparent reason), and now found out the problem is tx irqs (UART_IIR_THRI) are getting lost because serial_update_irq() checks for the rx condtion,

	... if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR))
first before checking for the tx irq condition,
	... if ((s->ier & UART_IER_THRI) && s->thr_ipending)

which at least in this case (FreeBSD 8 guest after doing
set console="comconsole"
at the loader prompt or when simply echo'ing text to /dev/ttyu0 or typing to the serial port from cu(1) on a `regular' vga console) causes the second condition (.. && s->thr_ipending) to be never reached anymore, or only after a very long delay. Moving that condition up so it is checked first like this,

Index: qemu/hw/serial.c

(quoted diff) +3 -3
@@ -189,7 +188,9 @@ static void serial_update_irq(SerialStat
 {
     uint8_t tmp_iir = UART_IIR_NO_INT;
 
-    if ((s->ier & UART_IER_RLSI) && (s->lsr & UART_LSR_INT_ANY)) {
+    if ((s->ier & UART_IER_THRI) && s->thr_ipending) {
+        tmp_iir = UART_IIR_THRI;
+    } else if ((s->ier & UART_IER_RLSI) && (s->lsr & UART_LSR_INT_ANY)) {
         tmp_iir = UART_IIR_RLSI;
     } else if ((s->ier & UART_IER_RDI) && s->timeout_ipending) {
         /* Note that(s->ier & UART_IER_RDI) can mask this interrupt,
@@ -202,8 +203,6 @@ static void serial_update_irq(SerialStat
         } else if (s->recv_fifo.count >= s->recv_fifo.itl) {
            tmp_iir = UART_IIR_RDI;
         }
-    } else if ((s->ier & UART_IER_THRI) && s->thr_ipending) {
-        tmp_iir = UART_IIR_THRI;
     } else if ((s->ier & UART_IER_MSI) && (s->msr & UART_MSR_ANY_DELTA)) {
         tmp_iir = UART_IIR_MSI;
     }
Quoted 7 lines
Quoted 3 lines

...fixes the issue for me, but I'm not 100% sure if this might cause rx irqs to come (too?) late when a guest keeps sending while its receiving at the same time. Anyone care to comment? :)

The reordering violates the 16550A spec in that RX event overrules TX in the IRQ status register. Maybe something else is wrong but it's not the ordering in serial_update_irq.

Well one problem seems to be the rx condition,
... if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR))
is not enough to trigger an irq, yet still causes the following conditions not to be checked anymore at all. And ideed, fixing that seems to get my FreeBSD 8 guest back to working order as well:

Quoted 5 lines
Quoted 2 lines

Applied. In the future, could you please make sure to send patches with a correct unified headers?

Alright, if thats is what you guys prefer... (I just didn't want to break the thread.)

Don't need to break the thread, just use

| --- a/hw/serial.c
| +++ a/hw/serial.c

instead of simply

| Index: qemu/hw/serial.c

ie the output of diff -u

Quoted 5 lines

Anyway, I guess this is also material for the stable branch(es)?
(I just saw 0.11.0 has already been tagged but not announced yet, and another patch merged to the same branch after that, maybe the tag can still be slided if this is possible with git?)

Pushed to the branch. For the details about the release, I let Anthony handling that. Worst case scenario, it will be in 0.11.1.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#9 lore raw
Quoted 66 lines · Aurelien Jarno
Quoted 57 lines · Juergen Lock

In article <[email protected]> you write:

Quoted 56 lines · Juergen Lock
Quoted 54 lines · Jan Kiszka
Quoted 40 lines
Quoted 39 lines · Juergen Lock

Hi!

I got a report of FreeBSD guest's new uart(4) driver misbehaving in
qemu again(?) (output stopping for no apparent reason), and now found out the problem is tx irqs (UART_IIR_THRI) are getting lost because serial_update_irq() checks for the rx condtion,

	... if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR))
first before checking for the tx irq condition,
	... if ((s->ier & UART_IER_THRI) && s->thr_ipending)

which at least in this case (FreeBSD 8 guest after doing
set console="comconsole"
at the loader prompt or when simply echo'ing text to /dev/ttyu0 or typing to the serial port from cu(1) on a `regular' vga console) causes the second condition (.. && s->thr_ipending) to be never reached anymore, or only after a very long delay. Moving that condition up so it is checked first like this,

Index: qemu/hw/serial.c

(quoted diff) +3 -3
@@ -189,7 +188,9 @@ static void serial_update_irq(SerialStat
 {
     uint8_t tmp_iir = UART_IIR_NO_INT;
 
-    if ((s->ier & UART_IER_RLSI) && (s->lsr & UART_LSR_INT_ANY)) {
+    if ((s->ier & UART_IER_THRI) && s->thr_ipending) {
+        tmp_iir = UART_IIR_THRI;
+    } else if ((s->ier & UART_IER_RLSI) && (s->lsr & UART_LSR_INT_ANY)) {
         tmp_iir = UART_IIR_RLSI;
     } else if ((s->ier & UART_IER_RDI) && s->timeout_ipending) {
         /* Note that(s->ier & UART_IER_RDI) can mask this interrupt,
@@ -202,8 +203,6 @@ static void serial_update_irq(SerialStat
         } else if (s->recv_fifo.count >= s->recv_fifo.itl) {
            tmp_iir = UART_IIR_RDI;
         }
-    } else if ((s->ier & UART_IER_THRI) && s->thr_ipending) {
-        tmp_iir = UART_IIR_THRI;
     } else if ((s->ier & UART_IER_MSI) && (s->msr & UART_MSR_ANY_DELTA)) {
         tmp_iir = UART_IIR_MSI;
     }
Quoted 7 lines
Quoted 3 lines

...fixes the issue for me, but I'm not 100% sure if this might cause rx irqs to come (too?) late when a guest keeps sending while its receiving at the same time. Anyone care to comment? :)

The reordering violates the 16550A spec in that RX event overrules TX in the IRQ status register. Maybe something else is wrong but it's not the ordering in serial_update_irq.

Well one problem seems to be the rx condition,
... if ((s->ier & UART_IER_RDI) && (s->lsr & UART_LSR_DR))
is not enough to trigger an irq, yet still causes the following conditions not to be checked anymore at all. And ideed, fixing that seems to get my FreeBSD 8 guest back to working order as well:

Quoted 5 lines
Quoted 2 lines

Applied. In the future, could you please make sure to send patches with a correct unified headers?

Alright, if thats is what you guys prefer... (I just didn't want to break the thread.)

Don't need to break the thread, just use

Quoted 9 lines

| --- a/hw/serial.c
| +++ a/hw/serial.c

instead of simply

| Index: qemu/hw/serial.c

ie the output of diff -u

Oh ok, then I completely misunderstood. (And I had no idea this makes a difference... :) Anyway, I'll try to remember.

Quoted 9 lines
Quoted 5 lines

Anyway, I guess this is also material for the stable branch(es)?
(I just saw 0.11.0 has already been tagged but not announced yet, and another patch merged to the same branch after that, maybe the tag can still be slided if this is possible with git?)

Pushed to the branch. For the details about the release, I let Anthony handling that. Worst case scenario, it will be in 0.11.1.

Yeah, looks like it...

Thanx,
Juergen