Message ID | 20210515002719.QX9ZRXcYB%akpm@linux-foundation.org |
---|---|
State | New |
Headers | show |
Series | [01/13] mm/hugetlb: fix F_SEAL_FUTURE_WRITE | expand |
--- a/mm/shmem.c~userfaultfd-release-page-in-error-path-to-avoid-bug_on +++ a/mm/shmem.c @@ -2361,8 +2361,18 @@ static int shmem_mfill_atomic_pte(struct pgoff_t offset, max_off; ret = -ENOMEM; - if (!shmem_inode_acct_block(inode, 1)) + if (!shmem_inode_acct_block(inode, 1)) { + /* + * We may have got a page, returned -ENOENT triggering a retry, + * and now we find ourselves with -ENOMEM. Release the page, to + * avoid a BUG_ON in our caller. + */ + if (unlikely(*pagep)) { + put_page(*pagep); + *pagep = NULL; + } goto out; + } if (!*pagep) { page = shmem_alloc_page(gfp, info, pgoff);