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

David Howells
2026-04-28T13:19:30Z

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@redhat.com>
cc: Paulo Alcantara <pc@manguebit.org>
cc: netfs@lists.linux.dev
cc: linux-fsdevel@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);