linux/fs/netfs
David Howells 89635eae07
netfs: Fix race between cache write completion and ALL_QUEUED being set
When netfslib is issuing subrequests, the subrequests start processing
immediately and may complete before we reach the end of the issuing
function.  At the end of the issuing function we set NETFS_RREQ_ALL_QUEUED
to indicate to the collector that we aren't going to issue any more subreqs
and that it can do the final notifications and cleanup.

Now, this isn't a problem if the request is synchronous
(NETFS_RREQ_OFFLOAD_COLLECTION is unset) as the result collection will be
done in-thread and we're guaranteed an opportunity to run the collector.

However, if the request is asynchronous, collection is primarily triggered
by the termination of subrequests queuing it on a workqueue.  Now, a race
can occur here if the app thread sets ALL_QUEUED after the last subrequest
terminates.

This can happen most easily with the copy2cache code (as used by Ceph)
where, in the collection routine of a read request, an asynchronous write
request is spawned to copy data to the cache.  Folios are added to the
write request as they're unlocked, but there may be a delay before
ALL_QUEUED is set as the write subrequests may complete before we get
there.

If all the write subreqs have finished by the ALL_QUEUED point, no further
events happen and the collection never happens, leaving the request
hanging.

Fix this by queuing the collector after setting ALL_QUEUED.  This is a bit
heavy-handed and it may be sufficient to do it only if there are no extant
subreqs.

Also add a tracepoint to cross-reference both requests in a copy-to-request
operation and add a trace to the netfs_rreq tracepoint to indicate the
setting of ALL_QUEUED.

Fixes: e2d46f2ec3 ("netfs: Change the read result collector to only use one work item")
Reported-by: Max Kellermann <max.kellermann@ionos.com>
Link: https://lore.kernel.org/r/CAKPOu+8z_ijTLHdiCYGU_Uk7yYD=shxyGLwfe-L7AV3DhebS3w@mail.gmail.com/
Signed-off-by: David Howells <dhowells@redhat.com>
Link: https://lore.kernel.org/20250711151005.2956810-3-dhowells@redhat.com
Reviewed-by: Paulo Alcantara (Red Hat) <pc@manguebit.org>
cc: Paulo Alcantara <pc@manguebit.org>
cc: Viacheslav Dubeyko <slava@dubeyko.com>
cc: Alex Markuze <amarkuze@redhat.com>
cc: Ilya Dryomov <idryomov@gmail.com>
cc: netfs@lists.linux.dev
cc: ceph-devel@vger.kernel.org
cc: linux-fsdevel@vger.kernel.org
cc: stable@vger.kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
2025-07-14 11:05:02 +02:00
..
buffered_read.c Merge patch series "netfs: Miscellaneous fixes" 2025-05-21 14:35:34 +02:00
buffered_write.c netfs: Merge i_size update functions 2025-07-01 22:37:14 +02:00
direct_read.c netfs: Fix undifferentiation of DIO reads from unbuffered reads 2025-05-23 10:35:03 +02:00
direct_write.c netfs: Update tracepoints in a number of ways 2025-07-01 22:37:14 +02:00
fscache_cache.c netfs: Mark __nonstring lookup tables 2025-04-17 10:13:46 +02:00
fscache_cookie.c netfs: Mark __nonstring lookup tables 2025-04-17 10:13:46 +02:00
fscache_internal.h
fscache_io.c netfs: Fix the request's work item to not require a ref 2025-05-21 14:35:20 +02:00
fscache_main.c
fscache_proc.c
fscache_stats.c
fscache_volume.c
internal.h netfs: Update tracepoints in a number of ways 2025-07-01 22:37:14 +02:00
iterator.c
Kconfig
locking.c
main.c netfs: Renumber the NETFS_RREQ_* flags to make traces easier to read 2025-07-01 22:37:14 +02:00
Makefile netfs: Add support for caching single monolithic objects such as AFS dirs 2024-12-20 22:34:06 +01:00
misc.c netfs: Update tracepoints in a number of ways 2025-07-01 22:37:14 +02:00
objects.c netfs: Fix undifferentiation of DIO reads from unbuffered reads 2025-05-23 10:35:03 +02:00
read_collect.c netfs: Update tracepoints in a number of ways 2025-07-01 22:37:14 +02:00
read_pgpriv2.c netfs: Fix race between cache write completion and ALL_QUEUED being set 2025-07-14 11:05:02 +02:00
read_retry.c netfs: Fix wait/wake to be consistent about the waitqueue used 2025-05-21 14:35:21 +02:00
read_single.c netfs: Fix the request's work item to not require a ref 2025-05-21 14:35:20 +02:00
rolling_buffer.c netfs: Fix rolling_buffer_load_from_ra() to not clear mark bits 2025-03-19 10:04:22 +01:00
stats.c netfs: Add retry stat counters 2025-02-13 16:00:48 +01:00
write_collect.c netfs: Update tracepoints in a number of ways 2025-07-01 22:37:14 +02:00
write_issue.c netfs: Fix wait/wake to be consistent about the waitqueue used 2025-05-21 14:35:21 +02:00
write_retry.c netfs: Update tracepoints in a number of ways 2025-07-01 22:37:14 +02:00