Skip to content

Commit 93b0d91

Browse files
xzpeterakpm00
authored andcommitted
mm/shmem: use page_mapping() to detect page cache for uffd continue
mfill_atomic_install_pte() checks page->mapping to detect whether one page is used in the page cache. However as pointed out by Matthew, the page can logically be a tail page rather than always the head in the case of uffd minor mode with UFFDIO_CONTINUE. It means we could wrongly install one pte with shmem thp tail page assuming it's an anonymous page. It's not that clear even for anonymous page, since normally anonymous pages also have page->mapping being setup with the anon vma. It's safe here only because the only such caller to mfill_atomic_install_pte() is always passing in a newly allocated page (mcopy_atomic_pte()), whose page->mapping is not yet setup. However that's not extremely obvious either. For either of above, use page_mapping() instead. Link: https://lkml.kernel.org/r/Y2K+y7wnhC4vbnP2@x1n Fixes: 1531325 ("userfaultfd/shmem: support UFFDIO_CONTINUE for shmem") Signed-off-by: Peter Xu <[email protected]> Reported-by: Matthew Wilcox <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Axel Rasmussen <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 867400a commit 93b0d91

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mm/userfaultfd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ int mfill_atomic_install_pte(struct mm_struct *dst_mm, pmd_t *dst_pmd,
6464
pte_t _dst_pte, *dst_pte;
6565
bool writable = dst_vma->vm_flags & VM_WRITE;
6666
bool vm_shared = dst_vma->vm_flags & VM_SHARED;
67-
bool page_in_cache = page->mapping;
67+
bool page_in_cache = page_mapping(page);
6868
spinlock_t *ptl;
6969
struct inode *inode;
7070
pgoff_t offset, max_off;

0 commit comments

Comments
 (0)