]> www.infradead.org Git - users/jedix/linux-maple.git/commit
NFS: Fix a race when updating an existing write
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Sat, 16 Aug 2025 14:25:20 +0000 (07:25 -0700)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Tue, 19 Aug 2025 18:16:02 +0000 (11:16 -0700)
commit76d2e3890fb169168c73f2e4f8375c7cc24a765e
tree5d23b867c67851ea8ba45cbbd2ad1a85b74e3cc0
parentc17b750b3ad9f45f2b6f7e6f7f4679844244f0b9
NFS: Fix a race when updating an existing write

After nfs_lock_and_join_requests() tests for whether the request is
still attached to the mapping, nothing prevents a call to
nfs_inode_remove_request() from succeeding until we actually lock the
page group.
The reason is that whoever called nfs_inode_remove_request() doesn't
necessarily have a lock on the page group head.

So in order to avoid races, let's take the page group lock earlier in
nfs_lock_and_join_requests(), and hold it across the removal of the
request in nfs_inode_remove_request().

Reported-by: Jeff Layton <jlayton@kernel.org>
Tested-by: Joe Quanaim <jdq@meta.com>
Tested-by: Andrew Steffen <aksteffen@meta.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Fixes: bd37d6fce184 ("NFSv4: Convert nfs_lock_and_join_requests() to use nfs_page_find_head_request()")
Cc: stable@vger.kernel.org
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/pagelist.c
fs/nfs/write.c
include/linux/nfs_page.h