Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions drivers/iommu/riscv/iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,15 @@ static unsigned long *riscv_iommu_pte_alloc(struct riscv_iommu_domain *domain,
return NULL;
old = pte;
pte = _io_pte_entry(virt_to_pfn(addr), _PAGE_TABLE);

/*
* To ensure that the table itself is visible prior to its PTE,
* a barrier is required; additionally, the dma_wmb primitive is
* selected to avoid potential race conditions between
* the IOMMU and the CPU.
*/
dma_wmb();

if (cmpxchg_relaxed(ptr, old, pte) != old) {
iommu_free_page(addr);
goto pte_retry;
Expand Down Expand Up @@ -1214,6 +1223,15 @@ static int riscv_iommu_map_pages(struct iommu_domain *iommu_domain,

old = READ_ONCE(*ptr);
pte = _io_pte_entry(phys_to_pfn(phys), pte_prot);

/*
* To ensure that the table itself is visible prior to its PTE,
* a barrier is required; additionally, the dma_wmb primitive is
* selected to avoid potential race conditions between
* the IOMMU and the CPU.
*/
dma_wmb();

if (cmpxchg_relaxed(ptr, old, pte) != old)
continue;

Expand Down
Loading