linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Christian Meissl <meissl.christian@gmail.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Russell King <linux@armlinux.org.uk>,
	Christoph Hellwig <hch@lst.de>,
	 Philipp Zabel <p.zabel@pengutronix.de>,
	linux-kernel@vger.kernel.org, linux-media@vger.kernel.org
Subject: [PATCH] ARM/dma-mapping: invalidate caches on arch_dma_prep_coherent
Date: Tue, 17 Jun 2025 09:54:46 +0200	[thread overview]
Message-ID: <43a834c8f871f8719368b3f3239f27ee4f6c6286.camel@gmail.com> (raw)

since switching to dma-direct, memory using DMA_ATTR_NO_KERNEL_MAPPING
is no longer allocated using the arch specific handlers and instead
will use dma_direct_alloc_no_mapping. While the arm specific allocation
handlers implicitly clear the allocated dma buffers and will flush any caches
dma-direct relies on ARCH_HAS_DMA_PREP_COHERENT to flush the caches.

Without this flush video frame corruption can occur in drivers
like the coda v4l2 driver which explicitly sets the DMA_ATTR_NO_KERNEL_MAPPING flag.

Fixes: ae626eb97376 ("ARM/dma-mapping: use dma-direct unconditionally")
Signed-off-by: Christian Meissl <meissl.christian@gmail.com>
---
 arch/arm/Kconfig          | 1 +
 arch/arm/mm/dma-mapping.c | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 3072731fe09c..7a3aaf3a490b 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -14,6 +14,7 @@ config ARM
        select ARCH_HAS_DEBUG_VIRTUAL if MMU
        select ARCH_HAS_DMA_ALLOC if MMU
        select ARCH_HAS_DMA_OPS
+       select ARCH_HAS_DMA_PREP_COHERENT
        select ARCH_HAS_DMA_WRITE_COMBINE if !ARM_DMA_MEM_BUFFERABLE
        select ARCH_HAS_ELF_RANDOMIZE
        select ARCH_HAS_FORTIFY_SOURCE
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 88c2d68a69c9..bde7ae4ba31a 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -1821,3 +1821,11 @@ void arch_dma_free(struct device *dev, size_t size, void *cpu_addr,
 {
        __arm_dma_free(dev, size, cpu_addr, dma_handle, attrs, false);
 }
+
+void arch_dma_prep_coherent(struct page *page, size_t size)
+{
+       void *ptr = page_address(page);
+
+       dmac_flush_range(ptr, ptr + size);
+       outer_flush_range(__pa(ptr), __pa(ptr) + size);
+}
-- 
2.49.0


             reply	other threads:[~2025-06-17  7:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-17  7:54 Christian Meissl [this message]
2025-06-17 13:17 ` [PATCH] ARM/dma-mapping: invalidate caches on arch_dma_prep_coherent Catalin Marinas

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=43a834c8f871f8719368b3f3239f27ee4f6c6286.camel@gmail.com \
    --to=meissl.christian@gmail.com \
    --cc=hch@lst.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=p.zabel@pengutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).