Skip to content

Commit 73f37db

Browse files
CmdrMoozyakpm00
authored andcommitted
mm: userfaultfd: fix UFFDIO_CONTINUE on fallocated shmem pages
When fallocate() is used on a shmem file, the pages we allocate can end up with !PageUptodate. Since UFFDIO_CONTINUE tries to find the existing page the user wants to map with SGP_READ, we would fail to find such a page, since shmem_getpage_gfp returns with a "NULL" pagep for SGP_READ if it discovers !PageUptodate. As a result, UFFDIO_CONTINUE returns -EFAULT, as it would do if the page wasn't found in the page cache at all. This isn't the intended behavior. UFFDIO_CONTINUE is just trying to find if a page exists, and doesn't care whether it still needs to be cleared or not. So, instead of SGP_READ, pass in SGP_NOALLOC. This is the same, except for one critical difference: in the !PageUptodate case, SGP_NOALLOC will clear the page and then return it. With this change, UFFDIO_CONTINUE works properly (succeeds) on a shmem file which has been fallocated, but otherwise not modified. Link: https://lkml.kernel.org/r/[email protected] Fixes: 1531325 ("userfaultfd/shmem: support UFFDIO_CONTINUE for shmem") Signed-off-by: Axel Rasmussen <[email protected]> Acked-by: Peter Xu <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 03c765b commit 73f37db

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

mm/userfaultfd.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,10 @@ static int mcontinue_atomic_pte(struct mm_struct *dst_mm,
246246
struct page *page;
247247
int ret;
248248

249-
ret = shmem_getpage(inode, pgoff, &page, SGP_READ);
249+
ret = shmem_getpage(inode, pgoff, &page, SGP_NOALLOC);
250+
/* Our caller expects us to return -EFAULT if we failed to find page. */
251+
if (ret == -ENOENT)
252+
ret = -EFAULT;
250253
if (ret)
251254
goto out;
252255
if (!page) {

0 commit comments

Comments
 (0)