mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marek Szyprowski <m.szyprowski@samsung.com>
To: linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
	Robin Murphy <robin.murphy@arm.com>,
	Christoph Hellwig <hch@infradead.org>,
	Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Nicholas Piggin <npiggin@gmail.com>,
	"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
	"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
	Shrikanth Hegde <sshegde@linux.ibm.com>,
	Chris Zankel <chris@zankel.net>,
	Max Filippov <jcmvbkbc@gmail.com>
Subject: [PATCH v2 2/7] xtensa: handle highmem pages in arch_dma_prep_coherent()
Date: Tue, 10 Nov 2026 10:48:22 +0100	[thread overview]
Message-ID: <20261110094830.2081847-3-m.szyprowski@samsung.com> (raw)
In-Reply-To: <20261110094830.2081847-1-m.szyprowski@samsung.com>

arch_dma_prep_coherent() performs the cache maintenance on the address
returned by page_address(). xtensa with CONFIG_HIGHMEM uses
HASHED_PAGE_VIRTUAL, so page_address() returns NULL for a highmem page
that is not kmapped, and the cache operation then works on the virtual
range starting at 0 instead of the buffer, leaving any dirty cache lines
of the buffer in place.

Highmem pages do reach this function: dma_alloc_contiguous() can return
a highmem CMA page, which dma_direct_alloc() handles by forcing the remap
path and calling arch_dma_prep_coherent() on that page before creating
the uncached mapping.

Fix this by reusing do_cache_op(), which the arch_sync_dma_for_*() hooks
already use and which maps highmem pages one page at a time with
kmap_atomic(). For lowmem pages it does a single cache operation over
the whole range, so the behaviour is unchanged there. A small wrapper
is needed because __flush_invalidate_dcache_range() is a macro on cores
with a write-through data cache.

Fixes: 0f665b9e2a6d ("xtensa: use the generic uncached segment support")
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
 arch/xtensa/kernel/pci-dma.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/arch/xtensa/kernel/pci-dma.c b/arch/xtensa/kernel/pci-dma.c
index e1c00ec37eed..41467a1ba068 100644
--- a/arch/xtensa/kernel/pci-dma.c
+++ b/arch/xtensa/kernel/pci-dma.c
@@ -80,9 +80,19 @@ void arch_sync_dma_for_device(phys_addr_t paddr, size_t size,
 	}
 }
 
+/*
+ * __flush_invalidate_dcache_range() may be a macro on cores with a
+ * write-through data cache, so it cannot be passed to do_cache_op().
+ */
+static void flush_invalidate_dcache_range(unsigned long start,
+					  unsigned long size)
+{
+	__flush_invalidate_dcache_range(start, size);
+}
+
 void arch_dma_prep_coherent(struct page *page, size_t size)
 {
-	__flush_invalidate_dcache_range((unsigned long)page_address(page), size);
+	do_cache_op(page_to_phys(page), size, flush_invalidate_dcache_range);
 }
 
 /*
-- 
2.43.0


  parent reply	other threads:[~2026-11-10  9:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20261110094846eucas1p140d5ebfe71b47d4e4b5e2162ba051c51@eucas1p1.samsung.com>
2026-11-10  9:48 ` [PATCH v2 0/7] dma-mapping: DMA_ATTR_NO_KERNEL_MAPPING related fixes Marek Szyprowski
     [not found]   ` <CGME20261110094847eucas1p125691a852f3621482adae13de1205223@eucas1p1.samsung.com>
2026-11-10  9:48     ` [PATCH v2 1/7] xtensa: write back dirty lines in arch_dma_prep_coherent() Marek Szyprowski
2026-11-10 12:40       ` Max Filippov
     [not found]   ` <CGME20261110094848eucas1p2577d7a3c60643a040e599dfa1bf97f08@eucas1p2.samsung.com>
2026-11-10  9:48     ` Marek Szyprowski [this message]
2026-11-10 12:42       ` [PATCH v2 2/7] xtensa: handle highmem pages " Max Filippov
     [not found]   ` <CGME20261110094849eucas1p2ece5eda5ed8c159ec05951bb8a3052be@eucas1p2.samsung.com>
2026-11-10  9:48     ` [PATCH v2 3/7] MIPS: mm: " Marek Szyprowski
2026-11-16 19:07       ` Thomas Bogendoerfer
     [not found]   ` <CGME20261110094850eucas1p1f10fa1473aca341473077f60a088b490@eucas1p1.samsung.com>
2026-11-10  9:48     ` [PATCH v2 4/7] powerpc/mm: " Marek Szyprowski
     [not found]   ` <CGME20261110094851eucas1p10eccf143e36dcc8933008074dee399c9@eucas1p1.samsung.com>
2026-11-10  9:48     ` [PATCH v2 5/7] dma-mapping: document that arch_dma_prep_coherent() must handle highmem Marek Szyprowski
     [not found]   ` <CGME20261110094852eucas1p28920baba9ddde5dbb2760e45fee7179a@eucas1p2.samsung.com>
2026-11-10  9:48     ` [PATCH v2 6/7] dma-direct: do not skip cache maintenance for highmem pages in no-mapping allocations Marek Szyprowski
     [not found]   ` <CGME20261110094853eucas1p2c89af10eb0d4611c4fc080d559696015@eucas1p2.samsung.com>
2026-11-10  9:48     ` [PATCH v2 7/7] dma-direct: zero memory allocated with DMA_ATTR_NO_KERNEL_MAPPING Marek Szyprowski

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=20261110094830.2081847-3-m.szyprowski@samsung.com \
    --to=m.szyprowski@samsung.com \
    --cc=chleroy@kernel.org \
    --cc=chris@zankel.net \
    --cc=hch@infradead.org \
    --cc=iommu@lists.linux.dev \
    --cc=jcmvbkbc@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=ritesh.list@gmail.com \
    --cc=robin.murphy@arm.com \
    --cc=sshegde@linux.ibm.com \
    --cc=tsbogend@alpha.franken.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

all inboxes | Powered by JetHome®