Skip to contentSkip to conversation

iommu/arm-smmu-v3: Add rmb after reading event queue prod_reg

PATCH Applied Zhou Wang 2 participants 3 messages Sep 28, 2020 – Sep 29, 2020

Subsystems (2)
lore
Share & tools
lore

Zhou Wang

author
#0 lore raw

PATCH 1/1 iommu/arm-smmu-v3: Add rmb after reading event queue prod_reg

In arm_smmu_evtq_thread, reading event queue is from consumer pointer, which has no address dependency on producer pointer, prog_reg(MMIO) and event queue memory(Normal memory) can disorder. So the load for event queue can be done before the load of prod_reg, then perhaps wrong event entry value will be got.

Add rmb to make sure to get correct event queue entry value.

---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +3 -0
index c192544..93c9077 100644
@@ -819,6 +819,9 @@ static int queue_sync_prod_in(struct arm_smmu_queue *q)
 	int ret = 0;
 	u32 prod = readl_relaxed(q->prod_reg);
 
+	/* Ensure that reading event queue is after reading prod_reg */
+	rmb();
+
 	if (Q_OVF(prod) != Q_OVF(q->llq.prod))
 		ret = -EOVERFLOW;
 
Signature · 6 lines
2.8.1

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
maintainer Applied
#1 lore raw
Quoted 7 lines · Zhou Wang

In arm_smmu_evtq_thread, reading event queue is from consumer pointer, which has no address dependency on producer pointer, prog_reg(MMIO) and event queue memory(Normal memory) can disorder. So the load for event queue can be done before the load of prod_reg, then perhaps wrong event entry value will be got.

Add rmb to make sure to get correct event queue entry value.

Applied to will (for-joerg/arm-smmu/updates), thanks!

[1/1] iommu/arm-smmu-v3: Add rmb after reading event queue prod_reg

      https://git.kernel.org/will/c/a76a37777f2c 

(please note that I changed the patch to use readl() instead of an rmb() in conjunction with the _relaxed() accessor, and then adjusted the cons side to match in terms of DMB vs DSB).

Cheers,

Signature · 9 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
author
#2 lore raw
Quoted 9 lines · Will Deacon
Quoted 7 lines · Zhou Wang

In arm_smmu_evtq_thread, reading event queue is from consumer pointer, which has no address dependency on producer pointer, prog_reg(MMIO) and event queue memory(Normal memory) can disorder. So the load for event queue can be done before the load of prod_reg, then perhaps wrong event entry value will be got.

Add rmb to make sure to get correct event queue entry value.

Quoted 8 lines

Applied to will (for-joerg/arm-smmu/updates), thanks!

[1/1] iommu/arm-smmu-v3: Add rmb after reading event queue prod_reg

      https://git.kernel.org/will/c/a76a37777f2c 

(please note that I changed the patch to use readl() instead of an rmb() in conjunction with the _relaxed() accessor, and then adjusted the cons side to match in terms of DMB vs DSB).

Thanks for taking this patch!

Best,
Zhou

Quoted 3 lines

Cheers,

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu