iommu/riscv: add dma_wmb before cmpxchg_relaxed#309
Conversation
|
开始测试 log: https://github.com/RVCK-Project/rvck/actions/runs/27664081160 参数解析结果
测试完成 详细结果:
Kunit Test Result[03:42:15] Testing complete. Ran 482 tests: passed: 466, skipped: 16
Kernel Build Result
Check Patch Result
LAVA Check (qemu)
result: Lava check done!
|
|
开始测试 log: https://github.com/RVCK-Project/rvck/actions/runs/27677458532 参数解析结果
测试完成 详细结果:
Kunit Test Result[08:58:23] Testing complete. Ran 482 tests: passed: 466, skipped: 16
Kernel Build Result
Check Patch Result
LAVA Check (qemu)
result: Lava check done!
|
|
The real race here is CPU-CPU (concurrent pte_alloc callers), not CPU-to-DMA-device. dma_wmb fixes it functionally but is semantically misleading. Suggest using cmpxchg_release instead,— matching upstream generic_pt (pt_table_install64 uses try_cmpxchg64_release)
Also, the CPU vs IOMMU-HW-walker race likely doesn't exist for new PDE installation,Please double-check whether this race is actually reachable in practice. |
|
@fangyu0809 As the comment explains, the introduction of dma_wmb() primarily addresses the lack of ordering guarantees for cmpxchg64_release on non‑SMP architectures. The new version modifies this to: I believe this adjustment is also intended to maintain compatibility across both SMP and non‑SMP configurations. Therefore, in my current modification, I have chosen to adopt the earlier approach — using dma_wmb() combined with cmpxchg64_relaxed — for consistency and to preserve the original ordering semantics. |
|
开始测试 log: https://github.com/RVCK-Project/rvck/actions/runs/28210386797 参数解析结果
测试完成 详细结果:
Kunit Test Result[01:07:04] Testing complete. Ran 482 tests: passed: 466, skipped: 16
Kernel Build Result
Check Patch Result
LAVA Check (qemu)
result: Lava check done!
|
|
开始测试 log: https://github.com/RVCK-Project/rvck/actions/runs/28371670607 参数解析结果
测试完成 详细结果:
Kunit Test Result[12:27:18] Testing complete. Ran 482 tests: passed: 466, skipped: 16
Kernel Build Result
Check Patch Result
LAVA Check (qemu)
result: Lava check done!
|
|
@fangyu0809 @sterling-teng Hi,两位老师,是否可以合入了 |
因为这个补丁29日push后才过ci,而且不是backport的补丁;稳妥起见,等今天rebase后我们评审测试之后再合并吧。 |
|
Reviewed-by: Fangyu Yu fangyu.yu@linux.alibaba.com |
|
@GooTal 请问这个问题您是在什么硬件环境下发现的,可以复现吗?我想试试。 |
| * a barrier is required; additionally, the dma_wmb primitive is | ||
| * selected to avoid potential race conditions between | ||
| * the IOMMU and the CPU. | ||
| * An out-of-tree bugfix that may require future updates. |
There was a problem hiding this comment.
“An out-of-tree bugfix that may require future updates.” 这种注释建议删掉,如果这个解决方案的确还有疑问的话可能放在个人的开发分支上会比较合适些。
| * a barrier is required; additionally, the dma_wmb primitive is | ||
| * selected to avoid potential race conditions between | ||
| * the IOMMU and the CPU. | ||
| * An out-of-tree bugfix that may require future updates. |
There was a problem hiding this comment.
“An out-of-tree bugfix that may require future updates.” 同理
|
ommit 的 title 中的前缀请遵守上游 patch 的习惯,采用 “iommu/riscv: ”,注意前缀和描述之间要加空格。 BTW:我看 rvck-6.6 已经重新 rebase 了,请你修改后也重新 rebase 一下,不然这个 PR 里改动看上去太多了。 谢谢 |
|
开始测试 log: https://github.com/RVCK-Project/rvck/actions/runs/28504331254 参数解析结果
测试完成 详细结果:
Kunit Test Result[08:35:09] Testing complete. Ran 482 tests: passed: 466, skipped: 16
Kernel Build Result
Check Patch Result
LAVA Check (qemu)
result: Lava check done!
|
|
开始测试 log: https://github.com/RVCK-Project/rvck/actions/runs/28504963822 参数解析结果
测试完成 详细结果:
Kunit Test Result[08:46:42] Testing complete. Ran 482 tests: passed: 465, skipped: 17
Kernel Build Result
Check Patch Result
LAVA Check (qemu)
result: Lava check done!
|
已更新 |
driver inclusion category: bugfix Link: RVCK-Project#308 -------------------------------- When using NVMe for PCIe peripherals on an RV multi-core CPU with IOMMU enabled, the command `fio --filename=/dev/nvme0n1 --ioengine=libaio --direct=1 --iodepth=256 --numjobs=8 --group_reporting=1 --bs=1M --time_based=1 --runtime=2 --rw=read --name=test_read_8 --thread=1` resulted a fault 15 exception during IOMMU testing. When multiple cores modify iommu page talbe simultaneously, executing riscv_iommu_map_pages or riscv_iommu_pte_alloc, an out-of-order iommu page table clearing problem can occur due to a memory barrier missing. It caused PTE being incorrectly cleared. Setting dma_wmb ensures that all previous DMA write operations have been completed before cmpxchg_relaxed. This issue is relatively rare and may only occur during stress testing. Signed-off-by: bailu <bai.lu5@zte.com.cn> Signed-off-by: liuqingtao <liu.qingtao2@zte.com.cn>
|
开始测试 log: https://github.com/RVCK-Project/rvck/actions/runs/28992666612 参数解析结果
测试完成 详细结果:
Kunit Test Result[03:54:20] Testing complete. Ran 482 tests: passed: 465, skipped: 17
Kernel Build Result
Check Patch Result
LAVA Check (qemu)
result: Lava check done!
|
|
已经合并到rvck-6.6. |
fixed: #308
drivers/iommu:riscv:add dma_wmb before cmpxchg_relaxed
driver inclusion
category: bugfix
bugzilla: #308
When using NVMe for PCIe peripherals on an RV multi-core CPU with IOMMU
enabled, the command
fio --filename=/dev/nvme0n1 --ioengine=libaio --direct=1 --iodepth=256 --numjobs=8 --group_reporting=1 --bs=1M --time_based=1 --runtime=2 --rw=read --name=test_read_8 --thread=1resulted a fault 15 exception during IOMMU testing.
When multiple cores modify iommu page talbe simultaneously, executing
riscv_iommu_map_pages or riscv_iommu_pte_alloc, an out-of-order iommu
page table clearing problem can occur due to a memory barrier missing.
It caused PTE being incorrectly cleared.
Setting dma_wmb ensures that all previous DMA write operations have
been completed before cmpxchg_relaxed.
This issue is relatively rare and may only occur during stress testing.
Signed-off-by: bailu bai.lu5@zte.com.cn
Signed-off-by: liuqingtao liu.qingtao2@zte.com.cn