* [PATCH] sparc: iommu/pci_sun4v: fix page alignment in dma mapping
@ 2026-02-17 16:21 stian
2026-02-17 16:38 ` John Paul Adrian Glaubitz
0 siblings, 1 reply; 15+ messages in thread
From: stian @ 2026-02-17 16:21 UTC (permalink / raw)
Cc: Stian Halseth, Marek Szyprowski, David S. Miller, Andreas Larsson,
Leon Romanovsky, sparclinux, linux-kernel
From: Stian Halseth <stian@itx.no>
'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.
Fixes: 38c0d0ebf520 ("sparc: Use physical address DMA mapping")
Reported-by: Stian Halseth <stian@itx.no>
Suggested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Stian Halseth <stian@itx.no>
---
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;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH] sparc: iommu/pci_sun4v: fix page alignment in dma mapping 2026-02-17 16:21 [PATCH] sparc: iommu/pci_sun4v: fix page alignment in dma mapping stian @ 2026-02-17 16:38 ` John Paul Adrian Glaubitz 2026-02-17 16:48 ` Stian Halseth 2026-02-17 17:10 ` [PATCH v2] sparc: Fix " stian 0 siblings, 2 replies; 15+ messages in thread From: John Paul Adrian Glaubitz @ 2026-02-17 16:38 UTC (permalink / raw) To: stian Cc: Marek Szyprowski, David S. Miller, Andreas Larsson, Leon Romanovsky, sparclinux, linux-kernel 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. On Tue, 2026-02-17 at 17:21 +0100, stian@itx.no wrote: > From: Stian Halseth <stian@itx.no> > > '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. > Fixes: 38c0d0ebf520 ("sparc: Use physical address DMA mapping") > > Reported-by: Stian Halseth <stian@itx.no> > Suggested-by: Marek Szyprowski <m.szyprowski@samsung.com> > Signed-off-by: Stian Halseth <stian@itx.no> > --- > 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 -- .''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] sparc: iommu/pci_sun4v: fix page alignment in dma mapping 2026-02-17 16:38 ` John Paul Adrian Glaubitz @ 2026-02-17 16:48 ` Stian Halseth 2026-02-17 17:16 ` John Paul Adrian Glaubitz 2026-02-17 17:10 ` [PATCH v2] sparc: Fix " stian 1 sibling, 1 reply; 15+ messages in thread From: Stian Halseth @ 2026-02-17 16:48 UTC (permalink / raw) To: John Paul Adrian Glaubitz Cc: Marek Szyprowski, David S. Miller, Andreas Larsson, Leon Romanovsky, sparclinux, linux-kernel 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@itx.no wrote: > > From: Stian Halseth <stian@itx.no> > > > > '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@itx.no> > > Suggested-by: Marek Szyprowski <m.szyprowski@samsung.com> > > Signed-off-by: Stian Halseth <stian@itx.no> > > --- > > 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 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] sparc: iommu/pci_sun4v: fix page alignment in dma mapping 2026-02-17 16:48 ` Stian Halseth @ 2026-02-17 17:16 ` John Paul Adrian Glaubitz 2026-02-17 17:25 ` Leon Romanovsky 0 siblings, 1 reply; 15+ messages in thread From: John Paul Adrian Glaubitz @ 2026-02-17 17:16 UTC (permalink / raw) To: Stian Halseth Cc: Marek Szyprowski, David S. Miller, Andreas Larsson, Leon Romanovsky, sparclinux, linux-kernel Hi Stian, On Tue, 2026-02-17 at 17:48 +0100, Stian Halseth wrote: > 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@itx.no wrote: > > > From: Stian Halseth <stian@itx.no> > > > > > > '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. Perfect! I have nothing to add. Let's have Andreas review your patch ;-). Adrian -- .''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] sparc: iommu/pci_sun4v: fix page alignment in dma mapping 2026-02-17 17:16 ` John Paul Adrian Glaubitz @ 2026-02-17 17:25 ` Leon Romanovsky 2026-02-17 17:33 ` Stian Halseth 0 siblings, 1 reply; 15+ messages in thread From: Leon Romanovsky @ 2026-02-17 17:25 UTC (permalink / raw) To: John Paul Adrian Glaubitz, Stian Halseth Cc: Marek Szyprowski, David Miller, Andreas Larsson, sparclinux, linux-kernel On Tue, Feb 17, 2026, at 19:16, John Paul Adrian Glaubitz wrote: > Hi Stian, > > On Tue, 2026-02-17 at 17:48 +0100, Stian Halseth wrote: >> 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@itx.no wrote: >> > > From: Stian Halseth <stian@itx.no> >> > > >> > > '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. > > Perfect! I have nothing to add. Let's have Andreas review your patch ;-). Please add Fixes line, so the patch will be taken to stable@ in automatic way. Thanks > > Adrian > > -- > .''`. John Paul Adrian Glaubitz > : :' : Debian Developer > `. `' Physicist > `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] sparc: iommu/pci_sun4v: fix page alignment in dma mapping 2026-02-17 17:25 ` Leon Romanovsky @ 2026-02-17 17:33 ` Stian Halseth 2026-02-17 17:52 ` Leon Romanovsky 0 siblings, 1 reply; 15+ messages in thread From: Stian Halseth @ 2026-02-17 17:33 UTC (permalink / raw) To: Leon Romanovsky, John Paul Adrian Glaubitz Cc: Marek Szyprowski, David Miller, Andreas Larsson, sparclinux, linux-kernel Hi Leon, On Tue, 2026-02-17 at 19:25 +0200, Leon Romanovsky wrote: > > > On Tue, Feb 17, 2026, at 19:16, John Paul Adrian Glaubitz wrote: > > Hi Stian, > > > > On Tue, 2026-02-17 at 17:48 +0100, Stian Halseth wrote: > > > 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@itx.no wrote: > > > > > From: Stian Halseth <stian@itx.no> > > > > > > > > > > '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. > > > > Perfect! I have nothing to add. Let's have Andreas review your > > patch ;-). > > Please add Fixes line, so the patch will be taken to stable@ in > automatic way. I currently have: Fixes: 38c0d0ebf520 ("sparc: Use physical address DMA mapping") Is this sufficient, or do I need to add something else? > > Thanks > > > > > Adrian > > > > -- > > .''`. John Paul Adrian Glaubitz > > : :' : Debian Developer > > `. `' Physicist > > `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913 -- Best regards Stian Halseth ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] sparc: iommu/pci_sun4v: fix page alignment in dma mapping 2026-02-17 17:33 ` Stian Halseth @ 2026-02-17 17:52 ` Leon Romanovsky 2026-02-17 19:41 ` Stian Halseth 0 siblings, 1 reply; 15+ messages in thread From: Leon Romanovsky @ 2026-02-17 17:52 UTC (permalink / raw) To: Stian Halseth, John Paul Adrian Glaubitz Cc: Marek Szyprowski, David Miller, Andreas Larsson, sparclinux, linux-kernel On Tue, Feb 17, 2026, at 19:33, Stian Halseth wrote: > Hi Leon, > > > On Tue, 2026-02-17 at 19:25 +0200, Leon Romanovsky wrote: >> >> >> On Tue, Feb 17, 2026, at 19:16, John Paul Adrian Glaubitz wrote: >> > Hi Stian, >> > >> > On Tue, 2026-02-17 at 17:48 +0100, Stian Halseth wrote: >> > > 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@itx.no wrote: >> > > > > From: Stian Halseth <stian@itx.no> >> > > > > >> > > > > '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. >> > >> > Perfect! I have nothing to add. Let's have Andreas review your >> > patch ;-). >> >> Please add Fixes line, so the patch will be taken to stable@ in >> automatic way. > I currently have: > Fixes: 38c0d0ebf520 ("sparc: Use physical address DMA mapping") > > Is this sufficient, or do I need to add something else? Ohh, you added extra line between signed-of-by and fixes line. Just remove that extra blank line. Thanks >> >> Thanks >> >> > >> > Adrian >> > >> > -- >> > .''`. John Paul Adrian Glaubitz >> > : :' : Debian Developer >> > `. `' Physicist >> > `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913 > > -- > Best regards > Stian Halseth > ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] sparc: iommu/pci_sun4v: fix page alignment in dma mapping 2026-02-17 17:52 ` Leon Romanovsky @ 2026-02-17 19:41 ` Stian Halseth 2026-02-17 19:43 ` John Paul Adrian Glaubitz 0 siblings, 1 reply; 15+ messages in thread From: Stian Halseth @ 2026-02-17 19:41 UTC (permalink / raw) To: Leon Romanovsky, John Paul Adrian Glaubitz Cc: Marek Szyprowski, David Miller, Andreas Larsson, sparclinux, linux-kernel On Tue, 2026-02-17 at 19:52 +0200, Leon Romanovsky wrote: > > > On Tue, Feb 17, 2026, at 19:33, Stian Halseth wrote: > > Hi Leon, > > > > > > On Tue, 2026-02-17 at 19:25 +0200, Leon Romanovsky wrote: > > > > > > > > > On Tue, Feb 17, 2026, at 19:16, John Paul Adrian Glaubitz wrote: > > > > Hi Stian, > > > > > > > > On Tue, 2026-02-17 at 17:48 +0100, Stian Halseth wrote: > > > > > 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@itx.no wrote: > > > > > > > From: Stian Halseth <stian@itx.no> > > > > > > > > > > > > > > '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. > > > > > > > > Perfect! I have nothing to add. Let's have Andreas review your > > > > patch ;-). > > > > > > Please add Fixes line, so the patch will be taken to stable@ in > > > automatic way. > > I currently have: > > Fixes: 38c0d0ebf520 ("sparc: Use physical address DMA mapping") > > > > Is this sufficient, or do I need to add something else? > > Ohh, you added extra line between signed-of-by and fixes line. > > Just remove that extra blank line. > > Thanks Ah, I see what you mean now. There _was_ an extra line in the first submitted patch [1]. This is not the case in the updated patch v2 [2], submitted Tue, 17 Feb 2026 17:21:13 +0100. Let me know if there's still an issue with the latest patch, or if I've made a mistake when submitting it. My first patch to LKML, sorry about the extra work :) > > > > > > > Thanks > > > > > > > > > > > Adrian > > > > > > > > -- > > > > .''`. John Paul Adrian Glaubitz > > > > : :' : Debian Developer > > > > `. `' Physicist > > > > `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913 > > > > -- > > Best regards > > Stian Halseth > > [1] https://lkml.org/lkml/2026/2/17/845 [2] https://lkml.org/lkml/2026/2/17/908 -- Best regards Stian Halseth ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] sparc: iommu/pci_sun4v: fix page alignment in dma mapping 2026-02-17 19:41 ` Stian Halseth @ 2026-02-17 19:43 ` John Paul Adrian Glaubitz 0 siblings, 0 replies; 15+ messages in thread From: John Paul Adrian Glaubitz @ 2026-02-17 19:43 UTC (permalink / raw) To: Stian Halseth, Leon Romanovsky Cc: Marek Szyprowski, David Miller, Andreas Larsson, sparclinux, linux-kernel Hi Stian, On Tue, 2026-02-17 at 20:41 +0100, Stian Halseth wrote: > Let me know if there's still an issue with the latest patch, or if I've > made a mistake when submitting it. My first patch to LKML, sorry about > the extra work :) No need to apologize, you're doing a fantastic job! ;-) Adrian -- .''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2] sparc: Fix page alignment in dma mapping 2026-02-17 16:38 ` John Paul Adrian Glaubitz 2026-02-17 16:48 ` Stian Halseth @ 2026-02-17 17:10 ` stian 2026-02-18 8:48 ` Leon Romanovsky 2026-02-18 10:28 ` Marek Szyprowski 1 sibling, 2 replies; 15+ messages in thread From: stian @ 2026-02-17 17:10 UTC (permalink / raw) To: John Paul Adrian Glaubitz Cc: Stian Halseth, Marek Szyprowski, David S. Miller, Andreas Larsson, Leon Romanovsky, sparclinux, linux-kernel From: Stian Halseth <stian@itx.no> '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, covering both generic SPARC code and sun4v. Fixes: 38c0d0ebf520 ("sparc: Use physical address DMA mapping") Reported-by: Stian Halseth <stian@itx.no> Closes: https://github.com/sparclinux/issues/issues/75 Suggested-by: Marek Szyprowski <m.szyprowski@samsung.com> Signed-off-by: Stian Halseth <stian@itx.no> --- 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; } -- 2.53.0 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v2] sparc: Fix page alignment in dma mapping 2026-02-17 17:10 ` [PATCH v2] sparc: Fix " stian @ 2026-02-18 8:48 ` Leon Romanovsky 2026-02-18 10:28 ` Marek Szyprowski 1 sibling, 0 replies; 15+ messages in thread From: Leon Romanovsky @ 2026-02-18 8:48 UTC (permalink / raw) To: stian Cc: John Paul Adrian Glaubitz, Marek Szyprowski, David S. Miller, Andreas Larsson, sparclinux, linux-kernel On Tue, Feb 17, 2026 at 06:10:19PM +0100, stian@itx.no wrote: > From: Stian Halseth <stian@itx.no> > > '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, covering both generic SPARC code and sun4v. > > Fixes: 38c0d0ebf520 ("sparc: Use physical address DMA mapping") > Reported-by: Stian Halseth <stian@itx.no> > Closes: https://github.com/sparclinux/issues/issues/75 > Suggested-by: Marek Szyprowski <m.szyprowski@samsung.com> > Signed-off-by: Stian Halseth <stian@itx.no> > --- > arch/sparc/kernel/iommu.c | 2 ++ > arch/sparc/kernel/pci_sun4v.c | 2 +- > 2 files changed, 3 insertions(+), 1 deletion(-) > Thanks, Reviewed-by: Leon Romanovsky <leon@kernel.org> ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2] sparc: Fix page alignment in dma mapping 2026-02-17 17:10 ` [PATCH v2] sparc: Fix " stian 2026-02-18 8:48 ` Leon Romanovsky @ 2026-02-18 10:28 ` Marek Szyprowski 2026-02-18 11:09 ` Stian Halseth 1 sibling, 1 reply; 15+ messages in thread From: Marek Szyprowski @ 2026-02-18 10:28 UTC (permalink / raw) To: stian, John Paul Adrian Glaubitz Cc: David S. Miller, Andreas Larsson, Leon Romanovsky, sparclinux, linux-kernel On 17.02.2026 18:10, stian@itx.no wrote: > From: Stian Halseth <stian@itx.no> > > '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, covering both generic SPARC code and sun4v. > > Fixes: 38c0d0ebf520 ("sparc: Use physical address DMA mapping") > Reported-by: Stian Halseth <stian@itx.no> > Closes: https://protect2.fireeye.com/v1/url?k=4d8fbc00-1214850c-4d8e374f-000babff3563-ee1be24be576e072&q=1&e=0f8967ce-f558-4339-bddb-f324ec46c035&u=https%3A%2F%2Fgithub.com%2Fsparclinux%2Fissues%2Fissues%2F75 > Suggested-by: Marek Szyprowski <m.szyprowski@samsung.com> > Signed-off-by: Stian Halseth <stian@itx.no> > --- > 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); > + I've just noticed that IO_PAGE_SIZE might not equal to PAGE_SIZE (not sure if this is true in case of SPARCs), so it would be better to rely on IO_PAGE_MASK or IO_PAGE_SIZE only. Just unify the fix for the both affected functions either by masking phys with IO_PAGE_SIZE where it is used or by subtracting (phys & ~IO_PAGE_MASK) from it. > 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; > } Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2] sparc: Fix page alignment in dma mapping 2026-02-18 10:28 ` Marek Szyprowski @ 2026-02-18 11:09 ` Stian Halseth 2026-02-18 11:14 ` Leon Romanovsky 2026-02-18 11:40 ` Marek Szyprowski 0 siblings, 2 replies; 15+ messages in thread From: Stian Halseth @ 2026-02-18 11:09 UTC (permalink / raw) To: Marek Szyprowski, John Paul Adrian Glaubitz Cc: David S. Miller, Andreas Larsson, Leon Romanovsky, sparclinux, linux-kernel On Wed, 2026-02-18 at 11:28 +0100, Marek Szyprowski wrote: > On 17.02.2026 18:10, stian@itx.no wrote: > > From: Stian Halseth <stian@itx.no> > > > > '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, covering both generic SPARC code and sun4v. > > > > Fixes: 38c0d0ebf520 ("sparc: Use physical address DMA mapping") > > Reported-by: Stian Halseth <stian@itx.no> > > Closes: https://protect2.fireeye.com/v1/url?k=4d8fbc00-1214850c- > > 4d8e374f-000babff3563-ee1be24be576e072&q=1&e=0f8967ce-f558-4339- > > bddb- > > f324ec46c035&u=https%3A%2F%2Fgithub.com%2Fsparclinux%2Fissues%2Fiss > > ues%2F75 > > Suggested-by: Marek Szyprowski <m.szyprowski@samsung.com> > > Signed-off-by: Stian Halseth <stian@itx.no> > > --- > > 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); > > + > > I've just noticed that IO_PAGE_SIZE might not equal to PAGE_SIZE (not > sure if this is true in case of SPARCs), so it would be better to > rely > on IO_PAGE_MASK or IO_PAGE_SIZE only. Just unify the fix for the both > affected functions either by masking phys with IO_PAGE_SIZE where it > is > used or by subtracting (phys & ~IO_PAGE_MASK) from it. > Good point, and thanks for the review. I failed to consider that the offset_in_page is based on PAGE_SIZE, not IO_PAGE_SIZE. Suggestion, subtract IO_PAGE_MASK in both functions. arch/sparc/kernel/iommu.c: -phys -= offset_in_page(phys) +phys &= IO_PAGE_MASK; arch/sparc/kernel/pci_sun4v.c (better to subtract before loop?): +phys &= IO_PAGE_MASK; for (i = 0; i < npages; i++, phys += IO_PAGE_SIZE) { -long err = iommu_batch_add(phys & IO_PAGE_MASK, mask); +long err = iommu_batch_add(phys, mask); if (unlikely(err < 0L)) goto iommu_map_fail; } Is this acceptable, and in line with kernel coding style? If yes, I can submit patch v3 with this proposed change. And Patch v3, should be sent using the message ID of this review response, right? Still learning :) > > 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; > > } > > Best regards -- Med vennlig hilsen Stian Halseth Mobile +47 406 77 777 Office(dir) +47 236 80 400 (402) E-mail stian@itx.no ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2] sparc: Fix page alignment in dma mapping 2026-02-18 11:09 ` Stian Halseth @ 2026-02-18 11:14 ` Leon Romanovsky 2026-02-18 11:40 ` Marek Szyprowski 1 sibling, 0 replies; 15+ messages in thread From: Leon Romanovsky @ 2026-02-18 11:14 UTC (permalink / raw) To: Stian Halseth Cc: Marek Szyprowski, John Paul Adrian Glaubitz, David S. Miller, Andreas Larsson, sparclinux, linux-kernel On Wed, Feb 18, 2026 at 12:09:06PM +0100, Stian Halseth wrote: > On Wed, 2026-02-18 at 11:28 +0100, Marek Szyprowski wrote: > > On 17.02.2026 18:10, stian@itx.no wrote: > > > From: Stian Halseth <stian@itx.no> > > > > > > '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, covering both generic SPARC code and sun4v. > > > > > > Fixes: 38c0d0ebf520 ("sparc: Use physical address DMA mapping") > > > Reported-by: Stian Halseth <stian@itx.no> > > > Closes: https://protect2.fireeye.com/v1/url?k=4d8fbc00-1214850c- > > > 4d8e374f-000babff3563-ee1be24be576e072&q=1&e=0f8967ce-f558-4339- > > > bddb- > > > f324ec46c035&u=https%3A%2F%2Fgithub.com%2Fsparclinux%2Fissues%2Fiss > > > ues%2F75 > > > Suggested-by: Marek Szyprowski <m.szyprowski@samsung.com> > > > Signed-off-by: Stian Halseth <stian@itx.no> > > > --- > > > 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); > > > + > > > > I've just noticed that IO_PAGE_SIZE might not equal to PAGE_SIZE (not > > sure if this is true in case of SPARCs), so it would be better to > > rely > > on IO_PAGE_MASK or IO_PAGE_SIZE only. Just unify the fix for the both > > affected functions either by masking phys with IO_PAGE_SIZE where it > > is > > used or by subtracting (phys & ~IO_PAGE_MASK) from it. > > > > Good point, and thanks for the review. > > I failed to consider that the offset_in_page is based on PAGE_SIZE, not > IO_PAGE_SIZE. > > Suggestion, subtract IO_PAGE_MASK in both functions. > > arch/sparc/kernel/iommu.c: > -phys -= offset_in_page(phys) > +phys &= IO_PAGE_MASK; > > > arch/sparc/kernel/pci_sun4v.c (better to subtract before loop?): > +phys &= IO_PAGE_MASK; > > for (i = 0; i < npages; i++, phys += IO_PAGE_SIZE) { > -long err = iommu_batch_add(phys & IO_PAGE_MASK, mask); > +long err = iommu_batch_add(phys, mask); > if (unlikely(err < 0L)) > goto iommu_map_fail; > } > > Is this acceptable, and in line with kernel coding style? > > If yes, I can submit patch v3 with this proposed change. > > And Patch v3, should be sent using the message ID of this review > response, right? Still learning :) No, just send patch v3 without Reply-To field. Add changelog under --- trailer line and describe changes. Thanks ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2] sparc: Fix page alignment in dma mapping 2026-02-18 11:09 ` Stian Halseth 2026-02-18 11:14 ` Leon Romanovsky @ 2026-02-18 11:40 ` Marek Szyprowski 1 sibling, 0 replies; 15+ messages in thread From: Marek Szyprowski @ 2026-02-18 11:40 UTC (permalink / raw) To: Stian Halseth, John Paul Adrian Glaubitz Cc: David S. Miller, Andreas Larsson, Leon Romanovsky, sparclinux, linux-kernel On 18.02.2026 12:09, Stian Halseth wrote: > On Wed, 2026-02-18 at 11:28 +0100, Marek Szyprowski wrote: >> On 17.02.2026 18:10, stian@itx.no wrote: >>> From: Stian Halseth <stian@itx.no> >>> >>> '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, covering both generic SPARC code and sun4v. >>> >>> Fixes: 38c0d0ebf520 ("sparc: Use physical address DMA mapping") >>> Reported-by: Stian Halseth <stian@itx.no> >>> Closes: https://protect2.fireeye.com/v1/url?k=4d8fbc00-1214850c- >>> 4d8e374f-000babff3563-ee1be24be576e072&q=1&e=0f8967ce-f558-4339- >>> bddb- >>> f324ec46c035&u=https%3A%2F%2Fgithub.com%2Fsparclinux%2Fissues%2Fiss >>> ues%2F75 >>> Suggested-by: Marek Szyprowski <m.szyprowski@samsung.com> >>> Signed-off-by: Stian Halseth <stian@itx.no> >>> --- >>> 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); >>> + >> I've just noticed that IO_PAGE_SIZE might not equal to PAGE_SIZE (not >> sure if this is true in case of SPARCs), so it would be better to >> rely >> on IO_PAGE_MASK or IO_PAGE_SIZE only. Just unify the fix for the both >> affected functions either by masking phys with IO_PAGE_SIZE where it >> is >> used or by subtracting (phys & ~IO_PAGE_MASK) from it. >> > Good point, and thanks for the review. > > I failed to consider that the offset_in_page is based on PAGE_SIZE, not > IO_PAGE_SIZE. > > Suggestion, subtract IO_PAGE_MASK in both functions. > > arch/sparc/kernel/iommu.c: > -phys -= offset_in_page(phys) > +phys &= IO_PAGE_MASK; > > > arch/sparc/kernel/pci_sun4v.c (better to subtract before loop?): > +phys &= IO_PAGE_MASK; > > for (i = 0; i < npages; i++, phys += IO_PAGE_SIZE) { > -long err = iommu_batch_add(phys & IO_PAGE_MASK, mask); > +long err = iommu_batch_add(phys, mask); > if (unlikely(err < 0L)) > goto iommu_map_fail; > } > > Is this acceptable, and in line with kernel coding style? Yes, that's fine. > If yes, I can submit patch v3 with this proposed change. > > And Patch v3, should be sent using the message ID of this review > response, right? Still learning :) Usually the next version is being sent as a new thread. Just add a few lines of history and links to the previous attempt(s) to it, like for example here: https://lore.kernel.org/all/20260203102133.1478331-1-m.szyprowski@samsung.com/ Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2026-02-18 11:41 UTC | newest] Thread overview: 15+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-02-17 16:21 [PATCH] sparc: iommu/pci_sun4v: fix page alignment in dma mapping stian 2026-02-17 16:38 ` John Paul Adrian Glaubitz 2026-02-17 16:48 ` Stian Halseth 2026-02-17 17:16 ` John Paul Adrian Glaubitz 2026-02-17 17:25 ` Leon Romanovsky 2026-02-17 17:33 ` Stian Halseth 2026-02-17 17:52 ` Leon Romanovsky 2026-02-17 19:41 ` Stian Halseth 2026-02-17 19:43 ` John Paul Adrian Glaubitz 2026-02-17 17:10 ` [PATCH v2] sparc: Fix " stian 2026-02-18 8:48 ` Leon Romanovsky 2026-02-18 10:28 ` Marek Szyprowski 2026-02-18 11:09 ` Stian Halseth 2026-02-18 11:14 ` Leon Romanovsky 2026-02-18 11:40 ` Marek Szyprowski
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.