Skip to contentSkip to conversation

alpha: marvel: Fix irq_set_status_flags to use correct IRQ number

PATCH In review Matt Turner 2 participants 4 messages May 28 – May 29

Subsystems (2)
lore
Share & tools
lore

Matt Turner

author maintainer
#0 lore raw

PATCH 1/2 alpha: marvel: Fix irq_set_status_flags to use correct IRQ number

Pass base + i to irq_set_status_flags() to match the IRQ number used in irq_set_chip_and_handler(). Previously, IRQ_LEVEL was set on the wrong (low-numbered) IRQ descriptors rather than the IO7 IRQs at base + i.

Fixes 08876fe8519c ("alpha: marvel: Convert irq_chip functions")
---
 arch/alpha/kernel/sys_marvel.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/alpha/kernel/sys_marvel.c +2 -2
index 1f99b03effc2..bebeea3c286d 100644
@@ -275,7 +275,7 @@ init_io7_irqs(struct io7 *io7,
 	/* Set up the lsi irqs.  */
 	for (i = 0; i < 128; ++i) {
 		irq_set_chip_and_handler(base + i, lsi_ops, handle_level_irq);
-		irq_set_status_flags(i, IRQ_LEVEL);
+		irq_set_status_flags(base + i, IRQ_LEVEL);
 	}
 
 	/* Disable the implemented irqs in hardware.  */
@@ -289,7 +289,7 @@ init_io7_irqs(struct io7 *io7,
 	/* Set up the msi irqs.  */
 	for (i = 128; i < (128 + 512); ++i) {
 		irq_set_chip_and_handler(base + i, msi_ops, handle_level_irq);
-		irq_set_status_flags(i, IRQ_LEVEL);
+		irq_set_status_flags(base + i, IRQ_LEVEL);
 	}
 
 	for (i = 0; i < 16; ++i)
Signature · 1 line
2.53.0
author maintainer
#1 lore raw

PATCH 2/2 alpha: marvel: Fix lock ordering in init_io7_irqs()

Move irq_set_chip_and_handler() and irq_set_status_flags() calls outside the io7->irq_lock raw spinlock. These functions take sparse_irq_lock, which is a mutex, and taking a sleeping lock while holding a raw spinlock is invalid. The raw spinlock only needs to protect the hardware CSR accesses.

This fixes the following lockdep splat during boot:

[ BUG: Invalid wait context ]
swapper/0/0 is trying to lock:
sparse_irq_lock{....}-{4:4}, at: irq_mark_irq
other info that might help us debug this:
context-{5:5}
1 lock held by swapper/0/0:
#0: &io7->irq_lock{....}-{2:2}, at: init_io7_irqs.constprop.0

Assisted-by Claude:claude-opus-4-6
---
 arch/alpha/kernel/sys_marvel.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
arch/alpha/kernel/sys_marvel.c +12 -13
index bebeea3c286d..a37707e05e34 100644
@@ -263,6 +263,18 @@ init_io7_irqs(struct io7 *io7,
 	 */
 	printk("  Interrupts reported to CPU at PE %u\n", boot_cpuid);
 
+	/* Set up the lsi irqs.  */
+	for (i = 0; i < 128; ++i) {
+		irq_set_chip_and_handler(base + i, lsi_ops, handle_level_irq);
+		irq_set_status_flags(base + i, IRQ_LEVEL);
+	}
+
+	/* Set up the msi irqs.  */
+	for (i = 128; i < (128 + 512); ++i) {
+		irq_set_chip_and_handler(base + i, msi_ops, handle_level_irq);
+		irq_set_status_flags(base + i, IRQ_LEVEL);
+	}
+
 	raw_spin_lock(&io7->irq_lock);
 
 	/* set up the error irqs */
@@ -272,12 +284,6 @@ init_io7_irqs(struct io7 *io7,
 	io7_redirect_irq(io7, &io7->csrs->STV_CTL.csr, boot_cpuid);
 	io7_redirect_irq(io7, &io7->csrs->HEI_CTL.csr, boot_cpuid);
 
-	/* Set up the lsi irqs.  */
-	for (i = 0; i < 128; ++i) {
-		irq_set_chip_and_handler(base + i, lsi_ops, handle_level_irq);
-		irq_set_status_flags(base + i, IRQ_LEVEL);
-	}
-
 	/* Disable the implemented irqs in hardware.  */
 	for (i = 0; i < 0x60; ++i) 
 		init_one_io7_lsi(io7, i, boot_cpuid);
@@ -285,13 +291,6 @@ init_io7_irqs(struct io7 *io7,
 	init_one_io7_lsi(io7, 0x74, boot_cpuid);
 	init_one_io7_lsi(io7, 0x75, boot_cpuid);
 
-
-	/* Set up the msi irqs.  */
-	for (i = 128; i < (128 + 512); ++i) {
-		irq_set_chip_and_handler(base + i, msi_ops, handle_level_irq);
-		irq_set_status_flags(base + i, IRQ_LEVEL);
-	}
-
 	for (i = 0; i < 16; ++i)
 		init_one_io7_msi(io7, i, boot_cpuid);
 
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] alpha: marvel: Fix lock ordering in init_io7_irqs()

Quoted 75 lines · Matt Turner

Move irq_set_chip_and_handler() and irq_set_status_flags() calls outside the io7->irq_lock raw spinlock. These functions take sparse_irq_lock, which is a mutex, and taking a sleeping lock while holding a raw spinlock is invalid. The raw spinlock only needs to protect the hardware CSR accesses.

This fixes the following lockdep splat during boot:

[ BUG: Invalid wait context ]
swapper/0/0 is trying to lock:
sparse_irq_lock{....}-{4:4}, at: irq_mark_irq
other info that might help us debug this:
context-{5:5}
1 lock held by swapper/0/0:

   #0: &io7->irq_lock{....}-{2:2}, at: init_io7_irqs.constprop.0
Assisted-by Claude:claude-opus-4-6
---
 arch/alpha/kernel/sys_marvel.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
arch/alpha/kernel/sys_marvel.c +12 -14
index bebeea3c286d..a37707e05e34 100644
@@ -263,6 +263,18 @@ init_io7_irqs(struct io7 *io7,
         */
        printk("  Interrupts reported to CPU at PE %u\n", boot_cpuid);
 
+       /* Set up the lsi irqs.  */
+       for (i = 0; i < 128; ++i) {
+               irq_set_chip_and_handler(base + i, lsi_ops, handle_level_irq);
+               irq_set_status_flags(base + i, IRQ_LEVEL);
+       }
+
+       /* Set up the msi irqs.  */
+       for (i = 128; i < (128 + 512); ++i) {
+               irq_set_chip_and_handler(base + i, msi_ops, handle_level_irq);
+               irq_set_status_flags(base + i, IRQ_LEVEL);
+       }
+
        raw_spin_lock(&io7->irq_lock);
 
        /* set up the error irqs */
@@ -272,12 +284,6 @@ init_io7_irqs(struct io7 *io7,
        io7_redirect_irq(io7, &io7->csrs->STV_CTL.csr, boot_cpuid);
        io7_redirect_irq(io7, &io7->csrs->HEI_CTL.csr, boot_cpuid);
 
-       /* Set up the lsi irqs.  */
-       for (i = 0; i < 128; ++i) {
-               irq_set_chip_and_handler(base + i, lsi_ops, handle_level_irq);
-               irq_set_status_flags(base + i, IRQ_LEVEL);
-       }
-
        /* Disable the implemented irqs in hardware.  */
        for (i = 0; i < 0x60; ++i)
                init_one_io7_lsi(io7, i, boot_cpuid);
@@ -285,13 +291,6 @@ init_io7_irqs(struct io7 *io7,
        init_one_io7_lsi(io7, 0x74, boot_cpuid);
        init_one_io7_lsi(io7, 0x75, boot_cpuid);
 
-
-       /* Set up the msi irqs.  */
-       for (i = 128; i < (128 + 512); ++i) {
-               irq_set_chip_and_handler(base + i, msi_ops, handle_level_irq);
-               irq_set_status_flags(base + i, IRQ_LEVEL);
-       }
-
        for (i = 0; i < 16; ++i)
                init_one_io7_msi(io7, i, boot_cpuid);
 
--
Quoted 2 lines

2.53.0

With the preceding irq_set_status_flags(base + i, ...) fix applied, this looks correct to me. The generic IRQ descriptor setup is moved outside io7->irq_lock, while the raw spinlock still protects the IO7 hardware CSR accesses. That matches the lockdep report and avoids taking sparse_irq_lock from raw-spinlock context.

maintainer Reviewed-by on v1 1/2
#3 lore raw
In reply to Matt Turner
Quoted 36 lines · Matt Turner

Pass base + i to irq_set_status_flags() to match the IRQ number used in irq_set_chip_and_handler(). Previously, IRQ_LEVEL was set on the wrong (low-numbered) IRQ descriptors rather than the IO7 IRQs at base + i.

Fixes 08876fe8519c ("alpha: marvel: Convert irq_chip functions")
---
 arch/alpha/kernel/sys_marvel.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/alpha/kernel/sys_marvel.c +2 -3
index 1f99b03effc2..bebeea3c286d 100644
@@ -275,7 +275,7 @@ init_io7_irqs(struct io7 *io7,
        /* Set up the lsi irqs.  */
        for (i = 0; i < 128; ++i) {
                irq_set_chip_and_handler(base + i, lsi_ops, handle_level_irq);
-               irq_set_status_flags(i, IRQ_LEVEL);
+               irq_set_status_flags(base + i, IRQ_LEVEL);
        }
 
        /* Disable the implemented irqs in hardware.  */
@@ -289,7 +289,7 @@ init_io7_irqs(struct io7 *io7,
        /* Set up the msi irqs.  */
        for (i = 128; i < (128 + 512); ++i) {
                irq_set_chip_and_handler(base + i, msi_ops, handle_level_irq);
-               irq_set_status_flags(i, IRQ_LEVEL);
+               irq_set_status_flags(base + i, IRQ_LEVEL);
        }
 
        for (i = 0; i < 16; ++i)
--
Quoted 2 lines

2.53.0

This looks correct to me. irq_set_status_flags() should use the same Linux IRQ number as irq_set_chip_and_handler(), i.e. base + i, otherwise IRQ_LEVEL is applied to the wrong low-numbered descriptors rather than the IO7 IRQs.