NFS/localio: complete a write outside of file_start_write()
Subsystems (2)
Jeff Layton
maintainerPATCH 1/1 NFS/localio: complete a write outside of file_start_write()
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.
--- fs/nfs/localio.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
fs/nfs/localio.c +9 -1
@@ -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,
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 50 lines · Jeff Layton
nfs_local_call_write()completes the I/O while it still holdssb_writersfromfile_start_write(). When the write comes up short (a fatal signal stopsgeneric_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_writeSince LOCALIO issues I/O inline outside of reclaim context, that restarted write runs in the same task and takes
sb_writersagain. Lockdep reports possible recursive locking, and iffreeze_super()starts waiting for writers in between, the secondfile_start_write()blocks behind it forever.Drop
sb_writersbefore 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 <[email protected]>--- fs/nfs/localio.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)fs/nfs/localio.c +2
-1@@ -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);
fs/nfs/localio.c static void nfs_local_call_write(struct work_struct *work) · line 1049
Quoted 10 lines
fs/nfs/localio.c +7
-0+/* +* 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; }
Thanks for this and the other localio delegations patchset. I'm reviewing and testing them. Will probably get back with you on Monday.
Mike