tty/serial: atmel_serial: BUG: stop DMA from transmitting in stop_tx
Subsystems (4)
PATCH 1/1 tty/serial: atmel_serial: BUG: stop DMA from transmitting in stop_tx
If we don't disable the transmitter in atmel_stop_tx, the DMA buffer continues to send data until it is emptied.
This cause problems with the flow control (CTS is asserted and data are still sent).
So, disabling the transmitter in atmel_stop_tx is a sane thing to do.
Tested on at91sam9g35-cm(DMA)
Tested for regressions on sama5d2-xplained(Fifo) and at91sam9g20ek(PDC)
--- drivers/tty/serial/atmel_serial.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
NB: this is not for the 4.10 merge window, I'm just sending it now to have some comments if someone is againts it.
drivers/tty/serial/atmel_serial.c +11 -0
@@ -481,6 +481,14 @@ static void atmel_stop_tx(struct uart_port *port)/* disable PDC transmit */ atmel_uart_writel (port,ATMEL_PDC_PTCR ,ATMEL_PDC_TXTDIS ); } + +/* +* Disable the transmitter. +* This is mandatory when DMA is used, otherwise the DMA buffer +* is fully transmitted. +*/ +atmel_uart_writel (port,ATMEL_US_CR ,ATMEL_US_TXDIS ); +/* Disable interrupts */ atmel_uart_writel (port,ATMEL_US_IDR , atmel_port->tx_done_mask);
@@ -513,6 +521,9 @@ static void atmel_start_tx(struct uart_port *port)/* Enable interrupts */ atmel_uart_writel (port,ATMEL_US_IER , atmel_port->tx_done_mask); + +/* re-enable the transmitter */ +atmel_uart_writel (port,ATMEL_US_CR ,ATMEL_US_TXEN ); }/*
Le 13/12/2016 � 17:27, Richard Genoud a �crit :
Quoted 5 lines
If we don't disable the transmitter in
atmel_stop_tx, the DMA buffer continues to send data until it is emptied.
This cause problems with the flow control (CTS is asserted and data are still sent).
Quoted 7 lines
So, disabling the transmitter in
atmel_stop_txis a sane thing to do.Tested on at91sam9g35-cm(DMA)
Tested for regressions on sama5d2-xplained(Fifo) and at91sam9g20ek(PDC)Cc <[email protected]> (beware, this won't apply before 4.3)Signed-off-by Richard Genoud <[email protected]>
Quoted 37 lines
--- drivers/tty/serial/atmel_serial.c | 11 +++++++++++ 1 file changed, 11 insertions(+)NB: this is not for the 4.10 merge window, I'm just sending it now to have some comments if someone is againts it.
drivers/tty/serial/atmel_serial.c +11
-0@@ -481,6 +481,14 @@ static void atmel_stop_tx(struct uart_port *port)/* disable PDC transmit */ atmel_uart_writel (port,ATMEL_PDC_PTCR ,ATMEL_PDC_TXTDIS ); } + +/* +* Disable the transmitter. +* This is mandatory when DMA is used, otherwise the DMA buffer +* is fully transmitted. +*/ +atmel_uart_writel (port,ATMEL_US_CR ,ATMEL_US_TXDIS ); +/* Disable interrupts */ atmel_uart_writel (port,ATMEL_US_IDR , atmel_port->tx_done_mask);@@ -513,6 +521,9 @@ static void atmel_start_tx(struct uart_port *port)/* Enable interrupts */ atmel_uart_writel (port,ATMEL_US_IER , atmel_port->tx_done_mask); + +/* re-enable the transmitter */ +atmel_uart_writel (port,ATMEL_US_CR ,ATMEL_US_TXEN ); }/*
Signature · 1 line
Nicolas Ferre
2017-01-02 12:13 GMT+01:00 Nicolas Ferre <[email protected]>:
Quoted 51 lines
Le 13/12/2016 ? 17:27, Richard Genoud a ?crit :
Quoted 5 lines
If we don't disable the transmitter in
atmel_stop_tx, the DMA buffer continues to send data until it is emptied.
This cause problems with the flow control (CTS is asserted and data are still sent).Quoted 7 lines
So, disabling the transmitter in
atmel_stop_txis a sane thing to do.Tested on at91sam9g35-cm(DMA)
Tested for regressions on sama5d2-xplained(Fifo) and at91sam9g20ek(PDC)Cc <[email protected]> (beware, this won't apply before 4.3)Signed-off-by Richard Genoud <[email protected]>Acked-by Nicolas Ferre <[email protected]>Quoted 35 lines
--- drivers/tty/serial/atmel_serial.c | 11 +++++++++++ 1 file changed, 11 insertions(+)NB: this is not for the 4.10 merge window, I'm just sending it now to have some comments if someone is againts it.
drivers/tty/serial/atmel_serial.c +11
-0@@ -481,6 +481,14 @@ static void atmel_stop_tx(struct uart_port *port)/* disable PDC transmit */ atmel_uart_writel (port,ATMEL_PDC_PTCR ,ATMEL_PDC_TXTDIS ); } + +/* +* Disable the transmitter. +* This is mandatory when DMA is used, otherwise the DMA buffer +* is fully transmitted. +*/ +atmel_uart_writel (port,ATMEL_US_CR ,ATMEL_US_TXDIS ); +/* Disable interrupts */ atmel_uart_writel (port,ATMEL_US_IDR , atmel_port->tx_done_mask);@@ -513,6 +521,9 @@ static void atmel_start_tx(struct uart_port *port)/* Enable interrupts */ atmel_uart_writel (port,ATMEL_US_IER , atmel_port->tx_done_mask); + +/* re-enable the transmitter */ +atmel_uart_writel (port,ATMEL_US_CR ,ATMEL_US_TXEN ); }
Quoted 6 lines
drivers/tty/serial/atmel_serial.c static void atmel_start_tx(struct uart_port *port) · line 529
Quoted 2 lines
drivers/tty/serial/atmel_serial.c +0
-0/* --
Nicolas Ferre
Greg, could you also take this patch in your tree ?
Thanks !
Richard.
Greg Kroah-Hartman
maintainerQuoted 52 lines · Richard Genoud
2017-01-02 12:13 GMT+01:00 Nicolas Ferre <[email protected]>:
Quoted 51 lines
Le 13/12/2016 � 17:27, Richard Genoud a �crit :
Quoted 5 lines
If we don't disable the transmitter in
atmel_stop_tx, the DMA buffer continues to send data until it is emptied.
This cause problems with the flow control (CTS is asserted and data are still sent).Quoted 7 lines
So, disabling the transmitter in
atmel_stop_txis a sane thing to do.Tested on at91sam9g35-cm(DMA)
Tested for regressions on sama5d2-xplained(Fifo) and at91sam9g20ek(PDC)Cc <[email protected]> (beware, this won't apply before 4.3)Signed-off-by Richard Genoud <[email protected]>Acked-by Nicolas Ferre <[email protected]>Quoted 35 lines
--- drivers/tty/serial/atmel_serial.c | 11 +++++++++++ 1 file changed, 11 insertions(+)NB: this is not for the 4.10 merge window, I'm just sending it now to have some comments if someone is againts it.
drivers/tty/serial/atmel_serial.c +11
-0@@ -481,6 +481,14 @@ static void atmel_stop_tx(struct uart_port *port)/* disable PDC transmit */ atmel_uart_writel (port,ATMEL_PDC_PTCR ,ATMEL_PDC_TXTDIS ); } + +/* +* Disable the transmitter. +* This is mandatory when DMA is used, otherwise the DMA buffer +* is fully transmitted. +*/ +atmel_uart_writel (port,ATMEL_US_CR ,ATMEL_US_TXDIS ); +/* Disable interrupts */ atmel_uart_writel (port,ATMEL_US_IDR , atmel_port->tx_done_mask);@@ -513,6 +521,9 @@ static void atmel_start_tx(struct uart_port *port)/* Enable interrupts */ atmel_uart_writel (port,ATMEL_US_IER , atmel_port->tx_done_mask); + +/* re-enable the transmitter */ +atmel_uart_writel (port,ATMEL_US_CR ,ATMEL_US_TXEN ); }
Quoted 8 lines
Quoted 6 lines
drivers/tty/serial/atmel_serial.c static void atmel_start_tx(struct uart_port *port) · line 529
Quoted 2 lines
drivers/tty/serial/atmel_serial.c +0
-0/* --
Nicolas FerreGreg, could you also take this patch in your tree ?
Yup!
Le 13/12/2016 ? 17:27, Richard Genoud a ?crit :
Quoted 39 lines
If we don't disable the transmitter in
atmel_stop_tx, the DMA buffer continues to send data until it is emptied.
This cause problems with the flow control (CTS is asserted and data are still sent).So, disabling the transmitter in
atmel_stop_txis a sane thing to do.Tested on at91sam9g35-cm(DMA)
Tested for regressions on sama5d2-xplained(Fifo) and at91sam9g20ek(PDC)Cc <[email protected]> (beware, this won't apply before 4.3)Signed-off-by Richard Genoud <[email protected]>--- drivers/tty/serial/atmel_serial.c | 11 +++++++++++ 1 file changed, 11 insertions(+)NB: this is not for the 4.10 merge window, I'm just sending it now to have some comments if someone is againts it.
drivers/tty/serial/atmel_serial.c +8
-0@@ -481,6 +481,14 @@ static void atmel_stop_tx(struct uart_port *port)/* disable PDC transmit */ atmel_uart_writel (port,ATMEL_PDC_PTCR ,ATMEL_PDC_TXTDIS ); } + +/* +* Disable the transmitter. +* This is mandatory when DMA is used, otherwise the DMA buffer +* is fully transmitted. +*/ +atmel_uart_writel (port,ATMEL_US_CR ,ATMEL_US_TXDIS ); +/* Disable interrupts */ atmel_uart_writel (port,ATMEL_US_IDR , atmel_port->tx_done_mask);
drivers/tty/serial/atmel_serial.c static void atmel_start_tx(struct uart_port *port) · line 529
Quoted 9 lines
drivers/tty/serial/atmel_serial.c +3
-0@@ -513,6 +521,9 @@ static void atmel_start_tx(struct uart_port *port)/* Enable interrupts */ atmel_uart_writel (port,ATMEL_US_IER , atmel_port->tx_done_mask); + +/* re-enable the transmitter */ +atmel_uart_writel (port,ATMEL_US_CR ,ATMEL_US_TXEN ); }/*
Hi Richard,
I've just discovered that I have some weird behavior with this patch. On current Linus' tree, with sama5d2 + DMA, I see some garbage characters coming out of the console when I try to stop my system (reboot/halt) [1].
Moreover, and I do understand that it's not the problem right here, when applied on our linux-4.4-at91 branch (our vendor tree actually), it hangs the boot process as it seems that a burst of open/close of the serial port happens while starting the rootfs. It's definitively my own problem, but it can bring light to what we are seeing on Mainline...
I think that we may need to flush the DMA channel in this atmel_stop_tx() function.
Best regards,
[1] If you want to test, you need to apply this patch for eMMC BTW:
https://patchwork.kernel.org/patch/9617489/
Signature · 1 line
Nicolas Ferre
2017-03-15 12:37 GMT+01:00 Nicolas Ferre <[email protected]>:
Quoted 48 lines
Le 13/12/2016 ? 17:27, Richard Genoud a ?crit :
Quoted 47 lines
If we don't disable the transmitter in
atmel_stop_tx, the DMA buffer continues to send data until it is emptied.
This cause problems with the flow control (CTS is asserted and data are still sent).So, disabling the transmitter in
atmel_stop_txis a sane thing to do.Tested on at91sam9g35-cm(DMA)
Tested for regressions on sama5d2-xplained(Fifo) and at91sam9g20ek(PDC)Cc <[email protected]> (beware, this won't apply before 4.3)Signed-off-by Richard Genoud <[email protected]>--- drivers/tty/serial/atmel_serial.c | 11 +++++++++++ 1 file changed, 11 insertions(+)NB: this is not for the 4.10 merge window, I'm just sending it now to have some comments if someone is againts it.
drivers/tty/serial/atmel_serial.c +11
-0@@ -481,6 +481,14 @@ static void atmel_stop_tx(struct uart_port *port)/* disable PDC transmit */ atmel_uart_writel (port,ATMEL_PDC_PTCR ,ATMEL_PDC_TXTDIS ); } + +/* +* Disable the transmitter. +* This is mandatory when DMA is used, otherwise the DMA buffer +* is fully transmitted. +*/ +atmel_uart_writel (port,ATMEL_US_CR ,ATMEL_US_TXDIS ); +/* Disable interrupts */ atmel_uart_writel (port,ATMEL_US_IDR , atmel_port->tx_done_mask);@@ -513,6 +521,9 @@ static void atmel_start_tx(struct uart_port *port)/* Enable interrupts */ atmel_uart_writel (port,ATMEL_US_IER , atmel_port->tx_done_mask); + +/* re-enable the transmitter */ +atmel_uart_writel (port,ATMEL_US_CR ,ATMEL_US_TXEN ); }
Quoted 3 lines
drivers/tty/serial/atmel_serial.c static void atmel_start_tx(struct uart_port *port) · line 529
Quoted 1 line
drivers/tty/serial/atmel_serial.c +0
-0/* Hi Richard,
Hi !
Quoted 4 lines
I've just discovered that I have some weird behavior with this patch. On current Linus' tree, with sama5d2 + DMA, I see some garbage characters coming out of the console when I try to stop my system (reboot/halt) [1].
Yes, I've also seen that on my board, it was on my todo list. (Although I didn't know this patch was the culprit !)
Quoted 6 lines
Moreover, and I do understand that it's not the problem right here, when applied on our linux-4.4-at91 branch (our vendor tree actually), it hangs the boot process as it seems that a burst of open/close of the serial port happens while starting the rootfs. It's definitively my own problem, but it can bring light to what we are seeing on Mainline...
a?e !
This is clearly something we'll have to understand !
Quoted 3 lines
I think that we may need to flush the DMA channel in this
atmel_stop_tx()function.
yes, I'll look into that.
Quoted 7 lines
Best regards,
[1] If you want to test, you need to apply this patch for eMMC BTW:
https://patchwork.kernel.org/patch/9617489/--
Nicolas Ferre
Thanks !
Richard.
Nicolas Ferre
maintainerRFC PATCH 1/1 tty/serial: atmel: fix TX path in atmel_console_write()
A side effect of 89d8232411a8 ("tty/serial: atmel_serial: BUG: stop DMA from transmitting in stop_tx") is that the console can be called with TX path disabled. Then the system would hang trying to push charecters out in atmel_console_putchar().
in stop_tx")
Cc: stable <[email protected]> # 4.4+
---
Hi Richard,
I found this to fix the problem with system hang in my linux-4.4-at91 branch (in the atmel_console_putchar() waiting loop actually). I'm open to more insignt.
As we cannot figure out if this bit is set or not, I didn't preserve the current status...
Regards,
drivers/tty/serial/atmel_serial.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/tty/serial/atmel_serial.c +3 -0
@@ -2483,6 +2483,9 @@ static void atmel_console_write(struct console *co, const char *s, u_int count) pdc_tx =atmel_uart_readl (port,ATMEL_PDC_PTSR ) &ATMEL_PDC_TXTEN ;atmel_uart_writel (port,ATMEL_PDC_PTCR ,ATMEL_PDC_TXTDIS ); +/* Make sure that tx path is actually able to send characters */ +atmel_uart_writel (port,ATMEL_US_CR ,ATMEL_US_TXEN ); +uart_console_write (port, s, count, atmel_console_putchar);/*
Signature · 1 line
2.9.0
Re: [RFC PATCH] tty/serial: atmel: fix TX path in atmel_console_write()
Quoted 12 lines · Nicolas Ferre
A side effect of
89d8232411a8("tty/serial:atmel_serial: BUG: stop DMA from transmitting instop_tx") is that the console can be called with TX path disabled. Then the system would hang trying to push charecters out inatmel_console_putchar().Signed-off-by Nicolas Ferre <[email protected]>Fixes 89d8232411a8 ("tty/serial: atmel_serial: BUG: stop DMA from transmittingin
stop_tx")
Cc: stable <[email protected]> # 4.4+
---
Hi Richard,
Quoted 7 lines
I found this to fix the problem with system hang in my linux-4.4-at91 branch (in the
atmel_console_putchar()waiting loop actually). I'm open to more insignt.
As we cannot figure out if this bit is set or not, I didn't preserve the current status...Regards,
So, I'm guessing that you may see some lines/characters printed twice on the screen, don't you ?
Quoted 9 lines
drivers/tty/serial/atmel_serial.c | 3 +++ 1 file changed, 3 insertions(+)drivers/tty/serial/atmel_serial.c +0
-0
drivers/tty/serial/atmel_serial.c static void atmel_console_write(struct console *co, const char *s, u_int count) · line 2491
Quoted 9 lines
drivers/tty/serial/atmel_serial.c +3
-0@@ -2483,6 +2483,9 @@ static void atmel_console_write(struct console *co, const char *s, u_int count) pdc_tx =atmel_uart_readl (port,ATMEL_PDC_PTSR ) &ATMEL_PDC_TXTEN ;atmel_uart_writel (port,ATMEL_PDC_PTCR ,ATMEL_PDC_TXTDIS ); +/* Make sure that tx path is actually able to send characters */ +atmel_uart_writel (port,ATMEL_US_CR ,ATMEL_US_TXEN ); +uart_console_write (port, s, count, atmel_console_putchar);/*
Richard.
Nicolas Ferre
maintainerRe: [RFC PATCH] tty/serial: atmel: fix TX path in atmel_console_write()
Le 15/03/2017 ? 17:19, Richard Genoud a ?crit :
Quoted 19 lines · Nicolas Ferre
Quoted 18 lines
A side effect of
89d8232411a8("tty/serial:atmel_serial: BUG: stop DMA from transmitting instop_tx") is that the console can be called with TX path disabled. Then the system would hang trying to push charecters out inatmel_console_putchar().Signed-off-by Nicolas Ferre <[email protected]>Fixes 89d8232411a8 ("tty/serial: atmel_serial: BUG: stop DMA from transmittingin
stop_tx")
Cc: stable <[email protected]> # 4.4+
---
Hi Richard,I found this to fix the problem with system hang in my linux-4.4-at91 branch (in the
atmel_console_putchar()waiting loop actually). I'm open to more insignt.
As we cannot figure out if this bit is set or not, I didn't preserve the current status...
Quoted 4 lines
Quoted 1 line
Regards,
So, I'm guessing that you may see some lines/characters printed twice on the screen, don't you ?
Well, actually, I don't think so because the repetitions that I see are probably due to open/close/open/close/re-open/... of the serial console itself.
Same with the line "random: udevd: uninitialized urandom read (16 bytes read, 21 bits of entropy available)", they happen at different moment in time => the printk log timestamping seem to indicate that they are different.
Here is my log:
http://code.bulix.org/bok23n-123056
Regards,
Quoted 21 lines
Quoted 9 lines
drivers/tty/serial/atmel_serial.c | 3 +++ 1 file changed, 3 insertions(+)drivers/tty/serial/atmel_serial.c +0
-0drivers/tty/serial/atmel_serial.c static void atmel_console_write(struct console *co, const char *s, u_int count) · line 2491
Quoted 9 lines
drivers/tty/serial/atmel_serial.c +3
-0@@ -2483,6 +2483,9 @@ static void atmel_console_write(struct console *co, const char *s, u_int count) pdc_tx =atmel_uart_readl (port,ATMEL_PDC_PTSR ) &ATMEL_PDC_TXTEN ;atmel_uart_writel (port,ATMEL_PDC_PTCR ,ATMEL_PDC_TXTDIS ); +/* Make sure that tx path is actually able to send characters */ +atmel_uart_writel (port,ATMEL_US_CR ,ATMEL_US_TXEN ); +uart_console_write (port, s, count, atmel_console_putchar);/* Richard.
Signature · 1 line
Nicolas Ferre
Re: [RFC PATCH] tty/serial: atmel: fix TX path in atmel_console_write()
2017-03-15 17:56 GMT+01:00 Nicolas Ferre <[email protected]>:
Quoted 25 lines
Le 15/03/2017 ? 17:19, Richard Genoud a ?crit :
Quoted 19 lines · Nicolas Ferre
Quoted 18 lines
A side effect of
89d8232411a8("tty/serial:atmel_serial: BUG: stop DMA from transmitting instop_tx") is that the console can be called with TX path disabled. Then the system would hang trying to push charecters out inatmel_console_putchar().Signed-off-by Nicolas Ferre <[email protected]>Fixes 89d8232411a8 ("tty/serial: atmel_serial: BUG: stop DMA from transmittingin
stop_tx")
Cc: stable <[email protected]> # 4.4+
---
Hi Richard,I found this to fix the problem with system hang in my linux-4.4-at91 branch (in the
atmel_console_putchar()waiting loop actually). I'm open to more insignt.
As we cannot figure out if this bit is set or not, I didn't preserve the current status...Quoted 4 lines
Quoted 1 line
Regards,
So, I'm guessing that you may see some lines/characters printed twice on the screen, don't you ?
Quoted 8 lines
Well, actually, I don't think so because the repetitions that I see are probably due to open/close/open/close/re-open/... of the serial console itself.
Same with the line "random: udevd: uninitialized urandom read (16 bytes read, 21 bits of entropy available)", they happen at different moment in time => the printk log timestamping seem to indicate that they are different.
Hi Nicolas,
It seems that the problem is between atmel_tx_dma() and its callback atmel_complete_tx_dma().
At some point, atmel_tx_dma() is called, does the job, and then, just before the callback is called, the xmit->head and xmit->tail pointers are set to zero (by uart_flush_buffer())
So, when atmel_complete_tx_dma() is called, it does:xmit->tail += atmel_port->tx_len;
not knowing that the head and tail pointers have been reseted. => it's like there's (UART_XMIT_SIZE - atmel_port->tx_len) characters to transmit on the serial line.
PS: I can trigger this bug by holding down the d key at login and then ctrl - basically, a ctrl-d just after sending text - with a rate success of about 1/5 :)
Could you try this patch to see if it corrects also your system hang ?
(The patch is small, but the bug hunt was a headache :))
[PATCH] tty/serial: atmel: fix race condition (TX+DMA)
If uart_flush_buffer() is called between atmel_tx_dma() and atmel_complete_tx_dma(), the circular buffer has been cleared, but not atmel_port->tx_len.
That leads to a circular buffer overflow (dumping (UART_XMIT_SIZE - atmel_port->tx_len) bytes).
--- drivers/tty/serial/atmel_serial.c | 5 +++++ 1 file changed, 5 insertions(+)
(quoted diff) +0 -0
b/drivers/tty/serial/atmel_serial.c
index 833d3d80446f..89552157e334 100644
drivers/tty/serial/atmel_serial.c +0 -0
@@ -1934,6 +1934,11 @@ static void atmel_flush_buffer(struct uart_port
*port)
atmel_uart_writel(port, ATMEL_PDC_TCR, 0); atmel_port->pdc_tx.ofs = 0;
}
+ /*
+ * in uart_flush_buffer(), the xmit circular buffer has just
+ * been cleared, so we have to reset tx_len accordingly.
+ */
+ atmel_port->tx_len = 0;
}
/*
Re: [RFC PATCH] tty/serial: atmel: fix TX path in atmel_console_write()
Le 17/03/2017 ? 16:11, Richard Genoud a ?crit :
Quoted 48 lines
2017-03-15 17:56 GMT+01:00 Nicolas Ferre <[email protected]>:
Quoted 25 lines
Le 15/03/2017 ? 17:19, Richard Genoud a ?crit :
Quoted 19 lines · Nicolas Ferre
Quoted 18 lines
A side effect of
89d8232411a8("tty/serial:atmel_serial: BUG: stop DMA from transmitting instop_tx") is that the console can be called with TX path disabled. Then the system would hang trying to push charecters out inatmel_console_putchar().Signed-off-by Nicolas Ferre <[email protected]>Fixes 89d8232411a8 ("tty/serial: atmel_serial: BUG: stop DMA from transmittingin
stop_tx")
Cc: stable <[email protected]> # 4.4+
---
Hi Richard,I found this to fix the problem with system hang in my linux-4.4-at91 branch (in the
atmel_console_putchar()waiting loop actually). I'm open to more insignt.
As we cannot figure out if this bit is set or not, I didn't preserve the current status...Quoted 4 lines
Quoted 1 line
Regards,
So, I'm guessing that you may see some lines/characters printed twice on the screen, don't you ?
Quoted 8 lines
Well, actually, I don't think so because the repetitions that I see are probably due to open/close/open/close/re-open/... of the serial console itself.
Same with the line "random: udevd: uninitialized urandom read (16 bytes read, 21 bits of entropy available)", they happen at different moment in time => the printk log timestamping seem to indicate that they are different.
Hi Nicolas,
It seems that the problem is between
atmel_tx_dma()and its callbackatmel_complete_tx_dma().At some point,
atmel_tx_dma()is called, does the job, and then, just before the callback is called, thexmit->headandxmit->tailpointers are set to zero (byuart_flush_buffer())
So, whenatmel_complete_tx_dma()is called, it does:xmit->tail+=atmel_port->tx_len;
not knowing that the head and tail pointers have been reseted. => it's like there's (UART_XMIT_SIZE-atmel_port->tx_len) characters to transmit on the serial line.
Quoted 5 lines
PS: I can trigger this bug by holding down the d key at login and then ctrl - basically, a ctrl-d just after sending text - with a rate success of about 1/5 :)
Could you try this patch to see if it corrects also your system hang ?
Just tried, it doesn't fix the system hang.
But it seems to solve the issue that I had while halting the system: a kind of flush of a previous buffer in the console.
So, I think it does solve something.
So, with both my patch and yours:
Regards,
Quoted 34 lines
(The patch is small, but the bug hunt was a headache :))
[PATCH] tty/serial: atmel: fix race condition (TX+DMA)
If
uart_flush_buffer()is called betweenatmel_tx_dma()andatmel_complete_tx_dma(), the circular buffer has been cleared, but notatmel_port->tx_len.
That leads to a circular buffer overflow (dumping (UART_XMIT_SIZE-atmel_port->tx_len) bytes).Signed-off-by Richard Genoud <[email protected]>--- drivers/tty/serial/atmel_serial.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/tty/serial/atmel_serial.c +5
-0@@ -1934,6 +1934,11 @@ static void atmel_flush_buffer(struct uart_port *port)atmel_uart_writel (port,ATMEL_PDC_TCR ,0 ); atmel_port->pdc_tx.ofs =0 ; } +/* +* in uart_flush_buffer(), the xmit circular buffer has just +* been cleared, so we have to reset tx_len accordingly. +*/ + atmel_port->tx_len =0 ; }/*
Signature · 1 line
Nicolas Ferre
Re: [RFC PATCH] tty/serial: atmel: fix TX path in atmel_console_write()
In reply to Nicolas FerreQuoted 29 lines · Nicolas Ferre
A side effect of
89d8232411a8("tty/serial:atmel_serial: BUG: stop DMA from transmitting instop_tx") is that the console can be called with TX path disabled. Then the system would hang trying to push charecters out inatmel_console_putchar().Signed-off-by Nicolas Ferre <[email protected]>Fixes 89d8232411a8 ("tty/serial: atmel_serial: BUG: stop DMA from transmittingin
stop_tx")
Cc: stable <[email protected]> # 4.4+
---
Hi Richard,I found this to fix the problem with system hang in my linux-4.4-at91 branch (in the
atmel_console_putchar()waiting loop actually). I'm open to more insignt.
As we cannot figure out if this bit is set or not, I didn't preserve the current status...Regards,
drivers/tty/serial/atmel_serial.c | 3 +++ 1 file changed, 3 insertions(+)drivers/tty/serial/atmel_serial.c +0
-0
drivers/tty/serial/atmel_serial.c static void atmel_console_write(struct console *co, const char *s, u_int count) · line 2491
Quoted 9 lines
drivers/tty/serial/atmel_serial.c +3
-0@@ -2483,6 +2483,9 @@ static void atmel_console_write(struct console *co, const char *s, u_int count) pdc_tx =atmel_uart_readl (port,ATMEL_PDC_PTSR ) &ATMEL_PDC_TXTEN ;atmel_uart_writel (port,ATMEL_PDC_PTCR ,ATMEL_PDC_TXTDIS ); +/* Make sure that tx path is actually able to send characters */ +atmel_uart_writel (port,ATMEL_US_CR ,ATMEL_US_TXEN ); +uart_console_write (port, s, count, atmel_console_putchar);/*