Skip to contentSkip to conversation

xen/drivers/char: fix IRQ registration failure propagation

PATCH Superseded Oleksii Moisieiev 3 participants 9 messages Apr 9 – Apr 14 Arm Samsung Exynos

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover xen/drivers/char: fix IRQ registration failure propagation

This series fixes a common bug pattern found in several Xen UART drivers:
when setup_irq() fails during post-IRQ initialization, drivers log the error but continue executing and unconditionally unmask hardware interrupt lines with no handler registered. On platforms where the GIC receives these asserted lines, the result is either repeated spurious-interrupt warnings or an unhandled interrupt fault.

Patch 1, originally submitted as a standalone fix in v1, addresses the issue in the SCIF driver and moves the hardware error-flag clearing sequence to before the setup_irq() call so that stale error bits are cleared unconditionally. Patches 2-4 apply the same early-return fix to the pl011, cadence-uart, and exynos4210-uart drivers.

The pl011 and cadence-uart drivers additionally had a positive-condition IRQ guard (if uart->irq > 0) that could fall through to the interrupt unmask even when no valid IRQ was provided. Both are restructured to use the early-return idiom.

Changes in v2:
- Extend fix to pl011, cadence-uart and exynos4210
- fix typo in patch 1 description

Oleksii Moisieiev (4):
xen/drivers/char: fix SCIF IRQ registration failure propagation xen/drivers/char/pl011: fix IRQ registration failure propagation xen/drivers/char/cadence-uart: fix IRQ registration failure
propagation
xen/drivers/char: fix exynos4210 IRQ registration failure propagation

 xen/drivers/char/cadence-uart.c    | 17 +++++++++++------
 xen/drivers/char/exynos4210-uart.c |  4 ++++
 xen/drivers/char/pl011.c           | 17 +++++++++++------
 xen/drivers/char/scif-uart.c       | 16 ++++++++++++----
 4 files changed, 38 insertions(+), 16 deletions(-)
Signature · 4 lines
2.43.0

base-commit: 2ca756d39f59f834160263fd142ef91c6ca3dd90
branch: amoi_dfmea_scif
#5 lore raw

PATCH v2 3/4 xen/drivers/char/cadence-uart: fix IRQ registration failure propagation

In cuart_init_postirq(), two code paths could reach the interrupt-enable write to IER without a handler being registered:

- When no valid IRQ number was provided (uart->irq <= 0), the original positive-condition guard (if uart->irq > 0) skipped the irqaction setup but still fell through to the IER write, enabling the receive data interrupt with no handler installed.

- When setup_irq() returned an error, only an error message was printed and execution continued to the IER write, arming the receive hardware interrupt line with no handler to service it. On platforms where the GIC receives this asserted line, the result is either repeated spurious-interrupt warnings or an unhandled interrupt fault.

Restructure cuart_init_postirq() to use early returns in both error paths.

---

 xen/drivers/char/cadence-uart.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
xen/drivers/char/cadence-uart.c +11 -6
index b2f379833f..a63dc4adb2 100644
@@ -72,13 +72,18 @@ static void __init cuart_init_postirq(struct serial_port *port)
     struct cuart *uart = port->uart;
     int rc;
 
-    if ( uart->irq > 0 )
+    /* Don't unmask interrupts if no valid irq was provided */
+    if ( uart->irq <= 0 )
+        return;
+
+    uart->irqaction.handler = cuart_interrupt;
+    uart->irqaction.name    = "cadence-uart";
+    uart->irqaction.dev_id  = port;
+    if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
     {
-        uart->irqaction.handler = cuart_interrupt;
-        uart->irqaction.name    = "cadence-uart";
-        uart->irqaction.dev_id  = port;
-        if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
-            printk("ERROR: Failed to allocate cadence-uart IRQ %d\n", uart->irq);
+        printk("ERROR: Failed to allocate cadence-uart IRQ %d\n", uart->irq);
+        /* Do not unmask interrupts if irq handler wasn't set */
+        return;
     }
 
     /* Clear pending error interrupts */
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/4 xen/drivers/char: fix SCIF IRQ registration failure propagation

In reply to Oleksii Moisieiev

In scif_uart_init_postirq(), when setup_irq() returns an error the failure was only logged via dprintk() and execution continued, unconditionally writing TIE|RIE|REIE into the Serial Control Register (SCSCR). This armed all three hardware interrupt lines (TX FIFO empty, RX data ready, receive error) with no handler registered to service them. On platforms where the GIC receives these asserted lines, the result is either repeated spurious-interrupt warnings or an unhandled interrupt fault.

The fix adds an early return inside the error branch. The interrupt-enable write to SCSCR is skipped entirely when no handler is registered.

SCIF TX continues to operate correctly after this change. The Xen serial framework never calls serial_async_transmit() for SCIF, so port->txbuf is always NULL. This causes __serial_putc() to take the synchronous finite-capacity path, which polls the SCFSR_TDFE hardware flag directly and does not depend on the interrupt mechanism. RX wouldn't work if irq wasn't registered.

As a secondary clean-up, the hardware error-flag clearing sequence is moved to before the setup_irq() call so that error bits accumulated since init_preirq() are cleared unconditionally, regardless of whether IRQ registration succeeds.

---

Changes in v2:
- Extend fix to pl011, cadence-uart and exynos4210
- fix typo in patch 1 description

 xen/drivers/char/scif-uart.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
xen/drivers/char/scif-uart.c +12 -4
index 888821a3b8..673a2d3800 100644
@@ -187,16 +187,24 @@ static void __init scif_uart_init_postirq(struct serial_port *port)
     uart->irqaction.name    = "scif_uart";
     uart->irqaction.dev_id  = port;
 
-    if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
-        dprintk(XENLOG_ERR, "Failed to allocated scif_uart IRQ %d\n",
-                uart->irq);
-
     /* Clear all errors */
     if ( scif_readw(uart, params->status_reg) & params->error_mask )
         scif_writew(uart, params->status_reg, ~params->error_mask);
     if ( scif_readw(uart, params->overrun_reg) & params->overrun_mask )
         scif_writew(uart, params->overrun_reg, ~params->overrun_mask);
 
+    if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
+    {
+        dprintk(XENLOG_ERR, "Failed to allocated scif_uart IRQ %d\n",
+                uart->irq);
+        /*
+         * If the IRQ handler could not be installed (setup_irq failed),
+         * do not enable TX/RX or error interrupts. Serial transmit will
+         * fall back to polling mode.
+         */
+        return;
+    }
+
     /* Enable TX/RX and Error Interrupts  */
     scif_writew(uart, SCIF_SCSCR, scif_readw(uart, SCIF_SCSCR) |
                 params->irq_flags);
Signature · 1 line
2.43.0
#3 lore raw

PATCH v2 2/4 xen/drivers/char/pl011: fix IRQ registration failure propagation

In reply to Oleksii Moisieiev

In pl011_init_postirq(), two code paths could reach the interrupt-unmask write to IMSC without a handler being registered:

- When no valid IRQ number was provided (uart->irq <= 0), the original positive-condition guard (if uart->irq > 0) skipped the irqaction setup but still fell through to the IMSC write, unmasking RTI|OEI|BEI|PEI|FEI|TXI|RXI with no handler installed.

- When setup_irq() returned an error, only an error message was printed and execution continued to the IMSC write, arming all hardware interrupt lines with no handler to service them. On platforms where the GIC receives these asserted lines, the result is either repeated spurious-interrupt warnings or an unhandled interrupt fault.

Restructure pl011_init_postirq() to use early returns: return immediately when no valid IRQ is provided, and return after logging the error when setup_irq() fails. The interrupt-enable write to IMSC is only reached when IRQ registration succeeds.

---

 xen/drivers/char/pl011.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
xen/drivers/char/pl011.c +11 -6
index 5f9913367d..918b9d4d4a 100644
@@ -150,13 +150,18 @@ static void __init pl011_init_postirq(struct serial_port *port)
     struct pl011 *uart = port->uart;
     int rc;
 
-    if ( uart->irq > 0 )
+    /* Don't unmask interrupts if no valid irq was provided */
+    if ( uart->irq <= 0 )
+        return;
+
+    uart->irqaction.handler = pl011_interrupt;
+    uart->irqaction.name    = "pl011";
+    uart->irqaction.dev_id  = port;
+    if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
     {
-        uart->irqaction.handler = pl011_interrupt;
-        uart->irqaction.name    = "pl011";
-        uart->irqaction.dev_id  = port;
-        if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
-            printk("ERROR: Failed to allocate pl011 IRQ %d\n", uart->irq);
+        printk("ERROR: Failed to allocate pl011 IRQ %d\n", uart->irq);
+        /* Do not unmask interrupts if irq handler wasn't set */
+        return;
     }
 
     /* Clear pending error interrupts */
Signature · 1 line
2.43.0
#7 lore raw

PATCH v2 4/4 xen/drivers/char: fix exynos4210 IRQ registration failure propagation

In reply to Oleksii Moisieiev

In exynos4210_uart_init_postirq(), when setup_irq() returns an error the failure was only logged via dprintk() and execution continued, unconditionally clearing UINTM and setting UMCON_INT_EN. This enabled receive and transmit interrupt lines with no handler registered. On platforms where the GIC receives these asserted lines, the result is either repeated spurious-interrupt warnings or an unhandled interrupt fault.

Add an early return in the setup_irq() error branch so that the interrupt-enable writes to UINTM and UMCON are skipped when IRQ registration fails.

---

 xen/drivers/char/exynos4210-uart.c | 4 ++++
 1 file changed, 4 insertions(+)
xen/drivers/char/exynos4210-uart.c +4 -0
index 58901df554..2e5860ea2b 100644
@@ -199,8 +199,12 @@ static void __init exynos4210_uart_init_postirq(struct serial_port *port)
     uart->irqaction.dev_id  = port;
 
     if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
+    {
         dprintk(XENLOG_ERR, "Failed to allocated exynos4210_uart IRQ %d\n",
                 uart->irq);
+        /* Don't enable interrupts if irq setup was failed */
+        return;
+    }
 
     /* Unmask interrupts */
     exynos4210_write(uart, UINTM, ~UINTM_ALLI);
Signature · 1 line
2.43.0
Reviewed-by on v2 1/4
#2 lore raw

Re: [PATCH v2 1/4] xen/drivers/char: fix SCIF IRQ registration failure propagation

In reply to Oleksii Moisieiev
Quoted 20 lines · Oleksii Moisieiev

In scif_uart_init_postirq(), when setup_irq() returns an error the failure was only logged via dprintk() and execution continued, unconditionally writing TIE|RIE|REIE into the Serial Control Register (SCSCR). This armed all three hardware interrupt lines (TX FIFO empty, RX data ready, receive error) with no handler registered to service them. On platforms where the GIC receives these asserted lines, the result is either repeated spurious-interrupt warnings or an unhandled interrupt fault.

The fix adds an early return inside the error branch. The interrupt-enable write to SCSCR is skipped entirely when no handler is registered.

SCIF TX continues to operate correctly after this change. The Xen serial framework never calls serial_async_transmit() for SCIF, so port->txbuf is always NULL. This causes __serial_putc() to take the synchronous finite-capacity path, which polls the SCFSR_TDFE hardware flag directly and does not depend on the interrupt mechanism. RX wouldn't work if irq wasn't registered.

Quoted 6 lines

As a secondary clean-up, the hardware error-flag clearing sequence is moved to before the setup_irq() call so that error bits accumulated since init_preirq() are cleared unconditionally, regardless of whether IRQ registration succeeds.

~Michal

Reviewed-by on v2 4/4
#8 lore raw

Re: [PATCH v2 4/4] xen/drivers/char: fix exynos4210 IRQ registration failure propagation

In reply to Oleksii Moisieiev
Quoted 8 lines · Oleksii Moisieiev

In exynos4210_uart_init_postirq(), when setup_irq() returns an error the failure was only logged via dprintk() and execution continued, unconditionally clearing UINTM and setting UMCON_INT_EN. This enabled receive and transmit interrupt lines with no handler registered. On platforms where the GIC receives these asserted lines, the result is either repeated spurious-interrupt warnings or an unhandled interrupt fault.

Quoted 5 lines

Add an early return in the setup_irq() error branch so that the interrupt-enable writes to UINTM and UMCON are skipped when IRQ registration fails.

~Michal

Reviewed-by on v2 2/4
#4 lore raw

Re: [PATCH v2 2/4] xen/drivers/char/pl011: fix IRQ registration failure propagation

In reply to Oleksii Moisieiev
Quoted 47 lines · Oleksii Moisieiev

In pl011_init_postirq(), two code paths could reach the interrupt-unmask write to IMSC without a handler being registered:

- When no valid IRQ number was provided (uart->irq <= 0), the original positive-condition guard (if uart->irq > 0) skipped the irqaction setup but still fell through to the IMSC write, unmasking RTI|OEI|BEI|PEI|FEI|TXI|RXI with no handler installed.

- When setup_irq() returned an error, only an error message was printed and execution continued to the IMSC write, arming all hardware interrupt lines with no handler to service them. On platforms where the GIC receives these asserted lines, the result is either repeated spurious-interrupt warnings or an unhandled interrupt fault.

Restructure pl011_init_postirq() to use early returns: return immediately when no valid IRQ is provided, and return after logging the error when setup_irq() fails. The interrupt-enable write to IMSC is only reached when IRQ registration succeeds.

---

 xen/drivers/char/pl011.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
xen/drivers/char/pl011.c +8 -2
index 5f9913367d..918b9d4d4a 100644
@@ -150,13 +150,18 @@ static void __init pl011_init_postirq(struct serial_port *port)
     struct pl011 *uart = port->uart;
     int rc;
 
-    if ( uart->irq > 0 )
+    /* Don't unmask interrupts if no valid irq was provided */
+    if ( uart->irq <= 0 )
+        return;
+
+    uart->irqaction.handler = pl011_interrupt;
+    uart->irqaction.name    = "pl011";
+    uart->irqaction.dev_id  = port;
+    if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
     {
-        uart->irqaction.handler = pl011_interrupt;

xen/drivers/char/pl011.c static void __init pl011_init_postirq(struct serial_port *port) · line 167

Quoted 10 lines
xen/drivers/char/pl011.c +3 -4
-        uart->irqaction.name    = "pl011";
-        uart->irqaction.dev_id  = port;
-        if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
-            printk("ERROR: Failed to allocate pl011 IRQ %d\n", uart->irq);
+        printk("ERROR: Failed to allocate pl011 IRQ %d\n", uart->irq);
+        /* Do not unmask interrupts if irq handler wasn't set */
+        return;
     }
 
     /* Clear pending error interrupts */

I think we should clear pending errors every time. Other than that, the patch is ok. Provided the remark is addressed:

~Michal

#6 lore raw

Re: [PATCH v2 3/4] xen/drivers/char/cadence-uart: fix IRQ registration failure propagation

In reply to Oleksii Moisieiev

On 4/9/26 16:50, Oleksii Moisieiev wrote:

Hello Oleksii

Quoted 31 lines

In cuart_init_postirq(), two code paths could reach the interrupt-enable write to IER without a handler being registered:

- When no valid IRQ number was provided (uart->irq <= 0), the original positive-condition guard (if uart->irq > 0) skipped the irqaction setup but still fell through to the IER write, enabling the receive data interrupt with no handler installed.

- When setup_irq() returned an error, only an error message was printed and execution continued to the IER write, arming the receive hardware interrupt line with no handler to service it. On platforms where the GIC receives this asserted line, the result is either repeated spurious-interrupt warnings or an unhandled interrupt fault.

Restructure cuart_init_postirq() to use early returns in both error paths.

---

  xen/drivers/char/cadence-uart.c | 17 +++++++++++------
  1 file changed, 11 insertions(+), 6 deletions(-)
xen/drivers/char/cadence-uart.c +0 -0
index b2f379833f..a63dc4adb2 100644

xen/drivers/char/cadence-uart.c static void __init cuart_init_postirq(struct serial_port *port) · line 76

Quoted 6 lines
xen/drivers/char/cadence-uart.c +2 -1
@@ -72,13 +72,18 @@ static void __init cuart_init_postirq(struct serial_port *port)
      struct cuart *uart = port->uart;
      int rc;
 
-    if ( uart->irq > 0 )
+    /* Don't unmask interrupts if no valid irq was provided */
+    if ( uart->irq <= 0 )

But irq field is defined as an unsigned int. By definition, an unsigned int can never be less than zero.

xen/drivers/char/cadence-uart.c static void __init cuart_init_postirq(struct serial_port *port) · line 84

Quoted 13 lines
xen/drivers/char/cadence-uart.c +7 -5
+        return;
+
+    uart->irqaction.handler = cuart_interrupt;
+    uart->irqaction.name    = "cadence-uart";
+    uart->irqaction.dev_id  = port;
+    if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
      {
-        uart->irqaction.handler = cuart_interrupt;
-        uart->irqaction.name    = "cadence-uart";
-        uart->irqaction.dev_id  = port;
-        if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
-            printk("ERROR: Failed to allocate cadence-uart IRQ %d\n", uart->irq);
+        printk("ERROR: Failed to allocate cadence-uart IRQ %d\n", uart->irq);

NIT: The format specifier should be %u

xen/drivers/char/cadence-uart.c static void __init cuart_init_postirq(struct serial_port *port) · line 89

Quoted 5 lines
xen/drivers/char/cadence-uart.c +2 -0
+        /* Do not unmask interrupts if irq handler wasn't set */
+        return;
      }
 
      /* Clear pending error interrupts */

I notice that with this change, the block that clears pending error interrupts is now skipped if setup_irq() fails or if no valid IRQ is provided. Is this intentional / OK? In "[PATCH v2 1/4] xen/drivers/char: fix SCIF IRQ registration failure propagation", the error status registers are always cleared, even on failure.