Skip to content

drivers/iommu:riscv:add dma_wmb before cmpxchg_relaxed#309

Open
GooTal wants to merge 1 commit into
RVCK-Project:rvck-6.6from
zte-riscv:pr-iommu-dma_wmb
Open

drivers/iommu:riscv:add dma_wmb before cmpxchg_relaxed#309
GooTal wants to merge 1 commit into
RVCK-Project:rvck-6.6from
zte-riscv:pr-iommu-dma_wmb

Conversation

@GooTal

@GooTal GooTal commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

drivers/iommu:riscv:add dma_wmb before cmpxchg_relaxed

driver inclusion
category: bugfix
bugzilla: #308


When multiple cores execute riscv_iommu_map_pages/riscv_iommu_pte_alloc, a parallel consistency problem can occur.
Setting dma_wmb ensures that all previous DMA write operations have been completed before cmpxchg_relaxed.

Signed-off-by: bailu bai.lu5@zte.com.cn
Signed-off-by: liuqingtao liu.qingtao2@zte.com.cn

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

开始测试 log: https://github.com/RVCK-Project/rvck/actions/runs/27664081160

参数解析结果
args value
repository RVCK-Project/rvck
head ref pull/309/head
base ref rvck-6.6
LAVA repo RVCK-Project/lavaci
LAVA hardware ['qemu']
LAVA Testcase path lava-testcases/common-test/ltp/ltp.yaml
need run job kunit-test,kernel-build,check-patch,lava-trigger

测试完成

详细结果:
check result
kunit-test success
kernel-build success
check-patch failure
lava-trigger-qemu success
lava-trigger-sg2042 skipped
lava-trigger-k1 skipped
lava-trigger-lpi4a skipped

Kunit Test Result

[03:42:15] Testing complete. Ran 482 tests: passed: 466, skipped: 16

Kernel Build Result

Check Patch Result

Total Errors 1
Total Warnings 1

LAVA Check (qemu)

args value
testcase_repo RVCK-Project/lavaci
lava_template lava-job-template/qemu/qemu-ltp.yaml
testcase_path lava-testcases/common-test/ltp/ltp.yaml
kernel_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/309_27664081160_1/Image
initramfs_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/309_27664081160_1/initramfs.img
rootfs_download_url https://fast-mirror.isrc.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/RVCK/openEuler24.03-LTS-SP1/openeuler-rootfs.img.zst
testcase_ref main
testitem_name RVCK-Project_rvck_pull_request_target_309__common-test_qemu

result: Lava check done!

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

开始测试 log: https://github.com/RVCK-Project/rvck/actions/runs/27677458532

参数解析结果
args value
repository RVCK-Project/rvck
head ref pull/309/head
base ref rvck-6.6
LAVA repo RVCK-Project/lavaci
LAVA hardware ['qemu']
LAVA Testcase path lava-testcases/common-test/ltp/ltp.yaml
need run job kunit-test,kernel-build,check-patch,lava-trigger

测试完成

详细结果:
check result
kunit-test success
kernel-build success
check-patch success
lava-trigger-qemu success
lava-trigger-sg2042 skipped
lava-trigger-k1 skipped
lava-trigger-lpi4a skipped

Kunit Test Result

[08:58:23] Testing complete. Ran 482 tests: passed: 466, skipped: 16

Kernel Build Result

Check Patch Result

Total Errors 0
Total Warnings 0

LAVA Check (qemu)

args value
testcase_repo RVCK-Project/lavaci
lava_template lava-job-template/qemu/qemu-ltp.yaml
testcase_path lava-testcases/common-test/ltp/ltp.yaml
kernel_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/309_27677458532_1/Image
initramfs_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/309_27677458532_1/initramfs.img
rootfs_download_url https://fast-mirror.isrc.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/RVCK/openEuler24.03-LTS-SP1/openeuler-rootfs.img.zst
testcase_ref main
testitem_name RVCK-Project_rvck_pull_request_target_309__common-test_qemu

result: Lava check done!

@fangyu0809

fangyu0809 commented Jun 18, 2026

Copy link
Copy Markdown

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)

  • ret = cmpxchg_relaxed(ptep, 0ULL, pte);
  • ret = cmpxchg_release(ptep, 0ULL, pte);

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.

@king729

king729 commented Jun 22, 2026

Copy link
Copy Markdown

@fangyu0809
The trade-off of this modification come from the current ARM implementation:

/*
 * Ensure the table itself is visible before its PTE can be.
 * Whilst we could get away with cmpxchg64_release below, this
 * doesn't have any ordering semantics when !CONFIG_SMP.
 */
dma_wmb();

old = cmpxchg64_relaxed(ptep, curr, new);

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:

if (!IS_ENABLED(CONFIG_SMP))
    dma_wmb();
ret = try_cmpxchg64_release(entryp, &old_entry, table_entry);

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.

driver inclusion
category: bugfix
Link: RVCK-Project#308

--------------------------------

When multiple cores execute riscv_iommu_map_pages/riscv_iommu_pte_alloc,
a parallel consistency problem can occur.
Setting dma_wmb ensures that all previous DMA write operations have
been completed before cmpxchg_relaxed.

Signed-off-by: bailu <bai.lu5@zte.com.cn>
Signed-off-by: liuqingtao <liu.qingtao2@zte.com.cn>
@GooTal GooTal force-pushed the pr-iommu-dma_wmb branch from b42cb3f to 26f0782 Compare June 26, 2026 01:02
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown

开始测试 log: https://github.com/RVCK-Project/rvck/actions/runs/28210386797

参数解析结果
args value
repository RVCK-Project/rvck
head ref pull/309/head
base ref rvck-6.6
LAVA repo RVCK-Project/lavaci
LAVA hardware ['qemu']
LAVA Testcase path lava-testcases/common-test/ltp/ltp.yaml
need run job kunit-test,kernel-build,check-patch,lava-trigger

测试完成

详细结果:
check result
kunit-test success
kernel-build success
check-patch failure
lava-trigger-qemu success
lava-trigger-sg2042 skipped
lava-trigger-k1 skipped
lava-trigger-lpi4a skipped

Kunit Test Result

[01:07:04] Testing complete. Ran 482 tests: passed: 466, skipped: 16

Kernel Build Result

Check Patch Result

Total Errors 20
Total Warnings 1

LAVA Check (qemu)

args value
testcase_repo RVCK-Project/lavaci
lava_template lava-job-template/qemu/qemu-ltp.yaml
testcase_path lava-testcases/common-test/ltp/ltp.yaml
kernel_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/309_28210386797_1/Image
initramfs_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/309_28210386797_1/initramfs.img
rootfs_download_url https://fast-mirror.isrc.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/RVCK/openEuler24.03-LTS-SP1/openeuler-rootfs.img.zst
testcase_ref main
testitem_name RVCK-Project_rvck_pull_request_target_309__common-test_qemu

result: Lava check done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants