Skip to contentSkip to conversation

irqchip/sifive-plic: Respect mask state when setting affinity

PATCH Superseded Inochi Amaoto 2 participants 6 messages Aug 7, 2025 – Aug 8, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 irqchip/sifive-plic: Respect mask state when setting affinity

The plic_set_affinity always call plic_irq_enable(), which clears up the priority setting even the irq is only masked. This make the irq unmasked unexpectly.

Replace the plic_irq_enable/disable() with plic_irq_toggle() to avoid changing priority setting.

---
 drivers/irqchip/irq-sifive-plic.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/irqchip/irq-sifive-plic.c +5 -2
index bf69a4802b71..5bf5050996da 100644
@@ -148,6 +148,7 @@ static void plic_irq_enable(struct irq_data *d)
 
 static void plic_irq_disable(struct irq_data *d)
 {
+	plic_irq_mask(d);
 	plic_irq_toggle(irq_data_get_effective_affinity_mask(d), d, 0);
 }
 
@@ -179,12 +180,14 @@ static int plic_set_affinity(struct irq_data *d,
 	if (cpu >= nr_cpu_ids)
 		return -EINVAL;
 
-	plic_irq_disable(d);
+	/* Invalidate the original routing entry */
+	plic_irq_toggle(irq_data_get_effective_affinity_mask(d), d, 0);
 
 	irq_data_update_effective_affinity(d, cpumask_of(cpu));
 
+	/* Setting the new routing entry if irq is enabled */
 	if (!irqd_irq_disabled(d))
-		plic_irq_enable(d);
+		plic_irq_toggle(irq_data_get_effective_affinity_mask(d), d, 1);
 
 	return IRQ_SET_MASK_OK_DONE;
 }
Signature · 1 line
2.50.1
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 18 lines · Inochi Amaoto

The plic_set_affinity always call plic_irq_enable(), which clears up the priority setting even the irq is only masked. This make the irq unmasked unexpectly.

Replace the plic_irq_enable/disable() with plic_irq_toggle() to avoid changing priority setting.

---
 drivers/irqchip/irq-sifive-plic.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/irqchip/irq-sifive-plic.c +0 -0
index bf69a4802b71..5bf5050996da 100644

drivers/irqchip/irq-sifive-plic.c static void plic_irq_enable(struct irq_data *d) · line 153

Quoted 6 lines
drivers/irqchip/irq-sifive-plic.c +1 -0
@@ -148,6 +148,7 @@ static void plic_irq_enable(struct irq_data *d)
 
 static void plic_irq_disable(struct irq_data *d)
 {
+	plic_irq_mask(d);
 	plic_irq_toggle(irq_data_get_effective_affinity_mask(d), d, 0);
 }

This part is not required for the problem you are addressing, right?

I do not oppose the change, I'm just curious if I miss something here.

Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +2 -1
@@ -179,12 +180,14 @@ static int plic_set_affinity(struct irq_data *d,
 	if (cpu >= nr_cpu_ids)
 		return -EINVAL;
 
-	plic_irq_disable(d);
+	/* Invalidate the original routing entry */
+	plic_irq_toggle(irq_data_get_effective_affinity_mask(d), d, 0);

drivers/irqchip/irq-sifive-plic.c static int plic_set_affinity(struct irq_data *d, · line 193

Quoted 10 lines
drivers/irqchip/irq-sifive-plic.c +2 -1
 
 	irq_data_update_effective_affinity(d, cpumask_of(cpu));
 
+	/* Setting the new routing entry if irq is enabled */
 	if (!irqd_irq_disabled(d))
-		plic_irq_enable(d);
+		plic_irq_toggle(irq_data_get_effective_affinity_mask(d), d, 1);
 
 	return IRQ_SET_MASK_OK_DONE;
 }

This part makes sense:

#2 lore raw
Quoted 29 lines · Nam Cao
Quoted 18 lines · Inochi Amaoto

The plic_set_affinity always call plic_irq_enable(), which clears up the priority setting even the irq is only masked. This make the irq unmasked unexpectly.

Replace the plic_irq_enable/disable() with plic_irq_toggle() to avoid changing priority setting.

---
 drivers/irqchip/irq-sifive-plic.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/irqchip/irq-sifive-plic.c +0 -0
index bf69a4802b71..5bf5050996da 100644

drivers/irqchip/irq-sifive-plic.c static void plic_irq_enable(struct irq_data *d) · line 153

Quoted 6 lines
drivers/irqchip/irq-sifive-plic.c +1 -0
@@ -148,6 +148,7 @@ static void plic_irq_enable(struct irq_data *d)
 
 static void plic_irq_disable(struct irq_data *d)
 {
+	plic_irq_mask(d);
 	plic_irq_toggle(irq_data_get_effective_affinity_mask(d), d, 0);
 }

This part is not required for the problem you are addressing, right?

Quoted 2 lines

I do not oppose the change, I'm just curious if I miss something here.

It is true, this is added because it is needed to follow the disable required of the irqchip. I think it is better to split to a separate one.

Quoted 23 lines
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +2 -1
@@ -179,12 +180,14 @@ static int plic_set_affinity(struct irq_data *d,
 	if (cpu >= nr_cpu_ids)
 		return -EINVAL;
 
-	plic_irq_disable(d);
+	/* Invalidate the original routing entry */
+	plic_irq_toggle(irq_data_get_effective_affinity_mask(d), d, 0);

drivers/irqchip/irq-sifive-plic.c static int plic_set_affinity(struct irq_data *d, · line 193

Quoted 10 lines
drivers/irqchip/irq-sifive-plic.c +2 -1
 
 	irq_data_update_effective_affinity(d, cpumask_of(cpu));
 
+	/* Setting the new routing entry if irq is enabled */
 	if (!irqd_irq_disabled(d))
-		plic_irq_enable(d);
+		plic_irq_toggle(irq_data_get_effective_affinity_mask(d), d, 1);
 
 	return IRQ_SET_MASK_OK_DONE;
 }

This part makes sense:

#3 lore raw
Quoted 30 lines · Inochi Amaoto
Quoted 29 lines · Nam Cao
Quoted 18 lines · Inochi Amaoto

The plic_set_affinity always call plic_irq_enable(), which clears up the priority setting even the irq is only masked. This make the irq unmasked unexpectly.

Replace the plic_irq_enable/disable() with plic_irq_toggle() to avoid changing priority setting.

---
 drivers/irqchip/irq-sifive-plic.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/irqchip/irq-sifive-plic.c +0 -0
index bf69a4802b71..5bf5050996da 100644

drivers/irqchip/irq-sifive-plic.c static void plic_irq_enable(struct irq_data *d) · line 153

Quoted 6 lines
drivers/irqchip/irq-sifive-plic.c +1 -0
@@ -148,6 +148,7 @@ static void plic_irq_enable(struct irq_data *d)
 
 static void plic_irq_disable(struct irq_data *d)
 {
+	plic_irq_mask(d);
 	plic_irq_toggle(irq_data_get_effective_affinity_mask(d), d, 0);
 }

This part is not required for the problem you are addressing, right?

Quoted 7 lines
Quoted 2 lines

I do not oppose the change, I'm just curious if I miss something here.

It is true, this is added because it is needed to follow the disable required of the irqchip. I think it is better to split to a separate one.

After some dig in, I found it is not very necessary to add this, When all enable bit is clear, the PRIORIT register of irq is not functional, so only umask the irq does not make sense. Only calling irq_enable does enable the irq.

I prefer to add a comment to describe this behavior, instead of adding this change in a separate patch.

Regards,
Inochi

#4 lore raw
Quoted 5 lines · Inochi Amaoto

On Fri, Aug 08, 2025 at 06:01:39AM +0800, Inochi Amaoto wrote:
After some dig in, I found it is not very necessary to add this, When all enable bit is clear, the PRIORIT register of irq is not functional, so only umask the irq does not make sense. Only calling irq_enable does enable the irq.

Yeah, I contemplated doing this myself when I added the unmask to plic_irq_enable(), because it looks more natural that plic_irq_enable() and plic_irq_disable() are opposite. But I don't think it is necessary.

Quoted 2 lines

I prefer to add a comment to describe this behavior, instead of adding this change in a separate patch.

No preference from me.

Nam

#5 lore raw
Quoted 8 lines · Nam Cao
Quoted 5 lines · Inochi Amaoto

On Fri, Aug 08, 2025 at 06:01:39AM +0800, Inochi Amaoto wrote:
After some dig in, I found it is not very necessary to add this, When all enable bit is clear, the PRIORIT register of irq is not functional, so only umask the irq does not make sense. Only calling irq_enable does enable the irq.

Quoted 9 lines

Yeah, I contemplated doing this myself when I added the unmask to plic_irq_enable(), because it looks more natural that plic_irq_enable() and plic_irq_disable() are opposite. But I don't think it is necessary.

Quoted 2 lines

I prefer to add a comment to describe this behavior, instead of adding this change in a separate patch.

No preference from me.

OK, I will just remove this mask function.

Regards,
Inochi