Linux NFS development
 help / color / mirror / Atom feed
* [PATCH] NFS/localio: complete a write outside of file_start_write()
@ 2026-12-04 18:30 Jeff Layton
  2026-12-04 21:14 ` Mike Snitzer
  0 siblings, 1 reply; 2+ messages in thread
From: Jeff Layton @ 2026-12-04 18:30 UTC (permalink / raw)
  To: Trond Myklebust, Anna Schumaker, Mike Snitzer,
	Benjamin Coddington
  Cc: Chuck Lever, linux-nfs, Jeff Layton

nfs_local_call_write() completes the I/O while it still holds
sb_writers from file_start_write(). When the write comes up short (a
fatal signal stops generic_perform_write(), for example), the
completion restarts it:

  nfs_local_write_iocb_done
    nfs_local_pgio_release
      nfs_local_pgio_restart
        nfs_local_do_write
          nfs_local_call_write
            file_start_write

Since LOCALIO issues I/O inline outside of reclaim context, that
restarted write runs in the same task and takes sb_writers again.
Lockdep reports possible recursive locking, and if freeze_super()
starts waiting for writers in between, the second file_start_write()
blocks behind it forever.

Drop sb_writers before completing. The restart, or the release of the
iocb, then happens with no freeze protection held.

Fixes: da729ddd4a1bc ("NFS/localio: issue IO inline when not in a memory-reclaim context")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 fs/nfs/localio.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/fs/nfs/localio.c b/fs/nfs/localio.c
index 68b24872f752..cfda82ffdebb 100644
--- a/fs/nfs/localio.c
+++ b/fs/nfs/localio.c
@@ -993,6 +993,7 @@ static void nfs_local_call_write(struct work_struct *work)
 		container_of(work, struct nfs_local_kiocb, work);
 	struct file *filp = iocb->kiocb.ki_filp;
 	unsigned long old_flags = current->flags;
+	bool done = false;
 	ssize_t status;
 	int n_iters;
 
@@ -1030,12 +1031,19 @@ static void nfs_local_call_write(struct work_struct *work)
 				set_bit(NFS_CONTEXT_WRITE_SYNC,
 					&ctx->open_context->flags);
 			}
-			nfs_local_write_iocb_done(iocb);
+			done = true;
 			break;
 		}
 	}
 	file_end_write(filp);
 
+	/*
+	 * Complete outside of file_start_write(): completion restarts a short
+	 * write, which can call back into this function in this same task.
+	 */
+	if (done)
+		nfs_local_write_iocb_done(iocb);
+
 	current->flags = old_flags;
 }
 

---
base-commit: 3e19991734326332c736e24c9b47b2cffb8f9e42
change-id: 20261204-localio-freeze-0a96d42f2d71

Best regards,
-- 
Jeff Layton <jlayton@kernel.org>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-04 21:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 18:30 [PATCH] NFS/localio: complete a write outside of file_start_write() Jeff Layton
2026-12-04 21:14 ` Mike Snitzer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox