Backporting CVE-2025-38073 fix patch
Subsystems (13)
cover Backporting CVE-2025-38073 fix patch
This series aims to fix the CVE-2025-38073 for 6.1 LTS. Which is fixed by c0e473a0d226 ("block: fix race between set_blocksize and read paths"). This patch is built on top multiple refactors that where merged on 6.6. The needed dependecies are:
- e003f74afbd2 ("filemap: add a kiocb_invalidate_pages helper")
- c402a9a9430b ("filemap: add a kiocb_invalidate_post_direct_write helper")
- 182c25e9c157 ("filemap: update ki_pos in generic_perform_write")
- 44fff0fa08ec ("fs: factor out a direct_write_fallback helper")
- 727cfe976758 ("block: open code __generic_file_write_iter for blkdev writes")
Also backport follow up fixes:
- fb881cd76045 ("nilfs2: fix deadlock warnings caused by lock dependency in init_nilfs()").
- 8287474aa5ff ("direct_write_fallback(): on error revert the ->ki_pos update from buffered write")
Thanks,
MNAdam
Al Viro (1):
direct_write_fallback(): on error revert the ->ki_pos update from
buffered write
Christoph Hellwig (5):
filemap: add a kiocb_invalidate_pages helper
filemap: add a kiocb_invalidate_post_direct_write helper
filemap: update ki_pos in generic_perform_write
fs: factor out a direct_write_fallback helper
block: open code __generic_file_write_iter for blkdev writes
Darrick J. Wong (1):
block: fix race between set_blocksize and read paths
Ryusuke Konishi (1):
nilfs2: fix deadlock warnings caused by lock dependency in
init_nilfs()
block/bdev.c | 17 +++++ block/blk-zoned.c | 5 +- block/fops.c | 61 +++++++++++++++- block/ioctl.c | 6 ++ fs/ceph/file.c | 2 - fs/direct-io.c | 10 +-- fs/ext4/file.c | 9 +-- fs/f2fs/file.c | 1 - fs/iomap/direct-io.c | 12 +--- fs/libfs.c | 42 +++++++++++ fs/nfs/file.c | 1 - fs/nilfs2/the_nilfs.c | 3 - include/linux/fs.h | 7 +- include/linux/pagemap.h | 2 + mm/filemap.c | 154 +++++++++++++++++----------------------- 15 files changed, 205 insertions(+), 127 deletions(-)
Signature · 12 lines
2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597
PATCH 1/8 filemap: add a kiocb_invalidate_pages helper
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.
--- include/linux/pagemap.h | 1 + mm/filemap.c | 48 ++++++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 20 deletions(-)
include/linux/pagemap.h +1 -0
@@ -30,6 +30,7 @@ static inline void invalidate_remote_inode(struct inode *inode)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 *);
mm/filemap.c +28 -20
64 lines not on this page · raw message
Signature · 12 lines
2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597
Patch "filemap: add a kiocb_invalidate_pages helper" has been added to the 6.1-stable tree
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 <mcgrof@kern
el.org>,
<[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.
--- include/linux/pagemap.h | 1 + mm/filemap.c | 48 ++++++++++++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 20 deletions(-)
include/linux/pagemap.h +1 -0
@@ -30,6 +30,7 @@ static inline void invalidate_remote_inoint 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 *);
mm/filemap.c +28 -20
64 lines not on this page · raw message
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
PATCH 2/8 filemap: add a kiocb_invalidate_post_direct_write helper
In reply to Mahmoud AdamFrom: Christoph Hellwig <[email protected]>
commit c402a9a9430b670926decbb284b756ee6f47c1ec upstream.
Add a helper to invalidate page cache after a dio write.
--- fs/direct-io.c | 10 ++-------- fs/iomap/direct-io.c | 12 ++---------- include/linux/fs.h | 5 ----- include/linux/pagemap.h | 1 + mm/filemap.c | 37 ++++++++++++++++++++----------------- 5 files changed, 25 insertions(+), 40 deletions(-)
fs/direct-io.c +2 -8
@@ -286,14 +286,8 @@ static ssize_t dio_complete(struct dio *dio, ssize_t ret, unsigned int flags)* zeros from unwritten extents. */ if (flags &DIO_COMPLETE_INVALIDATE && - ret >0 && dio_op ==REQ_OP_WRITE && - dio->inode->i_mapping->nrpages) { - err =invalidate_inode_pages2_range (dio->inode->i_mapping, - offset >>PAGE_SHIFT , - (offset + ret -1 ) >>PAGE_SHIFT ); -if (err) -dio_warn_stale_pagecache (dio->iocb->ki_filp); - } + ret >0 && dio_op ==REQ_OP_WRITE ) +kiocb_invalidate_post_direct_write (dio->iocb, ret);inode_dio_end (dio->inode);
fs/iomap/direct-io.c +2 -10
@@ -81,7 +81,6 @@ ssize_t iomap_dio_complete(struct iomap_dio *dio) {const struct iomap_dio_ops *dops = dio->dops;struct kiocb *iocb = dio->iocb; -struct inode *inode =file_inode (iocb->ki_filp);loff_t offset = iocb->ki_pos;ssize_t ret = dio->error;
@@ -108,15 +107,8 @@ ssize_t iomap_dio_complete(struct iomap_dio *dio)* ->end_io() when necessary, otherwise a racing buffer read would cache * zeros from unwritten extents. */ -if (!dio->error && dio->size && - (dio->flags &IOMAP_DIO_WRITE ) && inode->i_mapping->nrpages) { -int err; - err =invalidate_inode_pages2_range (inode->i_mapping, - offset >>PAGE_SHIFT , - (offset + dio->size -1 ) >>PAGE_SHIFT ); -if (err) -dio_warn_stale_pagecache (iocb->ki_filp); - } +if (!dio->error && dio->size && (dio->flags &IOMAP_DIO_WRITE )) +kiocb_invalidate_post_direct_write (iocb, dio->size);inode_dio_end (file_inode (iocb->ki_filp));if (ret >0 ) {
include/linux/fs.h +0 -5
@@ -3371,11 +3371,6 @@ static inline void inode_dio_end(struct inode *inode)wake_up_bit (&inode->i_state, __I_DIO_WAKEUP); } -/* -* Warn about a page cache invalidation failure diring a direct I/O write. -*/ -void dio_warn_stale_pagecache (struct file *filp); -extern void inode_set_flags (struct inode *inode,unsigned int flags,unsigned int mask);
include/linux/pagemap.h +1 -0
@@ -31,6 +31,7 @@ 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); +void kiocb_invalidate_post_direct_write (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 *);
mm/filemap.c +20 -17
@@ -3733,7 +3733,7 @@ EXPORT_SYMBOL(read_cache_page_gfp);/* * Warn about a page cache invalidation failure during a direct I/O write. */ -void dio_warn_stale_pagecache (struct file *filp) +static void dio_warn_stale_pagecache (struct file *filp) { static DEFINE_RATELIMIT_STATE(_rs, 86400 * HZ, DEFAULT_RATELIMIT_BURST);char pathname[128 ];
@@ -3750,19 +3750,23 @@ void dio_warn_stale_pagecache(struct file *filp) } } +void kiocb_invalidate_post_direct_write (struct kiocb *iocb,size_t count) +{ +struct address_space *mapping = iocb->ki_filp->f_mapping; + +if (mapping->nrpages && +invalidate_inode_pages2_range (mapping, + iocb->ki_pos >>PAGE_SHIFT , + (iocb->ki_pos + count -1 ) >>PAGE_SHIFT )) +dio_warn_stale_pagecache (iocb->ki_filp); +} +ssize_t generic_file_direct_write (struct kiocb *iocb,struct iov_iter *from) { -struct file *file = iocb->ki_filp; -struct address_space *mapping = file->f_mapping; -struct inode *inode = mapping->host; -loff_t pos = iocb->ki_pos; -ssize_t written; -size_t write_len; -pgoff_t end; - - write_len =iov_iter_count (from); - end = (pos + write_len -1 ) >>PAGE_SHIFT ; +struct address_space *mapping = iocb->ki_filp->f_mapping; +size_t write_len =iov_iter_count (from); +ssize_t written;/* * If a page can not be invalidated, return 0 to fall back
@@ -3772,7 +3776,7 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from)if (written) {if (written == -EBUSY )return 0 ; - goto out; +return written; } written = mapping->a_ops->direct_IO (iocb, from);
@@ -3794,11 +3798,11 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from)* * Skip invalidation for async writes or if mapping has no pages. */ -if (written >0 && mapping->nrpages && -invalidate_inode_pages2_range (mapping, pos >>PAGE_SHIFT , end)) -dio_warn_stale_pagecache (file); -if (written >0 ) { +struct inode *inode = mapping->host; +loff_t pos = iocb->ki_pos; + +kiocb_invalidate_post_direct_write (iocb, written); pos += written; write_len -= written;if (pos >i_size_read (inode) && !S_ISBLK (inode->i_mode)) {
@@ -3809,7 +3813,6 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from) }if (written != -EIOCBQUEUED )iov_iter_revert (from, write_len -iov_iter_count (from)); -out:return written; }EXPORT_SYMBOL (generic_file_direct_write);
Signature · 12 lines
2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597
Patch "filemap: add a kiocb_invalidate_post_direct_write helper" has been added to the 6.1-stable tree
This is a note to let you know that I've just added the patch titled
filemap: add a kiocb_invalidate_post_direct_write 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_post_direct_write-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:13:23 2025
From: Mahmoud Adam <[email protected]>
Date: Tue, 21 Oct 2025 09:03:37 +0200
Subject: filemap: add a kiocb_invalidate_post_direct_write 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 <mcgrof@kern
el.org>,
<[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 c402a9a9430b670926decbb284b756ee6f47c1ec upstream.
Add a helper to invalidate page cache after a dio write.
--- fs/direct-io.c | 10 ++-------- fs/iomap/direct-io.c | 12 ++---------- include/linux/fs.h | 5 ----- include/linux/pagemap.h | 1 + mm/filemap.c | 37 ++++++++++++++++++++----------------- 5 files changed, 25 insertions(+), 40 deletions(-)
fs/direct-io.c +2 -8
@@ -286,14 +286,8 @@ static ssize_t dio_complete(struct dio ** zeros from unwritten extents. */ if (flags &DIO_COMPLETE_INVALIDATE && - ret >0 && dio_op ==REQ_OP_WRITE && - dio->inode->i_mapping->nrpages) { - err =invalidate_inode_pages2_range (dio->inode->i_mapping, - offset >>PAGE_SHIFT , - (offset + ret -1 ) >>PAGE_SHIFT ); -if (err) -dio_warn_stale_pagecache (dio->iocb->ki_filp); - } + ret >0 && dio_op ==REQ_OP_WRITE ) +kiocb_invalidate_post_direct_write (dio->iocb, ret);inode_dio_end (dio->inode);
fs/iomap/direct-io.c +2 -10
@@ -81,7 +81,6 @@ ssize_t iomap_dio_complete(struct iomap_ {const struct iomap_dio_ops *dops = dio->dops;struct kiocb *iocb = dio->iocb; -struct inode *inode =file_inode (iocb->ki_filp);loff_t offset = iocb->ki_pos;ssize_t ret = dio->error;
@@ -108,15 +107,8 @@ ssize_t iomap_dio_complete(struct iomap_* ->end_io() when necessary, otherwise a racing buffer read would cache * zeros from unwritten extents. */ -if (!dio->error && dio->size && - (dio->flags &IOMAP_DIO_WRITE ) && inode->i_mapping->nrpages) { -int err; - err =invalidate_inode_pages2_range (inode->i_mapping, - offset >>PAGE_SHIFT , - (offset + dio->size -1 ) >>PAGE_SHIFT ); -if (err) -dio_warn_stale_pagecache (iocb->ki_filp); - } +if (!dio->error && dio->size && (dio->flags &IOMAP_DIO_WRITE )) +kiocb_invalidate_post_direct_write (iocb, dio->size);inode_dio_end (file_inode (iocb->ki_filp));if (ret >0 ) {
include/linux/fs.h +0 -5
@@ -3371,11 +3371,6 @@ static inline void inode_dio_end(structwake_up_bit (&inode->i_state, __I_DIO_WAKEUP); } -/* -* Warn about a page cache invalidation failure diring a direct I/O write. -*/ -void dio_warn_stale_pagecache (struct file *filp); -extern void inode_set_flags (struct inode *inode,unsigned int flags,unsigned int mask);
include/linux/pagemap.h +1 -0
@@ -31,6 +31,7 @@ int invalidate_inode_pages2(struct addreint invalidate_inode_pages2_range (struct address_space *mapping,pgoff_t start,pgoff_t end);int kiocb_invalidate_pages (struct kiocb *iocb,size_t count); +void kiocb_invalidate_post_direct_write (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 *);
mm/filemap.c +20 -17
@@ -3733,7 +3733,7 @@ EXPORT_SYMBOL(read_cache_page_gfp);/* * Warn about a page cache invalidation failure during a direct I/O write. */ -void dio_warn_stale_pagecache (struct file *filp) +static void dio_warn_stale_pagecache (struct file *filp) { static DEFINE_RATELIMIT_STATE(_rs, 86400 * HZ, DEFAULT_RATELIMIT_BURST);char pathname[128 ];
@@ -3750,19 +3750,23 @@ void dio_warn_stale_pagecache(struct fil } } +void kiocb_invalidate_post_direct_write (struct kiocb *iocb,size_t count) +{ +struct address_space *mapping = iocb->ki_filp->f_mapping; + +if (mapping->nrpages && +invalidate_inode_pages2_range (mapping, + iocb->ki_pos >>PAGE_SHIFT , + (iocb->ki_pos + count -1 ) >>PAGE_SHIFT )) +dio_warn_stale_pagecache (iocb->ki_filp); +} +ssize_t generic_file_direct_write (struct kiocb *iocb,struct iov_iter *from) { -struct file *file = iocb->ki_filp; -struct address_space *mapping = file->f_mapping; -struct inode *inode = mapping->host; -loff_t pos = iocb->ki_pos; -ssize_t written; -size_t write_len; -pgoff_t end; - - write_len =iov_iter_count (from); - end = (pos + write_len -1 ) >>PAGE_SHIFT ; +struct address_space *mapping = iocb->ki_filp->f_mapping; +size_t write_len =iov_iter_count (from); +ssize_t written;/* * If a page can not be invalidated, return 0 to fall back
@@ -3772,7 +3776,7 @@ generic_file_direct_write(struct kiocb *if (written) {if (written == -EBUSY )return 0 ; - goto out; +return written; } written = mapping->a_ops->direct_IO (iocb, from);
@@ -3794,11 +3798,11 @@ generic_file_direct_write(struct kiocb ** * Skip invalidation for async writes or if mapping has no pages. */ -if (written >0 && mapping->nrpages && -invalidate_inode_pages2_range (mapping, pos >>PAGE_SHIFT , end)) -dio_warn_stale_pagecache (file); -if (written >0 ) { +struct inode *inode = mapping->host; +loff_t pos = iocb->ki_pos; + +kiocb_invalidate_post_direct_write (iocb, written); pos += written; write_len -= written;if (pos >i_size_read (inode) && !S_ISBLK (inode->i_mode)) {
@@ -3809,7 +3813,6 @@ generic_file_direct_write(struct kiocb * }if (written != -EIOCBQUEUED )iov_iter_revert (from, write_len -iov_iter_count (from)); -out:return written; }EXPORT_SYMBOL (generic_file_direct_write);
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
PATCH 3/8 filemap: update ki_pos in generic_perform_write
In reply to Mahmoud AdamFrom: Christoph Hellwig <[email protected]>
commit 182c25e9c157f37bd0ab5a82fe2417e2223df459 upstream.
All callers of generic_perform_write need to updated ki_pos, move it into common code.
--- fs/ceph/file.c | 2 -- fs/ext4/file.c | 9 +++------ fs/f2fs/file.c | 1 - fs/nfs/file.c | 1 - mm/filemap.c | 8 ++++---- 5 files changed, 7 insertions(+), 14 deletions(-)
fs/ceph/file.c +0 -2
@@ -1891,8 +1891,6 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from)* can not run at the same time */ written =generic_perform_write (iocb, from); -if (likely (written >=0 )) - iocb->ki_pos = pos + written;ceph_end_io_write (inode); }
fs/ext4/file.c +3 -6
@@ -287,12 +287,9 @@ static ssize_t ext4_buffered_write_iter(struct kiocb *iocb, out:inode_unlock (inode); -if (likely (ret >0 )) { - iocb->ki_pos += ret; - ret =generic_write_sync (iocb, ret); - } - -return ret; +if (unlikely (ret <=0 )) +return ret; +return generic_write_sync (iocb, ret); } static ssize_t ext4_handle_inode_extension(struct inode *inode, loff_t offset,
fs/f2fs/file.c +0 -1
@@ -4661,7 +4661,6 @@ static ssize_t f2fs_buffered_write_iter(struct kiocb *iocb, current->backing_dev_info =NULL ;if (ret >0 ) { - iocb->ki_pos += ret;f2fs_update_iostat (F2FS_I_SB (inode), inode,APP_BUFFERED_IO , ret); }
fs/nfs/file.c +0 -1
@@ -645,7 +645,6 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) goto out; written = result; - iocb->ki_pos += written;nfs_add_stats (inode,NFSIOS_NORMALWRITTENBYTES , written);if (mntflags &NFS_MOUNT_WRITE_EAGER ) {
mm/filemap.c +4 -4
@@ -3891,7 +3891,10 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i)balance_dirty_pages_ratelimited (mapping); }while (iov_iter_count (i)); -return written ? written : status; +if (!written) +return status; + iocb->ki_pos += written; +return written; }EXPORT_SYMBOL (generic_perform_write);
@@ -3970,7 +3973,6 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) endbyte = pos + status -1 ; err =filemap_write_and_wait_range (mapping, pos, endbyte);if (err ==0 ) { - iocb->ki_pos = endbyte +1 ; written += status; invalidate_mapping_pages(mapping, pos >> PAGE_SHIFT,
@@ -3983,8 +3985,6 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) } }else { written =generic_perform_write (iocb, from); -if (likely (written >0 )) - iocb->ki_pos += written; } out: current->backing_dev_info =NULL ;
Signature · 12 lines
2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597
Patch "filemap: update ki_pos in generic_perform_write" has been added to the 6.1-stable tree
This is a note to let you know that I've just added the patch titled
filemap: update ki_pos in generic_perform_write
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-update-ki_pos-in-generic_perform_write.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:16:51 2025
From: Mahmoud Adam <[email protected]>
Date: Tue, 21 Oct 2025 09:03:38 +0200
Subject: filemap: update ki_pos in generic_perform_write
To: <[email protected]>
Cc: <[email protected]>, <[email protected]>, Christoph Hellwig <[email protected]>, Xiubo Li <[email protected]>, Damien Le Moal <[email protected]>, Hannes Reinecke <[email protected]>, Theodore Ts'o <[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]>, "Trond Myklebust" <[email protected]>, Andrew Morton <[email protected]>, Jeff Layton <[email protected]>, Andreas Dilger <[email protected]>, Christoph Hellwig <[email protected]>, "Ryusuke Konishi" <[email protected]>, Luis Chamberlain <mcgrof@kern
el.org>,
<[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 182c25e9c157f37bd0ab5a82fe2417e2223df459 upstream.
All callers of generic_perform_write need to updated ki_pos, move it into common code.
--- fs/ceph/file.c | 2 -- fs/ext4/file.c | 9 +++------ fs/f2fs/file.c | 1 - fs/nfs/file.c | 1 - mm/filemap.c | 8 ++++---- 5 files changed, 7 insertions(+), 14 deletions(-)
fs/ceph/file.c +0 -2
@@ -1891,8 +1891,6 @@ retry_snap:* can not run at the same time */ written =generic_perform_write (iocb, from); -if (likely (written >=0 )) - iocb->ki_pos = pos + written;ceph_end_io_write (inode); }
fs/ext4/file.c +3 -6
@@ -287,12 +287,9 @@ static ssize_t ext4_buffered_write_iter( out:inode_unlock (inode); -if (likely (ret >0 )) { - iocb->ki_pos += ret; - ret =generic_write_sync (iocb, ret); - } - -return ret; +if (unlikely (ret <=0 )) +return ret; +return generic_write_sync (iocb, ret); } static ssize_t ext4_handle_inode_extension(struct inode *inode, loff_t offset,
fs/f2fs/file.c +0 -1
@@ -4659,7 +4659,6 @@ static ssize_t f2fs_buffered_write_iter( current->backing_dev_info =NULL ;if (ret >0 ) { - iocb->ki_pos += ret;f2fs_update_iostat (F2FS_I_SB (inode), inode,APP_BUFFERED_IO , ret); }
fs/nfs/file.c +0 -1
@@ -645,7 +645,6 @@ ssize_t nfs_file_write(struct kiocb *ioc goto out; written = result; - iocb->ki_pos += written;nfs_add_stats (inode,NFSIOS_NORMALWRITTENBYTES , written);if (mntflags &NFS_MOUNT_WRITE_EAGER ) {
mm/filemap.c +4 -4
@@ -3891,7 +3891,10 @@ again:balance_dirty_pages_ratelimited (mapping); }while (iov_iter_count (i)); -return written ? written : status; +if (!written) +return status; + iocb->ki_pos += written; +return written; }EXPORT_SYMBOL (generic_perform_write);
@@ -3970,7 +3973,6 @@ ssize_t __generic_file_write_iter(struct endbyte = pos + status -1 ; err =filemap_write_and_wait_range (mapping, pos, endbyte);if (err ==0 ) { - iocb->ki_pos = endbyte +1 ; written += status; invalidate_mapping_pages(mapping, pos >> PAGE_SHIFT,
@@ -3983,8 +3985,6 @@ ssize_t __generic_file_write_iter(struct } }else { written =generic_perform_write (iocb, from); -if (likely (written >0 )) - iocb->ki_pos += written; } out: current->backing_dev_info =NULL ;
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
PATCH 4/8 fs: factor out a direct_write_fallback helper
In reply to Mahmoud AdamFrom: Christoph Hellwig <[email protected]>
commit 44fff0fa08ec5a6d9d5fb05443a36d854d0ece4d upstream.
Add a helper dealing with handling the syncing of a buffered write fallback for direct I/O.
[backing_dev_info still being used here. do small changes to the patch to keep the out label. Which means replacing all returns to goto out.]
--- fs/libfs.c | 41 +++++++++++++++++++++++++++++++ include/linux/fs.h | 2 ++ mm/filemap.c | 61 +++++++++++----------------------------------- 3 files changed, 57 insertions(+), 47 deletions(-)
fs/libfs.c +41 -0
@@ -1582,3 +1582,44 @@ bool inode_maybe_inc_iversion(struct inode *inode, bool force)return true; }EXPORT_SYMBOL (inode_maybe_inc_iversion); + +ssize_t direct_write_fallback (struct kiocb *iocb,struct iov_iter *iter, +ssize_t direct_written,ssize_t buffered_written) +{ +struct address_space *mapping = iocb->ki_filp->f_mapping; +loff_t pos = iocb->ki_pos - buffered_written; +loff_t end = iocb->ki_pos -1 ; +int err; + +/* +* If the buffered write fallback returned an error, we want to return +* the number of bytes which were written by direct I/O, or the error +* code if that was zero. +* +* Note that this differs from normal direct-io semantics, which will +* return -EFOO even if some bytes were written. +*/ +if (unlikely (buffered_written <0 )) { +if (direct_written) +return direct_written; +return buffered_written; + } + +/* +* We need to ensure that the page cache pages are written to disk and +* invalidated to preserve the expected O_DIRECT semantics. +*/ + err =filemap_write_and_wait_range (mapping, pos, end); +if (err <0 ) { +/* +* We don't know how much we wrote, so just return the number of +* bytes which were direct-written +*/ +if (direct_written) +return direct_written; +return err; + } +invalidate_mapping_pages (mapping, pos >>PAGE_SHIFT , end >>PAGE_SHIFT ); +return direct_written + buffered_written; +} +EXPORT_SYMBOL_GPL (direct_write_fallback);
include/linux/fs.h +2 -0
@@ -3278,6 +3278,8 @@ extern ssize_t __generic_file_write_iter(struct kiocb *, struct iov_iter *);extern ssize_t generic_file_write_iter (struct kiocb *,struct iov_iter *);extern ssize_t generic_file_direct_write (struct kiocb *,struct iov_iter *);ssize_t generic_perform_write (struct kiocb *,struct iov_iter *); +ssize_t direct_write_fallback (struct kiocb *iocb,struct iov_iter *iter, +ssize_t direct_written,ssize_t buffered_written);ssize_t vfs_iter_read (struct file *file,struct iov_iter *iter,loff_t *ppos,rwf_t flags);
mm/filemap.c +14 -47
85 lines not on this page · raw message
Signature · 12 lines
2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597
Patch "fs: factor out a direct_write_fallback helper" has been added to the 6.1-stable tree
This is a note to let you know that I've just added the patch titled
fs: factor out a direct_write_fallback 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:
fs-factor-out-a-direct_write_fallback-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:17:20 2025
From: Mahmoud Adam <[email protected]>
Date: Tue, 21 Oct 2025 09:03:39 +0200
Subject: fs: factor out a direct_write_fallback helper
To: <[email protected]>
Cc: <[email protected]>, <[email protected]>, Christoph Hellwig <[email protected]>, Damien Le Moal <[email protected]>, Miklos Szeredi <[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]>, Hannes Reinecke <[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]>, "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 <mcgrof@kern
el.org>,
<[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 44fff0fa08ec5a6d9d5fb05443a36d854d0ece4d upstream.
Add a helper dealing with handling the syncing of a buffered write fallback for direct I/O.
[backing_dev_info still being used here. do small changes to the patch to keep the out label. Which means replacing all returns to goto out.]
--- fs/libfs.c | 41 +++++++++++++++++++++++++++++++++++ include/linux/fs.h | 2 + mm/filemap.c | 61 ++++++++++++----------------------------------------- 3 files changed, 57 insertions(+), 47 deletions(-)
fs/libfs.c +41 -0
@@ -1582,3 +1582,44 @@ bool inode_maybe_inc_iversion(struct inoreturn true; }EXPORT_SYMBOL (inode_maybe_inc_iversion); + +ssize_t direct_write_fallback (struct kiocb *iocb,struct iov_iter *iter, +ssize_t direct_written,ssize_t buffered_written) +{ +struct address_space *mapping = iocb->ki_filp->f_mapping; +loff_t pos = iocb->ki_pos - buffered_written; +loff_t end = iocb->ki_pos -1 ; +int err; + +/* +* If the buffered write fallback returned an error, we want to return +* the number of bytes which were written by direct I/O, or the error +* code if that was zero. +* +* Note that this differs from normal direct-io semantics, which will +* return -EFOO even if some bytes were written. +*/ +if (unlikely (buffered_written <0 )) { +if (direct_written) +return direct_written; +return buffered_written; + } + +/* +* We need to ensure that the page cache pages are written to disk and +* invalidated to preserve the expected O_DIRECT semantics. +*/ + err =filemap_write_and_wait_range (mapping, pos, end); +if (err <0 ) { +/* +* We don't know how much we wrote, so just return the number of +* bytes which were direct-written +*/ +if (direct_written) +return direct_written; +return err; + } +invalidate_mapping_pages (mapping, pos >>PAGE_SHIFT , end >>PAGE_SHIFT ); +return direct_written + buffered_written; +} +EXPORT_SYMBOL_GPL (direct_write_fallback);
include/linux/fs.h +2 -0
@@ -3278,6 +3278,8 @@ extern ssize_t __generic_file_write_iterextern ssize_t generic_file_write_iter (struct kiocb *,struct iov_iter *);extern ssize_t generic_file_direct_write (struct kiocb *,struct iov_iter *);ssize_t generic_perform_write (struct kiocb *,struct iov_iter *); +ssize_t direct_write_fallback (struct kiocb *iocb,struct iov_iter *iter, +ssize_t direct_written,ssize_t buffered_written);ssize_t vfs_iter_read (struct file *file,struct iov_iter *iter,loff_t *ppos,rwf_t flags);
mm/filemap.c +14 -47
85 lines not on this page · raw message
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
PATCH 5/8 direct_write_fallback(): on error revert the ->ki_pos update from buffered write
In reply to Mahmoud AdamFrom: Al Viro <[email protected]>
commit 8287474aa5ffb41df52552c4ae4748e791d2faf2 upstream.
If we fail filemap_write_and_wait_range() on the range the buffered write went into, we only report the "number of bytes which we direct-written", to quote the comment in there. Which is fine, but buffered write has already advanced iocb->ki_pos, so we need to roll that back. Otherwise we end up with e.g. write(2) advancing position by more than the amount it reports having written.
Message-Id: <20230827214518.GU3390869@ZenIV>
--- fs/libfs.c | 1 + 1 file changed, 1 insertion(+)
fs/libfs.c +1 -0
@@ -1615,6 +1615,7 @@ ssize_t direct_write_fallback(struct kiocb *iocb, struct iov_iter *iter,* We don't know how much we wrote, so just return the number of * bytes which were direct-written */ + iocb->ki_pos -= buffered_written;if (direct_written)return direct_written;return err;
Signature · 12 lines
2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597
Patch "direct_write_fallback(): on error revert the ->ki_pos update from buffered write" has been added to the 6.1-stable tree
20230827214518.GU3390869@ZenIV>
Message-ID: <2025110356-extending-goal-0e9a@gregkh>
MIME-Version: 1.0
Content-Type: text/plain; charset=ANSI_X3.4-1968
Content-Transfer-Encoding: 8bit
X-stable: commit
X-Patchwork-Hint: ignore
This is a note to let you know that I've just added the patch titled
direct_write_fallback(): on error revert the ->ki_pos update from buffered write
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:
direct_write_fallback-on-error-revert-the-ki_pos-update-from-buffered-write.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:13:26 2025
From: Mahmoud Adam <[email protected]>
Date: Tue, 21 Oct 2025 09:03:40 +0200
Subject: direct_write_fallback(): on error revert the ->ki_pos update from buffered write
To: <[email protected]>
Cc: <[email protected]>, <[email protected]>, Al Viro <[email protected]>, Christian Brauner <[email protected]>, Jens Axboe <[email protected]>, Xiubo Li <[email protected]>, Ilya Dryomov <[email protected]>, Jeff Layton <[email protected]>, Theodore Ts'o <[email protected]>, Andreas Dilger <[email protected]>, Jaegeuk Kim <[email protected]>, Chao Yu <[email protected]>, Christoph Hellwig <[email protected]>, "Darrick J. Wong" <[email protected]>, Trond Myklebust <[email protected]>, Anna Schumaker <[email protected]>, "Ryusuke Konishi" <[email protected]>, "Matthew Wilcox (Oracle)" <[email protected]>, Andrew Morton <[email protected]>, "Hannes Reinecke" <[email protected]>, Damien Le Moal <[email protected]>, "Luis Chamberlain" <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <linux-f2fs-devel@lists.
sourcefo
rge.net>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>
Message-ID: <[email protected]>
From: Al Viro <[email protected]>
commit 8287474aa5ffb41df52552c4ae4748e791d2faf2 upstream.
If we fail filemap_write_and_wait_range() on the range the buffered write went into, we only report the "number of bytes which we direct-written", to quote the comment in there. Which is fine, but buffered write has already advanced iocb->ki_pos, so we need to roll that back. Otherwise we end up with e.g. write(2) advancing position by more than the amount it reports having written.
Message-Id: <20230827214518.GU3390869@ZenIV>
--- fs/libfs.c | 1 + 1 file changed, 1 insertion(+)
fs/libfs.c +1 -0
@@ -1615,6 +1615,7 @@ ssize_t direct_write_fallback(struct kio* We don't know how much we wrote, so just return the number of * bytes which were direct-written */ + iocb->ki_pos -= buffered_written;if (direct_written)return direct_written;return err;
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
PATCH 6/8 block: open code __generic_file_write_iter for blkdev writes
In reply to Mahmoud AdamFrom: Christoph Hellwig <[email protected]>
commit 727cfe976758b79f8d2f8051c75a5ccb14539a56 upstream.
Open code __generic_file_write_iter to remove the indirect call into ->direct_IO and to prepare using the iomap based write code.
--- block/fops.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-)
block/fops.c +43 -2
@@ -515,6 +515,30 @@ static int blkdev_close(struct inode *inode, struct file *filp)return 0 ; } +static ssize_t +blkdev_direct_write (struct kiocb *iocb,struct iov_iter *from) +{ +size_t count =iov_iter_count (from); +ssize_t written; + + written =kiocb_invalidate_pages (iocb, count); +if (written) { +if (written == -EBUSY ) +return 0 ; +return written; + } + + written =blkdev_direct_IO (iocb, from); +if (written >0 ) { +kiocb_invalidate_post_direct_write (iocb, count); + iocb->ki_pos += written; + count -= written; + } +if (written != -EIOCBQUEUED ) +iov_iter_revert (from, count -iov_iter_count (from)); +return written; +} +/* * Write data to the block device. Only intended for the block device itself * and the raw driver which basically is a fake block device.
@@ -524,7 +548,8 @@ static int blkdev_close(struct inode *inode, struct file *filp)*/ static ssize_t blkdev_write_iter (struct kiocb *iocb,struct iov_iter *from) { -struct block_device *bdev = iocb->ki_filp->private_data; +struct file *file = iocb->ki_filp; +struct block_device *bdev = file->private_data;struct inode *bd_inode = bdev->bd_inode;loff_t size =bdev_nr_bytes (bdev);struct blk_plug plug;
@@ -553,7 +578,23 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) }blk_start_plug (&plug); - ret =__generic_file_write_iter (iocb, from); + ret =file_remove_privs (file); +if (ret) +return ret; + + ret =file_update_time (file); +if (ret) +return ret; + +if (iocb->ki_flags &IOCB_DIRECT ) { + ret =blkdev_direct_write (iocb, from); +if (ret >=0 &&iov_iter_count (from)) + ret =direct_write_fallback (iocb, from, ret, +generic_perform_write (iocb, from)); + }else { + ret =generic_perform_write (iocb, from); + } +if (ret >0 ) ret =generic_write_sync (iocb, ret);iov_iter_reexpand (from,iov_iter_count (from) + shorted);
Signature · 12 lines
2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597
Patch "block: open code __generic_file_write_iter for blkdev writes" has been added to the 6.1-stable tree
This is a note to let you know that I've just added the patch titled
block: open code __generic_file_write_iter for blkdev writes
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:
block-open-code-__generic_file_write_iter-for-blkdev-writes.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:18:34 2025
From: Mahmoud Adam <[email protected]>
Date: Tue, 21 Oct 2025 09:03:41 +0200
Subject: block: open code __generic_file_write_iter for blkdev writes
To: <[email protected]>
Cc: <[email protected]>, <[email protected]>, Christoph Hellwig <[email protected]>, Johannes Thumshirn <[email protected]>, "Christian Brauner" <[email protected]>, Hannes Reinecke <[email protected]>, "Luis Chamberlain" <[email protected]>, Jens Axboe <[email protected]>, Xiubo Li <[email protected]>, Ilya Dryomov <[email protected]>, Jeff Layton <[email protected]>, Alexander Viro <[email protected]>, Theodore Ts'o <[email protected]>, Andreas Dilger <[email protected]>, Jaegeuk Kim <[email protected]>, Chao Yu <[email protected]>, Christoph Hellwig <[email protected]>, "Darrick J. Wong" <[email protected]>, Trond Myklebust <[email protected]>, Anna Schumaker <[email protected]>, "Ryusuke Konishi" <[email protected]>, "Matthew Wilcox (Oracle)" <[email protected]>, Andrew Morton <[email protected]>, "Damien Le Moal" <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]
Quoted 1 line
, <linu
[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>
Message-ID: <[email protected]>
From: Christoph Hellwig <[email protected]>
commit 727cfe976758b79f8d2f8051c75a5ccb14539a56 upstream.
Open code __generic_file_write_iter to remove the indirect call into ->direct_IO and to prepare using the iomap based write code.
--- block/fops.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-)
block/fops.c +43 -2
@@ -515,6 +515,30 @@ static int blkdev_close(struct inode *inreturn 0 ; } +static ssize_t +blkdev_direct_write (struct kiocb *iocb,struct iov_iter *from) +{ +size_t count =iov_iter_count (from); +ssize_t written; + + written =kiocb_invalidate_pages (iocb, count); +if (written) { +if (written == -EBUSY ) +return 0 ; +return written; + } + + written =blkdev_direct_IO (iocb, from); +if (written >0 ) { +kiocb_invalidate_post_direct_write (iocb, count); + iocb->ki_pos += written; + count -= written; + } +if (written != -EIOCBQUEUED ) +iov_iter_revert (from, count -iov_iter_count (from)); +return written; +} +/* * Write data to the block device. Only intended for the block device itself * and the raw driver which basically is a fake block device.
@@ -524,7 +548,8 @@ static int blkdev_close(struct inode *in*/ static ssize_t blkdev_write_iter (struct kiocb *iocb,struct iov_iter *from) { -struct block_device *bdev = iocb->ki_filp->private_data; +struct file *file = iocb->ki_filp; +struct block_device *bdev = file->private_data;struct inode *bd_inode = bdev->bd_inode;loff_t size =bdev_nr_bytes (bdev);struct blk_plug plug;
@@ -553,7 +578,23 @@ static ssize_t blkdev_write_iter(struct }blk_start_plug (&plug); - ret =__generic_file_write_iter (iocb, from); + ret =file_remove_privs (file); +if (ret) +return ret; + + ret =file_update_time (file); +if (ret) +return ret; + +if (iocb->ki_flags &IOCB_DIRECT ) { + ret =blkdev_direct_write (iocb, from); +if (ret >=0 &&iov_iter_count (from)) + ret =direct_write_fallback (iocb, from, ret, +generic_perform_write (iocb, from)); + }else { + ret =generic_perform_write (iocb, from); + } +if (ret >0 ) ret =generic_write_sync (iocb, ret);iov_iter_reexpand (from,iov_iter_count (from) + shorted);
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
PATCH 7/8 block: fix race between set_blocksize and read paths
In reply to Mahmoud AdamFrom: "Darrick J. Wong" <[email protected]>
commit c0e473a0d226479e8e925d5ba93f751d8df628e9 upstream.
With the new large sector size support, it's now the case that set_blocksize can change i_blksize and the folio order in a manner that conflicts with a concurrent reader and causes a kernel crash.
Specifically, let's say that udev-worker calls libblkid to detect the labels on a block device. The read call can create an order-0 folio to read the first 4096 bytes from the disk. But then udev is preempted.
Next, someone tries to mount an 8k-sectorsize filesystem from the same block device. The filesystem calls set_blksize, which sets i_blksize to 8192 and the minimum folio order to 1.
Now udev resumes, still holding the order-0 folio it allocated. It then tries to schedule a read bio and do_mpage_readahead tries to create bufferheads for the folio. Unfortunately, blocks_per_folio == 0 because the page size is 4096 but the blocksize is 8192 so no bufferheads are attached and the bh walk never sets bdev. We then submit the bio with a NULL block device and crash.
Therefore, truncate the page cache after flushing but before updating i_blksize. However, that's not enough -- we also need to lock out file IO and page faults during the update. Take both the i_rwsem and the invalidate_lock in exclusive mode for invalidations, and in shared mode for read/write operations.
I don't know if this is the correct fix, but xfs/259 found it.
--- block/bdev.c | 17 +++++++++++++++++ block/blk-zoned.c | 5 ++++- block/fops.c | 16 ++++++++++++++++ block/ioctl.c | 6 ++++++ 4 files changed, 43 insertions(+), 1 deletion(-)
block/bdev.c +17 -0
@@ -147,9 +147,26 @@ int set_blocksize(struct block_device *bdev, int size)/* Don't change the size if it is same as current */ if (bdev->bd_inode->i_blkbits !=blksize_bits (size)) { +/* +* Flush and truncate the pagecache before we reconfigure the +* mapping geometry because folio sizes are variable now. If a +* reader has already allocated a folio whose size is smaller +* than the new min_order but invokes readahead after the new +* min_order becomes visible, readahead will think there are +* "zero" blocks per folio and crash. Take the inode and +* invalidation locks to avoid racing with +* read/write/fallocate. +*/ +inode_lock (bdev->bd_inode); +filemap_invalidate_lock (bdev->bd_inode->i_mapping); +sync_blockdev (bdev); +kill_bdev (bdev); + bdev->bd_inode->i_blkbits =blksize_bits (size);kill_bdev (bdev); +filemap_invalidate_unlock (bdev->bd_inode->i_mapping); +inode_unlock (bdev->bd_inode); }return 0 ; }
block/blk-zoned.c +4 -1
@@ -417,6 +417,7 @@ int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode, op =REQ_OP_ZONE_RESET ;/* Invalidate the page cache, including dirty pages. */ +inode_lock (bdev->bd_inode);filemap_invalidate_lock (bdev->bd_inode->i_mapping); ret =blkdev_truncate_zone_range (bdev, mode, &zrange);if (ret)
@@ -439,8 +440,10 @@ int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode, GFP_KERNEL); fail: -if (cmd ==BLKRESETZONE ) +if (cmd ==BLKRESETZONE ) {filemap_invalidate_unlock (bdev->bd_inode->i_mapping); +inode_unlock (bdev->bd_inode); + }return ret; }
block/fops.c +16 -0
@@ -592,7 +592,14 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) ret =direct_write_fallback (iocb, from, ret,generic_perform_write (iocb, from)); }else { +/* +* Take i_rwsem and invalidate_lock to avoid racing with +* set_blocksize changing i_blkbits/folio order and punching +* out the pagecache. +*/ +inode_lock_shared (bd_inode); ret =generic_perform_write (iocb, from); +inode_unlock_shared (bd_inode); }if (ret >0 )
@@ -605,6 +612,7 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)static ssize_t blkdev_read_iter (struct kiocb *iocb,struct iov_iter *to) {struct block_device *bdev = iocb->ki_filp->private_data; +struct inode *bd_inode = bdev->bd_inode;loff_t size =bdev_nr_bytes (bdev);loff_t pos = iocb->ki_pos;size_t shorted =0 ;
@@ -652,7 +660,13 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to) goto reexpand; } +/* +* Take i_rwsem and invalidate_lock to avoid racing with set_blocksize +* changing i_blkbits/folio order and punching out the pagecache. +*/ +inode_lock_shared (bd_inode); ret =filemap_read (iocb, to, ret); +inode_unlock_shared (bd_inode); reexpand:if (unlikely (shorted))
@@ -695,6 +709,7 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start,if ((start | len) & (bdev_logical_block_size (bdev) -1 ))return -EINVAL ; +inode_lock (inode);filemap_invalidate_lock (inode->i_mapping);/*
@@ -735,6 +750,7 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start, fail:filemap_invalidate_unlock (inode->i_mapping); +inode_unlock (inode);return error; }
block/ioctl.c +6 -0
@@ -114,6 +114,7 @@ static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode, end > bdev_nr_bytes(bdev))return -EINVAL ; +inode_lock (inode);filemap_invalidate_lock (inode->i_mapping); err =truncate_bdev_range (bdev, mode, start, end -1 );if (err)
@@ -121,6 +122,7 @@ static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode, err =blkdev_issue_discard (bdev, start >>9 , len >>9 ,GFP_KERNEL ); fail:filemap_invalidate_unlock (inode->i_mapping); +inode_unlock (inode);return err; }
@@ -146,12 +148,14 @@ static int blk_ioctl_secure_erase(struct block_device *bdev, fmode_t mode, end > bdev_nr_bytes(bdev))return -EINVAL ; +inode_lock (bdev->bd_inode);filemap_invalidate_lock (bdev->bd_inode->i_mapping); err =truncate_bdev_range (bdev, mode, start, end -1 );if (!err) err =blkdev_issue_secure_erase (bdev, start >>9 , len >>9 ,GFP_KERNEL );filemap_invalidate_unlock (bdev->bd_inode->i_mapping); +inode_unlock (bdev->bd_inode);return err; }
@@ -184,6 +188,7 @@ static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode,return -EINVAL ;/* Invalidate the page cache, including dirty pages */ +inode_lock (inode);filemap_invalidate_lock (inode->i_mapping); err =truncate_bdev_range (bdev, mode, start, end);if (err)
@@ -194,6 +199,7 @@ static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode, fail:filemap_invalidate_unlock (inode->i_mapping); +inode_unlock (inode);return err; }
Signature · 12 lines
2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597
Patch "block: fix race between set_blocksize and read paths" has been added to the 6.1-stable tree
This is a note to let you know that I've just added the patch titled
block: fix race between set_blocksize and read paths
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:
block-fix-race-between-set_blocksize-and-read-paths.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:13:58 2025
From: Mahmoud Adam <[email protected]>
Date: Tue, 21 Oct 2025 09:03:42 +0200
Subject: block: fix race between set_blocksize and read paths
To: <[email protected]>
Cc: <[email protected]>, <[email protected]>, "Darrick J. Wong" <[email protected]>, Christoph Hellwig <[email protected]>, Luis Chamberlain <[email protected]>, Shin'ichiro Kawasaki <[email protected]>, "Jens Axboe" <[email protected]>, Xiubo Li <[email protected]>, Ilya Dryomov <[email protected]>, Jeff Layton <[email protected]>, Alexander Viro <[email protected]>, Theodore Ts'o <[email protected]>, Andreas Dilger <[email protected]>, Jaegeuk Kim <[email protected]>, Chao Yu <[email protected]>, Christoph Hellwig <[email protected]>, Trond Myklebust <[email protected]>, Anna Schumaker <[email protected]>, "Ryusuke Konishi" <[email protected]>, "Matthew Wilcox (Oracle)" <[email protected]>, Andrew Morton <[email protected]>, "Hannes Reinecke" <[email protected]>, Damien Le Moal <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <li
nux-ext4
@vger.kernel.org>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>
Message-ID: <[email protected]>
From: "Darrick J. Wong" <[email protected]>
commit c0e473a0d226479e8e925d5ba93f751d8df628e9 upstream.
With the new large sector size support, it's now the case that set_blocksize can change i_blksize and the folio order in a manner that conflicts with a concurrent reader and causes a kernel crash.
Specifically, let's say that udev-worker calls libblkid to detect the labels on a block device. The read call can create an order-0 folio to read the first 4096 bytes from the disk. But then udev is preempted.
Next, someone tries to mount an 8k-sectorsize filesystem from the same block device. The filesystem calls set_blksize, which sets i_blksize to 8192 and the minimum folio order to 1.
Now udev resumes, still holding the order-0 folio it allocated. It then tries to schedule a read bio and do_mpage_readahead tries to create bufferheads for the folio. Unfortunately, blocks_per_folio == 0 because the page size is 4096 but the blocksize is 8192 so no bufferheads are attached and the bh walk never sets bdev. We then submit the bio with a NULL block device and crash.
Therefore, truncate the page cache after flushing but before updating i_blksize. However, that's not enough -- we also need to lock out file IO and page faults during the update. Take both the i_rwsem and the invalidate_lock in exclusive mode for invalidations, and in shared mode for read/write operations.
I don't know if this is the correct fix, but xfs/259 found it.
--- block/bdev.c | 17 +++++++++++++++++ block/blk-zoned.c | 5 ++++- block/fops.c | 16 ++++++++++++++++ block/ioctl.c | 6 ++++++ 4 files changed, 43 insertions(+), 1 deletion(-)
block/bdev.c +17 -0
@@ -147,9 +147,26 @@ int set_blocksize(struct block_device *b/* Don't change the size if it is same as current */ if (bdev->bd_inode->i_blkbits !=blksize_bits (size)) { +/* +* Flush and truncate the pagecache before we reconfigure the +* mapping geometry because folio sizes are variable now. If a +* reader has already allocated a folio whose size is smaller +* than the new min_order but invokes readahead after the new +* min_order becomes visible, readahead will think there are +* "zero" blocks per folio and crash. Take the inode and +* invalidation locks to avoid racing with +* read/write/fallocate. +*/ +inode_lock (bdev->bd_inode); +filemap_invalidate_lock (bdev->bd_inode->i_mapping); +sync_blockdev (bdev); +kill_bdev (bdev); + bdev->bd_inode->i_blkbits =blksize_bits (size);kill_bdev (bdev); +filemap_invalidate_unlock (bdev->bd_inode->i_mapping); +inode_unlock (bdev->bd_inode); }return 0 ; }
block/blk-zoned.c +4 -1
@@ -417,6 +417,7 @@ int blkdev_zone_mgmt_ioctl(struct block_ op =REQ_OP_ZONE_RESET ;/* Invalidate the page cache, including dirty pages. */ +inode_lock (bdev->bd_inode);filemap_invalidate_lock (bdev->bd_inode->i_mapping); ret =blkdev_truncate_zone_range (bdev, mode, &zrange);if (ret)
@@ -439,8 +440,10 @@ int blkdev_zone_mgmt_ioctl(struct block_ GFP_KERNEL); fail: -if (cmd ==BLKRESETZONE ) +if (cmd ==BLKRESETZONE ) {filemap_invalidate_unlock (bdev->bd_inode->i_mapping); +inode_unlock (bdev->bd_inode); + }return ret; }
block/fops.c +16 -0
@@ -592,7 +592,14 @@ static ssize_t blkdev_write_iter(struct ret =direct_write_fallback (iocb, from, ret,generic_perform_write (iocb, from)); }else { +/* +* Take i_rwsem and invalidate_lock to avoid racing with +* set_blocksize changing i_blkbits/folio order and punching +* out the pagecache. +*/ +inode_lock_shared (bd_inode); ret =generic_perform_write (iocb, from); +inode_unlock_shared (bd_inode); }if (ret >0 )
@@ -605,6 +612,7 @@ static ssize_t blkdev_write_iter(structstatic ssize_t blkdev_read_iter (struct kiocb *iocb,struct iov_iter *to) {struct block_device *bdev = iocb->ki_filp->private_data; +struct inode *bd_inode = bdev->bd_inode;loff_t size =bdev_nr_bytes (bdev);loff_t pos = iocb->ki_pos;size_t shorted =0 ;
@@ -652,7 +660,13 @@ static ssize_t blkdev_read_iter(struct k goto reexpand; } +/* +* Take i_rwsem and invalidate_lock to avoid racing with set_blocksize +* changing i_blkbits/folio order and punching out the pagecache. +*/ +inode_lock_shared (bd_inode); ret =filemap_read (iocb, to, ret); +inode_unlock_shared (bd_inode); reexpand:if (unlikely (shorted))
@@ -695,6 +709,7 @@ static long blkdev_fallocate(struct fileif ((start | len) & (bdev_logical_block_size (bdev) -1 ))return -EINVAL ; +inode_lock (inode);filemap_invalidate_lock (inode->i_mapping);/*
@@ -735,6 +750,7 @@ static long blkdev_fallocate(struct file fail:filemap_invalidate_unlock (inode->i_mapping); +inode_unlock (inode);return error; }
block/ioctl.c +6 -0
@@ -114,6 +114,7 @@ static int blk_ioctl_discard(struct bloc end > bdev_nr_bytes(bdev))return -EINVAL ; +inode_lock (inode);filemap_invalidate_lock (inode->i_mapping); err =truncate_bdev_range (bdev, mode, start, end -1 );if (err)
@@ -121,6 +122,7 @@ static int blk_ioctl_discard(struct bloc err =blkdev_issue_discard (bdev, start >>9 , len >>9 ,GFP_KERNEL ); fail:filemap_invalidate_unlock (inode->i_mapping); +inode_unlock (inode);return err; }
@@ -146,12 +148,14 @@ static int blk_ioctl_secure_erase(struct end > bdev_nr_bytes(bdev))return -EINVAL ; +inode_lock (bdev->bd_inode);filemap_invalidate_lock (bdev->bd_inode->i_mapping); err =truncate_bdev_range (bdev, mode, start, end -1 );if (!err) err =blkdev_issue_secure_erase (bdev, start >>9 , len >>9 ,GFP_KERNEL );filemap_invalidate_unlock (bdev->bd_inode->i_mapping); +inode_unlock (bdev->bd_inode);return err; }
@@ -184,6 +188,7 @@ static int blk_ioctl_zeroout(struct blocreturn -EINVAL ;/* Invalidate the page cache, including dirty pages */ +inode_lock (inode);filemap_invalidate_lock (inode->i_mapping); err =truncate_bdev_range (bdev, mode, start, end);if (err)
@@ -194,6 +199,7 @@ static int blk_ioctl_zeroout(struct bloc fail:filemap_invalidate_unlock (inode->i_mapping); +inode_unlock (inode);return err; }
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
PATCH 8/8 nilfs2: fix deadlock warnings caused by lock dependency in init_nilfs()
In reply to Mahmoud AdamFrom: Ryusuke Konishi <[email protected]>
commit fb881cd7604536b17a1927fb0533f9a6982ffcc5 upstream.
After commit c0e473a0d226 ("block: fix race between set_blocksize and read paths") was merged, set_blocksize() called by sb_set_blocksize() now locks the inode of the backing device file. As a result of this change, syzbot started reporting deadlock warnings due to a circular dependency involving the semaphore "ns_sem" of the nilfs object, the inode lock of the backing device file, and the locks that this inode lock is transitively dependent on.
This is caused by a new lock dependency added by the above change, since init_nilfs() calls sb_set_blocksize() in the lock section of "ns_sem". However, these warnings are false positives because init_nilfs() is called in the early stage of the mount operation and the filesystem has not yet started.
The reason why "ns_sem" is locked in init_nilfs() was to avoid a race condition in nilfs_fill_super() caused by sharing a nilfs object among multiple filesystem instances (super block structures) in the early implementation. However, nilfs objects and super block structures have long ago become one-to-one, and there is no longer any need to use the semaphore there.
So, fix this issue by removing the use of the semaphore "ns_sem" in init_nilfs().
--- fs/nilfs2/the_nilfs.c | 3 --- 1 file changed, 3 deletions(-)
fs/nilfs2/the_nilfs.c +0 -3
@@ -680,8 +680,6 @@ int init_nilfs(struct the_nilfs *nilfs, struct super_block *sb, char *data)int blocksize;int err; -down_write (&nilfs->ns_sem); - blocksize =sb_min_blocksize (sb,NILFS_MIN_BLOCK_SIZE );if (!blocksize) {nilfs_err (sb,"unable to set blocksize" );
@@ -757,7 +755,6 @@ int init_nilfs(struct the_nilfs *nilfs, struct super_block *sb, char *data)set_nilfs_init (nilfs); err =0 ; out: -up_write (&nilfs->ns_sem);return err; failed_sbh:
Signature · 12 lines
2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597
Patch "nilfs2: fix deadlock warnings caused by lock dependency in init_nilfs()" has been added to the 6.1-stable tree
This is a note to let you know that I've just added the patch titled
nilfs2: fix deadlock warnings caused by lock dependency in init_nilfs()
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:
nilfs2-fix-deadlock-warnings-caused-by-lock-dependency-in-init_nilfs.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:19:13 2025
From: Mahmoud Adam <[email protected]>
Date: Tue, 21 Oct 2025 09:03:43 +0200
Subject: nilfs2: fix deadlock warnings caused by lock dependency in init_nilfs()
To: <[email protected]>
Cc: <[email protected]>, <[email protected]>, Ryusuke Konishi <[email protected]>, <[email protected]>, <[email protected]>, Andrew Morton <[email protected]>, Jens Axboe <[email protected]>, Xiubo Li <[email protected]>, Ilya Dryomov <[email protected]>, Jeff Layton <[email protected]>, Alexander Viro <[email protected]>, Theodore Ts'o <[email protected]>, Andreas Dilger <[email protected]>, Jaegeuk Kim <[email protected]>, Chao Yu <[email protected]>, Christoph Hellwig <[email protected]>, "Darrick J. Wong" <[email protected]>, Trond Myklebust <[email protected]>, Anna Schumaker <[email protected]>, "Matthew Wilcox (Oracle)" <[email protected]>, Hannes Reinecke <[email protected]>, Damien Le Moal <[email protected]>, Luis Chamberlain <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <linux-fsdev
el@vger.
kernel.org>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>
Message-ID: <[email protected]>
From: Ryusuke Konishi <[email protected]>
commit fb881cd7604536b17a1927fb0533f9a6982ffcc5 upstream.
After commit c0e473a0d226 ("block: fix race between set_blocksize and read paths") was merged, set_blocksize() called by sb_set_blocksize() now locks the inode of the backing device file. As a result of this change, syzbot started reporting deadlock warnings due to a circular dependency involving the semaphore "ns_sem" of the nilfs object, the inode lock of the backing device file, and the locks that this inode lock is transitively dependent on.
This is caused by a new lock dependency added by the above change, since init_nilfs() calls sb_set_blocksize() in the lock section of "ns_sem". However, these warnings are false positives because init_nilfs() is called in the early stage of the mount operation and the filesystem has not yet started.
The reason why "ns_sem" is locked in init_nilfs() was to avoid a race condition in nilfs_fill_super() caused by sharing a nilfs object among multiple filesystem instances (super block structures) in the early implementation. However, nilfs objects and super block structures have long ago become one-to-one, and there is no longer any need to use the semaphore there.
So, fix this issue by removing the use of the semaphore "ns_sem" in init_nilfs().
--- fs/nilfs2/the_nilfs.c | 3 --- 1 file changed, 3 deletions(-)
fs/nilfs2/the_nilfs.c +0 -3
@@ -680,8 +680,6 @@ int init_nilfs(struct the_nilfs *nilfs,int blocksize;int err; -down_write (&nilfs->ns_sem); - blocksize =sb_min_blocksize (sb,NILFS_MIN_BLOCK_SIZE );if (!blocksize) {nilfs_err (sb,"unable to set blocksize" );
@@ -757,7 +755,6 @@ int init_nilfs(struct the_nilfs *nilfs,set_nilfs_init (nilfs); err =0 ; out: -up_write (&nilfs->ns_sem);return err; failed_sbh:
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
Greg KH
maintainerQuoted 1 line · Mahmoud Adam
This series aims to fix the CVE-2025-38073 for 6.1 LTS.
That's not going to work until there is a fix in the 6.6.y tree first. You all know this quite well :(
Please work on that tree first, and then move to older ones.
thanks,
greg k-h
Quoted 10 lines · Greg KH
Quoted 1 line · Mahmoud Adam
This series aims to fix the CVE-2025-38073 for 6.1 LTS.
That's not going to work until there is a fix in the 6.6.y tree first. You all know this quite well :(
Please work on that tree first, and then move to older ones.
Yup, I've already sent a series for 6.6 yesterday:
https://lore.kernel.org/stable/[email protected]/
- MNAdam
Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13
10243 Berlin
Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597
Greg KH
maintainerQuoted 7 lines · Mahmoud Nagy Adam
Quoted 5 lines · Greg KH
Quoted 1 line · Mahmoud Adam
This series aims to fix the CVE-2025-38073 for 6.1 LTS.
Quoted 8 lines
Quoted 5 lines
That's not going to work until there is a fix in the 6.6.y tree first. You all know this quite well :(
Please work on that tree first, and then move to older ones.
Yup, I've already sent a series for 6.6 yesterday:
https://lore.kernel.org/stable/[email protected]/
Ah, totally missed that as it was "just" a single backport, my fault.
Thanks for this, I'll review this when I get a chance. How was this tested?
greg k-h
Quoted 11 lines · Greg KH
Quoted 10 lines · Mahmoud Nagy Adam
Quoted 8 lines · Greg KH
Quoted 1 line · Mahmoud Adam
This series aims to fix the CVE-2025-38073 for 6.1 LTS.
That's not going to work until there is a fix in the 6.6.y tree first. You all know this quite well :(
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Please work on that tree first, and then move to older ones.
Yup, I've already sent a series for 6.6 yesterday:
https://lore.kernel.org/stable/[email protected]/Ah, totally missed that as it was "just" a single backport, my fault.
6.6 had all the required dependencies already so it was fortunately a simpler series :). I'll make sure to reference the other series in the future as well.
Quoted 2 lines
Thanks for this, I'll review this when I get a chance. How was this tested?
This was tested by our internal testing over various EC2 instances (x86_64 & ARM). Our testing includes running kselftests, fstests, LTP suites.
If there are specific tests you’d like me to run or results to provide, please let me know.
Thanks,
MNAdam
Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13
10243 Berlin
Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597