From: Barry Song <21cnbao@gmail.com>
To: catalin.marinas@arm.com, m.szyprowski@samsung.com,
robin.murphy@arm.com, will@kernel.org
Cc: ada.coupriediaz@arm.com, anshuman.khandual@arm.com,
ardb@kernel.org, iommu@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, maz@kernel.org,
ryan.roberts@arm.com, surenb@google.com, v-songbaohua@oppo.com,
zhengtangquan@oppo.com, Joerg Roedel <joro@8bytes.org>
Subject: [PATCH RFC 6/6] dma-iommu: Allow DMA sync batching for IOVA link/unlink
Date: Fri, 19 Dec 2025 13:36:58 +0800 [thread overview]
Message-ID: <20251219053658.84978-7-21cnbao@gmail.com> (raw)
In-Reply-To: <20251219053658.84978-1-21cnbao@gmail.com>
From: Barry Song <v-songbaohua@oppo.com>
Apply batched DMA synchronization to __dma_iova_link() and
iommu_dma_iova_unlink_range_slow(). For multiple
sync_dma_for_device() and sync_dma_for_cpu() calls, we only
need to wait once for the completion of all sync operations,
rather than waiting for each one individually.
I do not have the hardware to test this, so it is marked as
RFC. I would greatly appreciate it if someone could test it.
Suggested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Barry Song <v-songbaohua@oppo.com>
---
drivers/iommu/dma-iommu.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index c92088855450..95432bdc364f 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -1837,7 +1837,7 @@ static int __dma_iova_link(struct device *dev, dma_addr_t addr,
int prot = dma_info_to_prot(dir, coherent, attrs);
if (!coherent && !(attrs & (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_MMIO)))
- arch_sync_dma_for_device(phys, size, dir);
+ arch_sync_dma_for_device_batch_add(phys, size, dir);
return iommu_map_nosync(iommu_get_dma_domain(dev), addr, phys, size,
prot, GFP_ATOMIC);
@@ -1980,6 +1980,8 @@ int dma_iova_sync(struct device *dev, struct dma_iova_state *state,
dma_addr_t addr = state->addr + offset;
size_t iova_start_pad = iova_offset(iovad, addr);
+ if (!dev_is_dma_coherent(dev))
+ arch_sync_dma_batch_flush();
return iommu_sync_map(domain, addr - iova_start_pad,
iova_align(iovad, size + iova_start_pad));
}
@@ -1993,6 +1995,8 @@ static void iommu_dma_iova_unlink_range_slow(struct device *dev,
struct iommu_dma_cookie *cookie = domain->iova_cookie;
struct iova_domain *iovad = &cookie->iovad;
size_t iova_start_pad = iova_offset(iovad, addr);
+ bool need_sync_dma = !dev_is_dma_coherent(dev) &&
+ !(attrs & (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_MMIO));
dma_addr_t end = addr + size;
do {
@@ -2007,8 +2011,7 @@ static void iommu_dma_iova_unlink_range_slow(struct device *dev,
len = min_t(size_t,
end - addr, iovad->granule - iova_start_pad);
- if (!dev_is_dma_coherent(dev) &&
- !(attrs & (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_MMIO)))
+ if (need_sync_dma)
arch_sync_dma_for_cpu(phys, len, dir);
swiotlb_tbl_unmap_single(dev, phys, len, dir, attrs);
@@ -2016,6 +2019,9 @@ static void iommu_dma_iova_unlink_range_slow(struct device *dev,
addr += len;
iova_start_pad = 0;
} while (addr < end);
+
+ if (need_sync_dma)
+ arch_sync_dma_batch_flush();
}
static void __iommu_dma_iova_unlink(struct device *dev,
--
2.39.3 (Apple Git-146)
next prev parent reply other threads:[~2025-12-19 5:37 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-19 5:36 [PATCH 0/6] dma-mapping: arm64: support batched cache sync Barry Song
2025-12-19 5:36 ` [PATCH 1/6] arm64: Provide dcache_by_myline_op_nosync helper Barry Song
2025-12-19 12:20 ` Robin Murphy
2025-12-21 7:22 ` Barry Song
2025-12-19 5:36 ` [PATCH 2/6] arm64: Provide dcache_clean_poc_nosync helper Barry Song
2025-12-19 5:36 ` [PATCH 3/6] arm64: Provide dcache_inval_poc_nosync helper Barry Song
2025-12-19 12:34 ` Robin Murphy
2025-12-21 7:59 ` Barry Song
2025-12-19 5:36 ` [PATCH 4/6] arm64: Provide arch_sync_dma_ batched helpers Barry Song
2025-12-19 5:36 ` [PATCH 5/6] dma-mapping: Allow batched DMA sync operations if supported by the arch Barry Song
2025-12-20 17:37 ` kernel test robot
2025-12-21 5:15 ` Barry Song
2025-12-21 11:55 ` Leon Romanovsky
2025-12-21 19:24 ` Barry Song
2025-12-22 8:49 ` Leon Romanovsky
2025-12-23 0:02 ` Barry Song
2025-12-23 2:36 ` Barry Song
2025-12-23 14:14 ` Leon Romanovsky
2025-12-24 1:29 ` Barry Song
2025-12-24 8:51 ` Leon Romanovsky
2025-12-25 5:45 ` Barry Song
2025-12-25 12:36 ` Leon Romanovsky
2025-12-25 13:31 ` Barry Song
2025-12-25 13:40 ` Leon Romanovsky
2025-12-21 12:36 ` kernel test robot
2025-12-22 12:43 ` kernel test robot
2025-12-22 14:00 ` kernel test robot
2025-12-19 5:36 ` Barry Song [this message]
2025-12-19 6:04 ` [PATCH 0/6] dma-mapping: arm64: support batched cache sync Barry Song
2025-12-19 6:12 ` Barry Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251219053658.84978-7-21cnbao@gmail.com \
--to=21cnbao@gmail.com \
--cc=ada.coupriediaz@arm.com \
--cc=anshuman.khandual@arm.com \
--cc=ardb@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=maz@kernel.org \
--cc=robin.murphy@arm.com \
--cc=ryan.roberts@arm.com \
--cc=surenb@google.com \
--cc=v-songbaohua@oppo.com \
--cc=will@kernel.org \
--cc=zhengtangquan@oppo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®