Hi Ulad

On 2026/11/19 03:50, Uladzislau Rezki wrote:
> On Mon, Nov 16, 2026 at 03:13:20PM +0800, Hao Ge wrote:
>> ioremap and arch setup code map their ranges with vmap_page_range().
>> When the walk fails half way, or the KMSAN metadata fails after the
>> walk, the ptes installed so far stay behind. The caller frees the
>> vm_area on the error path, so the next mapping that lands on the same
>> range trips the BUG() in vmap_pte_range().
>>
>> vmap_range_noflush() now takes a mapped_end argument that the walk
>> levels advance as they install, and vmap_pte_range() BUG()s before
>> it installs over a pte that is already set. The ptes below mapped_end
>> are therefore all ours, while a pte above it can only have been put
>> there by somebody else, for example when the caller's range overlaps
>> an existing mapping. On a walk failure the undo is limited to
>> [addr, mapped_end), going further would clear ptes that are not
>> ours. If the walk completed and only the KMSAN metadata failed, the
>> whole range was installed by this call and all of it is undone.
>>
>> All callers are sleepable, the teardown passes can_resched = true.
>>
>> Signed-off-by: Hao Ge <[email protected]>
>> ---
>>  mm/vmalloc.c | 52 +++++++++++++++++++++++++++++++++++++++-------------
>>  1 file changed, 39 insertions(+), 13 deletions(-)
>>
>> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
>> index d99d7710e1ba..5c1eacc2a0ac 100644
>> --- a/mm/vmalloc.c
>> +++ b/mm/vmalloc.c
>> @@ -117,7 +117,8 @@ static __always_inline unsigned long vmap_set_ptes(pte_t 
>> *ptep,
>>  
>>  static int vmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
>>                      phys_addr_t phys_addr, pgprot_t prot,
>> -                    unsigned int max_page_shift, pgtbl_mod_mask *mask)
>> +                    unsigned int max_page_shift, pgtbl_mod_mask *mask,
>> +                    unsigned long *mapped_end)
>>  {
>>      pte_t *pte;
>>      u64 pfn;
>> @@ -143,6 +144,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long 
>> addr, unsigned long end,
>>  
>>              size = vmap_set_ptes(pte, addr, end, pfn, prot, max_page_shift);
>>              nr_pages = PFN_DOWN(size);
>> +            *mapped_end = addr + size;
>>      } while (pte += nr_pages, pfn += nr_pages, addr += size, addr != end);
>>  
> vmap_pte_range() either s=install everything or nothing. At least if i
> do not miss anything.

Right, vmap_pte_range() either installs the whole range or nothing.

I will drop the mapped_end argument from it, and vmap_pmd_range() will
advance *mapped_end = next after the call succeeds.

Thanks
Best Regards
Hao

> 
> --
> Uladzislau Rezki
> 
> --
> Uladzislau Rezki

Reply via email to