serial: 8250: Toggle IER bits on only after irq has been set up
PATCH v3 1/1 serial: 8250: Toggle IER bits on only after irq has been set up
Invoking TIOCVHANGUP on 8250_mid port on Ice Lake-D and then reopening the port triggers these faults during serial8250_do_startup():
DMAR: DRHD: handling fault status reg 3
DMAR: [DMA Write NO_PASID] Request device [00:1a.0] fault addr 0x0 [fault reason 0x05] PTE Write access is not set
If the IRQ hasn't been set up yet, the UART will have zeroes in its MSI address/data registers. Disabling the IRQ at the interrupt controller won't stop the UART from performing a DMA write to the address programmed in its MSI address register (zero) when it wants to signal an interrupt.
The UARTs (in Ice Lake-D) implement PCI 2.1 style MSI without masking capability, so there is no way to mask the interrupt at the source PCI function level, except disabling the MSI capability entirely, but that would cause it to fall back to INTx# assertion, and the PCI specification prohibits disabling the MSI capability as a way to mask a function's interrupt service request.
The MSI address register is zeroed during by the hangup as the irq is freed. The interrupt is signalled during serial8250_do_startup() performing a THRE test that temporarily toggles THRI in IER. The THRE test currently occurs before UART's irq (and MSI address) is properly set up.
Refactor serial8250_do_startup() such that irq is set up before the THRE test. The current irq setup code is intermixed with the timer setup code. As THRE test must be performed prior to the timer setup, extract it into own function and call it only after the THRE test.
---
v3:
- Improved the commit with Lennert's superior descriptions.
- Added Andy's Rev-by
drivers/tty/serial/8250/8250.h | 2 ++ drivers/tty/serial/8250/8250_core.c | 16 +++++++++++----- drivers/tty/serial/8250/8250_port.c | 8 +++++--- 3 files changed, 18 insertions(+), 8 deletions(-)
drivers/tty/serial/8250/8250.h +2 -0
@@ -403,3 +403,5 @@ static inline int serial_index(struct uart_port *port) {return port->minor -64 ; } + +void univ8250_setup_timer (struct uart_8250_port *up);
drivers/tty/serial/8250/8250_core.c +11 -5
@@ -298,10 +298,9 @@ static void serial8250_backup_timeout(struct timer_list *t) jiffies + uart_poll_timeout(&up->port) + HZ / 5); } -static int univ8250_setup_irq (struct uart_8250_port *up) +void univ8250_setup_timer (struct uart_8250_port *up) {struct uart_port *port = &up->port; -int retval =0 ;/* * The above check will only give an accurate result the first time
@@ -322,10 +321,17 @@ static int univ8250_setup_irq(struct uart_8250_port *up)*/ if (!port->irq)mod_timer (&up->timer, jiffies +uart_poll_timeout (port)); -else - retval =serial_link_irq_chain (up); +} +EXPORT_SYMBOL_GPL (univ8250_setup_timer); -return retval; +static int univ8250_setup_irq (struct uart_8250_port *up) +{ +struct uart_port *port = &up->port; + +if (port->irq) +return serial_link_irq_chain (up); + +return 0 ; }static void univ8250_release_irq (struct uart_8250_port *up)
drivers/tty/serial/8250/8250_port.c +5 -3
@@ -2294,6 +2294,10 @@ int serial8250_do_startup(struct uart_port *port)if (port->irq && (up->port.flags &UPF_SHARE_IRQ )) up->port.irqflags |=IRQF_SHARED ; + retval = up->ops->setup_irq (up); +if (retval) + goto out; +if (port->irq && !(up->port.flags &UPF_NO_THRE_TEST )) {unsigned char iir1;
@@ -2336,9 +2340,7 @@ int serial8250_do_startup(struct uart_port *port) } } - retval = up->ops->setup_irq (up); -if (retval) - goto out; +univ8250_setup_timer (up);/* * Now, initialize the UART
Signature · 1 line
2.30.2
Quoted 108 lines · Ilpo Järvinen
Invoking TIOCVHANGUP on 8250_mid port on Ice Lake-D and then reopening the port triggers these faults during
serial8250_do_startup():DMAR: DRHD: handling fault status reg 3
DMAR: [DMA WriteNO_PASID] Request device [00:1a.0] fault addr0x0[fault reason0x05] PTE Write access is not setIf the IRQ hasn't been set up yet, the UART will have zeroes in its MSI address/data registers. Disabling the IRQ at the interrupt controller won't stop the UART from performing a DMA write to the address programmed in its MSI address register (zero) when it wants to signal an interrupt.
The UARTs (in Ice Lake-D) implement PCI 2.1 style MSI without masking capability, so there is no way to mask the interrupt at the source PCI function level, except disabling the MSI capability entirely, but that would cause it to fall back to INTx# assertion, and the PCI specification prohibits disabling the MSI capability as a way to mask a function's interrupt service request.
The MSI address register is zeroed during by the hangup as the irq is freed. The interrupt is signalled during
serial8250_do_startup()performing a THRE test that temporarily toggles THRI in IER. The THRE test currently occurs before UART's irq (and MSI address) is properly set up.Refactor
serial8250_do_startup()such that irq is set up before the THRE test. The current irq setup code is intermixed with the timer setup code. As THRE test must be performed prior to the timer setup, extract it into own function and call it only after the THRE test.Reported-by Lennert Buytenhek <[email protected]>Tested-by Lennert Buytenhek <[email protected]>Fixes 40b36daad0ac ("[PATCH] 8250 UART backup timer")Reviewed-by Andy Shevchenko <[email protected]>Signed-off-by Ilpo Järvinen <[email protected]>---
v3:
- Improved the commit with Lennert's superior descriptions.
- Added Andy's Rev-bydrivers/tty/serial/8250/8250.h | 2 ++ drivers/tty/serial/8250/8250_core.c | 16 +++++++++++----- drivers/tty/serial/8250/8250_port.c | 8 +++++--- 3 files changed, 18 insertions(+), 8 deletions(-)drivers/tty/serial/8250/8250.h +2
-0@@ -403,3 +403,5 @@ static inline int serial_index(struct uart_port *port) {return port->minor -64 ; } + +void univ8250_setup_timer (struct uart_8250_port *up);drivers/tty/serial/8250/8250_core.c +11
-5@@ -298,10 +298,9 @@ static void serial8250_backup_timeout(struct timer_list *t) jiffies + uart_poll_timeout(&up->port) + HZ / 5); } -static int univ8250_setup_irq (struct uart_8250_port *up) +void univ8250_setup_timer (struct uart_8250_port *up) {struct uart_port *port = &up->port; -int retval =0 ;/* * The above check will only give an accurate result the first time @@ -322,10 +321,17 @@ static int univ8250_setup_irq(struct uart_8250_port *up)*/ if (!port->irq)mod_timer (&up->timer, jiffies +uart_poll_timeout (port)); -else - retval =serial_link_irq_chain (up); +} +EXPORT_SYMBOL_GPL (univ8250_setup_timer); -return retval; +static int univ8250_setup_irq (struct uart_8250_port *up) +{ +struct uart_port *port = &up->port; + +if (port->irq) +return serial_link_irq_chain (up); + +return 0 ; }static void univ8250_release_irq (struct uart_8250_port *up)drivers/tty/serial/8250/8250_port.c +4
-0@@ -2294,6 +2294,10 @@ int serial8250_do_startup(struct uart_port *port)if (port->irq && (up->port.flags &UPF_SHARE_IRQ )) up->port.irqflags |=IRQF_SHARED ; + retval = up->ops->setup_irq (up); +if (retval) + goto out; +if (port->irq && !(up->port.flags &UPF_NO_THRE_TEST )) {unsigned char iir1;
drivers/tty/serial/8250/8250_port.c int serial8250_do_startup(struct uart_port *port) · line 2346
Quoted 10 lines
drivers/tty/serial/8250/8250_port.c +1
-3@@ -2336,9 +2340,7 @@ int serial8250_do_startup(struct uart_port *port) } } - retval = up->ops->setup_irq (up); -if (retval) - goto out; +univ8250_setup_timer (up);/* * Now, initialize the UART
Hi Greg,
Please scratch this patch. It seems to create a circular dependency issue with allmodconfig. I'll send v4 once the problem is sorted out.
Signature · 1 line
i.
Quoted 1 line · Ilpo Järvinen
On Mon, 19 Sep 2022, Ilpo Järvinen wrote:
...
Quoted 7 lines
drivers/tty/serial/8250/8250_port.c int serial8250_do_startup(struct uart_port *port) · line 2343
Quoted 4 lines
drivers/tty/serial/8250/8250_port.c +1
-3- retval = up->ops->setup_irq (up); -if (retval) - goto out; +univ8250_setup_timer (up);Please scratch this patch. It seems to create a circular dependency issue with allmodconfig. I'll send v4 once the problem is sorted out.
In accordance with what you told me privately, I think you will need yet another ops, i.e. ->setup_timer().
Signature · 2 lines
With Best Regards, Andy Shevchenko