Re: [PATCH] sparc: iommu/pci_sun4v: fix page alignment in dma mapping
From: Stian Halseth
Date: Tue Feb 17 2026 - 11:48:19 EST
Hi Adrian,
Thanks for the review and suggestions.
On Tue, 2026-02-17 at 17:38 +0100, John Paul Adrian Glaubitz wrote:
> Hi Stian,
>
> please rephrase the subject to:
>
> sparc: Fix page alignment in dma mapping
>
> Your patch is not specific to sun4v but also fixes generic sparc
> code,
> so you should remove the part "iommu/pci_sun4v:" from the subject.
>
Understood — I will update the patch subject as suggested.
> On Tue, 2026-02-17 at 17:21 +0100, stian@xxxxxx wrote:
> > From: Stian Halseth <stian@xxxxxx>
> >
> > 'phys' may include an offset within the page, while 'base_paddr' is
> > already page-aligned.
> >
> > This caused incorrect DMA mapping in dma_4u_map_phys and
> > dma_4v_map_phys.
> >
> > Fix both functions by masking phys with IO_PAGE_MASK or subtracting
> > the page offset.
>
> Please remove the newlines between your sentences, they're not
> necessary
> and also trim the lines at 80 columns.
Will do — I’ll reformat the commit message to 80-column lines
and remove extra newlines.
> > Fixes: 38c0d0ebf520 ("sparc: Use physical address DMA mapping")
> >
> > Reported-by: Stian Halseth <stian@xxxxxx>
> > Suggested-by: Marek Szyprowski <m.szyprowski@xxxxxxxxxxx>
> > Signed-off-by: Stian Halseth <stian@xxxxxx>
> > ---
> > arch/sparc/kernel/iommu.c | 2 ++
> > arch/sparc/kernel/pci_sun4v.c | 2 +-
> > 2 files changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/sparc/kernel/iommu.c b/arch/sparc/kernel/iommu.c
> > index 46ef88bc9c26..f3755a388ac7 100644
> > --- a/arch/sparc/kernel/iommu.c
> > +++ b/arch/sparc/kernel/iommu.c
> > @@ -312,6 +312,8 @@ static dma_addr_t dma_4u_map_phys(struct device
> > *dev, phys_addr_t phys,
> > if (direction != DMA_TO_DEVICE)
> > iopte_protection |= IOPTE_WRITE;
> >
> > + phys -= offset_in_page(phys);
> > +
> > for (i = 0; i < npages; i++, base++, phys += IO_PAGE_SIZE)
> > iopte_val(*base) = iopte_protection | phys;
> >
> > diff --git a/arch/sparc/kernel/pci_sun4v.c
> > b/arch/sparc/kernel/pci_sun4v.c
> > index 791f0a76665f..2f30eeac4861 100644
> > --- a/arch/sparc/kernel/pci_sun4v.c
> > +++ b/arch/sparc/kernel/pci_sun4v.c
> > @@ -411,7 +411,7 @@ static dma_addr_t dma_4v_map_phys(struct device
> > *dev, phys_addr_t phys,
> > iommu_batch_start(dev, prot, entry);
> >
> > for (i = 0; i < npages; i++, phys += IO_PAGE_SIZE) {
> > - long err = iommu_batch_add(phys, mask);
> > + long err = iommu_batch_add(phys & IO_PAGE_MASK, mask);
> > if (unlikely(err < 0L))
> > goto iommu_map_fail;
> > }
>
> Looks good to me otherwise.
>
> Adrian
>
I’ll send an updated patch (v2) shortly with these changes applied.
Thanks again for reviewing.
--
Med vennlig hilsen
Stian Halseth