sparc: iommu/pci_sun4v: fix page alignment in dma mapping
PATCH 1/1 sparc: iommu/pci_sun4v: fix page alignment in dma mapping
From: Stian Halseth <[email protected]>
'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.
--- arch/sparc/kernel/iommu.c | 2 ++ arch/sparc/kernel/pci_sun4v.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
arch/sparc/kernel/iommu.c +2 -0
@@ -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;
arch/sparc/kernel/pci_sun4v.c +1 -1
@@ -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; }
Signature · 1 line
2.53.0
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.
Quoted 7 lines · On Tue, 2026-02-17 at 17:21 +0100, [email protected] wrote:
From: Stian Halseth <[email protected]>
'phys' may include an offset within the page, while '
base_paddr' is already page-aligned.This caused incorrect DMA mapping in
dma_4u_map_physanddma_4v_map_phys.Fix both functions by masking phys with
IO_PAGE_MASKor subtracting the page offset.
Please remove the newlines between your sentences, they're not necessary and also trim the lines at 80 columns.
Quoted 28 lines
Fixes 38c0d0ebf520 ("sparc: Use physical address DMA mapping")Reported-by Stian Halseth <[email protected]>Suggested-by Marek Szyprowski <[email protected]>Signed-off-by Stian Halseth <[email protected]>--- arch/sparc/kernel/iommu.c | 2 ++ arch/sparc/kernel/pci_sun4v.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)arch/sparc/kernel/iommu.c +2
-0@@ -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;arch/sparc/kernel/pci_sun4v.c +0
-0
arch/sparc/kernel/pci_sun4v.c static dma_addr_t dma_4v_map_phys(struct device *dev, phys_addr_t phys, · line 417
Quoted 8 lines
arch/sparc/kernel/pci_sun4v.c +1
-1@@ -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
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Hi Adrian,
Thanks for the review and suggestions.
Quoted 10 lines · John Paul Adrian Glaubitz
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.
Quoted 9 lines · On Tue, 2026-02-17 at 17:21 +0100, [email protected] wrote:
Quoted 8 lines
From: Stian Halseth <[email protected]>
'phys' may include an offset within the page, while '
base_paddr' is already page-aligned.This caused incorrect DMA mapping in
dma_4u_map_physanddma_4v_map_phys.
Quoted 6 lines
Quoted 2 lines
Fix both functions by masking phys with
IO_PAGE_MASKor 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.
Quoted 42 lines
Quoted 32 lines
Fixes 38c0d0ebf520 ("sparc: Use physical address DMA mapping")Reported-by Stian Halseth <[email protected]>Suggested-by Marek Szyprowski <[email protected]>Signed-off-by Stian Halseth <[email protected]>---
arch/sparc/kernel/iommu.c | 2 ++
arch/sparc/kernel/pci_sun4v.c | 2 +-2 files changed, 3 insertions(+), 1 deletion(-)arch/sparc/kernel/iommu.c +0
-0@@ -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;arch/sparc/kernel/pci_sun4v.c +0
-0@@ -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);Quoted 7 lines
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))
gotoiommu_map_fail;
}Looks good to me otherwise.
Quoted 2 lines
Adrian
I’ll send an updated patch (v2) shortly with these changes applied.
Thanks again for reviewing.
Signature · 2 lines
Med vennlig hilsen Stian Halseth
Hi Stian,
Quoted 26 lines · Stian Halseth
Thanks for the review and suggestions.
Quoted 10 lines · John Paul Adrian Glaubitz
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.
Quoted 12 lines · On Tue, 2026-02-17 at 17:21 +0100, [email protected] wrote:
Quoted 10 lines
From: Stian Halseth <[email protected]>
'phys' may include an offset within the page, while '
base_paddr' is already page-aligned.This caused incorrect DMA mapping in
dma_4u_map_physanddma_4v_map_phys.Fix both functions by masking phys with
IO_PAGE_MASKor subtracting the page offset.
Quoted 6 lines
Quoted 3 lines
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
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Quoted 29 lines · John Paul Adrian Glaubitz
Hi Stian,
Quoted 26 lines · Stian Halseth
Thanks for the review and suggestions.
Quoted 10 lines · John Paul Adrian Glaubitz
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.
Quoted 12 lines · On Tue, 2026-02-17 at 17:21 +0100, [email protected] wrote:
Quoted 10 lines
From: Stian Halseth <[email protected]>
'phys' may include an offset within the page, while '
base_paddr' is already page-aligned.This caused incorrect DMA mapping in
dma_4u_map_physanddma_4v_map_phys.Fix both functions by masking phys with
IO_PAGE_MASKor subtracting the page offset.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
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
Quoted 8 lines
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Hi Leon,
Quoted 41 lines · Leon Romanovsky
Quoted 38 lines · John Paul Adrian Glaubitz
Hi Stian,
Quoted 35 lines · Stian Halseth
Thanks for the review and suggestions.
Quoted 4 lines · John Paul Adrian Glaubitz
Hi Stian,
please rephrase the subject to:
Quoted 8 lines
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.
Quoted 17 lines · On Tue, 2026-02-17 at 17:21 +0100, [email protected] wrote:
Quoted 6 lines
From: Stian Halseth <[email protected]>
'phys' may include an offset within the page, while '
base_paddr' is
already page-aligned.Quoted 6 lines
This caused incorrect DMA mapping in
dma_4u_map_physanddma_4v_map_phys.Fix both functions by masking phys with
IO_PAGE_MASKor subtracting
the page offset.Please remove the newlines between your sentences, they're not necessary
and also trim the lines at 80 columns.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
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:
Is this sufficient, or do I need to add something else?
Quoted 11 lines
Thanks
Quoted 8 lines
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Signature · 3 lines
Best regards Stian Halseth
Quoted 51 lines · Stian Halseth
Hi Leon,
Quoted 47 lines · Leon Romanovsky
Quoted 43 lines · John Paul Adrian Glaubitz
Hi Stian,
Quoted 31 lines · Stian Halseth
Thanks for the review and suggestions.
Quoted 4 lines · John Paul Adrian Glaubitz
Hi Stian,
please rephrase the subject to:
Quoted 8 lines
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.
Quoted 14 lines · On Tue, 2026-02-17 at 17:21 +0100, [email protected] wrote:
Quoted 12 lines
From: Stian Halseth <[email protected]>
'phys' may include an offset within the page, while '
base_paddr' is
already page-aligned.This caused incorrect DMA mapping in
dma_4u_map_physanddma_4v_map_phys.Fix both functions by masking phys with
IO_PAGE_MASKor subtracting
the page offset.Quoted 6 lines
Quoted 3 lines
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 ;-).
Quoted 6 lines
Quoted 2 lines
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
Quoted 16 lines
Quoted 11 lines
Thanks
Quoted 8 lines
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913Signature · 3 lines
Best regards Stian Halseth
Quoted 60 lines · Leon Romanovsky
Quoted 57 lines · Stian Halseth
Hi Leon,
Quoted 42 lines · Leon Romanovsky
Quoted 39 lines · John Paul Adrian Glaubitz
Hi Stian,
Quoted 36 lines · Stian Halseth
Thanks for the review and suggestions.
Quoted 4 lines · John Paul Adrian Glaubitz
Hi Stian,
please rephrase the subject to:
Quoted 8 lines
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.
Quoted 18 lines · On Tue, 2026-02-17 at 17:21 +0100, [email protected] wrote:
Quoted 6 lines
From: Stian Halseth <[email protected]>
'phys' may include an offset within the page, while '
base_paddr' is
already page-aligned.Quoted 6 lines
This caused incorrect DMA mapping in
dma_4u_map_physanddma_4v_map_phys.Fix both functions by masking phys with
IO_PAGE_MASKor subtracting
the page offset.Please remove the newlines between your sentences, they're not
necessary
and also trim the lines at 80 columns.Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
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")
Quoted 7 lines
Quoted 1 line
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 :)
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Thanks
Quoted 8 lines
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Quoted 4 lines
Quoted 4 lines
Signature · 3 lines
Best regards Stian Halseth
[1] https://lkml.org/lkml/2026/2/17/845
[2] https://lkml.org/lkml/2026/2/17/908
Signature · 3 lines
Best regards Stian Halseth
Hi Stian,
Quoted 3 lines · Stian Halseth
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
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
PATCH v2 1/1 sparc: Fix page alignment in dma mapping
In reply to John Paul Adrian GlaubitzFrom: Stian Halseth <[email protected]>
'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.
--- arch/sparc/kernel/iommu.c | 2 ++ arch/sparc/kernel/pci_sun4v.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
arch/sparc/kernel/iommu.c +2 -0
@@ -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;
arch/sparc/kernel/pci_sun4v.c +1 -1
@@ -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; }
Signature · 1 line
2.53.0
Re: [PATCH v2] sparc: Fix page alignment in dma mapping
Quoted 14 lines · On Tue, Feb 17, 2026 at 06:10:19PM +0100, [email protected] wrote:
From: Stian Halseth <[email protected]>
'phys' may include an offset within the page, while '
base_paddr' is already page-aligned. This caused incorrect DMA mapping indma_4u_map_physanddma_4v_map_phys.Fix both functions by masking phys with
IO_PAGE_MASKor subtracting the page offset, covering both generic SPARC code and sun4v.Fixes 38c0d0ebf520 ("sparc: Use physical address DMA mapping")Reported-by Stian Halseth <[email protected]>Suggested-by Marek Szyprowski <[email protected]>Signed-off-by Stian Halseth <[email protected]>
Quoted 5 lines
--- arch/sparc/kernel/iommu.c | 2 ++ arch/sparc/kernel/pci_sun4v.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
Thanks,
Re: [PATCH v2] sparc: Fix page alignment in dma mapping
In reply to [email protected]Quoted 24 lines · On 17.02.2026 18:10, [email protected] wrote:
From: Stian Halseth <[email protected]>
'phys' may include an offset within the page, while '
base_paddr' is already page-aligned. This caused incorrect DMA mapping indma_4u_map_physanddma_4v_map_phys.Fix both functions by masking phys with
IO_PAGE_MASKor subtracting the page offset, covering both generic SPARC code and sun4v.Fixes 38c0d0ebf520 ("sparc: Use physical address DMA mapping")Reported-by Stian Halseth <[email protected]>Suggested-by Marek Szyprowski <[email protected]>Signed-off-by Stian Halseth <[email protected]>--- arch/sparc/kernel/iommu.c | 2 ++ arch/sparc/kernel/pci_sun4v.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)arch/sparc/kernel/iommu.c +0
-0
arch/sparc/kernel/iommu.c static dma_addr_t dma_4u_map_phys(struct device *dev, phys_addr_t phys, · line 316
Quoted 5 lines
arch/sparc/kernel/iommu.c +2
-0@@ -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.
Quoted 8 lines
arch/sparc/kernel/iommu.c +0
-0for (i =0 ; i < npages; i++, base++, phys +=IO_PAGE_SIZE )iopte_val (*base) = iopte_protection | phys;arch/sparc/kernel/pci_sun4v.c +0
-0
arch/sparc/kernel/pci_sun4v.c static dma_addr_t dma_4v_map_phys(struct device *dev, phys_addr_t phys, · line 417
Quoted 8 lines
arch/sparc/kernel/pci_sun4v.c +1
-1@@ -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
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
Re: [PATCH v2] sparc: Fix page alignment in dma mapping
Quoted 39 lines · Marek Szyprowski
Quoted 34 lines · On 17.02.2026 18:10, [email protected] wrote:
From: Stian Halseth <[email protected]>
'phys' may include an offset within the page, while '
base_paddr' is already
page-aligned. This caused incorrect DMA mapping indma_4u_map_physanddma_4v_map_phys.Fix both functions by masking phys with
IO_PAGE_MASKor subtracting the
page offset, covering both generic SPARC code and sun4v.Fixes 38c0d0ebf520 ("sparc: Use physical address DMA mapping")Reported-by Stian Halseth <[email protected]>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 <[email protected]>Signed-off-by Stian Halseth <[email protected]>---
arch/sparc/kernel/iommu.c | 2 ++
arch/sparc/kernel/pci_sun4v.c| 2 +-2 files changed, 3 insertions(+), 1 deletion(-)arch/sparc/kernel/iommu.c +0
-0@@ -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;Quoted 3 lines
+ phys -=offset_in_page(phys);
+
Quoted 8 lines
I've just noticed that
IO_PAGE_SIZEmight not equal toPAGE_SIZE(not sure if this is true in case of SPARCs), so it would be better to rely
onIO_PAGE_MASKorIO_PAGE_SIZEonly. Just unify the fix for the both affected functions either by masking phys withIO_PAGE_SIZEwhere 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 :)
Quoted 20 lines
Quoted 11 lines
for (i = 0; i < npages; i++, base++, phys +=
IO_PAGE_SIZE)iopte_val(*base)=iopte_protection| phys;arch/sparc/kernel/pci_sun4v.c +0
-0@@ -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);Quoted 7 lines
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))
gotoiommu_map_fail;
}Best regards
Signature · 6 lines
Med vennlig hilsen Stian Halseth Mobile +47 406 77 777 Office(dir) +47 236 80 400 (402) E-mail [email protected]
Re: [PATCH v2] sparc: Fix page alignment in dma mapping
Quoted 69 lines · Stian Halseth
Quoted 39 lines · Marek Szyprowski
Quoted 34 lines · On 17.02.2026 18:10, [email protected] wrote:
From: Stian Halseth <[email protected]>
'phys' may include an offset within the page, while '
base_paddr' is already
page-aligned. This caused incorrect DMA mapping indma_4u_map_physanddma_4v_map_phys.Fix both functions by masking phys with
IO_PAGE_MASKor subtracting the
page offset, covering both generic SPARC code and sun4v.Fixes 38c0d0ebf520 ("sparc: Use physical address DMA mapping")Reported-by Stian Halseth <[email protected]>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 <[email protected]>Signed-off-by Stian Halseth <[email protected]>---
arch/sparc/kernel/iommu.c | 2 ++
arch/sparc/kernel/pci_sun4v.c| 2 +-2 files changed, 3 insertions(+), 1 deletion(-)arch/sparc/kernel/iommu.c +0
-0@@ -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;Quoted 3 lines
+ phys -=offset_in_page(phys);
+Quoted 8 lines
I've just noticed that
IO_PAGE_SIZEmight not equal toPAGE_SIZE(not sure if this is true in case of SPARCs), so it would be better to rely
onIO_PAGE_MASKorIO_PAGE_SIZEonly. Just unify the fix for the both affected functions either by masking phys withIO_PAGE_SIZEwhere 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_pageis based onPAGE_SIZE, notIO_PAGE_SIZE.Suggestion, subtract
IO_PAGE_MASKin 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;
Quoted 8 lines
}
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
Re: [PATCH v2] sparc: Fix page alignment in dma mapping
In reply to Stian HalsethQuoted 62 lines · Stian Halseth
Quoted 36 lines · Marek Szyprowski
Quoted 35 lines · On 17.02.2026 18:10, [email protected] wrote:
From: Stian Halseth <[email protected]>
'phys' may include an offset within the page, while '
base_paddr' is already
page-aligned. This caused incorrect DMA mapping indma_4u_map_physanddma_4v_map_phys.Fix both functions by masking phys with
IO_PAGE_MASKor subtracting the
page offset, covering both generic SPARC code and sun4v.Fixes 38c0d0ebf520 ("sparc: Use physical address DMA mapping")Reported-by Stian Halseth <[email protected]>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 <[email protected]>Signed-off-by Stian Halseth <[email protected]>--- arch/sparc/kernel/iommu.c | 2 ++ arch/sparc/kernel/pci_sun4v.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)arch/sparc/kernel/iommu.c +0
-0@@ -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;Quoted 10 lines
arch/sparc/kernel/iommu.c static dma_addr_t dma_4u_map_phys(struct device *dev, phys_addr_t phys, · line 316
Quoted 2 lines
arch/sparc/kernel/iommu.c +2
-0+ phys -=offset_in_page (phys); +I've just noticed that
IO_PAGE_SIZEmight not equal toPAGE_SIZE(not sure if this is true in case of SPARCs), so it would be better to rely
onIO_PAGE_MASKorIO_PAGE_SIZEonly. Just unify the fix for the both affected functions either by masking phys withIO_PAGE_SIZEwhere 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_pageis based onPAGE_SIZE, notIO_PAGE_SIZE.Suggestion, subtract
IO_PAGE_MASKin 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;
Quoted 8 lines
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.
Quoted 4 lines
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/[email protected]/
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland