Skip to contentSkip to conversation

Patch "irqchip/sifive-plic: Cache the interrupt enable state" has been added to the 6.18-stable tree

PATCH New Charles Mirabile 2 participants 4 messages Nov 17 – Nov 19 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Hi All—

Quoted 8 lines · Sasha Levin

This is a note to let you know that I've just added the patch titled

irqchip/sifive-plic: Cache the interrupt enable state

to the 6.18-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

Quoted 6 lines

The filename of the patch is:
irqchip-sifive-plic-cache-the-interrupt-enable-state.patch
and it can be found in the queue-6.18 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

This patch makes substantial changes to the driver and how it processes interrupts. I am not sure it is a great candidate for stable.

Quoted 23 lines

commit 036776c9c1002f36de16fa9e17e5fafccd095864

Author: Charles Mirabile <[email protected]>
Date:   Fri Oct 24 09:36:42 2025 +0100

irqchip/sifive-plic: Cache the interrupt enable state

[ Upstream commit 14ff9e54dd14339776afff78e2d29e0edb3a4402 ]

Optimize the PLIC driver by maintaining the interrupt enable state in the handler's enable_save array during normal operation rather than only during suspend/resume. This eliminates the need to read enable registers during suspend and makes the enable state immediately available for other purposes.

Let __plic_toggle() update both the hardware registers and the cached enable_save state atomically within the existing enable_lock protection.

That allows to remove the suspend-time enable register reading since handler::enable_save now always reflects the current state.

Quoted 7 lines

[ tglx: Massaged change log ]

Stable-dep-of: 0f214e5bbee5 ("irqchip/sifive-plic: Avoid signed shift in interrupt enable mask")

Especially if we are just trying to backport this commit...

Consider the following version of 0f214e5bbee5 ("irqchip/sifive-plic:
Avoid signed shift in interrupt enable mask")

(quoted diff) +0 -0

b/drivers/irqchip/irq-sifive-plic.c
index ca70641982ed6..0995e1fdd5b47 100644

drivers/irqchip/irq-sifive-plic.c +0 -0
@@ -97,7 +97,7 @@ static int plic_irq_set_type(struct irq_data *d,

unsigned int type);
static void __plic_toggle(void __iomem *enable_base, int hwirq, int enable) {
u32 __iomem *reg = enable_base + (hwirq / 32) * sizeof(u32);
- u32 hwirq_mask = 1 << (hwirq % 32);
+ u32 hwirq_mask = BIT(hwirq % 32);

  if (enable)
  writel(readl(reg) | hwirq_mask, reg);

that applies on 6.18.64. Forgive that this is not a proper patch for git am, I am not at a system with git-send-email set up.

Quoted 68 lines
drivers/irqchip/irq-sifive-plic.c +13 -16
index ca70641982ed6..2056a4d45656a 100644
@@ -94,15 +94,22 @@ static DEFINE_PER_CPU(struct plic_handler, plic_handlers);
 
 static int plic_irq_set_type(struct irq_data *d, unsigned int type);
 
-static void __plic_toggle(void __iomem *enable_base, int hwirq, int enable)
+static void __plic_toggle(struct plic_handler *handler, int hwirq, int enable)
 {
-       u32 __iomem *reg = enable_base + (hwirq / 32) * sizeof(u32);
+       u32 __iomem *base = handler->enable_base;
        u32 hwirq_mask = 1 << (hwirq % 32);
+       int group = hwirq / 32;
+       u32 value;
+
+       value = readl(base + group);
 
        if (enable)
-               writel(readl(reg) | hwirq_mask, reg);
+               value |= hwirq_mask;
        else
-               writel(readl(reg) & ~hwirq_mask, reg);
+               value &= ~hwirq_mask;
+
+       handler->enable_save[group] = value;
+       writel(value, base + group);
 }
 
 static void plic_toggle(struct plic_handler *handler, int hwirq, int enable)
@@ -110,7 +117,7 @@ static void plic_toggle(struct plic_handler *handler, int hwirq, int enable)
        unsigned long flags;
 
        raw_spin_lock_irqsave(&handler->enable_lock, flags);
-       __plic_toggle(handler->enable_base, hwirq, enable);
+       __plic_toggle(handler, hwirq, enable);
        raw_spin_unlock_irqrestore(&handler->enable_lock, flags);
 }
 
@@ -252,33 +259,16 @@ static int plic_irq_set_type(struct irq_data *d, unsigned int type)
 
 static int plic_irq_suspend(void *data)
 {
-       unsigned int i, cpu;
-       unsigned long flags;
-       u32 __iomem *reg;
        struct plic_priv *priv;
 
        priv = per_cpu_ptr(&plic_handlers, smp_processor_id())->priv;
 
        /* irq ID 0 is reserved */
-       for (i = 1; i < priv->nr_irqs; i++) {
+       for (unsigned int i = 1; i < priv->nr_irqs; i++) {
                __assign_bit(i, priv->prio_save,
                             readl(priv->regs + PRIORITY_BASE + i * PRIORITY_PER_ID));
        }
 
-       for_each_present_cpu(cpu) {
-               struct plic_handler *handler = per_cpu_ptr(&plic_handlers, cpu);
-
-               if (!handler->present)
-                       continue;
-
-               raw_spin_lock_irqsave(&handler->enable_lock, flags);

drivers/irqchip/irq-sifive-plic.c static int plic_irq_set_type(struct irq_data *d, unsigned int type) · line 274

Quoted 10 lines
drivers/irqchip/irq-sifive-plic.c +0 -7
-               for (i = 0; i < DIV_ROUND_UP(priv->nr_irqs, 32); i++) {
-                       reg = handler->enable_base + i * sizeof(u32);
-                       handler->enable_save[i] = readl(reg);
-               }
-               raw_spin_unlock_irqrestore(&handler->enable_lock, flags);
-       }
-
        return 0;
 }
 

Best—Charlie

maintainer
#2 lore raw
Quoted 3 lines

This patch makes substantial changes to the driver and how it processes interrupts. I am not sure it is a great candidate for stable.

Agreed. I dropped it, and the BIT() fix that needed it, from the 6.18, 6.12, 6.6 and 6.1 queues. The same applies to your notices for the other three trees.

Could you send git-am-able BIT()-only backports of 0f214e5bbee5 ("irqchip/sifive-plic: Avoid signed shift in interrupt enable mask"), one per tree ([PATCH 6.18.y] through [PATCH 6.1.y])? I'll queue them. 7.3 already has the cache patch in its base release, so it keeps the original fix.

Signature · 2 lines
Thanks,
Sasha
#3 lore raw

PATCH 1/1 irqchip/sifive-plic: Avoid signed shift in interrupt enable mask

Hi—

Quoted 11 lines · Sasha Levin
Quoted 3 lines

This patch makes substantial changes to the driver and how it processes interrupts. I am not sure it is a great candidate for stable.

Agreed. I dropped it, and the BIT() fix that needed it, from the 6.18, 6.12, 6.6 and 6.1 queues. The same applies to your notices for the other three trees.

Could you send git-am-able BIT()-only backports of 0f214e5bbee5 ("irqchip/sifive-plic: Avoid signed shift in interrupt enable mask"), one per tree ([PATCH 6.18.y] through [PATCH 6.1.y])? I'll queue them. 7.3 already has the cache patch in its base release, so it keeps the original fix.

The following (below the scissors) can be am'd on top of all of the trees. I am not sure exactly what format is desirable for a stable commit, but I did add the upstream commit hash and my SoB.

Quoted 4 lines
Signature · 3 lines
-- 
Thanks,
Sasha

Best—Charlie

-- >8 --
commit 9ebdbab003ec949b3739f548f527c18b811d6568
Author: Pengpeng Hou <[email protected]>
Date: Sun, 20 Sep 2026 21:06:53 +0800

[Upstream commit 0f214e5bbee59d5952d3c061fd65ed9a1e175981]

__plic_toggle() builds a 32-bit interrupt enable mask using a signed integer literal. A valid interrupt selecting bit 31 evaluates 1 << 31, which shifts a signed int into its sign bit.

Use BIT(), matching the equivalent mask construction in plic_irq_eoi(). The resulting mask remains representable in u32 on both RV32 and RV64.

The issue was found by our static-analysis tool.

Fixes 8237f8bc4f6e ("irqchip: add a SiFive PLIC driver")
Assisted-by gpt 5
---
 drivers/irqchip/irq-sifive-plic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-sifive-plic.c +1 -1
index ca70641982ed6..0995e1fdd5b47 100644
@@ -97,7 +97,7 @@ static int plic_irq_set_type(struct irq_data *d, unsigned int type);
 static void __plic_toggle(void __iomem *enable_base, int hwirq, int enable)
 {
 	u32 __iomem *reg = enable_base + (hwirq / 32) * sizeof(u32);
-	u32 hwirq_mask = 1 << (hwirq % 32);
+	u32 hwirq_mask = BIT(hwirq % 32);
 
 	if (enable)
 		writel(readl(reg) | hwirq_mask, reg);
Signature · 1 line
2.56.0
maintainer Applied
#4 lore raw
In reply to Charles Mirabile
Quoted 3 lines

Hi All—

On Tue, Nov 17, 2026 at 11:28 AM Sasha Levin <[email protected]> wrote:

Queued the BIT() fix for 6.18, 6.12, 6.6 and 6.1, thanks. On 6.1 I used the one-line BIT() form from your 6.1 mail.

Signature · 2 lines
Thanks,
Sasha