* [PATCH] iommu/riscv: Remove overflows on the invalidation path
@ 2026-03-27 15:22 Jason Gunthorpe
2026-04-02 7:36 ` Joerg Roedel
2026-04-30 3:25 ` patchwork-bot+linux-riscv
0 siblings, 2 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2026-03-27 15:22 UTC (permalink / raw)
To: Alexandre Ghiti, Albert Ou, iommu, Joerg Roedel, linux-riscv,
Palmer Dabbelt, Paul Walmsley, Robin Murphy, Will Deacon
Cc: Lu Baolu, Joerg Roedel, Palmer Dabbelt, patches, Tomasz Jeznach,
Zong Li
Since RISC-V supports a sign extended page table it should support
a gather->end of ULONG_MAX, but if this happens it will infinite loop
because of the overflow.
Also avoid overflow computing the length by moving the +1 to the other
side of the <
Fixes: 488ffbf18171 ("iommu/riscv: Paging domain support")
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
drivers/iommu/riscv/iommu.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c
index 368f3cbd2d0a96..a31f50bbad3535 100644
--- a/drivers/iommu/riscv/iommu.c
+++ b/drivers/iommu/riscv/iommu.c
@@ -934,8 +934,6 @@ static void riscv_iommu_iotlb_inval(struct riscv_iommu_domain *domain,
struct riscv_iommu_bond *bond;
struct riscv_iommu_device *iommu, *prev;
struct riscv_iommu_command cmd;
- unsigned long len = end - start + 1;
- unsigned long iova;
/*
* For each IOMMU linked with this protection domain (via bonds->dev),
@@ -978,11 +976,14 @@ static void riscv_iommu_iotlb_inval(struct riscv_iommu_domain *domain,
riscv_iommu_cmd_inval_vma(&cmd);
riscv_iommu_cmd_inval_set_pscid(&cmd, domain->pscid);
- if (len && len < RISCV_IOMMU_IOTLB_INVAL_LIMIT) {
- for (iova = start; iova < end; iova += PAGE_SIZE) {
+ if (end - start < RISCV_IOMMU_IOTLB_INVAL_LIMIT - 1) {
+ unsigned long iova = start;
+
+ do {
riscv_iommu_cmd_inval_set_addr(&cmd, iova);
riscv_iommu_cmd_send(iommu, &cmd);
- }
+ } while (!check_add_overflow(iova, PAGE_SIZE, &iova) &&
+ iova < end);
} else {
riscv_iommu_cmd_send(iommu, &cmd);
}
base-commit: cbb4dc8cd574b387c7811af91006476c5fa98285
--
2.43.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] iommu/riscv: Remove overflows on the invalidation path
2026-03-27 15:22 [PATCH] iommu/riscv: Remove overflows on the invalidation path Jason Gunthorpe
@ 2026-04-02 7:36 ` Joerg Roedel
2026-04-30 3:25 ` patchwork-bot+linux-riscv
1 sibling, 0 replies; 3+ messages in thread
From: Joerg Roedel @ 2026-04-02 7:36 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Alexandre Ghiti, Albert Ou, iommu, linux-riscv, Palmer Dabbelt,
Paul Walmsley, Robin Murphy, Will Deacon, Lu Baolu, Joerg Roedel,
Palmer Dabbelt, patches, Tomasz Jeznach, Zong Li
On Fri, Mar 27, 2026 at 12:22:10PM -0300, Jason Gunthorpe wrote:
> drivers/iommu/riscv/iommu.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
Applied, thanks.
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iommu/riscv: Remove overflows on the invalidation path
2026-03-27 15:22 [PATCH] iommu/riscv: Remove overflows on the invalidation path Jason Gunthorpe
2026-04-02 7:36 ` Joerg Roedel
@ 2026-04-30 3:25 ` patchwork-bot+linux-riscv
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+linux-riscv @ 2026-04-30 3:25 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: linux-riscv, alex, aou, iommu, joro, palmer, pjw, robin.murphy,
will, baolu.lu, jroedel, palmer, patches, tjeznach, zong.li
Hello:
This patch was applied to riscv/linux.git (fixes)
by Joerg Roedel <joerg.roedel@amd.com>:
On Fri, 27 Mar 2026 12:22:10 -0300 you wrote:
> Since RISC-V supports a sign extended page table it should support
> a gather->end of ULONG_MAX, but if this happens it will infinite loop
> because of the overflow.
>
> Also avoid overflow computing the length by moving the +1 to the other
> side of the <
>
> [...]
Here is the summary with links:
- iommu/riscv: Remove overflows on the invalidation path
https://git.kernel.org/riscv/c/40a13b499579
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-30 3:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-27 15:22 [PATCH] iommu/riscv: Remove overflows on the invalidation path Jason Gunthorpe
2026-04-02 7:36 ` Joerg Roedel
2026-04-30 3:25 ` patchwork-bot+linux-riscv
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox