This is a note to let you know that I've just added the patch titled iov_iter: Introduce nofault flag to disable page faults to the 5.15-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: iov_iter-introduce-nofault-flag-to-disable-page-faults.patch and it can be found in the queue-5.15 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From foo@baz Fri Apr 29 11:07:48 AM CEST 2022 From: Anand Jain <anand.jain@xxxxxxxxxx> Date: Fri, 15 Apr 2022 06:28:52 +0800 Subject: iov_iter: Introduce nofault flag to disable page faults To: stable@xxxxxxxxxxxxxxx Cc: linux-btrfs@xxxxxxxxxxxxxxx, Andreas Gruenbacher <agruenba@xxxxxxxxxx>, Anand Jain <anand.jain@xxxxxxxxxx> Message-ID: <56bf354a8e9c5f2d3d9482c90510d4ff0890d996.1649951733.git.anand.jain@xxxxxxxxxx> From: Andreas Gruenbacher <agruenba@xxxxxxxxxx> commit 3337ab08d08b1a375f88471d9c8b1cac968cb054 upstream Introduce a new nofault flag to indicate to iov_iter_get_pages not to fault in user pages. This is implemented by passing the FOLL_NOFAULT flag to get_user_pages, which causes get_user_pages to fail when it would otherwise fault in a page. We'll use the ->nofault flag to prevent iomap_dio_rw from faulting in pages when page faults are not allowed. Signed-off-by: Andreas Gruenbacher <agruenba@xxxxxxxxxx> Signed-off-by: Anand Jain <anand.jain@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- include/linux/uio.h | 1 + lib/iov_iter.c | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -35,6 +35,7 @@ struct iov_iter_state { struct iov_iter { u8 iter_type; + bool nofault; bool data_source; size_t iov_offset; size_t count; --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -514,6 +514,7 @@ void iov_iter_init(struct iov_iter *i, u WARN_ON(direction & ~(READ | WRITE)); *i = (struct iov_iter) { .iter_type = ITER_IOVEC, + .nofault = false, .data_source = direction, .iov = iov, .nr_segs = nr_segs, @@ -1529,13 +1530,17 @@ ssize_t iov_iter_get_pages(struct iov_it return 0; if (likely(iter_is_iovec(i))) { + unsigned int gup_flags = 0; unsigned long addr; + if (iov_iter_rw(i) != WRITE) + gup_flags |= FOLL_WRITE; + if (i->nofault) + gup_flags |= FOLL_NOFAULT; + addr = first_iovec_segment(i, &len, start, maxsize, maxpages); n = DIV_ROUND_UP(len, PAGE_SIZE); - res = get_user_pages_fast(addr, n, - iov_iter_rw(i) != WRITE ? FOLL_WRITE : 0, - pages); + res = get_user_pages_fast(addr, n, gup_flags, pages); if (unlikely(res <= 0)) return res; return (res == n ? len : res * PAGE_SIZE) - *start; @@ -1651,15 +1656,20 @@ ssize_t iov_iter_get_pages_alloc(struct return 0; if (likely(iter_is_iovec(i))) { + unsigned int gup_flags = 0; unsigned long addr; + if (iov_iter_rw(i) != WRITE) + gup_flags |= FOLL_WRITE; + if (i->nofault) + gup_flags |= FOLL_NOFAULT; + addr = first_iovec_segment(i, &len, start, maxsize, ~0U); n = DIV_ROUND_UP(len, PAGE_SIZE); p = get_pages_array(n); if (!p) return -ENOMEM; - res = get_user_pages_fast(addr, n, - iov_iter_rw(i) != WRITE ? FOLL_WRITE : 0, p); + res = get_user_pages_fast(addr, n, gup_flags, p); if (unlikely(res <= 0)) { kvfree(p); *pages = NULL; Patches currently in stable-queue which might be from anand.jain@xxxxxxxxxx are queue-5.15/gup-turn-fault_in_pages_-readable-writeable-into-fault_in_-readable-writeable.patch queue-5.15/iov_iter-introduce-nofault-flag-to-disable-page-faults.patch queue-5.15/gfs2-fix-mmap-page-fault-deadlocks-for-direct-i-o.patch queue-5.15/iomap-support-partial-direct-i-o-on-user-copy-failures.patch queue-5.15/mm-gup-make-fault_in_safe_writeable-use-fixup_user_fault.patch queue-5.15/gfs2-add-wrapper-for-iomap_file_buffered_write.patch queue-5.15/gup-introduce-foll_nofault-flag-to-disable-page-faults.patch queue-5.15/iov_iter-introduce-fault_in_iov_iter_writeable.patch queue-5.15/gfs2-fix-mmap-page-fault-deadlocks-for-buffered-i-o.patch queue-5.15/btrfs-fallback-to-blocking-mode-when-doing-async-dio-over-multiple-extents.patch queue-5.15/gfs2-clean-up-function-may_grant.patch queue-5.15/btrfs-fix-deadlock-due-to-page-faults-during-direct-io-reads-and-writes.patch queue-5.15/iov_iter-turn-iov_iter_fault_in_readable-into-fault_in_iov_iter_readable.patch queue-5.15/gfs2-move-the-inode-glock-locking-to-gfs2_file_buffered_write.patch queue-5.15/gfs2-introduce-flag-for-glock-holder-auto-demotion.patch queue-5.15/iomap-fix-iomap_dio_rw-return-value-for-user-copies.patch queue-5.15/gfs2-eliminate-ip-i_gh.patch queue-5.15/iomap-add-done_before-argument-to-iomap_dio_rw.patch