public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Serial: UART_BUG_TXEN race conditions
@ 2006-06-26 20:07 Ingo van Lil
  2006-06-26 20:25 ` Russell King
  2006-06-27 13:05 ` linux-os (Dick Johnson)
  0 siblings, 2 replies; 8+ messages in thread
From: Ingo van Lil @ 2006-06-26 20:07 UTC (permalink / raw)
  To: linux-kernel

Hello everybody,

I'm currently working with Linux on a custom ASIC system with two 
crappy UART ports that show a behaviour quite similar to the problem 
that the UART_BUG_TXEN workaround is supposed to deal with. The 
interesting lines are in serial8250_start_tx 
(drivers/serial/8250.c:1127)

	if (up->bugs & UART_BUG_TXEN) {
		unsigned char lsr, iir;
		lsr = serial_in(up, UART_LSR);
		iir = serial_in(up, UART_IIR);
		if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT)
			transmit_chars(up);
	}

Correct me if I'm mistaken, but I see two possible race conditions with 
that piece of code:

1. What if the IIR actually equals UART_IIR_THRI at that point? The
    read access will clear the interrupt condition and the workaround
    will effect the actual opposite of its intention: Neither
    serial8250_start_tx() nor the interrupt handler will start
    transmitting characters for the ring buffer.

2. What if an interrupt is triggered shortly after reading the IIR?
    Both serial8250_start_tx() and the interrupt handler will start
    a transmission simultaneously.

Problem #1 should be quite easy to deal with: If the IIR read comes out 
as UART_IIR_THRI then the interrupt handler won't initiate a 
transmission, so we should. I'm not entirely sure how to deal with #2, 
though. Maybe it's enough to clear the THRE bit while transmitting 
characters, maybe some kind of locking is required.

Cheers,
Ingo



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-06-28  8:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-26 20:07 Serial: UART_BUG_TXEN race conditions Ingo van Lil
2006-06-26 20:25 ` Russell King
2006-06-26 20:52   ` Ingo van Lil
2006-06-28  8:00   ` [PATCH] " Ingo van Lil
2006-06-27 13:05 ` linux-os (Dick Johnson)
2006-06-27 19:19   ` Ingo van Lil
2006-06-27 19:59     ` linux-os (Dick Johnson)
2006-06-27 20:47   ` H. Peter Anvin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox