Linux NFS development
 help / color / mirror / Atom feed
From: Mike Snitzer <snitzer@kernel.org>
To: Jeff Layton <jlayton@kernel.org>
Cc: Trond Myklebust <trondmy@kernel.org>,
	Anna Schumaker <anna@kernel.org>,
	Mike Snitzer <snitzer@hammerspace.com>,
	Benjamin Coddington <bcodding@hammerspace.com>,
	Chuck Lever <cel@kernel.org>,
	linux-nfs@vger.kernel.org
Subject: Re: NFS/localio: complete a write outside of file_start_write()
Date: Fri, 4 Dec 2026 16:14:56 -0500	[thread overview]
Message-ID: <axMtUMKx7ImCYu_H@kernel.org> (raw)
In-Reply-To: <20261204-localio-freeze-v1-1-447caf7af2ca@kernel.org>

On Fri, Dec 04, 2026 at 01:30:06PM -0500, Jeff Layton wrote:
> 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;
>  }
>  

Thanks for this and the other localio delegations patchset. I'm
reviewing and testing them. Will probably get back with you on Monday.

Mike

      reply	other threads:[~2026-12-04 21:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=axMtUMKx7ImCYu_H@kernel.org \
    --to=snitzer@kernel.org \
    --cc=anna@kernel.org \
    --cc=bcodding@hammerspace.com \
    --cc=cel@kernel.org \
    --cc=jlayton@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=snitzer@hammerspace.com \
    --cc=trondmy@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox