Hang in uart_block_til_ready()
Hello Russell
I've discovered a problem where I'm not sure wether it's an error in the kernel or in the hardware.
The hardware I'm using for the serial console is a HP Lights-Out 100 Management. It provides a (virtual) serial port which then can be used for remote administration over the network and is available as ttyS2 in Linux. I'm using it for a serial console.
When doing open("/dev/ttyS2", O_RDWR) from userland, like it's done by screen(1) and by my test program, the kernel "hangs" in the schedule() call in the function uart_block_til_ready of serial_core.c.
The patch below fixes it, but I'm not sure wether it is the correct way, nor if it might create other problems.
The problem was reproducable with 2.6.15.6, 2.6.16 and 2.6.16-git20 (all vanilla). I've not been able to reproduce it on another box where the serial console is on ttyS0 and done by a common 16550A-compatible chip.
Do you or somebody else have an idea what's going on here and how to fix it correctly?
Thanks,
Michael
---
drivers/serial/serial_core.c renamed from drivers/serial/serial_core.c.orig +4 -0
@@ -1456,6 +1456,10 @@ uart_block_til_ready(struct file *filp,break ; } +/* hansmi: fixes a hang on open("/dev/ttyS2", O_RDWR) for me */ +if (uart_console (port) && (port->cons->flags &CON_ENABLED )) +break ; +/* * Set DTR to allow modem to know we're waiting. Do * not set RTS here - we want to make sure we catch
Quoted 2 lines · Michael Hanselmann
I've discovered a problem where I'm not sure wether it's an error in the kernel or in the hardware.
It's neither - it's a bug in your test program. If you want "callout" semantics, open the port using O_NONBLOCK mode.
If you don't open the port using O_NONBLOCK then the port will wait for the DCD line (or virtual DCD line) to be asserted by the hardware before exiting uart_block_til_ready(). This is used for gettys on UARTs so they don't display the login banner until someone connects to the port.
Signature · 3 lines
Russell King Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/ maintainer of: 2.6 Serial core
Hello Russell
Quoted 6 lines · Russell King
Quoted 2 lines · Michael Hanselmann
I've discovered a problem where I'm not sure wether it's an error in the kernel or in the hardware.
It's neither - it's a bug in your test program. If you want "callout" semantics, open the port using
O_NONBLOCKmode.
I've now patched screen(1) and it works, but one thing is amazing me. The other computer I wrote about has the serial console on ttyS0 and starting screen(1) on the serial console works. Here's the relevant strace part:
screen-strace:open("/dev/ttyS0", O_RDWR|O_NONBLOCK) = 3 screen-strace.23801:open("/dev/ttyS0", O_RDWR) = 3
This doesn't work on the HP box with the serial console on ttyS2. After adding O_NONBLOCK, it works. Here's the strace:
screen-strace:open("/dev/ttyS2", O_RDWR|O_NONBLOCK) = 3 screen-strace.31830:open("/dev/ttyS2", O_RDWR|O_NONBLOCK) = 3
Am I going correct that this is a bug in screen(1) and it only works on the first box by some mysterious reason? Mabye some timing issue?
Thanks,
Michael
Signature · 1 line
Gentoo Linux developer, http://hansmi.ch/, http://forkbomb.ch/
Quoted 7 lines · Michael Hanselmann
Hello Russell
Quoted 3 lines · Russell King
Quoted 2 lines · Michael Hanselmann
I've discovered a problem where I'm not sure wether it's an error in the kernel or in the hardware.
Quoted 7 lines
Quoted 2 lines
It's neither - it's a bug in your test program. If you want "callout" semantics, open the port using
O_NONBLOCKmode.I've now patched screen(1) and it works, but one thing is amazing me. The other computer I wrote about has the serial console on ttyS0 and starting screen(1) on the serial console works. Here's the relevant strace part:
Have you checked the state of the DCD line in both cases? Look in /proc/tty/driver/serial.
Quoted 2 lines
Am I going correct that this is a bug in screen(1) and it only works on the first box by some mysterious reason? Mabye some timing issue?
Probably "works" on the first box because it happens to have DCD asserted on the real serial port.
Signature · 3 lines
Russell King Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/ maintainer of: 2.6 Serial core
Quoted 2 lines · Russell King
Have you checked the state of the DCD line in both cases? Look in
/proc/tty/driver/serial.
HP box:
2: uart:16550A port:000003E8 irq:4 tx:12888 rx:147 RTS|CTS|DTR|DSR
other box:
0: uart:16550A port:000003F8 irq:4 tx:18886 rx:299 RTS|CTS|DTR|DSR|CD
So, yes. The other box has CD set (unless CD is not DCD). It might be that the serial cable used there does this, but I can't check it because the box is several hundreds of kilometers away.
Quoted 2 lines
Probably "works" on the first box because it happens to have DCD asserted on the real serial port.
Yes, that explains it.
Thanks for your help,
Michael
Signature · 1 line
Gentoo Linux developer, http://hansmi.ch/, http://forkbomb.ch/