mm/memory: Pass head page to do_set_pmd()
Subsystems (2)
PATCH 1/1 mm/memory: Pass head page to do_set_pmd()
The requirement that the head page be passed to do_set_pmd() was added in commit ef37b2ea08ac ("mm/memory: page_add_file_rmap() -> folio_add_file_rmap_[pte|pmd]()") and prevents pmd-mapping in the finish_fault() path if vmf->page is anything but the head page for an otherwise suitable vma and pmd-sized page. Have finish_fault() pass in the head page instead.
--- mm/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory.c +1 -1
@@ -4764,7 +4764,7 @@ vm_fault_t finish_fault(struct vm_fault *vmf)if (pmd_none (*vmf->pmd)) {if (PageTransCompound (page)) { - ret =do_set_pmd (vmf, page); + ret =do_set_pmd (vmf,compound_head (page));if (ret !=VM_FAULT_FALLBACK )return ret; }
Signature · 1 line
2.34.1
Quoted 18 lines · Andrew Bresticker
The requirement that the head page be passed to
do_set_pmd()was added in commitef37b2ea08ac("mm/memory:page_add_file_rmap()-> folio_add_file_rmap_[pte|pmd]()") and prevents pmd-mapping in thefinish_fault()path ifvmf->pageis anything but the head page for an otherwise suitable vma and pmd-sized page. Havefinish_fault()pass in the head page instead.Fixes ef37b2ea08ac ("mm/memory: page_add_file_rmap() -> folio_add_file_rmap_[pte|pmd]()")Signed-off-by Andrew Bresticker <[email protected]>--- mm/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/memory.c +0
-0
mm/memory.c vm_fault_t finish_fault(struct vm_fault *vmf) · line 4770
Quoted 8 lines
mm/memory.c +1
-1@@ -4764,7 +4764,7 @@ vm_fault_t finish_fault(struct vm_fault *vmf)if (pmd_none (*vmf->pmd)) {if (PageTransCompound (page)) { - ret =do_set_pmd (vmf, page); + ret =do_set_pmd (vmf,compound_head (page));if (ret !=VM_FAULT_FALLBACK )return ret; }
That certainly makes the "page != &folio->page" check happy.
It is *likely* incorrect if we would ever have folios > PMD size (which we don't have on that path yet).
I assume that the thp_vma_suitable_order() check would detect any kind of "different placement of the folio in virtual address space", where we could mess up.
Question is: should we instead drop the "page != &folio->page" check that I added?
I think I added that check because I saw the "compound_order(page)" check and assumed it would return 0 for tail pages, but missed that we get the compound head first.
Signature · 3 lines
Cheers, David / dhildenb
Quoted 33 lines · David Hildenbrand
Quoted 18 lines · Andrew Bresticker
The requirement that the head page be passed to
do_set_pmd()was added in commitef37b2ea08ac("mm/memory:page_add_file_rmap()-> folio_add_file_rmap_[pte|pmd]()") and prevents pmd-mapping in thefinish_fault()path ifvmf->pageis anything but the head page for an otherwise suitable vma and pmd-sized page. Havefinish_fault()pass in the head page instead.Fixes ef37b2ea08ac ("mm/memory: page_add_file_rmap() -> folio_add_file_rmap_[pte|pmd]()")Signed-off-by Andrew Bresticker <[email protected]>--- mm/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/memory.c +0
-0mm/memory.c vm_fault_t finish_fault(struct vm_fault *vmf) · line 4770
Quoted 8 lines
mm/memory.c +1
-1@@ -4764,7 +4764,7 @@ vm_fault_t finish_fault(struct vm_fault *vmf)if (pmd_none (*vmf->pmd)) {if (PageTransCompound (page)) { - ret =do_set_pmd (vmf, page); + ret =do_set_pmd (vmf,compound_head (page));if (ret !=VM_FAULT_FALLBACK )return ret; }That certainly makes the "page !=
&folio->page" check happy.It is *likely* incorrect if we would ever have folios > PMD size (which we don't have on that path yet).
Quoted 6 lines
I assume that the
thp_vma_suitable_order()check would detect any kind of "different placement of the folio in virtual address space", where we could mess up.Question is: should we instead drop the "page !=
&folio->page" check that I added?
To be precise, the something like following:
mm/memory.c +2 -1
@@ -4699,8 +4699,9 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page)if (!thp_vma_suitable_order (vma, haddr,PMD_ORDER ))return ret; -if (page != &folio->page ||folio_order (folio) !=HPAGE_PMD_ORDER ) +if (folio_order (folio) !=HPAGE_PMD_ORDER )return ret; + page = &folio->page;/* * Just backoff if any subpage of a THP is corrupted otherwise
Signature · 3 lines
Cheers, David / dhildenb
Quoted 31 lines · David Hildenbrand
Quoted 18 lines · Andrew Bresticker
The requirement that the head page be passed to
do_set_pmd()was added in commitef37b2ea08ac("mm/memory:page_add_file_rmap()-> folio_add_file_rmap_[pte|pmd]()") and prevents pmd-mapping in thefinish_fault()path ifvmf->pageis anything but the head page for an otherwise suitable vma and pmd-sized page. Havefinish_fault()pass in the head page instead.Fixes ef37b2ea08ac ("mm/memory: page_add_file_rmap() -> folio_add_file_rmap_[pte|pmd]()")Signed-off-by Andrew Bresticker <[email protected]>--- mm/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/memory.c +0
-0mm/memory.c vm_fault_t finish_fault(struct vm_fault *vmf) · line 4770
Quoted 8 lines
mm/memory.c +1
-1@@ -4764,7 +4764,7 @@ vm_fault_t finish_fault(struct vm_fault *vmf)if (pmd_none (*vmf->pmd)) {if (PageTransCompound (page)) { - ret =do_set_pmd (vmf, page); + ret =do_set_pmd (vmf,compound_head (page));if (ret !=VM_FAULT_FALLBACK )return ret; }That certainly makes the "page !=
&folio->page" check happy.
Quoted 6 lines
It is *likely* incorrect if we would ever have folios > PMD size (which we don't have on that path yet).
I assume that the
thp_vma_suitable_order()check would detect any kind of "different placement of the folio in virtual address space", where we could mess up.
thp_vma_suitable_order() checks that the folio fits in the vma, if that's what you mean.
Quoted 2 lines
Question is: should we instead drop the "page !=
&folio->page" check that I added?
Indeed that's probably better as I'm now noticing that filemap_map_pmd() has the same issue. Will send a v2.
Thanks.
-Andrew
Quoted 10 lines
I think I added that check because I saw the "
compound_order(page)" check and assumed it would return 0 for tail pages, but missed that we get the compound head first.--
Cheers,David / dhildenb