--- x/mm/filemap.c +++ y/mm/filemap.c @@ -3482,10 +3482,11 @@ static vm_fault_t filemap_map_folio_rang struct file *file = vma->vm_file; struct page *page = folio_page(folio, start); unsigned int mmap_miss = READ_ONCE(file->f_ra.mmap_miss); - unsigned int count = 0; + unsigned int count, i; pte_t *old_ptep = vmf->pte; - do { + count = 0; + for (i = 0; i < nr_pages; i++) { if (PageHWPoison(page + count)) goto skip; @@ -3515,7 +3516,7 @@ skip: vmf->pte += count; addr += count * PAGE_SIZE; count = 0; - } while (--nr_pages > 0); + } if (count) { set_pte_range(vmf, folio, page, count, addr);