This is a note to let you know that I've just added the patch titled

    filemap: add a kiocb_invalidate_pages helper

to the 6.1-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:
     filemap-add-a-kiocb_invalidate_pages-helper.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <[email protected]> know about it.


>From [email protected] Tue Oct 21 16:11:59 
>2025
From: Mahmoud Adam <[email protected]>
Date: Tue, 21 Oct 2025 09:03:36 +0200
Subject: filemap: add a kiocb_invalidate_pages helper
To: <[email protected]>
Cc: <[email protected]>, <[email protected]>, Christoph Hellwig 
<[email protected]>, Damien Le Moal <[email protected]>, Hannes Reinecke 
<[email protected]>, "Darrick J. Wong" <[email protected]>, Al Viro 
<[email protected]>, Andreas Gruenbacher <[email protected]>, "Anna 
Schumaker" <[email protected]>, Chao Yu <[email protected]>, Christian Brauner 
<[email protected]>, Ilya Dryomov <[email protected]>, Jaegeuk Kim 
<[email protected]>, Jens Axboe <[email protected]>, Johannes Thumshirn 
<[email protected]>, Matthew Wilcox <[email protected]>, "Miklos 
Szeredi" <[email protected]>, Miklos Szeredi <[email protected]>, "Theodore 
Ts'o" <[email protected]>, Trond Myklebust <[email protected]>, Xiubo 
Li <[email protected]>, Andrew Morton <[email protected]>, "Jeff 
Layton" <[email protected]>, Andreas Dilger <[email protected]>, 
Christoph Hellwig <[email protected]>, Ryusuke Konishi 
<[email protected]>, Luis Chamberlain <[email protected]>,
  <[email protected]>, <[email protected]>, 
<[email protected]>, <[email protected]>, 
<[email protected]>, <[email protected]>, 
<[email protected]>, <[email protected]>, 
<[email protected]>, <[email protected]>
Message-ID: <[email protected]>

From: Christoph Hellwig <[email protected]>

commit e003f74afbd2feadbb9ffbf9135e2d2fb5d320a5 upstream.

Factor out a helper that calls filemap_write_and_wait_range and
invalidate_inode_pages2_range for the range covered by a write kiocb or
returns -EAGAIN if the kiocb is marked as nowait and there would be pages
to write or invalidate.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Christoph Hellwig <[email protected]>
Reviewed-by: Damien Le Moal <[email protected]>
Reviewed-by: Hannes Reinecke <[email protected]>
Acked-by: Darrick J. Wong <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Andreas Gruenbacher <[email protected]>
Cc: Anna Schumaker <[email protected]>
Cc: Chao Yu <[email protected]>
Cc: Christian Brauner <[email protected]>
Cc: Ilya Dryomov <[email protected]>
Cc: Jaegeuk Kim <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Johannes Thumshirn <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Miklos Szeredi <[email protected]>
Cc: Miklos Szeredi <[email protected]>
Cc: Theodore Ts'o <[email protected]>
Cc: Trond Myklebust <[email protected]>
Cc: Xiubo Li <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Mahmoud Adam <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
 include/linux/pagemap.h |    1 +
 mm/filemap.c            |   48 ++++++++++++++++++++++++++++--------------------
 2 files changed, 29 insertions(+), 20 deletions(-)

--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -30,6 +30,7 @@ static inline void invalidate_remote_ino
 int invalidate_inode_pages2(struct address_space *mapping);
 int invalidate_inode_pages2_range(struct address_space *mapping,
                pgoff_t start, pgoff_t end);
+int kiocb_invalidate_pages(struct kiocb *iocb, size_t count);
 int write_inode_now(struct inode *, int sync);
 int filemap_fdatawrite(struct address_space *);
 int filemap_flush(struct address_space *);
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2839,6 +2839,33 @@ put_folios:
 }
 EXPORT_SYMBOL_GPL(filemap_read);
 
+int kiocb_invalidate_pages(struct kiocb *iocb, size_t count)
+{
+       struct address_space *mapping = iocb->ki_filp->f_mapping;
+       loff_t pos = iocb->ki_pos;
+       loff_t end = pos + count - 1;
+       int ret;
+
+       if (iocb->ki_flags & IOCB_NOWAIT) {
+               /* we could block if there are any pages in the range */
+               if (filemap_range_has_page(mapping, pos, end))
+                       return -EAGAIN;
+       } else {
+               ret = filemap_write_and_wait_range(mapping, pos, end);
+               if (ret)
+                       return ret;
+       }
+
+       /*
+        * After a write we want buffered reads to be sure to go to disk to get
+        * the new data.  We invalidate clean cached page from the region we're
+        * about to write.  We do this *before* the write so that we can return
+        * without clobbering -EIOCBQUEUED from ->direct_IO().
+        */
+       return invalidate_inode_pages2_range(mapping, pos >> PAGE_SHIFT,
+                                            end >> PAGE_SHIFT);
+}
+
 /**
  * generic_file_read_iter - generic filesystem read routine
  * @iocb:      kernel I/O control block
@@ -3737,30 +3764,11 @@ generic_file_direct_write(struct kiocb *
        write_len = iov_iter_count(from);
        end = (pos + write_len - 1) >> PAGE_SHIFT;
 
-       if (iocb->ki_flags & IOCB_NOWAIT) {
-               /* If there are pages to writeback, return */
-               if (filemap_range_has_page(file->f_mapping, pos,
-                                          pos + write_len - 1))
-                       return -EAGAIN;
-       } else {
-               written = filemap_write_and_wait_range(mapping, pos,
-                                                       pos + write_len - 1);
-               if (written)
-                       goto out;
-       }
-
-       /*
-        * After a write we want buffered reads to be sure to go to disk to get
-        * the new data.  We invalidate clean cached page from the region we're
-        * about to write.  We do this *before* the write so that we can return
-        * without clobbering -EIOCBQUEUED from ->direct_IO().
-        */
-       written = invalidate_inode_pages2_range(mapping,
-                                       pos >> PAGE_SHIFT, end);
        /*
         * If a page can not be invalidated, return 0 to fall back
         * to buffered write.
         */
+       written = kiocb_invalidate_pages(iocb, write_len);
        if (written) {
                if (written == -EBUSY)
                        return 0;


Patches currently in stable-queue which might be from [email protected] are

queue-6.1/block-fix-race-between-set_blocksize-and-read-paths.patch
queue-6.1/filemap-add-a-kiocb_invalidate_pages-helper.patch
queue-6.1/fs-factor-out-a-direct_write_fallback-helper.patch
queue-6.1/direct_write_fallback-on-error-revert-the-ki_pos-update-from-buffered-write.patch
queue-6.1/filemap-update-ki_pos-in-generic_perform_write.patch
queue-6.1/filemap-add-a-kiocb_invalidate_post_direct_write-helper.patch
queue-6.1/nilfs2-fix-deadlock-warnings-caused-by-lock-dependency-in-init_nilfs.patch
queue-6.1/block-open-code-__generic_file_write_iter-for-blkdev-writes.patch


_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to