Linux MIPS Architecture development
 help / color / mirror / Atom feed
From: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
To: Marek Szyprowski <m.szyprowski@samsung.com>,
	linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
	"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>
Cc: 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>,
	Shrikanth Hegde <sshegde@linux.ibm.com>,
	Chris Zankel <chris@zankel.net>,
	Max Filippov <jcmvbkbc@gmail.com>
Subject: Re: [PATCH v2 4/7] powerpc/mm: handle highmem pages in arch_dma_prep_coherent()
Date: Thu, 19 Nov 2026 19:59:02 +0530	[thread overview]
Message-ID: <5wxslwsx.ritesh.list@gmail.com> (raw)
In-Reply-To: <2b64e853-89a7-4fa5-a4f8-2c6b0b62bf74@samsung.com>

Marek Szyprowski <m.szyprowski@samsung.com> writes:

> On 19.11.2026 13:07, Ritesh Harjani (IBM) wrote:
>> Marek Szyprowski <m.szyprowski@samsung.com> writes:
>>
>>> arch_dma_prep_coherent() performs the cache maintenance on the address
>>> returned by page_address(). On 32-bit powerpc with CONFIG_HIGHMEM that
>>> is NULL for a highmem page which is not kmapped, so the flush would
>>> operate on the wrong virtual range and leave the dirty lines of the
>>> buffer in place.
>>>
>>> The generic DMA code may pass highmem pages to this hook:
>>> dma_direct_alloc() handles a highmem page returned by
>>> dma_alloc_contiguous() by forcing the remap path, which calls
>>> arch_dma_prep_coherent() on that page before creating the uncached
>>> mapping. This cannot happen on powerpc today only because it does not
>>> select HAVE_DMA_CONTIGUOUS, so dma-direct never gets a highmem page
>>> there, but nothing in the hook's contract rules it out.
>>>
>>> Use __dma_sync_page() with DMA_BIDIRECTIONAL, which the
>>> arch_sync_dma_for_*() hooks already use and which kmaps highmem pages
>>> one at a time. Without CONFIG_HIGHMEM it does the same
>>> flush_dcache_range() on the linear mapping as before.
>>>
>> Does that mean, this change can add additional overhead for
>> CONFIG_HIGHMEM=y kernels, where the buffer received still belongs to
>> lowmem? (Because of extra per-page book keeping like
>> local_irq_save/restore, kmap_xxx). Thoughts?
>>
>> Although functionally the change looks correct to me. But maybe
>> __dma_sync_page() on powerpc side could use some cleanups (outside of
>> this patch series perhaps).
> Indeed, __dma_sync_page() could be improved by calling __dma_sync_page_highmem()
> only for highmem pages. Something like:
>
>
> diff --git a/arch/powerpc/mm/dma-noncoherent.c b/arch/powerpc/mm/dma-noncoherent.c
> index e646256365d5..199ce0467b58 100644
> --- a/arch/powerpc/mm/dma-noncoherent.c
> +++ b/arch/powerpc/mm/dma-noncoherent.c
> @@ -97,11 +97,12 @@ static void __dma_sync_page(phys_addr_t paddr, size_t size, int dir)
>         unsigned offset = paddr & ~PAGE_MASK;
>

Should we return early if size=0 is passed. Although I couldn't find any
caller where this could happen, but since we are doing "paddr + size - 1",
hence wanted to flag it.


>  #ifdef CONFIG_HIGHMEM
> -       __dma_sync_page_highmem(page, offset, size, dir);
> -#else
> -       unsigned long start = (unsigned long)page_address(page) + offset;
> -       __dma_sync((void *)start, size, dir);
> +       if (PageHighMem(pfn_to_page(PHYS_PFN(paddr + size - 1)))) {
> +               __dma_sync_page_highmem(page, offset, size, dir);
> +               return;
> +       }
>  #endif
> +       __dma_sync(page_address(page) + offset, size, dir);
>  }
>
>  void arch_sync_dma_for_device(phys_addr_t paddr, size_t size,
>
>
> Do You want me to add it as another patch for this series?

I think this should work. I guess we should add this patch first and
then patch-4 on top of it.

Thanks for taking care of it. This at least will avoid the extra work
which we would have done otherwise for highmem kernels, where the buffer
passed to this still comes from lowmem.

-ritesh

  reply	other threads:[~2026-11-19 14:36 UTC|newest]

Thread overview: 14+ 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
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
2026-11-10  9:48   ` [PATCH v2 2/7] xtensa: handle highmem pages " Marek Szyprowski
2026-11-10 12:42     ` Max Filippov
2026-11-10  9:48   ` [PATCH v2 3/7] MIPS: mm: " Marek Szyprowski
2026-11-16 19:07     ` Thomas Bogendoerfer
2026-11-10  9:48   ` [PATCH v2 4/7] powerpc/mm: " Marek Szyprowski
2026-11-19 12:07     ` Ritesh Harjani
2026-11-19 13:17       ` Marek Szyprowski
2026-11-19 14:29         ` Ritesh Harjani [this message]
2026-11-10  9:48   ` [PATCH v2 5/7] dma-mapping: document that arch_dma_prep_coherent() must handle highmem Marek Szyprowski
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
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=5wxslwsx.ritesh.list@gmail.com \
    --to=ritesh.list@gmail.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=m.szyprowski@samsung.com \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@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