Skip to contentSkip to conversation

irqchip/gic-v3: Use wmb() instead of smb_wmb() in gic_raise_softirq()

PATCH In review Shanker Donthineni 5 participants 6 messages Feb 1, 2018 – Feb 18, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 irqchip/gic-v3: Use wmb() instead of smb_wmb() in gic_raise_softirq()

A DMB instruction can be used to ensure the relative order of only memory accesses before and after the barrier. Since writes to system registers are not memory operations, barrier DMB is not sufficient for observability of memory accesses that occur before ICC_SGI1R_EL1 writes.

A DSB instruction ensures that no instructions that appear in program order after the DSB instruction, can execute until the DSB instruction has completed.

---
 drivers/irqchip/irq-gic-v3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3.c +1 -1
index b56c3e2..980ae8e 100644
@@ -688,7 +688,7 @@ static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq)
 	 * Ensure that stores to Normal memory are visible to the
 	 * other CPUs before issuing the IPI.
 	 */
-	smp_wmb();
+	wmb();
 
 	for_each_cpu(cpu, mask) {
 		u64 cluster_id = MPIDR_TO_SGI_CLUSTER_ID(cpu_logical_map(cpu));
Signature · 2 lines
Qualcomm Datacenter Technologies, Inc. on behalf of the Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Acked-by on v1 1/1
#1 lore raw

Hi Shanker,

Quoted 20 lines · Shanker Donthineni

A DMB instruction can be used to ensure the relative order of only memory accesses before and after the barrier. Since writes to system registers are not memory operations, barrier DMB is not sufficient for observability of memory accesses that occur before ICC_SGI1R_EL1 writes.

A DSB instruction ensures that no instructions that appear in program order after the DSB instruction, can execute until the DSB instruction has completed.

---
 drivers/irqchip/irq-gic-v3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3.c +0 -0
index b56c3e2..980ae8e 100644

drivers/irqchip/irq-gic-v3.c static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq) · line 691

Quoted 5 lines
drivers/irqchip/irq-gic-v3.c +1 -1
@@ -688,7 +688,7 @@ static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq)
 	 * Ensure that stores to Normal memory are visible to the
 	 * other CPUs before issuing the IPI.
 	 */
-	smp_wmb();
+	wmb();

I think this is the right thing to do and the smp_wmb() was accidentally pulled in here as a copy-paste from the GICv2 driver where it is sufficient in practice.

Did you spot this by code inspection, or did the DMB actually cause observable failures? (trying to figure out whether or not this need to go to -stable).

Anyway:

Cheers,

Will

#2 lore raw

Hi Will, Thanks for your quick reply.

Quoted 33 lines · Will Deacon

Hi Shanker,

Quoted 20 lines · Shanker Donthineni

A DMB instruction can be used to ensure the relative order of only memory accesses before and after the barrier. Since writes to system registers are not memory operations, barrier DMB is not sufficient for observability of memory accesses that occur before ICC_SGI1R_EL1 writes.

A DSB instruction ensures that no instructions that appear in program order after the DSB instruction, can execute until the DSB instruction has completed.

---
 drivers/irqchip/irq-gic-v3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3.c +0 -0
index b56c3e2..980ae8e 100644

drivers/irqchip/irq-gic-v3.c static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq) · line 691

Quoted 5 lines
drivers/irqchip/irq-gic-v3.c +1 -1
@@ -688,7 +688,7 @@ static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq)
 	 * Ensure that stores to Normal memory are visible to the
 	 * other CPUs before issuing the IPI.
 	 */
-	smp_wmb();
+	wmb();

I think this is the right thing to do and the smp_wmb() was accidentally pulled in here as a copy-paste from the GICv2 driver where it is sufficient in practice.

Quoted 4 lines

Did you spot this by code inspection, or did the DMB actually cause observable failures? (trying to figure out whether or not this need to go to -stable).

We've inspected the code because kernel was causing failures in scheduler/IPI_RESCHDULE. After some time of debugging, we landed in GIC driver and found that the issue was due to the DMB barrier.

Side note, we're also missing synchronization barriers in GIC driver after writing some of the ICC_XXX system registers. I'm planning to post those changes for comments.

e.g: gic_write_sgi1r(val) and gic_write_eoir(irqnr);

Quoted 8 lines

Anyway:

Cheers,

Will

Signature · 3 lines
Shanker Donthineni
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
#3 lore raw
Quoted 36 lines · Shanker Donthineni

Hi Will, Thanks for your quick reply.

Quoted 33 lines · Will Deacon

Hi Shanker,

Quoted 20 lines · Shanker Donthineni

A DMB instruction can be used to ensure the relative order of only memory accesses before and after the barrier. Since writes to system registers are not memory operations, barrier DMB is not sufficient for observability of memory accesses that occur before ICC_SGI1R_EL1 writes.

A DSB instruction ensures that no instructions that appear in program order after the DSB instruction, can execute until the DSB instruction has completed.

---
 drivers/irqchip/irq-gic-v3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3.c +0 -0
index b56c3e2..980ae8e 100644

drivers/irqchip/irq-gic-v3.c static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq) · line 691

Quoted 5 lines
drivers/irqchip/irq-gic-v3.c +1 -1
@@ -688,7 +688,7 @@ static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq)
 	 * Ensure that stores to Normal memory are visible to the
 	 * other CPUs before issuing the IPI.
 	 */
-	smp_wmb();
+	wmb();

I think this is the right thing to do and the smp_wmb() was accidentally pulled in here as a copy-paste from the GICv2 driver where it is sufficient in practice.

Quoted 8 lines
Quoted 4 lines

Did you spot this by code inspection, or did the DMB actually cause observable failures? (trying to figure out whether or not this need to go to -stable).

We've inspected the code because kernel was causing failures in scheduler/IPI_RESCHDULE. After some time of debugging, we landed in GIC driver and found that the issue was due to the DMB barrier.

OK. I've applied this with a cc: stable and Will's Ack.

Quoted 4 lines

Side note, we're also missing synchronization barriers in GIC driver after writing some of the ICC_XXX system registers. I'm planning to post those changes for comments.

e.g: gic_write_sgi1r(val) and gic_write_eoir(irqnr);

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Tested-by
#4 lore raw
Quoted 48 lines · Marc Zyngier
Quoted 36 lines · Shanker Donthineni

Hi Will, Thanks for your quick reply.

Quoted 33 lines · Will Deacon

Hi Shanker,

Quoted 20 lines · Shanker Donthineni

A DMB instruction can be used to ensure the relative order of only memory accesses before and after the barrier. Since writes to system registers are not memory operations, barrier DMB is not sufficient for observability of memory accesses that occur before ICC_SGI1R_EL1 writes.

A DSB instruction ensures that no instructions that appear in program order after the DSB instruction, can execute until the DSB instruction has completed.

---
 drivers/irqchip/irq-gic-v3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3.c +0 -0
index b56c3e2..980ae8e 100644

drivers/irqchip/irq-gic-v3.c static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq) · line 691

Quoted 5 lines
drivers/irqchip/irq-gic-v3.c +1 -1
@@ -688,7 +688,7 @@ static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq)
 	 * Ensure that stores to Normal memory are visible to the
 	 * other CPUs before issuing the IPI.
 	 */
-	smp_wmb();
+	wmb();

I think this is the right thing to do and the smp_wmb() was accidentally pulled in here as a copy-paste from the GICv2 driver where it is sufficient in practice.

Quoted 8 lines
Quoted 4 lines

Did you spot this by code inspection, or did the DMB actually cause observable failures? (trying to figure out whether or not this need to go to -stable).

We've inspected the code because kernel was causing failures in scheduler/IPI_RESCHDULE. After some time of debugging, we landed in GIC driver and found that the issue was due to the DMB barrier.

OK. I've applied this with a cc: stable and Will's Ack.

Quoted 9 lines
Quoted 4 lines

Side note, we're also missing synchronization barriers in GIC driver after writing some of the ICC_XXX system registers. I'm planning to post those changes for comments.

e.g: gic_write_sgi1r(val) and gic_write_eoir(irqnr);

Thanks,

	M.
Signature · 4 lines
Adam Wallis
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.
#5 lore raw
In reply to Shanker Donthineni

drivers/irqchip/irq-gic-v3.c static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq) · line 691

Quoted 8 lines
drivers/irqchip/irq-gic-v3.c +1 -1
@@ -688,7 +688,7 @@ static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq)
 	 * Ensure that stores to Normal memory are visible to the
 	 * other CPUs before issuing the IPI.
 	 */
-	smp_wmb();
+	wmb();

Sorry for waking up the old thread. isn't dsb(ishst) enough here as we only need to guarantee the visibility of data to other CPUs in smp inner domain before we send the ipi?

drivers/irqchip/irq-gic-v3.c static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq) · line 694

Quoted 3 lines
drivers/irqchip/irq-gic-v3.c +0 -0
 	for_each_cpu(cpu, mask) {
 		u64 cluster_id = MPIDR_TO_SGI_CLUSTER_ID(cpu_logical_map(cpu));

Thanks
Barry