]> www.infradead.org Git - users/hch/misc.git/commit
netfs: Fix the request's work item to not require a ref
authorDavid Howells <dhowells@redhat.com>
Mon, 19 May 2025 09:07:03 +0000 (10:07 +0100)
committerChristian Brauner <brauner@kernel.org>
Wed, 21 May 2025 12:35:20 +0000 (14:35 +0200)
commit20d72b00ca814d748f5663484e5c53bb2bf37a3a
tree79947001bb39d0f99605a8966a5bbd4dd9685a04
parent34eb98c6598c4057640ca56dd1fad6555187473a
netfs: Fix the request's work item to not require a ref

When the netfs_io_request struct's work item is queued, it must be supplied
with a ref to the work item struct to prevent it being deallocated whilst
on the queue or whilst it is being processed.  This is tricky to manage as
we have to get a ref before we try and queue it and then we may find it's
already queued and is thus already holding a ref - in which case we have to
try and get rid of the ref again.

The problem comes if we're in BH or IRQ context and need to drop the ref:
if netfs_put_request() reduces the count to 0, we have to do the cleanup -
but the cleanup may need to wait.

Fix this by adding a new work item to the request, ->cleanup_work, and
dispatching that when the refcount hits zero.  That can then synchronously
cancel any outstanding work on the main work item before doing the cleanup.

Adding a new work item also deals with another problem upstream where it's
sometimes changing the work func in the put function and requeuing it -
which has occasionally in the past caused the cleanup to happen
incorrectly.

As a bonus, this allows us to get rid of the 'was_async' parameter from a
bunch of functions.  This indicated whether the put function might not be
permitted to sleep.

Fixes: 3d3c95046742 ("netfs: Provide readahead and readpage netfs helpers")
Signed-off-by: David Howells <dhowells@redhat.com>
Link: https://lore.kernel.org/20250519090707.2848510-4-dhowells@redhat.com
cc: Paulo Alcantara <pc@manguebit.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Steve French <stfrench@microsoft.com>
cc: linux-cifs@vger.kernel.org
cc: netfs@lists.linux.dev
cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
26 files changed:
fs/9p/vfs_addr.c
fs/afs/write.c
fs/cachefiles/io.c
fs/ceph/addr.c
fs/erofs/fscache.c
fs/netfs/buffered_read.c
fs/netfs/direct_read.c
fs/netfs/direct_write.c
fs/netfs/fscache_io.c
fs/netfs/internal.h
fs/netfs/objects.c
fs/netfs/read_collect.c
fs/netfs/read_pgpriv2.c
fs/netfs/read_retry.c
fs/netfs/read_single.c
fs/netfs/write_collect.c
fs/netfs/write_issue.c
fs/netfs/write_retry.c
fs/smb/client/cifsproto.h
fs/smb/client/cifssmb.c
fs/smb/client/file.c
fs/smb/client/smb2pdu.c
include/linux/fscache.h
include/linux/netfs.h
include/trace/events/netfs.h
net/9p/client.c