Skip to content

NFS: keep final releases out of writeback

Mike Snitzer linux-nfs 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest4 patches 0 repliesNew
  2. v23 patches 0 repliesSuperseded

Changes in v3 from the cover letter

- New patch 4, for the LOCALIO COMMIT release on an allocation failure.
- The cover letter now explains why the release is deferred rather than another reference taken. Its subject also covers patch 3.
- Patch 1: put_nfs_open_context_async() is declared without extern.
- Patch 2 now has a test that reproduces its deadlock, see Testing.
- Rebased on Anna's linux-next. v2's base-commit was not public.

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4NFS: don't release the open context of a failed write from writebackfs/nfs/inode.c fs/nfs/internal.h fs/nfs/write.c +1 more+42 -30 replies
2/4NFS: don't run the release of a WRITE or COMMIT in the submitterfs/nfs/pagelist.c fs/nfs/write.c+4 -20 replies
3/4NFSv4/pnfs: don't run the release of a LAYOUTCOMMIT in the submitterfs/nfs/nfs4proc.c+6 -10 replies
4/4NFS/localio: don't run the release of a failed COMMIT in the submitterfs/nfs/localio.c+27 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH v3 0/4] NFS: keep final releases out of writeback

v2: https://lore.kernel.org/linux-nfs/[email protected]/
v1: https://lore.kernel.org/linux-nfs/[email protected]/

Releasing an open context closes NFSv4 state and drops what may be the last reference to the dentry, the inode and the superblock. The flusher holds sb->s_umount and has set I_SYNC on the inode, so it must not do either final release. It would wait for itself, on s_umount in deactivate_super() or on I_SYNC in evict(). A write normally avoids this because the RPC release callback of a WRITE or COMMIT runs on nfsiod. This series fixes the four ways in which writeback can still run such a release itself:

Patch 1: nfs_write_error() completes a write that fails before the client sends it, and it does that in the submitter. A client hit this deadlock in the field when its server began to return AUTH_TOOWEAK.

Patch 2: nfs_initiate_pgio() and nfs_initiate_commit() drop their task reference with rpc_put_task(). If the task has already completed, that call runs the release callback in the submitter. This is the deadlock that NeilBrown reported in 2014:
https://lore.kernel.org/linux-nfs/[email protected]/

Patch 3: the asynchronous LAYOUTCOMMIT that ->write_inode() sends has the same problem as patch 2. It pins an inode and the superblock instead of an open context, and its task has no workqueue.

Patch 4: when LOCALIO cannot allocate its fsync context for a COMMIT, nfs_local_commit() runs the release of the COMMIT in the submitter.

All four move the release to nfsiod, where every other write already does it. None changes how or when a filesystem shuts down, and nfs_sb_deactive() does not change.

Why not take another reference instead? These paths take and drop every reference in balance:

- Each write request holds its open context. So a closed file keeps its context until the client writes or fails its requests.
- Since commit 3d4ff43d895c ("nfs_open_context doesn't need struct path either"), an open context holds the superblock active. After umount, the last open context can hold the last active reference.
- The flusher holds s_umount and I_SYNC, but no reference of its own. Commit 169ebd90131b ("writeback: Avoid iput() from flusher thread") removed its inode reference on purpose.

A missing reference would show as an early release: a use-after-free or a refcount warning. Here the opposite happens: a thread waits for locks that it holds itself, because it drops the last reference. Another reference only changes which put is the last one. The flusher cannot drop a reference after it releases s_umount and I_SYNC, so the last put must run in another thread. For writes that thread is already nfsiod, and commit bf294b41cefc ("SUNRPC: Close a race in __rpc_wait_for_completion_task()") added rpc_put_task_async() for this case. The series moves the four exceptions to that rule. It does not add a new way to defer a release.

Testing: NFSv3 over loopback, with a test-only knob that makes nfs_do_writepage() see -EACCES in the pageio descriptor. Dirty a file through a mapping after closing it, unmount, and let the periodic flusher write it back. A plain umount is enough to leave the write requests as the only thing that keeps the superblock alive.

                  plain file           sillyrenamed file
  v1              shuts down, from     flusher hangs in evict(),
                  v1's work item       waiting for I_SYNC

this series shuts down, from shuts down, from the release
the context's of the sillyrename REMOVE
work item

Patch 2 has a test of its own, with a second test-only knob. The knob leaves the COMMIT to nfs_write_inode() in the flusher. There it waits for the COMMIT to complete before nfs_initiate_commit() puts the task. Without patch 2, the flusher hangs in deactivate_super(), with the stack in the commit message of patch 2. With patch 2, the release runs on nfsiod and the filesystem shuts down in 2 s.

Patches 3 and 4 close a race and a rare error path, and neither test exercises them. Each patch builds with W=1 on Anna's linux-next.

Changes since v2:
- New patch 4, for the LOCALIO COMMIT release on an allocation failure.
- The cover letter now explains why the release is deferred rather than another reference taken. Its subject also covers patch 3.
- Patch 1: put_nfs_open_context_async() is declared without extern.
- Patch 2 now has a test that reproduces its deadlock, see Testing.
- Rebased on Anna's linux-next. v2's base-commit was not public.

Mike Snitzer (4):
NFS: don't release the open context of a failed write from writeback
NFS: don't run the release of a WRITE or COMMIT in the submitter NFSv4/pnfs: don't run the release of a LAYOUTCOMMIT in the submitter NFS/localio: don't run the release of a failed COMMIT in the submitter

 fs/nfs/inode.c         | 37 ++++++++++++++++++++++++++++++++++---
 fs/nfs/internal.h      |  1 +
 fs/nfs/localio.c       | 28 +++++++++++++++++++++++++++-
 fs/nfs/nfs4proc.c      |  7 ++++++-
 fs/nfs/pagelist.c      |  3 ++-
 fs/nfs/write.c         |  8 +++++++-
 include/linux/nfs_fs.h |  2 ++
 7 files changed, 79 insertions(+), 7 deletions(-)

base-commit: ef30b3efb7e8bae94d790a6503a595e1051323e7

Signature · 1 line
2.52.0