Skip to contentSkip to conversation

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

DISCUSSION Charles Mirabile 1 participant 1 message Nov 17 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, me again—

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.1-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

Quoted 7 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.1 subdirectory.

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

Yes, I think we should not backport this and instead accept a slight context difference in 0f214e5bbee5 ("irqchip/sifive-plic: Avoid signed shift in interrupt enable mask")

The following diff applies on v6.1.192

(quoted diff) +0 -0

b/drivers/irqchip/irq-sifive-plic.c
index fb1dae22ab17f..396fb37abf611 100644

drivers/irqchip/irq-sifive-plic.c +0 -0
@@ -89,7 +89,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);

Best—Charliediff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c
index fb1dae22ab17f..396fb37abf611 100644

drivers/irqchip/irq-sifive-plic.c +0 -0
@@ -89,7 +89,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);
Quoted 107 lines

commit 0281eadd39536ef2d99dd6ce5bbedfaac4db9ca9

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.

[ tglx: Massaged change log ]

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

drivers/irqchip/irq-sifive-plic.c +13 -23
index 1986d4a49e671..cd537d8714721 100644
@@ -90,15 +90,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)
@@ -106,7 +113,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);
 }
 
@@ -249,33 +256,16 @@ static int plic_irq_set_type(struct irq_data *d, unsigned int type)
 
 static int plic_irq_suspend(void)
 {
-       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);
-               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;
 }