From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 1/2] ARM: mmu: optimize dma_alloc_coherent for cache-coherent DMA masters
Date: Thu, 15 Jan 2026 13:05:52 +0100 [thread overview]
Message-ID: <20260115120557.3433211-1-a.fatoum@barebox.org> (raw)
If a device is DMA-capable and cache-coherent, it can be considerably
faster to keep shared memory cached, instead of mapping it uncached
unconditionally like we currently do.
This was very noticeable when using Virt I/O with KVM acceleration as
described in commit 3ebd05809a49 ("virtio: don't use DMA API unless
required").
In preparation for simplifying the code in the aforementioned commit,
consult dev_is_dma_coherent() before doing cache maintenance.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
arch/arm/cpu/mmu-common.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/arch/arm/cpu/mmu-common.c b/arch/arm/cpu/mmu-common.c
index a1431c0ff461..2b22ab47cac8 100644
--- a/arch/arm/cpu/mmu-common.c
+++ b/arch/arm/cpu/mmu-common.c
@@ -50,9 +50,11 @@ void *dma_alloc_map(struct device *dev,
*dma_handle = (dma_addr_t)ret;
memset(ret, 0, size);
- dma_flush_range(ret, size);
- remap_range(ret, size, map_type);
+ if (!dev_is_dma_coherent(dev)) {
+ dma_flush_range(ret, size);
+ remap_range(ret, size, map_type);
+ }
return ret;
}
@@ -70,8 +72,8 @@ void *dma_alloc_coherent(struct device *dev,
void dma_free_coherent(struct device *dev,
void *mem, dma_addr_t dma_handle, size_t size)
{
- size = PAGE_ALIGN(size);
- remap_range(mem, size, MAP_CACHED);
+ if (!dev_is_dma_coherent(dev))
+ remap_range(mem, PAGE_ALIGN(size), MAP_CACHED);
free(mem);
}
--
2.47.3
next reply other threads:[~2026-01-15 12:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-15 12:05 Ahmad Fatoum [this message]
2026-01-15 12:05 ` [PATCH 2/2] virtio: use DMA coherent APIs Ahmad Fatoum
2026-01-19 10:20 ` [PATCH 1/2] ARM: mmu: optimize dma_alloc_coherent for cache-coherent DMA masters Sascha Hauer
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=20260115120557.3433211-1-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
/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