mm: fix oops when filemap_map_pmd) without prealloc_pte
PATCH 1/1 mm: fix oops when filemap_map_pmd) without prealloc_pte
syzbot reports oops in lockdep's __lock_acquire(), called from __pte_offset_map_lock() called from filemap_map_pages(); or when I run the repro, the oops comes in pmd_install(), called from filemap_map_pmd() called from filemap_map_pages(), just before the __pte_offset_map_lock().
The problem is that filemap_map_pmd() has been assuming that when it finds pmd_none(), a page table has already been prepared in prealloc_pte; and indeed do_fault_around() has been careful to preallocate one there, when it finds pmd_none(): but what if *pmd became none in between?
My 6.6 mods in mm/khugepaged.c, avoiding mmap_lock for write, have made it easy for *pmd to be cleared while servicing a page fault; but even before those, a huge *pmd might be zapped while a fault is serviced.
The difference in symptomatic stack traces comes from the "memory model" in use: pmd_install() uses pmd_populate() uses page_to_pfn(): in some models that is strict, and will oops on the NULL prealloc_pte; in other models, it will construct a bogus value to be populated into *pmd, then __pte_offset_map_lock() oops when trying to access split ptlock pointer (or some other symptom in normal case of ptlock embedded not pointer).
--- mm/filemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/filemap.c +1 -1
@@ -3209,7 +3209,7 @@ static bool filemap_map_pmd(struct vm_fault *vmf, struct page *page) } } -if (pmd_none (*vmf->pmd)) { +if (pmd_none (*vmf->pmd) && vmf->prealloc_pte) { vmf->ptl =pmd_lock (mm, vmf->pmd);if (likely (pmd_none (*vmf->pmd))) {mm_inc_nr_ptes (mm);
Signature · 1 line
2.35.3
Greg KH
maintainerQuoted 36 lines · Hugh Dickins
syzbot reports oops in lockdep's
__lock_acquire(), called from__pte_offset_map_lock()called fromfilemap_map_pages(); or when I run the repro, the oops comes inpmd_install(), called fromfilemap_map_pmd()called fromfilemap_map_pages(), just before the__pte_offset_map_lock().The problem is that
filemap_map_pmd()has been assuming that when it findspmd_none(), a page table has already been prepared inprealloc_pte; and indeeddo_fault_around()has been careful to preallocate one there, when it findspmd_none(): but what if *pmd became none in between?My 6.6 mods in
mm/khugepaged.c, avoidingmmap_lockfor write, have made it easy for *pmd to be cleared while servicing a page fault; but even before those, a huge *pmd might be zapped while a fault is serviced.The difference in symptomatic stack traces comes from the "memory model" in use:
pmd_install()usespmd_populate()usespage_to_pfn(): in some models that is strict, and will oops on the NULLprealloc_pte; in other models, it will construct a bogus value to be populated into *pmd, then__pte_offset_map_lock()oops when trying to access split ptlock pointer (or some other symptom in normal case of ptlock embedded not pointer).Fixes f9ce0be71d1f ("mm: Cleanup faultaround and finish_fault() codepaths")Signed-off-by Hugh Dickins <[email protected]>Reported-and-tested-by [email protected]Reviewed-by David Hildenbrand <[email protected]>Cc Jann Horn <[email protected]>,Cc José Pekkarinen <[email protected]>Cc Kirill A. Shutemov <[email protected]>Cc Matthew Wilcox (Oracle) <[email protected]>Cc <[email protected]> [5.12+]Signed-off-by Andrew Morton <[email protected]>(cherry picked from commit 9aa1345d66b8132745ffb99b348b1492088da9e2)Signed-off-by Hugh Dickins <[email protected]>
Quoted 4 lines
--- mm/filemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Now queued up, thanks.
greg k-h
Quoted 42 lines · Greg KH
Quoted 36 lines · Hugh Dickins
syzbot reports oops in lockdep's
__lock_acquire(), called from__pte_offset_map_lock()called fromfilemap_map_pages(); or when I run the repro, the oops comes inpmd_install(), called fromfilemap_map_pmd()called fromfilemap_map_pages(), just before the__pte_offset_map_lock().The problem is that
filemap_map_pmd()has been assuming that when it findspmd_none(), a page table has already been prepared inprealloc_pte; and indeeddo_fault_around()has been careful to preallocate one there, when it findspmd_none(): but what if *pmd became none in between?My 6.6 mods in
mm/khugepaged.c, avoidingmmap_lockfor write, have made it easy for *pmd to be cleared while servicing a page fault; but even before those, a huge *pmd might be zapped while a fault is serviced.The difference in symptomatic stack traces comes from the "memory model" in use:
pmd_install()usespmd_populate()usespage_to_pfn(): in some models that is strict, and will oops on the NULLprealloc_pte; in other models, it will construct a bogus value to be populated into *pmd, then__pte_offset_map_lock()oops when trying to access split ptlock pointer (or some other symptom in normal case of ptlock embedded not pointer).Fixes f9ce0be71d1f ("mm: Cleanup faultaround and finish_fault() codepaths")Signed-off-by Hugh Dickins <[email protected]>Reported-and-tested-by [email protected]Reviewed-by David Hildenbrand <[email protected]>Cc Jann Horn <[email protected]>,Cc José Pekkarinen <[email protected]>Cc Kirill A. Shutemov <[email protected]>Cc Matthew Wilcox (Oracle) <[email protected]>Cc <[email protected]> [5.12+]Signed-off-by Andrew Morton <[email protected]>(cherry picked from commit 9aa1345d66b8132745ffb99b348b1492088da9e2)Signed-off-by Hugh Dickins <[email protected]>Quoted 4 lines
--- mm/filemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 3 lines
Now queued up, thanks.
greg k-h
Thanks Greg: but Sasha appears to have a competing queue, in which he's cherry-picked in a dependency from 5.16 ahead of a clean cherry-pick for this one.
He posted his the next day: I expect it's more to your taste (pull in dependency rather than edit cherry-pick) and it looked fine to me. Please sort out with Sasha which goes forward, either will do.
Hugh
Greg KH
maintainerQuoted 47 lines · Hugh Dickins
Quoted 42 lines · Greg KH
Quoted 36 lines · Hugh Dickins
syzbot reports oops in lockdep's
__lock_acquire(), called from__pte_offset_map_lock()called fromfilemap_map_pages(); or when I run the repro, the oops comes inpmd_install(), called fromfilemap_map_pmd()called fromfilemap_map_pages(), just before the__pte_offset_map_lock().The problem is that
filemap_map_pmd()has been assuming that when it findspmd_none(), a page table has already been prepared inprealloc_pte; and indeeddo_fault_around()has been careful to preallocate one there, when it findspmd_none(): but what if *pmd became none in between?My 6.6 mods in
mm/khugepaged.c, avoidingmmap_lockfor write, have made it easy for *pmd to be cleared while servicing a page fault; but even before those, a huge *pmd might be zapped while a fault is serviced.The difference in symptomatic stack traces comes from the "memory model" in use:
pmd_install()usespmd_populate()usespage_to_pfn(): in some models that is strict, and will oops on the NULLprealloc_pte; in other models, it will construct a bogus value to be populated into *pmd, then__pte_offset_map_lock()oops when trying to access split ptlock pointer (or some other symptom in normal case of ptlock embedded not pointer).Fixes f9ce0be71d1f ("mm: Cleanup faultaround and finish_fault() codepaths")Signed-off-by Hugh Dickins <[email protected]>Reported-and-tested-by [email protected]Reviewed-by David Hildenbrand <[email protected]>Cc Jann Horn <[email protected]>,Cc José Pekkarinen <[email protected]>Cc Kirill A. Shutemov <[email protected]>Cc Matthew Wilcox (Oracle) <[email protected]>Cc <[email protected]> [5.12+]Signed-off-by Andrew Morton <[email protected]>(cherry picked from commit 9aa1345d66b8132745ffb99b348b1492088da9e2)Signed-off-by Hugh Dickins <[email protected]>Quoted 4 lines
--- mm/filemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 3 lines
Now queued up, thanks.
greg k-h
Quoted 7 lines
Thanks Greg: but Sasha appears to have a competing queue, in which he's cherry-picked in a dependency from 5.16 ahead of a clean cherry-pick for this one.
He posted his the next day: I expect it's more to your taste (pull in dependency rather than edit cherry-pick) and it looked fine to me. Please sort out with Sasha which goes forward, either will do.
I dropped his version and took yours :)