serial: 8250_dw: Avoid "too much work" from bogus rx timeout interrupt
Subsystems (4)
PATCH v2 1/1 serial: 8250_dw: Avoid "too much work" from bogus rx timeout interrupt
On a Rockchip rk3399-based board during suspend/resume testing, we found that we could get the console UART into a state where it would print this to the console a lot:
serial8250: too much work for irq42
Followed eventually by:
NMI watchdog: BUG: soft lockup - CPU#0 stuck for 11s!
Upon debugging I found that we're in this state:
iir = 0x000000cc
lsr = 0x00000060
It appears that somehow we have a RX Timeout interrupt but there is no actual data present to receive. When we're in this state the UART driver claims that it handled the interrupt but it actually doesn't really do anything. This means that we keep getting the interrupt over and over again.
Normally we don't actually need to do anything special to handle a RX Timeout interrupt. We'll notice that there is some data ready and we'll read it, which will end up clearing the RX Timeout. In this case we have a problem specifically because we got the RX TImeout without any data. Reading a bogus byte is confirmed to get us out of this state.
It's unclear how exactly the UART got into this state, but it is known that the UART lines are essentially undriven and unpowered during suspend, so possibly during resume some garbage / half transmitted bits are seen on the line and put the UART into this state.
The UART on the rk3399 is a DesignWare based 8250 UART. From mailing list posts, it appears that other people have run into similar problems with DesignWare based IP. Presumably this problem is unique to that IP, so I have placed the workaround there to avoid possibly of accidentally triggering bad behavior on other IP. Also note the RX Timeout behaves very differently in the DMA case, for for now the workaround is only applied to the non-DMA case.
---
Testing and development done on a kernel-4.4 based tree, then picked to ToT, where the code applied cleanly.
Changes in v2:
- Only apply to 8250_dw, not all 8250
- Only apply to the non-DMA case
drivers/tty/serial/8250/8250_dw.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
drivers/tty/serial/8250/8250_dw.c +23 -0
@@ -201,8 +201,31 @@ static unsigned int dw8250_serial_in32be(struct uart_port *p, int offset)static int dw8250_handle_irq (struct uart_port *p) { +struct uart_8250_port *up =up_to_u8250p (p);struct dw8250_data *d = p->private_data;unsigned int iir = p->serial_in (p,UART_IIR ); +unsigned int status; +unsigned long flags; + +/* +* There are ways to get Designware-based UARTs into a state where +* they are asserting UART_IIR_RX_TIMEOUT but there is no actual +* data available. If we see such a case then we'll do a bogus +* read. If we don't do this then the "RX TIMEOUT" interrupt will +* fire forever. +* +* This problem has only been observed so far when not in DMA mode +* so we limit the workaround only to non-DMA mode. +*/ +if (!up->dma && ((iir &0x3f ) ==UART_IIR_RX_TIMEOUT )) { +spin_lock_irqsave (&p->lock, flags); + status = p->serial_in (p,UART_LSR ); + +if (!(status & (UART_LSR_DR |UART_LSR_BI ))) + (void ) p->serial_in (p,UART_RX ); + +spin_unlock_irqrestore (&p->lock, flags); + }if (serial8250_handle_irq (p, iir))return 1 ;
Signature · 1 line
2.11.0.483.g087da7b7c-goog
Quoted 25 lines · Douglas Anderson
On a Rockchip rk3399-based board during suspend/resume testing, we found that we could get the console UART into a state where it would print this to the console a lot:
serial8250: too much work for irq42Followed eventually by:
NMI watchdog: BUG: soft lockup - CPU#0 stuck for 11s!Upon debugging I found that we're in this state:
iir = 0x000000cc lsr = 0x00000060It appears that somehow we have a RX Timeout interrupt but there is no actual data present to receive. When we're in this state the UART driver claims that it handled the interrupt but it actually doesn't really do anything. This means that we keep getting the interrupt over and over again.
Normally we don't actually need to do anything special to handle a RX Timeout interrupt. We'll notice that there is some data ready and we'll read it, which will end up clearing the RX Timeout. In this case we have a problem specifically because we got the RX TImeout without any data. Reading a bogus byte is confirmed to get us out of this state.
Quoted 4 lines
It's unclear how exactly the UART got into this state, but it is known that the UART lines are essentially undriven and unpowered during suspend, so possibly during resume some garbage / half transmitted bits are seen on the line and put the UART into this state.
Its been a long time since I looked at this, but IIRC it wasn't garbage bits, but spurious interrupts. The FIFO is implemented in such a way that it acts as a ring, and with a known input you could know ahead of time what the result of the extra read would be. This tricked me up, as with the inputs I was originally using it appeared to be valid data, when in fact it was just the next buffer in the ring which still had old data.
This probably doesn't help much, but at least gives some background knowledge.
---
Cal
Quoted 57 lines
The UART on the rk3399 is a DesignWare based 8250 UART. From mailing list posts, it appears that other people have run into similar problems with DesignWare based IP. Presumably this problem is unique to that IP, so I have placed the workaround there to avoid possibly of accidentally triggering bad behavior on other IP. Also note the RX Timeout behaves very differently in the DMA case, for for now the workaround is only applied to the non-DMA case.
Signed-off-by Douglas Anderson <[email protected]>---
Testing and development done on a kernel-4.4 based tree, then picked to ToT, where the code applied cleanly.Changes in v2:
- Only apply to 8250_dw, not all 8250
- Only apply to the non-DMA casedrivers/tty/serial/8250/8250_dw.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)drivers/tty/serial/8250/8250_dw.c +23
-0@@ -201,8 +201,31 @@ static unsigned int dw8250_serial_in32be(struct uart_port *p, int offset)static int dw8250_handle_irq (struct uart_port *p) { +struct uart_8250_port *up =up_to_u8250p (p);struct dw8250_data *d = p->private_data;unsigned int iir = p->serial_in (p,UART_IIR ); +unsigned int status; +unsigned long flags; + +/* +* There are ways to get Designware-based UARTs into a state where +* they are asserting UART_IIR_RX_TIMEOUT but there is no actual +* data available. If we see such a case then we'll do a bogus +* read. If we don't do this then the "RX TIMEOUT" interrupt will +* fire forever. +* +* This problem has only been observed so far when not in DMA mode +* so we limit the workaround only to non-DMA mode. +*/ +if (!up->dma && ((iir &0x3f ) ==UART_IIR_RX_TIMEOUT )) { +spin_lock_irqsave (&p->lock, flags); + status = p->serial_in (p,UART_LSR ); + +if (!(status & (UART_LSR_DR |UART_LSR_BI ))) + (void ) p->serial_in (p,UART_RX ); + +spin_unlock_irqrestore (&p->lock, flags); + }if (serial8250_handle_irq (p, iir))return 1 ;
Hey Douglas,
Quoted 12 lines · Douglas Anderson
On a Rockchip rk3399-based board during suspend/resume testing, we found that we could get the console UART into a state where it would print this to the console a lot:
serial8250: too much work for irq42Followed eventually by:
NMI watchdog: BUG: soft lockup - CPU#0 stuck for 11s!Upon debugging I found that we're in this state:
iir =0x000000cc
lsr =0x00000060
Quoted 5 lines
It appears that somehow we have a RX Timeout interrupt but there is no actual data present to receive. When we're in this state the UART driver claims that it handled the interrupt but it actually doesn't really do anything. This means that we keep getting the interrupt over and over again.
I may be running into the same thing on an A20 SoC, but still in the stage of figuring out what is going on, as we get this error very occasionally. Do you have a way to externally induce this behavior other then suspend/resume? As we get it during uart-use and do not have (or I have never tried) suspend/resume on our platform.
Quoted 43 lines
Normally we don't actually need to do anything special to handle a RX Timeout interrupt. We'll notice that there is some data ready and we'll read it, which will end up clearing the RX Timeout. In this case we have a problem specifically because we got the RX TImeout without any data. Reading a bogus byte is confirmed to get us out of this state.
It's unclear how exactly the UART got into this state, but it is known that the UART lines are essentially undriven and unpowered during suspend, so possibly during resume some garbage / half transmitted bits are seen on the line and put the UART into this state.
The UART on the rk3399 is a DesignWare based 8250 UART. From mailing list posts, it appears that other people have run into similar problems with DesignWare based IP. Presumably this problem is unique to that IP, so I have placed the workaround there to avoid possibly of accidentally triggering bad behavior on other IP. Also note the RX Timeout behaves very differently in the DMA case, for for now the workaround is only applied to the non-DMA case.
Signed-off-by Douglas Anderson <[email protected]>---
Testing and development done on a kernel-4.4 based tree, then picked to ToT, where the code applied cleanly.Changes in v2:
- Only apply to 8250_dw, not all 8250
- Only apply to the non-DMA casedrivers/tty/serial/8250/8250_dw.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)drivers/tty/serial/8250/8250_dw.c +1
-0@@ -201,8 +201,31 @@ static unsigned int dw8250_serial_in32be(struct uart_port *p, int offset)static int dw8250_handle_irq (struct uart_port *p) { +struct uart_8250_port *up =up_to_u8250p (p);struct dw8250_data *d = p->private_data;
drivers/tty/serial/8250/8250_dw.c static unsigned int dw8250_serial_in32be(struct uart_port *p, int offset) · line 215
Quoted 10 lines
drivers/tty/serial/8250/8250_dw.c +9
-0unsigned int iir = p->serial_in (p,UART_IIR ); +unsigned int status; +unsigned long flags; + +/* +* There are ways to get Designware-based UARTs into a state where +* they are asserting UART_IIR_RX_TIMEOUT but there is no actual +* data available. If we see such a case then we'll do a bogus +* read. If we don't do this then the "RX TIMEOUT" interrupt will +* fire forever.
I think what you are saying is 'do a bogus read as that is the only way to clear the interrupt, otherwise it will keep firing forever.'?
drivers/tty/serial/8250/8250_dw.c static unsigned int dw8250_serial_in32be(struct uart_port *p, int offset) · line 220
Quoted 5 lines
drivers/tty/serial/8250/8250_dw.c +5
-0+* +* This problem has only been observed so far when not in DMA mode +* so we limit the workaround only to non-DMA mode. +*/ +if (!up->dma && ((iir &0x3f ) ==UART_IIR_RX_TIMEOUT )) {
why not
if (!up->dma && ((iir & UART_IIR_RX_TIMEOUT) == UART_IIR_RX_TIMEOUT)) {
it follows the flow as other conditionals in the 8250 source and you really only need to mask the specific interrupt anyway.
drivers/tty/serial/8250/8250_dw.c static unsigned int dw8250_serial_in32be(struct uart_port *p, int offset) · line 221
Quoted 1 line
drivers/tty/serial/8250/8250_dw.c +1
-0+spin_lock_irqsave (&p->lock, flags);
this is a bit above my knowledge of driver etc, but I don't any spinlocks in the 8250 handle_irq glue drivers, except in the OMAP's case where they are handeling a DMA IRQ. So I ask, because I don't know, why is it needed here?
drivers/tty/serial/8250/8250_dw.c static unsigned int dw8250_serial_in32be(struct uart_port *p, int offset) · line 225
Quoted 4 lines
drivers/tty/serial/8250/8250_dw.c +4
-0+ status = p->serial_in (p,UART_LSR ); + +if (!(status & (UART_LSR_DR |UART_LSR_BI ))) + (void ) p->serial_in (p,UART_RX );
I think there should be no space between (void) and p->serial_in
drivers/tty/serial/8250/8250_dw.c static unsigned int dw8250_serial_in32be(struct uart_port *p, int offset) · line 231
Quoted 7 lines
drivers/tty/serial/8250/8250_dw.c +3
-0+ +spin_unlock_irqrestore (&p->lock, flags); + }if (serial8250_handle_irq (p, iir))return 1 ;
Once I found a way to reproduce the problem (without suspend) I will test this to see if it fixes it for us too.
Olliver
Quoted 1 line · Olliver Schinagl
On 07-02-17 00:30, Douglas Anderson wrote:
First of all I didn't get why people from Cc list are suddenly disappeared. Check your mail client settings. Returning back some of them.
Quoted 11 lines
Quoted 5 lines
It appears that somehow we have a RX Timeout interrupt but there is no actual data present to receive. When we're in this state the UART driver claims that it handled the interrupt but it actually doesn't really do anything. This means that we keep getting the interrupt over and over again.
I may be running into the same thing on an A20 SoC, but still in the stage of figuring out what is going on, as we get this error very occasionally. Do you have a way to externally induce this behavior other then suspend/resume? As we get it during uart-use and do not have (or I have never tried) suspend/resume on our platform.
On Intel platforms with this IP I can see similar when run loopback test on high speeds.
California may correct me since he did a lot of investigation of the issue on x86.
Quoted 15 lines
Quoted 4 lines
static int
dw8250_handle_irq(struct uart_port *p){drivers/tty/serial/8250/8250_dw.c +1
-0+struct uart_8250_port *up =up_to_u8250p (p);struct dw8250_data *d = p->private_data;drivers/tty/serial/8250/8250_dw.c static unsigned int dw8250_serial_in32be(struct uart_port *p, int offset) · line 215
Quoted 10 lines
drivers/tty/serial/8250/8250_dw.c +9
-0unsigned int iir = p->serial_in (p,UART_IIR ); +unsigned int status; +unsigned long flags; + +/* +* There are ways to get Designware-based UARTs into a state where +* they are asserting UART_IIR_RX_TIMEOUT but there is no actual +* data available. If we see such a case then we'll do a bogus +* read. If we don't do this then the "RX TIMEOUT" interrupt will +* fire forever.
Quoted 2 lines
I think what you are saying is 'do a bogus read as that is the only way to clear the interrupt, otherwise it will keep firing forever.'?
No, we don't know if this _the only way_. It looks like no one from us can tell you a root cause, except may be Synopsys guys.
Quoted 5 lines
Quoted 1 line
+
spin_lock_irqsave(&p->lock, flags);this is a bit above my knowledge of driver etc, but I don't any spinlocks in the 8250
handle_irqglue drivers, except in the OMAP's case where they are handeling a DMA IRQ. So I ask, because I don't know, why is it needed here?
They serialize IO accessors.
Regarding to the rest comments, the patch is already in upstream, if you feel that something should be changed, send an incremental fix.
Quoted 2 lines
Once I found a way to reproduce the problem (without suspend) I will test this to see if it fixes it for us too.
It would be appreciated, but better to get know the root cause and what _hardware_ guys think about solutions.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hey Andy,
Quoted 6 lines · Andy Shevchenko
Quoted 1 line · Olliver Schinagl
On 07-02-17 00:30, Douglas Anderson wrote:
First of all I didn't get why people from Cc list are suddenly disappeared. Check your mail client settings. Returning back some of them.
Appologies, I replied via gmane's news feed to Douglas's initial post as I did not have the original post and I failed to check the other recipients. My fault. Sorry. I've added the original others as well.
Quoted 33 lines
Quoted 7 lines
Quoted 6 lines
It appears that somehow we have a RX Timeout interrupt but there is no actual data present to receive. When we're in this state the UART driver claims that it handled the interrupt but it actually doesn't really do anything. This means that we keep getting the interrupt over and over again.
Quoted 5 lines
I may be running into the same thing on an A20 SoC, but still in the stage of figuring out what is going on, as we get this error very occasionally. Do you have a way to externally induce this behavior other then suspend/resume? As we get it during uart-use and do not have (or I have never tried) suspend/resume on our platform.
On Intel platforms with this IP I can see similar when run loopback test on high speeds.
California may correct me since he did a lot of investigation of the issue on x86.Quoted 15 lines
Quoted 14 lines
static int
dw8250_handle_irq(struct uart_port *p){drivers/tty/serial/8250/8250_dw.c +10
-0+struct uart_8250_port *up =up_to_u8250p (p);struct dw8250_data *d = p->private_data;unsigned int iir = p->serial_in (p,UART_IIR ); +unsigned int status; +unsigned long flags; + +/* +* There are ways to get Designware-based UARTs into a state where +* they are asserting UART_IIR_RX_TIMEOUT but there is no actual +* data available. If we see such a case then we'll do a bogus +* read. If we don't do this then the "RX TIMEOUT" interrupt will +* fire forever.
Quoted 5 lines
Quoted 2 lines
I think what you are saying is 'do a bogus read as that is the only way to clear the interrupt, otherwise it will keep firing forever.'?
No, we don't know if this
_theonlyway_. It looks like no one from us can tell you a root cause, except may be Synopsys guys.
Has anybody tried to contact synopsis/dw about this issue at all?
true, it is not the only way (maybe only as far as we know for now) but it is 'the' way currently.
Quoted 11 lines
Quoted 6 lines
Quoted 2 lines
+
spin_lock_irqsave(&p->lock, flags);this is a bit above my knowledge of driver etc, but I don't any spinlocks in the 8250
handle_irqglue drivers, except in the OMAP's case where they are handeling a DMA IRQ. So I ask, because I don't know, why is it needed here?They serialize IO accessors.
Regarding to the rest comments, the patch is already in upstream, if you feel that something should be changed, send an incremental fix.
Ah, I thought I checked, but thought I didn't see it. I'll probably forgot to fetch. I'll send a patch for the small mask fix.
Quoted 7 lines
Quoted 3 lines
Once I found a way to reproduce the problem (without suspend) I will test this to see if it fixes it for us too.
It would be appreciated, but better to get know the root cause and what _hardware_ guys think about solutions.
I read over the docs of the IP block (I know a little FPGA programming) (dw_apb_uart of 2006) but found nothing yet that would warn for this behavior. I suppose hardware/fgpa guys can give more background here potentially, but it may also be simply an IP bug?
Olliver