[PATCH v5 14/24] netfs: Fix potential deadlock in write-through mode

David Howells dhowells at redhat.com
Tue Apr 28 06:17:44 PDT 2026


Fix netfs_advance_writethrough() to always unlock the supplied folio.  It's
been marked for writeback and the caller is holding both inode->i_rwsem and
ictx->wb_lock, so there shouldn't be any danger of truncation, migration,
fallocation, flushing or other I/O interfering whilst the folio is
unlocked.

Note that this may be easier to deal with once the queuing of folios is split
from the generation of subrequests.

Fixes: 288ace2f57c9 ("netfs: New writeback implementation")
Closes: https://sashiko.dev/#/patchset/20260427154639.180684-1-dhowells%40redhat.com
Signed-off-by: David Howells <dhowells at redhat.com>
cc: Paulo Alcantara <pc at manguebit.org>
cc: netfs at lists.linux.dev
cc: linux-fsdevel at vger.kernel.org
---
 fs/netfs/write_issue.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/netfs/write_issue.c b/fs/netfs/write_issue.c
index b0e9690bb90c..0b07ebecb157 100644
--- a/fs/netfs/write_issue.c
+++ b/fs/netfs/write_issue.c
@@ -665,8 +665,10 @@ int netfs_advance_writethrough(struct netfs_io_request *wreq, struct writeback_c
 	}
 
 	wreq->len += copied;
-	if (!to_page_end)
+	if (!to_page_end) {
+		folio_unlock(folio);
 		return 0;
+	}
 
 	*writethrough_cache = NULL;
 	return netfs_write_folio(wreq, wbc, folio);
@@ -683,8 +685,10 @@ ssize_t netfs_end_writethrough(struct netfs_io_request *wreq, struct writeback_c
 
 	_enter("R=%x", wreq->debug_id);
 
-	if (writethrough_cache)
+	if (writethrough_cache) {
+		folio_lock(writethrough_cache);
 		netfs_write_folio(wreq, wbc, writethrough_cache);
+	}
 
 	netfs_end_issue_write(wreq);
 




More information about the linux-afs mailing list