[PATCH v13 3/5] mm/vmalloc: use physical page count in vread_iter()
From: Shivam Kalra via B4 Relay
Date: Mon May 11 2026 - 04:20:23 EST
From: Shivam Kalra <shivamkalra98@xxxxxxxxxxx>
Update vread_iter() to derive the vm area size from vm->nr_pages rather
than get_vm_area_size().
Currently both values are equivalent, but the upcoming vrealloc() shrink
functionality will free pages without reducing the virtual reservation
size. After such a shrink, the old get_vm_area_size() based calculation
would overestimate the mapped range, causing vread_iter() to attempt
reading from unmapped addresses. Switch to vm->nr_pages now so the
reader remains correct once shrink support is added.
Reviewed-by: Uladzislau Rezki (Sony) <urezki@xxxxxxxxx>
Signed-off-by: Shivam Kalra <shivamkalra98@xxxxxxxxxxx>
---
mm/vmalloc.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 87278cf2046e..d69174afb171 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -4666,7 +4666,14 @@ long vread_iter(struct iov_iter *iter, const char *addr, size_t count)
smp_rmb();
vaddr = (char *) va->va_start;
- size = vm ? get_vm_area_size(vm) : va_size(va);
+ if (vm)
+ /*
+ * Cannot use get_vm_area_size() because realloc()
+ * may shrink the mapping and area->size may be outdated.
+ */
+ size = vm->nr_pages << PAGE_SHIFT;
+ else
+ size = va_size(va);
if (addr >= vaddr + size)
goto next_va;
--
2.43.0