[PATCH 2/2] iommu: debug-pagealloc: Fix mappings starting at phys 0
From: Mostafa Saleh
Date: Mon Nov 30 2026 - 11:47:39 EST
__iommu_debug_map() warns and counts nothing when phys is 0, but unmap
only skips the page that iommu_iova_to_phys() reports as 0 and
decrements the others,
Unmapping a multi-page mapping that starts at physical address 0
therefore underflows every other page.
Physical address 0 is a valid target. Drop the warning and skip only
that page, as unmap does.
Fixes: 7e84593795b3 ("iommu: debug-pagealloc: Track IOMMU pages")
Signed-off-by: Mostafa Saleh <smostafa@xxxxxxxxxx>
---
drivers/iommu/iommu-debug-pagealloc.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/iommu-debug-pagealloc.c b/drivers/iommu/iommu-debug-pagealloc.c
index fb6e06d42102..24397eecd6cc 100644
--- a/drivers/iommu/iommu-debug-pagealloc.c
+++ b/drivers/iommu/iommu-debug-pagealloc.c
@@ -102,11 +102,16 @@ void __iommu_debug_map(struct iommu_domain *domain, phys_addr_t phys, size_t siz
phys_addr_t end;
size_t page_size = iommu_debug_page_size(domain);
- if (WARN_ON(!phys || check_add_overflow(phys, size, &end)))
+ if (WARN_ON(check_add_overflow(phys, size, &end)))
return;
- for (off = 0 ; off < size ; off += page_size)
+ for (off = 0 ; off < size ; off += page_size) {
+ /* Unmap cannot tell PA 0 from an unmapped IOVA */
+ if (!(phys + off))
+ continue;
+
iommu_debug_inc_page(phys + off);
+ }
}
static void __iommu_debug_update_iova(struct iommu_domain *domain,
--
2.56.1.839.g22a8290db9-goog