Re: [PATCH v4 4/9] mm/vmalloc: BUG_ON() on an unaligned range in vmap_pages_range_noflush_walk()
From: Hao Ge
Date: Sun Nov 15 2026 - 22:15:49 EST
Hi Ulad
On 2026/11/12 20:11, Uladzislau Rezki wrote:
> On Tue, Nov 10, 2026 at 07:25:41PM +0800, Hao Ge wrote:
>> The pte loop of vmap_pages_pte_range() maps whole pages and stops
>> only when addr lands exactly on end. An unaligned end lets addr
>> jump over it and the loop keeps mapping into whatever follows the
>> range. An unaligned start maps the page below the range with its
>> first pte. That corruption is impossible to debug afterwards, so
>> bug out on addr and end at the entry of
>> vmap_pages_range_noflush_walk().
>>
>> Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
>> Signed-off-by: Hao Ge <hao.ge@xxxxxxxxx>
>> ---
>> mm/vmalloc.c | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
>> index 27f2674a5556..86fbb1d2b27a 100644
>> --- a/mm/vmalloc.c
>> +++ b/mm/vmalloc.c
>> @@ -698,6 +698,8 @@ static int vmap_pages_range_noflush_walk(unsigned long addr, unsigned long end,
>> pgtbl_mod_mask mask = 0;
>>
>> BUG_ON(addr >= end);
>> + BUG_ON(!PAGE_ALIGNED(addr) || !PAGE_ALIGNED(end));
>> +
>>
> But why do we add this? We used to live without it and as far i see
> we have not gotten any report about any unaligned addresses un-maping.
>
> The vmap allocator grantees that va->va_start/end have to be page
> aligned.
You are right that no in-tree caller passes an unaligned range today.
This came about after looking at
commit a739e6b557af ("mm: vmalloc: WARN_ON if mapping size is not PAGE_SIZE aligned").
That commit only guards the ioremap family. vmap_pte_range() is reached
through vmap_page_range() only, so what it protects is ioremap_page_range(),
pci_remap_iospace() and friends, which map physically contiguous ranges.
vmap_pages_range_noflush_walk() has the same loop and serves the other half of the picture,
the virtually contiguous mappings, where the physical pages behind the range do not have to
be contiguous, and since functions like vmap_pages_range() take addr and end from the caller as
they are, the page alignment is the caller's contract in the first place, so this is the same idea
as a739e6b557af and the check just makes that contract visible.
That said, dropping this patch is also fine with me. Nobody can actually trigger it today, as I said at
the beginning, so I will drop it from the next version.
Thanks
Best Regards
Hao
>
> --
> Uladzislau Rezki