| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/10/05 07:33 | flow | patch-triage |
7mArgs:null Results: {
"EnableConfigs": [
"NETFS_SUPPORT",
"FSCACHE",
"CACHEFILES",
"AFS_FS"
],
"FocusSymbols": [
"bvecq_slice",
"bvecq_load_from_ra",
"bvecq_pos_advance",
"bvecq_zero",
"bvecq_buffer_init",
"bvecq_buffer_append",
"netfs_extract_iter",
"netfs_readahead",
"netfs_read_single",
"netfs_writepages",
"netfs_writeback_single",
"netfs_unbuffered_read_iter_locked",
"netfs_unbuffered_write_iter_locked",
"afs_symlink_writepages"
],
"KMSANReasoning": "The patch series refactors the netfs and AFS I/O buffering architecture by replacing the 'rolling_buffer' construct with 'bvecq_pos' cursors and bvec queue slicing/zeroing operations. \n\nEvaluating the changes for uninitialized memory risks and info-leaks:\n1. All newly introduced or modified structures on the stack and heap are properly initialized. 'struct bvecq_pos' local instances are explicitly zero-initialized (e.g., '= {}' or through 'bvecq_pos_set()'), while heap-allocated requests ('netfs_io_request' and 'netfs_io_subrequest') are zeroed using memset() during allocation in 'netfs_alloc_request()' and 'netfs_alloc_subrequest()'.\n2. The 'struct readahead_control' modifications add an internal counter '_nr_folios', which is zero-initialized by designated initializer macros (DEFINE_READAHEAD) and reset in 'read_pages()'.\n3. 'bvecq_zero()' explicitly clears destination buffer pages using memset() before signaling completion.\n4. No kernel structures, padding, or uninitialized buffers are copied to user space (no copy_to_user, put_user, netlink, ioctl, or BPF transfers).\n5. Any potential memory bugs introduced by this patch series (e.g., cursor pointer manipulation errors, reference counting on bvecq nodes, bounds on segment slicing, or concurrency bugs between producer and consumer cursors) would manifest as out-of-bounds accesses, use-after-free, or NULL pointer dereferences, all of which are already reliably detected by KASAN and standard bug detectors.\n\nTherefore, there are no uninitialized memory risks or info-leak vectors that warrant a dedicated KMSAN fuzzing session.",
"NeedsKMSAN": false,
"Reasoning": "The patch replaces the rolling_buffer implementation in netfs with a new bvecq queue and cursor-based architecture (bvecq_pos, bvecq_slice, bvecq_load_from_ra, etc.). It updates readahead folio counting in mm/readahead.c, refactors iterator extraction into bvec queues (netfs_extract_iter), and modifies read, write, direct I/O, readahead, retry, and writeback paths in NetFS, AFS, and Cachefiles. These changes modify reachable core filesystem and MM logic, altering buffer management, refcounting, and slicing invariants, which makes fuzzing worthwhile to uncover regressions, memory bugs, or assertion failures.",
"WorthFuzzing": true
} |
| 1/1 | 2026/10/05 07:33 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit c5a2218e2e5504bde2e57f0bae41a96022008bb9\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Mon Oct 5 07:33:58 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/fs/afs/dir.c b/fs/afs/dir.c\nindex 5fac02d2d2814..39cba3f37ecd4 100644\n--- a/fs/afs/dir.c\n+++ b/fs/afs/dir.c\n@@ -2229,8 +2229,9 @@ static int afs_dir_writepages(struct address_space *mapping,\n \n \tif (test_bit(AFS_VNODE_DIR_VALID, \u0026dvnode-\u003eflags)) {\n \t\tiov_iter_bvec_queue(\u0026iter, ITER_SOURCE, dvnode-\u003edirectory, 0, 0,\n-\t\t\t\t i_size_read(\u0026dvnode-\u003enetfs.inode));\n-\t\tret = netfs_writeback_single(mapping, wbc, \u0026iter);\n+\t\t\t\t dvnode-\u003edirectory_size);\n+\t\tret = netfs_writeback_single(mapping, wbc, \u0026iter,\n+\t\t\t\t\t i_size_read(\u0026dvnode-\u003enetfs.inode));\n \t\tif (ret == 1)\n \t\t\tret = 0; /* Skipped write due to lock conflict. */\n \t}\ndiff --git a/fs/afs/symlink.c b/fs/afs/symlink.c\nindex 9a611efe6b264..ae03ceff42b85 100644\n--- a/fs/afs/symlink.c\n+++ b/fs/afs/symlink.c\n@@ -248,9 +248,9 @@ int afs_symlink_writepages(struct address_space *mapping,\n \n \tif (vnode-\u003edirectory \u0026\u0026\n \t atomic64_read(\u0026vnode-\u003ecb_expires_at) != AFS_NO_CB_PROMISE) {\n-\t\tiov_iter_bvec_queue(\u0026iter, ITER_SOURCE, vnode-\u003edirectory, 0, 0,\n-\t\t\t\t i_size_read(\u0026vnode-\u003enetfs.inode));\n-\t\tret = netfs_writeback_single(mapping, wbc, \u0026iter);\n+\t\tiov_iter_bvec_queue(\u0026iter, ITER_SOURCE, vnode-\u003edirectory, 0, 0, PAGE_SIZE);\n+\t\tret = netfs_writeback_single(mapping, wbc, \u0026iter,\n+\t\t\t\t\t i_size_read(\u0026vnode-\u003enetfs.inode));\n \t}\n \n \tif (ret == 0) {\ndiff --git a/fs/cachefiles/io.c b/fs/cachefiles/io.c\nindex d05059822288c..788439ea6e1c8 100644\n--- a/fs/cachefiles/io.c\n+++ b/fs/cachefiles/io.c\n@@ -546,7 +546,6 @@ static void cachefiles_issue_write(struct netfs_io_subrequest *subreq)\n \tstruct netfs_cache_resources *cres = \u0026wreq-\u003ecache_resources;\n \tstruct cachefiles_object *object = cachefiles_cres_object(cres);\n \tstruct cachefiles_cache *cache = object-\u003evolume-\u003ecache;\n-\tstruct netfs_io_stream *stream = \u0026wreq-\u003eio_streams[subreq-\u003estream_nr];\n \tconst struct cred *saved_cred;\n \tsize_t off, pre, post, len = subreq-\u003elen;\n \tuoff_t start = subreq-\u003estart;\n@@ -571,17 +570,6 @@ static void cachefiles_issue_write(struct netfs_io_subrequest *subreq)\n \t}\n \n \t/* We also need to end on the cache granularity boundary */\n-\tif (start + len == wreq-\u003ei_size) {\n-\t\tsize_t part = len \u0026 (cache-\u003ebsize - 1);\n-\t\tsize_t need = cache-\u003ebsize - part;\n-\n-\t\tif (part \u0026\u0026 stream-\u003esubmit_extendable_to \u003e= need) {\n-\t\t\tlen += need;\n-\t\t\tsubreq-\u003elen += need;\n-\t\t\tsubreq-\u003eio_iter.count += need;\n-\t\t}\n-\t}\n-\n \tpost = len \u0026 (cache-\u003ebsize - 1);\n \tif (post) {\n \t\tlen -= post;\ndiff --git a/fs/netfs/Makefile b/fs/netfs/Makefile\nindex b1ea4439c1bb4..421dd0be413b3 100644\n--- a/fs/netfs/Makefile\n+++ b/fs/netfs/Makefile\n@@ -14,7 +14,6 @@ netfs-y := \\\n \tread_collect.o \\\n \tread_retry.o \\\n \tread_single.o \\\n-\trolling_buffer.o \\\n \twrite_collect.o \\\n \twrite_issue.o \\\n \twrite_retry.o\ndiff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c\nindex aa1e4f8d46ab3..945bfa6eed3f0 100644\n--- a/fs/netfs/buffered_read.c\n+++ b/fs/netfs/buffered_read.c\n@@ -114,26 +114,21 @@ static int netfs_begin_cache_read(struct netfs_io_request *rreq, struct netfs_in\n static ssize_t netfs_prepare_read_iterator(struct netfs_io_subrequest *subreq)\n {\n \tstruct netfs_io_request *rreq = subreq-\u003erreq;\n+\tstruct netfs_io_stream *stream = \u0026rreq-\u003eio_streams[0];\n+\tssize_t extracted;\n \tsize_t rsize = subreq-\u003elen;\n \n \tif (subreq-\u003esource == NETFS_DOWNLOAD_FROM_SERVER)\n-\t\trsize = umin(rsize, rreq-\u003eio_streams[0].sreq_max_len);\n-\n-\tsubreq-\u003elen = rsize;\n-\tif (unlikely(rreq-\u003eio_streams[0].sreq_max_segs)) {\n-\t\tsize_t limit = netfs_limit_iter(\u0026rreq-\u003ebuffer.iter, 0, rsize,\n-\t\t\t\t\t\trreq-\u003eio_streams[0].sreq_max_segs);\n-\n-\t\tif (limit \u003c rsize) {\n-\t\t\tsubreq-\u003elen = limit;\n-\t\t\ttrace_netfs_sreq(subreq, netfs_sreq_trace_limited);\n-\t\t}\n+\t\trsize = umin(rsize, stream-\u003esreq_max_len);\n+\n+\tbvecq_pos_set(\u0026subreq-\u003eio_buffer, \u0026rreq-\u003edispatch_cursor);\n+\textracted = bvecq_slice(\u0026rreq-\u003edispatch_cursor, rsize,\n+\t\t\t\tstream-\u003esreq_max_segs, \u0026subreq-\u003enr_segs);\n+\tif (extracted \u003c rsize) {\n+\t\tsubreq-\u003elen = extracted;\n+\t\ttrace_netfs_sreq(subreq, netfs_sreq_trace_limited);\n \t}\n \n-\tsubreq-\u003eio_iter\t= rreq-\u003ebuffer.iter;\n-\n-\tiov_iter_truncate(\u0026subreq-\u003eio_iter, subreq-\u003elen);\n-\trolling_buffer_advance(\u0026rreq-\u003ebuffer, subreq-\u003elen);\n \treturn subreq-\u003elen;\n }\n \n@@ -192,6 +187,9 @@ void netfs_queue_read(struct netfs_io_request *rreq,\n static void netfs_issue_read(struct netfs_io_request *rreq,\n \t\t\t struct netfs_io_subrequest *subreq)\n {\n+\tiov_iter_bvec_queue(\u0026subreq-\u003eio_iter, ITER_DEST, subreq-\u003eio_buffer.bvecq,\n+\t\t\t subreq-\u003eio_buffer.slot, subreq-\u003eio_buffer.offset, subreq-\u003elen);\n+\n \tswitch (subreq-\u003esource) {\n \tcase NETFS_DOWNLOAD_FROM_SERVER:\n \t\trreq-\u003enetfs_ops-\u003eissue_read(subreq);\n@@ -200,10 +198,9 @@ static void netfs_issue_read(struct netfs_io_request *rreq,\n \t\tnetfs_read_cache_to_pagecache(rreq, subreq);\n \t\tbreak;\n \tdefault:\n-\t\t__set_bit(NETFS_SREQ_CLEAR_TAIL, \u0026subreq-\u003eflags);\n-\t\tsubreq-\u003eerror = 0;\n-\t\tiov_iter_zero(subreq-\u003elen, \u0026subreq-\u003eio_iter);\n+\t\tbvecq_zero(\u0026subreq-\u003eio_buffer, subreq-\u003elen);\n \t\tsubreq-\u003etransferred = subreq-\u003elen;\n+\t\tsubreq-\u003eerror = 0;\n \t\tnetfs_read_subreq_terminated(subreq);\n \t\tbreak;\n \t}\n@@ -215,31 +212,31 @@ static void netfs_issue_read(struct netfs_io_request *rreq,\n * otherwise we set the deprecated PG_private_2.\n */\n static void netfs_mark_copy_to_cache(struct netfs_io_request *rreq,\n-\t\t\t\t struct bvecq **bq,\n-\t\t\t\t unsigned int *offset,\n-\t\t\t\t int *slot,\n-\t\t\t\t size_t len,\n-\t\t\t\t bool copy)\n+\t\t\t\t struct bvecq_pos *mark, size_t len, bool copy)\n {\n+\tstruct bvecq *bq = mark-\u003ebvecq;\n+\tunsigned int offset = mark-\u003eoffset;\n+\tint slot = mark-\u003eslot;\n+\n \twhile (len \u003e 0) {\n-\t\tstruct folio *folio;\n \t\tsize_t fsize, overlap;\n \n-\t\tif (!*bq)\n+\t\tif (!bq)\n \t\t\tbreak;\n-\t\tif (!bvecq_acquire_slot(*bq, *slot)) {\n-\t\t\t*bq = bvecq_next(*bq);\n-\t\t\t*slot = 0;\n-\t\t\t*offset = 0;\n+\t\tif (!bvecq_acquire_slot(bq, slot)) {\n+\t\t\tbq = bq-\u003enext;\n+\t\t\tslot = 0;\n+\t\t\toffset = 0;\n \t\t\tcontinue;\n \t\t}\n \n \t\t/* Determine how much the subreq overlaps the folio, if at all. */\n-\t\tfsize = (*bq)-\u003ebv[*slot].bv_len;\n-\t\toverlap = min(len, fsize - *offset);\n+\t\tfsize = bq-\u003ebv[slot].bv_len;\n+\t\toverlap = min(len, fsize - offset);\n \n \t\tif (overlap \u003e 0 \u0026\u0026 copy) {\n-\t\t\tfolio = bvec_folio(\u0026(*bq)-\u003ebv[*slot]);\n+\t\t\tstruct folio *folio = bvec_folio(\u0026bq-\u003ebv[slot]);\n+\n \t\t\tif (netfs_using_pgpriv2(rreq)) {\n \t\t\t\tif (!folio_test_private_2(folio))\n \t\t\t\t\tfolio_start_private_2(folio);\n@@ -251,12 +248,20 @@ static void netfs_mark_copy_to_cache(struct netfs_io_request *rreq,\n \t\t}\n \n \t\tlen -= overlap;\n-\t\t*offset += overlap;\n-\t\tif (*offset \u003e= fsize) {\n-\t\t\t*slot += 1;\n-\t\t\t*offset = 0;\n+\t\toffset += overlap;\n+\t\tif (offset \u003e= fsize) {\n+\t\t\tslot += 1;\n+\t\t\toffset = 0;\n \t\t}\n \t}\n+\n+\tif (bq) {\n+\t\tbvecq_pos_move(mark, bq);\n+\t\tmark-\u003eoffset = offset;\n+\t\tmark-\u003eslot = slot;\n+\t} else {\n+\t\tbvecq_pos_unset(mark);\n+\t}\n }\n \n /*\n@@ -275,11 +280,14 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq)\n \t\t.cached_to[1]\t= ULLONG_MAX,\n \t};\n \tstruct fscache_occupancy *occ = \u0026_occ;\n-\tstruct bvecq *bq = rreq-\u003ebuffer.tail;\n-\tunsigned int offset = 0;\n+\tstruct bvecq_pos mark_cursor;\n \tssize_t size = rreq-\u003elen;\n \tuoff_t start = rreq-\u003estart;\n-\tint ret = 0, slot = 0;\n+\tint ret = 0;\n+\n+\t_enter(\"R=%08x\", rreq-\u003edebug_id);\n+\n+\tbvecq_pos_set(\u0026mark_cursor, \u0026rreq-\u003edispatch_cursor);\n \n \tdo {\n \t\tint (*prepare_read)(struct netfs_io_subrequest *subreq) = NULL;\n@@ -408,10 +416,10 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq)\n \t\tif (size \u003c= 0)\n \t\t\tnetfs_all_subreqs_queued(rreq);\n \n-\t\tif (bq) {\n+\t\tif (mark_cursor.bvecq) {\n \t\t\t/* See if the cache indicated this should be cached. */\n \t\t\tcopy = test_bit(NETFS_SREQ_COPY_TO_CACHE, \u0026subreq-\u003eflags);\n-\t\t\tnetfs_mark_copy_to_cache(rreq, \u0026bq, \u0026slot, \u0026offset, slice, copy);\n+\t\t\tnetfs_mark_copy_to_cache(rreq, \u0026mark_cursor, slice, copy);\n \t\t}\n \n \t\ttrace_netfs_sreq(subreq, netfs_sreq_trace_submit);\n@@ -432,6 +440,9 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq)\n \n \t/* Defer error return as we may need to wait for outstanding I/O. */\n \tcmpxchg(\u0026rreq-\u003eerror, 0, ret);\n+\n+\tbvecq_pos_unset(\u0026mark_cursor);\n+\tbvecq_pos_unset(\u0026rreq-\u003edispatch_cursor);\n }\n \n /**\n@@ -479,7 +490,7 @@ void netfs_readahead(struct readahead_control *ractl)\n \t * acquires a ref on each folio that we will need to release later -\n \t * but we don't want to do that until after we've started the I/O.\n \t */\n-\tadded = rolling_buffer_bulk_load_from_ra(\u0026rreq-\u003ebuffer, ractl, rreq-\u003egfp);\n+\tadded = bvecq_load_from_ra(\u0026rreq-\u003edispatch_cursor, ractl);\n \tif (added \u003c 0) {\n \t\tret = added;\n \t\tgoto cleanup_free;\n@@ -488,6 +499,7 @@ void netfs_readahead(struct readahead_control *ractl)\n \n \trreq-\u003esubmitted = rreq-\u003estart + added;\n \trreq-\u003ecleaned_to = rreq-\u003estart;\n+\tbvecq_pos_set(\u0026rreq-\u003ecollect_cursor, \u0026rreq-\u003edispatch_cursor);\n \tnetfs_read_set_unlock_at(rreq);\n \n \tnetfs_read_to_pagecache(rreq);\n@@ -500,20 +512,26 @@ void netfs_readahead(struct readahead_control *ractl)\n EXPORT_SYMBOL(netfs_readahead);\n \n /*\n- * Create a rolling buffer with a single occupying folio.\n+ * Create a buffer queue with a single occupying folio.\n */\n static int netfs_create_singular_buffer(struct netfs_io_request *rreq, struct folio *folio)\n {\n-\tssize_t added;\n+\tstruct bvecq *bq;\n+\tsize_t fsize = folio_size(folio);\n \n-\tif (rolling_buffer_init(\u0026rreq-\u003ebuffer, ITER_DEST, rreq-\u003egfp, false) \u003c 0)\n+\tbq = bvecq_alloc_one(1, rreq-\u003egfp, false);\n+\tif (!bq)\n \t\treturn -ENOMEM;\n \n-\tadded = rolling_buffer_append(\u0026rreq-\u003ebuffer, folio, rreq-\u003egfp);\n-\tif (added \u003c 0)\n-\t\treturn added;\n-\trreq-\u003esubmitted = rreq-\u003estart + added;\n-\trreq-\u003eprogress_at = added;\n+\trreq-\u003edispatch_cursor.bvecq = bq;\n+\trreq-\u003edispatch_cursor.slot = 0;\n+\trreq-\u003edispatch_cursor.offset = 0;\n+\n+\tbvec_set_folio(\u0026bq-\u003ebv[0], folio, fsize, 0);\n+\tbvecq_filled_to(bq, 1);\n+\tbvecq_pos_set(\u0026rreq-\u003ecollect_cursor, \u0026rreq-\u003edispatch_cursor);\n+\trreq-\u003esubmitted = rreq-\u003estart + fsize;\n+\trreq-\u003eprogress_at = fsize;\n \treturn 0;\n }\n \n@@ -527,14 +545,14 @@ static int netfs_read_gaps(struct file *file, struct folio *folio)\n \tstruct netfs_group *group = netfs_folio_group(folio);\n \tstruct netfs_folio *finfo = netfs_folio_info(folio);\n \tstruct netfs_inode *ctx = netfs_inode(mapping-\u003ehost);\n-\tstruct bio_vec *bvec = NULL;\n+\tstruct bvecq *bq = NULL;\n \tunsigned int from = finfo-\u003edirty_offset;\n \tunsigned int to = from + finfo-\u003edirty_len;\n \tunsigned int off = 0;\n \tsize_t flen = folio_size(folio);\n \tsize_t nr_bvec = flen / PAGE_SIZE + 2;\n \tsize_t part;\n-\tint ret, i = 0, sink_from = -1, sink_to = -1;\n+\tint ret, i = 0;\n \n \t_enter(\"%lx\", folio-\u003eindex);\n \n@@ -555,31 +573,46 @@ static int netfs_read_gaps(struct file *file, struct folio *folio)\n \t * end get copied to, but the middle is discarded.\n \t */\n \tret = -ENOMEM;\n-\tbvec = kmalloc_objs(*bvec, nr_bvec);\n-\tif (!bvec)\n+\tbq = bvecq_alloc_chain(nr_bvec, rreq-\u003egfp, false);\n+\tif (!bq)\n \t\tgoto discard;\n+\trreq-\u003edispatch_cursor.bvecq = bq;\n \n \ttrace_netfs_folio(folio, netfs_folio_trace_read_gaps);\n \n+\tfor (struct bvecq *p = bq; p; p = p-\u003enext)\n+\t\tp-\u003emem_type = BVECQ_MEM_PAGECACHE;\n+\n \tif (from \u003e 0) {\n-\t\tbvec_set_folio(\u0026bvec[i++], folio, from, 0);\n+\t\tfolio_get(folio);\n+\t\tbvec_set_folio(\u0026bq-\u003ebv[i++], folio, from, 0);\n \t\toff = from;\n \t}\n-\tsink_from = i;\n \twhile (off \u003c to) {\n \t\tstruct folio *sink = folio_alloc(GFP_KERNEL, 0);\n \n \t\tif (!sink)\n \t\t\tgoto discard;\n-\t\tpart = min_t(size_t, to - off, PAGE_SIZE);\n-\t\tbvec_set_folio(\u0026bvec[i], sink, part, 0);\n+\t\tif (i \u003e= bq-\u003emax_slots) {\n+\t\t\tbvecq_filled_to(bq, i);\n+\t\t\tbq = bq-\u003enext;\n+\t\t\ti = 0;\n+\t\t}\n+\t\tpart = min(to - off, PAGE_SIZE);\n+\t\tbvec_set_folio(\u0026bq-\u003ebv[i++], sink, part, 0);\n \t\toff += part;\n-\t\tsink_to = i;\n-\t\ti++;\n \t}\n-\tif (to \u003c flen)\n-\t\tbvec_set_folio(\u0026bvec[i++], folio, flen - to, to);\n-\tiov_iter_bvec(\u0026rreq-\u003ebuffer.iter, ITER_DEST, bvec, i, rreq-\u003elen);\n+\tif (to \u003c flen) {\n+\t\tif (i \u003e= bq-\u003emax_slots) {\n+\t\t\tbvecq_filled_to(bq, i);\n+\t\t\tbq = bq-\u003enext;\n+\t\t\ti = 0;\n+\t\t}\n+\t\tfolio_get(folio);\n+\t\tbvec_set_folio(\u0026bq-\u003ebv[i++], folio, flen - to, to);\n+\t}\n+\tbvecq_filled_to(bq, i);\n+\n \trreq-\u003esubmitted = rreq-\u003estart + flen;\n \n \tnetfs_read_to_pagecache(rreq);\n@@ -596,22 +629,16 @@ static int netfs_read_gaps(struct file *file, struct folio *folio)\n \t\tfolio_mark_uptodate(folio);\n \t}\n \n-\tif (sink_to \u003e= 0)\n-\t\tfor (; sink_from \u003c= sink_to; sink_from++)\n-\t\t\tfolio_put(bvec_folio(\u0026bvec[sink_from]));\n-\tkfree(bvec);\n+\tbvecq_pos_unset(\u0026rreq-\u003edispatch_cursor);\n \tfolio_unlock(folio);\n \tnetfs_put_request(rreq, netfs_rreq_trace_put_return);\n \treturn ret \u003c 0 ? ret : 0;\n \n discard:\n+\tbvecq_pos_unset(\u0026rreq-\u003edispatch_cursor);\n \tnetfs_put_failed_request(rreq);\n alloc_error:\n \tfolio_unlock(folio);\n-\tif (sink_to \u003e= 0)\n-\t\tfor (; sink_from \u003c= sink_to; sink_from++)\n-\t\t\tfolio_put(bvec_folio(\u0026bvec[sink_from]));\n-\tkfree(bvec);\n \treturn ret;\n }\n \ndiff --git a/fs/netfs/bvecq.c b/fs/netfs/bvecq.c\nindex 5b747f6b59382..2edc0045c2453 100644\n--- a/fs/netfs/bvecq.c\n+++ b/fs/netfs/bvecq.c\n@@ -342,3 +342,313 @@ int bvecq_expand_buffer(struct bvecq **_buffer, size_t *_cur_size, size_t size,\n \treturn 0;\n }\n EXPORT_SYMBOL(bvecq_expand_buffer);\n+\n+/**\n+ * bvecq_buffer_init - Initialise a buffer and set position\n+ * @pos: The position to point at the new buffer.\n+ * @gfp: The allocation constraints.\n+ * @for_writeback: True if allocating for writeback\n+ *\n+ * Initialise a rolling buffer. We allocate an unpopulated bvecq node to so\n+ * that the pointers can be independently driven by the producer and the\n+ * consumer.\n+ *\n+ * Return 0 if successful; -ENOMEM on allocation failure.\n+ */\n+int bvecq_buffer_init(struct bvecq_pos *pos, gfp_t gfp, bool for_writeback)\n+{\n+\tstruct bvecq *bq;\n+\n+\tbq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, for_writeback);\n+\tif (!bq)\n+\t\treturn -ENOMEM;\n+\n+\tpos-\u003ebvecq = bq; /* Comes with a ref. */\n+\tpos-\u003eslot = 0;\n+\tpos-\u003eoffset = 0;\n+\treturn 0;\n+}\n+\n+/**\n+ * bvecq_buffer_append - Append a new bvecq node to a buffer\n+ * @pos: The position of the last node.\n+ * @bq: The buffer to add.\n+ *\n+ * Add a new node on to the buffer chain at the specified position, either\n+ * because the previous one is full or because we have a discontiguity to\n+ * contend with, and update @pos to point to it.\n+ */\n+void bvecq_buffer_append(struct bvecq_pos *pos, struct bvecq *bq)\n+{\n+\tstruct bvecq *head = pos-\u003ebvecq;\n+\n+\tpos-\u003ebvecq = bvecq_get(bq);\n+\tpos-\u003eslot = 0;\n+\tpos-\u003eoffset = 0;\n+\n+\t/* [!] NOTE: After we set head-\u003enext, the consumer is at liberty to\n+\t * immediately delete the old head.\n+\t */\n+\tbvecq_append(head, bq);\n+\tbvecq_put(head);\n+}\n+\n+/**\n+ * bvecq_pos_advance - Advance a bvecq position\n+ * @pos: The position to advance.\n+ * @amount: The amount of bytes to advance by.\n+ *\n+ * Advance the specified bvecq position by @amount bytes. @pos is updated and\n+ * bvecq ref counts may have been manipulated. If the position hits the end of\n+ * the queue, then it is left pointing beyond the last slot of the last bvecq\n+ * so that it doesn't break the chain.\n+ */\n+void bvecq_pos_advance(struct bvecq_pos *pos, size_t amount)\n+{\n+\tstruct bvecq *bq = pos-\u003ebvecq, *next;\n+\tunsigned int slot = pos-\u003eslot;\n+\tsize_t offset = pos-\u003eoffset;\n+\n+\twhile (amount) {\n+\t\tsize_t part;\n+\n+\t\tif (!bvecq_acquire_slot(bq, slot)) {\n+\t\t\tnext = bvecq_next(bq);\n+\t\t\tif (!next) {\n+\t\t\t\tWARN_ON_ONCE(amount \u003e 0);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tif (bvecq_acquire_slot(bq, slot))\n+\t\t\t\tcontinue; /* More slots got added. */\n+\t\t\tbq = next;\n+\t\t\tslot = 0;\n+\t\t\toffset = 0;\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tpart = bq-\u003ebv[slot].bv_len - offset;\n+\n+\t\tif (part \u003e amount) {\n+\t\t\toffset += amount;\n+\t\t\tbreak;\n+\t\t}\n+\t\tamount -= part;\n+\t\toffset = 0;\n+\t\tslot++;\n+\t}\n+\n+\tpos-\u003eslot = slot;\n+\tpos-\u003eoffset = offset;\n+\tbvecq_pos_move(pos, bq);\n+}\n+\n+/*\n+ * Clear part of the memory pointed to by a bio_vec.\n+ */\n+static void bvec_zero(const struct bio_vec *bv, size_t offset, size_t len)\n+{\n+\tstruct page *page = bv-\u003ebv_page;\n+\n+\toffset += bv-\u003ebv_offset;\n+\n+\tpage += offset / PAGE_SIZE;\n+\toffset = offset % PAGE_SIZE;\n+\n+\twhile (len) {\n+\t\tsize_t part = min(len, PAGE_SIZE - offset);\n+\t\tchar *p = kmap_local_page(page);\n+\n+\t\tmemset(p + offset, 0, part);\n+\t\tkunmap_local(p);\n+\n+\t\tlen -= part;\n+\t\toffset = 0;\n+\t\tpage++;\n+\t}\n+}\n+\n+/**\n+ * bvecq_zero - Clear memory starting at the bvecq position.\n+ * @pos: The position in the bvecq chain to start clearing.\n+ * @amount: The number of bytes to clear.\n+ *\n+ * Clear memory fragments pointed to by a bvec queue. @pos is updated and\n+ * bvecq ref counts may have been manipulated. If the position hits the end of\n+ * the queue, then it is left pointing beyond the last slot of the last bvecq\n+ * so that it doesn't break the chain.\n+ *\n+ * Return: The number of bytes cleared.\n+ */\n+ssize_t bvecq_zero(struct bvecq_pos *pos, size_t amount)\n+{\n+\tstruct bvecq *bq = pos-\u003ebvecq, *next;\n+\tunsigned int slot = pos-\u003eslot;\n+\tssize_t cleared = 0;\n+\tsize_t offset = pos-\u003eoffset;\n+\n+\twhile (amount) {\n+\t\tconst struct bio_vec *bv;\n+\t\tsize_t part;\n+\n+\t\tif (!bvecq_acquire_slot(bq, slot)) {\n+\t\t\tnext = bvecq_next(bq);\n+\t\t\tif (!next) {\n+\t\t\t\tWARN_ON_ONCE(amount \u003e 0);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tif (bvecq_acquire_slot(bq, slot))\n+\t\t\t\tcontinue; /* More slots got added. */\n+\t\t\tbq = next;\n+\t\t\tslot = 0;\n+\t\t\toffset = 0;\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tbv = \u0026bq-\u003ebv[slot];\n+\t\tif (offset \u003e= bv-\u003ebv_len) {\n+\t\t\tslot++;\n+\t\t\toffset = 0;\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tpart = min(bv-\u003ebv_len - offset, amount);\n+\t\tbvec_zero(bv, offset, part);\n+\t\tcleared += part;\n+\t\toffset += part;\n+\t\tamount -= part;\n+\t}\n+\n+\tpos-\u003eslot = slot;\n+\tpos-\u003eoffset = offset;\n+\tbvecq_pos_move(pos, bq);\n+\treturn cleared;\n+}\n+\n+/**\n+ * bvecq_slice - Find a slice of a bvecq queue\n+ * @pos: The position to start at.\n+ * @max_size: The maximum size of the slice (or ULONG_MAX).\n+ * @max_slots: The maximum number of slots in the slice (or INT_MAX).\n+ * @_nr_slots: Where to put the number of slots (updated).\n+ *\n+ * Determine the size and number of slots that can be obtained the next slice\n+ * of bvec queue up to the maximum size and slot count specified.\n+ *\n+ * @pos is updated to the end of the slice. If the position hits the end of\n+ * the queue, then it is left pointing beyond the last slot of the last bvecq\n+ * so that it doesn't break the chain.\n+ *\n+ * Return: The number of bytes in the slice.\n+ */\n+size_t bvecq_slice(struct bvecq_pos *pos, size_t max_size,\n+\t\t unsigned int max_slots, unsigned int *_nr_slots)\n+{\n+\tstruct bvecq *bq, *next;\n+\tunsigned int slot = pos-\u003eslot, nslots = 0;\n+\tsize_t size = 0, offset = pos-\u003eoffset;\n+\n+\tbq = pos-\u003ebvecq;\n+\tfor (;;) {\n+\t\tfor (; slot \u003c bvecq_nr_slots_acquire(bq); slot++) {\n+\t\t\tconst struct bio_vec *bvec = \u0026bq-\u003ebv[slot];\n+\n+\t\t\tif (offset \u003c bvec-\u003ebv_len \u0026\u0026 bvec-\u003ebv_page) {\n+\t\t\t\tsize_t part = min(bvec-\u003ebv_len - offset, max_size);\n+\n+\t\t\t\tsize += part;\n+\t\t\t\toffset += part;\n+\t\t\t\tmax_size -= part;\n+\t\t\t\tnslots++;\n+\t\t\t\tif (!max_size || nslots \u003e= max_slots)\n+\t\t\t\t\tgoto out;\n+\t\t\t}\n+\t\t\toffset = 0;\n+\t\t}\n+\n+\t\t/* pos-\u003ebvecq isn't allowed to go NULL as the queue may get\n+\t\t * extended and we would lose our place.\n+\t\t */\n+\t\tnext = bvecq_next(bq);\n+\t\tif (!next)\n+\t\t\tbreak;\n+\t\tif (bvecq_acquire_slot(bq, slot))\n+\t\t\tcontinue; /* More slots got added. */\n+\t\tslot = 0;\n+\t\tbq = next;\n+\t}\n+\n+out:\n+\t*_nr_slots = nslots;\n+\tif (slot == bvecq_nr_slots_acquire(bq)) {\n+\t\tnext = bvecq_next(bq);\n+\t\tif (next) {\n+\t\t\tbq = next;\n+\t\t\tslot = 0;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\tbvecq_pos_move(pos, bq);\n+\tpos-\u003eslot = slot;\n+\tpos-\u003eoffset = offset;\n+\treturn size;\n+}\n+\n+/**\n+ * bvecq_load_from_ra - Allocate a bvecq chain and load from readahead\n+ * @pos: Blank position object to attach the new chain to.\n+ * @ractl: The readahead control context.\n+ *\n+ * Decant the set of folios to be read from the readahead context into a bvecq\n+ * chain. Each folio occupies one bio_vec element.\n+ *\n+ * Return: Amount of data loaded or -ENOMEM on allocation failure.\n+ */\n+ssize_t bvecq_load_from_ra(struct bvecq_pos *pos, struct readahead_control *ractl)\n+{\n+\tXA_STATE(xas, \u0026ractl-\u003emapping-\u003ei_pages, ractl-\u003e_index);\n+\tstruct folio *folio;\n+\tstruct bvecq *bq;\n+\tunsigned int slot = 0;\n+\tsize_t loaded = 0;\n+\n+\tbq = bvecq_alloc_chain(ractl-\u003e_nr_folios, GFP_KERNEL, false);\n+\tif (!bq)\n+\t\treturn -ENOMEM;\n+\n+\tpos-\u003ebvecq = bq;\n+\tpos-\u003eslot = 0;\n+\tpos-\u003eoffset = 0;\n+\n+\trcu_read_lock();\n+\n+\txas_for_each(\u0026xas, folio, ractl-\u003e_index + ractl-\u003e_nr_pages - 1) {\n+\t\tsize_t len;\n+\n+\t\tif (xas_retry(\u0026xas, folio))\n+\t\t\tcontinue;\n+\t\tVM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);\n+\n+\t\tlen = folio_size(folio);\n+\t\tbvec_set_folio(\u0026bq-\u003ebv[slot], folio, len, 0);\n+\t\tloaded += len;\n+\t\tslot++;\n+\t\ttrace_netfs_folio(folio, netfs_folio_trace_read);\n+\n+\t\tif (slot \u003e= bq-\u003emax_slots) {\n+\t\t\tbvecq_filled_to(bq, slot);\n+\t\t\tbq = bq-\u003enext;\n+\t\t\tif (!bq)\n+\t\t\t\tbreak;\n+\t\t\tslot = 0;\n+\t\t}\n+\t}\n+\n+\trcu_read_unlock();\n+\n+\tif (bq)\n+\t\tbvecq_filled_to(bq, slot);\n+\n+\tractl-\u003e_index += ractl-\u003e_nr_pages;\n+\tractl-\u003e_nr_pages = 0;\n+\treturn loaded;\n+}\ndiff --git a/fs/netfs/direct_read.c b/fs/netfs/direct_read.c\nindex 8c15f30797238..dae890e8df285 100644\n--- a/fs/netfs/direct_read.c\n+++ b/fs/netfs/direct_read.c\n@@ -16,44 +16,21 @@\n #include \u003clinux/netfs.h\u003e\n #include \"internal.h\"\n \n-static void netfs_prepare_dio_read_iterator(struct netfs_io_subrequest *subreq)\n-{\n-\tstruct netfs_io_request *rreq = subreq-\u003erreq;\n-\tsize_t rsize;\n-\n-\trsize = umin(subreq-\u003elen, rreq-\u003eio_streams[0].sreq_max_len);\n-\tsubreq-\u003elen = rsize;\n-\n-\tif (unlikely(rreq-\u003eio_streams[0].sreq_max_segs)) {\n-\t\tsize_t limit = netfs_limit_iter(\u0026rreq-\u003ebuffer.iter, 0, rsize,\n-\t\t\t\t\t\trreq-\u003eio_streams[0].sreq_max_segs);\n-\n-\t\tif (limit \u003c rsize) {\n-\t\t\tsubreq-\u003elen = limit;\n-\t\t\ttrace_netfs_sreq(subreq, netfs_sreq_trace_limited);\n-\t\t}\n-\t}\n-\n-\ttrace_netfs_sreq(subreq, netfs_sreq_trace_prepare);\n-\n-\tsubreq-\u003eio_iter\t= rreq-\u003ebuffer.iter;\n-\tiov_iter_truncate(\u0026subreq-\u003eio_iter, subreq-\u003elen);\n-\tiov_iter_advance(\u0026rreq-\u003ebuffer.iter, subreq-\u003elen);\n-}\n-\n /*\n * Perform a read to a buffer from the server, slicing up the region to be read\n * according to the network rsize.\n */\n static void netfs_dispatch_unbuffered_reads(struct netfs_io_request *rreq)\n {\n+\tstruct netfs_io_stream *stream = \u0026rreq-\u003eio_streams[0];\n \tssize_t size = rreq-\u003elen;\n \tuoff_t start = rreq-\u003estart;\n \tint ret;\n \n+\tbvecq_pos_set(\u0026rreq-\u003ecollect_cursor, \u0026rreq-\u003edispatch_cursor);\n+\n \tdo {\n \t\tstruct netfs_io_subrequest *subreq;\n-\t\tssize_t slice;\n \n \t\tsubreq = netfs_alloc_subrequest(rreq, NETFS_DOWNLOAD_FROM_SERVER);\n \t\tif (!subreq) {\n@@ -78,14 +55,22 @@ static void netfs_dispatch_unbuffered_reads(struct netfs_io_request *rreq)\n \t\t\t}\n \t\t}\n \n-\t\tnetfs_prepare_dio_read_iterator(subreq);\n-\t\tslice = subreq-\u003elen;\n-\t\tsize -= slice;\n-\t\tstart += slice;\n-\t\trreq-\u003esubmitted += slice;\n+\t\tbvecq_pos_set(\u0026subreq-\u003eio_buffer, \u0026rreq-\u003edispatch_cursor);\n+\t\tsubreq-\u003elen = bvecq_slice(\u0026rreq-\u003edispatch_cursor,\n+\t\t\t\t\t umin(size, stream-\u003esreq_max_len),\n+\t\t\t\t\t stream-\u003esreq_max_segs,\n+\t\t\t\t\t \u0026subreq-\u003enr_segs);\n+\n+\t\tsize -= subreq-\u003elen;\n+\t\tstart += subreq-\u003elen;\n+\t\trreq-\u003esubmitted += subreq-\u003elen;\n \t\tif (size \u003c= 0)\n \t\t\tnetfs_all_subreqs_queued(rreq);\n \n+\t\tiov_iter_bvec_queue(\u0026subreq-\u003eio_iter, ITER_DEST, subreq-\u003eio_buffer.bvecq,\n+\t\t\t\t subreq-\u003eio_buffer.slot, subreq-\u003eio_buffer.offset,\n+\t\t\t\t subreq-\u003elen);\n+\n \t\trreq-\u003enetfs_ops-\u003eissue_read(subreq);\n \n \t\tif (test_bit(NETFS_RREQ_PAUSE, \u0026rreq-\u003eflags))\n@@ -99,6 +84,8 @@ static void netfs_dispatch_unbuffered_reads(struct netfs_io_request *rreq)\n \t\tnetfs_all_subreqs_queued(rreq);\n \t\tnetfs_wake_collector(rreq);\n \t}\n+\n+\tbvecq_pos_unset(\u0026rreq-\u003edispatch_cursor);\n }\n \n /*\n@@ -177,25 +164,17 @@ ssize_t netfs_unbuffered_read_iter_locked(struct kiocb *iocb, struct iov_iter *i\n \t * buffer for ourselves as the caller's iterator will be trashed when\n \t * we return.\n \t *\n-\t * In such a case, extract an iterator to represent as much of the the\n-\t * output buffer as we can manage. Note that the extraction might not\n-\t * be able to allocate a sufficiently large bvec array and may shorten\n-\t * the request.\n+\t * Extract a buffer queue to represent as much of the output buffer as\n+\t * we can manage. The fragments are extracted into a bvecq which will\n+\t * have sufficient nodes allocated to hold all the data, though this\n+\t * may end up truncated if ENOMEM is encountered.\n \t */\n-\tif (user_backed_iter(iter)) {\n-\t\tret = netfs_extract_user_iter(iter, rreq-\u003elen, \u0026rreq-\u003ebuffer.iter, 0);\n-\t\tif (ret \u003c 0)\n-\t\t\tgoto error_put;\n-\t\trreq-\u003edirect_bv = (struct bio_vec *)rreq-\u003ebuffer.iter.bvec;\n-\t\trreq-\u003edirect_bv_count = ret;\n-\t\trreq-\u003edirect_bv_unpin = iov_iter_extract_will_pin(iter);\n-\t\trreq-\u003elen = iov_iter_count(\u0026rreq-\u003ebuffer.iter);\n-\t} else {\n-\t\trreq-\u003ebuffer.iter = *iter;\n-\t\trreq-\u003elen = orig_count;\n-\t\trreq-\u003edirect_bv_unpin = false;\n-\t\tiov_iter_advance(iter, orig_count);\n-\t}\n+\tret = netfs_extract_iter(iter, rreq-\u003elen, INT_MAX,\n+\t\t\t\t \u0026rreq-\u003edispatch_cursor.bvecq, 0, rreq-\u003egfp);\n+\tif (ret \u003c 0)\n+\t\tgoto error_put;\n+\n+\trreq-\u003elen = ret;\n \n \t// TODO: Set up bounce buffer if needed\n \ndiff --git a/fs/netfs/direct_write.c b/fs/netfs/direct_write.c\nindex 32200c10d2a45..e783405158277 100644\n--- a/fs/netfs/direct_write.c\n+++ b/fs/netfs/direct_write.c\n@@ -73,7 +73,11 @@ static void netfs_unbuffered_write_collect(struct netfs_io_request *wreq,\n \tspin_unlock(\u0026wreq-\u003elock);\n \n \twreq-\u003etransferred += subreq-\u003etransferred;\n-\tiov_iter_advance(\u0026wreq-\u003ebuffer.iter, subreq-\u003etransferred);\n+\tif (subreq-\u003etransferred \u003c subreq-\u003elen) {\n+\t\tbvecq_pos_unset(\u0026wreq-\u003edispatch_cursor);\n+\t\tbvecq_pos_transfer(\u0026wreq-\u003edispatch_cursor, \u0026subreq-\u003eio_buffer);\n+\t\tbvecq_pos_advance(\u0026wreq-\u003edispatch_cursor, subreq-\u003etransferred);\n+\t}\n \n \tstream-\u003ecollected_to = subreq-\u003estart + subreq-\u003etransferred;\n \twreq-\u003ecollected_to = stream-\u003ecollected_to;\n@@ -99,6 +103,8 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)\n \n \t_enter(\"%llx\", wreq-\u003elen);\n \n+\tbvecq_pos_set(\u0026wreq-\u003ecollect_cursor, \u0026wreq-\u003edispatch_cursor);\n+\n \tif (wreq-\u003eorigin == NETFS_DIO_WRITE)\n \t\tinode_dio_begin(wreq-\u003einode);\n \n@@ -116,6 +122,8 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)\n \t\t\t\tbreak;\n \t\t\t}\n \t\t\tstream-\u003econstruct = NULL;\n+\t\t} else {\n+\t\t\tbvecq_pos_set(\u0026subreq-\u003eio_buffer, \u0026wreq-\u003edispatch_cursor);\n \t\t}\n \n \t\t/* Check if (re-)preparation failed. */\n@@ -125,9 +133,16 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)\n \t\t\tbreak;\n \t\t}\n \n-\t\tiov_iter_truncate(\u0026subreq-\u003eio_iter, wreq-\u003elen - wreq-\u003etransferred);\n+\t\tsubreq-\u003elen = bvecq_slice(\u0026wreq-\u003edispatch_cursor, stream-\u003esreq_max_len,\n+\t\t\t\t\t stream-\u003esreq_max_segs, \u0026subreq-\u003enr_segs);\n+\n+\t\tiov_iter_bvec_queue(\u0026subreq-\u003eio_iter, ITER_SOURCE,\n+\t\t\t\t subreq-\u003eio_buffer.bvecq, subreq-\u003eio_buffer.slot,\n+\t\t\t\t subreq-\u003eio_buffer.offset,\n+\t\t\t\t subreq-\u003elen);\n+\n \t\tif (!iov_iter_count(\u0026subreq-\u003eio_iter)) {\n-\t\t\tpr_warn(\"netfs: Unexpected zero-length iterator R=%08x\\n\",\n+\t\t\tpr_warn(\"netfs: Unexpected zero-length slice R=%08x\\n\",\n \t\t\t\twreq-\u003edebug_id);\n \t\t\t__set_bit(NETFS_SREQ_FAILED, \u0026subreq-\u003eflags);\n \t\t\tnetfs_write_subrequest_terminated(subreq, -EIO);\n@@ -135,12 +150,6 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)\n \t\t\tbreak;\n \t\t}\n \n-\t\tsubreq-\u003elen = netfs_limit_iter(\u0026subreq-\u003eio_iter, 0,\n-\t\t\t\t\t stream-\u003esreq_max_len,\n-\t\t\t\t\t stream-\u003esreq_max_segs);\n-\t\tiov_iter_truncate(\u0026subreq-\u003eio_iter, subreq-\u003elen);\n-\t\tstream-\u003esubmit_extendable_to = subreq-\u003elen;\n-\n \t\ttrace_netfs_sreq(subreq, netfs_sreq_trace_submit);\n \t\tstream-\u003eissue_write(subreq);\n \n@@ -175,9 +184,13 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)\n \t\t */\n \t\tsubreq-\u003eerror = -EAGAIN;\n \t\ttrace_netfs_sreq(subreq, netfs_sreq_trace_retry);\n+\n+\t\tbvecq_pos_unset(\u0026wreq-\u003edispatch_cursor);\n+\t\tbvecq_pos_transfer(\u0026wreq-\u003edispatch_cursor, \u0026subreq-\u003eio_buffer);\n+\n \t\tif (subreq-\u003etransferred \u003e 0) {\n-\t\t\tiov_iter_advance(\u0026wreq-\u003ebuffer.iter, subreq-\u003etransferred);\n \t\t\twreq-\u003etransferred += subreq-\u003etransferred;\n+\t\t\tbvecq_pos_advance(\u0026wreq-\u003edispatch_cursor, subreq-\u003etransferred);\n \t\t}\n \n \t\tif (stream-\u003esource == NETFS_UPLOAD_TO_SERVER \u0026\u0026\n@@ -188,7 +201,6 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)\n \t\t__clear_bit(NETFS_SREQ_NEED_RETRY, \u0026subreq-\u003eflags);\n \t\t__clear_bit(NETFS_SREQ_BOUNDARY, \u0026subreq-\u003eflags);\n \t\t__clear_bit(NETFS_SREQ_FAILED, \u0026subreq-\u003eflags);\n-\t\tsubreq-\u003eio_iter\t\t= wreq-\u003ebuffer.iter;\n \t\tsubreq-\u003estart\t\t= wreq-\u003estart + wreq-\u003etransferred;\n \t\tsubreq-\u003elen\t\t= wreq-\u003elen - wreq-\u003etransferred;\n \t\tsubreq-\u003etransferred\t= 0;\n@@ -204,6 +216,7 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)\n \t\tnetfs_stat(\u0026netfs_n_wh_retry_write_subreq);\n \t}\n \n+\tbvecq_pos_unset(\u0026wreq-\u003edispatch_cursor);\n \tnetfs_unbuffered_write_done(wreq);\n \t_leave(\" = %d\", ret);\n \treturn ret;\n@@ -222,10 +235,10 @@ static void netfs_unbuffered_write_async(struct work_struct *work)\n * encrypted file. This can also be used for direct I/O writes.\n */\n ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *iter,\n-\t\t\t\t\t\t struct netfs_group *netfs_group)\n+\t\t\t\t\t struct netfs_group *netfs_group)\n {\n \tstruct netfs_io_request *wreq;\n-\tssize_t ret, n;\n+\tssize_t ret;\n \tuoff_t start = iocb-\u003eki_pos;\n \tuoff_t end = start + iov_iter_count(iter);\n \tsize_t len = iov_iter_count(iter);\n@@ -261,25 +274,17 @@ ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *\n \t\t * allocate a sufficiently large bvec array and may shorten the\n \t\t * request.\n \t\t */\n-\t\tif (user_backed_iter(iter)) {\n-\t\t\tn = netfs_extract_user_iter(iter, len, \u0026wreq-\u003ebuffer.iter, 0);\n-\t\t\tif (n \u003c 0) {\n-\t\t\t\tret = n;\n-\t\t\t\tgoto error_put;\n-\t\t\t}\n-\t\t\twreq-\u003edirect_bv = (struct bio_vec *)wreq-\u003ebuffer.iter.bvec;\n-\t\t\twreq-\u003edirect_bv_count = n;\n-\t\t\twreq-\u003edirect_bv_unpin = iov_iter_extract_will_pin(iter);\n-\t\t} else {\n-\t\t\t/* If this is a kernel-generated async DIO request,\n-\t\t\t * assume that any resources the iterator points to\n-\t\t\t * (eg. a bio_vec array) will persist till the end of\n-\t\t\t * the op.\n-\t\t\t */\n-\t\t\twreq-\u003ebuffer.iter = *iter;\n-\t\t}\n+\t\tssize_t n = netfs_extract_iter(iter, len, INT_MAX,\n+\t\t\t\t\t \u0026wreq-\u003edispatch_cursor.bvecq, 0, wreq-\u003egfp);\n \n-\t\twreq-\u003elen = iov_iter_count(\u0026wreq-\u003ebuffer.iter);\n+\t\tif (n \u003c 0) {\n+\t\t\tret = n;\n+\t\t\tgoto error_put;\n+\t\t}\n+\t\twreq-\u003elen = n;\n+\t\t_debug(\"dio-write %zx/%zx %u/%u\",\n+\t\t n, len, wreq-\u003edispatch_cursor.bvecq-\u003enr_slots,\n+\t\t wreq-\u003edispatch_cursor.bvecq-\u003emax_slots);\n \t}\n \n \t__set_bit(NETFS_RREQ_USE_IO_ITER, \u0026wreq-\u003eflags);\ndiff --git a/fs/netfs/internal.h b/fs/netfs/internal.h\nindex 827b8898d309a..3adf75dcc6322 100644\n--- a/fs/netfs/internal.h\n+++ b/fs/netfs/internal.h\n@@ -70,7 +70,6 @@ static inline void netfs_proc_del_rreq(struct netfs_io_request *rreq) {}\n /*\n * misc.c\n */\n-void netfs_reset_iter(struct netfs_io_subrequest *subreq);\n void netfs_wake_collector(struct netfs_io_request *rreq);\n void netfs_subreq_clear_in_progress(struct netfs_io_subrequest *subreq);\n void netfs_wait_for_in_progress_stream(struct netfs_io_request *rreq,\n@@ -237,8 +236,7 @@ void netfs_prepare_write(struct netfs_io_request *wreq,\n \t\t\t struct netfs_io_stream *stream,\n \t\t\t uoff_t start);\n void netfs_reissue_write(struct netfs_io_stream *stream,\n-\t\t\t struct netfs_io_subrequest *subreq,\n-\t\t\t struct iov_iter *source);\n+\t\t\t struct netfs_io_subrequest *subreq);\n void netfs_issue_write(struct netfs_io_request *wreq,\n \t\t struct netfs_io_stream *stream);\n size_t netfs_advance_write(struct netfs_io_request *wreq,\ndiff --git a/fs/netfs/iterator.c b/fs/netfs/iterator.c\nindex 31748526d5682..dc97e5b0d4495 100644\n--- a/fs/netfs/iterator.c\n+++ b/fs/netfs/iterator.c\n@@ -14,296 +14,144 @@\n #include \"internal.h\"\n \n /**\n- * netfs_extract_user_iter - Extract the pages from a user iterator into a bvec\n+ * netfs_extract_iter - Extract virtually contiguous pages from an iterator into a bvecq\n * @orig: The original iterator\n- * @orig_len: The amount of iterator to copy\n- * @new: The iterator to be set up\n+ * @max_len: Maximum number of bytes to extract\n+ * @max_pages: Maximum number of pages to extract\n+ * @_bvecq_head: Where to cache the bvec queue\n * @extraction_flags: Flags to qualify the request\n+ * @gfp: Allocation mode for bvecq structs.\n *\n- * Extract the page fragments from the given amount of the source iterator and\n- * build up a second iterator that refers to all of those bits. This allows\n- * the original iterator to be disposed of.\n+ * Extract virtually contiguous page fragments from the source iterator up to\n+ * the given maxima and build bvec queue that refers to all of those bits.\n+ * This allows the original iterator to disposed of.\n *\n- * @extraction_flags can have ITER_ALLOW_P2PDMA set to request peer-to-peer DMA be\n- * allowed on the pages extracted.\n+ * @extraction_flags can have ITER_ALLOW_P2PDMA set to request peer-to-peer DMA\n+ * be allowed on the pages extracted.\n *\n- * On success, the number of elements in the bvec is returned, the original\n- * iterator will have been advanced by the amount extracted.\n+ * On success or partial success, the amount of data in the bvec is returned,\n+ * the original iterator will have been advanced by the amount extracted.\n *\n- * The iov_iter_extract_mode() function should be used to query how cleanup\n- * should be performed.\n+ * If an error occurs and no pages are extracted, an error will be returned and\n+ * any allocated bvecq will be freed. If there is no data to be extracted (or\n+ * @max_len or @max_pages are zero), a single empty bvecq will be returned.\n+ *\n+ * The bvecq segments are marked with indications on how to get clean up the\n+ * extracted fragments.\n */\n-ssize_t netfs_extract_user_iter(struct iov_iter *orig, size_t orig_len,\n-\t\t\t\tstruct iov_iter *new,\n-\t\t\t\tiov_iter_extraction_t extraction_flags)\n+ssize_t netfs_extract_iter(struct iov_iter *orig, size_t max_len, size_t max_pages,\n+\t\t\t struct bvecq **_bvecq_head,\n+\t\t\t iov_iter_extraction_t extraction_flags, gfp_t gfp)\n {\n-\tstruct bio_vec *bv = NULL;\n-\tstruct page **pages;\n-\tunsigned int cur_npages;\n-\tunsigned int max_pages;\n-\tunsigned int npages = 0;\n-\tunsigned int i;\n+\tstruct bvecq *bq_tail = NULL, *bq;\n \tssize_t ret = 0;\n-\tsize_t count = orig_len, offset, len;\n-\tsize_t bv_size, pg_size;\n+\tsize_t extracted = 0;\n \n-\tif (WARN_ON_ONCE(!iter_is_ubuf(orig) \u0026\u0026 !iter_is_iovec(orig)))\n-\t\treturn -EIO;\n+\t_enter(\"{%u,%zx},%zx\", orig-\u003eiter_type, orig-\u003ecount, max_len);\n \n-\tmax_pages = iov_iter_npages(orig, INT_MAX);\n-\tbv_size = array_size(max_pages, sizeof(*bv));\n-\tbv = kvmalloc(bv_size, GFP_KERNEL);\n-\tif (!bv)\n-\t\treturn -ENOMEM;\n+\t*_bvecq_head = NULL;\n+\tif (max_len \u003e orig-\u003ecount)\n+\t\tmax_len = orig-\u003ecount;\n+\tif (!max_len || !max_pages)\n+\t\tgoto alloc_empty;\n+\tif (WARN_ON_ONCE(max_pages \u003e INT_MAX))\n+\t\tmax_pages = INT_MAX; /* Protect iov_iter_npages(). */\n \n-\t/* Put the page list at the end of the bvec list storage. bvec\n-\t * elements are larger than page pointers, so as long as we work\n-\t * 0-\u003elast, we should be fine.\n-\t */\n-\tpg_size = array_size(max_pages, sizeof(*pages));\n-\tpages = (void *)bv + bv_size - pg_size;\n+\tmax_pages = iov_iter_npages(orig, max_pages);\n+\tif (!max_pages)\n+\t\tgoto alloc_empty;\n \n-\twhile (count \u0026\u0026 npages \u003c max_pages) {\n-\t\tret = iov_iter_extract_pages(orig, \u0026pages, count,\n-\t\t\t\t\t max_pages - npages, extraction_flags,\n-\t\t\t\t\t \u0026offset);\n-\t\tif (unlikely(ret \u003c= 0)) {\n-\t\t\tret = ret ?: -EIO;\n+\tdo {\n+\t\tbq = bvecq_alloc_one(max_pages, gfp, false);\n+\t\tif (!bq) {\n+\t\t\tret = -ENOMEM;\n \t\t\tbreak;\n \t\t}\n+\t\tif (user_backed_iter(orig))\n+\t\t\tbq-\u003emem_type = iov_iter_extract_will_pin(orig) ?\n+\t\t\t\tBVECQ_MEM_GUP : BVECQ_MEM_PAGECACHE;\n \n-\t\tif (WARN(ret \u003e count,\n-\t\t\t \"%s: extract_pages overrun %zd \u003e %zu bytes\\n\",\n-\t\t\t __func__, ret, count)) {\n-\t\t\tret = -EIO;\n-\t\t\tbreak;\n-\t\t}\n+\t\tif (bq_tail)\n+\t\t\tbvecq_append(bq_tail, bq);\n+\t\telse\n+\t\t\t*_bvecq_head = bq;\n+\t\tbq_tail = bq;\n \n-\t\tcur_npages = DIV_ROUND_UP(offset + ret, PAGE_SIZE);\n-\t\tif (WARN(cur_npages \u003e max_pages - npages,\n-\t\t\t \"%s: extract_pages overrun %u \u003e %u pages\\n\",\n-\t\t\t __func__, npages + cur_npages, max_pages)) {\n-\t\t\tret = -EIO;\n+\t\tif (max_len == 0)\n \t\t\tbreak;\n-\t\t}\n-\n-\t\tcount -= ret;\n-\t\tret += offset;\n-\n-\t\tfor (i = 0; i \u003c cur_npages; i++) {\n-\t\t\tlen = ret \u003e PAGE_SIZE ? PAGE_SIZE : ret;\n-\t\t\tbvec_set_page(bv + npages + i, *pages++, len - offset, offset);\n-\t\t\tret -= len;\n-\t\t\toffset = 0;\n-\t\t}\n-\n-\t\tnpages += cur_npages;\n-\t}\n-\n-\t/* Note: Don't try to clean up after EIO. Either we got no pages, so\n-\t * nothing to clean up, or we got a buffer overrun, memory corruption\n-\t * and can't trust the stuff in the buffer (a WARN was emitted).\n-\t */\n-\n-\tif (ret \u003c 0 \u0026\u0026 (ret == -ENOMEM || npages == 0)) {\n-\t\tfor (i = 0; i \u003c npages; i++)\n-\t\t\tunpin_user_page(bv[i].bv_page);\n-\t\tkvfree(bv);\n-\t\treturn ret;\n-\t}\n \n-\tiov_iter_bvec(new, orig-\u003edata_source, bv, npages, orig_len - count);\n-\treturn npages;\n-}\n-EXPORT_SYMBOL_GPL(netfs_extract_user_iter);\n-\n-/*\n- * Select the span of a bvec iterator we're going to use. Limit it by both maximum\n- * size and maximum number of segments. Returns the size of the span in bytes.\n- */\n-static size_t netfs_limit_bvec(const struct iov_iter *iter, size_t start_offset,\n-\t\t\t size_t max_size, size_t max_segs)\n-{\n-\tconst struct bio_vec *bvecs = iter-\u003ebvec;\n-\tunsigned int nbv = iter-\u003enr_segs, ix = 0, nsegs = 0;\n-\tsize_t len, span = 0, n = iter-\u003ecount;\n-\tsize_t skip = iter-\u003eiov_offset + start_offset;\n-\n-\tif (WARN_ON(!iov_iter_is_bvec(iter)) ||\n-\t WARN_ON(start_offset \u003e n) ||\n-\t n == 0)\n-\t\treturn 0;\n-\n-\twhile (n \u0026\u0026 ix \u003c nbv \u0026\u0026 skip) {\n-\t\tlen = bvecs[ix].bv_len;\n-\t\tif (skip \u003c len)\n-\t\t\tbreak;\n-\t\tskip -= len;\n-\t\tn -= len;\n-\t\tix++;\n-\t}\n-\n-\twhile (n \u0026\u0026 ix \u003c nbv) {\n-\t\tlen = min3(n, bvecs[ix].bv_len - skip, max_size);\n-\t\tspan += len;\n-\t\tnsegs++;\n-\t\tix++;\n-\t\tif (span \u003e= max_size || nsegs \u003e= max_segs)\n-\t\t\tbreak;\n-\t\tskip = 0;\n-\t\tn -= len;\n-\t}\n-\n-\treturn min(span, max_size);\n-}\n-\n-/*\n- * Select the span of a kvec iterator we're going to use. Limit it by both\n- * maximum size and maximum number of segments. Returns the size of the span\n- * in bytes.\n- */\n-static size_t netfs_limit_kvec(const struct iov_iter *iter, size_t start_offset,\n-\t\t\t size_t max_size, size_t max_segs)\n-{\n-\tconst struct kvec *kvecs = iter-\u003ekvec;\n-\tunsigned int nkv = iter-\u003enr_segs, ix = 0, nsegs = 0;\n-\tsize_t len, span = 0, n = iter-\u003ecount;\n-\tsize_t skip = iter-\u003eiov_offset + start_offset;\n-\n-\tif (WARN_ON(!iov_iter_is_kvec(iter)) ||\n-\t WARN_ON(start_offset \u003e n) ||\n-\t n == 0)\n-\t\treturn 0;\n-\n-\twhile (n \u0026\u0026 ix \u003c nkv \u0026\u0026 skip) {\n-\t\tlen = kvecs[ix].iov_len;\n-\t\tif (skip \u003c len)\n-\t\t\tbreak;\n-\t\tskip -= len;\n-\t\tn -= len;\n-\t\tix++;\n-\t}\n-\n-\twhile (n \u0026\u0026 ix \u003c nkv) {\n-\t\tlen = min3(n, kvecs[ix].iov_len - skip, max_size);\n-\t\tspan += len;\n-\t\tnsegs++;\n-\t\tix++;\n-\t\tif (span \u003e= max_size || nsegs \u003e= max_segs)\n-\t\t\tbreak;\n-\t\tskip = 0;\n-\t\tn -= len;\n-\t}\n-\n-\treturn min(span, max_size);\n-}\n-\n-/*\n- * Select the span of an xarray iterator we're going to use. Limit it by both\n- * maximum size and maximum number of segments. It is assumed that segments\n- * can be larger than a page in size, provided they're physically contiguous.\n- * Returns the size of the span in bytes.\n- */\n-static size_t netfs_limit_xarray(const struct iov_iter *iter, size_t start_offset,\n-\t\t\t\t size_t max_size, size_t max_segs)\n-{\n-\tstruct folio *folio;\n-\tunsigned int nsegs = 0;\n-\tuoff_t pos = iter-\u003exarray_start + iter-\u003eiov_offset;\n-\tpgoff_t index = pos / PAGE_SIZE;\n-\tsize_t span = 0, n = iter-\u003ecount;\n-\n-\tXA_STATE(xas, iter-\u003exarray, index);\n-\n-\tif (WARN_ON(!iov_iter_is_xarray(iter)) ||\n-\t WARN_ON(start_offset \u003e n) ||\n-\t n == 0)\n-\t\treturn 0;\n-\tmax_size = min(max_size, n - start_offset);\n-\n-\trcu_read_lock();\n-\txas_for_each(\u0026xas, folio, ULONG_MAX) {\n-\t\tsize_t offset, flen, len;\n-\t\tif (xas_retry(\u0026xas, folio))\n-\t\t\tcontinue;\n-\t\tif (WARN_ON(xa_is_value(folio)))\n-\t\t\tbreak;\n-\t\tif (WARN_ON(folio_test_hugetlb(folio)))\n-\t\t\tbreak;\n-\n-\t\tflen = folio_size(folio);\n-\t\toffset = offset_in_folio(folio, pos);\n-\t\tlen = min(max_size, flen - offset);\n-\t\tspan += len;\n-\t\tnsegs++;\n-\t\tif (span \u003e= max_size || nsegs \u003e= max_segs)\n-\t\t\tbreak;\n-\t}\n-\n-\trcu_read_unlock();\n-\treturn min(span, max_size);\n-}\n-\n-/*\n- * Select the span of a bvecq iterator we're going to use. Limit it by both\n- * maximum size and maximum number of segments. Returns the size of the span\n- * in bytes.\n- */\n-static size_t netfs_limit_bvecq(const struct iov_iter *iter, size_t start_offset,\n-\t\t\t\tsize_t max_size, size_t max_segs)\n-{\n-\tconst struct bvecq *bq = iter-\u003ebvecq;\n-\tunsigned int nsegs = 0;\n-\tunsigned int slot = iter-\u003ebvecq_slot;\n-\tsize_t span = 0, n = iter-\u003ecount;\n-\n-\tif (WARN_ON(!iov_iter_is_bvecq(iter)) ||\n-\t WARN_ON(start_offset \u003e n) ||\n-\t n == 0)\n-\t\treturn 0;\n-\tmax_size = umin(max_size, n - start_offset);\n-\n-\tif (!bvecq_acquire_slot(bq, slot)) {\n-\t\tbq = bvecq_next(bq);\n-\t\tslot = 0;\n-\t}\n-\n-\tstart_offset += iter-\u003eiov_offset;\n-\tdo {\n-\t\tsize_t flen;\n-\n-\t\tflen = bq-\u003ebv[slot].bv_len;\n-\t\tif (start_offset \u003c flen) {\n-\t\t\tspan += flen - start_offset;\n-\t\t\tnsegs++;\n-\t\t\tstart_offset = 0;\n-\t\t} else {\n-\t\t\tstart_offset -= flen;\n-\t\t}\n-\t\tif (span \u003e= max_size || nsegs \u003e= max_segs)\n-\t\t\tbreak;\n-\n-\t\tslot++;\n-\t\tif (!bvecq_acquire_slot(bq, slot)) {\n-\t\t\tbq = bvecq_next(bq);\n-\t\t\tslot = 0;\n-\t\t}\n-\t} while (bq);\n-\n-\treturn umin(span, max_size);\n-}\n+\t\tstruct bio_vec *bv = bq-\u003ebv;\n+\t\tunsigned int slot = 0;\n+\t\tdo {\n+\t\t\tstruct page **pages;\n+\t\t\tssize_t got;\n+\t\t\tsize_t offset;\n+\t\t\tsize_t space = bq-\u003emax_slots - slot;\n+\t\t\tsize_t bv_size = array_size(bq-\u003emax_slots, sizeof(*bv));\n+\t\t\tsize_t pg_size = array_size(space, sizeof(*pages));\n+\n+\t\t\t/* Put the page list at the end of the bvec list\n+\t\t\t * storage. bvec elements are larger than page\n+\t\t\t * pointers, so as long as we work 0-\u003elast, we should\n+\t\t\t * be fine.\n+\t\t\t */\n+\t\t\tpages = (void *)bv + bv_size - pg_size;\n+\n+\t\t\tgot = iov_iter_extract_pages(orig, \u0026pages, max_len,\n+\t\t\t\t\t\t min(space, max_pages),\n+\t\t\t\t\t\t extraction_flags, \u0026offset);\n+\t\t\tif (got \u003c 0) {\n+\t\t\t\tret = got;\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tif (got == 0) {\n+\t\t\t\tpr_err(\"extract_pages gave nothing from %zx, %zx\\n\",\n+\t\t\t\t extracted, max_len);\n+\t\t\t\tret = -EIO;\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tif (WARN(got \u003e max_len,\n+\t\t\t\t \"%s: extract_pages overrun %zx \u003e %zx bytes\\n\",\n+\t\t\t\t __func__, got, max_len)) {\n+\t\t\t\tret = -EIO;\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\textracted += got;\n+\t\t\tmax_len -= got;\n+\n+\t\t\tdo {\n+\t\t\t\tsize_t len = umin(got, PAGE_SIZE - offset);\n+\n+\t\t\t\tBUG_ON(slot \u003e= bq-\u003emax_slots);\n+\n+\t\t\t\tbvec_set_page(\u0026bq-\u003ebv[slot], *pages++, len, offset);\n+\t\t\t\tslot++;\n+\t\t\t\tmax_pages--;\n+\t\t\t\tgot -= len;\n+\t\t\t\toffset = 0;\n+\t\t\t} while (got \u003e 0);\n+\n+\t\t\tbvecq_filled_to(bq, slot);\n+\t\t} while (max_len \u003e 0 \u0026\u0026 max_pages \u003e 0 \u0026\u0026 !bvecq_is_full(bq));\n+\n+\t} while (max_len \u003e 0 \u0026\u0026 max_pages \u003e 0);\n+\n+out:\n+\tif (extracted || ret == 0)\n+\t\treturn extracted;\n+\tbvecq_put(*_bvecq_head);\n+\t*_bvecq_head = NULL;\n+\treturn ret;\n+\n+alloc_empty:\n+\tbq = bvecq_alloc_one(1, gfp, false);\n+\tif (!bq)\n+\t\treturn -ENOMEM;\n+\t*_bvecq_head = bq;\n+\treturn 0;\n \n-size_t netfs_limit_iter(const struct iov_iter *iter, size_t start_offset,\n-\t\t\tsize_t max_size, size_t max_segs)\n-{\n-\tif (iov_iter_is_bvecq(iter))\n-\t\treturn netfs_limit_bvecq(iter, start_offset, max_size, max_segs);\n-\tif (iov_iter_is_bvec(iter))\n-\t\treturn netfs_limit_bvec(iter, start_offset, max_size, max_segs);\n-\tif (iov_iter_is_xarray(iter))\n-\t\treturn netfs_limit_xarray(iter, start_offset, max_size, max_segs);\n-\tif (iov_iter_is_kvec(iter))\n-\t\treturn netfs_limit_kvec(iter, start_offset, max_size, max_segs);\n-\tBUG();\n }\n-EXPORT_SYMBOL(netfs_limit_iter);\n+EXPORT_SYMBOL_GPL(netfs_extract_iter);\ndiff --git a/fs/netfs/misc.c b/fs/netfs/misc.c\nindex 40e0ff6491329..4fa09560fb4b9 100644\n--- a/fs/netfs/misc.c\n+++ b/fs/netfs/misc.c\n@@ -8,24 +8,6 @@\n #include \u003clinux/swap.h\u003e\n #include \"internal.h\"\n \n-/*\n- * Reset the subrequest iterator to refer just to the region remaining to be\n- * read. The iterator may or may not have been advanced by socket ops or\n- * extraction ops to an extent that may or may not match the amount actually\n- * read.\n- */\n-void netfs_reset_iter(struct netfs_io_subrequest *subreq)\n-{\n-\tstruct iov_iter *io_iter = \u0026subreq-\u003eio_iter;\n-\tsize_t remain = subreq-\u003elen - subreq-\u003etransferred;\n-\n-\tif (io_iter-\u003ecount \u003e remain)\n-\t\tiov_iter_advance(io_iter, io_iter-\u003ecount - remain);\n-\telse if (io_iter-\u003ecount \u003c remain)\n-\t\tiov_iter_revert(io_iter, remain - io_iter-\u003ecount);\n-\tiov_iter_truncate(\u0026subreq-\u003eio_iter, remain);\n-}\n-\n /**\n * netfs_dirty_folio - Mark folio dirty and pin a cache object for writeback\n * @mapping: The mapping the folio belongs to.\ndiff --git a/fs/netfs/objects.c b/fs/netfs/objects.c\nindex 4b8d20559b0e1..bf17dc31fd9d8 100644\n--- a/fs/netfs/objects.c\n+++ b/fs/netfs/objects.c\n@@ -133,7 +133,6 @@ static void netfs_free_request_rcu(struct rcu_head *rcu)\n static void netfs_deinit_request(struct netfs_io_request *rreq)\n {\n \tstruct netfs_inode *ictx = netfs_inode(rreq-\u003einode);\n-\tunsigned int i;\n \n \ttrace_netfs_rreq(rreq, netfs_rreq_trace_free);\n \n@@ -148,16 +147,10 @@ static void netfs_deinit_request(struct netfs_io_request *rreq)\n \t\trreq-\u003enetfs_ops-\u003efree_request(rreq);\n \tif (rreq-\u003ecache_resources.ops)\n \t\trreq-\u003ecache_resources.ops-\u003eend_operation(\u0026rreq-\u003ecache_resources);\n-\tif (rreq-\u003edirect_bv) {\n-\t\tfor (i = 0; i \u003c rreq-\u003edirect_bv_count; i++) {\n-\t\t\tif (rreq-\u003edirect_bv[i].bv_page) {\n-\t\t\t\tif (rreq-\u003edirect_bv_unpin)\n-\t\t\t\t\tunpin_user_page(rreq-\u003edirect_bv[i].bv_page);\n-\t\t\t}\n-\t\t}\n-\t\tkvfree(rreq-\u003edirect_bv);\n-\t}\n-\trolling_buffer_clear(\u0026rreq-\u003ebuffer);\n+\tbvecq_pos_unset(\u0026rreq-\u003eload_cursor);\n+\tbvecq_pos_unset(\u0026rreq-\u003edispatch_cursor);\n+\tbvecq_pos_unset(\u0026rreq-\u003ecollect_cursor);\n+\tbvecq_put(rreq-\u003espare);\n \n \tif (atomic_dec_and_test(\u0026ictx-\u003eio_count))\n \t\twake_up_var(\u0026ictx-\u003eio_count);\n@@ -251,6 +244,7 @@ static void netfs_free_subrequest(struct netfs_io_subrequest *subreq)\n \ttrace_netfs_sreq(subreq, netfs_sreq_trace_free);\n \tif (rreq-\u003enetfs_ops-\u003efree_subrequest)\n \t\trreq-\u003enetfs_ops-\u003efree_subrequest(subreq);\n+\tbvecq_pos_unset(\u0026subreq-\u003eio_buffer);\n \tmempool_free(subreq, rreq-\u003enetfs_ops-\u003esubrequest_pool ?: \u0026netfs_subrequest_pool);\n \tnetfs_stat_d(\u0026netfs_n_rh_sreq);\n \tnetfs_put_request(rreq, netfs_rreq_trace_put_subreq);\ndiff --git a/fs/netfs/read_collect.c b/fs/netfs/read_collect.c\nindex 961b76e37a021..ff3a30b79e063 100644\n--- a/fs/netfs/read_collect.c\n+++ b/fs/netfs/read_collect.c\n@@ -26,9 +26,13 @@\n */\n static void netfs_clear_unread(struct netfs_io_subrequest *subreq)\n {\n-\tnetfs_reset_iter(subreq);\n-\tWARN_ON_ONCE(subreq-\u003elen - subreq-\u003etransferred != iov_iter_count(\u0026subreq-\u003eio_iter));\n-\tiov_iter_zero(iov_iter_count(\u0026subreq-\u003eio_iter), \u0026subreq-\u003eio_iter);\n+\tstruct iov_iter iter;\n+\n+\tiov_iter_bvec_queue(\u0026iter, ITER_DEST, subreq-\u003eio_buffer.bvecq,\n+\t\t\t subreq-\u003eio_buffer.slot, subreq-\u003eio_buffer.offset, subreq-\u003elen);\n+\tiov_iter_advance(\u0026iter, subreq-\u003etransferred);\n+\tiov_iter_zero(subreq-\u003elen, \u0026iter);\n+\n \tif (subreq-\u003estart + subreq-\u003etransferred \u003e= subreq-\u003erreq-\u003ei_size)\n \t\t__set_bit(NETFS_SREQ_HIT_EOF, \u0026subreq-\u003eflags);\n }\n@@ -122,8 +126,8 @@ static void netfs_unlock_read_folio(struct netfs_io_request *rreq,\n */\n void netfs_read_set_unlock_at(struct netfs_io_request *rreq)\n {\n-\tconst struct bvecq *bq = rreq-\u003ebuffer.tail;\n-\tunsigned int slot = rreq-\u003ebuffer.first_tail_slot;\n+\tconst struct bvecq *bq = rreq-\u003ecollect_cursor.bvecq;\n+\tunsigned int slot = rreq-\u003ecollect_cursor.slot;\n \tsize_t cleaned_to = rreq-\u003ecleaned_to - rreq-\u003estart;\n \tsize_t progress_at = cleaned_to;\n \tsize_t minimum = 256 * 1024;\n@@ -153,8 +157,8 @@ void netfs_read_set_unlock_at(struct netfs_io_request *rreq)\n static void netfs_read_unlock_folios(struct netfs_io_request *rreq,\n \t\t\t\t unsigned int *notes)\n {\n-\tstruct bvecq *bq = rreq-\u003ebuffer.tail;\n-\tunsigned int slot = rreq-\u003ebuffer.first_tail_slot;\n+\tstruct bvecq *bq = rreq-\u003ecollect_cursor.bvecq;\n+\tunsigned int slot = rreq-\u003ecollect_cursor.slot;\n \tuoff_t collected_to = rreq-\u003ecollected_to;\n \n \tif (rreq-\u003ecleaned_to \u003e= rreq-\u003ecollected_to)\n@@ -162,15 +166,6 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,\n \n \t// TODO: Begin decryption\n \n-\twhile (!bvecq_acquire_slot(bq, slot)) {\n-\t\tbq = rolling_buffer_delete_spent(\u0026rreq-\u003ebuffer);\n-\t\tif (!bq) {\n-\t\t\tWRITE_ONCE(rreq-\u003eprogress_at, rreq-\u003elen);\n-\t\t\treturn;\n-\t\t}\n-\t\tslot = 0;\n-\t}\n-\n \t/* We have to wait for readahead refs to have been released before we\n \t * can unlock any folios as the ref-dropper walks i_pages and the only\n \t * thing preventing these folios from being removed is the folio lock.\n@@ -180,9 +175,24 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,\n \n \tfor (;;) {\n \t\tstruct folio *folio;\n-\t\tuoff_t fpos, fend;\n+\t\tuoff_t fpos = rreq-\u003ecleaned_to, fend;\n \t\tsize_t fsize;\n \n+\t\t/* Clean up the head bvecq segment. If we clear an entire\n+\t\t * segment, then we can get rid of it provided it's not also\n+\t\t * the tail segment being filled by the issuer.\n+\t\t */\n+\t\tif (!bvecq_acquire_slot(bq, slot)) {\n+\t\t\trreq-\u003ecollect_cursor.slot = slot;\n+\t\t\tif (!bvecq_delete_spent(\u0026rreq-\u003ecollect_cursor)) {\n+\t\t\t\tWRITE_ONCE(rreq-\u003eprogress_at, rreq-\u003elen);\n+\t\t\t\treturn;\n+\t\t\t}\n+\t\t\tbq = rreq-\u003ecollect_cursor.bvecq;\n+\t\t\tslot = rreq-\u003ecollect_cursor.slot;\n+\t\t\tcontinue;\n+\t\t}\n+\n \t\tfolio = bvec_folio(\u0026bq-\u003ebv[slot]);\n \t\tif (WARN_ONCE(!folio_test_locked(folio),\n \t\t\t \"R=%08x: folio %lx is not locked\\n\",\n@@ -190,7 +200,6 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,\n \t\t\ttrace_netfs_folio(folio, netfs_folio_trace_not_locked);\n \n \t\tfsize = bq-\u003ebv[slot].bv_len;\n-\t\tfpos = folio_pos(folio);\n \t\tfend = fpos + fsize;\n \n \t\ttrace_netfs_collect_folio(rreq, folio);\n@@ -200,30 +209,16 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,\n \t\t\tbreak;\n \n \t\tnetfs_unlock_read_folio(rreq, bq, slot);\n-\t\tWRITE_ONCE(rreq-\u003ecleaned_to, fpos + fsize);\n-\t\t*notes |= MADE_PROGRESS;\n-\n-\t\t/* Clean up the head bq. If we clear an entire bq, then\n-\t\t * we can get rid of it provided it's not also the tail bq\n-\t\t * being filled by the issuer.\n-\t\t */\n-\t\tbq-\u003ebv[slot].bv_page = NULL;\n \t\tslot++;\n-\t\twhile (!bvecq_acquire_slot(bq, slot)) {\n-\t\t\tbq = rolling_buffer_delete_spent(\u0026rreq-\u003ebuffer);\n-\t\t\tif (!bq)\n-\t\t\t\tgoto done;\n-\t\t\tslot = 0;\n-\t\t}\n+\t\tWRITE_ONCE(rreq-\u003ecleaned_to, fend);\n+\t\t*notes |= MADE_PROGRESS;\n \n \t\tif (fpos + fsize \u003e= collected_to)\n \t\t\tbreak;\n \t}\n \n-\trreq-\u003ebuffer.tail = bq;\n-done:\n-\trreq-\u003ebuffer.first_tail_slot = slot;\n-\n+\tbvecq_pos_move(\u0026rreq-\u003ecollect_cursor, bq);\n+\trreq-\u003ecollect_cursor.slot = slot;\n \tnetfs_read_set_unlock_at(rreq);\n }\n \n@@ -398,12 +393,15 @@ static void netfs_rreq_assess_dio(struct netfs_io_request *rreq)\n \n \tif (rreq-\u003eorigin == NETFS_UNBUFFERED_READ ||\n \t rreq-\u003eorigin == NETFS_DIO_READ) {\n-\t\tfor (i = 0; i \u003c rreq-\u003edirect_bv_count; i++) {\n-\t\t\tflush_dcache_page(rreq-\u003edirect_bv[i].bv_page);\n-\t\t\t// TODO: cifs marks pages in the destination buffer\n-\t\t\t// dirty under some circumstances after a read. Do we\n-\t\t\t// need to do that too?\n-\t\t\tset_page_dirty(rreq-\u003edirect_bv[i].bv_page);\n+\t\tfor (struct bvecq *bq = rreq-\u003ecollect_cursor.bvecq; bq; bq = bvecq_next(bq)) {\n+\t\t\tunsigned int nr_slots = bvecq_nr_slots_acquire(bq);\n+\t\t\t/* Read the slot count before the slots. */\n+\n+\t\t\t/* Mark the target buffers dirty. */\n+\t\t\tfor (i = 0; i \u003c nr_slots; i++) {\n+\t\t\t\tflush_dcache_page(bq-\u003ebv[i].bv_page);\n+\t\t\t\tset_page_dirty(bq-\u003ebv[i].bv_page);\n+\t\t\t}\n \t\t}\n \t}\n \n@@ -497,7 +495,15 @@ bool netfs_read_collection(struct netfs_io_request *rreq)\n \n \ttrace_netfs_rreq(rreq, netfs_rreq_trace_done);\n \tnetfs_clear_subrequests(rreq);\n-\tnetfs_unlock_abandoned_read_pages(rreq);\n+\tswitch (rreq-\u003eorigin) {\n+\tcase NETFS_READAHEAD:\n+\tcase NETFS_READPAGE:\n+\tcase NETFS_READ_FOR_WRITE:\n+\t\tnetfs_unlock_abandoned_read_pages(rreq);\n+\t\tbreak;\n+\tdefault:\n+\t\tbreak;\n+\t}\n \tif (unlikely(rreq-\u003ecopy_to_cache))\n \t\tnetfs_pgpriv2_end_copy_to_cache(rreq);\n \treturn true;\ndiff --git a/fs/netfs/read_pgpriv2.c b/fs/netfs/read_pgpriv2.c\nindex f8e5667e278e1..f23c4cbfed581 100644\n--- a/fs/netfs/read_pgpriv2.c\n+++ b/fs/netfs/read_pgpriv2.c\n@@ -19,6 +19,9 @@\n static void netfs_pgpriv2_copy_folio(struct netfs_io_request *creq, struct folio *folio)\n {\n \tstruct netfs_io_stream *cache = \u0026creq-\u003eio_streams[1];\n+\tstruct bvecq *queue;\n+\tunsigned int slot;\n+\tsize_t dio_size = PAGE_SIZE;\n \tsize_t fsize = folio_size(folio), flen = fsize;\n \tuoff_t fpos = folio_pos(folio), i_size;\n \tbool to_eof = false;\n@@ -48,18 +51,37 @@ static void netfs_pgpriv2_copy_folio(struct netfs_io_request *creq, struct folio\n \t\tto_eof = true;\n \t}\n \n+\tflen = round_up(flen, dio_size);\n+\n \t_debug(\"folio %zx %zx\", flen, fsize);\n \n \ttrace_netfs_folio(folio, netfs_folio_trace_store_copy);\n \n-\t/* Attach the folio to the rolling buffer. */\n-\tif (rolling_buffer_append(\u0026creq-\u003ebuffer, folio, creq-\u003egfp) \u003c 0) {\n-\t\tset_bit(NETFS_RREQ_CANCEL_CACHING, \u0026creq-\u003eflags);\n-\t\tfolio_end_private_2(folio);\n-\t\treturn;\n+\t/* Institute a new bvec queue segment if the current one is full or if\n+\t * we encounter a discontiguity. The discontiguity break is important\n+\t * when it comes to bulk unlocking folios by file range.\n+\t */\n+\tqueue = creq-\u003eload_cursor.bvecq;\n+\tif (bvecq_is_full(queue) ||\n+\t (fpos != creq-\u003elast_end \u0026\u0026 creq-\u003elast_end \u003e 0 \u0026\u0026 queue-\u003enr_slots \u003e 0)) {\n+\t\tbvecq_buffer_append(\u0026creq-\u003eload_cursor, creq-\u003espare);\n+\t\tcreq-\u003espare = NULL;\n+\n+\t\tqueue = creq-\u003eload_cursor.bvecq;\n \t}\n \n-\tcache-\u003esubmit_extendable_to = fsize;\n+\t/* Attach the folio to the rolling buffer. */\n+\tslot = queue-\u003enr_slots;\n+\tbvec_set_folio(\u0026queue-\u003ebv[slot], folio, fsize, 0);\n+\ttrace_netfs_bv_slot(queue, slot);\n+\tslot++;\n+\tbvecq_filled_to(queue, slot);\n+\tcreq-\u003eload_cursor.slot = slot;\n+\tcreq-\u003eload_cursor.offset = 0;\n+\tcreq-\u003elast_end = fpos + flen;\n+\n+\tbvecq_pos_nudge(\u0026creq-\u003edispatch_cursor);\n+\n \tcache-\u003esubmit_off = 0;\n \tcache-\u003esubmit_len = flen;\n \n@@ -71,10 +93,9 @@ static void netfs_pgpriv2_copy_folio(struct netfs_io_request *creq, struct folio\n \tdo {\n \t\tssize_t part;\n \n-\t\tcreq-\u003ebuffer.iter.iov_offset = cache-\u003esubmit_off;\n+\t\tcreq-\u003edispatch_cursor.offset = cache-\u003esubmit_off;\n \n \t\tatomic64_set(\u0026creq-\u003eissued_to, fpos + cache-\u003esubmit_off);\n-\t\tcache-\u003esubmit_extendable_to = fsize - cache-\u003esubmit_off;\n \t\tpart = netfs_advance_write(creq, cache, fpos + cache-\u003esubmit_off,\n \t\t\t\t\t cache-\u003esubmit_len, to_eof);\n \t\tcache-\u003esubmit_off += part;\n@@ -84,8 +105,7 @@ static void netfs_pgpriv2_copy_folio(struct netfs_io_request *creq, struct folio\n \t\t\tcache-\u003esubmit_len -= part;\n \t} while (cache-\u003esubmit_len \u003e 0);\n \n-\tcreq-\u003ebuffer.iter.iov_offset = 0;\n-\trolling_buffer_advance(\u0026creq-\u003ebuffer, fsize);\n+\tbvecq_pos_step(\u0026creq-\u003edispatch_cursor);\n \tatomic64_set(\u0026creq-\u003eissued_to, fpos + fsize);\n \n \tif (flen \u003c fsize)\n@@ -111,6 +131,11 @@ static struct netfs_io_request *netfs_pgpriv2_begin_copy_to_cache(\n \tif (!creq-\u003eio_streams[1].avail)\n \t\tgoto cancel_put;\n \n+\tif (bvecq_buffer_init(\u0026creq-\u003eload_cursor, creq-\u003egfp, false) \u003c 0)\n+\t\tgoto cancel_put;\n+\tbvecq_pos_set(\u0026creq-\u003edispatch_cursor, \u0026creq-\u003eload_cursor);\n+\tbvecq_pos_set(\u0026creq-\u003ecollect_cursor, \u0026creq-\u003edispatch_cursor);\n+\n \t__set_bit(NETFS_RREQ_OFFLOAD_COLLECTION, \u0026creq-\u003eflags);\n \ttrace_netfs_copy2cache(rreq, creq);\n \ttrace_netfs_write(creq, netfs_write_trace_copy_to_cache);\n@@ -143,6 +168,14 @@ void netfs_pgpriv2_copy_to_cache(struct netfs_io_request *rreq, struct folio *fo\n \t\treturn;\n \t}\n \n+\tif (!creq-\u003espare) {\n+\t\tcreq-\u003espare = bvecq_alloc_one(BVECQ_POOL_SLOTS, creq-\u003egfp, false);\n+\t\tif (!creq-\u003espare) {\n+\t\t\tset_bit(NETFS_RREQ_CANCEL_CACHING, \u0026creq-\u003eflags);\n+\t\t\treturn;\n+\t\t}\n+\t}\n+\n \ttrace_netfs_folio(folio, netfs_folio_trace_pgpriv2_copy);\n \tnetfs_pgpriv2_copy_folio(creq, folio);\n }\n@@ -173,16 +206,18 @@ void netfs_pgpriv2_end_copy_to_cache(struct netfs_io_request *rreq)\n */\n bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *creq)\n {\n-\tstruct bvecq *bq = creq-\u003ebuffer.tail;\n-\tunsigned int slot = creq-\u003ebuffer.first_tail_slot;\n+\tstruct bvecq *bq = creq-\u003ecollect_cursor.bvecq;\n+\tunsigned int slot;\n \tuoff_t collected_to = creq-\u003ecollected_to;\n \tbool made_progress = false;\n \n+\tslot = creq-\u003ecollect_cursor.slot;\n \twhile (!bvecq_acquire_slot(bq, slot)) {\n-\t\tbq = rolling_buffer_delete_spent(\u0026creq-\u003ebuffer);\n-\t\tif (!bq)\n-\t\t\treturn false;\n-\t\tslot = 0;\n+\t\tcreq-\u003ecollect_cursor.slot = slot;\n+\t\tif (!bvecq_delete_spent(\u0026creq-\u003ecollect_cursor))\n+\t\t\tgoto out;\n+\t\tbq = creq-\u003ecollect_cursor.bvecq;\n+\t\tslot = creq-\u003ecollect_cursor.slot;\n \t}\n \n \tfor (;;) {\n@@ -213,25 +248,25 @@ bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *creq)\n \t\tcreq-\u003ecleaned_to = fpos + fsize;\n \t\tmade_progress = true;\n \n-\t\t/* Clean up the head bq. If we clear an entire bq, then\n-\t\t * we can get rid of it provided it's not also the tail bq\n-\t\t * being filled by the issuer.\n+\t\t/* Clean up the head segment. If we clear an entire segment,\n+\t\t * then we can get rid of it provided it's not also the tail\n+\t\t * segment being filled by the issuer.\n \t\t */\n \t\tbq-\u003ebv[slot].bv_page = NULL;\n \t\tslot++;\n \t\twhile (!bvecq_acquire_slot(bq, slot)) {\n-\t\t\tbq = rolling_buffer_delete_spent(\u0026creq-\u003ebuffer);\n-\t\t\tif (!bq)\n-\t\t\t\tgoto done;\n-\t\t\tslot = 0;\n+\t\t\tcreq-\u003ecollect_cursor.slot = slot;\n+\t\t\tif (!bvecq_delete_spent(\u0026creq-\u003ecollect_cursor))\n+\t\t\t\tgoto out;\n+\t\t\tbq = creq-\u003ecollect_cursor.bvecq;\n+\t\t\tslot = creq-\u003ecollect_cursor.slot;\n \t\t}\n \n \t\tif (fpos + fsize \u003e= collected_to)\n \t\t\tbreak;\n \t}\n \n-\tcreq-\u003ebuffer.tail = bq;\n-done:\n-\tcreq-\u003ebuffer.first_tail_slot = slot;\n+\tcreq-\u003ecollect_cursor.slot = slot;\n+out:\n \treturn made_progress;\n }\ndiff --git a/fs/netfs/read_retry.c b/fs/netfs/read_retry.c\nindex 142c3fb8dab17..7490b9ee1bf7c 100644\n--- a/fs/netfs/read_retry.c\n+++ b/fs/netfs/read_retry.c\n@@ -12,6 +12,10 @@\n static void netfs_reissue_read(struct netfs_io_request *rreq,\n \t\t\t struct netfs_io_subrequest *subreq)\n {\n+\tiov_iter_bvec_queue(\u0026subreq-\u003eio_iter, ITER_DEST, subreq-\u003eio_buffer.bvecq,\n+\t\t\t subreq-\u003eio_buffer.slot, subreq-\u003eio_buffer.offset, subreq-\u003elen);\n+\tiov_iter_advance(\u0026subreq-\u003eio_iter, subreq-\u003etransferred);\n+\n \tsubreq-\u003eerror = 0;\n \t__clear_bit(NETFS_SREQ_MADE_PROGRESS, \u0026subreq-\u003eflags);\n \t__set_bit(NETFS_SREQ_IN_PROGRESS, \u0026subreq-\u003eflags);\n@@ -27,6 +31,7 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)\n {\n \tstruct netfs_io_subrequest *subreq;\n \tstruct netfs_io_stream *stream = \u0026rreq-\u003eio_streams[0];\n+\tstruct bvecq_pos dispatch_cursor = {};\n \tstruct list_head *next;\n \n \t_enter(\"R=%x\", rreq-\u003edebug_id);\n@@ -46,9 +51,7 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)\n \t\t\tif (test_bit(NETFS_SREQ_FAILED, \u0026subreq-\u003eflags))\n \t\t\t\tbreak;\n \t\t\tif (__test_and_clear_bit(NETFS_SREQ_NEED_RETRY, \u0026subreq-\u003eflags)) {\n-\t\t\t\t__clear_bit(NETFS_SREQ_MADE_PROGRESS, \u0026subreq-\u003eflags);\n \t\t\t\tsubreq-\u003eretry_count++;\n-\t\t\t\tnetfs_reset_iter(subreq);\n \t\t\t\tnetfs_get_subrequest(subreq, netfs_sreq_trace_get_resubmit);\n \t\t\t\tnetfs_reissue_read(rreq, subreq);\n \t\t\t}\n@@ -74,11 +77,12 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)\n \n \tdo {\n \t\tstruct netfs_io_subrequest *from, *to, *tmp;\n-\t\tstruct iov_iter source;\n \t\tuoff_t start, len;\n \t\tsize_t part;\n \t\tbool boundary = false, subreq_superfluous = false;\n \n+\t\tbvecq_pos_unset(\u0026dispatch_cursor);\n+\n \t\t/* Go through the subreqs and find the next span of contiguous\n \t\t * buffer that we then rejig (cifs, for example, needs the\n \t\t * rsize renegotiating) and reissue.\n@@ -105,7 +109,8 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)\n \t\t\t\tbreak;\n \n \t\t\tsubreq = list_entry(next, struct netfs_io_subrequest, rreq_link);\n-\t\t\tif (subreq-\u003estart + subreq-\u003etransferred != start + len ||\n+\t\t\tif (subreq-\u003estart != start + len ||\n+\t\t\t subreq-\u003etransferred \u003e 0 ||\n \t\t\t test_bit(NETFS_SREQ_BOUNDARY, \u0026subreq-\u003eflags) ||\n \t\t\t !test_bit(NETFS_SREQ_NEED_RETRY, \u0026subreq-\u003eflags))\n \t\t\t\tbreak;\n@@ -118,11 +123,14 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)\n \t\t/* Determine the set of buffers we're going to use. Each\n \t\t * subreq gets a subset of a single overall contiguous buffer.\n \t\t */\n-\t\tnetfs_reset_iter(from);\n-\t\tsource = from-\u003eio_iter;\n-\t\tsource.count = len;\n+\t\tbvecq_pos_transfer(\u0026dispatch_cursor, \u0026from-\u003eio_buffer);\n+\t\tbvecq_pos_advance(\u0026dispatch_cursor, from-\u003etransferred);\n+\t\tfrom-\u003etransferred = 0;\n \n-\t\t/* Work through the sublist. */\n+\t\t/* Work through the sublist. The chain of buffers we're going\n+\t\t * to fill is attached to dispatch_cursor and we need to read\n+\t\t * 'len' amount of data from 'start'.\n+\t\t */\n \t\tsubreq = from;\n \t\tlist_for_each_entry_from(subreq, \u0026stream-\u003esubrequests, rreq_link) {\n \t\t\tif (!len) {\n@@ -130,16 +138,21 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)\n \t\t\t\tbreak;\n \t\t\t}\n \t\t\tsubreq-\u003esource\t= NETFS_DOWNLOAD_FROM_SERVER;\n-\t\t\tsubreq-\u003estart\t= start - subreq-\u003etransferred;\n-\t\t\tsubreq-\u003elen\t= len + subreq-\u003etransferred;\n+\t\t\tsubreq-\u003estart\t= start;\n+\t\t\tsubreq-\u003elen\t= len;\n \t\t\t__clear_bit(NETFS_SREQ_NEED_RETRY, \u0026subreq-\u003eflags);\n \t\t\t__clear_bit(NETFS_SREQ_MADE_PROGRESS, \u0026subreq-\u003eflags);\n \t\t\tsubreq-\u003eretry_count++;\n+\t\t\tsubreq-\u003etransferred = 0;\n+\n+\t\t\tbvecq_pos_unset(\u0026subreq-\u003eio_buffer);\n+\t\t\tbvecq_pos_set(\u0026subreq-\u003eio_buffer, \u0026dispatch_cursor);\n \n \t\t\ttrace_netfs_sreq(subreq, netfs_sreq_trace_retry);\n \n \t\t\t/* Renegotiate max_len (rsize) */\n-\t\t\tstream-\u003esreq_max_len = subreq-\u003elen;\n+\t\t\tstream-\u003esreq_max_len = len;\n+\t\t\tstream-\u003esreq_max_segs = INT_MAX;\n \t\t\tif (rreq-\u003enetfs_ops-\u003eprepare_read \u0026\u0026\n \t\t\t rreq-\u003enetfs_ops-\u003eprepare_read(subreq) \u003c 0) {\n \t\t\t\ttrace_netfs_sreq(subreq, netfs_sreq_trace_reprep_failed);\n@@ -147,13 +160,12 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)\n \t\t\t\tgoto abandon;\n \t\t\t}\n \n-\t\t\tpart = umin(len, stream-\u003esreq_max_len);\n-\t\t\tif (unlikely(stream-\u003esreq_max_segs))\n-\t\t\t\tpart = netfs_limit_iter(\u0026source, 0, part, stream-\u003esreq_max_segs);\n-\t\t\tsubreq-\u003elen = subreq-\u003etransferred + part;\n-\t\t\tsubreq-\u003eio_iter = source;\n-\t\t\tiov_iter_truncate(\u0026subreq-\u003eio_iter, part);\n-\t\t\tiov_iter_advance(\u0026source, part);\n+\t\t\tpart = bvecq_slice(\u0026dispatch_cursor,\n+\t\t\t\t\t umin(len, stream-\u003esreq_max_len),\n+\t\t\t\t\t stream-\u003esreq_max_segs,\n+\t\t\t\t\t \u0026subreq-\u003enr_segs);\n+\t\t\tsubreq-\u003elen = part;\n+\n \t\t\tlen -= part;\n \t\t\tstart += part;\n \t\t\tif (!len) {\n@@ -216,9 +228,7 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)\n \t\t\ttrace_netfs_sreq(subreq, netfs_sreq_trace_retry);\n \n \t\t\tstream-\u003esreq_max_len\t= umin(len, rreq-\u003ersize);\n-\t\t\tstream-\u003esreq_max_segs\t= 0;\n-\t\t\tif (unlikely(stream-\u003esreq_max_segs))\n-\t\t\t\tpart = netfs_limit_iter(\u0026source, 0, part, stream-\u003esreq_max_segs);\n+\t\t\tstream-\u003esreq_max_segs\t= INT_MAX;\n \n \t\t\tnetfs_stat(\u0026netfs_n_rh_download);\n \t\t\tif (rreq-\u003enetfs_ops-\u003eprepare_read(subreq) \u003c 0) {\n@@ -227,11 +237,12 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)\n \t\t\t\tgoto abandon;\n \t\t\t}\n \n-\t\t\tpart = umin(len, stream-\u003esreq_max_len);\n-\t\t\tsubreq-\u003elen = subreq-\u003etransferred + part;\n-\t\t\tsubreq-\u003eio_iter = source;\n-\t\t\tiov_iter_truncate(\u0026subreq-\u003eio_iter, part);\n-\t\t\tiov_iter_advance(\u0026source, part);\n+\t\t\tbvecq_pos_set(\u0026subreq-\u003eio_buffer, \u0026dispatch_cursor);\n+\t\t\tpart = bvecq_slice(\u0026dispatch_cursor,\n+\t\t\t\t\t umin(len, stream-\u003esreq_max_len),\n+\t\t\t\t\t stream-\u003esreq_max_segs,\n+\t\t\t\t\t \u0026subreq-\u003enr_segs);\n+\t\t\tsubreq-\u003elen = part;\n \n \t\t\tlen -= part;\n \t\t\tstart += part;\n@@ -245,12 +256,14 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)\n \n \t} while (!list_is_head(next, \u0026stream-\u003esubrequests));\n \n+out:\n+\tbvecq_pos_unset(\u0026dispatch_cursor);\n \treturn;\n \n \t/* If we hit an error, fail all remaining incomplete subrequests */\n abandon_after:\n \tif (list_is_last(\u0026subreq-\u003erreq_link, \u0026stream-\u003esubrequests))\n-\t\treturn;\n+\t\tgoto out;\n \tsubreq = list_next_entry(subreq, rreq_link);\n abandon:\n \tlist_for_each_entry_from(subreq, \u0026stream-\u003esubrequests, rreq_link) {\n@@ -261,6 +274,7 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)\n \t\t__set_bit(NETFS_SREQ_FAILED, \u0026subreq-\u003eflags);\n \t\t__clear_bit(NETFS_SREQ_NEED_RETRY, \u0026subreq-\u003eflags);\n \t}\n+\tgoto out;\n }\n \n /*\n@@ -300,26 +314,24 @@ void netfs_unlock_abandoned_read_pages(struct netfs_io_request *rreq)\n \tif (test_bit(NETFS_RREQ_NEED_PUT_RA_REFS, \u0026rreq-\u003eflags))\n \t\tnetfs_wait_for_put_ra_refs(rreq);\n \n-\tfor (p = rreq-\u003ebuffer.tail; p; p = p-\u003enext) {\n-\t\tfor (int slot = rreq-\u003ebuffer.first_tail_slot;\n-\t\t bvecq_acquire_slot(p, slot);\n-\t\t slot++) {\n-\t\t\tstruct folio *folio;\n+\tfor (p = rreq-\u003ecollect_cursor.bvecq; p; p = bvecq_next(p)) {\n+\t\tunsigned int nr_slots = bvecq_nr_slots_acquire(p);\n \n+\t\tfor (int slot = 0; slot \u003c nr_slots; slot++) {\n \t\t\tif (!p-\u003ebv[slot].bv_page)\n \t\t\t\tcontinue;\n \n-\t\t\tfolio = bvec_folio(\u0026p-\u003ebv[slot]);\n+\t\t\tstruct folio *folio = bvec_folio(\u0026p-\u003ebv[slot]);\n+\n \t\t\tnetfs_cancel_copy_to_cache(rreq, folio);\n \n \t\t\tif (folio == rreq-\u003eno_unlock_folio \u0026\u0026\n \t\t\t test_bit(NETFS_RREQ_NO_UNLOCK_FOLIO, \u0026rreq-\u003eflags)) {\n \t\t\t\t_debug(\"no unlock\");\n-\t\t\t} else {\n-\t\t\t\ttrace_netfs_folio(folio, netfs_folio_trace_abandon);\n-\t\t\t\tfolio_unlock(folio);\n+\t\t\t\tcontinue;\n \t\t\t}\n+\t\t\ttrace_netfs_folio(folio, netfs_folio_trace_abandon);\n+\t\t\tfolio_unlock(folio);\n \t\t}\n-\t\trreq-\u003ebuffer.first_tail_slot = 0;\n \t}\n }\ndiff --git a/fs/netfs/read_single.c b/fs/netfs/read_single.c\nindex b248e34bd0c86..c70941121de04 100644\n--- a/fs/netfs/read_single.c\n+++ b/fs/netfs/read_single.c\n@@ -101,7 +101,11 @@ static int netfs_single_dispatch_read(struct netfs_io_request *rreq)\n \n \tsubreq-\u003estart\t= 0;\n \tsubreq-\u003elen\t= rreq-\u003elen;\n-\tsubreq-\u003eio_iter\t= rreq-\u003ebuffer.iter;\n+\n+\tbvecq_pos_set(\u0026subreq-\u003eio_buffer, \u0026rreq-\u003edispatch_cursor);\n+\n+\tiov_iter_bvec_queue(\u0026subreq-\u003eio_iter, ITER_DEST, subreq-\u003eio_buffer.bvecq,\n+\t\t\t subreq-\u003eio_buffer.slot, subreq-\u003eio_buffer.offset, subreq-\u003elen);\n \n \tnetfs_queue_read(rreq, subreq);\n \n@@ -174,6 +178,15 @@ ssize_t netfs_read_single(struct inode *inode, struct file *file, struct iov_ite\n \tif (IS_ERR(rreq))\n \t\treturn PTR_ERR(rreq);\n \n+\tret = netfs_extract_iter(iter, rreq-\u003elen, INT_MAX, \u0026rreq-\u003edispatch_cursor.bvecq,\n+\t\t\t\t 0, rreq-\u003egfp);\n+\tif (ret \u003c 0)\n+\t\tgoto cleanup_free;\n+\tif (ret \u003c rreq-\u003elen) {\n+\t\tret = -EIO;\n+\t\tgoto cleanup_free;\n+\t}\n+\n \trreq-\u003eprogress_at = rreq-\u003elen;\n \n \tret = netfs_single_begin_cache_read(rreq, ictx);\n@@ -183,7 +196,6 @@ ssize_t netfs_read_single(struct inode *inode, struct file *file, struct iov_ite\n \tnetfs_stat(\u0026netfs_n_rh_read_single);\n \ttrace_netfs_read(rreq, 0, rreq-\u003elen, netfs_read_trace_read_single);\n \n-\trreq-\u003ebuffer.iter = *iter;\n \tnetfs_single_dispatch_read(rreq);\n \n \tret = netfs_wait_for_read(rreq);\ndiff --git a/fs/netfs/rolling_buffer.c b/fs/netfs/rolling_buffer.c\ndeleted file mode 100644\nindex 66ce9add40122..0000000000000\n--- a/fs/netfs/rolling_buffer.c\n+++ /dev/null\n@@ -1,182 +0,0 @@\n-// SPDX-License-Identifier: GPL-2.0-or-later\n-/* Rolling buffer helpers\n- *\n- * Copyright (C) 2024 Red Hat, Inc. All Rights Reserved.\n- * Written by David Howells (dhowells@redhat.com)\n- */\n-\n-#include \u003clinux/bitops.h\u003e\n-#include \u003clinux/mempool.h\u003e\n-#include \u003clinux/pagemap.h\u003e\n-#include \u003clinux/rolling_buffer.h\u003e\n-#include \u003clinux/slab.h\u003e\n-#include \"internal.h\"\n-\n-/*\n- * Initialise a rolling buffer. We allocate an empty folio queue struct to so\n- * that the pointers can be independently driven by the producer and the\n- * consumer.\n- */\n-int rolling_buffer_init(struct rolling_buffer *roll, unsigned int direction,\n-\t\t\tgfp_t gfp, bool for_writeback)\n-{\n-\tstruct bvecq *bq;\n-\n-\troll-\u003efor_writeback = for_writeback;\n-\n-\tbq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, for_writeback);\n-\tif (!bq)\n-\t\treturn -ENOMEM;\n-\n-\troll-\u003ehead = bq;\n-\troll-\u003etail = bq;\n-\tiov_iter_bvec_queue(\u0026roll-\u003eiter, direction, bq, 0, 0, 0);\n-\treturn 0;\n-}\n-\n-/*\n- * Add another bvecq to a rolling buffer if there's no space left.\n- */\n-int rolling_buffer_make_space(struct rolling_buffer *roll, gfp_t gfp)\n-{\n-\tstruct bvecq *bq, *head = roll-\u003ehead;\n-\n-\tif (!bvecq_is_full(head))\n-\t\treturn 0;\n-\n-\tbq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, roll-\u003efor_writeback);\n-\tif (!bq)\n-\t\treturn -ENOMEM;\n-\n-\troll-\u003ehead = bq;\n-\tif (bvecq_is_full(head)) {\n-\t\t/* Make sure we don't leave the master iterator pointing to a\n-\t\t * block that might get immediately consumed.\n-\t\t */\n-\t\tif (roll-\u003eiter.bvecq == head \u0026\u0026\n-\t\t roll-\u003eiter.bvecq_slot == head-\u003enr_slots) {\n-\t\t\troll-\u003eiter.bvecq = bq;\n-\t\t\troll-\u003eiter.bvecq_slot = 0;\n-\t\t}\n-\t}\n-\n-\t/* Make sure the initialisation is stored before the next pointer.\n-\t *\n-\t * [!] NOTE: After we set head-\u003enext, the consumer is at liberty to\n-\t * immediately delete the old head.\n-\t */\n-\tbvecq_append(head, bq);\n-\treturn 0;\n-}\n-\n-/*\n- * Decant the entire list of folios to read into a rolling buffer.\n- */\n-ssize_t rolling_buffer_bulk_load_from_ra(struct rolling_buffer *roll,\n-\t\t\t\t\t struct readahead_control *ractl,\n-\t\t\t\t\t gfp_t gfp)\n-{\n-\tstruct bvecq *bq;\n-\tsize_t loaded = 0;\n-\n-\twhile (ractl-\u003e_nr_pages - ractl-\u003e_batch_count \u003e 0) {\n-\t\tstruct page **pages;\n-\t\tunsigned int nr;\n-\n-\t\t/* Allocate a bvecq to put some folios into and attach it to\n-\t\t * the rolling buffer.\n-\t\t */\n-\t\tbq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, false);\n-\t\tif (!bq)\n-\t\t\tgoto nomem_unlock;\n-\t\tbq-\u003emem_type = BVECQ_MEM_EXTERNAL; /* Folio cleanup handled separately. */\n-\n-\t\tif (!roll-\u003etail)\n-\t\t\troll-\u003etail = bq;\n-\t\telse\n-\t\t\tbvecq_append(roll-\u003ehead, bq);\n-\t\troll-\u003ehead = bq;\n-\n-\t\t/* Get a bunch of folios and note their sizes. */\n-\t\tpages = (struct page **)(bq-\u003ebv + bq-\u003emax_slots);\n-\t\tpages -= bq-\u003emax_slots;\n-\t\tnr = __readahead_batch(ractl, pages, bq-\u003emax_slots);\n-\t\tif (WARN_ON_ONCE(!nr))\n-\t\t\tbreak;\n-\n-\t\tfor (int slot = 0; slot \u003c nr; slot++) {\n-\t\t\tstruct folio *folio = page_folio(pages[slot]);\n-\t\t\tsize_t len = folio_size(folio);\n-\n-\t\t\tbvec_set_folio(\u0026bq-\u003ebv[slot], folio, len, 0);\n-\t\t\tloaded += len;\n-\t\t\ttrace_netfs_folio(folio, netfs_folio_trace_read);\n-\t\t}\n-\n-\t\tbvecq_filled_to(bq, nr);\n-\t}\n-\n-\tWRITE_ONCE(roll-\u003eiter.count, loaded);\n-\tiov_iter_bvec_queue(\u0026roll-\u003eiter, ITER_DEST, roll-\u003etail, 0, 0, loaded);\n-\treturn loaded;\n-\n-nomem_unlock:\n-\tfor (bq = roll-\u003etail; bq; bq = bq-\u003enext) {\n-\t\tfor (int slot = 0; slot \u003c bq-\u003enr_slots; slot++) {\n-\t\t\tstruct folio *folio = bvec_folio(\u0026bq-\u003ebv[slot]);\n-\n-\t\t\tfolio_unlock(folio);\n-\t\t\tfolio_put(folio);\n-\t\t}\n-\t}\n-\trolling_buffer_clear(roll);\n-\troll-\u003ehead = NULL;\n-\troll-\u003etail = NULL;\n-\treturn -ENOMEM;\n-}\n-\n-/*\n- * Append a folio to the rolling buffer.\n- */\n-ssize_t rolling_buffer_append(struct rolling_buffer *roll, struct folio *folio,\n-\t\t\t gfp_t gfp)\n-{\n-\tssize_t size = folio_size(folio);\n-\tint slot;\n-\n-\tif (rolling_buffer_make_space(roll, gfp) \u003c 0)\n-\t\treturn -ENOMEM;\n-\n-\tslot = roll-\u003ehead-\u003enr_slots;\n-\tbvec_set_folio(\u0026roll-\u003ehead-\u003ebv[slot], folio, size, 0);\n-\tbvecq_filled_to(roll-\u003ehead, slot + 1);\n-\n-\tWRITE_ONCE(roll-\u003eiter.count, roll-\u003eiter.count + size);\n-\treturn size;\n-}\n-\n-/*\n- * Delete a spent buffer from a rolling queue and return the next in line. We\n- * don't return the last buffer to keep the pointers independent, but return\n- * NULL instead.\n- */\n-struct bvecq *rolling_buffer_delete_spent(struct rolling_buffer *roll)\n-{\n-\tstruct bvecq *spent = roll-\u003etail, *next = bvecq_next(spent);\n-\n-\tif (!next)\n-\t\treturn NULL;\n-\tnext-\u003eprev = NULL;\n-\troll-\u003etail = next;\n-\tspent-\u003enext = NULL;\n-\tbvecq_put(spent);\n-\treturn next;\n-}\n-\n-/*\n- * Clear out a rolling queue.\n- */\n-void rolling_buffer_clear(struct rolling_buffer *roll)\n-{\n-\tbvecq_put(roll-\u003etail);\n-}\ndiff --git a/fs/netfs/write_collect.c b/fs/netfs/write_collect.c\nindex 91b42820c8925..dcacbab254b92 100644\n--- a/fs/netfs/write_collect.c\n+++ b/fs/netfs/write_collect.c\n@@ -114,12 +114,12 @@ int netfs_folio_written_back(struct folio *folio)\n static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,\n \t\t\t\t\t unsigned int *notes)\n {\n-\tstruct bvecq *bq = wreq-\u003ebuffer.tail;\n-\tunsigned int slot = wreq-\u003ebuffer.first_tail_slot;\n+\tstruct bvecq *bq = wreq-\u003ecollect_cursor.bvecq;\n+\tunsigned int slot = wreq-\u003ecollect_cursor.slot;\n \tuoff_t collected_to = wreq-\u003ecollected_to;\n \n \tif (WARN_ON_ONCE(!bq)) {\n-\t\tpr_err(\"[!] Writeback unlock found empty rolling buffer!\\n\");\n+\t\tpr_err(\"[!] Writeback unlock found empty buffer!\\n\");\n \t\tnetfs_dump_request(wreq);\n \t\treturn;\n \t}\n@@ -130,19 +130,28 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,\n \t\treturn;\n \t}\n \n-\twhile (!bvecq_acquire_slot(bq, slot)) {\n-\t\tbq = rolling_buffer_delete_spent(\u0026wreq-\u003ebuffer);\n-\t\tif (!bq)\n-\t\t\treturn;\n-\t\tslot = 0;\n-\t}\n-\n \tfor (;;) {\n \t\tstruct folio *folio;\n \t\tstruct netfs_folio *finfo;\n \t\tuoff_t fpos, fend;\n \t\tsize_t fsize, flen;\n \n+\t\t/* Try to clean up the head of the queue if it appears to be\n+\t\t * used up, but we need to be very careful - the cleanup can\n+\t\t * catch the dispatcher, which could lead to us having nothing\n+\t\t * left in the queue, causing the front and back pointers to\n+\t\t * end up on different tracks. To avoid this, we must always\n+\t\t * keep at least one segment in the queue.\n+\t\t */\n+\t\tif (!bvecq_acquire_slot(bq, slot)) {\n+\t\t\twreq-\u003ecollect_cursor.slot = slot;\n+\t\t\tif (!bvecq_delete_spent(\u0026wreq-\u003ecollect_cursor))\n+\t\t\t\treturn;\n+\t\t\tbq = wreq-\u003ecollect_cursor.bvecq;\n+\t\t\tslot = wreq-\u003ecollect_cursor.slot;\n+\t\t\tcontinue;\n+\t\t}\n+\n \t\tfolio = bvec_folio(\u0026bq-\u003ebv[slot]);\n \t\tif (WARN_ONCE(!folio_test_writeback(folio),\n \t\t\t \"R=%08x: folio %lx is not under writeback\\n\",\n@@ -166,26 +175,13 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,\n \t\twreq-\u003ecleaned_to = fpos + fsize;\n \t\t*notes |= MADE_PROGRESS;\n \n-\t\t/* Clean up the head bq. If we clear an entire bq, then\n-\t\t * we can get rid of it provided it's not also the tail bq\n-\t\t * being filled by the issuer.\n-\t\t */\n \t\tbq-\u003ebv[slot].bv_page = NULL;\n \t\tslot++;\n-\t\twhile (!bvecq_acquire_slot(bq, slot)) {\n-\t\t\tbq = rolling_buffer_delete_spent(\u0026wreq-\u003ebuffer);\n-\t\t\tif (!bq)\n-\t\t\t\tgoto done;\n-\t\t\tslot = 0;\n-\t\t}\n-\n \t\tif (fpos + fsize \u003e= collected_to)\n \t\t\tbreak;\n \t}\n \n-\twreq-\u003ebuffer.tail = bq;\n-done:\n-\twreq-\u003ebuffer.first_tail_slot = slot;\n+\twreq-\u003ecollect_cursor.slot = slot;\n }\n \n /*\n@@ -230,7 +226,8 @@ static void netfs_collect_write_results(struct netfs_io_request *wreq)\n \ttrace_netfs_rreq(wreq, netfs_rreq_trace_collect);\n \n reassess_streams:\n-\tissued_to = atomic64_read(\u0026wreq-\u003eissued_to);\n+\t/* Order reading the issued_to point before reading the queue it refers to. */\n+\tissued_to = atomic64_read_acquire(\u0026wreq-\u003eissued_to);\n \tsmp_rmb();\n \tcollected_to = ULLONG_MAX;\n \tif (wreq-\u003eorigin == NETFS_WRITEBACK ||\n@@ -560,8 +557,12 @@ void netfs_write_subrequest_terminated(void *_op, ssize_t transferred_or_error)\n \t\t\t * data is tracked.\n \t\t\t */\n \t\t\tnetfs_stat(\u0026netfs_n_wh_write_failed);\n-\t\t\tif (test_bit(NETFS_SREQ_NEED_RETRY, \u0026subreq-\u003eflags))\n-\t\t\t\tbreak;\n+\t\t\tif (test_bit(NETFS_SREQ_NEED_RETRY, \u0026subreq-\u003eflags)) {\n+\t\t\t\t/* We don't retry failed cache writes. */\n+\t\t\t\t__clear_bit(NETFS_SREQ_NEED_RETRY, \u0026subreq-\u003eflags);\n+\t\t\t\tif (!subreq-\u003eerror)\n+\t\t\t\t\tsubreq-\u003eerror = -ENOBUFS;\n+\t\t\t}\n \n \t\t\ttrace_netfs_failure(wreq, subreq, transferred_or_error, netfs_fail_write);\n \t\t\t__set_bit(NETFS_SREQ_CANCELLED, \u0026subreq-\u003eflags);\ndiff --git a/fs/netfs/write_issue.c b/fs/netfs/write_issue.c\nindex f0f4786666512..8fab5cf00d7b6 100644\n--- a/fs/netfs/write_issue.c\n+++ b/fs/netfs/write_issue.c\n@@ -107,10 +107,6 @@ struct netfs_io_request *netfs_create_write_req(struct address_space *mapping,\n \tictx = netfs_inode(wreq-\u003einode);\n \tif (is_cacheable)\n \t\tfscache_begin_write_operation(\u0026wreq-\u003ecache_resources, netfs_i_cookie(ictx));\n-\tif (rolling_buffer_init(\u0026wreq-\u003ebuffer, ITER_SOURCE, wreq-\u003egfp,\n-\t\t\t\t(origin == NETFS_WRITEBACK ||\n-\t\t\t\t origin == NETFS_WRITEBACK_SINGLE)) \u003c 0)\n-\t\tgoto nomem;\n \n \twreq-\u003ecleaned_to = wreq-\u003estart;\n \tif (wreq-\u003ecache_resources.dio_size \u003e 1)\n@@ -135,9 +131,6 @@ struct netfs_io_request *netfs_create_write_req(struct address_space *mapping,\n \t}\n \n \treturn wreq;\n-nomem:\n-\tnetfs_put_failed_request(wreq);\n-\treturn ERR_PTR(-ENOMEM);\n }\n \n /**\n@@ -163,22 +156,14 @@ void netfs_prepare_write(struct netfs_io_request *wreq,\n \t\t\t uoff_t start)\n {\n \tstruct netfs_io_subrequest *subreq;\n-\tstruct iov_iter *wreq_iter = \u0026wreq-\u003ebuffer.iter;\n-\n-\t/* Make sure we don't point the iterator at a used-up bvecq struct\n-\t * being used as a placeholder to prevent the queue from collapsing.\n-\t * In such a case, extend the queue.\n-\t */\n-\tif (iov_iter_is_bvecq(wreq_iter) \u0026\u0026\n-\t !bvecq_acquire_slot(wreq_iter-\u003ebvecq, wreq_iter-\u003ebvecq_slot))\n-\t\trolling_buffer_make_space(\u0026wreq-\u003ebuffer, wreq-\u003egfp);\n \n \tsubreq = netfs_alloc_subrequest(wreq, stream-\u003esource);\n \tif (!subreq)\n \t\treturn;\n \tsubreq-\u003estart\t\t= start;\n \tsubreq-\u003estream_nr\t= stream-\u003estream_nr;\n-\tsubreq-\u003eio_iter\t\t= *wreq_iter;\n+\n+\tbvecq_pos_set(\u0026subreq-\u003eio_buffer, \u0026wreq-\u003edispatch_cursor);\n \n \t_enter(\"R=%x[%x]\", wreq-\u003edebug_id, subreq-\u003edebug_index);\n \n@@ -259,15 +244,14 @@ static void netfs_do_issue_write(struct netfs_io_stream *stream,\n }\n \n void netfs_reissue_write(struct netfs_io_stream *stream,\n-\t\t\t struct netfs_io_subrequest *subreq,\n-\t\t\t struct iov_iter *source)\n+\t\t\t struct netfs_io_subrequest *subreq)\n {\n-\tsize_t size = subreq-\u003elen - subreq-\u003etransferred;\n-\n \t// TODO: Use encrypted buffer\n-\tsubreq-\u003eio_iter = *source;\n-\tiov_iter_advance(source, size);\n-\tiov_iter_truncate(\u0026subreq-\u003eio_iter, size);\n+\tiov_iter_bvec_queue(\u0026subreq-\u003eio_iter, ITER_SOURCE,\n+\t\t\t subreq-\u003eio_buffer.bvecq, subreq-\u003eio_buffer.slot,\n+\t\t\t subreq-\u003eio_buffer.offset,\n+\t\t\t subreq-\u003elen);\n+\tiov_iter_advance(\u0026subreq-\u003eio_iter, subreq-\u003etransferred);\n \n \tsubreq-\u003eretry_count++;\n \tsubreq-\u003eerror = 0;\n@@ -285,8 +269,12 @@ void netfs_issue_write(struct netfs_io_request *wreq,\n \tif (!subreq)\n \t\treturn;\n \n+\tiov_iter_bvec_queue(\u0026subreq-\u003eio_iter, ITER_SOURCE,\n+\t\t\t subreq-\u003eio_buffer.bvecq, subreq-\u003eio_buffer.slot,\n+\t\t\t subreq-\u003eio_buffer.offset,\n+\t\t\t subreq-\u003elen);\n+\n \tstream-\u003econstruct = NULL;\n-\tsubreq-\u003eio_iter.count = subreq-\u003elen;\n \tnetfs_do_issue_write(stream, subreq);\n }\n \n@@ -323,7 +311,6 @@ size_t netfs_advance_write(struct netfs_io_request *wreq,\n \t_debug(\"part %zx/%zx %zx/%zx\", subreq-\u003elen, stream-\u003esreq_max_len, part, len);\n \tsubreq-\u003elen += part;\n \tsubreq-\u003enr_segs++;\n-\tstream-\u003esubmit_extendable_to -= part;\n \n \tif (subreq-\u003elen \u003e= stream-\u003esreq_max_len ||\n \t subreq-\u003enr_segs \u003e= stream-\u003esreq_max_segs ||\n@@ -347,7 +334,8 @@ static int netfs_write_folio(struct netfs_io_request *wreq,\n \tstruct netfs_io_stream *stream;\n \tstruct netfs_group *fgroup; /* TODO: Use this with ceph */\n \tstruct netfs_folio *finfo;\n-\tsize_t iter_off = 0;\n+\tstruct bvecq *queue = wreq-\u003eload_cursor.bvecq;\n+\tunsigned int slot;\n \tsize_t fsize = folio_size(folio), flen = fsize, foff = 0;\n \tuoff_t fpos = folio_pos(folio), i_size;\n \tbool to_eof = false, streamw = false;\n@@ -355,12 +343,20 @@ static int netfs_write_folio(struct netfs_io_request *wreq,\n \n \t_enter(\"\");\n \n-\tif (rolling_buffer_make_space(\u0026wreq-\u003ebuffer, wreq-\u003egfp) \u003c 0)\n-\t\treturn -ENOMEM;\n+\tif (!wreq-\u003espare) {\n+\t\twreq-\u003espare = bvecq_alloc_one(BVECQ_POOL_SLOTS, wreq-\u003egfp, true);\n+\t\tif (!wreq-\u003espare)\n+\t\t\treturn -ENOMEM;\n+\t}\n \n-\t/* netfs_perform_write() may shift i_size around the page or from out\n-\t * of the page to beyond it, but cannot move i_size into or through the\n-\t * page since we have it locked.\n+\t/* netfs_perform_write() may shift i_size around the folio or from out\n+\t * of the folio to beyond it, but cannot move i_size into or through\n+\t * the folio since we have it locked.\n+\t *\n+\t * Truncate could in theory move i_size into or before the folio, but\n+\t * it should take steps to prevent writeback from happening\n+\t * concurrently and should wait for any in-progress writebacks before\n+\t * proceeding.\n \t */\n \ti_size = i_size_read(wreq-\u003einode);\n \n@@ -452,8 +448,29 @@ static int netfs_write_folio(struct netfs_io_request *wreq,\n \t\ttrace_netfs_folio(folio, netfs_folio_trace_store_plus);\n \t}\n \n+\t/* Institute a new bvec queue segment if the current one is full or if\n+\t * we encounter a discontiguity. The discontiguity break is important\n+\t * when it comes to bulk unlocking folios by file range.\n+\t */\n+\tif (bvecq_is_full(queue) ||\n+\t (fpos != wreq-\u003elast_end \u0026\u0026 wreq-\u003elast_end \u003e 0)) {\n+\t\tbvecq_buffer_append(\u0026wreq-\u003eload_cursor, wreq-\u003espare);\n+\t\twreq-\u003espare = NULL;\n+\n+\t\tqueue = wreq-\u003eload_cursor.bvecq;\n+\t\tbvecq_pos_move(\u0026wreq-\u003edispatch_cursor, queue);\n+\t\twreq-\u003edispatch_cursor.slot = 0;\n+\t}\n+\n \t/* Attach the folio to the rolling buffer. */\n-\trolling_buffer_append(\u0026wreq-\u003ebuffer, folio, wreq-\u003egfp);\n+\tslot = queue-\u003enr_slots;\n+\tbvec_set_folio(\u0026queue-\u003ebv[slot], folio, fsize, 0);\n+\ttrace_netfs_bv_slot(queue, slot);\n+\tslot++;\n+\tbvecq_filled_to(queue, slot);\n+\twreq-\u003eload_cursor.slot = slot;\n+\twreq-\u003eload_cursor.offset = 0;\n+\twreq-\u003elast_end = fpos + fsize;\n \n \t/* Move the submission point forward to allow for write-streaming data\n \t * not starting at the front of the page. We don't do write-streaming\n@@ -462,10 +479,19 @@ static int netfs_write_folio(struct netfs_io_request *wreq,\n \t * Also skip uploading for data that's been read and just needs copying\n \t * to the cache.\n \t */\n+\tbvecq_pos_nudge(\u0026wreq-\u003edispatch_cursor);\n+\n \tfor (int s = 0; s \u003c NR_IO_STREAMS; s++) {\n+\t\tsize_t soff = foff, slen = flen, alignment = 1;\n+\n \t\tstream = \u0026wreq-\u003eio_streams[s];\n-\t\tstream-\u003esubmit_off = foff;\n-\t\tstream-\u003esubmit_len = flen;\n+\t\tif (stream-\u003esource == NETFS_WRITE_TO_CACHE)\n+\t\t\talignment = wreq-\u003ecache_resources.dio_size;\n+\t\tstream = \u0026wreq-\u003eio_streams[s];\n+\t\tstream-\u003esubmit_off = round_down(soff, alignment);\n+\t\tslen += foff - stream-\u003esubmit_off;\n+\t\tstream-\u003esubmit_len = round_up(slen, alignment);\n+\n \t\tif (!stream-\u003eavail ||\n \t\t (stream-\u003esource == NETFS_WRITE_TO_CACHE \u0026\u0026 streamw) ||\n \t\t (stream-\u003esource == NETFS_UPLOAD_TO_SERVER \u0026\u0026\n@@ -499,14 +525,10 @@ static int netfs_write_folio(struct netfs_io_request *wreq,\n \t\t\tbreak;\n \t\tstream = \u0026wreq-\u003eio_streams[choose_s];\n \n-\t\t/* Advance the iterator(s). */\n-\t\tif (stream-\u003esubmit_off \u003e iter_off) {\n-\t\t\trolling_buffer_advance(\u0026wreq-\u003ebuffer, stream-\u003esubmit_off - iter_off);\n-\t\t\titer_off = stream-\u003esubmit_off;\n-\t\t}\n+\t\t/* Advance the cursor. */\n+\t\twreq-\u003edispatch_cursor.offset = stream-\u003esubmit_off;\n \n \t\tatomic64_set(\u0026wreq-\u003eissued_to, fpos + stream-\u003esubmit_off);\n-\t\tstream-\u003esubmit_extendable_to = fsize - stream-\u003esubmit_off;\n \t\tpart = netfs_advance_write(wreq, stream, fpos + stream-\u003esubmit_off,\n \t\t\t\t\t stream-\u003esubmit_len, to_eof);\n \t\tstream-\u003esubmit_off += part;\n@@ -518,9 +540,9 @@ static int netfs_write_folio(struct netfs_io_request *wreq,\n \t\t\tdebug = true;\n \t}\n \n-\tif (fsize \u003e iter_off)\n-\t\trolling_buffer_advance(\u0026wreq-\u003ebuffer, fsize - iter_off);\n-\tatomic64_set(\u0026wreq-\u003eissued_to, fpos + fsize);\n+\tbvecq_pos_step(\u0026wreq-\u003edispatch_cursor);\n+\t/* Order loading the queue before updating the issue_to point */\n+\tatomic64_set_release(\u0026wreq-\u003eissued_to, fpos + fsize);\n \n \tif (!debug)\n \t\tkdebug(\"R=%x: No submit\", wreq-\u003edebug_id);\n@@ -581,6 +603,11 @@ int netfs_writepages(struct address_space *mapping,\n \t\tgoto couldnt_start;\n \t}\n \n+\tif (bvecq_buffer_init(\u0026wreq-\u003eload_cursor, wreq-\u003egfp, true) \u003c 0)\n+\t\tgoto nomem;\n+\tbvecq_pos_set(\u0026wreq-\u003edispatch_cursor, \u0026wreq-\u003eload_cursor);\n+\tbvecq_pos_set(\u0026wreq-\u003ecollect_cursor, \u0026wreq-\u003edispatch_cursor);\n+\n \t__set_bit(NETFS_RREQ_OFFLOAD_COLLECTION, \u0026wreq-\u003eflags);\n \ttrace_netfs_write(wreq, netfs_write_trace_writeback);\n \tnetfs_stat(\u0026netfs_n_wh_writepages);\n@@ -605,12 +632,17 @@ int netfs_writepages(struct address_space *mapping,\n \t} while ((folio = writeback_iter(mapping, wbc, folio, \u0026error)));\n \n \tnetfs_end_issue_write(wreq);\n+\tbvecq_pos_unset(\u0026wreq-\u003eload_cursor);\n+\tbvecq_pos_unset(\u0026wreq-\u003edispatch_cursor);\n \tnetfs_wake_collector(wreq);\n \n \tnetfs_put_request(wreq, netfs_rreq_trace_put_return);\n \t_leave(\" = %d\", error);\n \treturn error;\n \n+nomem:\n+\terror = -ENOMEM;\n+\tnetfs_put_failed_request(wreq);\n couldnt_start:\n \tif (error == -ENOMEM) {\n \t\tfolio_redirty_for_writepage(wbc, folio);\n@@ -631,23 +663,28 @@ EXPORT_SYMBOL(netfs_writepages);\n * netfs_writeback_single - Write back a monolithic payload\n * @mapping: The mapping to write from\n * @wbc: Hints from the VM\n- * @iter: Data to write.\n+ * @iter: Buffer to write from\n+ * @len: Amount to write from buffer\n *\n * Write a monolithic, non-pagecache object back to the server and/or the\n- * cache. The caller must explicitly set NETFS_RREQ_UPLOAD_TO_SERVER when\n- * initialising the request if it wants the data to be written to the server\n- * (for AFS directories and symlinks, this is not possible; things like mkdir,\n- * symlink, rmdir and unlink must be used instead).\n+ * cache. There's a maximum of one subrequest per stream. The buffer should be\n+ * rounded out sufficiently that it can accommodate cache DIO rounding.\n+ *\n+ * The caller must explicitly set NETFS_RREQ_UPLOAD_TO_SERVER when initialising\n+ * the request if it wants the data to be written to the server (for AFS\n+ * directories and symlinks, this is not possible; things like mkdir, symlink,\n+ * rmdir and unlink must be used instead).\n *\n * Return: 0 if successful; 1 if skipped due to lock conflict and WB_SYNC_NONE;\n * or a negative error code.\n */\n int netfs_writeback_single(struct address_space *mapping,\n \t\t\t struct writeback_control *wbc,\n-\t\t\t struct iov_iter *iter)\n+\t\t\t struct iov_iter *iter, size_t len)\n {\n \tstruct netfs_io_request *wreq;\n \tstruct netfs_inode *ictx = netfs_inode(mapping-\u003ehost);\n+\tsize_t clen;\n \tint ret;\n \n \tif (!netfs_wb_begin(ictx, wbc-\u003esync_mode == WB_SYNC_NONE)) {\n@@ -661,10 +698,27 @@ int netfs_writeback_single(struct address_space *mapping,\n \t\tret = PTR_ERR(wreq);\n \t\tgoto couldnt_start;\n \t}\n+\twreq-\u003elen = len;\n+\tclen = len;\n+\n+\tif (wreq-\u003ecache_resources.dio_size \u003e 1) {\n+\t\tclen = round_up(len, wreq-\u003ecache_resources.dio_size);\n+\t\tif (clen \u003e iov_iter_count(iter)) {\n+\t\t\tret = -EIO;\n+\t\t\tgoto cleanup_free;\n+\t\t}\n+\t}\n \n-\twreq-\u003ebuffer.iter = *iter;\n-\twreq-\u003elen = iov_iter_count(iter);\n-\twreq-\u003esubmitted = wreq-\u003elen;\n+\tret = netfs_extract_iter(iter, clen, INT_MAX, \u0026wreq-\u003edispatch_cursor.bvecq,\n+\t\t\t\t 0, wreq-\u003egfp);\n+\tif (ret \u003c 0)\n+\t\tgoto cleanup_free;\n+\tif (ret \u003c clen) {\n+\t\tret = -EIO;\n+\t\tgoto cleanup_free;\n+\t}\n+\n+\tbvecq_pos_set(\u0026wreq-\u003ecollect_cursor, \u0026wreq-\u003edispatch_cursor);\n \n \t__set_bit(NETFS_RREQ_OFFLOAD_COLLECTION, \u0026wreq-\u003eflags);\n \ttrace_netfs_write(wreq, netfs_write_trace_writeback_single);\n@@ -685,12 +739,14 @@ int netfs_writeback_single(struct address_space *mapping,\n \n \t\tsubreq = stream-\u003econstruct;\n \t\tsubreq-\u003elen = wreq-\u003elen;\n+\t\tif (stream-\u003esource == NETFS_WRITE_TO_CACHE)\n+\t\t\tsubreq-\u003elen = clen;\n \t\tstream-\u003esubmit_len = subreq-\u003elen;\n-\t\tstream-\u003esubmit_extendable_to = round_up(wreq-\u003elen, PAGE_SIZE);\n \n \t\tnetfs_issue_write(wreq, stream);\n \t}\n \n+\twreq-\u003esubmitted = wreq-\u003elen;\n \tnetfs_all_subreqs_queued(wreq);\n \tnetfs_wake_collector(wreq);\n \n@@ -705,6 +761,8 @@ int netfs_writeback_single(struct address_space *mapping,\n \t_leave(\" = %d\", ret);\n \treturn ret;\n \n+cleanup_free:\n+\tnetfs_put_failed_request(wreq);\n couldnt_start:\n \tnetfs_wb_end(ictx);\n \t_leave(\" = %d\", ret);\ndiff --git a/fs/netfs/write_retry.c b/fs/netfs/write_retry.c\nindex 2f20577563e14..235e75eb10914 100644\n--- a/fs/netfs/write_retry.c\n+++ b/fs/netfs/write_retry.c\n@@ -17,15 +17,17 @@\n static void netfs_retry_write_stream(struct netfs_io_request *wreq,\n \t\t\t\t struct netfs_io_stream *stream)\n {\n+\tstruct bvecq_pos dispatch_cursor = {};\n \tstruct list_head *next;\n \n \t_enter(\"R=%x[%x:]\", wreq-\u003edebug_id, stream-\u003estream_nr);\n \n \tif (list_empty(\u0026stream-\u003esubrequests))\n \t\treturn;\n+\tif (WARN_ON_ONCE(stream-\u003esource != NETFS_UPLOAD_TO_SERVER))\n+\t\treturn; /* Shouldn't be retrying cache writes. */\n \n-\tif (stream-\u003esource == NETFS_UPLOAD_TO_SERVER \u0026\u0026\n-\t wreq-\u003enetfs_ops-\u003eretry_request)\n+\tif (wreq-\u003enetfs_ops-\u003eretry_request)\n \t\twreq-\u003enetfs_ops-\u003eretry_request(wreq, stream);\n \n \tif (unlikely(stream-\u003efailed))\n@@ -39,12 +41,8 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,\n \t\t\tif (test_bit(NETFS_SREQ_FAILED, \u0026subreq-\u003eflags))\n \t\t\t\tbreak;\n \t\t\tif (__test_and_clear_bit(NETFS_SREQ_NEED_RETRY, \u0026subreq-\u003eflags)) {\n-\t\t\t\tstruct iov_iter source;\n-\n-\t\t\t\tnetfs_reset_iter(subreq);\n-\t\t\t\tsource = subreq-\u003eio_iter;\n \t\t\t\tnetfs_get_subrequest(subreq, netfs_sreq_trace_get_resubmit);\n-\t\t\t\tnetfs_reissue_write(stream, subreq, \u0026source);\n+\t\t\t\tnetfs_reissue_write(stream, subreq);\n \t\t\t}\n \t\t}\n \t\treturn;\n@@ -54,11 +52,12 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,\n \n \tdo {\n \t\tstruct netfs_io_subrequest *subreq = NULL, *from, *to, *tmp;\n-\t\tstruct iov_iter source;\n \t\tuoff_t start, len;\n \t\tsize_t part;\n \t\tbool boundary = false;\n \n+\t\tbvecq_pos_unset(\u0026dispatch_cursor);\n+\n \t\t/* Go through the stream and find the next span of contiguous\n \t\t * data that we then rejig (cifs, for example, needs the wsize\n \t\t * renegotiating) and reissue.\n@@ -70,7 +69,7 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,\n \n \t\tif (test_bit(NETFS_SREQ_FAILED, \u0026from-\u003eflags) ||\n \t\t !test_bit(NETFS_SREQ_NEED_RETRY, \u0026from-\u003eflags))\n-\t\t\treturn;\n+\t\t\tgoto out;\n \n \t\tfor (;;) {\n \t\t\t/* Read pointer to subreq before reading subreq state. */\n@@ -79,7 +78,8 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,\n \t\t\t\tbreak;\n \n \t\t\tsubreq = list_entry(next, struct netfs_io_subrequest, rreq_link);\n-\t\t\tif (subreq-\u003estart + subreq-\u003etransferred != start + len ||\n+\t\t\tif (subreq-\u003estart != start + len ||\n+\t\t\t subreq-\u003etransferred \u003e 0 ||\n \t\t\t test_bit(NETFS_SREQ_BOUNDARY, \u0026subreq-\u003eflags) ||\n \t\t\t !test_bit(NETFS_SREQ_NEED_RETRY, \u0026subreq-\u003eflags))\n \t\t\t\tbreak;\n@@ -90,11 +90,13 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,\n \t\t/* Determine the set of buffers we're going to use. Each\n \t\t * subreq gets a subset of a single overall contiguous buffer.\n \t\t */\n-\t\tnetfs_reset_iter(from);\n-\t\tsource = from-\u003eio_iter;\n-\t\tsource.count = len;\n+\t\tbvecq_pos_transfer(\u0026dispatch_cursor, \u0026from-\u003eio_buffer);\n+\t\tbvecq_pos_advance(\u0026dispatch_cursor, from-\u003etransferred);\n \n-\t\t/* Work through the sublist. */\n+\t\t/* Work through the sublist. The chain of buffers we're going\n+\t\t * to fill is attached to dispatch_cursor and we need to read\n+\t\t * 'len' amount of data from 'start'.\n+\t\t */\n \t\tsubreq = from;\n \t\tlist_for_each_entry_from(subreq, \u0026stream-\u003esubrequests, rreq_link) {\n \t\t\tif (!len)\n@@ -104,16 +106,22 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,\n \t\t\tsubreq-\u003elen\t= len;\n \t\t\t__clear_bit(NETFS_SREQ_NEED_RETRY, \u0026subreq-\u003eflags);\n \t\t\ttrace_netfs_sreq(subreq, netfs_sreq_trace_retry);\n+\t\t\tsubreq-\u003etransferred = 0;\n+\n+\t\t\tbvecq_pos_unset(\u0026subreq-\u003eio_buffer);\n \n \t\t\t/* Renegotiate max_len (wsize) */\n \t\t\tstream-\u003esreq_max_len = len;\n+\t\t\tstream-\u003esreq_max_segs = INT_MAX;\n \t\t\tstream-\u003eprepare_write(subreq);\n \n-\t\t\tpart = umin(len, stream-\u003esreq_max_len);\n-\t\t\tif (unlikely(stream-\u003esreq_max_segs))\n-\t\t\t\tpart = netfs_limit_iter(\u0026source, 0, part, stream-\u003esreq_max_segs);\n+\t\t\tbvecq_pos_set(\u0026subreq-\u003eio_buffer, \u0026dispatch_cursor);\n+\t\t\tpart = bvecq_slice(\u0026dispatch_cursor,\n+\t\t\t\t\t umin(len, stream-\u003esreq_max_len),\n+\t\t\t\t\t stream-\u003esreq_max_segs,\n+\t\t\t\t\t \u0026subreq-\u003enr_segs);\n \t\t\tsubreq-\u003elen = part;\n-\t\t\tsubreq-\u003etransferred = 0;\n+\n \t\t\tlen -= part;\n \t\t\tstart += part;\n \t\t\tif (len \u0026\u0026 subreq == to \u0026\u0026\n@@ -121,7 +129,7 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,\n \t\t\t\tboundary = true;\n \n \t\t\tnetfs_get_subrequest(subreq, netfs_sreq_trace_get_resubmit);\n-\t\t\tnetfs_reissue_write(stream, subreq, \u0026source);\n+\t\t\tnetfs_reissue_write(stream, subreq);\n \t\t\tif (subreq == to)\n \t\t\t\tbreak;\n \t\t}\n@@ -172,17 +180,19 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,\n \t\t\t\tnetfs_stat(\u0026netfs_n_wh_upload);\n \t\t\t\tstream-\u003esreq_max_len = umin(len, wreq-\u003ewsize);\n \t\t\t\tbreak;\n-\t\t\tcase NETFS_WRITE_TO_CACHE:\n-\t\t\t\tnetfs_stat(\u0026netfs_n_wh_write);\n-\t\t\t\tbreak;\n \t\t\tdefault:\n \t\t\t\tWARN_ON_ONCE(1);\n \t\t\t}\n \n \t\t\tstream-\u003eprepare_write(subreq);\n \n-\t\t\tpart = umin(len, stream-\u003esreq_max_len);\n+\t\t\tbvecq_pos_set(\u0026subreq-\u003eio_buffer, \u0026dispatch_cursor);\n+\t\t\tpart = bvecq_slice(\u0026dispatch_cursor,\n+\t\t\t\t\t umin(len, stream-\u003esreq_max_len),\n+\t\t\t\t\t stream-\u003esreq_max_segs,\n+\t\t\t\t\t \u0026subreq-\u003enr_segs);\n \t\t\tsubreq-\u003elen = subreq-\u003etransferred + part;\n+\n \t\t\tlen -= part;\n \t\t\tstart += part;\n \t\t\tif (!len \u0026\u0026 boundary) {\n@@ -190,13 +200,16 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,\n \t\t\t\tboundary = false;\n \t\t\t}\n \n-\t\t\tnetfs_reissue_write(stream, subreq, \u0026source);\n+\t\t\tnetfs_reissue_write(stream, subreq);\n \t\t\tif (!len)\n \t\t\t\tbreak;\n \n \t\t} while (len);\n \n \t} while (!list_is_head(next, \u0026stream-\u003esubrequests));\n+\n+out:\n+\tbvecq_pos_unset(\u0026dispatch_cursor);\n }\n \n /*\ndiff --git a/include/linux/bvecq.h b/include/linux/bvecq.h\nindex b984aaa449088..389f6407cb846 100644\n--- a/include/linux/bvecq.h\n+++ b/include/linux/bvecq.h\n@@ -54,6 +54,16 @@ struct bvecq {\n /* Number of slots in a 4K bvecq. */\n #define BVECQ_4KB_SLOTS ((4096 - sizeof(struct bvecq)) / sizeof(struct bio_vec))\n \n+/*\n+ * Position in a bio_vec queue. The bvecq holds a ref on the queue segment it\n+ * points to.\n+ */\n+struct bvecq_pos {\n+\tstruct bvecq\t\t*bvecq;\t\t/* The first bvecq */\n+\tunsigned int\t\toffset;\t\t/* The offset within the starting slot */\n+\tu16\t\t\tslot;\t\t/* The starting slot */\n+};\n+\n void bvecq_dump(const struct bvecq *bq);\n struct bvecq *bvecq_alloc_one(size_t nr_slots, gfp_t gfp, bool for_writeback);\n struct bvecq *bvecq_alloc_chain(size_t nr_slots, gfp_t gfp, bool for_writeback);\n@@ -61,6 +71,13 @@ struct bvecq *bvecq_alloc_buffer2(size_t size, unsigned int pre_slots, gfp_t gfp\n \t\t\t\t bool for_writeback);\n void bvecq_put(struct bvecq *bq);\n int bvecq_expand_buffer(struct bvecq **_buffer, size_t *_cur_size, size_t size, gfp_t gfp);\n+int bvecq_buffer_init(struct bvecq_pos *pos, gfp_t gfp, bool for_writeback);\n+void bvecq_buffer_append(struct bvecq_pos *pos, struct bvecq *bq);\n+void bvecq_pos_advance(struct bvecq_pos *pos, size_t amount);\n+ssize_t bvecq_zero(struct bvecq_pos *pos, size_t amount);\n+size_t bvecq_slice(struct bvecq_pos *pos, size_t max_size,\n+\t\t unsigned int max_slots, unsigned int *_nr_slots);\n+ssize_t bvecq_load_from_ra(struct bvecq_pos *pos, struct readahead_control *ractl);\n \n /**\n * bvecq_alloc_buffer - Allocate a bvecq chain and populate with buffers\n@@ -163,4 +180,171 @@ static inline struct bvecq *bvecq_next(const struct bvecq *bq)\n \treturn smp_load_acquire(\u0026bq-\u003enext);\n }\n \n+/**\n+ * bvecq_pos_set - Set one position to be the same as another\n+ * @pos: The position object to set\n+ * @at: The source position.\n+ *\n+ * Set @pos to have the same position as @at. This may take a ref on the\n+ * bvecq pointed to.\n+ */\n+static inline void bvecq_pos_set(struct bvecq_pos *pos, const struct bvecq_pos *at)\n+{\n+\t*pos = *at;\n+\tbvecq_get(pos-\u003ebvecq);\n+}\n+\n+/**\n+ * bvecq_pos_unset - Unset a position\n+ * @pos: The position object to unset\n+ *\n+ * Unset @pos. This does any needed ref cleanup.\n+ */\n+static inline void bvecq_pos_unset(struct bvecq_pos *pos)\n+{\n+\tbvecq_put(pos-\u003ebvecq);\n+\tpos-\u003ebvecq = NULL;\n+\tpos-\u003eslot = 0;\n+\tpos-\u003eoffset = 0;\n+}\n+\n+/**\n+ * bvecq_pos_transfer - Transfer one position to another, clearing the first\n+ * @pos: The position object to set\n+ * @from: The source position to clear.\n+ *\n+ * Set @pos to have the same position as @from and then clear @from. This may\n+ * transfer a ref on the bvecq pointed to.\n+ */\n+static inline void bvecq_pos_transfer(struct bvecq_pos *pos, struct bvecq_pos *from)\n+{\n+\t*pos = *from;\n+\tfrom-\u003ebvecq = NULL;\n+\tfrom-\u003eslot = 0;\n+\tfrom-\u003eoffset = 0;\n+}\n+\n+/**\n+ * bvecq_pos_move - Update a position to a new bvecq\n+ * @pos: The position object to update.\n+ * @to: The new bvecq to point at.\n+ *\n+ * Update @pos to point to @to if it doesn't already do so. This may\n+ * manipulate refs on the bvecqs pointed to.\n+ */\n+static inline void bvecq_pos_move(struct bvecq_pos *pos, struct bvecq *to)\n+{\n+\tstruct bvecq *old = pos-\u003ebvecq;\n+\n+\tif (old != to) {\n+\t\tpos-\u003ebvecq = bvecq_get(to);\n+\t\tbvecq_put(old);\n+\t}\n+}\n+\n+/**\n+ * bvecq_pos_nudge - Nudge a position onto the next segment if current used up\n+ * @pos: The position object to nudge.\n+ *\n+ * Update @pos to point to the next segment in the chain if we've used up the\n+ * current segment. This may manipulate refs on the bvecqs pointed to.\n+ *\n+ * Return: true if found a new segment, false if hit the end.\n+ */\n+static inline bool bvecq_pos_nudge(struct bvecq_pos *pos)\n+{\n+\tstruct bvecq *bq = pos-\u003ebvecq;\n+\n+\tfor (;;) {\n+\t\tif (!bvecq_acquire_slot(bq, pos-\u003eslot)) {\n+\t\t\tbq = bvecq_next(bq);\n+\t\t\tif (!bq)\n+\t\t\t\treturn false;\n+\t\t\tif (bvecq_acquire_slot(bq, pos-\u003eslot))\n+\t\t\t\tcontinue; /* More slots got added. */\n+\t\t\tbvecq_pos_move(pos, bq);\n+\t\t\tpos-\u003eslot = 0;\n+\t\t\tpos-\u003eoffset = 0;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tif (pos-\u003eoffset \u003e= bq-\u003ebv[pos-\u003eslot].bv_len) {\n+\t\t\tpos-\u003eslot++;\n+\t\t\tpos-\u003eoffset = 0;\n+\t\t\tcontinue;\n+\t\t}\n+\t\treturn true;\n+\t}\n+}\n+\n+/**\n+ * bvecq_pos_step - Step a position to the next slot if possible\n+ * @pos: The position object to step.\n+ *\n+ * Update @pos to point to the next slot in the queue if not at the end. This\n+ * may manipulate refs on the bvecqs pointed to.\n+ *\n+ * Return: true if successful, false if was at the end.\n+ */\n+static inline bool bvecq_pos_step(struct bvecq_pos *pos)\n+{\n+\tstruct bvecq *bq = pos-\u003ebvecq, *next;\n+\n+\tpos-\u003eslot++;\n+\tpos-\u003eoffset = 0;\n+\tif (bvecq_acquire_slot(bq, pos-\u003eslot))\n+\t\treturn true;\n+\tnext = bvecq_next(bq);\n+\tif (!next)\n+\t\treturn false;\n+\tif (bvecq_acquire_slot(bq, pos-\u003eslot))\n+\t\treturn true;\n+\tbvecq_pos_move(pos, next);\n+\tpos-\u003eslot = 0;\n+\treturn true;\n+}\n+\n+/**\n+ * bvecq_delete_spent - Delete the bvecq at the front if possible\n+ * @pos: The position object to update.\n+ *\n+ * Delete the used up bvecq at the front of the queue that @pos points to if it\n+ * is not the last node in the queue; if it is the last node in the queue, it\n+ * is kept so that the queue doesn't become detached from the other end. This\n+ * may manipulate refs on the bvecqs pointed to. It is also possible that the\n+ * producer will fill more slots in the current bvecq.\n+ *\n+ * Also, we have to be very careful: the consumer can catch the producer, which\n+ * could lead to us having nothing left in the queue, causing the front and\n+ * back pointers to end up on different tracks. To avoid this, we must always\n+ * keep at least one segment in the queue.\n+ *\n+ * The caller must reload from @pos after calling this.\n+ *\n+ * Return: true if there's more available; false if not.\n+ */\n+static inline bool bvecq_delete_spent(struct bvecq_pos *pos)\n+{\n+\tstruct bvecq *spent = pos-\u003ebvecq;\n+\tstruct bvecq *next;\n+\tunsigned int slot = pos-\u003eslot;\n+\n+again:\n+\t/* Read the contents of the queue node after the pointer to it. */\n+\tnext = bvecq_next(spent);\n+\tif (!next)\n+\t\treturn false; /* Nothing more to consume at the moment. */\n+\tif (slot \u003c bvecq_nr_slots_acquire(spent))\n+\t\treturn true; /* The producer added more. */\n+\tnext-\u003eprev = NULL;\n+\tbvecq_pos_move(pos, next);\n+\tpos-\u003eslot = 0;\n+\tpos-\u003eoffset = 0;\n+\tif (!bvecq_acquire_slot(next, 0)) {\n+\t\tspent = next;\n+\t\tslot = 0;\n+\t\tgoto again;\n+\t}\n+\treturn true;\n+}\n+\n #endif /* _LINUX_BVECQ_H */\ndiff --git a/include/linux/netfs.h b/include/linux/netfs.h\nindex f1f85473b0eee..b3a58ce8115c7 100644\n--- a/include/linux/netfs.h\n+++ b/include/linux/netfs.h\n@@ -19,10 +19,12 @@\n #include \u003clinux/pagemap.h\u003e\n #include \u003clinux/bvecq.h\u003e\n #include \u003clinux/uio.h\u003e\n-#include \u003clinux/rolling_buffer.h\u003e\n \n enum netfs_sreq_ref_trace;\n typedef struct mempool mempool_t;\n+struct readahead_control;\n+struct netfs_io_request;\n+struct netfs_io_subrequest;\n struct fscache_occupancy;\n \n /**\n@@ -144,7 +146,6 @@ struct netfs_io_stream {\n \tunsigned int\t\tsreq_max_segs;\t/* 0 or max number of segments in an iterator */\n \tunsigned int\t\tsubmit_off;\t/* Folio offset we're submitting from */\n \tunsigned int\t\tsubmit_len;\t/* Amount of data left to submit */\n-\tunsigned int\t\tsubmit_extendable_to; /* Amount I/O can be rounded up to */\n \tvoid (*prepare_write)(struct netfs_io_subrequest *subreq);\n \tvoid (*issue_write)(struct netfs_io_subrequest *subreq);\n \t/* Collection tracking */\n@@ -187,6 +188,7 @@ struct netfs_io_subrequest {\n \tstruct netfs_io_request *rreq;\t\t/* Supervising I/O request */\n \tstruct work_struct\twork;\n \tstruct list_head\trreq_link;\t/* Link in rreq-\u003esubrequests */\n+\tstruct bvecq_pos\tio_buffer;\t/* Bookmark in the combined queue of the start */\n \tstruct iov_iter\t\tio_iter;\t/* Iterator for this subrequest */\n \tuoff_t\t\t\tstart;\t\t/* Where to start the I/O */\n \tsize_t\t\t\tlen;\t\t/* Size of the I/O */\n@@ -247,11 +249,14 @@ struct netfs_io_request {\n \tstruct netfs_io_stream\tio_streams[2];\t/* Streams of parallel I/O operations */\n #define NR_IO_STREAMS 2 //wreq-\u003enr_io_streams\n \tstruct netfs_group\t*group;\t\t/* Writeback group being written back */\n-\tstruct rolling_buffer\tbuffer;\t\t/* Unencrypted buffer */\n+\tstruct bvecq\t\t*spare;\t\t/* Advance allocation of bvecq */\n+\tstruct bvecq_pos\tload_cursor;\t/* Point at which new folios are loaded in */\n+\tstruct bvecq_pos\tdispatch_cursor; /* Point from which buffers are dispatched */\n+\tstruct bvecq_pos\tcollect_cursor;\t/* Clear-up point of I/O buffer */\n \twait_queue_head_t\twaitq;\t\t/* Processor waiter */\n \tvoid\t\t\t*netfs_priv;\t/* Private data for the netfs */\n \tvoid\t\t\t*netfs_priv2;\t/* Private data for the netfs */\n-\tstruct bio_vec\t\t*direct_bv;\t/* DIO buffer list (when handling iovec-iter) */\n+\tuoff_t\t\t\tlast_end;\t/* End pos of last folio submitted */\n \tuoff_t\t\t\tsubmitted;\t/* Amount submitted for I/O so far */\n \tuoff_t\t\t\tlen;\t\t/* Length of the request */\n \tsize_t\t\t\ttransferred;\t/* Amount to be indicated as transferred */\n@@ -266,7 +271,6 @@ struct netfs_io_request {\n \tuoff_t\t\t\tabandon_to;\t/* Position to abandon folios to */\n \tconst struct folio\t*no_unlock_folio; /* Don't unlock this folio after read */\n \tgfp_t\t\t\tgfp;\t\t/* GFP flags to use */\n-\tunsigned int\t\tdirect_bv_count; /* Number of elements in direct_bv[] */\n \tunsigned int\t\tdebug_id;\n \tunsigned int\t\trsize;\t\t/* Maximum read size (0 for none) */\n \tunsigned int\t\twsize;\t\t/* Maximum write size (0 for none) */\n@@ -274,7 +278,6 @@ struct netfs_io_request {\n \tunsigned int\t\tnr_group_rel;\t/* Number of refs to release on -\u003egroup */\n \tspinlock_t\t\tlock;\t\t/* Lock for queuing subreqs */\n \tenum netfs_io_origin\torigin;\t\t/* Origin of the request */\n-\tbool\t\t\tdirect_bv_unpin; /* T if direct_bv[] must be unpinned */\n \trefcount_t\t\tref;\n \tunsigned long\t\tflags;\n #define NETFS_RREQ_IN_PROGRESS\t\t0\t/* Unlocked when the request completes (has ref) */\n@@ -425,7 +428,7 @@ void netfs_single_mark_inode_dirty(struct inode *inode);\n ssize_t netfs_read_single(struct inode *inode, struct file *file, struct iov_iter *iter);\n int netfs_writeback_single(struct address_space *mapping,\n \t\t\t struct writeback_control *wbc,\n-\t\t\t struct iov_iter *iter);\n+\t\t\t struct iov_iter *iter, size_t len);\n \n /* Address operations API */\n struct readahead_control;\n@@ -452,11 +455,9 @@ void netfs_get_subrequest(struct netfs_io_subrequest *subreq,\n \t\t\t enum netfs_sreq_ref_trace what);\n void netfs_put_subrequest(struct netfs_io_subrequest *subreq,\n \t\t\t enum netfs_sreq_ref_trace what);\n-ssize_t netfs_extract_user_iter(struct iov_iter *orig, size_t orig_len,\n-\t\t\t\tstruct iov_iter *new,\n-\t\t\t\tiov_iter_extraction_t extraction_flags);\n-size_t netfs_limit_iter(const struct iov_iter *iter, size_t start_offset,\n-\t\t\tsize_t max_size, size_t max_segs);\n+ssize_t netfs_extract_iter(struct iov_iter *orig, size_t max_len, size_t max_pages,\n+\t\t\t struct bvecq **_bvecq_head,\n+\t\t\t iov_iter_extraction_t extraction_flags, gfp_t gfp);\n void netfs_prepare_write_failed(struct netfs_io_subrequest *subreq);\n void netfs_write_subrequest_terminated(void *_op, ssize_t transferred_or_error);\n \ndiff --git a/include/linux/pagemap.h b/include/linux/pagemap.h\nindex 0adfa6605653d..b7154b81d0d7c 100644\n--- a/include/linux/pagemap.h\n+++ b/include/linux/pagemap.h\n@@ -1411,6 +1411,7 @@ struct readahead_control {\n \tstruct file_ra_state *ra;\n /* private: use the readahead_* accessors instead */\n \tpgoff_t _index;\n+\tunsigned int _nr_folios;\n \tunsigned int _nr_pages;\n \tunsigned int _batch_count;\n \tbool dropbehind;\n@@ -1590,6 +1591,15 @@ static inline size_t readahead_batch_length(const struct readahead_control *rac)\n \treturn rac-\u003e_batch_count * PAGE_SIZE;\n }\n \n+/**\n+ * readahead_folio_count - Get the number of folios in this readahead request.\n+ * @rac: The readahead request.\n+ */\n+static inline unsigned int readahead_folio_count(const struct readahead_control *rac)\n+{\n+\treturn rac-\u003e_nr_folios;\n+}\n+\n static inline unsigned long dir_pages(const struct inode *inode)\n {\n \treturn (unsigned long)(inode-\u003ei_size + PAGE_SIZE - 1) \u003e\u003e\ndiff --git a/include/linux/rolling_buffer.h b/include/linux/rolling_buffer.h\ndeleted file mode 100644\nindex 5c0bc4221f010..0000000000000\n--- a/include/linux/rolling_buffer.h\n+++ /dev/null\n@@ -1,47 +0,0 @@\n-/* SPDX-License-Identifier: GPL-2.0-or-later */\n-/* Rolling buffer of folios\n- *\n- * Copyright (C) 2024 Red Hat, Inc. All Rights Reserved.\n- * Written by David Howells (dhowells@redhat.com)\n- */\n-\n-#ifndef _ROLLING_BUFFER_H\n-#define _ROLLING_BUFFER_H\n-\n-#include \u003clinux/bvecq.h\u003e\n-#include \u003clinux/uio.h\u003e\n-\n-/*\n- * Rolling buffer. Whilst the buffer is live and in use, folios and bvecq\n- * segments can be added to one end by one thread and removed from the other\n- * end by another thread. The buffer isn't allowed to be empty; it must always\n- * have at least one bvecq in it so that neither side has to modify both queue\n- * pointers.\n- *\n- * The iterator in the buffer is extended as buffers are inserted. It can be\n- * snapshotted to use a segment of the buffer.\n- */\n-struct rolling_buffer {\n-\tstruct bvecq\t\t*head;\t\t/* Producer's insertion point */\n-\tstruct bvecq\t\t*tail;\t\t/* Consumer's removal point */\n-\tstruct iov_iter\t\titer;\t\t/* Iterator tracking what's left in the buffer */\n-\tu8\t\t\tfirst_tail_slot; /* First slot in -\u003etail */\n-\tbool\t\t\tfor_writeback;\t/* T if being used for writeback */\n-};\n-\n-int rolling_buffer_init(struct rolling_buffer *roll, unsigned int direction,\n-\t\t\tgfp_t gfp, bool for_writeback);\n-int rolling_buffer_make_space(struct rolling_buffer *roll, gfp_t gfp);\n-ssize_t rolling_buffer_bulk_load_from_ra(struct rolling_buffer *roll,\n-\t\t\t\t\t struct readahead_control *ractl,\n-\t\t\t\t\t gfp_t gfp);\n-ssize_t rolling_buffer_append(struct rolling_buffer *roll, struct folio *folio, gfp_t gfp);\n-struct bvecq *rolling_buffer_delete_spent(struct rolling_buffer *roll);\n-void rolling_buffer_clear(struct rolling_buffer *roll);\n-\n-static inline void rolling_buffer_advance(struct rolling_buffer *roll, size_t amount)\n-{\n-\tiov_iter_advance(\u0026roll-\u003eiter, amount);\n-}\n-\n-#endif /* _ROLLING_BUFFER_H */\ndiff --git a/include/trace/events/netfs.h b/include/trace/events/netfs.h\nindex e80c27c49ce25..81a3b7aaa187c 100644\n--- a/include/trace/events/netfs.h\n+++ b/include/trace/events/netfs.h\n@@ -229,7 +229,9 @@\n \tEM(netfs_folio_trace_sched_copy,\t\"sched-copy\")\t\\\n \tEM(netfs_folio_trace_store,\t\t\"store\")\t\\\n \tEM(netfs_folio_trace_store_copy,\t\"store-copy\")\t\\\n-\tE_(netfs_folio_trace_store_plus,\t\"store+\")\n+\tEM(netfs_folio_trace_store_plus,\t\"store+\")\t\\\n+\tEM(netfs_folio_trace_zero,\t\t\"zero\")\t\t\\\n+\tE_(netfs_folio_trace_zero_ra,\t\t\"zero-ra\")\n \n #define netfs_collect_contig_traces\t\t\t\t\\\n \tEM(netfs_contig_trace_collect,\t\t\"Collect\")\t\\\n@@ -386,10 +388,10 @@ TRACE_EVENT(netfs_sreq,\n \t\t __entry-\u003elen\t= sreq-\u003elen;\n \t\t __entry-\u003etransferred = sreq-\u003etransferred;\n \t\t __entry-\u003estart\t= sreq-\u003estart;\n-\t\t __entry-\u003eslot\t= sreq-\u003eio_iter.bvecq_slot;\n+\t\t __entry-\u003eslot\t= sreq-\u003eio_buffer.slot;\n \t\t\t ),\n \n-\t TP_printk(\"R=%08x[%x] %s %s f=%03x s=%llx %zx/%zx s=%u e=%d\",\n+\t TP_printk(\"R=%08x[%x] %s %s f=%03x s=%llx %zx/%zx bv=%u e=%d\",\n \t\t __entry-\u003erreq, __entry-\u003eindex,\n \t\t __print_symbolic(__entry-\u003esource, netfs_sreq_sources),\n \t\t __print_symbolic(__entry-\u003ewhat, netfs_sreq_traces),\n@@ -782,6 +784,30 @@ TRACE_EVENT(netfs_read_progress_at,\n \t\t __entry-\u003erreq, __entry-\u003ecleaned_to, __entry-\u003eprogress_at)\n \t );\n \n+TRACE_EVENT(netfs_bv_slot,\n+\t TP_PROTO(const struct bvecq *bq, int slot),\n+\n+\t TP_ARGS(bq, slot),\n+\n+\t TP_STRUCT__entry(\n+\t\t __field(unsigned long,\t\tpfn)\n+\t\t __field(unsigned int,\t\toffset)\n+\t\t __field(unsigned int,\t\tlen)\n+\t\t __field(unsigned int,\t\tslot)\n+\t\t\t ),\n+\n+\t TP_fast_assign(\n+\t\t __entry-\u003eslot = slot;\n+\t\t __entry-\u003epfn = page_to_pfn(bq-\u003ebv[slot].bv_page);\n+\t\t __entry-\u003eoffset = bq-\u003ebv[slot].bv_offset;\n+\t\t __entry-\u003elen = bq-\u003ebv[slot].bv_len;\n+\t\t\t ),\n+\n+\t TP_printk(\"bq[%x] p=%lx %x-%x\",\n+\t\t __entry-\u003eslot,\n+\t\t __entry-\u003epfn, __entry-\u003eoffset, __entry-\u003eoffset + __entry-\u003elen)\n+\t );\n+\n #undef EM\n #undef E_\n #endif /* _TRACE_NETFS_H */\ndiff --git a/mm/readahead.c b/mm/readahead.c\nindex 6e5563290287e..196542fb1c930 100644\n--- a/mm/readahead.c\n+++ b/mm/readahead.c\n@@ -188,6 +188,7 @@ static void read_pages(struct readahead_control *rac)\n \tif (unlikely(rac-\u003e_workingset))\n \t\tpsi_memstall_leave(\u0026rac-\u003e_pflags);\n \trac-\u003e_workingset = false;\n+\trac-\u003e_nr_folios = 0;\n \n \tBUG_ON(readahead_count(rac));\n }\n@@ -303,6 +304,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl,\n \t\tif (i == mark)\n \t\t\tfolio_set_readahead(folio);\n \t\tractl-\u003e_workingset |= folio_test_workingset(folio);\n+\t\tractl-\u003e_nr_folios++;\n \t\tractl-\u003e_nr_pages += min_nrpages;\n \t\ti += min_nrpages;\n \t}\n@@ -473,6 +475,7 @@ static inline int ra_alloc_folio(struct readahead_control *ractl, pgoff_t index,\n \t\treturn err;\n \t}\n \n+\tractl-\u003e_nr_folios++;\n \tractl-\u003e_nr_pages += 1UL \u003c\u003c order;\n \tractl-\u003e_workingset |= folio_test_workingset(folio);\n \treturn 0;\n@@ -822,6 +825,7 @@ void readahead_expand(struct readahead_control *ractl,\n \t\t\tractl-\u003e_workingset = true;\n \t\t\tpsi_memstall_enter(\u0026ractl-\u003e_pflags);\n \t\t}\n+\t\tractl-\u003e_nr_folios++;\n \t\tractl-\u003e_nr_pages += min_nrpages;\n \t\tractl-\u003e_index = folio-\u003eindex;\n \t}\n@@ -851,6 +855,7 @@ void readahead_expand(struct readahead_control *ractl,\n \t\t\tractl-\u003e_workingset = true;\n \t\t\tpsi_memstall_enter(\u0026ractl-\u003e_pflags);\n \t\t}\n+\t\tractl-\u003e_nr_folios++;\n \t\tractl-\u003e_nr_pages += min_nrpages;\n \t\tif (ra) {\n \t\t\tra-\u003esize += min_nrpages;\n"
} |
| 2/1 | 2026/10/05 07:34 | agent | patch-evaluator |
0mModel:core Args: null Results: {
"EnableConfigs": [
"NETFS_SUPPORT",
"FSCACHE",
"CACHEFILES",
"AFS_FS"
],
"FocusSymbols": [
"bvecq_slice",
"bvecq_load_from_ra",
"bvecq_pos_advance",
"bvecq_zero",
"bvecq_buffer_init",
"bvecq_buffer_append",
"netfs_extract_iter",
"netfs_readahead",
"netfs_read_single",
"netfs_writepages",
"netfs_writeback_single",
"netfs_unbuffered_read_iter_locked",
"netfs_unbuffered_write_iter_locked",
"afs_symlink_writepages"
],
"Reasoning": "The patch replaces the rolling_buffer implementation in netfs with a new bvecq queue and cursor-based architecture (bvecq_pos, bvecq_slice, bvecq_load_from_ra, etc.). It updates readahead folio counting in mm/readahead.c, refactors iterator extraction into bvec queues (netfs_extract_iter), and modifies read, write, direct I/O, readahead, retry, and writeback paths in NetFS, AFS, and Cachefiles. These changes modify reachable core filesystem and MM logic, altering buffer management, refcounting, and slicing invariants, which makes fuzzing worthwhile to uncover regressions, memory bugs, or assertion failures.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit c5a2218e2e5504bde2e57f0bae41a96022008bb9
Author: syz-cluster <triage@syzkaller.com>
Date: Mon Oct 5 07:33:58 2026 +0000
syz-cluster: applied patch under review
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index 5fac02d2d2814..39cba3f37ecd4 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -2229,8 +2229,9 @@ static int afs_dir_writepages(struct address_space *mapping,
if (test_bit(AFS_VNODE_DIR_VALID, &dvnode->flags)) {
iov_iter_bvec_queue(&iter, ITER_SOURCE, dvnode->directory, 0, 0,
- i_size_read(&dvnode->netfs.inode));
- ret = netfs_writeback_single(mapping, wbc, &iter);
+ dvnode->directory_size);
+ ret = netfs_writeback_single(mapping, wbc, &iter,
+ i_size_read(&dvnode->netfs.inode));
if (ret == 1)
ret = 0; /* Skipped write due to lock conflict. */
}
diff --git a/fs/afs/symlink.c b/fs/afs/symlink.c
index 9a611efe6b264..ae03ceff42b85 100644
--- a/fs/afs/symlink.c
+++ b/fs/afs/symlink.c
@@ -248,9 +248,9 @@ int afs_symlink_writepages(struct address_space *mapping,
if (vnode->directory &&
atomic64_read(&vnode->cb_expires_at) != AFS_NO_CB_PROMISE) {
- iov_iter_bvec_queue(&iter, ITER_SOURCE, vnode->directory, 0, 0,
- i_size_read(&vnode->netfs.inode));
- ret = netfs_writeback_single(mapping, wbc, &iter);
+ iov_iter_bvec_queue(&iter, ITER_SOURCE, vnode->directory, 0, 0, PAGE_SIZE);
+ ret = netfs_writeback_single(mapping, wbc, &iter,
+ i_size_read(&vnode->netfs.inode));
}
if (ret == 0) {
diff --git a/fs/cachefiles/io.c b/fs/cachefiles/io.c
index d05059822288c..788439ea6e1c8 100644
--- a/fs/cachefiles/io.c
+++ b/fs/cachefiles/io.c
@@ -546,7 +546,6 @@ static void cachefiles_issue_write(struct netfs_io_subrequest *subreq)
struct netfs_cache_resources *cres = &wreq->cache_resources;
struct cachefiles_object *object = cachefiles_cres_object(cres);
struct cachefiles_cache *cache = object->volume->cache;
- struct netfs_io_stream *stream = &wreq->io_streams[subreq->stream_nr];
const struct cred *saved_cred;
size_t off, pre, post, len = subreq->len;
uoff_t start = subreq->start;
@@ -571,17 +570,6 @@ static void cachefiles_issue_write(struct netfs_io_subrequest *subreq)
}
/* We also need to end on the cache granularity boundary */
- if (start + len == wreq->i_size) {
- size_t part = len & (cache->bsize - 1);
- size_t need = cache->bsize - part;
-
- if (part && stream->submit_extendable_to >= need) {
- len += need;
- subreq->len += need;
- subreq->io_iter.count += need;
- }
- }
-
post = len & (cache->bsize - 1);
if (post) {
len -= post;
diff --git a/fs/netfs/Makefile b/fs/netfs/Makefile
index b1ea4439c1bb4..421dd0be413b3 100644
--- a/fs/netfs/Makefile
+++ b/fs/netfs/Makefile
@@ -14,7 +14,6 @@ netfs-y := \
read_collect.o \
read_retry.o \
read_single.o \
- rolling_buffer.o \
write_collect.o \
write_issue.o \
write_retry.o
diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c
index aa1e4f8d46ab3..945bfa6eed3f0 100644
--- a/fs/netfs/buffered_read.c
+++ b/fs/netfs/buffered_read.c
@@ -114,26 +114,21 @@ static int netfs_begin_cache_read(struct netfs_io_request *rreq, struct netfs_in
static ssize_t netfs_prepare_read_iterator(struct netfs_io_subrequest *subreq)
{
struct netfs_io_request *rreq = subreq->rreq;
+ struct netfs_io_stream *stream = &rreq->io_streams[0];
+ ssize_t extracted;
size_t rsize = subreq->len;
if (subreq->source == NETFS_DOWNLOAD_FROM_SERVER)
- rsize = umin(rsize, rreq->io_streams[0].sreq_max_len);
-
- subreq->len = rsize;
- if (unlikely(rreq->io_streams[0].sreq_max_segs)) {
- size_t limit = netfs_limit_iter(&rreq->buffer.iter, 0, rsize,
- rreq->io_streams[0].sreq_max_segs);
-
- if (limit < rsize) {
- subreq->len = limit;
- trace_netfs_sreq(subreq, netfs_sreq_trace_limited);
- }
+ rsize = umin(rsize, stream->sreq_max_len);
+
+ bvecq_pos_set(&subreq->io_buffer, &rreq->dispatch_cursor);
+ extracted = bvecq_slice(&rreq->dispatch_cursor, rsize,
+ stream->sreq_max_segs, &subreq->nr_segs);
+ if (extracted < rsize) {
+ subreq->len = extracted;
+ trace_netfs_sreq(subreq, netfs_sreq_trace_limited);
}
- subreq->io_iter = rreq->buffer.iter;
-
- iov_iter_truncate(&subreq->io_iter, subreq->len);
- rolling_buffer_advance(&rreq->buffer, subreq->len);
return subreq->len;
}
@@ -192,6 +187,9 @@ void netfs_queue_read(struct netfs_io_request *rreq,
static void netfs_issue_read(struct netfs_io_request *rreq,
struct netfs_io_subrequest *subreq)
{
+ iov_iter_bvec_queue(&subreq->io_iter, ITER_DEST, subreq->io_buffer.bvecq,
+ subreq->io_buffer.slot, subreq->io_buffer.offset, subreq->len);
+
switch (subreq->source) {
case NETFS_DOWNLOAD_FROM_SERVER:
rreq->netfs_ops->issue_read(subreq);
@@ -200,10 +198,9 @@ static void netfs_issue_read(struct netfs_io_request *rreq,
netfs_read_cache_to_pagecache(rreq, subreq);
break;
default:
- __set_bit(NETFS_SREQ_CLEAR_TAIL, &subreq->flags);
- subreq->error = 0;
- iov_iter_zero(subreq->len, &subreq->io_iter);
+ bvecq_zero(&subreq->io_buffer, subreq->len);
subreq->transferred = subreq->len;
+ subreq->error = 0;
netfs_read_subreq_terminated(subreq);
break;
}
@@ -215,31 +212,31 @@ static void netfs_issue_read(struct netfs_io_request *rreq,
* otherwise we set the deprecated PG_private_2.
*/
static void netfs_mark_copy_to_cache(struct netfs_io_request *rreq,
- struct bvecq **bq,
- unsigned int *offset,
- int *slot,
- size_t len,
- bool copy)
+ struct bvecq_pos *mark, size_t len, bool copy)
{
+ struct bvecq *bq = mark->bvecq;
+ unsigned int offset = mark->offset;
+ int slot = mark->slot;
+
while (len > 0) {
- struct folio *folio;
size_t fsize, overlap;
- if (!*bq)
+ if (!bq)
break;
- if (!bvecq_acquire_slot(*bq, *slot)) {
- *bq = bvecq_next(*bq);
- *slot = 0;
- *offset = 0;
+ if (!bvecq_acquire_slot(bq, slot)) {
+ bq = bq->next;
+ slot = 0;
+ offset = 0;
continue;
}
/* Determine how much the subreq overlaps the folio, if at all. */
- fsize = (*bq)->bv[*slot].bv_len;
- overlap = min(len, fsize - *offset);
+ fsize = bq->bv[slot].bv_len;
+ overlap = min(len, fsize - offset);
if (overlap > 0 && copy) {
- folio = bvec_folio(&(*bq)->bv[*slot]);
+ struct folio *folio = bvec_folio(&bq->bv[slot]);
+
if (netfs_using_pgpriv2(rreq)) {
if (!folio_test_private_2(folio))
folio_start_private_2(folio);
@@ -251,12 +248,20 @@ static void netfs_mark_copy_to_cache(struct netfs_io_request *rreq,
}
len -= overlap;
- *offset += overlap;
- if (*offset >= fsize) {
- *slot += 1;
- *offset = 0;
+ offset += overlap;
+ if (offset >= fsize) {
+ slot += 1;
+ offset = 0;
}
}
+
+ if (bq) {
+ bvecq_pos_move(mark, bq);
+ mark->offset = offset;
+ mark->slot = slot;
+ } else {
+ bvecq_pos_unset(mark);
+ }
}
/*
@@ -275,11 +280,14 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq)
.cached_to[1] = ULLONG_MAX,
};
struct fscache_occupancy *occ = &_occ;
- struct bvecq *bq = rreq->buffer.tail;
- unsigned int offset = 0;
+ struct bvecq_pos mark_cursor;
ssize_t size = rreq->len;
uoff_t start = rreq->start;
- int ret = 0, slot = 0;
+ int ret = 0;
+
+ _enter("R=%08x", rreq->debug_id);
+
+ bvecq_pos_set(&mark_cursor, &rreq->dispatch_cursor);
do {
int (*prepare_read)(struct netfs_io_subrequest *subreq) = NULL;
@@ -408,10 +416,10 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq)
if (size <= 0)
netfs_all_subreqs_queued(rreq);
- if (bq) {
+ if (mark_cursor.bvecq) {
/* See if the cache indicated this should be cached. */
copy = test_bit(NETFS_SREQ_COPY_TO_CACHE, &subreq->flags);
- netfs_mark_copy_to_cache(rreq, &bq, &slot, &offset, slice, copy);
+ netfs_mark_copy_to_cache(rreq, &mark_cursor, slice, copy);
}
trace_netfs_sreq(subreq, netfs_sreq_trace_submit);
@@ -432,6 +440,9 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq)
/* Defer error return as we may need to wait for outstanding I/O. */
cmpxchg(&rreq->error, 0, ret);
+
+ bvecq_pos_unset(&mark_cursor);
+ bvecq_pos_unset(&rreq->dispatch_cursor);
}
/**
@@ -479,7 +490,7 @@ void netfs_readahead(struct readahead_control *ractl)
* acquires a ref on each folio that we will need to release later -
* but we don't want to do that until after we've started the I/O.
*/
- added = rolling_buffer_bulk_load_from_ra(&rreq->buffer, ractl, rreq->gfp);
+ added = bvecq_load_from_ra(&rreq->dispatch_cursor, ractl);
if (added < 0) {
ret = added;
goto cleanup_free;
@@ -488,6 +499,7 @@ void netfs_readahead(struct readahead_control *ractl)
rreq->submitted = rreq->start + added;
rreq->cleaned_to = rreq->start;
+ bvecq_pos_set(&rreq->collect_cursor, &rreq->dispatch_cursor);
netfs_read_set_unlock_at(rreq);
netfs_read_to_pagecache(rreq);
@@ -500,20 +512,26 @@ void netfs_readahead(struct readahead_control *ractl)
EXPORT_SYMBOL(netfs_readahead);
/*
- * Create a rolling buffer with a single occupying folio.
+ * Create a buffer queue with a single occupying folio.
*/
static int netfs_create_singular_buffer(struct netfs_io_request *rreq, struct folio *folio)
{
- ssize_t added;
+ struct bvecq *bq;
+ size_t fsize = folio_size(folio);
- if (rolling_buffer_init(&rreq->buffer, ITER_DEST, rreq->gfp, false) < 0)
+ bq = bvecq_alloc_one(1, rreq->gfp, false);
+ if (!bq)
return -ENOMEM;
- added = rolling_buffer_append(&rreq->buffer, folio, rreq->gfp);
- if (added < 0)
- return added;
- rreq->submitted = rreq->start + added;
- rreq->progress_at = added;
+ rreq->dispatch_cursor.bvecq = bq;
+ rreq->dispatch_cursor.slot = 0;
+ rreq->dispatch_cursor.offset = 0;
+
+ bvec_set_folio(&bq->bv[0], folio, fsize, 0);
+ bvecq_filled_to(bq, 1);
+ bvecq_pos_set(&rreq->collect_cursor, &rreq->dispatch_cursor);
+ rreq->submitted = rreq->start + fsize;
+ rreq->progress_at = fsize;
return 0;
}
@@ -527,14 +545,14 @@ static int netfs_read_gaps(struct file *file, struct folio *folio)
struct netfs_group *group = netfs_folio_group(folio);
struct netfs_folio *finfo = netfs_folio_info(folio);
struct netfs_inode *ctx = netfs_inode(mapping->host);
- struct bio_vec *bvec = NULL;
+ struct bvecq *bq = NULL;
unsigned int from = finfo->dirty_offset;
unsigned int to = from + finfo->dirty_len;
unsigned int off = 0;
size_t flen = folio_size(folio);
size_t nr_bvec = flen / PAGE_SIZE + 2;
size_t part;
- int ret, i = 0, sink_from = -1, sink_to = -1;
+ int ret, i = 0;
_enter("%lx", folio->index);
@@ -555,31 +573,46 @@ static int netfs_read_gaps(struct file *file, struct folio *folio)
* end get copied to, but the middle is discarded.
*/
ret = -ENOMEM;
- bvec = kmalloc_objs(*bvec, nr_bvec);
- if (!bvec)
+ bq = bvecq_alloc_chain(nr_bvec, rreq->gfp, false);
+ if (!bq)
goto discard;
+ rreq->dispatch_cursor.bvecq = bq;
trace_netfs_folio(folio, netfs_folio_trace_read_gaps);
+ for (struct bvecq *p = bq; p; p = p->next)
+ p->mem_type = BVECQ_MEM_PAGECACHE;
+
if (from > 0) {
- bvec_set_folio(&bvec[i++], folio, from, 0);
+ folio_get(folio);
+ bvec_set_folio(&bq->bv[i++], folio, from, 0);
off = from;
}
- sink_from = i;
while (off < to) {
struct folio *sink = folio_alloc(GFP_KERNEL, 0);
if (!sink)
goto discard;
- part = min_t(size_t, to - off, PAGE_SIZE);
- bvec_set_folio(&bvec[i], sink, part, 0);
+ if (i >= bq->max_slots) {
+ bvecq_filled_to(bq, i);
+ bq = bq->next;
+ i = 0;
+ }
+ part = min(to - off, PAGE_SIZE);
+ bvec_set_folio(&bq->bv[i++], sink, part, 0);
off += part;
- sink_to = i;
- i++;
}
- if (to < flen)
- bvec_set_folio(&bvec[i++], folio, flen - to, to);
- iov_iter_bvec(&rreq->buffer.iter, ITER_DEST, bvec, i, rreq->len);
+ if (to < flen) {
+ if (i >= bq->max_slots) {
+ bvecq_filled_to(bq, i);
+ bq = bq->next;
+ i = 0;
+ }
+ folio_get(folio);
+ bvec_set_folio(&bq->bv[i++], folio, flen - to, to);
+ }
+ bvecq_filled_to(bq, i);
+
rreq->submitted = rreq->start + flen;
netfs_read_to_pagecache(rreq);
@@ -596,22 +629,16 @@ static int netfs_read_gaps(struct file *file, struct folio *folio)
folio_mark_uptodate(folio);
}
- if (sink_to >= 0)
- for (; sink_from <= sink_to; sink_from++)
- folio_put(bvec_folio(&bvec[sink_from]));
- kfree(bvec);
+ bvecq_pos_unset(&rreq->dispatch_cursor);
folio_unlock(folio);
netfs_put_request(rreq, netfs_rreq_trace_put_return);
return ret < 0 ? ret : 0;
discard:
+ bvecq_pos_unset(&rreq->dispatch_cursor);
netfs_put_failed_request(rreq);
alloc_error:
folio_unlock(folio);
- if (sink_to >= 0)
- for (; sink_from <= sink_to; sink_from++)
- folio_put(bvec_folio(&bvec[sink_from]));
- kfree(bvec);
return ret;
}
diff --git a/fs/netfs/bvecq.c b/fs/netfs/bvecq.c
index 5b747f6b59382..2edc0045c2453 100644
--- a/fs/netfs/bvecq.c
+++ b/fs/netfs/bvecq.c
@@ -342,3 +342,313 @@ int bvecq_expand_buffer(struct bvecq **_buffer, size_t *_cur_size, size_t size,
return 0;
}
EXPORT_SYMBOL(bvecq_expand_buffer);
+
+/**
+ * bvecq_buffer_init - Initialise a buffer and set position
+ * @pos: The position to point at the new buffer.
+ * @gfp: The allocation constraints.
+ * @for_writeback: True if allocating for writeback
+ *
+ * Initialise a rolling buffer. We allocate an unpopulated bvecq node to so
+ * that the pointers can be independently driven by the producer and the
+ * consumer.
+ *
+ * Return 0 if successful; -ENOMEM on allocation failure.
+ */
+int bvecq_buffer_init(struct bvecq_pos *pos, gfp_t gfp, bool for_writeback)
+{
+ struct bvecq *bq;
+
+ bq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, for_writeback);
+ if (!bq)
+ return -ENOMEM;
+
+ pos->bvecq = bq; /* Comes with a ref. */
+ pos->slot = 0;
+ pos->offset = 0;
+ return 0;
+}
+
+/**
+ * bvecq_buffer_append - Append a new bvecq node to a buffer
+ * @pos: The position of the last node.
+ * @bq: The buffer to add.
+ *
+ * Add a new node on to the buffer chain at the specified position, either
+ * because the previous one is full or because we have a discontiguity to
+ * contend with, and update @pos to point to it.
+ */
+void bvecq_buffer_append(struct bvecq_pos *pos, struct bvecq *bq)
+{
+ struct bvecq *head = pos->bvecq;
+
+ pos->bvecq = bvecq_get(bq);
+ pos->slot = 0;
+ pos->offset = 0;
+
+ /* [!] NOTE: After we set head->next, the consumer is at liberty to
+ * immediately delete the old head.
+ */
+ bvecq_append(head, bq);
+ bvecq_put(head);
+}
+
+/**
+ * bvecq_pos_advance - Advance a bvecq position
+ * @pos: The position to advance.
+ * @amount: The amount of bytes to advance by.
+ *
+ * Advance the specified bvecq position by @amount bytes. @pos is updated and
+ * bvecq ref counts may have been manipulated. If the position hits the end of
+ * the queue, then it is left pointing beyond the last slot of the last bvecq
+ * so that it doesn't break the chain.
+ */
+void bvecq_pos_advance(struct bvecq_pos *pos, size_t amount)
+{
+ struct bvecq *bq = pos->bvecq, *next;
+ unsigned int slot = pos->slot;
+ size_t offset = pos->offset;
+
+ while (amount) {
+ size_t part;
+
+ if (!bvecq_acquire_slot(bq, slot)) {
+ next = bvecq_next(bq);
+ if (!next) {
+ WARN_ON_ONCE(amount > 0);
+ break;
+ }
+ if (bvecq_acquire_slot(bq, slot))
+ continue; /* More slots got added. */
+ bq = next;
+ slot = 0;
+ offset = 0;
+ continue;
+ }
+
+ part = bq->bv[slot].bv_len - offset;
+
+ if (part > amount) {
+ offset += amount;
+ break;
+ }
+ amount -= part;
+ offset = 0;
+ slot++;
+ }
+
+ pos->slot = slot;
+ pos->offset = offset;
+ bvecq_pos_move(pos, bq);
+}
+
+/*
+ * Clear part of the memory pointed to by a bio_vec.
+ */
+static void bvec_zero(const struct bio_vec *bv, size_t offset, size_t len)
+{
+ struct page *page = bv->bv_page;
+
+ offset += bv->bv_offset;
+
+ page += offset / PAGE_SIZE;
+ offset = offset % PAGE_SIZE;
+
+ while (len) {
+ size_t part = min(len, PAGE_SIZE - offset);
+ char *p = kmap_local_page(page);
+
+ memset(p + offset, 0, part);
+ kunmap_local(p);
+
+ len -= part;
+ offset = 0;
+ page++;
+ }
+}
+
+/**
+ * bvecq_zero - Clear memory starting at the bvecq position.
+ * @pos: The position in the bvecq chain to start clearing.
+ * @amount: The number of bytes to clear.
+ *
+ * Clear memory fragments pointed to by a bvec queue. @pos is updated and
+ * bvecq ref counts may have been manipulated. If the position hits the end of
+ * the queue, then it is left pointing beyond the last slot of the last bvecq
+ * so that it doesn't break the chain.
+ *
+ * Return: The number of bytes cleared.
+ */
+ssize_t bvecq_zero(struct bvecq_pos *pos, size_t amount)
+{
+ struct bvecq *bq = pos->bvecq, *next;
+ unsigned int slot = pos->slot;
+ ssize_t cleared = 0;
+ size_t offset = pos->offset;
+
+ while (amount) {
+ const struct bio_vec *bv;
+ size_t part;
+
+ if (!bvecq_acquire_slot(bq, slot)) {
+ next = bvecq_next(bq);
+ if (!next) {
+ WARN_ON_ONCE(amount > 0);
+ break;
+ }
+ if (bvecq_acquire_slot(bq, slot))
+ continue; /* More slots got added. */
+ bq = next;
+ slot = 0;
+ offset = 0;
+ continue;
+ }
+
+ bv = &bq->bv[slot];
+ if (offset >= bv->bv_len) {
+ slot++;
+ offset = 0;
+ continue;
+ }
+
+ part = min(bv->bv_len - offset, amount);
+ bvec_zero(bv, offset, part);
+ cleared += part;
+ offset += part;
+ amount -= part;
+ }
+
+ pos->slot = slot;
+ pos->offset = offset;
+ bvecq_pos_move(pos, bq);
+ return cleared;
+}
+
+/**
+ * bvecq_slice - Find a slice of a bvecq queue
+ * @pos: The position to start at.
+ * @max_size: The maximum size of the slice (or ULONG_MAX).
+ * @max_slots: The maximum number of slots in the slice (or INT_MAX).
+ * @_nr_slots: Where to put the number of slots (updated).
+ *
+ * Determine the size and number of slots that can be obtained the next slice
+ * of bvec queue up to the maximum size and slot count specified.
+ *
+ * @pos is updated to the end of the slice. If the position hits the end of
+ * the queue, then it is left pointing beyond the last slot of the last bvecq
+ * so that it doesn't break the chain.
+ *
+ * Return: The number of bytes in the slice.
+ */
+size_t bvecq_slice(struct bvecq_pos *pos, size_t max_size,
+ unsigned int max_slots, unsigned int *_nr_slots)
+{
+ struct bvecq *bq, *next;
+ unsigned int slot = pos->slot, nslots = 0;
+ size_t size = 0, offset = pos->offset;
+
+ bq = pos->bvecq;
+ for (;;) {
+ for (; slot < bvecq_nr_slots_acquire(bq); slot++) {
+ const struct bio_vec *bvec = &bq->bv[slot];
+
+ if (offset < bvec->bv_len && bvec->bv_page) {
+ size_t part = min(bvec->bv_len - offset, max_size);
+
+ size += part;
+ offset += part;
+ max_size -= part;
+ nslots++;
+ if (!max_size || nslots >= max_slots)
+ goto out;
+ }
+ offset = 0;
+ }
+
+ /* pos->bvecq isn't allowed to go NULL as the queue may get
+ * extended and we would lose our place.
+ */
+ next = bvecq_next(bq);
+ if (!next)
+ break;
+ if (bvecq_acquire_slot(bq, slot))
+ continue; /* More slots got added. */
+ slot = 0;
+ bq = next;
+ }
+
+out:
+ *_nr_slots = nslots;
+ if (slot == bvecq_nr_slots_acquire(bq)) {
+ next = bvecq_next(bq);
+ if (next) {
+ bq = next;
+ slot = 0;
+ offset = 0;
+ }
+ }
+ bvecq_pos_move(pos, bq);
+ pos->slot = slot;
+ pos->offset = offset;
+ return size;
+}
+
+/**
+ * bvecq_load_from_ra - Allocate a bvecq chain and load from readahead
+ * @pos: Blank position object to attach the new chain to.
+ * @ractl: The readahead control context.
+ *
+ * Decant the set of folios to be read from the readahead context into a bvecq
+ * chain. Each folio occupies one bio_vec element.
+ *
+ * Return: Amount of data loaded or -ENOMEM on allocation failure.
+ */
+ssize_t bvecq_load_from_ra(struct bvecq_pos *pos, struct readahead_control *ractl)
+{
+ XA_STATE(xas, &ractl->mapping->i_pages, ractl->_index);
+ struct folio *folio;
+ struct bvecq *bq;
+ unsigned int slot = 0;
+ size_t loaded = 0;
+
+ bq = bvecq_alloc_chain(ractl->_nr_folios, GFP_KERNEL, false);
+ if (!bq)
+ return -ENOMEM;
+
+ pos->bvecq = bq;
+ pos->slot = 0;
+ pos->offset = 0;
+
+ rcu_read_lock();
+
+ xas_for_each(&xas, folio, ractl->_index + ractl->_nr_pages - 1) {
+ size_t len;
+
+ if (xas_retry(&xas, folio))
+ continue;
+ VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
+
+ len = folio_size(folio);
+ bvec_set_folio(&bq->bv[slot], folio, len, 0);
+ loaded += len;
+ slot++;
+ trace_netfs_folio(folio, netfs_folio_trace_read);
+
+ if (slot >= bq->max_slots) {
+ bvecq_filled_to(bq, slot);
+ bq = bq->next;
+ if (!bq)
+ break;
+ slot = 0;
+ }
+ }
+
+ rcu_read_unlock();
+
+ if (bq)
+ bvecq_filled_to(bq, slot);
+
+ ractl->_index += ractl->_nr_pages;
+ ractl->_nr_pages = 0;
+ return loaded;
+}
diff --git a/fs/netfs/direct_read.c b/fs/netfs/direct_read.c
index 8c15f30797238..dae890e8df285 100644
--- a/fs/netfs/direct_read.c
+++ b/fs/netfs/direct_read.c
@@ -16,44 +16,21 @@
#include <linux/netfs.h>
#include "internal.h"
-static void netfs_prepare_dio_read_iterator(struct netfs_io_subrequest *subreq)
-{
- struct netfs_io_request *rreq = subreq->rreq;
- size_t rsize;
-
- rsize = umin(subreq->len, rreq->io_streams[0].sreq_max_len);
- subreq->len = rsize;
-
- if (unlikely(rreq->io_streams[0].sreq_max_segs)) {
- size_t limit = netfs_limit_iter(&rreq->buffer.iter, 0, rsize,
- rreq->io_streams[0].sreq_max_segs);
-
- if (limit < rsize) {
- subreq->len = limit;
- trace_netfs_sreq(subreq, netfs_sreq_trace_limited);
- }
- }
-
- trace_netfs_sreq(subreq, netfs_sreq_trace_prepare);
-
- subreq->io_iter = rreq->buffer.iter;
- iov_iter_truncate(&subreq->io_iter, subreq->len);
- iov_iter_advance(&rreq->buffer.iter, subreq->len);
-}
-
/*
* Perform a read to a buffer from the server, slicing up the region to be read
* according to the network rsize.
*/
static void netfs_dispatch_unbuffered_reads(struct netfs_io_request *rreq)
{
+ struct netfs_io_stream *stream = &rreq->io_streams[0];
ssize_t size = rreq->len;
uoff_t start = rreq->start;
int ret;
+ bvecq_pos_set(&rreq->collect_cursor, &rreq->dispatch_cursor);
+
do {
struct netfs_io_subrequest *subreq;
- ssize_t slice;
subreq = netfs_alloc_subrequest(rreq, NETFS_DOWNLOAD_FROM_SERVER);
if (!subreq) {
@@ -78,14 +55,22 @@ static void netfs_dispatch_unbuffered_reads(struct netfs_io_request *rreq)
}
}
- netfs_prepare_dio_read_iterator(subreq);
- slice = subreq->len;
- size -= slice;
- start += slice;
- rreq->submitted += slice;
+ bvecq_pos_set(&subreq->io_buffer, &rreq->dispatch_cursor);
+ subreq->len = bvecq_slice(&rreq->dispatch_cursor,
+ umin(size, stream->sreq_max_len),
+ stream->sreq_max_segs,
+ &subreq->nr_segs);
+
+ size -= subreq->len;
+ start += subreq->len;
+ rreq->submitted += subreq->len;
if (size <= 0)
netfs_all_subreqs_queued(rreq);
+ iov_iter_bvec_queue(&subreq->io_iter, ITER_DEST, subreq->io_buffer.bvecq,
+ subreq->io_buffer.slot, subreq->io_buffer.offset,
+ subreq->len);
+
rreq->netfs_ops->issue_read(subreq);
if (test_bit(NETFS_RREQ_PAUSE, &rreq->flags))
@@ -99,6 +84,8 @@ static void netfs_dispatch_unbuffered_reads(struct netfs_io_request *rreq)
netfs_all_subreqs_queued(rreq);
netfs_wake_collector(rreq);
}
+
+ bvecq_pos_unset(&rreq->dispatch_cursor);
}
/*
@@ -177,25 +164,17 @@ ssize_t netfs_unbuffered_read_iter_locked(struct kiocb *iocb, struct iov_iter *i
* buffer for ourselves as the caller's iterator will be trashed when
* we return.
*
- * In such a case, extract an iterator to represent as much of the the
- * output buffer as we can manage. Note that the extraction might not
- * be able to allocate a sufficiently large bvec array and may shorten
- * the request.
+ * Extract a buffer queue to represent as much of the output buffer as
+ * we can manage. The fragments are extracted into a bvecq which will
+ * have sufficient nodes allocated to hold all the data, though this
+ * may end up truncated if ENOMEM is encountered.
*/
- if (user_backed_iter(iter)) {
- ret = netfs_extract_user_iter(iter, rreq->len, &rreq->buffer.iter, 0);
- if (ret < 0)
- goto error_put;
- rreq->direct_bv = (struct bio_vec *)rreq->buffer.iter.bvec;
- rreq->direct_bv_count = ret;
- rreq->direct_bv_unpin = iov_iter_extract_will_pin(iter);
- rreq->len = iov_iter_count(&rreq->buffer.iter);
- } else {
- rreq->buffer.iter = *iter;
- rreq->len = orig_count;
- rreq->direct_bv_unpin = false;
- iov_iter_advance(iter, orig_count);
- }
+ ret = netfs_extract_iter(iter, rreq->len, INT_MAX,
+ &rreq->dispatch_cursor.bvecq, 0, rreq->gfp);
+ if (ret < 0)
+ goto error_put;
+
+ rreq->len = ret;
// TODO: Set up bounce buffer if needed
diff --git a/fs/netfs/direct_write.c b/fs/netfs/direct_write.c
index 32200c10d2a45..e783405158277 100644
--- a/fs/netfs/direct_write.c
+++ b/fs/netfs/direct_write.c
@@ -73,7 +73,11 @@ static void netfs_unbuffered_write_collect(struct netfs_io_request *wreq,
spin_unlock(&wreq->lock);
wreq->transferred += subreq->transferred;
- iov_iter_advance(&wreq->buffer.iter, subreq->transferred);
+ if (subreq->transferred < subreq->len) {
+ bvecq_pos_unset(&wreq->dispatch_cursor);
+ bvecq_pos_transfer(&wreq->dispatch_cursor, &subreq->io_buffer);
+ bvecq_pos_advance(&wreq->dispatch_cursor, subreq->transferred);
+ }
stream->collected_to = subreq->start + subreq->transferred;
wreq->collected_to = stream->collected_to;
@@ -99,6 +103,8 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
_enter("%llx", wreq->len);
+ bvecq_pos_set(&wreq->collect_cursor, &wreq->dispatch_cursor);
+
if (wreq->origin == NETFS_DIO_WRITE)
inode_dio_begin(wreq->inode);
@@ -116,6 +122,8 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
break;
}
stream->construct = NULL;
+ } else {
+ bvecq_pos_set(&subreq->io_buffer, &wreq->dispatch_cursor);
}
/* Check if (re-)preparation failed. */
@@ -125,9 +133,16 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
break;
}
- iov_iter_truncate(&subreq->io_iter, wreq->len - wreq->transferred);
+ subreq->len = bvecq_slice(&wreq->dispatch_cursor, stream->sreq_max_len,
+ stream->sreq_max_segs, &subreq->nr_segs);
+
+ iov_iter_bvec_queue(&subreq->io_iter, ITER_SOURCE,
+ subreq->io_buffer.bvecq, subreq->io_buffer.slot,
+ subreq->io_buffer.offset,
+ subreq->len);
+
if (!iov_iter_count(&subreq->io_iter)) {
- pr_warn("netfs: Unexpected zero-length iterator R=%08x\n",
+ pr_warn("netfs: Unexpected zero-length slice R=%08x\n",
wreq->debug_id);
__set_bit(NETFS_SREQ_FAILED, &subreq->flags);
netfs_write_subrequest_terminated(subreq, -EIO);
@@ -135,12 +150,6 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
break;
}
- subreq->len = netfs_limit_iter(&subreq->io_iter, 0,
- stream->sreq_max_len,
- stream->sreq_max_segs);
- iov_iter_truncate(&subreq->io_iter, subreq->len);
- stream->submit_extendable_to = subreq->len;
-
trace_netfs_sreq(subreq, netfs_sreq_trace_submit);
stream->issue_write(subreq);
@@ -175,9 +184,13 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
*/
subreq->error = -EAGAIN;
trace_netfs_sreq(subreq, netfs_sreq_trace_retry);
+
+ bvecq_pos_unset(&wreq->dispatch_cursor);
+ bvecq_pos_transfer(&wreq->dispatch_cursor, &subreq->io_buffer);
+
if (subreq->transferred > 0) {
- iov_iter_advance(&wreq->buffer.iter, subreq->transferred);
wreq->transferred += subreq->transferred;
+ bvecq_pos_advance(&wreq->dispatch_cursor, subreq->transferred);
}
if (stream->source == NETFS_UPLOAD_TO_SERVER &&
@@ -188,7 +201,6 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
__clear_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags);
__clear_bit(NETFS_SREQ_BOUNDARY, &subreq->flags);
__clear_bit(NETFS_SREQ_FAILED, &subreq->flags);
- subreq->io_iter = wreq->buffer.iter;
subreq->start = wreq->start + wreq->transferred;
subreq->len = wreq->len - wreq->transferred;
subreq->transferred = 0;
@@ -204,6 +216,7 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
netfs_stat(&netfs_n_wh_retry_write_subreq);
}
+ bvecq_pos_unset(&wreq->dispatch_cursor);
netfs_unbuffered_write_done(wreq);
_leave(" = %d", ret);
return ret;
@@ -222,10 +235,10 @@ static void netfs_unbuffered_write_async(struct work_struct *work)
* encrypted file. This can also be used for direct I/O writes.
*/
ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *iter,
- struct netfs_group *netfs_group)
+ struct netfs_group *netfs_group)
{
struct netfs_io_request *wreq;
- ssize_t ret, n;
+ ssize_t ret;
uoff_t start = iocb->ki_pos;
uoff_t end = start + iov_iter_count(iter);
size_t len = iov_iter_count(iter);
@@ -261,25 +274,17 @@ ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *
* allocate a sufficiently large bvec array and may shorten the
* request.
*/
- if (user_backed_iter(iter)) {
- n = netfs_extract_user_iter(iter, len, &wreq->buffer.iter, 0);
- if (n < 0) {
- ret = n;
- goto error_put;
- }
- wreq->direct_bv = (struct bio_vec *)wreq->buffer.iter.bvec;
- wreq->direct_bv_count = n;
- wreq->direct_bv_unpin = iov_iter_extract_will_pin(iter);
- } else {
- /* If this is a kernel-generated async DIO request,
- * assume that any resources the iterator points to
- * (eg. a bio_vec array) will persist till the end of
- * the op.
- */
- wreq->buffer.iter = *iter;
- }
+ ssize_t n = netfs_extract_iter(iter, len, INT_MAX,
+ &wreq->dispatch_cursor.bvecq, 0, wreq->gfp);
- wreq->len = iov_iter_count(&wreq->buffer.iter);
+ if (n < 0) {
+ ret = n;
+ goto error_put;
+ }
+ wreq->len = n;
+ _debug("dio-write %zx/%zx %u/%u",
+ n, len, wreq->dispatch_cursor.bvecq->nr_slots,
+ wreq->dispatch_cursor.bvecq->max_slots);
}
__set_bit(NETFS_RREQ_USE_IO_ITER, &wreq->flags);
diff --git a/fs/netfs/internal.h b/fs/netfs/internal.h
index 827b8898d309a..3adf75dcc6322 100644
--- a/fs/netfs/internal.h
+++ b/fs/netfs/internal.h
@@ -70,7 +70,6 @@ static inline void netfs_proc_del_rreq(struct netfs_io_request *rreq) {}
/*
* misc.c
*/
-void netfs_reset_iter(struct netfs_io_subrequest *subreq);
void netfs_wake_collector(struct netfs_io_request *rreq);
void netfs_subreq_clear_in_progress(struct netfs_io_subrequest *subreq);
void netfs_wait_for_in_progress_stream(struct netfs_io_request *rreq,
@@ -237,8 +236,7 @@ void netfs_prepare_write(struct netfs_io_request *wreq,
struct netfs_io_stream *stream,
uoff_t start);
void netfs_reissue_write(struct netfs_io_stream *stream,
- struct netfs_io_subrequest *subreq,
- struct iov_iter *source);
+ struct netfs_io_subrequest *subreq);
void netfs_issue_write(struct netfs_io_request *wreq,
struct netfs_io_stream *stream);
size_t netfs_advance_write(struct netfs_io_request *wreq,
diff --git a/fs/netfs/iterator.c b/fs/netfs/iterator.c
index 31748526d5682..dc97e5b0d4495 100644
--- a/fs/netfs/iterator.c
+++ b/fs/netfs/iterator.c
@@ -14,296 +14,144 @@
#include "internal.h"
/**
- * netfs_extract_user_iter - Extract the pages from a user iterator into a bvec
+ * netfs_extract_iter - Extract virtually contiguous pages from an iterator into a bvecq
* @orig: The original iterator
- * @orig_len: The amount of iterator to copy
- * @new: The iterator to be set up
+ * @max_len: Maximum number of bytes to extract
+ * @max_pages: Maximum number of pages to extract
+ * @_bvecq_head: Where to cache the bvec queue
* @extraction_flags: Flags to qualify the request
+ * @gfp: Allocation mode for bvecq structs.
*
- * Extract the page fragments from the given amount of the source iterator and
- * build up a second iterator that refers to all of those bits. This allows
- * the original iterator to be disposed of.
+ * Extract virtually contiguous page fragments from the source iterator up to
+ * the given maxima and build bvec queue that refers to all of those bits.
+ * This allows the original iterator to disposed of.
*
- * @extraction_flags can have ITER_ALLOW_P2PDMA set to request peer-to-peer DMA be
- * allowed on the pages extracted.
+ * @extraction_flags can have ITER_ALLOW_P2PDMA set to request peer-to-peer DMA
+ * be allowed on the pages extracted.
*
- * On success, the number of elements in the bvec is returned, the original
- * iterator will have been advanced by the amount extracted.
+ * On success or partial success, the amount of data in the bvec is returned,
+ * the original iterator will have been advanced by the amount extracted.
*
- * The iov_iter_extract_mode() function should be used to query how cleanup
- * should be performed.
+ * If an error occurs and no pages are extracted, an error will be returned and
+ * any allocated bvecq will be freed. If there is no data to be extracted (or
+ * @max_len or @max_pages are zero), a single empty bvecq will be returned.
+ *
+ * The bvecq segments are marked with indications on how to get clean up the
+ * extracted fragments.
*/
-ssize_t netfs_extract_user_iter(struct iov_iter *orig, size_t orig_len,
- struct iov_iter *new,
- iov_iter_extraction_t extraction_flags)
+ssize_t netfs_extract_iter(struct iov_iter *orig, size_t max_len, size_t max_pages,
+ struct bvecq **_bvecq_head,
+ iov_iter_extraction_t extraction_flags, gfp_t gfp)
{
- struct bio_vec *bv = NULL;
- struct page **pages;
- unsigned int cur_npages;
- unsigned int max_pages;
- unsigned int npages = 0;
- unsigned int i;
+ struct bvecq *bq_tail = NULL, *bq;
ssize_t ret = 0;
- size_t count = orig_len, offset, len;
- size_t bv_size, pg_size;
+ size_t extracted = 0;
- if (WARN_ON_ONCE(!iter_is_ubuf(orig) && !iter_is_iovec(orig)))
- return -EIO;
+ _enter("{%u,%zx},%zx", orig->iter_type, orig->count, max_len);
- max_pages = iov_iter_npages(orig, INT_MAX);
- bv_size = array_size(max_pages, sizeof(*bv));
- bv = kvmalloc(bv_size, GFP_KERNEL);
- if (!bv)
- return -ENOMEM;
+ *_bvecq_head = NULL;
+ if (max_len > orig->count)
+ max_len = orig->count;
+ if (!max_len || !max_pages)
+ goto alloc_empty;
+ if (WARN_ON_ONCE(max_pages > INT_MAX))
+ max_pages = INT_MAX; /* Protect iov_iter_npages(). */
- /* Put the page list at the end of the bvec list storage. bvec
- * elements are larger than page pointers, so as long as we work
- * 0->last, we should be fine.
- */
- pg_size = array_size(max_pages, sizeof(*pages));
- pages = (void *)bv + bv_size - pg_size;
+ max_pages = iov_iter_npages(orig, max_pages);
+ if (!max_pages)
+ goto alloc_empty;
- while (count && npages < max_pages) {
- ret = iov_iter_extract_pages(orig, &pages, count,
- max_pages - npages, extraction_flags,
- &offset);
- if (unlikely(ret <= 0)) {
- ret = ret ?: -EIO;
+ do {
+ bq = bvecq_alloc_one(max_pages, gfp, false);
+ if (!bq) {
+ ret = -ENOMEM;
break;
}
+ if (user_backed_iter(orig))
+ bq->mem_type = iov_iter_extract_will_pin(orig) ?
+ BVECQ_MEM_GUP : BVECQ_MEM_PAGECACHE;
- if (WARN(ret > count,
- "%s: extract_pages overrun %zd > %zu bytes\n",
- __func__, ret, count)) {
- ret = -EIO;
- break;
- }
+ if (bq_tail)
+ bvecq_append(bq_tail, bq);
+ else
+ *_bvecq_head = bq;
+ bq_tail = bq;
- cur_npages = DIV_ROUND_UP(offset + ret, PAGE_SIZE);
- if (WARN(cur_npages > max_pages - npages,
- "%s: extract_pages overrun %u > %u pages\n",
- __func__, npages + cur_npages, max_pages)) {
- ret = -EIO;
+ if (max_len == 0)
break;
- }
-
- count -= ret;
- ret += offset;
-
- for (i = 0; i < cur_npages; i++) {
- len = ret > PAGE_SIZE ? PAGE_SIZE : ret;
- bvec_set_page(bv + npages + i, *pages++, len - offset, offset);
- ret -= len;
- offset = 0;
- }
-
- npages += cur_npages;
- }
-
- /* Note: Don't try to clean up after EIO. Either we got no pages, so
- * nothing to clean up, or we got a buffer overrun, memory corruption
- * and can't trust the stuff in the buffer (a WARN was emitted).
- */
-
- if (ret < 0 && (ret == -ENOMEM || npages == 0)) {
- for (i = 0; i < npages; i++)
- unpin_user_page(bv[i].bv_page);
- kvfree(bv);
- return ret;
- }
- iov_iter_bvec(new, orig->data_source, bv, npages, orig_len - count);
- return npages;
-}
-EXPORT_SYMBOL_GPL(netfs_extract_user_iter);
-
-/*
- * Select the span of a bvec iterator we're going to use. Limit it by both maximum
- * size and maximum number of segments. Returns the size of the span in bytes.
- */
-static size_t netfs_limit_bvec(const struct iov_iter *iter, size_t start_offset,
- size_t max_size, size_t max_segs)
-{
- const struct bio_vec *bvecs = iter->bvec;
- unsigned int nbv = iter->nr_segs, ix = 0, nsegs = 0;
- size_t len, span = 0, n = iter->count;
- size_t skip = iter->iov_offset + start_offset;
-
- if (WARN_ON(!iov_iter_is_bvec(iter)) ||
- WARN_ON(start_offset > n) ||
- n == 0)
- return 0;
-
- while (n && ix < nbv && skip) {
- len = bvecs[ix].bv_len;
- if (skip < len)
- break;
- skip -= len;
- n -= len;
- ix++;
- }
-
- while (n && ix < nbv) {
- len = min3(n, bvecs[ix].bv_len - skip, max_size);
- span += len;
- nsegs++;
- ix++;
- if (span >= max_size || nsegs >= max_segs)
- break;
- skip = 0;
- n -= len;
- }
-
- return min(span, max_size);
-}
-
-/*
- * Select the span of a kvec iterator we're going to use. Limit it by both
- * maximum size and maximum number of segments. Returns the size of the span
- * in bytes.
- */
-static size_t netfs_limit_kvec(const struct iov_iter *iter, size_t start_offset,
- size_t max_size, size_t max_segs)
-{
- const struct kvec *kvecs = iter->kvec;
- unsigned int nkv = iter->nr_segs, ix = 0, nsegs = 0;
- size_t len, span = 0, n = iter->count;
- size_t skip = iter->iov_offset + start_offset;
-
- if (WARN_ON(!iov_iter_is_kvec(iter)) ||
- WARN_ON(start_offset > n) ||
- n == 0)
- return 0;
-
- while (n && ix < nkv && skip) {
- len = kvecs[ix].iov_len;
- if (skip < len)
- break;
- skip -= len;
- n -= len;
- ix++;
- }
-
- while (n && ix < nkv) {
- len = min3(n, kvecs[ix].iov_len - skip, max_size);
- span += len;
- nsegs++;
- ix++;
- if (span >= max_size || nsegs >= max_segs)
- break;
- skip = 0;
- n -= len;
- }
-
- return min(span, max_size);
-}
-
-/*
- * Select the span of an xarray iterator we're going to use. Limit it by both
- * maximum size and maximum number of segments. It is assumed that segments
- * can be larger than a page in size, provided they're physically contiguous.
- * Returns the size of the span in bytes.
- */
-static size_t netfs_limit_xarray(const struct iov_iter *iter, size_t start_offset,
- size_t max_size, size_t max_segs)
-{
- struct folio *folio;
- unsigned int nsegs = 0;
- uoff_t pos = iter->xarray_start + iter->iov_offset;
- pgoff_t index = pos / PAGE_SIZE;
- size_t span = 0, n = iter->count;
-
- XA_STATE(xas, iter->xarray, index);
-
- if (WARN_ON(!iov_iter_is_xarray(iter)) ||
- WARN_ON(start_offset > n) ||
- n == 0)
- return 0;
- max_size = min(max_size, n - start_offset);
-
- rcu_read_lock();
- xas_for_each(&xas, folio, ULONG_MAX) {
- size_t offset, flen, len;
- if (xas_retry(&xas, folio))
- continue;
- if (WARN_ON(xa_is_value(folio)))
- break;
- if (WARN_ON(folio_test_hugetlb(folio)))
- break;
-
- flen = folio_size(folio);
- offset = offset_in_folio(folio, pos);
- len = min(max_size, flen - offset);
- span += len;
- nsegs++;
- if (span >= max_size || nsegs >= max_segs)
- break;
- }
-
- rcu_read_unlock();
- return min(span, max_size);
-}
-
-/*
- * Select the span of a bvecq iterator we're going to use. Limit it by both
- * maximum size and maximum number of segments. Returns the size of the span
- * in bytes.
- */
-static size_t netfs_limit_bvecq(const struct iov_iter *iter, size_t start_offset,
- size_t max_size, size_t max_segs)
-{
- const struct bvecq *bq = iter->bvecq;
- unsigned int nsegs = 0;
- unsigned int slot = iter->bvecq_slot;
- size_t span = 0, n = iter->count;
-
- if (WARN_ON(!iov_iter_is_bvecq(iter)) ||
- WARN_ON(start_offset > n) ||
- n == 0)
- return 0;
- max_size = umin(max_size, n - start_offset);
-
- if (!bvecq_acquire_slot(bq, slot)) {
- bq = bvecq_next(bq);
- slot = 0;
- }
-
- start_offset += iter->iov_offset;
- do {
- size_t flen;
-
- flen = bq->bv[slot].bv_len;
- if (start_offset < flen) {
- span += flen - start_offset;
- nsegs++;
- start_offset = 0;
- } else {
- start_offset -= flen;
- }
- if (span >= max_size || nsegs >= max_segs)
- break;
-
- slot++;
- if (!bvecq_acquire_slot(bq, slot)) {
- bq = bvecq_next(bq);
- slot = 0;
- }
- } while (bq);
-
- return umin(span, max_size);
-}
+ struct bio_vec *bv = bq->bv;
+ unsigned int slot = 0;
+ do {
+ struct page **pages;
+ ssize_t got;
+ size_t offset;
+ size_t space = bq->max_slots - slot;
+ size_t bv_size = array_size(bq->max_slots, sizeof(*bv));
+ size_t pg_size = array_size(space, sizeof(*pages));
+
+ /* Put the page list at the end of the bvec list
+ * storage. bvec elements are larger than page
+ * pointers, so as long as we work 0->last, we should
+ * be fine.
+ */
+ pages = (void *)bv + bv_size - pg_size;
+
+ got = iov_iter_extract_pages(orig, &pages, max_len,
+ min(space, max_pages),
+ extraction_flags, &offset);
+ if (got < 0) {
+ ret = got;
+ goto out;
+ }
+
+ if (got == 0) {
+ pr_err("extract_pages gave nothing from %zx, %zx\n",
+ extracted, max_len);
+ ret = -EIO;
+ goto out;
+ }
+
+ if (WARN(got > max_len,
+ "%s: extract_pages overrun %zx > %zx bytes\n",
+ __func__, got, max_len)) {
+ ret = -EIO;
+ goto out;
+ }
+
+ extracted += got;
+ max_len -= got;
+
+ do {
+ size_t len = umin(got, PAGE_SIZE - offset);
+
+ BUG_ON(slot >= bq->max_slots);
+
+ bvec_set_page(&bq->bv[slot], *pages++, len, offset);
+ slot++;
+ max_pages--;
+ got -= len;
+ offset = 0;
+ } while (got > 0);
+
+ bvecq_filled_to(bq, slot);
+ } while (max_len > 0 && max_pages > 0 && !bvecq_is_full(bq));
+
+ } while (max_len > 0 && max_pages > 0);
+
+out:
+ if (extracted || ret == 0)
+ return extracted;
+ bvecq_put(*_bvecq_head);
+ *_bvecq_head = NULL;
+ return ret;
+
+alloc_empty:
+ bq = bvecq_alloc_one(1, gfp, false);
+ if (!bq)
+ return -ENOMEM;
+ *_bvecq_head = bq;
+ return 0;
-size_t netfs_limit_iter(const struct iov_iter *iter, size_t start_offset,
- size_t max_size, size_t max_segs)
-{
- if (iov_iter_is_bvecq(iter))
- return netfs_limit_bvecq(iter, start_offset, max_size, max_segs);
- if (iov_iter_is_bvec(iter))
- return netfs_limit_bvec(iter, start_offset, max_size, max_segs);
- if (iov_iter_is_xarray(iter))
- return netfs_limit_xarray(iter, start_offset, max_size, max_segs);
- if (iov_iter_is_kvec(iter))
- return netfs_limit_kvec(iter, start_offset, max_size, max_segs);
- BUG();
}
-EXPORT_SYMBOL(netfs_limit_iter);
+EXPORT_SYMBOL_GPL(netfs_extract_iter);
diff --git a/fs/netfs/misc.c b/fs/netfs/misc.c
index 40e0ff6491329..4fa09560fb4b9 100644
--- a/fs/netfs/misc.c
+++ b/fs/netfs/misc.c
@@ -8,24 +8,6 @@
#include <linux/swap.h>
#include "internal.h"
-/*
- * Reset the subrequest iterator to refer just to the region remaining to be
- * read. The iterator may or may not have been advanced by socket ops or
- * extraction ops to an extent that may or may not match the amount actually
- * read.
- */
-void netfs_reset_iter(struct netfs_io_subrequest *subreq)
-{
- struct iov_iter *io_iter = &subreq->io_iter;
- size_t remain = subreq->len - subreq->transferred;
-
- if (io_iter->count > remain)
- iov_iter_advance(io_iter, io_iter->count - remain);
- else if (io_iter->count < remain)
- iov_iter_revert(io_iter, remain - io_iter->count);
- iov_iter_truncate(&subreq->io_iter, remain);
-}
-
/**
* netfs_dirty_folio - Mark folio dirty and pin a cache object for writeback
* @mapping: The mapping the folio belongs to.
diff --git a/fs/netfs/objects.c b/fs/netfs/objects.c
index 4b8d20559b0e1..bf17dc31fd9d8 100644
--- a/fs/netfs/objects.c
+++ b/fs/netfs/objects.c
@@ -133,7 +133,6 @@ static void netfs_free_request_rcu(struct rcu_head *rcu)
static void netfs_deinit_request(struct netfs_io_request *rreq)
{
struct netfs_inode *ictx = netfs_inode(rreq->inode);
- unsigned int i;
trace_netfs_rreq(rreq, netfs_rreq_trace_free);
@@ -148,16 +147,10 @@ static void netfs_deinit_request(struct netfs_io_request *rreq)
rreq->netfs_ops->free_request(rreq);
if (rreq->cache_resources.ops)
rreq->cache_resources.ops->end_operation(&rreq->cache_resources);
- if (rreq->direct_bv) {
- for (i = 0; i < rreq->direct_bv_count; i++) {
- if (rreq->direct_bv[i].bv_page) {
- if (rreq->direct_bv_unpin)
- unpin_user_page(rreq->direct_bv[i].bv_page);
- }
- }
- kvfree(rreq->direct_bv);
- }
- rolling_buffer_clear(&rreq->buffer);
+ bvecq_pos_unset(&rreq->load_cursor);
+ bvecq_pos_unset(&rreq->dispatch_cursor);
+ bvecq_pos_unset(&rreq->collect_cursor);
+ bvecq_put(rreq->spare);
if (atomic_dec_and_test(&ictx->io_count))
wake_up_var(&ictx->io_count);
@@ -251,6 +244,7 @@ static void netfs_free_subrequest(struct netfs_io_subrequest *subreq)
trace_netfs_sreq(subreq, netfs_sreq_trace_free);
if (rreq->netfs_ops->free_subrequest)
rreq->netfs_ops->free_subrequest(subreq);
+ bvecq_pos_unset(&subreq->io_buffer);
mempool_free(subreq, rreq->netfs_ops->subrequest_pool ?: &netfs_subrequest_pool);
netfs_stat_d(&netfs_n_rh_sreq);
netfs_put_request(rreq, netfs_rreq_trace_put_subreq);
diff --git a/fs/netfs/read_collect.c b/fs/netfs/read_collect.c
index 961b76e37a021..ff3a30b79e063 100644
--- a/fs/netfs/read_collect.c
+++ b/fs/netfs/read_collect.c
@@ -26,9 +26,13 @@
*/
static void netfs_clear_unread(struct netfs_io_subrequest *subreq)
{
- netfs_reset_iter(subreq);
- WARN_ON_ONCE(subreq->len - subreq->transferred != iov_iter_count(&subreq->io_iter));
- iov_iter_zero(iov_iter_count(&subreq->io_iter), &subreq->io_iter);
+ struct iov_iter iter;
+
+ iov_iter_bvec_queue(&iter, ITER_DEST, subreq->io_buffer.bvecq,
+ subreq->io_buffer.slot, subreq->io_buffer.offset, subreq->len);
+ iov_iter_advance(&iter, subreq->transferred);
+ iov_iter_zero(subreq->len, &iter);
+
if (subreq->start + subreq->transferred >= subreq->rreq->i_size)
__set_bit(NETFS_SREQ_HIT_EOF, &subreq->flags);
}
@@ -122,8 +126,8 @@ static void netfs_unlock_read_folio(struct netfs_io_request *rreq,
*/
void netfs_read_set_unlock_at(struct netfs_io_request *rreq)
{
- const struct bvecq *bq = rreq->buffer.tail;
- unsigned int slot = rreq->buffer.first_tail_slot;
+ const struct bvecq *bq = rreq->collect_cursor.bvecq;
+ unsigned int slot = rreq->collect_cursor.slot;
size_t cleaned_to = rreq->cleaned_to - rreq->start;
size_t progress_at = cleaned_to;
size_t minimum = 256 * 1024;
@@ -153,8 +157,8 @@ void netfs_read_set_unlock_at(struct netfs_io_request *rreq)
static void netfs_read_unlock_folios(struct netfs_io_request *rreq,
unsigned int *notes)
{
- struct bvecq *bq = rreq->buffer.tail;
- unsigned int slot = rreq->buffer.first_tail_slot;
+ struct bvecq *bq = rreq->collect_cursor.bvecq;
+ unsigned int slot = rreq->collect_cursor.slot;
uoff_t collected_to = rreq->collected_to;
if (rreq->cleaned_to >= rreq->collected_to)
@@ -162,15 +166,6 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,
// TODO: Begin decryption
- while (!bvecq_acquire_slot(bq, slot)) {
- bq = rolling_buffer_delete_spent(&rreq->buffer);
- if (!bq) {
- WRITE_ONCE(rreq->progress_at, rreq->len);
- return;
- }
- slot = 0;
- }
-
/* We have to wait for readahead refs to have been released before we
* can unlock any folios as the ref-dropper walks i_pages and the only
* thing preventing these folios from being removed is the folio lock.
@@ -180,9 +175,24 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,
for (;;) {
struct folio *folio;
- uoff_t fpos, fend;
+ uoff_t fpos = rreq->cleaned_to, fend;
size_t fsize;
+ /* Clean up the head bvecq segment. If we clear an entire
+ * segment, then we can get rid of it provided it's not also
+ * the tail segment being filled by the issuer.
+ */
+ if (!bvecq_acquire_slot(bq, slot)) {
+ rreq->collect_cursor.slot = slot;
+ if (!bvecq_delete_spent(&rreq->collect_cursor)) {
+ WRITE_ONCE(rreq->progress_at, rreq->len);
+ return;
+ }
+ bq = rreq->collect_cursor.bvecq;
+ slot = rreq->collect_cursor.slot;
+ continue;
+ }
+
folio = bvec_folio(&bq->bv[slot]);
if (WARN_ONCE(!folio_test_locked(folio),
"R=%08x: folio %lx is not locked\n",
@@ -190,7 +200,6 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,
trace_netfs_folio(folio, netfs_folio_trace_not_locked);
fsize = bq->bv[slot].bv_len;
- fpos = folio_pos(folio);
fend = fpos + fsize;
trace_netfs_collect_folio(rreq, folio);
@@ -200,30 +209,16 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,
break;
netfs_unlock_read_folio(rreq, bq, slot);
- WRITE_ONCE(rreq->cleaned_to, fpos + fsize);
- *notes |= MADE_PROGRESS;
-
- /* Clean up the head bq. If we clear an entire bq, then
- * we can get rid of it provided it's not also the tail bq
- * being filled by the issuer.
- */
- bq->bv[slot].bv_page = NULL;
slot++;
- while (!bvecq_acquire_slot(bq, slot)) {
- bq = rolling_buffer_delete_spent(&rreq->buffer);
- if (!bq)
- goto done;
- slot = 0;
- }
+ WRITE_ONCE(rreq->cleaned_to, fend);
+ *notes |= MADE_PROGRESS;
if (fpos + fsize >= collected_to)
break;
}
- rreq->buffer.tail = bq;
-done:
- rreq->buffer.first_tail_slot = slot;
-
+ bvecq_pos_move(&rreq->collect_cursor, bq);
+ rreq->collect_cursor.slot = slot;
netfs_read_set_unlock_at(rreq);
}
@@ -398,12 +393,15 @@ static void netfs_rreq_assess_dio(struct netfs_io_request *rreq)
if (rreq->origin == NETFS_UNBUFFERED_READ ||
rreq->origin == NETFS_DIO_READ) {
- for (i = 0; i < rreq->direct_bv_count; i++) {
- flush_dcache_page(rreq->direct_bv[i].bv_page);
- // TODO: cifs marks pages in the destination buffer
- // dirty under some circumstances after a read. Do we
- // need to do that too?
- set_page_dirty(rreq->direct_bv[i].bv_page);
+ for (struct bvecq *bq = rreq->collect_cursor.bvecq; bq; bq = bvecq_next(bq)) {
+ unsigned int nr_slots = bvecq_nr_slots_acquire(bq);
+ /* Read the slot count before the slots. */
+
+ /* Mark the target buffers dirty. */
+ for (i = 0; i < nr_slots; i++) {
+ flush_dcache_page(bq->bv[i].bv_page);
+ set_page_dirty(bq->bv[i].bv_page);
+ }
}
}
@@ -497,7 +495,15 @@ bool netfs_read_collection(struct netfs_io_request *rreq)
trace_netfs_rreq(rreq, netfs_rreq_trace_done);
netfs_clear_subrequests(rreq);
- netfs_unlock_abandoned_read_pages(rreq);
+ switch (rreq->origin) {
+ case NETFS_READAHEAD:
+ case NETFS_READPAGE:
+ case NETFS_READ_FOR_WRITE:
+ netfs_unlock_abandoned_read_pages(rreq);
+ break;
+ default:
+ break;
+ }
if (unlikely(rreq->copy_to_cache))
netfs_pgpriv2_end_copy_to_cache(rreq);
return true;
diff --git a/fs/netfs/read_pgpriv2.c b/fs/netfs/read_pgpriv2.c
index f8e5667e278e1..f23c4cbfed581 100644
--- a/fs/netfs/read_pgpriv2.c
+++ b/fs/netfs/read_pgpriv2.c
@@ -19,6 +19,9 @@
static void netfs_pgpriv2_copy_folio(struct netfs_io_request *creq, struct folio *folio)
{
struct netfs_io_stream *cache = &creq->io_streams[1];
+ struct bvecq *queue;
+ unsigned int slot;
+ size_t dio_size = PAGE_SIZE;
size_t fsize = folio_size(folio), flen = fsize;
uoff_t fpos = folio_pos(folio), i_size;
bool to_eof = false;
@@ -48,18 +51,37 @@ static void netfs_pgpriv2_copy_folio(struct netfs_io_request *creq, struct folio
to_eof = true;
}
+ flen = round_up(flen, dio_size);
+
_debug("folio %zx %zx", flen, fsize);
trace_netfs_folio(folio, netfs_folio_trace_store_copy);
- /* Attach the folio to the rolling buffer. */
- if (rolling_buffer_append(&creq->buffer, folio, creq->gfp) < 0) {
- set_bit(NETFS_RREQ_CANCEL_CACHING, &creq->flags);
- folio_end_private_2(folio);
- return;
+ /* Institute a new bvec queue segment if the current one is full or if
+ * we encounter a discontiguity. The discontiguity break is important
+ * when it comes to bulk unlocking folios by file range.
+ */
+ queue = creq->load_cursor.bvecq;
+ if (bvecq_is_full(queue) ||
+ (fpos != creq->last_end && creq->last_end > 0 && queue->nr_slots > 0)) {
+ bvecq_buffer_append(&creq->load_cursor, creq->spare);
+ creq->spare = NULL;
+
+ queue = creq->load_cursor.bvecq;
}
- cache->submit_extendable_to = fsize;
+ /* Attach the folio to the rolling buffer. */
+ slot = queue->nr_slots;
+ bvec_set_folio(&queue->bv[slot], folio, fsize, 0);
+ trace_netfs_bv_slot(queue, slot);
+ slot++;
+ bvecq_filled_to(queue, slot);
+ creq->load_cursor.slot = slot;
+ creq->load_cursor.offset = 0;
+ creq->last_end = fpos + flen;
+
+ bvecq_pos_nudge(&creq->dispatch_cursor);
+
cache->submit_off = 0;
cache->submit_len = flen;
@@ -71,10 +93,9 @@ static void netfs_pgpriv2_copy_folio(struct netfs_io_request *creq, struct folio
do {
ssize_t part;
- creq->buffer.iter.iov_offset = cache->submit_off;
+ creq->dispatch_cursor.offset = cache->submit_off;
atomic64_set(&creq->issued_to, fpos + cache->submit_off);
- cache->submit_extendable_to = fsize - cache->submit_off;
part = netfs_advance_write(creq, cache, fpos + cache->submit_off,
cache->submit_len, to_eof);
cache->submit_off += part;
@@ -84,8 +105,7 @@ static void netfs_pgpriv2_copy_folio(struct netfs_io_request *creq, struct folio
cache->submit_len -= part;
} while (cache->submit_len > 0);
- creq->buffer.iter.iov_offset = 0;
- rolling_buffer_advance(&creq->buffer, fsize);
+ bvecq_pos_step(&creq->dispatch_cursor);
atomic64_set(&creq->issued_to, fpos + fsize);
if (flen < fsize)
@@ -111,6 +131,11 @@ static struct netfs_io_request *netfs_pgpriv2_begin_copy_to_cache(
if (!creq->io_streams[1].avail)
goto cancel_put;
+ if (bvecq_buffer_init(&creq->load_cursor, creq->gfp, false) < 0)
+ goto cancel_put;
+ bvecq_pos_set(&creq->dispatch_cursor, &creq->load_cursor);
+ bvecq_pos_set(&creq->collect_cursor, &creq->dispatch_cursor);
+
__set_bit(NETFS_RREQ_OFFLOAD_COLLECTION, &creq->flags);
trace_netfs_copy2cache(rreq, creq);
trace_netfs_write(creq, netfs_write_trace_copy_to_cache);
@@ -143,6 +168,14 @@ void netfs_pgpriv2_copy_to_cache(struct netfs_io_request *rreq, struct folio *fo
return;
}
+ if (!creq->spare) {
+ creq->spare = bvecq_alloc_one(BVECQ_POOL_SLOTS, creq->gfp, false);
+ if (!creq->spare) {
+ set_bit(NETFS_RREQ_CANCEL_CACHING, &creq->flags);
+ return;
+ }
+ }
+
trace_netfs_folio(folio, netfs_folio_trace_pgpriv2_copy);
netfs_pgpriv2_copy_folio(creq, folio);
}
@@ -173,16 +206,18 @@ void netfs_pgpriv2_end_copy_to_cache(struct netfs_io_request *rreq)
*/
bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *creq)
{
- struct bvecq *bq = creq->buffer.tail;
- unsigned int slot = creq->buffer.first_tail_slot;
+ struct bvecq *bq = creq->collect_cursor.bvecq;
+ unsigned int slot;
uoff_t collected_to = creq->collected_to;
bool made_progress = false;
+ slot = creq->collect_cursor.slot;
while (!bvecq_acquire_slot(bq, slot)) {
- bq = rolling_buffer_delete_spent(&creq->buffer);
- if (!bq)
- return false;
- slot = 0;
+ creq->collect_cursor.slot = slot;
+ if (!bvecq_delete_spent(&creq->collect_cursor))
+ goto out;
+ bq = creq->collect_cursor.bvecq;
+ slot = creq->collect_cursor.slot;
}
for (;;) {
@@ -213,25 +248,25 @@ bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *creq)
creq->cleaned_to = fpos + fsize;
made_progress = true;
- /* Clean up the head bq. If we clear an entire bq, then
- * we can get rid of it provided it's not also the tail bq
- * being filled by the issuer.
+ /* Clean up the head segment. If we clear an entire segment,
+ * then we can get rid of it provided it's not also the tail
+ * segment being filled by the issuer.
*/
bq->bv[slot].bv_page = NULL;
slot++;
while (!bvecq_acquire_slot(bq, slot)) {
- bq = rolling_buffer_delete_spent(&creq->buffer);
- if (!bq)
- goto done;
- slot = 0;
+ creq->collect_cursor.slot = slot;
+ if (!bvecq_delete_spent(&creq->collect_cursor))
+ goto out;
+ bq = creq->collect_cursor.bvecq;
+ slot = creq->collect_cursor.slot;
}
if (fpos + fsize >= collected_to)
break;
}
- creq->buffer.tail = bq;
-done:
- creq->buffer.first_tail_slot = slot;
+ creq->collect_cursor.slot = slot;
+out:
return made_progress;
}
diff --git a/fs/netfs/read_retry.c b/fs/netfs/read_retry.c
index 142c3fb8dab17..7490b9ee1bf7c 100644
--- a/fs/netfs/read_retry.c
+++ b/fs/netfs/read_retry.c
@@ -12,6 +12,10 @@
static void netfs_reissue_read(struct netfs_io_request *rreq,
struct netfs_io_subrequest *subreq)
{
+ iov_iter_bvec_queue(&subreq->io_iter, ITER_DEST, subreq->io_buffer.bvecq,
+ subreq->io_buffer.slot, subreq->io_buffer.offset, subreq->len);
+ iov_iter_advance(&subreq->io_iter, subreq->transferred);
+
subreq->error = 0;
__clear_bit(NETFS_SREQ_MADE_PROGRESS, &subreq->flags);
__set_bit(NETFS_SREQ_IN_PROGRESS, &subreq->flags);
@@ -27,6 +31,7 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
{
struct netfs_io_subrequest *subreq;
struct netfs_io_stream *stream = &rreq->io_streams[0];
+ struct bvecq_pos dispatch_cursor = {};
struct list_head *next;
_enter("R=%x", rreq->debug_id);
@@ -46,9 +51,7 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
if (test_bit(NETFS_SREQ_FAILED, &subreq->flags))
break;
if (__test_and_clear_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags)) {
- __clear_bit(NETFS_SREQ_MADE_PROGRESS, &subreq->flags);
subreq->retry_count++;
- netfs_reset_iter(subreq);
netfs_get_subrequest(subreq, netfs_sreq_trace_get_resubmit);
netfs_reissue_read(rreq, subreq);
}
@@ -74,11 +77,12 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
do {
struct netfs_io_subrequest *from, *to, *tmp;
- struct iov_iter source;
uoff_t start, len;
size_t part;
bool boundary = false, subreq_superfluous = false;
+ bvecq_pos_unset(&dispatch_cursor);
+
/* Go through the subreqs and find the next span of contiguous
* buffer that we then rejig (cifs, for example, needs the
* rsize renegotiating) and reissue.
@@ -105,7 +109,8 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
break;
subreq = list_entry(next, struct netfs_io_subrequest, rreq_link);
- if (subreq->start + subreq->transferred != start + len ||
+ if (subreq->start != start + len ||
+ subreq->transferred > 0 ||
test_bit(NETFS_SREQ_BOUNDARY, &subreq->flags) ||
!test_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags))
break;
@@ -118,11 +123,14 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
/* Determine the set of buffers we're going to use. Each
* subreq gets a subset of a single overall contiguous buffer.
*/
- netfs_reset_iter(from);
- source = from->io_iter;
- source.count = len;
+ bvecq_pos_transfer(&dispatch_cursor, &from->io_buffer);
+ bvecq_pos_advance(&dispatch_cursor, from->transferred);
+ from->transferred = 0;
- /* Work through the sublist. */
+ /* Work through the sublist. The chain of buffers we're going
+ * to fill is attached to dispatch_cursor and we need to read
+ * 'len' amount of data from 'start'.
+ */
subreq = from;
list_for_each_entry_from(subreq, &stream->subrequests, rreq_link) {
if (!len) {
@@ -130,16 +138,21 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
break;
}
subreq->source = NETFS_DOWNLOAD_FROM_SERVER;
- subreq->start = start - subreq->transferred;
- subreq->len = len + subreq->transferred;
+ subreq->start = start;
+ subreq->len = len;
__clear_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags);
__clear_bit(NETFS_SREQ_MADE_PROGRESS, &subreq->flags);
subreq->retry_count++;
+ subreq->transferred = 0;
+
+ bvecq_pos_unset(&subreq->io_buffer);
+ bvecq_pos_set(&subreq->io_buffer, &dispatch_cursor);
trace_netfs_sreq(subreq, netfs_sreq_trace_retry);
/* Renegotiate max_len (rsize) */
- stream->sreq_max_len = subreq->len;
+ stream->sreq_max_len = len;
+ stream->sreq_max_segs = INT_MAX;
if (rreq->netfs_ops->prepare_read &&
rreq->netfs_ops->prepare_read(subreq) < 0) {
trace_netfs_sreq(subreq, netfs_sreq_trace_reprep_failed);
@@ -147,13 +160,12 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
goto abandon;
}
- part = umin(len, stream->sreq_max_len);
- if (unlikely(stream->sreq_max_segs))
- part = netfs_limit_iter(&source, 0, part, stream->sreq_max_segs);
- subreq->len = subreq->transferred + part;
- subreq->io_iter = source;
- iov_iter_truncate(&subreq->io_iter, part);
- iov_iter_advance(&source, part);
+ part = bvecq_slice(&dispatch_cursor,
+ umin(len, stream->sreq_max_len),
+ stream->sreq_max_segs,
+ &subreq->nr_segs);
+ subreq->len = part;
+
len -= part;
start += part;
if (!len) {
@@ -216,9 +228,7 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
trace_netfs_sreq(subreq, netfs_sreq_trace_retry);
stream->sreq_max_len = umin(len, rreq->rsize);
- stream->sreq_max_segs = 0;
- if (unlikely(stream->sreq_max_segs))
- part = netfs_limit_iter(&source, 0, part, stream->sreq_max_segs);
+ stream->sreq_max_segs = INT_MAX;
netfs_stat(&netfs_n_rh_download);
if (rreq->netfs_ops->prepare_read(subreq) < 0) {
@@ -227,11 +237,12 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
goto abandon;
}
- part = umin(len, stream->sreq_max_len);
- subreq->len = subreq->transferred + part;
- subreq->io_iter = source;
- iov_iter_truncate(&subreq->io_iter, part);
- iov_iter_advance(&source, part);
+ bvecq_pos_set(&subreq->io_buffer, &dispatch_cursor);
+ part = bvecq_slice(&dispatch_cursor,
+ umin(len, stream->sreq_max_len),
+ stream->sreq_max_segs,
+ &subreq->nr_segs);
+ subreq->len = part;
len -= part;
start += part;
@@ -245,12 +256,14 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
} while (!list_is_head(next, &stream->subrequests));
+out:
+ bvecq_pos_unset(&dispatch_cursor);
return;
/* If we hit an error, fail all remaining incomplete subrequests */
abandon_after:
if (list_is_last(&subreq->rreq_link, &stream->subrequests))
- return;
+ goto out;
subreq = list_next_entry(subreq, rreq_link);
abandon:
list_for_each_entry_from(subreq, &stream->subrequests, rreq_link) {
@@ -261,6 +274,7 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
__set_bit(NETFS_SREQ_FAILED, &subreq->flags);
__clear_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags);
}
+ goto out;
}
/*
@@ -300,26 +314,24 @@ void netfs_unlock_abandoned_read_pages(struct netfs_io_request *rreq)
if (test_bit(NETFS_RREQ_NEED_PUT_RA_REFS, &rreq->flags))
netfs_wait_for_put_ra_refs(rreq);
- for (p = rreq->buffer.tail; p; p = p->next) {
- for (int slot = rreq->buffer.first_tail_slot;
- bvecq_acquire_slot(p, slot);
- slot++) {
- struct folio *folio;
+ for (p = rreq->collect_cursor.bvecq; p; p = bvecq_next(p)) {
+ unsigned int nr_slots = bvecq_nr_slots_acquire(p);
+ for (int slot = 0; slot < nr_slots; slot++) {
if (!p->bv[slot].bv_page)
continue;
- folio = bvec_folio(&p->bv[slot]);
+ struct folio *folio = bvec_folio(&p->bv[slot]);
+
netfs_cancel_copy_to_cache(rreq, folio);
if (folio == rreq->no_unlock_folio &&
test_bit(NETFS_RREQ_NO_UNLOCK_FOLIO, &rreq->flags)) {
_debug("no unlock");
- } else {
- trace_netfs_folio(folio, netfs_folio_trace_abandon);
- folio_unlock(folio);
+ continue;
}
+ trace_netfs_folio(folio, netfs_folio_trace_abandon);
+ folio_unlock(folio);
}
- rreq->buffer.first_tail_slot = 0;
}
}
diff --git a/fs/netfs/read_single.c b/fs/netfs/read_single.c
index b248e34bd0c86..c70941121de04 100644
--- a/fs/netfs/read_single.c
+++ b/fs/netfs/read_single.c
@@ -101,7 +101,11 @@ static int netfs_single_dispatch_read(struct netfs_io_request *rreq)
subreq->start = 0;
subreq->len = rreq->len;
- subreq->io_iter = rreq->buffer.iter;
+
+ bvecq_pos_set(&subreq->io_buffer, &rreq->dispatch_cursor);
+
+ iov_iter_bvec_queue(&subreq->io_iter, ITER_DEST, subreq->io_buffer.bvecq,
+ subreq->io_buffer.slot, subreq->io_buffer.offset, subreq->len);
netfs_queue_read(rreq, subreq);
@@ -174,6 +178,15 @@ ssize_t netfs_read_single(struct inode *inode, struct file *file, struct iov_ite
if (IS_ERR(rreq))
return PTR_ERR(rreq);
+ ret = netfs_extract_iter(iter, rreq->len, INT_MAX, &rreq->dispatch_cursor.bvecq,
+ 0, rreq->gfp);
+ if (ret < 0)
+ goto cleanup_free;
+ if (ret < rreq->len) {
+ ret = -EIO;
+ goto cleanup_free;
+ }
+
rreq->progress_at = rreq->len;
ret = netfs_single_begin_cache_read(rreq, ictx);
@@ -183,7 +196,6 @@ ssize_t netfs_read_single(struct inode *inode, struct file *file, struct iov_ite
netfs_stat(&netfs_n_rh_read_single);
trace_netfs_read(rreq, 0, rreq->len, netfs_read_trace_read_single);
- rreq->buffer.iter = *iter;
netfs_single_dispatch_read(rreq);
ret = netfs_wait_for_read(rreq);
diff --git a/fs/netfs/rolling_buffer.c b/fs/netfs/rolling_buffer.c
deleted file mode 100644
index 66ce9add40122..0000000000000
--- a/fs/netfs/rolling_buffer.c
+++ /dev/null
@@ -1,182 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/* Rolling buffer helpers
- *
- * Copyright (C) 2024 Red Hat, Inc. All Rights Reserved.
- * Written by David Howells (dhowells@redhat.com)
- */
-
-#include <linux/bitops.h>
-#include <linux/mempool.h>
-#include <linux/pagemap.h>
-#include <linux/rolling_buffer.h>
-#include <linux/slab.h>
-#include "internal.h"
-
-/*
- * Initialise a rolling buffer. We allocate an empty folio queue struct to so
- * that the pointers can be independently driven by the producer and the
- * consumer.
- */
-int rolling_buffer_init(struct rolling_buffer *roll, unsigned int direction,
- gfp_t gfp, bool for_writeback)
-{
- struct bvecq *bq;
-
- roll->for_writeback = for_writeback;
-
- bq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, for_writeback);
- if (!bq)
- return -ENOMEM;
-
- roll->head = bq;
- roll->tail = bq;
- iov_iter_bvec_queue(&roll->iter, direction, bq, 0, 0, 0);
- return 0;
-}
-
-/*
- * Add another bvecq to a rolling buffer if there's no space left.
- */
-int rolling_buffer_make_space(struct rolling_buffer *roll, gfp_t gfp)
-{
- struct bvecq *bq, *head = roll->head;
-
- if (!bvecq_is_full(head))
- return 0;
-
- bq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, roll->for_writeback);
- if (!bq)
- return -ENOMEM;
-
- roll->head = bq;
- if (bvecq_is_full(head)) {
- /* Make sure we don't leave the master iterator pointing to a
- * block that might get immediately consumed.
- */
- if (roll->iter.bvecq == head &&
- roll->iter.bvecq_slot == head->nr_slots) {
- roll->iter.bvecq = bq;
- roll->iter.bvecq_slot = 0;
- }
- }
-
- /* Make sure the initialisation is stored before the next pointer.
- *
- * [!] NOTE: After we set head->next, the consumer is at liberty to
- * immediately delete the old head.
- */
- bvecq_append(head, bq);
- return 0;
-}
-
-/*
- * Decant the entire list of folios to read into a rolling buffer.
- */
-ssize_t rolling_buffer_bulk_load_from_ra(struct rolling_buffer *roll,
- struct readahead_control *ractl,
- gfp_t gfp)
-{
- struct bvecq *bq;
- size_t loaded = 0;
-
- while (ractl->_nr_pages - ractl->_batch_count > 0) {
- struct page **pages;
- unsigned int nr;
-
- /* Allocate a bvecq to put some folios into and attach it to
- * the rolling buffer.
- */
- bq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, false);
- if (!bq)
- goto nomem_unlock;
- bq->mem_type = BVECQ_MEM_EXTERNAL; /* Folio cleanup handled separately. */
-
- if (!roll->tail)
- roll->tail = bq;
- else
- bvecq_append(roll->head, bq);
- roll->head = bq;
-
- /* Get a bunch of folios and note their sizes. */
- pages = (struct page **)(bq->bv + bq->max_slots);
- pages -= bq->max_slots;
- nr = __readahead_batch(ractl, pages, bq->max_slots);
- if (WARN_ON_ONCE(!nr))
- break;
-
- for (int slot = 0; slot < nr; slot++) {
- struct folio *folio = page_folio(pages[slot]);
- size_t len = folio_size(folio);
-
- bvec_set_folio(&bq->bv[slot], folio, len, 0);
- loaded += len;
- trace_netfs_folio(folio, netfs_folio_trace_read);
- }
-
- bvecq_filled_to(bq, nr);
- }
-
- WRITE_ONCE(roll->iter.count, loaded);
- iov_iter_bvec_queue(&roll->iter, ITER_DEST, roll->tail, 0, 0, loaded);
- return loaded;
-
-nomem_unlock:
- for (bq = roll->tail; bq; bq = bq->next) {
- for (int slot = 0; slot < bq->nr_slots; slot++) {
- struct folio *folio = bvec_folio(&bq->bv[slot]);
-
- folio_unlock(folio);
- folio_put(folio);
- }
- }
- rolling_buffer_clear(roll);
- roll->head = NULL;
- roll->tail = NULL;
- return -ENOMEM;
-}
-
-/*
- * Append a folio to the rolling buffer.
- */
-ssize_t rolling_buffer_append(struct rolling_buffer *roll, struct folio *folio,
- gfp_t gfp)
-{
- ssize_t size = folio_size(folio);
- int slot;
-
- if (rolling_buffer_make_space(roll, gfp) < 0)
- return -ENOMEM;
-
- slot = roll->head->nr_slots;
- bvec_set_folio(&roll->head->bv[slot], folio, size, 0);
- bvecq_filled_to(roll->head, slot + 1);
-
- WRITE_ONCE(roll->iter.count, roll->iter.count + size);
- return size;
-}
-
-/*
- * Delete a spent buffer from a rolling queue and return the next in line. We
- * don't return the last buffer to keep the pointers independent, but return
- * NULL instead.
- */
-struct bvecq *rolling_buffer_delete_spent(struct rolling_buffer *roll)
-{
- struct bvecq *spent = roll->tail, *next = bvecq_next(spent);
-
- if (!next)
- return NULL;
- next->prev = NULL;
- roll->tail = next;
- spent->next = NULL;
- bvecq_put(spent);
- return next;
-}
-
-/*
- * Clear out a rolling queue.
- */
-void rolling_buffer_clear(struct rolling_buffer *roll)
-{
- bvecq_put(roll->tail);
-}
diff --git a/fs/netfs/write_collect.c b/fs/netfs/write_collect.c
index 91b42820c8925..dcacbab254b92 100644
--- a/fs/netfs/write_collect.c
+++ b/fs/netfs/write_collect.c
@@ -114,12 +114,12 @@ int netfs_folio_written_back(struct folio *folio)
static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,
unsigned int *notes)
{
- struct bvecq *bq = wreq->buffer.tail;
- unsigned int slot = wreq->buffer.first_tail_slot;
+ struct bvecq *bq = wreq->collect_cursor.bvecq;
+ unsigned int slot = wreq->collect_cursor.slot;
uoff_t collected_to = wreq->collected_to;
if (WARN_ON_ONCE(!bq)) {
- pr_err("[!] Writeback unlock found empty rolling buffer!\n");
+ pr_err("[!] Writeback unlock found empty buffer!\n");
netfs_dump_request(wreq);
return;
}
@@ -130,19 +130,28 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,
return;
}
- while (!bvecq_acquire_slot(bq, slot)) {
- bq = rolling_buffer_delete_spent(&wreq->buffer);
- if (!bq)
- return;
- slot = 0;
- }
-
for (;;) {
struct folio *folio;
struct netfs_folio *finfo;
uoff_t fpos, fend;
size_t fsize, flen;
+ /* Try to clean up the head of the queue if it appears to be
+ * used up, but we need to be very careful - the cleanup can
+ * catch the dispatcher, which could lead to us having nothing
+ * left in the queue, causing the front and back pointers to
+ * end up on different tracks. To avoid this, we must always
+ * keep at least one segment in the queue.
+ */
+ if (!bvecq_acquire_slot(bq, slot)) {
+ wreq->collect_cursor.slot = slot;
+ if (!bvecq_delete_spent(&wreq->collect_cursor))
+ return;
+ bq = wreq->collect_cursor.bvecq;
+ slot = wreq->collect_cursor.slot;
+ continue;
+ }
+
folio = bvec_folio(&bq->bv[slot]);
if (WARN_ONCE(!folio_test_writeback(folio),
"R=%08x: folio %lx is not under writeback\n",
@@ -166,26 +175,13 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,
wreq->cleaned_to = fpos + fsize;
*notes |= MADE_PROGRESS;
- /* Clean up the head bq. If we clear an entire bq, then
- * we can get rid of it provided it's not also the tail bq
- * being filled by the issuer.
- */
bq->bv[slot].bv_page = NULL;
slot++;
- while (!bvecq_acquire_slot(bq, slot)) {
- bq = rolling_buffer_delete_spent(&wreq->buffer);
- if (!bq)
- goto done;
- slot = 0;
- }
-
if (fpos + fsize >= collected_to)
break;
}
- wreq->buffer.tail = bq;
-done:
- wreq->buffer.first_tail_slot = slot;
+ wreq->collect_cursor.slot = slot;
}
/*
@@ -230,7 +226,8 @@ static void netfs_collect_write_results(struct netfs_io_request *wreq)
trace_netfs_rreq(wreq, netfs_rreq_trace_collect);
reassess_streams:
- issued_to = atomic64_read(&wreq->issued_to);
+ /* Order reading the issued_to point before reading the queue it refers to. */
+ issued_to = atomic64_read_acquire(&wreq->issued_to);
smp_rmb();
collected_to = ULLONG_MAX;
if (wreq->origin == NETFS_WRITEBACK ||
@@ -560,8 +557,12 @@ void netfs_write_subrequest_terminated(void *_op, ssize_t transferred_or_error)
* data is tracked.
*/
netfs_stat(&netfs_n_wh_write_failed);
- if (test_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags))
- break;
+ if (test_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags)) {
+ /* We don't retry failed cache writes. */
+ __clear_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags);
+ if (!subreq->error)
+ subreq->error = -ENOBUFS;
+ }
trace_netfs_failure(wreq, subreq, transferred_or_error, netfs_fail_write);
__set_bit(NETFS_SREQ_CANCELLED, &subreq->flags);
diff --git a/fs/netfs/write_issue.c b/fs/netfs/write_issue.c
index f0f4786666512..8fab5cf00d7b6 100644
--- a/fs/netfs/write_issue.c
+++ b/fs/netfs/write_issue.c
@@ -107,10 +107,6 @@ struct netfs_io_request *netfs_create_write_req(struct address_space *mapping,
ictx = netfs_inode(wreq->inode);
if (is_cacheable)
fscache_begin_write_operation(&wreq->cache_resources, netfs_i_cookie(ictx));
- if (rolling_buffer_init(&wreq->buffer, ITER_SOURCE, wreq->gfp,
- (origin == NETFS_WRITEBACK ||
- origin == NETFS_WRITEBACK_SINGLE)) < 0)
- goto nomem;
wreq->cleaned_to = wreq->start;
if (wreq->cache_resources.dio_size > 1)
@@ -135,9 +131,6 @@ struct netfs_io_request *netfs_create_write_req(struct address_space *mapping,
}
return wreq;
-nomem:
- netfs_put_failed_request(wreq);
- return ERR_PTR(-ENOMEM);
}
/**
@@ -163,22 +156,14 @@ void netfs_prepare_write(struct netfs_io_request *wreq,
uoff_t start)
{
struct netfs_io_subrequest *subreq;
- struct iov_iter *wreq_iter = &wreq->buffer.iter;
-
- /* Make sure we don't point the iterator at a used-up bvecq struct
- * being used as a placeholder to prevent the queue from collapsing.
- * In such a case, extend the queue.
- */
- if (iov_iter_is_bvecq(wreq_iter) &&
- !bvecq_acquire_slot(wreq_iter->bvecq, wreq_iter->bvecq_slot))
- rolling_buffer_make_space(&wreq->buffer, wreq->gfp);
subreq = netfs_alloc_subrequest(wreq, stream->source);
if (!subreq)
return;
subreq->start = start;
subreq->stream_nr = stream->stream_nr;
- subreq->io_iter = *wreq_iter;
+
+ bvecq_pos_set(&subreq->io_buffer, &wreq->dispatch_cursor);
_enter("R=%x[%x]", wreq->debug_id, subreq->debug_index);
@@ -259,15 +244,14 @@ static void netfs_do_issue_write(struct netfs_io_stream *stream,
}
void netfs_reissue_write(struct netfs_io_stream *stream,
- struct netfs_io_subrequest *subreq,
- struct iov_iter *source)
+ struct netfs_io_subrequest *subreq)
{
- size_t size = subreq->len - subreq->transferred;
-
// TODO: Use encrypted buffer
- subreq->io_iter = *source;
- iov_iter_advance(source, size);
- iov_iter_truncate(&subreq->io_iter, size);
+ iov_iter_bvec_queue(&subreq->io_iter, ITER_SOURCE,
+ subreq->io_buffer.bvecq, subreq->io_buffer.slot,
+ subreq->io_buffer.offset,
+ subreq->len);
+ iov_iter_advance(&subreq->io_iter, subreq->transferred);
subreq->retry_count++;
subreq->error = 0;
@@ -285,8 +269,12 @@ void netfs_issue_write(struct netfs_io_request *wreq,
if (!subreq)
return;
+ iov_iter_bvec_queue(&subreq->io_iter, ITER_SOURCE,
+ subreq->io_buffer.bvecq, subreq->io_buffer.slot,
+ subreq->io_buffer.offset,
+ subreq->len);
+
stream->construct = NULL;
- subreq->io_iter.count = subreq->len;
netfs_do_issue_write(stream, subreq);
}
@@ -323,7 +311,6 @@ size_t netfs_advance_write(struct netfs_io_request *wreq,
_debug("part %zx/%zx %zx/%zx", subreq->len, stream->sreq_max_len, part, len);
subreq->len += part;
subreq->nr_segs++;
- stream->submit_extendable_to -= part;
if (subreq->len >= stream->sreq_max_len ||
subreq->nr_segs >= stream->sreq_max_segs ||
@@ -347,7 +334,8 @@ static int netfs_write_folio(struct netfs_io_request *wreq,
struct netfs_io_stream *stream;
struct netfs_group *fgroup; /* TODO: Use this with ceph */
struct netfs_folio *finfo;
- size_t iter_off = 0;
+ struct bvecq *queue = wreq->load_cursor.bvecq;
+ unsigned int slot;
size_t fsize = folio_size(folio), flen = fsize, foff = 0;
uoff_t fpos = folio_pos(folio), i_size;
bool to_eof = false, streamw = false;
@@ -355,12 +343,20 @@ static int netfs_write_folio(struct netfs_io_request *wreq,
_enter("");
- if (rolling_buffer_make_space(&wreq->buffer, wreq->gfp) < 0)
- return -ENOMEM;
+ if (!wreq->spare) {
+ wreq->spare = bvecq_alloc_one(BVECQ_POOL_SLOTS, wreq->gfp, true);
+ if (!wreq->spare)
+ return -ENOMEM;
+ }
- /* netfs_perform_write() may shift i_size around the page or from out
- * of the page to beyond it, but cannot move i_size into or through the
- * page since we have it locked.
+ /* netfs_perform_write() may shift i_size around the folio or from out
+ * of the folio to beyond it, but cannot move i_size into or through
+ * the folio since we have it locked.
+ *
+ * Truncate could in theory move i_size into or before the folio, but
+ * it should take steps to prevent writeback from happening
+ * concurrently and should wait for any in-progress writebacks before
+ * proceeding.
*/
i_size = i_size_read(wreq->inode);
@@ -452,8 +448,29 @@ static int netfs_write_folio(struct netfs_io_request *wreq,
trace_netfs_folio(folio, netfs_folio_trace_store_plus);
}
+ /* Institute a new bvec queue segment if the current one is full or if
+ * we encounter a discontiguity. The discontiguity break is important
+ * when it comes to bulk unlocking folios by file range.
+ */
+ if (bvecq_is_full(queue) ||
+ (fpos != wreq->last_end && wreq->last_end > 0)) {
+ bvecq_buffer_append(&wreq->load_cursor, wreq->spare);
+ wreq->spare = NULL;
+
+ queue = wreq->load_cursor.bvecq;
+ bvecq_pos_move(&wreq->dispatch_cursor, queue);
+ wreq->dispatch_cursor.slot = 0;
+ }
+
/* Attach the folio to the rolling buffer. */
- rolling_buffer_append(&wreq->buffer, folio, wreq->gfp);
+ slot = queue->nr_slots;
+ bvec_set_folio(&queue->bv[slot], folio, fsize, 0);
+ trace_netfs_bv_slot(queue, slot);
+ slot++;
+ bvecq_filled_to(queue, slot);
+ wreq->load_cursor.slot = slot;
+ wreq->load_cursor.offset = 0;
+ wreq->last_end = fpos + fsize;
/* Move the submission point forward to allow for write-streaming data
* not starting at the front of the page. We don't do write-streaming
@@ -462,10 +479,19 @@ static int netfs_write_folio(struct netfs_io_request *wreq,
* Also skip uploading for data that's been read and just needs copying
* to the cache.
*/
+ bvecq_pos_nudge(&wreq->dispatch_cursor);
+
for (int s = 0; s < NR_IO_STREAMS; s++) {
+ size_t soff = foff, slen = flen, alignment = 1;
+
stream = &wreq->io_streams[s];
- stream->submit_off = foff;
- stream->submit_len = flen;
+ if (stream->source == NETFS_WRITE_TO_CACHE)
+ alignment = wreq->cache_resources.dio_size;
+ stream = &wreq->io_streams[s];
+ stream->submit_off = round_down(soff, alignment);
+ slen += foff - stream->submit_off;
+ stream->submit_len = round_up(slen, alignment);
+
if (!stream->avail ||
(stream->source == NETFS_WRITE_TO_CACHE && streamw) ||
(stream->source == NETFS_UPLOAD_TO_SERVER &&
@@ -499,14 +525,10 @@ static int netfs_write_folio(struct netfs_io_request *wreq,
break;
stream = &wreq->io_streams[choose_s];
- /* Advance the iterator(s). */
- if (stream->submit_off > iter_off) {
- rolling_buffer_advance(&wreq->buffer, stream->submit_off - iter_off);
- iter_off = stream->submit_off;
- }
+ /* Advance the cursor. */
+ wreq->dispatch_cursor.offset = stream->submit_off;
atomic64_set(&wreq->issued_to, fpos + stream->submit_off);
- stream->submit_extendable_to = fsize - stream->submit_off;
part = netfs_advance_write(wreq, stream, fpos + stream->submit_off,
stream->submit_len, to_eof);
stream->submit_off += part;
@@ -518,9 +540,9 @@ static int netfs_write_folio(struct netfs_io_request *wreq,
debug = true;
}
- if (fsize > iter_off)
- rolling_buffer_advance(&wreq->buffer, fsize - iter_off);
- atomic64_set(&wreq->issued_to, fpos + fsize);
+ bvecq_pos_step(&wreq->dispatch_cursor);
+ /* Order loading the queue before updating the issue_to point */
+ atomic64_set_release(&wreq->issued_to, fpos + fsize);
if (!debug)
kdebug("R=%x: No submit", wreq->debug_id);
@@ -581,6 +603,11 @@ int netfs_writepages(struct address_space *mapping,
goto couldnt_start;
}
+ if (bvecq_buffer_init(&wreq->load_cursor, wreq->gfp, true) < 0)
+ goto nomem;
+ bvecq_pos_set(&wreq->dispatch_cursor, &wreq->load_cursor);
+ bvecq_pos_set(&wreq->collect_cursor, &wreq->dispatch_cursor);
+
__set_bit(NETFS_RREQ_OFFLOAD_COLLECTION, &wreq->flags);
trace_netfs_write(wreq, netfs_write_trace_writeback);
netfs_stat(&netfs_n_wh_writepages);
@@ -605,12 +632,17 @@ int netfs_writepages(struct address_space *mapping,
} while ((folio = writeback_iter(mapping, wbc, folio, &error)));
netfs_end_issue_write(wreq);
+ bvecq_pos_unset(&wreq->load_cursor);
+ bvecq_pos_unset(&wreq->dispatch_cursor);
netfs_wake_collector(wreq);
netfs_put_request(wreq, netfs_rreq_trace_put_return);
_leave(" = %d", error);
return error;
+nomem:
+ error = -ENOMEM;
+ netfs_put_failed_request(wreq);
couldnt_start:
if (error == -ENOMEM) {
folio_redirty_for_writepage(wbc, folio);
@@ -631,23 +663,28 @@ EXPORT_SYMBOL(netfs_writepages);
* netfs_writeback_single - Write back a monolithic payload
* @mapping: The mapping to write from
* @wbc: Hints from the VM
- * @iter: Data to write.
+ * @iter: Buffer to write from
+ * @len: Amount to write from buffer
*
* Write a monolithic, non-pagecache object back to the server and/or the
- * cache. The caller must explicitly set NETFS_RREQ_UPLOAD_TO_SERVER when
- * initialising the request if it wants the data to be written to the server
- * (for AFS directories and symlinks, this is not possible; things like mkdir,
- * symlink, rmdir and unlink must be used instead).
+ * cache. There's a maximum of one subrequest per stream. The buffer should be
+ * rounded out sufficiently that it can accommodate cache DIO rounding.
+ *
+ * The caller must explicitly set NETFS_RREQ_UPLOAD_TO_SERVER when initialising
+ * the request if it wants the data to be written to the server (for AFS
+ * directories and symlinks, this is not possible; things like mkdir, symlink,
+ * rmdir and unlink must be used instead).
*
* Return: 0 if successful; 1 if skipped due to lock conflict and WB_SYNC_NONE;
* or a negative error code.
*/
int netfs_writeback_single(struct address_space *mapping,
struct writeback_control *wbc,
- struct iov_iter *iter)
+ struct iov_iter *iter, size_t len)
{
struct netfs_io_request *wreq;
struct netfs_inode *ictx = netfs_inode(mapping->host);
+ size_t clen;
int ret;
if (!netfs_wb_begin(ictx, wbc->sync_mode == WB_SYNC_NONE)) {
@@ -661,10 +698,27 @@ int netfs_writeback_single(struct address_space *mapping,
ret = PTR_ERR(wreq);
goto couldnt_start;
}
+ wreq->len = len;
+ clen = len;
+
+ if (wreq->cache_resources.dio_size > 1) {
+ clen = round_up(len, wreq->cache_resources.dio_size);
+ if (clen > iov_iter_count(iter)) {
+ ret = -EIO;
+ goto cleanup_free;
+ }
+ }
- wreq->buffer.iter = *iter;
- wreq->len = iov_iter_count(iter);
- wreq->submitted = wreq->len;
+ ret = netfs_extract_iter(iter, clen, INT_MAX, &wreq->dispatch_cursor.bvecq,
+ 0, wreq->gfp);
+ if (ret < 0)
+ goto cleanup_free;
+ if (ret < clen) {
+ ret = -EIO;
+ goto cleanup_free;
+ }
+
+ bvecq_pos_set(&wreq->collect_cursor, &wreq->dispatch_cursor);
__set_bit(NETFS_RREQ_OFFLOAD_COLLECTION, &wreq->flags);
trace_netfs_write(wreq, netfs_write_trace_writeback_single);
@@ -685,12 +739,14 @@ int netfs_writeback_single(struct address_space *mapping,
subreq = stream->construct;
subreq->len = wreq->len;
+ if (stream->source == NETFS_WRITE_TO_CACHE)
+ subreq->len = clen;
stream->submit_len = subreq->len;
- stream->submit_extendable_to = round_up(wreq->len, PAGE_SIZE);
netfs_issue_write(wreq, stream);
}
+ wreq->submitted = wreq->len;
netfs_all_subreqs_queued(wreq);
netfs_wake_collector(wreq);
@@ -705,6 +761,8 @@ int netfs_writeback_single(struct address_space *mapping,
_leave(" = %d", ret);
return ret;
+cleanup_free:
+ netfs_put_failed_request(wreq);
couldnt_start:
netfs_wb_end(ictx);
_leave(" = %d", ret);
diff --git a/fs/netfs/write_retry.c b/fs/netfs/write_retry.c
index 2f20577563e14..235e75eb10914 100644
--- a/fs/netfs/write_retry.c
+++ b/fs/netfs/write_retry.c
@@ -17,15 +17,17 @@
static void netfs_retry_write_stream(struct netfs_io_request *wreq,
struct netfs_io_stream *stream)
{
+ struct bvecq_pos dispatch_cursor = {};
struct list_head *next;
_enter("R=%x[%x:]", wreq->debug_id, stream->stream_nr);
if (list_empty(&stream->subrequests))
return;
+ if (WARN_ON_ONCE(stream->source != NETFS_UPLOAD_TO_SERVER))
+ return; /* Shouldn't be retrying cache writes. */
- if (stream->source == NETFS_UPLOAD_TO_SERVER &&
- wreq->netfs_ops->retry_request)
+ if (wreq->netfs_ops->retry_request)
wreq->netfs_ops->retry_request(wreq, stream);
if (unlikely(stream->failed))
@@ -39,12 +41,8 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,
if (test_bit(NETFS_SREQ_FAILED, &subreq->flags))
break;
if (__test_and_clear_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags)) {
- struct iov_iter source;
-
- netfs_reset_iter(subreq);
- source = subreq->io_iter;
netfs_get_subrequest(subreq, netfs_sreq_trace_get_resubmit);
- netfs_reissue_write(stream, subreq, &source);
+ netfs_reissue_write(stream, subreq);
}
}
return;
@@ -54,11 +52,12 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,
do {
struct netfs_io_subrequest *subreq = NULL, *from, *to, *tmp;
- struct iov_iter source;
uoff_t start, len;
size_t part;
bool boundary = false;
+ bvecq_pos_unset(&dispatch_cursor);
+
/* Go through the stream and find the next span of contiguous
* data that we then rejig (cifs, for example, needs the wsize
* renegotiating) and reissue.
@@ -70,7 +69,7 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,
if (test_bit(NETFS_SREQ_FAILED, &from->flags) ||
!test_bit(NETFS_SREQ_NEED_RETRY, &from->flags))
- return;
+ goto out;
for (;;) {
/* Read pointer to subreq before reading subreq state. */
@@ -79,7 +78,8 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,
break;
subreq = list_entry(next, struct netfs_io_subrequest, rreq_link);
- if (subreq->start + subreq->transferred != start + len ||
+ if (subreq->start != start + len ||
+ subreq->transferred > 0 ||
test_bit(NETFS_SREQ_BOUNDARY, &subreq->flags) ||
!test_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags))
break;
@@ -90,11 +90,13 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,
/* Determine the set of buffers we're going to use. Each
* subreq gets a subset of a single overall contiguous buffer.
*/
- netfs_reset_iter(from);
- source = from->io_iter;
- source.count = len;
+ bvecq_pos_transfer(&dispatch_cursor, &from->io_buffer);
+ bvecq_pos_advance(&dispatch_cursor, from->transferred);
- /* Work through the sublist. */
+ /* Work through the sublist. The chain of buffers we're going
+ * to fill is attached to dispatch_cursor and we need to read
+ * 'len' amount of data from 'start'.
+ */
subreq = from;
list_for_each_entry_from(subreq, &stream->subrequests, rreq_link) {
if (!len)
@@ -104,16 +106,22 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,
subreq->len = len;
__clear_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags);
trace_netfs_sreq(subreq, netfs_sreq_trace_retry);
+ subreq->transferred = 0;
+
+ bvecq_pos_unset(&subreq->io_buffer);
/* Renegotiate max_len (wsize) */
stream->sreq_max_len = len;
+ stream->sreq_max_segs = INT_MAX;
stream->prepare_write(subreq);
- part = umin(len, stream->sreq_max_len);
- if (unlikely(stream->sreq_max_segs))
- part = netfs_limit_iter(&source, 0, part, stream->sreq_max_segs);
+ bvecq_pos_set(&subreq->io_buffer, &dispatch_cursor);
+ part = bvecq_slice(&dispatch_cursor,
+ umin(len, stream->sreq_max_len),
+ stream->sreq_max_segs,
+ &subreq->nr_segs);
subreq->len = part;
- subreq->transferred = 0;
+
len -= part;
start += part;
if (len && subreq == to &&
@@ -121,7 +129,7 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,
boundary = true;
netfs_get_subrequest(subreq, netfs_sreq_trace_get_resubmit);
- netfs_reissue_write(stream, subreq, &source);
+ netfs_reissue_write(stream, subreq);
if (subreq == to)
break;
}
@@ -172,17 +180,19 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,
netfs_stat(&netfs_n_wh_upload);
stream->sreq_max_len = umin(len, wreq->wsize);
break;
- case NETFS_WRITE_TO_CACHE:
- netfs_stat(&netfs_n_wh_write);
- break;
default:
WARN_ON_ONCE(1);
}
stream->prepare_write(subreq);
- part = umin(len, stream->sreq_max_len);
+ bvecq_pos_set(&subreq->io_buffer, &dispatch_cursor);
+ part = bvecq_slice(&dispatch_cursor,
+ umin(len, stream->sreq_max_len),
+ stream->sreq_max_segs,
+ &subreq->nr_segs);
subreq->len = subreq->transferred + part;
+
len -= part;
start += part;
if (!len && boundary) {
@@ -190,13 +200,16 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,
boundary = false;
}
- netfs_reissue_write(stream, subreq, &source);
+ netfs_reissue_write(stream, subreq);
if (!len)
break;
} while (len);
} while (!list_is_head(next, &stream->subrequests));
+
+out:
+ bvecq_pos_unset(&dispatch_cursor);
}
/*
diff --git a/include/linux/bvecq.h b/include/linux/bvecq.h
index b984aaa449088..389f6407cb846 100644
--- a/include/linux/bvecq.h
+++ b/include/linux/bvecq.h
@@ -54,6 +54,16 @@ struct bvecq {
/* Number of slots in a 4K bvecq. */
#define BVECQ_4KB_SLOTS ((4096 - sizeof(struct bvecq)) / sizeof(struct bio_vec))
+/*
+ * Position in a bio_vec queue. The bvecq holds a ref on the queue segment it
+ * points to.
+ */
+struct bvecq_pos {
+ struct bvecq *bvecq; /* The first bvecq */
+ unsigned int offset; /* The offset within the starting slot */
+ u16 slot; /* The starting slot */
+};
+
void bvecq_dump(const struct bvecq *bq);
struct bvecq *bvecq_alloc_one(size_t nr_slots, gfp_t gfp, bool for_writeback);
struct bvecq *bvecq_alloc_chain(size_t nr_slots, gfp_t gfp, bool for_writeback);
@@ -61,6 +71,13 @@ struct bvecq *bvecq_alloc_buffer2(size_t size, unsigned int pre_slots, gfp_t gfp
bool for_writeback);
void bvecq_put(struct bvecq *bq);
int bvecq_expand_buffer(struct bvecq **_buffer, size_t *_cur_size, size_t size, gfp_t gfp);
+int bvecq_buffer_init(struct bvecq_pos *pos, gfp_t gfp, bool for_writeback);
+void bvecq_buffer_append(struct bvecq_pos *pos, struct bvecq *bq);
+void bvecq_pos_advance(struct bvecq_pos *pos, size_t amount);
+ssize_t bvecq_zero(struct bvecq_pos *pos, size_t amount);
+size_t bvecq_slice(struct bvecq_pos *pos, size_t max_size,
+ unsigned int max_slots, unsigned int *_nr_slots);
+ssize_t bvecq_load_from_ra(struct bvecq_pos *pos, struct readahead_control *ractl);
/**
* bvecq_alloc_buffer - Allocate a bvecq chain and populate with buffers
@@ -163,4 +180,171 @@ static inline struct bvecq *bvecq_next(const struct bvecq *bq)
return smp_load_acquire(&bq->next);
}
+/**
+ * bvecq_pos_set - Set one position to be the same as another
+ * @pos: The position object to set
+ * @at: The source position.
+ *
+ * Set @pos to have the same position as @at. This may take a ref on the
+ * bvecq pointed to.
+ */
+static inline void bvecq_pos_set(struct bvecq_pos *pos, const struct bvecq_pos *at)
+{
+ *pos = *at;
+ bvecq_get(pos->bvecq);
+}
+
+/**
+ * bvecq_pos_unset - Unset a position
+ * @pos: The position object to unset
+ *
+ * Unset @pos. This does any needed ref cleanup.
+ */
+static inline void bvecq_pos_unset(struct bvecq_pos *pos)
+{
+ bvecq_put(pos->bvecq);
+ pos->bvecq = NULL;
+ pos->slot = 0;
+ pos->offset = 0;
+}
+
+/**
+ * bvecq_pos_transfer - Transfer one position to another, clearing the first
+ * @pos: The position object to set
+ * @from: The source position to clear.
+ *
+ * Set @pos to have the same position as @from and then clear @from. This may
+ * transfer a ref on the bvecq pointed to.
+ */
+static inline void bvecq_pos_transfer(struct bvecq_pos *pos, struct bvecq_pos *from)
+{
+ *pos = *from;
+ from->bvecq = NULL;
+ from->slot = 0;
+ from->offset = 0;
+}
+
+/**
+ * bvecq_pos_move - Update a position to a new bvecq
+ * @pos: The position object to update.
+ * @to: The new bvecq to point at.
+ *
+ * Update @pos to point to @to if it doesn't already do so. This may
+ * manipulate refs on the bvecqs pointed to.
+ */
+static inline void bvecq_pos_move(struct bvecq_pos *pos, struct bvecq *to)
+{
+ struct bvecq *old = pos->bvecq;
+
+ if (old != to) {
+ pos->bvecq = bvecq_get(to);
+ bvecq_put(old);
+ }
+}
+
+/**
+ * bvecq_pos_nudge - Nudge a position onto the next segment if current used up
+ * @pos: The position object to nudge.
+ *
+ * Update @pos to point to the next segment in the chain if we've used up the
+ * current segment. This may manipulate refs on the bvecqs pointed to.
+ *
+ * Return: true if found a new segment, false if hit the end.
+ */
+static inline bool bvecq_pos_nudge(struct bvecq_pos *pos)
+{
+ struct bvecq *bq = pos->bvecq;
+
+ for (;;) {
+ if (!bvecq_acquire_slot(bq, pos->slot)) {
+ bq = bvecq_next(bq);
+ if (!bq)
+ return false;
+ if (bvecq_acquire_slot(bq, pos->slot))
+ continue; /* More slots got added. */
+ bvecq_pos_move(pos, bq);
+ pos->slot = 0;
+ pos->offset = 0;
+ continue;
+ }
+ if (pos->offset >= bq->bv[pos->slot].bv_len) {
+ pos->slot++;
+ pos->offset = 0;
+ continue;
+ }
+ return true;
+ }
+}
+
+/**
+ * bvecq_pos_step - Step a position to the next slot if possible
+ * @pos: The position object to step.
+ *
+ * Update @pos to point to the next slot in the queue if not at the end. This
+ * may manipulate refs on the bvecqs pointed to.
+ *
+ * Return: true if successful, false if was at the end.
+ */
+static inline bool bvecq_pos_step(struct bvecq_pos *pos)
+{
+ struct bvecq *bq = pos->bvecq, *next;
+
+ pos->slot++;
+ pos->offset = 0;
+ if (bvecq_acquire_slot(bq, pos->slot))
+ return true;
+ next = bvecq_next(bq);
+ if (!next)
+ return false;
+ if (bvecq_acquire_slot(bq, pos->slot))
+ return true;
+ bvecq_pos_move(pos, next);
+ pos->slot = 0;
+ return true;
+}
+
+/**
+ * bvecq_delete_spent - Delete the bvecq at the front if possible
+ * @pos: The position object to update.
+ *
+ * Delete the used up bvecq at the front of the queue that @pos points to if it
+ * is not the last node in the queue; if it is the last node in the queue, it
+ * is kept so that the queue doesn't become detached from the other end. This
+ * may manipulate refs on the bvecqs pointed to. It is also possible that the
+ * producer will fill more slots in the current bvecq.
+ *
+ * Also, we have to be very careful: the consumer can catch the producer, which
+ * could lead to us having nothing left in the queue, causing the front and
+ * back pointers to end up on different tracks. To avoid this, we must always
+ * keep at least one segment in the queue.
+ *
+ * The caller must reload from @pos after calling this.
+ *
+ * Return: true if there's more available; false if not.
+ */
+static inline bool bvecq_delete_spent(struct bvecq_pos *pos)
+{
+ struct bvecq *spent = pos->bvecq;
+ struct bvecq *next;
+ unsigned int slot = pos->slot;
+
+again:
+ /* Read the contents of the queue node after the pointer to it. */
+ next = bvecq_next(spent);
+ if (!next)
+ return false; /* Nothing more to consume at the moment. */
+ if (slot < bvecq_nr_slots_acquire(spent))
+ return true; /* The producer added more. */
+ next->prev = NULL;
+ bvecq_pos_move(pos, next);
+ pos->slot = 0;
+ pos->offset = 0;
+ if (!bvecq_acquire_slot(next, 0)) {
+ spent = next;
+ slot = 0;
+ goto again;
+ }
+ return true;
+}
+
#endif /* _LINUX_BVECQ_H */
diff --git a/include/linux/netfs.h b/include/linux/netfs.h
index f1f85473b0eee..b3a58ce8115c7 100644
--- a/include/linux/netfs.h
+++ b/include/linux/netfs.h
@@ -19,10 +19,12 @@
#include <linux/pagemap.h>
#include <linux/bvecq.h>
#include <linux/uio.h>
-#include <linux/rolling_buffer.h>
enum netfs_sreq_ref_trace;
typedef struct mempool mempool_t;
+struct readahead_control;
+struct netfs_io_request;
+struct netfs_io_subrequest;
struct fscache_occupancy;
/**
@@ -144,7 +146,6 @@ struct netfs_io_stream {
unsigned int sreq_max_segs; /* 0 or max number of segments in an iterator */
unsigned int submit_off; /* Folio offset we're submitting from */
unsigned int submit_len; /* Amount of data left to submit */
- unsigned int submit_extendable_to; /* Amount I/O can be rounded up to */
void (*prepare_write)(struct netfs_io_subrequest *subreq);
void (*issue_write)(struct netfs_io_subrequest *subreq);
/* Collection tracking */
@@ -187,6 +188,7 @@ struct netfs_io_subrequest {
struct netfs_io_request *rreq; /* Supervising I/O request */
struct work_struct work;
struct list_head rreq_link; /* Link in rreq->subrequests */
+ struct bvecq_pos io_buffer; /* Bookmark in the combined queue of the start */
struct iov_iter io_iter; /* Iterator for this subrequest */
uoff_t start; /* Where to start the I/O */
size_t len; /* Size of the I/O */
@@ -247,11 +249,14 @@ struct netfs_io_request {
struct netfs_io_stream io_streams[2]; /* Streams of parallel I/O operations */
#define NR_IO_STREAMS 2 //wreq->nr_io_streams
struct netfs_group *group; /* Writeback group being written back */
- struct rolling_buffer buffer; /* Unencrypted buffer */
+ struct bvecq *spare; /* Advance allocation of bvecq */
+ struct bvecq_pos load_cursor; /* Point at which new folios are loaded in */
+ struct bvecq_pos dispatch_cursor; /* Point from which buffers are dispatched */
+ struct bvecq_pos collect_cursor; /* Clear-up point of I/O buffer */
wait_queue_head_t waitq; /* Processor waiter */
void *netfs_priv; /* Private data for the netfs */
void *netfs_priv2; /* Private data for the netfs */
- struct bio_vec *direct_bv; /* DIO buffer list (when handling iovec-iter) */
+ uoff_t last_end; /* End pos of last folio submitted */
uoff_t submitted; /* Amount submitted for I/O so far */
uoff_t len; /* Length of the request */
size_t transferred; /* Amount to be indicated as transferred */
@@ -266,7 +271,6 @@ struct netfs_io_request {
uoff_t abandon_to; /* Position to abandon folios to */
const struct folio *no_unlock_folio; /* Don't unlock this folio after read */
gfp_t gfp; /* GFP flags to use */
- unsigned int direct_bv_count; /* Number of elements in direct_bv[] */
unsigned int debug_id;
unsigned int rsize; /* Maximum read size (0 for none) */
unsigned int wsize; /* Maximum write size (0 for none) */
@@ -274,7 +278,6 @@ struct netfs_io_request {
unsigned int nr_group_rel; /* Number of refs to release on ->group */
spinlock_t lock; /* Lock for queuing subreqs */
enum netfs_io_origin origin; /* Origin of the request */
- bool direct_bv_unpin; /* T if direct_bv[] must be unpinned */
refcount_t ref;
unsigned long flags;
#define NETFS_RREQ_IN_PROGRESS 0 /* Unlocked when the request completes (has ref) */
@@ -425,7 +428,7 @@ void netfs_single_mark_inode_dirty(struct inode *inode);
ssize_t netfs_read_single(struct inode *inode, struct file *file, struct iov_iter *iter);
int netfs_writeback_single(struct address_space *mapping,
struct writeback_control *wbc,
- struct iov_iter *iter);
+ struct iov_iter *iter, size_t len);
/* Address operations API */
struct readahead_control;
@@ -452,11 +455,9 @@ void netfs_get_subrequest(struct netfs_io_subrequest *subreq,
enum netfs_sreq_ref_trace what);
void netfs_put_subrequest(struct netfs_io_subrequest *subreq,
enum netfs_sreq_ref_trace what);
-ssize_t netfs_extract_user_iter(struct iov_iter *orig, size_t orig_len,
- struct iov_iter *new,
- iov_iter_extraction_t extraction_flags);
-size_t netfs_limit_iter(const struct iov_iter *iter, size_t start_offset,
- size_t max_size, size_t max_segs);
+ssize_t netfs_extract_iter(struct iov_iter *orig, size_t max_len, size_t max_pages,
+ struct bvecq **_bvecq_head,
+ iov_iter_extraction_t extraction_flags, gfp_t gfp);
void netfs_prepare_write_failed(struct netfs_io_subrequest *subreq);
void netfs_write_subrequest_terminated(void *_op, ssize_t transferred_or_error);
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 0adfa6605653d..b7154b81d0d7c 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -1411,6 +1411,7 @@ struct readahead_control {
struct file_ra_state *ra;
/* private: use the readahead_* accessors instead */
pgoff_t _index;
+ unsigned int _nr_folios;
unsigned int _nr_pages;
unsigned int _batch_count;
bool dropbehind;
@@ -1590,6 +1591,15 @@ static inline size_t readahead_batch_length(const struct readahead_control *rac)
return rac->_batch_count * PAGE_SIZE;
}
+/**
+ * readahead_folio_count - Get the number of folios in this readahead request.
+ * @rac: The readahead request.
+ */
+static inline unsigned int readahead_folio_count(const struct readahead_control *rac)
+{
+ return rac->_nr_folios;
+}
+
static inline unsigned long dir_pages(const struct inode *inode)
{
return (unsigned long)(inode->i_size + PAGE_SIZE - 1) >>
diff --git a/include/linux/rolling_buffer.h b/include/linux/rolling_buffer.h
deleted file mode 100644
index 5c0bc4221f010..0000000000000
--- a/include/linux/rolling_buffer.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/* Rolling buffer of folios
- *
- * Copyright (C) 2024 Red Hat, Inc. All Rights Reserved.
- * Written by David Howells (dhowells@redhat.com)
- */
-
-#ifndef _ROLLING_BUFFER_H
-#define _ROLLING_BUFFER_H
-
-#include <linux/bvecq.h>
-#include <linux/uio.h>
-
-/*
- * Rolling buffer. Whilst the buffer is live and in use, folios and bvecq
- * segments can be added to one end by one thread and removed from the other
- * end by another thread. The buffer isn't allowed to be empty; it must always
- * have at least one bvecq in it so that neither side has to modify both queue
- * pointers.
- *
- * The iterator in the buffer is extended as buffers are inserted. It can be
- * snapshotted to use a segment of the buffer.
- */
-struct rolling_buffer {
- struct bvecq *head; /* Producer's insertion point */
- struct bvecq *tail; /* Consumer's removal point */
- struct iov_iter iter; /* Iterator tracking what's left in the buffer */
- u8 first_tail_slot; /* First slot in ->tail */
- bool for_writeback; /* T if being used for writeback */
-};
-
-int rolling_buffer_init(struct rolling_buffer *roll, unsigned int direction,
- gfp_t gfp, bool for_writeback);
-int rolling_buffer_make_space(struct rolling_buffer *roll, gfp_t gfp);
-ssize_t rolling_buffer_bulk_load_from_ra(struct rolling_buffer *roll,
- struct readahead_control *ractl,
- gfp_t gfp);
-ssize_t rolling_buffer_append(struct rolling_buffer *roll, struct folio *folio, gfp_t gfp);
-struct bvecq *rolling_buffer_delete_spent(struct rolling_buffer *roll);
-void rolling_buffer_clear(struct rolling_buffer *roll);
-
-static inline void rolling_buffer_advance(struct rolling_buffer *roll, size_t amount)
-{
- iov_iter_advance(&roll->iter, amount);
-}
-
-#endif /* _ROLLING_BUFFER_H */
diff --git a/include/trace/events/netfs.h b/include/trace/events/netfs.h
index e80c27c49ce25..81a3b7aaa187c 100644
--- a/include/trace/events/netfs.h
+++ b/include/trace/events/netfs.h
@@ -229,7 +229,9 @@
EM(netfs_folio_trace_sched_copy, "sched-copy") \
EM(netfs_folio_trace_store, "store") \
EM(netfs_folio_trace_store_copy, "store-copy") \
- E_(netfs_folio_trace_store_plus, "store+")
+ EM(netfs_folio_trace_store_plus, "store+") \
+ EM(netfs_folio_trace_zero, "zero") \
+ E_(netfs_folio_trace_zero_ra, "zero-ra")
#define netfs_collect_contig_traces \
EM(netfs_contig_trace_collect, "Collect") \
@@ -386,10 +388,10 @@ TRACE_EVENT(netfs_sreq,
__entry->len = sreq->len;
__entry->transferred = sreq->transferred;
__entry->start = sreq->start;
- __entry->slot = sreq->io_iter.bvecq_slot;
+ __entry->slot = sreq->io_buffer.slot;
),
- TP_printk("R=%08x[%x] %s %s f=%03x s=%llx %zx/%zx s=%u e=%d",
+ TP_printk("R=%08x[%x] %s %s f=%03x s=%llx %zx/%zx bv=%u e=%d",
__entry->rreq, __entry->index,
__print_symbolic(__entry->source, netfs_sreq_sources),
__print_symbolic(__entry->what, netfs_sreq_traces),
@@ -782,6 +784,30 @@ TRACE_EVENT(netfs_read_progress_at,
__entry->rreq, __entry->cleaned_to, __entry->progress_at)
);
+TRACE_EVENT(netfs_bv_slot,
+ TP_PROTO(const struct bvecq *bq, int slot),
+
+ TP_ARGS(bq, slot),
+
+ TP_STRUCT__entry(
+ __field(unsigned long, pfn)
+ __field(unsigned int, offset)
+ __field(unsigned int, len)
+ __field(unsigned int, slot)
+ ),
+
+ TP_fast_assign(
+ __entry->slot = slot;
+ __entry->pfn = page_to_pfn(bq->bv[slot].bv_page);
+ __entry->offset = bq->bv[slot].bv_offset;
+ __entry->len = bq->bv[slot].bv_len;
+ ),
+
+ TP_printk("bq[%x] p=%lx %x-%x",
+ __entry->slot,
+ __entry->pfn, __entry->offset, __entry->offset + __entry->len)
+ );
+
#undef EM
#undef E_
#endif /* _TRACE_NETFS_H */
diff --git a/mm/readahead.c b/mm/readahead.c
index 6e5563290287e..196542fb1c930 100644
--- a/mm/readahead.c
+++ b/mm/readahead.c
@@ -188,6 +188,7 @@ static void read_pages(struct readahead_control *rac)
if (unlikely(rac->_workingset))
psi_memstall_leave(&rac->_pflags);
rac->_workingset = false;
+ rac->_nr_folios = 0;
BUG_ON(readahead_count(rac));
}
@@ -303,6 +304,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl,
if (i == mark)
folio_set_readahead(folio);
ractl->_workingset |= folio_test_workingset(folio);
+ ractl->_nr_folios++;
ractl->_nr_pages += min_nrpages;
i += min_nrpages;
}
@@ -473,6 +475,7 @@ static inline int ra_alloc_folio(struct readahead_control *ractl, pgoff_t index,
return err;
}
+ ractl->_nr_folios++;
ractl->_nr_pages += 1UL << order;
ractl->_workingset |= folio_test_workingset(folio);
return 0;
@@ -822,6 +825,7 @@ void readahead_expand(struct readahead_control *ractl,
ractl->_workingset = true;
psi_memstall_enter(&ractl->_pflags);
}
+ ractl->_nr_folios++;
ractl->_nr_pages += min_nrpages;
ractl->_index = folio->index;
}
@@ -851,6 +855,7 @@ void readahead_expand(struct readahead_control *ractl,
ractl->_workingset = true;
psi_memstall_enter(&ractl->_pflags);
}
+ ractl->_nr_folios++;
ractl->_nr_pages += min_nrpages;
if (ra) {
ra->size += min_nrpages;
|
| 3/2 | 2026/10/05 07:34 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 47145 output: 26 thoughts: 768 Thoughts: **Analyzing this Patch: A Deep Dive into Netfs Buffer Management** Okay, let's get down to brass tacks. We've got an amd64 patch to dissect, and the first order of business is understanding the problem and its potential implications. I need to know if this code is even *reachable* in a standard virtualized environment like QEMU or GCE. This is crucial; if it's not something we can trigger easily, it complicates things significantly. The primary areas of concern jump out right away. We need to be especially wary of any logic changes in memory management, synchronization, BPF, the scheduler, core networking, VFS, or syscall handling. Also, any restructuring of data structures, abstractions, or algorithm flows that are broadly used, especially if there are runtime assertions involved. I'm going to have to carefully go through any changes to core subsystems. Then I'll search for target-specific features and entrypoints to make sure they aren't pervasive. Finally, I'll need to figure out which Kconfig flags are going to enable this. Now, let's see what the patch actually *does*. The file list gives me a pretty good first impression. It's touching `fs/afs/dir.c`, `fs/afs/symlink.c`, `fs/cachefiles/io.c`, and a *ton* of files in `fs/netfs/`, plus some key headers: `bvecq.h`, `netfs.h`, `pagemap.h`, and, notably, a trace event header. The `mm/readahead.c` inclusion is a significant clue. The initial read makes it clear: this is a major overhaul of `netfs`'s buffer management. They're ditching the `rolling_buffer` and replacing it with a new `bvecq` based system. It seems we're now dealing with cursors for loading, dispatching, and collecting data. Functions like `bvecq_buffer_init`, `bvecq_buffer_append`, `bvecq_pos_advance`, `bvecq_zero`, `bvecq_slice`, and `bvecq_load_from_ra` have been added, which is pretty substantial. I see modifications to `readahead.c` as well, along with changes to how netfs handles reads, writes, direct I/O, readahead, and writeback. Plus, it affects AFS and Cachefiles. The fact that `netfs` is involved means this impacts a core filesystem library used by the netfs-based filesystems like AFS, Ceph, CIFS/SMB, 9p, and so on. That makes it more important to review! So, can this be tested in a standard Syzkaller/QEMU setup? I need to know if netfs is readily reachable or if a specific configuration is required. I can mount and exercise netfs-based filesystems, so that's a good start. I can try AFS, CIFS, or 9p. But it seems I should check the Kconfig file for `fs/netfs` to see what configuration options exist for netfs. |
| 4/2 | 2026/10/05 07:34 | tool | grepper |
0mArgs:{
"Expression": "NETFS_SUPPORT",
"PathPrefix": "fs/"
}Results: {
"Output": "fs/9p/Kconfig=2=config 9P_FS\n--\nfs/9p/Kconfig-4-\tdepends on NET_9P\nfs/9p/Kconfig:5:\tselect NETFS_SUPPORT\nfs/9p/Kconfig-6-\thelp\n--\nfs/Makefile=61=obj-$(CONFIG_DLM)\t\t+= dlm/\n--\nfs/Makefile-63-# Do not add any filesystems before this line\nfs/Makefile:64:obj-$(CONFIG_NETFS_SUPPORT)\t+= netfs/\nfs/Makefile-65-obj-$(CONFIG_EXT4_FS)\t\t+= ext4/\n--\nfs/afs/Kconfig=2=config AFS_FS\n--\nfs/afs/Kconfig-6-\tselect DNS_RESOLVER\nfs/afs/Kconfig:7:\tselect NETFS_SUPPORT\nfs/afs/Kconfig-8-\tselect CRYPTO_KRB5\n--\nfs/cachefiles/Kconfig=3=config CACHEFILES\nfs/cachefiles/Kconfig-4-\ttristate \"Filesystem caching on files\"\nfs/cachefiles/Kconfig:5:\tdepends on NETFS_SUPPORT \u0026\u0026 FSCACHE \u0026\u0026 BLOCK\nfs/cachefiles/Kconfig-6-\thelp\n--\nfs/ceph/Kconfig=2=config CEPH_FS\n--\nfs/ceph/Kconfig-5-\tselect CEPH_LIB\nfs/ceph/Kconfig:6:\tselect NETFS_SUPPORT\nfs/ceph/Kconfig-7-\tselect NETFS_PGPRIV2\n--\nfs/netfs/Kconfig-2-\nfs/netfs/Kconfig:3:config NETFS_SUPPORT\nfs/netfs/Kconfig-4-\ttristate\n--\nfs/netfs/Kconfig=10=config NETFS_STATS\nfs/netfs/Kconfig-11-\tbool \"Gather statistical information on local caching\"\nfs/netfs/Kconfig:12:\tdepends on NETFS_SUPPORT \u0026\u0026 PROC_FS\nfs/netfs/Kconfig-13-\thelp\n--\nfs/netfs/Kconfig=28=config NETFS_DEBUG\nfs/netfs/Kconfig-29-\tbool \"Enable dynamic debugging netfslib and FS-Cache\"\nfs/netfs/Kconfig:30:\tdepends on NETFS_SUPPORT\nfs/netfs/Kconfig-31-\thelp\n--\nfs/netfs/Kconfig=36=config FSCACHE\nfs/netfs/Kconfig-37-\tbool \"General filesystem local caching manager\"\nfs/netfs/Kconfig:38:\tdepends on NETFS_SUPPORT\nfs/netfs/Kconfig-39-\thelp\n--\nfs/netfs/Makefile=34=netfs-$(CONFIG_FSCACHE_STATS) += fscache_stats.o\nfs/netfs/Makefile-35-\nfs/netfs/Makefile:36:obj-$(CONFIG_NETFS_SUPPORT) += netfs.o\n--\nfs/nfs/Kconfig=173=config NFS_FSCACHE\n--\nfs/nfs/Kconfig-175-\tdepends on NFS_FS\nfs/nfs/Kconfig:176:\tselect NETFS_SUPPORT\nfs/nfs/Kconfig-177-\tselect NETFS_PGPRIV2\n--\nfs/smb/client/Kconfig=2=config CIFS\n--\nfs/smb/client/Kconfig-20-\tselect OID_REGISTRY\nfs/smb/client/Kconfig:21:\tselect NETFS_SUPPORT\nfs/smb/client/Kconfig-22-\thelp\n"
} |
| 5/2 | 2026/10/05 07:34 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 49498 output: 33 thoughts: 89 Thoughts: Okay, here's my understanding, focusing on the configuration context. **Investigating Filesystem Configuration Dependencies** Alright, so I need to check how these filesystems are brought into the build. Specifically, I know that `fs/netfs/` depends on `CONFIG_NETFS_SUPPORT`, `fs/afs/` relies on `CONFIG_AFS_FS`, and `fs/cachefiles/` needs `CONFIG_CACHEFILES`. Those are all fairly standard filesystem configuration dependencies. And `mm/readahead.c` is, of course, a fundamental memory management component and always included. My immediate next step is clear: I need to dig into `fs/netfs/Kconfig` to understand the precise details of how `NETFS_SUPPORT` is defined and configured. Knowing its dependencies, defaults, and potentially any tristate nature is key to how the entire `netfs` filesystem is handled. From there, I can determine how it relates to the other filesystems in question, specifically in build configurations and potential interactions. |
| 6/2 | 2026/10/05 07:34 | tool | read-file |
0mArgs:{
"File": "fs/netfs/Kconfig",
"FirstLine": 1,
"LineCount": 50
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0-only\n 2:\t\n 3:\tconfig NETFS_SUPPORT\n 4:\t\ttristate\n 5:\t\thelp\n 6:\t\t This option enables support for network filesystems, including\n 7:\t\t helpers for high-level buffered I/O, abstracting out read\n 8:\t\t segmentation, local caching and transparent huge page support.\n 9:\t\n 10:\tconfig NETFS_STATS\n 11:\t\tbool \"Gather statistical information on local caching\"\n 12:\t\tdepends on NETFS_SUPPORT \u0026\u0026 PROC_FS\n 13:\t\thelp\n 14:\t\t This option causes statistical information to be gathered on local\n 15:\t\t caching and exported through file:\n 16:\t\n 17:\t\t\t/proc/fs/fscache/stats\n 18:\t\n 19:\t\t The gathering of statistics adds a certain amount of overhead to\n 20:\t\t execution as there are a quite a few stats gathered, and on a\n 21:\t\t multi-CPU system these may be on cachelines that keep bouncing\n 22:\t\t between CPUs. On the other hand, the stats are very useful for\n 23:\t\t debugging purposes. Saying 'Y' here is recommended.\n 24:\t\n 25:\tconfig NETFS_PGPRIV2\n 26:\t\tbool\n 27:\t\n 28:\tconfig NETFS_DEBUG\n 29:\t\tbool \"Enable dynamic debugging netfslib and FS-Cache\"\n 30:\t\tdepends on NETFS_SUPPORT\n 31:\t\thelp\n 32:\t\t This permits debugging to be dynamically enabled in the local caching\n 33:\t\t management module. If this is set, the debugging output may be\n 34:\t\t enabled by setting bits in /sys/module/netfs/parameters/debug.\n 35:\t\n 36:\tconfig FSCACHE\n 37:\t\tbool \"General filesystem local caching manager\"\n 38:\t\tdepends on NETFS_SUPPORT\n 39:\t\thelp\n 40:\t\t This option enables a generic filesystem caching manager that can be\n 41:\t\t used by various network and other filesystems to cache data locally.\n 42:\t\t Different sorts of caches can be plugged in, depending on the\n 43:\t\t resources available.\n 44:\t\n 45:\t\t See Documentation/filesystems/caching/fscache.rst for more information.\n 46:\t\n 47:\tconfig FSCACHE_STATS\n 48:\t\tbool \"Gather statistical information on local caching\"\n 49:\t\tdepends on FSCACHE \u0026\u0026 PROC_FS\n 50:\t\tselect NETFS_STATS\n"
} |
| 7/2 | 2026/10/05 07:34 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 50513 output: 32 thoughts: 122 Thoughts: **Investigating the `NETFS_SUPPORT` Configuration Option** Okay, so I'm looking into this `NETFS_SUPPORT` option, and it's flagged as a tristate without a direct prompt. Interesting. It's automatically selected by various filesystems—AFS, 9P, CIFS, CEPH, and NFS_FSCACHE—which makes sense. I can see why the system architects would do that. My initial question is, can someone enable `NETFS_SUPPORT` directly in a configuration? It seems like editing a defconfig or .config file with `CONFIG_NETFS_SUPPORT=y` works fine, which is good. But the Kconfig file itself shows those select statements. I should double-check fs/afs/Kconfig to see if the AFS filesystem also has some say in this option's state, because if AFS, 9P, CIFS, CEPH and NFS_FSCACHE all 'select' it, and I want to understand the full picture, I need to look at how AFS is configured. |
| 8/2 | 2026/10/05 07:34 | tool | read-file |
0mArgs:{
"File": "fs/afs/Kconfig",
"FirstLine": 1,
"LineCount": 25
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0-only\n 2:\tconfig AFS_FS\n 3:\t\ttristate \"Andrew File System support (AFS)\"\n 4:\t\tdepends on INET\n 5:\t\tselect AF_RXRPC\n 6:\t\tselect DNS_RESOLVER\n 7:\t\tselect NETFS_SUPPORT\n 8:\t\tselect CRYPTO_KRB5\n 9:\t\thelp\n 10:\t\t If you say Y here, you will get an experimental Andrew File System\n 11:\t\t driver. It currently only supports unsecured read-only AFS access.\n 12:\t\n 13:\t\t See \u003cfile:Documentation/filesystems/afs.rst\u003e for more information.\n 14:\t\n 15:\t\t If unsure, say N.\n 16:\t\n 17:\tconfig AFS_DEBUG\n 18:\t\tbool \"AFS dynamic debugging\"\n 19:\t\tdepends on AFS_FS\n 20:\t\thelp\n 21:\t\t Say Y here to make runtime controllable debugging messages appear.\n 22:\t\n 23:\t\t See \u003cfile:Documentation/filesystems/afs.rst\u003e for more information.\n 24:\t\n 25:\t\t If unsure, say N.\n"
} |
| 9/2 | 2026/10/05 07:34 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 51215 output: 33 thoughts: 13 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Investigating Kconfig and Cachefiles Configuration** Alright, before I finalize this, it's worth a quick check of the `fs/cachefiles/Kconfig` file. I need to be absolutely certain that there aren't any dependencies or configuration options within that specific subtree that might impact the final result. My experience tells me it's always prudent to cross-reference related configuration files. This helps identify any hidden flags or settings that could subtly influence the behaviour or availability of the cachefiles feature I am working with. I want to make sure I haven't overlooked any details at the configuration level. Let me just take a quick scan and make sure I haven't missed anything. |
| 10/2 | 2026/10/05 07:34 | tool | read-file |
0mArgs:{
"File": "fs/cachefiles/Kconfig",
"FirstLine": 1,
"LineCount": 25
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0-only\n 2:\t\n 3:\tconfig CACHEFILES\n 4:\t\ttristate \"Filesystem caching on files\"\n 5:\t\tdepends on NETFS_SUPPORT \u0026\u0026 FSCACHE \u0026\u0026 BLOCK\n 6:\t\thelp\n 7:\t\t This permits use of a mounted filesystem as a cache for other\n 8:\t\t filesystems - primarily networking filesystems - thus allowing fast\n 9:\t\t local disk to enhance the speed of slower devices.\n 10:\t\n 11:\t\t See Documentation/filesystems/caching/cachefiles.rst for more\n 12:\t\t information.\n 13:\t\n 14:\tconfig CACHEFILES_DEBUG\n 15:\t\tbool \"Debug CacheFiles\"\n 16:\t\tdepends on CACHEFILES\n 17:\t\thelp\n 18:\t\t This permits debugging to be dynamically enabled in the filesystem\n 19:\t\t caching on files module. If this is set, the debugging output may be\n 20:\t\t enabled by setting bits in /sys/module/cachefiles/parameters/debug or\n 21:\t\t by including a debugging specifier in /etc/cachefilesd.conf.\n 22:\t\n 23:\tconfig CACHEFILES_ERROR_INJECTION\n 24:\t\tbool \"Provide error injection for cachefiles\"\n 25:\t\tdepends on CACHEFILES \u0026\u0026 SYSCTL\n"
} |
| 11/2 | 2026/10/05 07:34 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 51779 output: 62 thoughts: 2152 Thoughts: **Fuzzing Target Identification** Okay, let's break this down. First, we need to determine the necessary kernel configurations. It looks like `FSCACHE`, `NETFS_SUPPORT`, `AFS_FS`, and `9P_FS` are all potentially relevant. If someone's compiling this code, `AFS_FS` implies `NETFS_SUPPORT`. However, `NETFS_SUPPORT`, `FSCACHE`, and `CACHEFILES` can also be directly configured. We need to remember these flags and that their `CONFIG_` prefix is optional. Next, we have to establish if this code merits fuzzing. This patch *drastically* overhauls the core NetFS logic, touching `fs/netfs/*`, `mm/readahead.c`, `fs/afs/*`, and `fs/cachefiles/*`. This is not just a tweak; it's a fundamental rework of NetFS's rolling buffer implementation with bvecq cursors and slices! The patch introduces a slew of new functions (e.g., `bvecq_buffer_init`, `bvecq_buffer_append`, `bvecq_slice`, etc.) and modifies dozens of existing ones, including crucial components like `netfs_readahead`, and all the write operations, plus updates to readahead in `mm/readahead.c`. Given the scope and algorithmic changes in a performance-critical subsystem, `WorthFuzzing` is a definite "true." Now, to nail down the `FocusSymbols`. We need to avoid ubiquitous lifecycle hot-paths, like general memory allocators or readahead functions called constantly across all filesystems, since that can be found in `mm/readahead.c` within `read_pages`, `page_cache_ra_unbounded`, `ra_alloc_folio`, `readahead_expand`. No, we must target the specific logic added or modified by this patch, or the direct API entrypoints for the subsystem feature under review. And we need to be careful with statically inlined functions. Since the compiler will inline them, the names won't exist in vmlinux, so let's identify non-static, feature-specific caller functions in `.c` files that exercise them. Here's the symbol list by file: In `fs/netfs/bvecq.c`: * `bvecq_buffer_init` (non-static) * `bvecq_buffer_append` (non-static) * `bvecq_pos_advance` (non-static) * `bvecq_zero` (non-static) * `bvecq_slice` (non-static) * `bvecq_load_from_ra` (non-static) In `fs/netfs/iterator.c`: * `netfs_extract_iter` (non-static) In `fs/netfs/buffered_read.c`: * `netfs_readahead` (exported) In `fs/netfs/direct_read.c`: * `netfs_unbuffered_read_iter_locked` (non-static) In `fs/netfs/direct_write.c`: * `netfs_unbuffered_write_iter_locked` (non-static) In `fs/netfs/read_collect.c`: * `netfs_read_set_unlock_at` (non-static) * `netfs_read_collection` (non-static) In `fs/netfs/read_pgpriv2.c`: * `netfs_pgpriv2_copy_to_cache` (non-static) * `netfs_pgpriv2_unlock_copied_folios` (non-static) In `fs/netfs/read_single.c`: * `netfs_read_single` (non-static) In `fs/netfs/write_collect.c`: * `netfs_write_subrequest_terminated` (non-static) In `fs/netfs/write_issue.c`: * `netfs_writepages` (exported) * `netfs_writeback_single` (non-static) * `netfs_create_write_req` (non-static) * `netfs_prepare_write` (non-static) * `netfs_reissue_write` (non-static) * `netfs_issue_write` (non-static) * `netfs_advance_write` (non-static) |
| 12/2 | 2026/10/05 07:34 | tool | grepper |
0mArgs:{
"Expression": "(bvecq_buffer_init|bvecq_slice|bvecq_load_from_ra|netfs_extract_iter|netfs_writeback_single)",
"PathPrefix": "include/"
}Results: {
"Output": "include/linux/bvecq.h=73=int bvecq_expand_buffer(struct bvecq **_buffer, size_t *_cur_size, size_t size, gfp_t gfp);\ninclude/linux/bvecq.h:74:int bvecq_buffer_init(struct bvecq_pos *pos, gfp_t gfp, bool for_writeback);\ninclude/linux/bvecq.h-75-void bvecq_buffer_append(struct bvecq_pos *pos, struct bvecq *bq);\n--\ninclude/linux/bvecq.h=77=ssize_t bvecq_zero(struct bvecq_pos *pos, size_t amount);\ninclude/linux/bvecq.h:78:size_t bvecq_slice(struct bvecq_pos *pos, size_t max_size,\ninclude/linux/bvecq.h-79-\t\t unsigned int max_slots, unsigned int *_nr_slots);\ninclude/linux/bvecq.h:80:ssize_t bvecq_load_from_ra(struct bvecq_pos *pos, struct readahead_control *ractl);\ninclude/linux/bvecq.h-81-\n--\ninclude/linux/netfs.h=428=ssize_t netfs_read_single(struct inode *inode, struct file *file, struct iov_iter *iter);\ninclude/linux/netfs.h:429:int netfs_writeback_single(struct address_space *mapping,\ninclude/linux/netfs.h-430-\t\t\t struct writeback_control *wbc,\n--\ninclude/linux/netfs.h=456=void netfs_put_subrequest(struct netfs_io_subrequest *subreq,\ninclude/linux/netfs.h-457-\t\t\t enum netfs_sreq_ref_trace what);\ninclude/linux/netfs.h:458:ssize_t netfs_extract_iter(struct iov_iter *orig, size_t max_len, size_t max_pages,\ninclude/linux/netfs.h-459-\t\t\t struct bvecq **_bvecq_head,\n"
} |
| 13/2 | 2026/10/05 07:34 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 55573 output: 25 thoughts: 36 Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue: **Investigating the Origins of `bvecq.c`** Alright, so I'm trying to trace the origin of `bvecq.c`. First instinct, and this is standard practice when dealing with kernel-level code like this, is to figure out the module membership. Is this file part of the `netfs` subsystem, is it within `lib`, or is it associated with `block`? That initial assessment is crucial. Knowing the broader subsystem or category narrows the search considerably and helps me understand its function within the larger kernel architecture. The next obvious step is to dive into the Makefiles. I need to pinpoint exactly where `bvecq.c` is being compiled. Looking at the build process is essential for understanding dependencies, build flags, and potential interactions with other modules. This information will quickly illuminate the project hierarchy and its relationship to other core system components. It'll also likely give me some crucial context. |
| 14/2 | 2026/10/05 07:34 | tool | grepper |
0mArgs:{
"Expression": "bvecq",
"PathPrefix": "fs/"
}Results: {
"Output": "\nFull output is too long, showing 200 out of 1134 lines.\nUse more precise expression if possible.\n\nfs/afs/dir.c=135=static void afs_dir_dump(struct afs_vnode *dvnode)\n--\nfs/afs/dir.c-143-\tiov_iter_bvec_queue(\u0026iter, ITER_SOURCE, dvnode-\u003edirectory, 0, 0, i_size);\nfs/afs/dir.c:144:\titerate_bvecq(\u0026iter, iov_iter_count(\u0026iter), NULL, NULL,\nfs/afs/dir.c-145-\t\t afs_dir_dump_step);\n--\nfs/afs/dir.c=197=static int afs_dir_check(struct afs_vnode *dvnode)\n--\nfs/afs/dir.c-206-\tiov_iter_bvec_queue(\u0026iter, ITER_SOURCE, dvnode-\u003edirectory, 0, 0, i_size);\nfs/afs/dir.c:207:\tchecked = iterate_bvecq(\u0026iter, iov_iter_count(\u0026iter), dvnode, NULL,\nfs/afs/dir.c-208-\t\t\t\tafs_dir_check_step);\n--\nfs/afs/dir.c=235=static ssize_t afs_do_read_single(struct afs_vnode *dvnode, struct file *file)\n--\nfs/afs/dir.c-252-\nfs/afs/dir.c:253:\t\tret = bvecq_expand_buffer(\u0026dvnode-\u003edirectory, \u0026cur_size,\nfs/afs/dir.c-254-\t\t\t\t\t round_up(i_size, PAGE_SIZE),\n--\nfs/afs/dir.c=488=static int afs_dir_iterate_contents(struct inode *dir, struct dir_context *dir_ctx)\n--\nfs/afs/dir.c-503-\nfs/afs/dir.c:504:\titerate_bvecq(\u0026iter, iov_iter_count(\u0026iter), dvnode, \u0026ctx,\nfs/afs/dir.c-505-\t\t afs_dir_iterate_step);\n--\nfs/afs/dir_edit.c=110=static union afs_xdr_dir_block *afs_dir_get_block(struct afs_dir_iter *iter, size_t block)\n--\nfs/afs/dir_edit.c-112-\tstruct afs_vnode *dvnode = iter-\u003edvnode;\nfs/afs/dir_edit.c:113:\tstruct bvecq *bq;\nfs/afs/dir_edit.c-114-\tsize_t blpos = block * AFS_DIR_BLOCK_SIZE;\n--\nfs/afs/dir_edit.c-120-\nfs/afs/dir_edit.c:121:\t\tret = bvecq_expand_buffer(\u0026dvnode-\u003edirectory, \u0026cur_size, blend,\nfs/afs/dir_edit.c-122-\t\t\t\t\t mapping_gfp_mask(dvnode-\u003enetfs.inode.i_mapping));\n--\nfs/afs/dir_search.c=67=union afs_xdr_dir_block *afs_dir_find_block(struct afs_dir_iter *iter, size_t block)\n--\nfs/afs/dir_search.c-69-\tstruct afs_vnode *dvnode = iter-\u003edvnode;\nfs/afs/dir_search.c:70:\tstruct bvecq *bq = iter-\u003ebq;\nfs/afs/dir_search.c-71-\tsize_t blpos = block * AFS_DIR_BLOCK_SIZE;\n--\nfs/afs/inode.c=655=void afs_evict_inode(struct inode *inode)\n--\nfs/afs/inode.c-685-\ttruncate_inode_pages_final(\u0026inode-\u003ei_data);\nfs/afs/inode.c:686:\tbvecq_put(vnode-\u003edirectory);\nfs/afs/inode.c-687-\tif (vnode-\u003esymlink)\n--\nfs/afs/internal.h=687=struct afs_vnode {\n--\nfs/afs/internal.h-712-\nfs/afs/internal.h:713:\tstruct bvecq\t\t*directory;\t/* Directory contents */\nfs/afs/internal.h-714-\tstruct afs_symlink __rcu *symlink;\t/* Symlink content */\n--\nfs/afs/internal.h=991=struct afs_dir_iter {\n--\nfs/afs/internal.h-993-\tunion afs_xdr_dir_block *block;\nfs/afs/internal.h:994:\tstruct bvecq\t\t*bq;\nfs/afs/internal.h-995-\tunsigned int\t\tfpos;\n--\nfs/afs/symlink.c=56=void afs_init_new_symlink(struct afs_vnode *vnode, struct afs_operation *op)\n--\nfs/afs/symlink.c-68-\tvnode-\u003edirectory =\nfs/afs/symlink.c:69:\t\tbvecq_alloc_buffer(PAGE_SIZE,\nfs/afs/symlink.c-70-\t\t\t\t mapping_gfp_mask(vnode-\u003enetfs.inode.i_mapping),\n--\nfs/afs/symlink.c=87=static ssize_t afs_do_read_symlink(struct afs_vnode *vnode)\n--\nfs/afs/symlink.c-100-\tif (!vnode-\u003edirectory) {\nfs/afs/symlink.c:101:\t\tvnode-\u003edirectory = bvecq_alloc_buffer(\nfs/afs/symlink.c-102-\t\t\tPAGE_SIZE, mapping_gfp_mask(vnode-\u003enetfs.inode.i_mapping), false);\n--\nfs/afs/symlink.c-137-\tif (!fscache_cookie_enabled(netfs_i_cookie(\u0026vnode-\u003enetfs))) {\nfs/afs/symlink.c:138:\t\tbvecq_put(vnode-\u003edirectory);\nfs/afs/symlink.c-139-\t\tvnode-\u003edirectory = NULL;\n--\nfs/afs/symlink.c=233=int afs_symlink_writepages(struct address_space *mapping,\n--\nfs/afs/symlink.c-257-\t\tnetfs_wb_begin(\u0026vnode-\u003enetfs, false);\nfs/afs/symlink.c:258:\t\tbvecq_put(vnode-\u003edirectory);\nfs/afs/symlink.c-259-\t\tvnode-\u003edirectory = NULL;\n--\nfs/netfs/Makefile=3=netfs-y := \\\n--\nfs/netfs/Makefile-5-\tbuffered_write.o \\\nfs/netfs/Makefile:6:\tbvecq.o \\\nfs/netfs/Makefile-7-\tdirect_read.o \\\n--\nfs/netfs/buffered_read.c=114=static ssize_t netfs_prepare_read_iterator(struct netfs_io_subrequest *subreq)\n--\nfs/netfs/buffered_read.c-123-\nfs/netfs/buffered_read.c:124:\tbvecq_pos_set(\u0026subreq-\u003eio_buffer, \u0026rreq-\u003edispatch_cursor);\nfs/netfs/buffered_read.c:125:\textracted = bvecq_slice(\u0026rreq-\u003edispatch_cursor, rsize,\nfs/netfs/buffered_read.c-126-\t\t\t\tstream-\u003esreq_max_segs, \u0026subreq-\u003enr_segs);\n--\nfs/netfs/buffered_read.c=187=static void netfs_issue_read(struct netfs_io_request *rreq,\n--\nfs/netfs/buffered_read.c-189-{\nfs/netfs/buffered_read.c:190:\tiov_iter_bvec_queue(\u0026subreq-\u003eio_iter, ITER_DEST, subreq-\u003eio_buffer.bvecq,\nfs/netfs/buffered_read.c-191-\t\t\t subreq-\u003eio_buffer.slot, subreq-\u003eio_buffer.offset, subreq-\u003elen);\n--\nfs/netfs/buffered_read.c-200-\tdefault:\nfs/netfs/buffered_read.c:201:\t\tbvecq_zero(\u0026subreq-\u003eio_buffer, subreq-\u003elen);\nfs/netfs/buffered_read.c-202-\t\tsubreq-\u003etransferred = subreq-\u003elen;\n--\nfs/netfs/buffered_read.c=214=static void netfs_mark_copy_to_cache(struct netfs_io_request *rreq,\nfs/netfs/buffered_read.c:215:\t\t\t\t struct bvecq_pos *mark, size_t len, bool copy)\nfs/netfs/buffered_read.c-216-{\nfs/netfs/buffered_read.c:217:\tstruct bvecq *bq = mark-\u003ebvecq;\nfs/netfs/buffered_read.c-218-\tunsigned int offset = mark-\u003eoffset;\n--\nfs/netfs/buffered_read.c-225-\t\t\tbreak;\nfs/netfs/buffered_read.c:226:\t\tif (!bvecq_acquire_slot(bq, slot)) {\nfs/netfs/buffered_read.c-227-\t\t\tbq = bq-\u003enext;\n--\nfs/netfs/buffered_read.c-258-\tif (bq) {\nfs/netfs/buffered_read.c:259:\t\tbvecq_pos_move(mark, bq);\nfs/netfs/buffered_read.c-260-\t\tmark-\u003eoffset = offset;\n--\nfs/netfs/buffered_read.c-262-\t} else {\nfs/netfs/buffered_read.c:263:\t\tbvecq_pos_unset(mark);\nfs/netfs/buffered_read.c-264-\t}\n--\nfs/netfs/buffered_read.c=272=static void netfs_read_to_pagecache(struct netfs_io_request *rreq)\n--\nfs/netfs/buffered_read.c-282-\tstruct fscache_occupancy *occ = \u0026_occ;\nfs/netfs/buffered_read.c:283:\tstruct bvecq_pos mark_cursor;\nfs/netfs/buffered_read.c-284-\tssize_t size = rreq-\u003elen;\n--\nfs/netfs/buffered_read.c-289-\nfs/netfs/buffered_read.c:290:\tbvecq_pos_set(\u0026mark_cursor, \u0026rreq-\u003edispatch_cursor);\nfs/netfs/buffered_read.c-291-\n--\nfs/netfs/buffered_read.c-418-\nfs/netfs/buffered_read.c:419:\t\tif (mark_cursor.bvecq) {\nfs/netfs/buffered_read.c-420-\t\t\t/* See if the cache indicated this should be cached. */\n--\nfs/netfs/buffered_read.c-443-\nfs/netfs/buffered_read.c:444:\tbvecq_pos_unset(\u0026mark_cursor);\nfs/netfs/buffered_read.c:445:\tbvecq_pos_unset(\u0026rreq-\u003edispatch_cursor);\nfs/netfs/buffered_read.c-446-}\n--\nfs/netfs/buffered_read.c=463=void netfs_readahead(struct readahead_control *ractl)\n--\nfs/netfs/buffered_read.c-488-\nfs/netfs/buffered_read.c:489:\t/* Load the folios to be read into a bvecq chain. Note that this\nfs/netfs/buffered_read.c-490-\t * acquires a ref on each folio that we will need to release later -\n--\nfs/netfs/buffered_read.c-492-\t */\nfs/netfs/buffered_read.c:493:\tadded = bvecq_load_from_ra(\u0026rreq-\u003edispatch_cursor, ractl);\nfs/netfs/buffered_read.c-494-\tif (added \u003c 0) {\n--\nfs/netfs/buffered_read.c-501-\trreq-\u003ecleaned_to = rreq-\u003estart;\nfs/netfs/buffered_read.c:502:\tbvecq_pos_set(\u0026rreq-\u003ecollect_cursor, \u0026rreq-\u003edispatch_cursor);\nfs/netfs/buffered_read.c-503-\tnetfs_read_set_unlock_at(rreq);\n--\nfs/netfs/buffered_read.c=517=static int netfs_create_singular_buffer(struct netfs_io_request *rreq, struct folio *folio)\nfs/netfs/buffered_read.c-518-{\nfs/netfs/buffered_read.c:519:\tstruct bvecq *bq;\nfs/netfs/buffered_read.c-520-\tsize_t fsize = folio_size(folio);\nfs/netfs/buffered_read.c-521-\nfs/netfs/buffered_read.c:522:\tbq = bvecq_alloc_one(1, rreq-\u003egfp, false);\nfs/netfs/buffered_read.c-523-\tif (!bq)\n--\nfs/netfs/buffered_read.c-525-\nfs/netfs/buffered_read.c:526:\trreq-\u003edispatch_cursor.bvecq = bq;\nfs/netfs/buffered_read.c-527-\trreq-\u003edispatch_cursor.slot = 0;\n--\nfs/netfs/buffered_read.c-530-\tbvec_set_folio(\u0026bq-\u003ebv[0], folio, fsize, 0);\nfs/netfs/buffered_read.c:531:\tbvecq_filled_to(bq, 1);\nfs/netfs/buffered_read.c:532:\tbvecq_pos_set(\u0026rreq-\u003ecollect_cursor, \u0026rreq-\u003edispatch_cursor);\nfs/netfs/buffered_read.c-533-\trreq-\u003esubmitted = rreq-\u003estart + fsize;\n--\nfs/netfs/buffered_read.c=541=static int netfs_read_gaps(struct file *file, struct folio *folio)\n--\nfs/netfs/buffered_read.c-547-\tstruct netfs_inode *ctx = netfs_inode(mapping-\u003ehost);\nfs/netfs/buffered_read.c:548:\tstruct bvecq *bq = NULL;\nfs/netfs/buffered_read.c-549-\tunsigned int from = finfo-\u003edirty_offset;\n--\nfs/netfs/buffered_read.c-575-\tret = -ENOMEM;\nfs/netfs/buffered_read.c:576:\tbq = bvecq_alloc_chain(nr_bvec, rreq-\u003egfp, false);\nfs/netfs/buffered_read.c-577-\tif (!bq)\nfs/netfs/buffered_read.c-578-\t\tgoto discard;\nfs/netfs/buffered_read.c:579:\trreq-\u003edispatch_cursor.bvecq = bq;\nfs/netfs/buffered_read.c-580-\n--\nfs/netfs/buffered_read.c-582-\nfs/netfs/buffered_read.c:583:\tfor (struct bvecq *p = bq; p; p = p-\u003enext)\nfs/netfs/buffered_read.c-584-\t\tp-\u003emem_type = BVECQ_MEM_PAGECACHE;\n--\nfs/netfs/buffered_read.c-596-\t\tif (i \u003e= bq-\u003emax_slots) {\nfs/netfs/buffered_read.c:597:\t\t\tbvecq_filled_to(bq, i);\nfs/netfs/buffered_read.c-598-\t\t\tbq = bq-\u003enext;\n--\nfs/netfs/buffered_read.c-606-\t\tif (i \u003e= bq-\u003emax_slots) {\nfs/netfs/buffered_read.c:607:\t\t\tbvecq_filled_to(bq, i);\nfs/netfs/buffered_read.c-608-\t\t\tbq = bq-\u003enext;\n--\nfs/netfs/buffered_read.c-613-\t}\nfs/netfs/buffered_read.c:614:\tbvecq_filled_to(bq, i);\nfs/netfs/buffered_read.c-615-\n--\n\n"
} |
| 15/2 | 2026/10/05 07:34 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 60060 output: 32 thoughts: 450 Thoughts: **Analyzing the netfs Module's Symbol Visibility** Okay, so `bvecq.c`, specifically located in `fs/netfs/bvecq.c`, is part of the `netfs.ko` module, or built-in if `NETFS_SUPPORT` is enabled. My primary concern here is symbol visibility – are the functions within `bvecq.c` exported or static? Let's dive into `fs/netfs/bvecq.c` and take a look around the definitions of functions such as `bvecq_buffer_init` and so forth. I've already glanced at the relevant diff. I see the following: * `int bvecq_buffer_init(struct bvecq_pos *pos, gfp_t gfp, bool for_writeback)` * `void bvecq_buffer_append(struct bvecq_pos *pos, struct bvecq *bq)` * `void bvecq_pos_advance(struct bvecq_pos *pos, size_t amount)` * `ssize_t bvecq_zero(struct bvecq_pos *pos, size_t amount)` * `size_t bvecq_slice(struct bvecq_pos *pos, size_t max_size, unsigned int max_slots, unsigned int *_nr_slots)` * `ssize_t bvecq_load_from_ra(struct bvecq_pos *pos, struct readahead_control *ractl)` None of those symbols are static. The declarations are in `include/linux/bvecq.h`. My immediate thought is, are they exported with `EXPORT_SYMBOL`? No, but within netfs or vmlinux, they will appear in /proc/kallsyms. Now, let's broaden the scope a bit. What other non-static functions have been modified or added within this context? I'll look at: * `netfs_extract_iter` in `fs/netfs/iterator.c`, which is `EXPORT_SYMBOL_GPL`. * `netfs_readahead` in `fs/netfs/buffered_read.c`, which is `EXPORT_SYMBOL`. * `netfs_read_single` in `fs/netfs/read_single.c`, which *seems* like it might be an `EXPORT_SYMBOL` candidate. Ultimately, I need to check the netfs module's exports more thoroughly to understand the complete picture. |
| 16/2 | 2026/10/05 07:34 | tool | grepper |
0mArgs:{
"Expression": "EXPORT_SYMBOL.*netfs_",
"PathPrefix": "fs/netfs/"
}Results: {
"Output": "\nFull output is too long, showing 200 out of 205 lines.\nUse more precise expression if possible.\n\nfs/netfs/buffered_read.c=463=void netfs_readahead(struct readahead_control *ractl)\n--\nfs/netfs/buffered_read.c-511-}\nfs/netfs/buffered_read.c:512:EXPORT_SYMBOL(netfs_readahead);\nfs/netfs/buffered_read.c-513-\n--\nfs/netfs/buffered_read.c=659=int netfs_read_folio(struct file *file, struct folio *folio)\n--\nfs/netfs/buffered_read.c-703-}\nfs/netfs/buffered_read.c:704:EXPORT_SYMBOL(netfs_read_folio);\nfs/netfs/buffered_read.c-705-\n--\nfs/netfs/buffered_read.c=788=int netfs_write_begin(struct netfs_inode *ctx,\n--\nfs/netfs/buffered_read.c-874-}\nfs/netfs/buffered_read.c:875:EXPORT_SYMBOL(netfs_write_begin);\nfs/netfs/buffered_read.c-876-\n--\nfs/netfs/buffered_read.c=948=ssize_t netfs_buffered_read_iter(struct kiocb *iocb, struct iov_iter *iter)\n--\nfs/netfs/buffered_read.c-964-}\nfs/netfs/buffered_read.c:965:EXPORT_SYMBOL(netfs_buffered_read_iter);\nfs/netfs/buffered_read.c-966-\n--\nfs/netfs/buffered_read.c=988=ssize_t netfs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)\n--\nfs/netfs/buffered_read.c-997-}\nfs/netfs/buffered_read.c:998:EXPORT_SYMBOL(netfs_file_read_iter);\n--\nfs/netfs/buffered_write.c=84=ssize_t netfs_perform_write(struct kiocb *iocb, struct iov_iter *iter,\n--\nfs/netfs/buffered_write.c-393-}\nfs/netfs/buffered_write.c:394:EXPORT_SYMBOL(netfs_perform_write);\nfs/netfs/buffered_write.c-395-\n--\nfs/netfs/buffered_write.c=419=ssize_t netfs_buffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *from,\n--\nfs/netfs/buffered_write.c-436-}\nfs/netfs/buffered_write.c:437:EXPORT_SYMBOL(netfs_buffered_write_iter_locked);\nfs/netfs/buffered_write.c-438-\n--\nfs/netfs/buffered_write.c=452=ssize_t netfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)\n--\nfs/netfs/buffered_write.c-479-}\nfs/netfs/buffered_write.c:480:EXPORT_SYMBOL(netfs_file_write_iter);\nfs/netfs/buffered_write.c-481-\n--\nfs/netfs/buffered_write.c=488=vm_fault_t netfs_page_mkwrite(struct vm_fault *vmf, struct netfs_group *netfs_group)\n--\nfs/netfs/buffered_write.c-566-}\nfs/netfs/buffered_write.c:567:EXPORT_SYMBOL(netfs_page_mkwrite);\n--\nfs/netfs/direct_read.c=136=ssize_t netfs_unbuffered_read_iter_locked(struct kiocb *iocb, struct iov_iter *iter)\n--\nfs/netfs/direct_read.c-204-}\nfs/netfs/direct_read.c:205:EXPORT_SYMBOL(netfs_unbuffered_read_iter_locked);\nfs/netfs/direct_read.c-206-\n--\nfs/netfs/direct_read.c=215=ssize_t netfs_unbuffered_read_iter(struct kiocb *iocb, struct iov_iter *iter)\n--\nfs/netfs/direct_read.c-229-}\nfs/netfs/direct_read.c:230:EXPORT_SYMBOL(netfs_unbuffered_read_iter);\n--\nfs/netfs/direct_write.c=237=ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *iter,\n--\nfs/netfs/direct_write.c-321-}\nfs/netfs/direct_write.c:322:EXPORT_SYMBOL(netfs_unbuffered_write_iter_locked);\nfs/netfs/direct_write.c-323-\n--\nfs/netfs/direct_write.c=337=ssize_t netfs_unbuffered_write_iter(struct kiocb *iocb, struct iov_iter *from)\n--\nfs/netfs/direct_write.c-400-}\nfs/netfs/direct_write.c:401:EXPORT_SYMBOL(netfs_unbuffered_write_iter);\n--\nfs/netfs/iterator.c=42=ssize_t netfs_extract_iter(struct iov_iter *orig, size_t max_len, size_t max_pages,\n--\nfs/netfs/iterator.c-156-}\nfs/netfs/iterator.c:157:EXPORT_SYMBOL_GPL(netfs_extract_iter);\n--\nfs/netfs/locking.c=61=int netfs_start_io_read(struct inode *inode)\n--\nfs/netfs/locking.c-82-}\nfs/netfs/locking.c:83:EXPORT_SYMBOL(netfs_start_io_read);\nfs/netfs/locking.c-84-\n--\nfs/netfs/locking.c=92=void netfs_end_io_read(struct inode *inode)\n--\nfs/netfs/locking.c-96-}\nfs/netfs/locking.c:97:EXPORT_SYMBOL(netfs_end_io_read);\nfs/netfs/locking.c-98-\n--\nfs/netfs/locking.c=106=int netfs_start_io_write(struct inode *inode)\n--\nfs/netfs/locking.c-119-}\nfs/netfs/locking.c:120:EXPORT_SYMBOL(netfs_start_io_write);\nfs/netfs/locking.c-121-\n--\nfs/netfs/locking.c=129=void netfs_end_io_write(struct inode *inode)\n--\nfs/netfs/locking.c-133-}\nfs/netfs/locking.c:134:EXPORT_SYMBOL(netfs_end_io_write);\nfs/netfs/locking.c-135-\n--\nfs/netfs/locking.c=172=int netfs_start_io_direct(struct inode *inode)\n--\nfs/netfs/locking.c-195-}\nfs/netfs/locking.c:196:EXPORT_SYMBOL(netfs_start_io_direct);\nfs/netfs/locking.c-197-\n--\nfs/netfs/locking.c=205=void netfs_end_io_direct(struct inode *inode)\n--\nfs/netfs/locking.c-209-}\nfs/netfs/locking.c:210:EXPORT_SYMBOL(netfs_end_io_direct);\nfs/netfs/locking.c-211-\n--\nfs/netfs/locking.c=259=bool netfs_wb_begin(struct netfs_inode *ictx, bool nowait)\n--\nfs/netfs/locking.c-269-}\nfs/netfs/locking.c:270:EXPORT_SYMBOL(netfs_wb_begin);\nfs/netfs/locking.c-271-\n--\nfs/netfs/locking.c=277=void netfs_wb_end(struct netfs_inode *ictx)\n--\nfs/netfs/locking.c-299-}\nfs/netfs/locking.c:300:EXPORT_SYMBOL(netfs_wb_end);\n--\nfs/netfs/misc.c=22=bool netfs_dirty_folio(struct address_space *mapping, struct folio *folio)\n--\nfs/netfs/misc.c-48-}\nfs/netfs/misc.c:49:EXPORT_SYMBOL(netfs_dirty_folio);\nfs/netfs/misc.c-50-\n--\nfs/netfs/misc.c=59=int netfs_unpin_writeback(struct inode *inode, struct writeback_control *wbc)\n--\nfs/netfs/misc.c-66-}\nfs/netfs/misc.c:67:EXPORT_SYMBOL(netfs_unpin_writeback);\nfs/netfs/misc.c-68-\n--\nfs/netfs/misc.c=77=void netfs_clear_inode_writeback(struct inode *inode, const void *aux)\n--\nfs/netfs/misc.c-85-}\nfs/netfs/misc.c:86:EXPORT_SYMBOL(netfs_clear_inode_writeback);\nfs/netfs/misc.c-87-\n--\nfs/netfs/misc.c=97=void netfs_invalidate_folio(struct folio *folio, size_t offset, size_t length)\n--\nfs/netfs/misc.c-179-}\nfs/netfs/misc.c:180:EXPORT_SYMBOL(netfs_invalidate_folio);\nfs/netfs/misc.c-181-\n--\nfs/netfs/misc.c=190=bool netfs_release_folio(struct folio *folio, gfp_t gfp)\n--\nfs/netfs/misc.c-218-}\nfs/netfs/misc.c:219:EXPORT_SYMBOL(netfs_release_folio);\nfs/netfs/misc.c-220-\n--\nfs/netfs/read_collect.c=536=void netfs_read_subreq_progress(struct netfs_io_subrequest *subreq)\n--\nfs/netfs/read_collect.c-558-}\nfs/netfs/read_collect.c:559:EXPORT_SYMBOL(netfs_read_subreq_progress);\nfs/netfs/read_collect.c-560-\n--\nfs/netfs/read_collect.c=577=void netfs_read_subreq_terminated(struct netfs_io_subrequest *subreq)\n--\nfs/netfs/read_collect.c-638-}\nfs/netfs/read_collect.c:639:EXPORT_SYMBOL(netfs_read_subreq_terminated);\nfs/netfs/read_collect.c-640-\n--\nfs/netfs/read_single.c=28=void netfs_single_mark_inode_dirty(struct inode *inode)\n--\nfs/netfs/read_single.c-53-}\nfs/netfs/read_single.c:54:EXPORT_SYMBOL(netfs_single_mark_inode_dirty);\nfs/netfs/read_single.c-55-\n--\nfs/netfs/read_single.c=170=ssize_t netfs_read_single(struct inode *inode, struct file *file, struct iov_iter *iter)\n--\nfs/netfs/read_single.c-208-}\nfs/netfs/read_single.c:209:EXPORT_SYMBOL(netfs_read_single);\n--\nfs/netfs/stats.c=51=int netfs_stats_show(struct seq_file *m, void *v)\n--\nfs/netfs/stats.c-100-}\nfs/netfs/stats.c:101:EXPORT_SYMBOL(netfs_stats_show);\n--\nfs/netfs/write_collect.c=524=void netfs_write_subrequest_terminated(void *_op, ssize_t transferred_or_error)\n--\nfs/netfs/write_collect.c-610-}\nfs/netfs/write_collect.c:611:EXPORT_SYMBOL(netfs_write_subrequest_terminated);\n--\nfs/netfs/write_issue.c=142=void netfs_prepare_write_failed(struct netfs_io_subrequest *subreq)\n--\nfs/netfs/write_issue.c-147-}\nfs/netfs/write_issue.c:148:EXPORT_SYMBOL(netfs_prepare_write_failed);\nfs/netfs/write_issue.c-149-\n--\nfs/netfs/write_issue.c=584=int netfs_writepages(struct address_space *mapping,\n--\nfs/netfs/write_issue.c-659-}\nfs/netfs/write_issue.c:660:EXPORT_SYMBOL(netfs_writepages);\nfs/netfs/write_issue.c-661-\n\n"
} |
| 17/2 | 2026/10/05 07:34 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 64472 output: 38 thoughts: 37 Thoughts: Okay, let's see. My first thought is to dig into the `fs/netfs/write_issue.c` file. I'm specifically targeting around line 660, given the context. My aim is to confirm whether `netfs_writeback_single` is exported. That function's likely crucial for understanding the writeback behavior in this network filesystem. I need to know if it's visible, accessible, and behaving as I expect within the kernel's modules and the netfs subsystem. Time to get my hands dirty. |
| 18/2 | 2026/10/05 07:34 | tool | read-file |
0mArgs:{
"File": "fs/netfs/write_issue.c",
"FirstLine": 750,
"LineCount": 25
}Results: {
"Contents": " 750:\t\tnetfs_all_subreqs_queued(wreq);\n 751:\t\tnetfs_wake_collector(wreq);\n 752:\t\n 753:\t\t/* TODO: Might want to be async here if WB_SYNC_NONE, but then need to\n 754:\t\t * wait before modifying.\n 755:\t\t */\n 756:\t\tret = netfs_wait_for_write(wreq);\n 757:\t\tif (ret \u003e 0)\n 758:\t\t\tret = 0;\n 759:\t\n 760:\t\tnetfs_put_request(wreq, netfs_rreq_trace_put_return);\n 761:\t\t_leave(\" = %d\", ret);\n 762:\t\treturn ret;\n 763:\t\n 764:\tcleanup_free:\n 765:\t\tnetfs_put_failed_request(wreq);\n 766:\tcouldnt_start:\n 767:\t\tnetfs_wb_end(ictx);\n 768:\t\t_leave(\" = %d\", ret);\n 769:\t\treturn ret;\n 770:\t}\n 771:\tEXPORT_SYMBOL(netfs_writeback_single);\n"
} |
| 19/2 | 2026/10/05 07:34 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 64997 output: 340 thoughts: 2117 Thoughts: **Analysis of NetFS, AFS, and Cachefiles Changes for Fuzzing Focus** Okay, so `netfs_writeback_single` is exported, that's a key starting point. I need to understand the surrounding code, especially in `fs/netfs/write_issue.c`, around `netfs_issue_write` and `netfs_reissue_write`. I'll cross-reference the headers (`internal.h` and `netfs.h`) for the function declarations of interest: `netfs_reissue_write`, `netfs_issue_write`, `netfs_prepare_write`, `netfs_advance_write`, and `netfs_write_folio`. I'll also check `afs_symlink_writepages` in `fs/afs/symlink.c` and `afs_dir_writepages` in `fs/afs/dir.c`. It's important to understand folio readahead, so I'll review `readahead_folio_count` in `include/linux/pagemap.h`. I'll also note where the readahead count (`rac->_nr_folios`) is updated in `mm/readahead.c`, specifically in functions like `read_pages`, `page_cache_ra_unbounded`, `ra_alloc_folio`, and `readahead_expand`. Now, the crucial part: the Kconfig options. I need to make sure I have the necessary configurations enabled. `NETFS_SUPPORT` is the foundational one for `fs/netfs/`. Then, `AFS_FS` for `fs/afs/`, `CACHEFILES` for `fs/cachefiles/`, and `FSCACHE`. Let me double-check `CACHEFILES`'s dependencies: it depends on `NETFS_SUPPORT`, `FSCACHE`, and `BLOCK`. `AFS_FS` depends on `INET`, `AF_RXRPC`, `DNS_RESOLVER`, `NETFS_SUPPORT`, and `CRYPTO_KRB5`. Therefore, the EnableConfigs are: `NETFS_SUPPORT`, `FSCACHE`, `CACHEFILES`, and `AFS_FS`. I'll quickly review the `fs/netfs/Makefile` to confirm which files are being compiled. The list of changed files (`buffered_read.o`, `bvecq.o`, etc.) are all compiled when `NETFS_SUPPORT` is enabled. `FSCACHE`, `CACHEFILES`, and `AFS_FS` are needed to compile specific files in `cachefiles` and `afs` as well. Now, let's select the symbols to focus on for fuzzing. I'm after specific functions, not general purpose ones. The functions modified and newly added: - `bvecq_buffer_init` - `bvecq_buffer_append` - `bvecq_pos_advance` - `bvecq_zero` - `bvecq_slice` - `bvecq_load_from_ra` - `netfs_extract_iter` - `netfs_readahead` - `netfs_read_single` - `netfs_writepages` - `netfs_writeback_single` - `netfs_unbuffered_read_iter_locked` - `netfs_unbuffered_write_iter_locked` - `afs_symlink_writepages` - `cachefiles_issue_write` I'll double-check whether functions are static or not: `afs_dir_writepages` is static, `afs_symlink_writepages` is non-static and `cachefiles_issue_write` is static. I'll include `netfs_write_subrequest_terminated`, `netfs_read_collection` and `netfs_pgpriv2_unlock_copied_folios` in the scope too. Let's review the role of symbols in `bvecq.c` and `iterator.c`. `bvecq_slice` is key, representing the new slicing logic. `bvecq_load_from_ra` handles readahead folio decanting, `bvecq_pos_advance` advances the cursor, `bvecq_zero` clears memory. `netfs_extract_iter` is the new iterator extraction. The `netfs_*` functions are all direct entry points. These are all specific to these filesystems, which is good. `netfs_readahead` is only called for filesystems that use netfs, unlike generic `read_pages`. I'll confirm the rationale: the patch fundamentally refactors buffer management, introducing |
| 20/2 | 2026/10/05 07:34 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"NETFS_SUPPORT",
"FSCACHE",
"CACHEFILES",
"AFS_FS"
],
"FocusSymbols": [
"bvecq_slice",
"bvecq_load_from_ra",
"bvecq_pos_advance",
"bvecq_zero",
"bvecq_buffer_init",
"bvecq_buffer_append",
"netfs_extract_iter",
"netfs_readahead",
"netfs_read_single",
"netfs_writepages",
"netfs_writeback_single",
"netfs_unbuffered_read_iter_locked",
"netfs_unbuffered_write_iter_locked",
"afs_symlink_writepages"
],
"Reasoning": "The patch replaces the rolling_buffer implementation in netfs with a new bvecq queue and cursor-based architecture (bvecq_pos, bvecq_slice, bvecq_load_from_ra, etc.). It updates readahead folio counting in mm/readahead.c, refactors iterator extraction into bvec queues (netfs_extract_iter), and modifies read, write, direct I/O, readahead, retry, and writeback paths in NetFS, AFS, and Cachefiles. These changes modify reachable core filesystem and MM logic, altering buffer management, refcounting, and slicing invariants, which makes fuzzing worthwhile to uncover regressions, memory bugs, or assertion failures.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"NETFS_SUPPORT",
"FSCACHE",
"CACHEFILES",
"AFS_FS"
],
"FocusSymbols": [
"bvecq_slice",
"bvecq_load_from_ra",
"bvecq_pos_advance",
"bvecq_zero",
"bvecq_buffer_init",
"bvecq_buffer_append",
"netfs_extract_iter",
"netfs_readahead",
"netfs_read_single",
"netfs_writepages",
"netfs_writeback_single",
"netfs_unbuffered_read_iter_locked",
"netfs_unbuffered_write_iter_locked",
"afs_symlink_writepages"
],
"Reasoning": "The patch replaces the rolling_buffer implementation in netfs with a new bvecq queue and cursor-based architecture (bvecq_pos, bvecq_slice, bvecq_load_from_ra, etc.). It updates readahead folio counting in mm/readahead.c, refactors iterator extraction into bvec queues (netfs_extract_iter), and modifies read, write, direct I/O, readahead, retry, and writeback paths in NetFS, AFS, and Cachefiles. These changes modify reachable core filesystem and MM logic, altering buffer management, refcounting, and slicing invariants, which makes fuzzing worthwhile to uncover regressions, memory bugs, or assertion failures.",
"WorthFuzzing": true
} |
| 21/1 | 2026/10/05 07:34 | action | If |
6mArgs:{
"WorthFuzzing": true
}Results: null |
| 22/2 | 2026/10/05 07:34 | agent | kmsan-evaluator |
6mModel:core Args: null Results: {
"KMSANReasoning": "The patch series refactors the netfs and AFS I/O buffering architecture by replacing the 'rolling_buffer' construct with 'bvecq_pos' cursors and bvec queue slicing/zeroing operations. \n\nEvaluating the changes for uninitialized memory risks and info-leaks:\n1. All newly introduced or modified structures on the stack and heap are properly initialized. 'struct bvecq_pos' local instances are explicitly zero-initialized (e.g., '= {}' or through 'bvecq_pos_set()'), while heap-allocated requests ('netfs_io_request' and 'netfs_io_subrequest') are zeroed using memset() during allocation in 'netfs_alloc_request()' and 'netfs_alloc_subrequest()'.\n2. The 'struct readahead_control' modifications add an internal counter '_nr_folios', which is zero-initialized by designated initializer macros (DEFINE_READAHEAD) and reset in 'read_pages()'.\n3. 'bvecq_zero()' explicitly clears destination buffer pages using memset() before signaling completion.\n4. No kernel structures, padding, or uninitialized buffers are copied to user space (no copy_to_user, put_user, netlink, ioctl, or BPF transfers).\n5. Any potential memory bugs introduced by this patch series (e.g., cursor pointer manipulation errors, reference counting on bvecq nodes, bounds on segment slicing, or concurrency bugs between producer and consumer cursors) would manifest as out-of-bounds accesses, use-after-free, or NULL pointer dereferences, all of which are already reliably detected by KASAN and standard bug detectors.\n\nTherefore, there are no uninitialized memory risks or info-leak vectors that warrant a dedicated KMSAN fuzzing session.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit c5a2218e2e5504bde2e57f0bae41a96022008bb9
Author: syz-cluster <triage@syzkaller.com>
Date: Mon Oct 5 07:33:58 2026 +0000
syz-cluster: applied patch under review
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index 5fac02d2d2814..39cba3f37ecd4 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -2229,8 +2229,9 @@ static int afs_dir_writepages(struct address_space *mapping,
if (test_bit(AFS_VNODE_DIR_VALID, &dvnode->flags)) {
iov_iter_bvec_queue(&iter, ITER_SOURCE, dvnode->directory, 0, 0,
- i_size_read(&dvnode->netfs.inode));
- ret = netfs_writeback_single(mapping, wbc, &iter);
+ dvnode->directory_size);
+ ret = netfs_writeback_single(mapping, wbc, &iter,
+ i_size_read(&dvnode->netfs.inode));
if (ret == 1)
ret = 0; /* Skipped write due to lock conflict. */
}
diff --git a/fs/afs/symlink.c b/fs/afs/symlink.c
index 9a611efe6b264..ae03ceff42b85 100644
--- a/fs/afs/symlink.c
+++ b/fs/afs/symlink.c
@@ -248,9 +248,9 @@ int afs_symlink_writepages(struct address_space *mapping,
if (vnode->directory &&
atomic64_read(&vnode->cb_expires_at) != AFS_NO_CB_PROMISE) {
- iov_iter_bvec_queue(&iter, ITER_SOURCE, vnode->directory, 0, 0,
- i_size_read(&vnode->netfs.inode));
- ret = netfs_writeback_single(mapping, wbc, &iter);
+ iov_iter_bvec_queue(&iter, ITER_SOURCE, vnode->directory, 0, 0, PAGE_SIZE);
+ ret = netfs_writeback_single(mapping, wbc, &iter,
+ i_size_read(&vnode->netfs.inode));
}
if (ret == 0) {
diff --git a/fs/cachefiles/io.c b/fs/cachefiles/io.c
index d05059822288c..788439ea6e1c8 100644
--- a/fs/cachefiles/io.c
+++ b/fs/cachefiles/io.c
@@ -546,7 +546,6 @@ static void cachefiles_issue_write(struct netfs_io_subrequest *subreq)
struct netfs_cache_resources *cres = &wreq->cache_resources;
struct cachefiles_object *object = cachefiles_cres_object(cres);
struct cachefiles_cache *cache = object->volume->cache;
- struct netfs_io_stream *stream = &wreq->io_streams[subreq->stream_nr];
const struct cred *saved_cred;
size_t off, pre, post, len = subreq->len;
uoff_t start = subreq->start;
@@ -571,17 +570,6 @@ static void cachefiles_issue_write(struct netfs_io_subrequest *subreq)
}
/* We also need to end on the cache granularity boundary */
- if (start + len == wreq->i_size) {
- size_t part = len & (cache->bsize - 1);
- size_t need = cache->bsize - part;
-
- if (part && stream->submit_extendable_to >= need) {
- len += need;
- subreq->len += need;
- subreq->io_iter.count += need;
- }
- }
-
post = len & (cache->bsize - 1);
if (post) {
len -= post;
diff --git a/fs/netfs/Makefile b/fs/netfs/Makefile
index b1ea4439c1bb4..421dd0be413b3 100644
--- a/fs/netfs/Makefile
+++ b/fs/netfs/Makefile
@@ -14,7 +14,6 @@ netfs-y := \
read_collect.o \
read_retry.o \
read_single.o \
- rolling_buffer.o \
write_collect.o \
write_issue.o \
write_retry.o
diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c
index aa1e4f8d46ab3..945bfa6eed3f0 100644
--- a/fs/netfs/buffered_read.c
+++ b/fs/netfs/buffered_read.c
@@ -114,26 +114,21 @@ static int netfs_begin_cache_read(struct netfs_io_request *rreq, struct netfs_in
static ssize_t netfs_prepare_read_iterator(struct netfs_io_subrequest *subreq)
{
struct netfs_io_request *rreq = subreq->rreq;
+ struct netfs_io_stream *stream = &rreq->io_streams[0];
+ ssize_t extracted;
size_t rsize = subreq->len;
if (subreq->source == NETFS_DOWNLOAD_FROM_SERVER)
- rsize = umin(rsize, rreq->io_streams[0].sreq_max_len);
-
- subreq->len = rsize;
- if (unlikely(rreq->io_streams[0].sreq_max_segs)) {
- size_t limit = netfs_limit_iter(&rreq->buffer.iter, 0, rsize,
- rreq->io_streams[0].sreq_max_segs);
-
- if (limit < rsize) {
- subreq->len = limit;
- trace_netfs_sreq(subreq, netfs_sreq_trace_limited);
- }
+ rsize = umin(rsize, stream->sreq_max_len);
+
+ bvecq_pos_set(&subreq->io_buffer, &rreq->dispatch_cursor);
+ extracted = bvecq_slice(&rreq->dispatch_cursor, rsize,
+ stream->sreq_max_segs, &subreq->nr_segs);
+ if (extracted < rsize) {
+ subreq->len = extracted;
+ trace_netfs_sreq(subreq, netfs_sreq_trace_limited);
}
- subreq->io_iter = rreq->buffer.iter;
-
- iov_iter_truncate(&subreq->io_iter, subreq->len);
- rolling_buffer_advance(&rreq->buffer, subreq->len);
return subreq->len;
}
@@ -192,6 +187,9 @@ void netfs_queue_read(struct netfs_io_request *rreq,
static void netfs_issue_read(struct netfs_io_request *rreq,
struct netfs_io_subrequest *subreq)
{
+ iov_iter_bvec_queue(&subreq->io_iter, ITER_DEST, subreq->io_buffer.bvecq,
+ subreq->io_buffer.slot, subreq->io_buffer.offset, subreq->len);
+
switch (subreq->source) {
case NETFS_DOWNLOAD_FROM_SERVER:
rreq->netfs_ops->issue_read(subreq);
@@ -200,10 +198,9 @@ static void netfs_issue_read(struct netfs_io_request *rreq,
netfs_read_cache_to_pagecache(rreq, subreq);
break;
default:
- __set_bit(NETFS_SREQ_CLEAR_TAIL, &subreq->flags);
- subreq->error = 0;
- iov_iter_zero(subreq->len, &subreq->io_iter);
+ bvecq_zero(&subreq->io_buffer, subreq->len);
subreq->transferred = subreq->len;
+ subreq->error = 0;
netfs_read_subreq_terminated(subreq);
break;
}
@@ -215,31 +212,31 @@ static void netfs_issue_read(struct netfs_io_request *rreq,
* otherwise we set the deprecated PG_private_2.
*/
static void netfs_mark_copy_to_cache(struct netfs_io_request *rreq,
- struct bvecq **bq,
- unsigned int *offset,
- int *slot,
- size_t len,
- bool copy)
+ struct bvecq_pos *mark, size_t len, bool copy)
{
+ struct bvecq *bq = mark->bvecq;
+ unsigned int offset = mark->offset;
+ int slot = mark->slot;
+
while (len > 0) {
- struct folio *folio;
size_t fsize, overlap;
- if (!*bq)
+ if (!bq)
break;
- if (!bvecq_acquire_slot(*bq, *slot)) {
- *bq = bvecq_next(*bq);
- *slot = 0;
- *offset = 0;
+ if (!bvecq_acquire_slot(bq, slot)) {
+ bq = bq->next;
+ slot = 0;
+ offset = 0;
continue;
}
/* Determine how much the subreq overlaps the folio, if at all. */
- fsize = (*bq)->bv[*slot].bv_len;
- overlap = min(len, fsize - *offset);
+ fsize = bq->bv[slot].bv_len;
+ overlap = min(len, fsize - offset);
if (overlap > 0 && copy) {
- folio = bvec_folio(&(*bq)->bv[*slot]);
+ struct folio *folio = bvec_folio(&bq->bv[slot]);
+
if (netfs_using_pgpriv2(rreq)) {
if (!folio_test_private_2(folio))
folio_start_private_2(folio);
@@ -251,12 +248,20 @@ static void netfs_mark_copy_to_cache(struct netfs_io_request *rreq,
}
len -= overlap;
- *offset += overlap;
- if (*offset >= fsize) {
- *slot += 1;
- *offset = 0;
+ offset += overlap;
+ if (offset >= fsize) {
+ slot += 1;
+ offset = 0;
}
}
+
+ if (bq) {
+ bvecq_pos_move(mark, bq);
+ mark->offset = offset;
+ mark->slot = slot;
+ } else {
+ bvecq_pos_unset(mark);
+ }
}
/*
@@ -275,11 +280,14 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq)
.cached_to[1] = ULLONG_MAX,
};
struct fscache_occupancy *occ = &_occ;
- struct bvecq *bq = rreq->buffer.tail;
- unsigned int offset = 0;
+ struct bvecq_pos mark_cursor;
ssize_t size = rreq->len;
uoff_t start = rreq->start;
- int ret = 0, slot = 0;
+ int ret = 0;
+
+ _enter("R=%08x", rreq->debug_id);
+
+ bvecq_pos_set(&mark_cursor, &rreq->dispatch_cursor);
do {
int (*prepare_read)(struct netfs_io_subrequest *subreq) = NULL;
@@ -408,10 +416,10 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq)
if (size <= 0)
netfs_all_subreqs_queued(rreq);
- if (bq) {
+ if (mark_cursor.bvecq) {
/* See if the cache indicated this should be cached. */
copy = test_bit(NETFS_SREQ_COPY_TO_CACHE, &subreq->flags);
- netfs_mark_copy_to_cache(rreq, &bq, &slot, &offset, slice, copy);
+ netfs_mark_copy_to_cache(rreq, &mark_cursor, slice, copy);
}
trace_netfs_sreq(subreq, netfs_sreq_trace_submit);
@@ -432,6 +440,9 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq)
/* Defer error return as we may need to wait for outstanding I/O. */
cmpxchg(&rreq->error, 0, ret);
+
+ bvecq_pos_unset(&mark_cursor);
+ bvecq_pos_unset(&rreq->dispatch_cursor);
}
/**
@@ -479,7 +490,7 @@ void netfs_readahead(struct readahead_control *ractl)
* acquires a ref on each folio that we will need to release later -
* but we don't want to do that until after we've started the I/O.
*/
- added = rolling_buffer_bulk_load_from_ra(&rreq->buffer, ractl, rreq->gfp);
+ added = bvecq_load_from_ra(&rreq->dispatch_cursor, ractl);
if (added < 0) {
ret = added;
goto cleanup_free;
@@ -488,6 +499,7 @@ void netfs_readahead(struct readahead_control *ractl)
rreq->submitted = rreq->start + added;
rreq->cleaned_to = rreq->start;
+ bvecq_pos_set(&rreq->collect_cursor, &rreq->dispatch_cursor);
netfs_read_set_unlock_at(rreq);
netfs_read_to_pagecache(rreq);
@@ -500,20 +512,26 @@ void netfs_readahead(struct readahead_control *ractl)
EXPORT_SYMBOL(netfs_readahead);
/*
- * Create a rolling buffer with a single occupying folio.
+ * Create a buffer queue with a single occupying folio.
*/
static int netfs_create_singular_buffer(struct netfs_io_request *rreq, struct folio *folio)
{
- ssize_t added;
+ struct bvecq *bq;
+ size_t fsize = folio_size(folio);
- if (rolling_buffer_init(&rreq->buffer, ITER_DEST, rreq->gfp, false) < 0)
+ bq = bvecq_alloc_one(1, rreq->gfp, false);
+ if (!bq)
return -ENOMEM;
- added = rolling_buffer_append(&rreq->buffer, folio, rreq->gfp);
- if (added < 0)
- return added;
- rreq->submitted = rreq->start + added;
- rreq->progress_at = added;
+ rreq->dispatch_cursor.bvecq = bq;
+ rreq->dispatch_cursor.slot = 0;
+ rreq->dispatch_cursor.offset = 0;
+
+ bvec_set_folio(&bq->bv[0], folio, fsize, 0);
+ bvecq_filled_to(bq, 1);
+ bvecq_pos_set(&rreq->collect_cursor, &rreq->dispatch_cursor);
+ rreq->submitted = rreq->start + fsize;
+ rreq->progress_at = fsize;
return 0;
}
@@ -527,14 +545,14 @@ static int netfs_read_gaps(struct file *file, struct folio *folio)
struct netfs_group *group = netfs_folio_group(folio);
struct netfs_folio *finfo = netfs_folio_info(folio);
struct netfs_inode *ctx = netfs_inode(mapping->host);
- struct bio_vec *bvec = NULL;
+ struct bvecq *bq = NULL;
unsigned int from = finfo->dirty_offset;
unsigned int to = from + finfo->dirty_len;
unsigned int off = 0;
size_t flen = folio_size(folio);
size_t nr_bvec = flen / PAGE_SIZE + 2;
size_t part;
- int ret, i = 0, sink_from = -1, sink_to = -1;
+ int ret, i = 0;
_enter("%lx", folio->index);
@@ -555,31 +573,46 @@ static int netfs_read_gaps(struct file *file, struct folio *folio)
* end get copied to, but the middle is discarded.
*/
ret = -ENOMEM;
- bvec = kmalloc_objs(*bvec, nr_bvec);
- if (!bvec)
+ bq = bvecq_alloc_chain(nr_bvec, rreq->gfp, false);
+ if (!bq)
goto discard;
+ rreq->dispatch_cursor.bvecq = bq;
trace_netfs_folio(folio, netfs_folio_trace_read_gaps);
+ for (struct bvecq *p = bq; p; p = p->next)
+ p->mem_type = BVECQ_MEM_PAGECACHE;
+
if (from > 0) {
- bvec_set_folio(&bvec[i++], folio, from, 0);
+ folio_get(folio);
+ bvec_set_folio(&bq->bv[i++], folio, from, 0);
off = from;
}
- sink_from = i;
while (off < to) {
struct folio *sink = folio_alloc(GFP_KERNEL, 0);
if (!sink)
goto discard;
- part = min_t(size_t, to - off, PAGE_SIZE);
- bvec_set_folio(&bvec[i], sink, part, 0);
+ if (i >= bq->max_slots) {
+ bvecq_filled_to(bq, i);
+ bq = bq->next;
+ i = 0;
+ }
+ part = min(to - off, PAGE_SIZE);
+ bvec_set_folio(&bq->bv[i++], sink, part, 0);
off += part;
- sink_to = i;
- i++;
}
- if (to < flen)
- bvec_set_folio(&bvec[i++], folio, flen - to, to);
- iov_iter_bvec(&rreq->buffer.iter, ITER_DEST, bvec, i, rreq->len);
+ if (to < flen) {
+ if (i >= bq->max_slots) {
+ bvecq_filled_to(bq, i);
+ bq = bq->next;
+ i = 0;
+ }
+ folio_get(folio);
+ bvec_set_folio(&bq->bv[i++], folio, flen - to, to);
+ }
+ bvecq_filled_to(bq, i);
+
rreq->submitted = rreq->start + flen;
netfs_read_to_pagecache(rreq);
@@ -596,22 +629,16 @@ static int netfs_read_gaps(struct file *file, struct folio *folio)
folio_mark_uptodate(folio);
}
- if (sink_to >= 0)
- for (; sink_from <= sink_to; sink_from++)
- folio_put(bvec_folio(&bvec[sink_from]));
- kfree(bvec);
+ bvecq_pos_unset(&rreq->dispatch_cursor);
folio_unlock(folio);
netfs_put_request(rreq, netfs_rreq_trace_put_return);
return ret < 0 ? ret : 0;
discard:
+ bvecq_pos_unset(&rreq->dispatch_cursor);
netfs_put_failed_request(rreq);
alloc_error:
folio_unlock(folio);
- if (sink_to >= 0)
- for (; sink_from <= sink_to; sink_from++)
- folio_put(bvec_folio(&bvec[sink_from]));
- kfree(bvec);
return ret;
}
diff --git a/fs/netfs/bvecq.c b/fs/netfs/bvecq.c
index 5b747f6b59382..2edc0045c2453 100644
--- a/fs/netfs/bvecq.c
+++ b/fs/netfs/bvecq.c
@@ -342,3 +342,313 @@ int bvecq_expand_buffer(struct bvecq **_buffer, size_t *_cur_size, size_t size,
return 0;
}
EXPORT_SYMBOL(bvecq_expand_buffer);
+
+/**
+ * bvecq_buffer_init - Initialise a buffer and set position
+ * @pos: The position to point at the new buffer.
+ * @gfp: The allocation constraints.
+ * @for_writeback: True if allocating for writeback
+ *
+ * Initialise a rolling buffer. We allocate an unpopulated bvecq node to so
+ * that the pointers can be independently driven by the producer and the
+ * consumer.
+ *
+ * Return 0 if successful; -ENOMEM on allocation failure.
+ */
+int bvecq_buffer_init(struct bvecq_pos *pos, gfp_t gfp, bool for_writeback)
+{
+ struct bvecq *bq;
+
+ bq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, for_writeback);
+ if (!bq)
+ return -ENOMEM;
+
+ pos->bvecq = bq; /* Comes with a ref. */
+ pos->slot = 0;
+ pos->offset = 0;
+ return 0;
+}
+
+/**
+ * bvecq_buffer_append - Append a new bvecq node to a buffer
+ * @pos: The position of the last node.
+ * @bq: The buffer to add.
+ *
+ * Add a new node on to the buffer chain at the specified position, either
+ * because the previous one is full or because we have a discontiguity to
+ * contend with, and update @pos to point to it.
+ */
+void bvecq_buffer_append(struct bvecq_pos *pos, struct bvecq *bq)
+{
+ struct bvecq *head = pos->bvecq;
+
+ pos->bvecq = bvecq_get(bq);
+ pos->slot = 0;
+ pos->offset = 0;
+
+ /* [!] NOTE: After we set head->next, the consumer is at liberty to
+ * immediately delete the old head.
+ */
+ bvecq_append(head, bq);
+ bvecq_put(head);
+}
+
+/**
+ * bvecq_pos_advance - Advance a bvecq position
+ * @pos: The position to advance.
+ * @amount: The amount of bytes to advance by.
+ *
+ * Advance the specified bvecq position by @amount bytes. @pos is updated and
+ * bvecq ref counts may have been manipulated. If the position hits the end of
+ * the queue, then it is left pointing beyond the last slot of the last bvecq
+ * so that it doesn't break the chain.
+ */
+void bvecq_pos_advance(struct bvecq_pos *pos, size_t amount)
+{
+ struct bvecq *bq = pos->bvecq, *next;
+ unsigned int slot = pos->slot;
+ size_t offset = pos->offset;
+
+ while (amount) {
+ size_t part;
+
+ if (!bvecq_acquire_slot(bq, slot)) {
+ next = bvecq_next(bq);
+ if (!next) {
+ WARN_ON_ONCE(amount > 0);
+ break;
+ }
+ if (bvecq_acquire_slot(bq, slot))
+ continue; /* More slots got added. */
+ bq = next;
+ slot = 0;
+ offset = 0;
+ continue;
+ }
+
+ part = bq->bv[slot].bv_len - offset;
+
+ if (part > amount) {
+ offset += amount;
+ break;
+ }
+ amount -= part;
+ offset = 0;
+ slot++;
+ }
+
+ pos->slot = slot;
+ pos->offset = offset;
+ bvecq_pos_move(pos, bq);
+}
+
+/*
+ * Clear part of the memory pointed to by a bio_vec.
+ */
+static void bvec_zero(const struct bio_vec *bv, size_t offset, size_t len)
+{
+ struct page *page = bv->bv_page;
+
+ offset += bv->bv_offset;
+
+ page += offset / PAGE_SIZE;
+ offset = offset % PAGE_SIZE;
+
+ while (len) {
+ size_t part = min(len, PAGE_SIZE - offset);
+ char *p = kmap_local_page(page);
+
+ memset(p + offset, 0, part);
+ kunmap_local(p);
+
+ len -= part;
+ offset = 0;
+ page++;
+ }
+}
+
+/**
+ * bvecq_zero - Clear memory starting at the bvecq position.
+ * @pos: The position in the bvecq chain to start clearing.
+ * @amount: The number of bytes to clear.
+ *
+ * Clear memory fragments pointed to by a bvec queue. @pos is updated and
+ * bvecq ref counts may have been manipulated. If the position hits the end of
+ * the queue, then it is left pointing beyond the last slot of the last bvecq
+ * so that it doesn't break the chain.
+ *
+ * Return: The number of bytes cleared.
+ */
+ssize_t bvecq_zero(struct bvecq_pos *pos, size_t amount)
+{
+ struct bvecq *bq = pos->bvecq, *next;
+ unsigned int slot = pos->slot;
+ ssize_t cleared = 0;
+ size_t offset = pos->offset;
+
+ while (amount) {
+ const struct bio_vec *bv;
+ size_t part;
+
+ if (!bvecq_acquire_slot(bq, slot)) {
+ next = bvecq_next(bq);
+ if (!next) {
+ WARN_ON_ONCE(amount > 0);
+ break;
+ }
+ if (bvecq_acquire_slot(bq, slot))
+ continue; /* More slots got added. */
+ bq = next;
+ slot = 0;
+ offset = 0;
+ continue;
+ }
+
+ bv = &bq->bv[slot];
+ if (offset >= bv->bv_len) {
+ slot++;
+ offset = 0;
+ continue;
+ }
+
+ part = min(bv->bv_len - offset, amount);
+ bvec_zero(bv, offset, part);
+ cleared += part;
+ offset += part;
+ amount -= part;
+ }
+
+ pos->slot = slot;
+ pos->offset = offset;
+ bvecq_pos_move(pos, bq);
+ return cleared;
+}
+
+/**
+ * bvecq_slice - Find a slice of a bvecq queue
+ * @pos: The position to start at.
+ * @max_size: The maximum size of the slice (or ULONG_MAX).
+ * @max_slots: The maximum number of slots in the slice (or INT_MAX).
+ * @_nr_slots: Where to put the number of slots (updated).
+ *
+ * Determine the size and number of slots that can be obtained the next slice
+ * of bvec queue up to the maximum size and slot count specified.
+ *
+ * @pos is updated to the end of the slice. If the position hits the end of
+ * the queue, then it is left pointing beyond the last slot of the last bvecq
+ * so that it doesn't break the chain.
+ *
+ * Return: The number of bytes in the slice.
+ */
+size_t bvecq_slice(struct bvecq_pos *pos, size_t max_size,
+ unsigned int max_slots, unsigned int *_nr_slots)
+{
+ struct bvecq *bq, *next;
+ unsigned int slot = pos->slot, nslots = 0;
+ size_t size = 0, offset = pos->offset;
+
+ bq = pos->bvecq;
+ for (;;) {
+ for (; slot < bvecq_nr_slots_acquire(bq); slot++) {
+ const struct bio_vec *bvec = &bq->bv[slot];
+
+ if (offset < bvec->bv_len && bvec->bv_page) {
+ size_t part = min(bvec->bv_len - offset, max_size);
+
+ size += part;
+ offset += part;
+ max_size -= part;
+ nslots++;
+ if (!max_size || nslots >= max_slots)
+ goto out;
+ }
+ offset = 0;
+ }
+
+ /* pos->bvecq isn't allowed to go NULL as the queue may get
+ * extended and we would lose our place.
+ */
+ next = bvecq_next(bq);
+ if (!next)
+ break;
+ if (bvecq_acquire_slot(bq, slot))
+ continue; /* More slots got added. */
+ slot = 0;
+ bq = next;
+ }
+
+out:
+ *_nr_slots = nslots;
+ if (slot == bvecq_nr_slots_acquire(bq)) {
+ next = bvecq_next(bq);
+ if (next) {
+ bq = next;
+ slot = 0;
+ offset = 0;
+ }
+ }
+ bvecq_pos_move(pos, bq);
+ pos->slot = slot;
+ pos->offset = offset;
+ return size;
+}
+
+/**
+ * bvecq_load_from_ra - Allocate a bvecq chain and load from readahead
+ * @pos: Blank position object to attach the new chain to.
+ * @ractl: The readahead control context.
+ *
+ * Decant the set of folios to be read from the readahead context into a bvecq
+ * chain. Each folio occupies one bio_vec element.
+ *
+ * Return: Amount of data loaded or -ENOMEM on allocation failure.
+ */
+ssize_t bvecq_load_from_ra(struct bvecq_pos *pos, struct readahead_control *ractl)
+{
+ XA_STATE(xas, &ractl->mapping->i_pages, ractl->_index);
+ struct folio *folio;
+ struct bvecq *bq;
+ unsigned int slot = 0;
+ size_t loaded = 0;
+
+ bq = bvecq_alloc_chain(ractl->_nr_folios, GFP_KERNEL, false);
+ if (!bq)
+ return -ENOMEM;
+
+ pos->bvecq = bq;
+ pos->slot = 0;
+ pos->offset = 0;
+
+ rcu_read_lock();
+
+ xas_for_each(&xas, folio, ractl->_index + ractl->_nr_pages - 1) {
+ size_t len;
+
+ if (xas_retry(&xas, folio))
+ continue;
+ VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
+
+ len = folio_size(folio);
+ bvec_set_folio(&bq->bv[slot], folio, len, 0);
+ loaded += len;
+ slot++;
+ trace_netfs_folio(folio, netfs_folio_trace_read);
+
+ if (slot >= bq->max_slots) {
+ bvecq_filled_to(bq, slot);
+ bq = bq->next;
+ if (!bq)
+ break;
+ slot = 0;
+ }
+ }
+
+ rcu_read_unlock();
+
+ if (bq)
+ bvecq_filled_to(bq, slot);
+
+ ractl->_index += ractl->_nr_pages;
+ ractl->_nr_pages = 0;
+ return loaded;
+}
diff --git a/fs/netfs/direct_read.c b/fs/netfs/direct_read.c
index 8c15f30797238..dae890e8df285 100644
--- a/fs/netfs/direct_read.c
+++ b/fs/netfs/direct_read.c
@@ -16,44 +16,21 @@
#include <linux/netfs.h>
#include "internal.h"
-static void netfs_prepare_dio_read_iterator(struct netfs_io_subrequest *subreq)
-{
- struct netfs_io_request *rreq = subreq->rreq;
- size_t rsize;
-
- rsize = umin(subreq->len, rreq->io_streams[0].sreq_max_len);
- subreq->len = rsize;
-
- if (unlikely(rreq->io_streams[0].sreq_max_segs)) {
- size_t limit = netfs_limit_iter(&rreq->buffer.iter, 0, rsize,
- rreq->io_streams[0].sreq_max_segs);
-
- if (limit < rsize) {
- subreq->len = limit;
- trace_netfs_sreq(subreq, netfs_sreq_trace_limited);
- }
- }
-
- trace_netfs_sreq(subreq, netfs_sreq_trace_prepare);
-
- subreq->io_iter = rreq->buffer.iter;
- iov_iter_truncate(&subreq->io_iter, subreq->len);
- iov_iter_advance(&rreq->buffer.iter, subreq->len);
-}
-
/*
* Perform a read to a buffer from the server, slicing up the region to be read
* according to the network rsize.
*/
static void netfs_dispatch_unbuffered_reads(struct netfs_io_request *rreq)
{
+ struct netfs_io_stream *stream = &rreq->io_streams[0];
ssize_t size = rreq->len;
uoff_t start = rreq->start;
int ret;
+ bvecq_pos_set(&rreq->collect_cursor, &rreq->dispatch_cursor);
+
do {
struct netfs_io_subrequest *subreq;
- ssize_t slice;
subreq = netfs_alloc_subrequest(rreq, NETFS_DOWNLOAD_FROM_SERVER);
if (!subreq) {
@@ -78,14 +55,22 @@ static void netfs_dispatch_unbuffered_reads(struct netfs_io_request *rreq)
}
}
- netfs_prepare_dio_read_iterator(subreq);
- slice = subreq->len;
- size -= slice;
- start += slice;
- rreq->submitted += slice;
+ bvecq_pos_set(&subreq->io_buffer, &rreq->dispatch_cursor);
+ subreq->len = bvecq_slice(&rreq->dispatch_cursor,
+ umin(size, stream->sreq_max_len),
+ stream->sreq_max_segs,
+ &subreq->nr_segs);
+
+ size -= subreq->len;
+ start += subreq->len;
+ rreq->submitted += subreq->len;
if (size <= 0)
netfs_all_subreqs_queued(rreq);
+ iov_iter_bvec_queue(&subreq->io_iter, ITER_DEST, subreq->io_buffer.bvecq,
+ subreq->io_buffer.slot, subreq->io_buffer.offset,
+ subreq->len);
+
rreq->netfs_ops->issue_read(subreq);
if (test_bit(NETFS_RREQ_PAUSE, &rreq->flags))
@@ -99,6 +84,8 @@ static void netfs_dispatch_unbuffered_reads(struct netfs_io_request *rreq)
netfs_all_subreqs_queued(rreq);
netfs_wake_collector(rreq);
}
+
+ bvecq_pos_unset(&rreq->dispatch_cursor);
}
/*
@@ -177,25 +164,17 @@ ssize_t netfs_unbuffered_read_iter_locked(struct kiocb *iocb, struct iov_iter *i
* buffer for ourselves as the caller's iterator will be trashed when
* we return.
*
- * In such a case, extract an iterator to represent as much of the the
- * output buffer as we can manage. Note that the extraction might not
- * be able to allocate a sufficiently large bvec array and may shorten
- * the request.
+ * Extract a buffer queue to represent as much of the output buffer as
+ * we can manage. The fragments are extracted into a bvecq which will
+ * have sufficient nodes allocated to hold all the data, though this
+ * may end up truncated if ENOMEM is encountered.
*/
- if (user_backed_iter(iter)) {
- ret = netfs_extract_user_iter(iter, rreq->len, &rreq->buffer.iter, 0);
- if (ret < 0)
- goto error_put;
- rreq->direct_bv = (struct bio_vec *)rreq->buffer.iter.bvec;
- rreq->direct_bv_count = ret;
- rreq->direct_bv_unpin = iov_iter_extract_will_pin(iter);
- rreq->len = iov_iter_count(&rreq->buffer.iter);
- } else {
- rreq->buffer.iter = *iter;
- rreq->len = orig_count;
- rreq->direct_bv_unpin = false;
- iov_iter_advance(iter, orig_count);
- }
+ ret = netfs_extract_iter(iter, rreq->len, INT_MAX,
+ &rreq->dispatch_cursor.bvecq, 0, rreq->gfp);
+ if (ret < 0)
+ goto error_put;
+
+ rreq->len = ret;
// TODO: Set up bounce buffer if needed
diff --git a/fs/netfs/direct_write.c b/fs/netfs/direct_write.c
index 32200c10d2a45..e783405158277 100644
--- a/fs/netfs/direct_write.c
+++ b/fs/netfs/direct_write.c
@@ -73,7 +73,11 @@ static void netfs_unbuffered_write_collect(struct netfs_io_request *wreq,
spin_unlock(&wreq->lock);
wreq->transferred += subreq->transferred;
- iov_iter_advance(&wreq->buffer.iter, subreq->transferred);
+ if (subreq->transferred < subreq->len) {
+ bvecq_pos_unset(&wreq->dispatch_cursor);
+ bvecq_pos_transfer(&wreq->dispatch_cursor, &subreq->io_buffer);
+ bvecq_pos_advance(&wreq->dispatch_cursor, subreq->transferred);
+ }
stream->collected_to = subreq->start + subreq->transferred;
wreq->collected_to = stream->collected_to;
@@ -99,6 +103,8 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
_enter("%llx", wreq->len);
+ bvecq_pos_set(&wreq->collect_cursor, &wreq->dispatch_cursor);
+
if (wreq->origin == NETFS_DIO_WRITE)
inode_dio_begin(wreq->inode);
@@ -116,6 +122,8 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
break;
}
stream->construct = NULL;
+ } else {
+ bvecq_pos_set(&subreq->io_buffer, &wreq->dispatch_cursor);
}
/* Check if (re-)preparation failed. */
@@ -125,9 +133,16 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
break;
}
- iov_iter_truncate(&subreq->io_iter, wreq->len - wreq->transferred);
+ subreq->len = bvecq_slice(&wreq->dispatch_cursor, stream->sreq_max_len,
+ stream->sreq_max_segs, &subreq->nr_segs);
+
+ iov_iter_bvec_queue(&subreq->io_iter, ITER_SOURCE,
+ subreq->io_buffer.bvecq, subreq->io_buffer.slot,
+ subreq->io_buffer.offset,
+ subreq->len);
+
if (!iov_iter_count(&subreq->io_iter)) {
- pr_warn("netfs: Unexpected zero-length iterator R=%08x\n",
+ pr_warn("netfs: Unexpected zero-length slice R=%08x\n",
wreq->debug_id);
__set_bit(NETFS_SREQ_FAILED, &subreq->flags);
netfs_write_subrequest_terminated(subreq, -EIO);
@@ -135,12 +150,6 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
break;
}
- subreq->len = netfs_limit_iter(&subreq->io_iter, 0,
- stream->sreq_max_len,
- stream->sreq_max_segs);
- iov_iter_truncate(&subreq->io_iter, subreq->len);
- stream->submit_extendable_to = subreq->len;
-
trace_netfs_sreq(subreq, netfs_sreq_trace_submit);
stream->issue_write(subreq);
@@ -175,9 +184,13 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
*/
subreq->error = -EAGAIN;
trace_netfs_sreq(subreq, netfs_sreq_trace_retry);
+
+ bvecq_pos_unset(&wreq->dispatch_cursor);
+ bvecq_pos_transfer(&wreq->dispatch_cursor, &subreq->io_buffer);
+
if (subreq->transferred > 0) {
- iov_iter_advance(&wreq->buffer.iter, subreq->transferred);
wreq->transferred += subreq->transferred;
+ bvecq_pos_advance(&wreq->dispatch_cursor, subreq->transferred);
}
if (stream->source == NETFS_UPLOAD_TO_SERVER &&
@@ -188,7 +201,6 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
__clear_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags);
__clear_bit(NETFS_SREQ_BOUNDARY, &subreq->flags);
__clear_bit(NETFS_SREQ_FAILED, &subreq->flags);
- subreq->io_iter = wreq->buffer.iter;
subreq->start = wreq->start + wreq->transferred;
subreq->len = wreq->len - wreq->transferred;
subreq->transferred = 0;
@@ -204,6 +216,7 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
netfs_stat(&netfs_n_wh_retry_write_subreq);
}
+ bvecq_pos_unset(&wreq->dispatch_cursor);
netfs_unbuffered_write_done(wreq);
_leave(" = %d", ret);
return ret;
@@ -222,10 +235,10 @@ static void netfs_unbuffered_write_async(struct work_struct *work)
* encrypted file. This can also be used for direct I/O writes.
*/
ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *iter,
- struct netfs_group *netfs_group)
+ struct netfs_group *netfs_group)
{
struct netfs_io_request *wreq;
- ssize_t ret, n;
+ ssize_t ret;
uoff_t start = iocb->ki_pos;
uoff_t end = start + iov_iter_count(iter);
size_t len = iov_iter_count(iter);
@@ -261,25 +274,17 @@ ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *
* allocate a sufficiently large bvec array and may shorten the
* request.
*/
- if (user_backed_iter(iter)) {
- n = netfs_extract_user_iter(iter, len, &wreq->buffer.iter, 0);
- if (n < 0) {
- ret = n;
- goto error_put;
- }
- wreq->direct_bv = (struct bio_vec *)wreq->buffer.iter.bvec;
- wreq->direct_bv_count = n;
- wreq->direct_bv_unpin = iov_iter_extract_will_pin(iter);
- } else {
- /* If this is a kernel-generated async DIO request,
- * assume that any resources the iterator points to
- * (eg. a bio_vec array) will persist till the end of
- * the op.
- */
- wreq->buffer.iter = *iter;
- }
+ ssize_t n = netfs_extract_iter(iter, len, INT_MAX,
+ &wreq->dispatch_cursor.bvecq, 0, wreq->gfp);
- wreq->len = iov_iter_count(&wreq->buffer.iter);
+ if (n < 0) {
+ ret = n;
+ goto error_put;
+ }
+ wreq->len = n;
+ _debug("dio-write %zx/%zx %u/%u",
+ n, len, wreq->dispatch_cursor.bvecq->nr_slots,
+ wreq->dispatch_cursor.bvecq->max_slots);
}
__set_bit(NETFS_RREQ_USE_IO_ITER, &wreq->flags);
diff --git a/fs/netfs/internal.h b/fs/netfs/internal.h
index 827b8898d309a..3adf75dcc6322 100644
--- a/fs/netfs/internal.h
+++ b/fs/netfs/internal.h
@@ -70,7 +70,6 @@ static inline void netfs_proc_del_rreq(struct netfs_io_request *rreq) {}
/*
* misc.c
*/
-void netfs_reset_iter(struct netfs_io_subrequest *subreq);
void netfs_wake_collector(struct netfs_io_request *rreq);
void netfs_subreq_clear_in_progress(struct netfs_io_subrequest *subreq);
void netfs_wait_for_in_progress_stream(struct netfs_io_request *rreq,
@@ -237,8 +236,7 @@ void netfs_prepare_write(struct netfs_io_request *wreq,
struct netfs_io_stream *stream,
uoff_t start);
void netfs_reissue_write(struct netfs_io_stream *stream,
- struct netfs_io_subrequest *subreq,
- struct iov_iter *source);
+ struct netfs_io_subrequest *subreq);
void netfs_issue_write(struct netfs_io_request *wreq,
struct netfs_io_stream *stream);
size_t netfs_advance_write(struct netfs_io_request *wreq,
diff --git a/fs/netfs/iterator.c b/fs/netfs/iterator.c
index 31748526d5682..dc97e5b0d4495 100644
--- a/fs/netfs/iterator.c
+++ b/fs/netfs/iterator.c
@@ -14,296 +14,144 @@
#include "internal.h"
/**
- * netfs_extract_user_iter - Extract the pages from a user iterator into a bvec
+ * netfs_extract_iter - Extract virtually contiguous pages from an iterator into a bvecq
* @orig: The original iterator
- * @orig_len: The amount of iterator to copy
- * @new: The iterator to be set up
+ * @max_len: Maximum number of bytes to extract
+ * @max_pages: Maximum number of pages to extract
+ * @_bvecq_head: Where to cache the bvec queue
* @extraction_flags: Flags to qualify the request
+ * @gfp: Allocation mode for bvecq structs.
*
- * Extract the page fragments from the given amount of the source iterator and
- * build up a second iterator that refers to all of those bits. This allows
- * the original iterator to be disposed of.
+ * Extract virtually contiguous page fragments from the source iterator up to
+ * the given maxima and build bvec queue that refers to all of those bits.
+ * This allows the original iterator to disposed of.
*
- * @extraction_flags can have ITER_ALLOW_P2PDMA set to request peer-to-peer DMA be
- * allowed on the pages extracted.
+ * @extraction_flags can have ITER_ALLOW_P2PDMA set to request peer-to-peer DMA
+ * be allowed on the pages extracted.
*
- * On success, the number of elements in the bvec is returned, the original
- * iterator will have been advanced by the amount extracted.
+ * On success or partial success, the amount of data in the bvec is returned,
+ * the original iterator will have been advanced by the amount extracted.
*
- * The iov_iter_extract_mode() function should be used to query how cleanup
- * should be performed.
+ * If an error occurs and no pages are extracted, an error will be returned and
+ * any allocated bvecq will be freed. If there is no data to be extracted (or
+ * @max_len or @max_pages are zero), a single empty bvecq will be returned.
+ *
+ * The bvecq segments are marked with indications on how to get clean up the
+ * extracted fragments.
*/
-ssize_t netfs_extract_user_iter(struct iov_iter *orig, size_t orig_len,
- struct iov_iter *new,
- iov_iter_extraction_t extraction_flags)
+ssize_t netfs_extract_iter(struct iov_iter *orig, size_t max_len, size_t max_pages,
+ struct bvecq **_bvecq_head,
+ iov_iter_extraction_t extraction_flags, gfp_t gfp)
{
- struct bio_vec *bv = NULL;
- struct page **pages;
- unsigned int cur_npages;
- unsigned int max_pages;
- unsigned int npages = 0;
- unsigned int i;
+ struct bvecq *bq_tail = NULL, *bq;
ssize_t ret = 0;
- size_t count = orig_len, offset, len;
- size_t bv_size, pg_size;
+ size_t extracted = 0;
- if (WARN_ON_ONCE(!iter_is_ubuf(orig) && !iter_is_iovec(orig)))
- return -EIO;
+ _enter("{%u,%zx},%zx", orig->iter_type, orig->count, max_len);
- max_pages = iov_iter_npages(orig, INT_MAX);
- bv_size = array_size(max_pages, sizeof(*bv));
- bv = kvmalloc(bv_size, GFP_KERNEL);
- if (!bv)
- return -ENOMEM;
+ *_bvecq_head = NULL;
+ if (max_len > orig->count)
+ max_len = orig->count;
+ if (!max_len || !max_pages)
+ goto alloc_empty;
+ if (WARN_ON_ONCE(max_pages > INT_MAX))
+ max_pages = INT_MAX; /* Protect iov_iter_npages(). */
- /* Put the page list at the end of the bvec list storage. bvec
- * elements are larger than page pointers, so as long as we work
- * 0->last, we should be fine.
- */
- pg_size = array_size(max_pages, sizeof(*pages));
- pages = (void *)bv + bv_size - pg_size;
+ max_pages = iov_iter_npages(orig, max_pages);
+ if (!max_pages)
+ goto alloc_empty;
- while (count && npages < max_pages) {
- ret = iov_iter_extract_pages(orig, &pages, count,
- max_pages - npages, extraction_flags,
- &offset);
- if (unlikely(ret <= 0)) {
- ret = ret ?: -EIO;
+ do {
+ bq = bvecq_alloc_one(max_pages, gfp, false);
+ if (!bq) {
+ ret = -ENOMEM;
break;
}
+ if (user_backed_iter(orig))
+ bq->mem_type = iov_iter_extract_will_pin(orig) ?
+ BVECQ_MEM_GUP : BVECQ_MEM_PAGECACHE;
- if (WARN(ret > count,
- "%s: extract_pages overrun %zd > %zu bytes\n",
- __func__, ret, count)) {
- ret = -EIO;
- break;
- }
+ if (bq_tail)
+ bvecq_append(bq_tail, bq);
+ else
+ *_bvecq_head = bq;
+ bq_tail = bq;
- cur_npages = DIV_ROUND_UP(offset + ret, PAGE_SIZE);
- if (WARN(cur_npages > max_pages - npages,
- "%s: extract_pages overrun %u > %u pages\n",
- __func__, npages + cur_npages, max_pages)) {
- ret = -EIO;
+ if (max_len == 0)
break;
- }
-
- count -= ret;
- ret += offset;
-
- for (i = 0; i < cur_npages; i++) {
- len = ret > PAGE_SIZE ? PAGE_SIZE : ret;
- bvec_set_page(bv + npages + i, *pages++, len - offset, offset);
- ret -= len;
- offset = 0;
- }
-
- npages += cur_npages;
- }
-
- /* Note: Don't try to clean up after EIO. Either we got no pages, so
- * nothing to clean up, or we got a buffer overrun, memory corruption
- * and can't trust the stuff in the buffer (a WARN was emitted).
- */
-
- if (ret < 0 && (ret == -ENOMEM || npages == 0)) {
- for (i = 0; i < npages; i++)
- unpin_user_page(bv[i].bv_page);
- kvfree(bv);
- return ret;
- }
- iov_iter_bvec(new, orig->data_source, bv, npages, orig_len - count);
- return npages;
-}
-EXPORT_SYMBOL_GPL(netfs_extract_user_iter);
-
-/*
- * Select the span of a bvec iterator we're going to use. Limit it by both maximum
- * size and maximum number of segments. Returns the size of the span in bytes.
- */
-static size_t netfs_limit_bvec(const struct iov_iter *iter, size_t start_offset,
- size_t max_size, size_t max_segs)
-{
- const struct bio_vec *bvecs = iter->bvec;
- unsigned int nbv = iter->nr_segs, ix = 0, nsegs = 0;
- size_t len, span = 0, n = iter->count;
- size_t skip = iter->iov_offset + start_offset;
-
- if (WARN_ON(!iov_iter_is_bvec(iter)) ||
- WARN_ON(start_offset > n) ||
- n == 0)
- return 0;
-
- while (n && ix < nbv && skip) {
- len = bvecs[ix].bv_len;
- if (skip < len)
- break;
- skip -= len;
- n -= len;
- ix++;
- }
-
- while (n && ix < nbv) {
- len = min3(n, bvecs[ix].bv_len - skip, max_size);
- span += len;
- nsegs++;
- ix++;
- if (span >= max_size || nsegs >= max_segs)
- break;
- skip = 0;
- n -= len;
- }
-
- return min(span, max_size);
-}
-
-/*
- * Select the span of a kvec iterator we're going to use. Limit it by both
- * maximum size and maximum number of segments. Returns the size of the span
- * in bytes.
- */
-static size_t netfs_limit_kvec(const struct iov_iter *iter, size_t start_offset,
- size_t max_size, size_t max_segs)
-{
- const struct kvec *kvecs = iter->kvec;
- unsigned int nkv = iter->nr_segs, ix = 0, nsegs = 0;
- size_t len, span = 0, n = iter->count;
- size_t skip = iter->iov_offset + start_offset;
-
- if (WARN_ON(!iov_iter_is_kvec(iter)) ||
- WARN_ON(start_offset > n) ||
- n == 0)
- return 0;
-
- while (n && ix < nkv && skip) {
- len = kvecs[ix].iov_len;
- if (skip < len)
- break;
- skip -= len;
- n -= len;
- ix++;
- }
-
- while (n && ix < nkv) {
- len = min3(n, kvecs[ix].iov_len - skip, max_size);
- span += len;
- nsegs++;
- ix++;
- if (span >= max_size || nsegs >= max_segs)
- break;
- skip = 0;
- n -= len;
- }
-
- return min(span, max_size);
-}
-
-/*
- * Select the span of an xarray iterator we're going to use. Limit it by both
- * maximum size and maximum number of segments. It is assumed that segments
- * can be larger than a page in size, provided they're physically contiguous.
- * Returns the size of the span in bytes.
- */
-static size_t netfs_limit_xarray(const struct iov_iter *iter, size_t start_offset,
- size_t max_size, size_t max_segs)
-{
- struct folio *folio;
- unsigned int nsegs = 0;
- uoff_t pos = iter->xarray_start + iter->iov_offset;
- pgoff_t index = pos / PAGE_SIZE;
- size_t span = 0, n = iter->count;
-
- XA_STATE(xas, iter->xarray, index);
-
- if (WARN_ON(!iov_iter_is_xarray(iter)) ||
- WARN_ON(start_offset > n) ||
- n == 0)
- return 0;
- max_size = min(max_size, n - start_offset);
-
- rcu_read_lock();
- xas_for_each(&xas, folio, ULONG_MAX) {
- size_t offset, flen, len;
- if (xas_retry(&xas, folio))
- continue;
- if (WARN_ON(xa_is_value(folio)))
- break;
- if (WARN_ON(folio_test_hugetlb(folio)))
- break;
-
- flen = folio_size(folio);
- offset = offset_in_folio(folio, pos);
- len = min(max_size, flen - offset);
- span += len;
- nsegs++;
- if (span >= max_size || nsegs >= max_segs)
- break;
- }
-
- rcu_read_unlock();
- return min(span, max_size);
-}
-
-/*
- * Select the span of a bvecq iterator we're going to use. Limit it by both
- * maximum size and maximum number of segments. Returns the size of the span
- * in bytes.
- */
-static size_t netfs_limit_bvecq(const struct iov_iter *iter, size_t start_offset,
- size_t max_size, size_t max_segs)
-{
- const struct bvecq *bq = iter->bvecq;
- unsigned int nsegs = 0;
- unsigned int slot = iter->bvecq_slot;
- size_t span = 0, n = iter->count;
-
- if (WARN_ON(!iov_iter_is_bvecq(iter)) ||
- WARN_ON(start_offset > n) ||
- n == 0)
- return 0;
- max_size = umin(max_size, n - start_offset);
-
- if (!bvecq_acquire_slot(bq, slot)) {
- bq = bvecq_next(bq);
- slot = 0;
- }
-
- start_offset += iter->iov_offset;
- do {
- size_t flen;
-
- flen = bq->bv[slot].bv_len;
- if (start_offset < flen) {
- span += flen - start_offset;
- nsegs++;
- start_offset = 0;
- } else {
- start_offset -= flen;
- }
- if (span >= max_size || nsegs >= max_segs)
- break;
-
- slot++;
- if (!bvecq_acquire_slot(bq, slot)) {
- bq = bvecq_next(bq);
- slot = 0;
- }
- } while (bq);
-
- return umin(span, max_size);
-}
+ struct bio_vec *bv = bq->bv;
+ unsigned int slot = 0;
+ do {
+ struct page **pages;
+ ssize_t got;
+ size_t offset;
+ size_t space = bq->max_slots - slot;
+ size_t bv_size = array_size(bq->max_slots, sizeof(*bv));
+ size_t pg_size = array_size(space, sizeof(*pages));
+
+ /* Put the page list at the end of the bvec list
+ * storage. bvec elements are larger than page
+ * pointers, so as long as we work 0->last, we should
+ * be fine.
+ */
+ pages = (void *)bv + bv_size - pg_size;
+
+ got = iov_iter_extract_pages(orig, &pages, max_len,
+ min(space, max_pages),
+ extraction_flags, &offset);
+ if (got < 0) {
+ ret = got;
+ goto out;
+ }
+
+ if (got == 0) {
+ pr_err("extract_pages gave nothing from %zx, %zx\n",
+ extracted, max_len);
+ ret = -EIO;
+ goto out;
+ }
+
+ if (WARN(got > max_len,
+ "%s: extract_pages overrun %zx > %zx bytes\n",
+ __func__, got, max_len)) {
+ ret = -EIO;
+ goto out;
+ }
+
+ extracted += got;
+ max_len -= got;
+
+ do {
+ size_t len = umin(got, PAGE_SIZE - offset);
+
+ BUG_ON(slot >= bq->max_slots);
+
+ bvec_set_page(&bq->bv[slot], *pages++, len, offset);
+ slot++;
+ max_pages--;
+ got -= len;
+ offset = 0;
+ } while (got > 0);
+
+ bvecq_filled_to(bq, slot);
+ } while (max_len > 0 && max_pages > 0 && !bvecq_is_full(bq));
+
+ } while (max_len > 0 && max_pages > 0);
+
+out:
+ if (extracted || ret == 0)
+ return extracted;
+ bvecq_put(*_bvecq_head);
+ *_bvecq_head = NULL;
+ return ret;
+
+alloc_empty:
+ bq = bvecq_alloc_one(1, gfp, false);
+ if (!bq)
+ return -ENOMEM;
+ *_bvecq_head = bq;
+ return 0;
-size_t netfs_limit_iter(const struct iov_iter *iter, size_t start_offset,
- size_t max_size, size_t max_segs)
-{
- if (iov_iter_is_bvecq(iter))
- return netfs_limit_bvecq(iter, start_offset, max_size, max_segs);
- if (iov_iter_is_bvec(iter))
- return netfs_limit_bvec(iter, start_offset, max_size, max_segs);
- if (iov_iter_is_xarray(iter))
- return netfs_limit_xarray(iter, start_offset, max_size, max_segs);
- if (iov_iter_is_kvec(iter))
- return netfs_limit_kvec(iter, start_offset, max_size, max_segs);
- BUG();
}
-EXPORT_SYMBOL(netfs_limit_iter);
+EXPORT_SYMBOL_GPL(netfs_extract_iter);
diff --git a/fs/netfs/misc.c b/fs/netfs/misc.c
index 40e0ff6491329..4fa09560fb4b9 100644
--- a/fs/netfs/misc.c
+++ b/fs/netfs/misc.c
@@ -8,24 +8,6 @@
#include <linux/swap.h>
#include "internal.h"
-/*
- * Reset the subrequest iterator to refer just to the region remaining to be
- * read. The iterator may or may not have been advanced by socket ops or
- * extraction ops to an extent that may or may not match the amount actually
- * read.
- */
-void netfs_reset_iter(struct netfs_io_subrequest *subreq)
-{
- struct iov_iter *io_iter = &subreq->io_iter;
- size_t remain = subreq->len - subreq->transferred;
-
- if (io_iter->count > remain)
- iov_iter_advance(io_iter, io_iter->count - remain);
- else if (io_iter->count < remain)
- iov_iter_revert(io_iter, remain - io_iter->count);
- iov_iter_truncate(&subreq->io_iter, remain);
-}
-
/**
* netfs_dirty_folio - Mark folio dirty and pin a cache object for writeback
* @mapping: The mapping the folio belongs to.
diff --git a/fs/netfs/objects.c b/fs/netfs/objects.c
index 4b8d20559b0e1..bf17dc31fd9d8 100644
--- a/fs/netfs/objects.c
+++ b/fs/netfs/objects.c
@@ -133,7 +133,6 @@ static void netfs_free_request_rcu(struct rcu_head *rcu)
static void netfs_deinit_request(struct netfs_io_request *rreq)
{
struct netfs_inode *ictx = netfs_inode(rreq->inode);
- unsigned int i;
trace_netfs_rreq(rreq, netfs_rreq_trace_free);
@@ -148,16 +147,10 @@ static void netfs_deinit_request(struct netfs_io_request *rreq)
rreq->netfs_ops->free_request(rreq);
if (rreq->cache_resources.ops)
rreq->cache_resources.ops->end_operation(&rreq->cache_resources);
- if (rreq->direct_bv) {
- for (i = 0; i < rreq->direct_bv_count; i++) {
- if (rreq->direct_bv[i].bv_page) {
- if (rreq->direct_bv_unpin)
- unpin_user_page(rreq->direct_bv[i].bv_page);
- }
- }
- kvfree(rreq->direct_bv);
- }
- rolling_buffer_clear(&rreq->buffer);
+ bvecq_pos_unset(&rreq->load_cursor);
+ bvecq_pos_unset(&rreq->dispatch_cursor);
+ bvecq_pos_unset(&rreq->collect_cursor);
+ bvecq_put(rreq->spare);
if (atomic_dec_and_test(&ictx->io_count))
wake_up_var(&ictx->io_count);
@@ -251,6 +244,7 @@ static void netfs_free_subrequest(struct netfs_io_subrequest *subreq)
trace_netfs_sreq(subreq, netfs_sreq_trace_free);
if (rreq->netfs_ops->free_subrequest)
rreq->netfs_ops->free_subrequest(subreq);
+ bvecq_pos_unset(&subreq->io_buffer);
mempool_free(subreq, rreq->netfs_ops->subrequest_pool ?: &netfs_subrequest_pool);
netfs_stat_d(&netfs_n_rh_sreq);
netfs_put_request(rreq, netfs_rreq_trace_put_subreq);
diff --git a/fs/netfs/read_collect.c b/fs/netfs/read_collect.c
index 961b76e37a021..ff3a30b79e063 100644
--- a/fs/netfs/read_collect.c
+++ b/fs/netfs/read_collect.c
@@ -26,9 +26,13 @@
*/
static void netfs_clear_unread(struct netfs_io_subrequest *subreq)
{
- netfs_reset_iter(subreq);
- WARN_ON_ONCE(subreq->len - subreq->transferred != iov_iter_count(&subreq->io_iter));
- iov_iter_zero(iov_iter_count(&subreq->io_iter), &subreq->io_iter);
+ struct iov_iter iter;
+
+ iov_iter_bvec_queue(&iter, ITER_DEST, subreq->io_buffer.bvecq,
+ subreq->io_buffer.slot, subreq->io_buffer.offset, subreq->len);
+ iov_iter_advance(&iter, subreq->transferred);
+ iov_iter_zero(subreq->len, &iter);
+
if (subreq->start + subreq->transferred >= subreq->rreq->i_size)
__set_bit(NETFS_SREQ_HIT_EOF, &subreq->flags);
}
@@ -122,8 +126,8 @@ static void netfs_unlock_read_folio(struct netfs_io_request *rreq,
*/
void netfs_read_set_unlock_at(struct netfs_io_request *rreq)
{
- const struct bvecq *bq = rreq->buffer.tail;
- unsigned int slot = rreq->buffer.first_tail_slot;
+ const struct bvecq *bq = rreq->collect_cursor.bvecq;
+ unsigned int slot = rreq->collect_cursor.slot;
size_t cleaned_to = rreq->cleaned_to - rreq->start;
size_t progress_at = cleaned_to;
size_t minimum = 256 * 1024;
@@ -153,8 +157,8 @@ void netfs_read_set_unlock_at(struct netfs_io_request *rreq)
static void netfs_read_unlock_folios(struct netfs_io_request *rreq,
unsigned int *notes)
{
- struct bvecq *bq = rreq->buffer.tail;
- unsigned int slot = rreq->buffer.first_tail_slot;
+ struct bvecq *bq = rreq->collect_cursor.bvecq;
+ unsigned int slot = rreq->collect_cursor.slot;
uoff_t collected_to = rreq->collected_to;
if (rreq->cleaned_to >= rreq->collected_to)
@@ -162,15 +166,6 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,
// TODO: Begin decryption
- while (!bvecq_acquire_slot(bq, slot)) {
- bq = rolling_buffer_delete_spent(&rreq->buffer);
- if (!bq) {
- WRITE_ONCE(rreq->progress_at, rreq->len);
- return;
- }
- slot = 0;
- }
-
/* We have to wait for readahead refs to have been released before we
* can unlock any folios as the ref-dropper walks i_pages and the only
* thing preventing these folios from being removed is the folio lock.
@@ -180,9 +175,24 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,
for (;;) {
struct folio *folio;
- uoff_t fpos, fend;
+ uoff_t fpos = rreq->cleaned_to, fend;
size_t fsize;
+ /* Clean up the head bvecq segment. If we clear an entire
+ * segment, then we can get rid of it provided it's not also
+ * the tail segment being filled by the issuer.
+ */
+ if (!bvecq_acquire_slot(bq, slot)) {
+ rreq->collect_cursor.slot = slot;
+ if (!bvecq_delete_spent(&rreq->collect_cursor)) {
+ WRITE_ONCE(rreq->progress_at, rreq->len);
+ return;
+ }
+ bq = rreq->collect_cursor.bvecq;
+ slot = rreq->collect_cursor.slot;
+ continue;
+ }
+
folio = bvec_folio(&bq->bv[slot]);
if (WARN_ONCE(!folio_test_locked(folio),
"R=%08x: folio %lx is not locked\n",
@@ -190,7 +200,6 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,
trace_netfs_folio(folio, netfs_folio_trace_not_locked);
fsize = bq->bv[slot].bv_len;
- fpos = folio_pos(folio);
fend = fpos + fsize;
trace_netfs_collect_folio(rreq, folio);
@@ -200,30 +209,16 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,
break;
netfs_unlock_read_folio(rreq, bq, slot);
- WRITE_ONCE(rreq->cleaned_to, fpos + fsize);
- *notes |= MADE_PROGRESS;
-
- /* Clean up the head bq. If we clear an entire bq, then
- * we can get rid of it provided it's not also the tail bq
- * being filled by the issuer.
- */
- bq->bv[slot].bv_page = NULL;
slot++;
- while (!bvecq_acquire_slot(bq, slot)) {
- bq = rolling_buffer_delete_spent(&rreq->buffer);
- if (!bq)
- goto done;
- slot = 0;
- }
+ WRITE_ONCE(rreq->cleaned_to, fend);
+ *notes |= MADE_PROGRESS;
if (fpos + fsize >= collected_to)
break;
}
- rreq->buffer.tail = bq;
-done:
- rreq->buffer.first_tail_slot = slot;
-
+ bvecq_pos_move(&rreq->collect_cursor, bq);
+ rreq->collect_cursor.slot = slot;
netfs_read_set_unlock_at(rreq);
}
@@ -398,12 +393,15 @@ static void netfs_rreq_assess_dio(struct netfs_io_request *rreq)
if (rreq->origin == NETFS_UNBUFFERED_READ ||
rreq->origin == NETFS_DIO_READ) {
- for (i = 0; i < rreq->direct_bv_count; i++) {
- flush_dcache_page(rreq->direct_bv[i].bv_page);
- // TODO: cifs marks pages in the destination buffer
- // dirty under some circumstances after a read. Do we
- // need to do that too?
- set_page_dirty(rreq->direct_bv[i].bv_page);
+ for (struct bvecq *bq = rreq->collect_cursor.bvecq; bq; bq = bvecq_next(bq)) {
+ unsigned int nr_slots = bvecq_nr_slots_acquire(bq);
+ /* Read the slot count before the slots. */
+
+ /* Mark the target buffers dirty. */
+ for (i = 0; i < nr_slots; i++) {
+ flush_dcache_page(bq->bv[i].bv_page);
+ set_page_dirty(bq->bv[i].bv_page);
+ }
}
}
@@ -497,7 +495,15 @@ bool netfs_read_collection(struct netfs_io_request *rreq)
trace_netfs_rreq(rreq, netfs_rreq_trace_done);
netfs_clear_subrequests(rreq);
- netfs_unlock_abandoned_read_pages(rreq);
+ switch (rreq->origin) {
+ case NETFS_READAHEAD:
+ case NETFS_READPAGE:
+ case NETFS_READ_FOR_WRITE:
+ netfs_unlock_abandoned_read_pages(rreq);
+ break;
+ default:
+ break;
+ }
if (unlikely(rreq->copy_to_cache))
netfs_pgpriv2_end_copy_to_cache(rreq);
return true;
diff --git a/fs/netfs/read_pgpriv2.c b/fs/netfs/read_pgpriv2.c
index f8e5667e278e1..f23c4cbfed581 100644
--- a/fs/netfs/read_pgpriv2.c
+++ b/fs/netfs/read_pgpriv2.c
@@ -19,6 +19,9 @@
static void netfs_pgpriv2_copy_folio(struct netfs_io_request *creq, struct folio *folio)
{
struct netfs_io_stream *cache = &creq->io_streams[1];
+ struct bvecq *queue;
+ unsigned int slot;
+ size_t dio_size = PAGE_SIZE;
size_t fsize = folio_size(folio), flen = fsize;
uoff_t fpos = folio_pos(folio), i_size;
bool to_eof = false;
@@ -48,18 +51,37 @@ static void netfs_pgpriv2_copy_folio(struct netfs_io_request *creq, struct folio
to_eof = true;
}
+ flen = round_up(flen, dio_size);
+
_debug("folio %zx %zx", flen, fsize);
trace_netfs_folio(folio, netfs_folio_trace_store_copy);
- /* Attach the folio to the rolling buffer. */
- if (rolling_buffer_append(&creq->buffer, folio, creq->gfp) < 0) {
- set_bit(NETFS_RREQ_CANCEL_CACHING, &creq->flags);
- folio_end_private_2(folio);
- return;
+ /* Institute a new bvec queue segment if the current one is full or if
+ * we encounter a discontiguity. The discontiguity break is important
+ * when it comes to bulk unlocking folios by file range.
+ */
+ queue = creq->load_cursor.bvecq;
+ if (bvecq_is_full(queue) ||
+ (fpos != creq->last_end && creq->last_end > 0 && queue->nr_slots > 0)) {
+ bvecq_buffer_append(&creq->load_cursor, creq->spare);
+ creq->spare = NULL;
+
+ queue = creq->load_cursor.bvecq;
}
- cache->submit_extendable_to = fsize;
+ /* Attach the folio to the rolling buffer. */
+ slot = queue->nr_slots;
+ bvec_set_folio(&queue->bv[slot], folio, fsize, 0);
+ trace_netfs_bv_slot(queue, slot);
+ slot++;
+ bvecq_filled_to(queue, slot);
+ creq->load_cursor.slot = slot;
+ creq->load_cursor.offset = 0;
+ creq->last_end = fpos + flen;
+
+ bvecq_pos_nudge(&creq->dispatch_cursor);
+
cache->submit_off = 0;
cache->submit_len = flen;
@@ -71,10 +93,9 @@ static void netfs_pgpriv2_copy_folio(struct netfs_io_request *creq, struct folio
do {
ssize_t part;
- creq->buffer.iter.iov_offset = cache->submit_off;
+ creq->dispatch_cursor.offset = cache->submit_off;
atomic64_set(&creq->issued_to, fpos + cache->submit_off);
- cache->submit_extendable_to = fsize - cache->submit_off;
part = netfs_advance_write(creq, cache, fpos + cache->submit_off,
cache->submit_len, to_eof);
cache->submit_off += part;
@@ -84,8 +105,7 @@ static void netfs_pgpriv2_copy_folio(struct netfs_io_request *creq, struct folio
cache->submit_len -= part;
} while (cache->submit_len > 0);
- creq->buffer.iter.iov_offset = 0;
- rolling_buffer_advance(&creq->buffer, fsize);
+ bvecq_pos_step(&creq->dispatch_cursor);
atomic64_set(&creq->issued_to, fpos + fsize);
if (flen < fsize)
@@ -111,6 +131,11 @@ static struct netfs_io_request *netfs_pgpriv2_begin_copy_to_cache(
if (!creq->io_streams[1].avail)
goto cancel_put;
+ if (bvecq_buffer_init(&creq->load_cursor, creq->gfp, false) < 0)
+ goto cancel_put;
+ bvecq_pos_set(&creq->dispatch_cursor, &creq->load_cursor);
+ bvecq_pos_set(&creq->collect_cursor, &creq->dispatch_cursor);
+
__set_bit(NETFS_RREQ_OFFLOAD_COLLECTION, &creq->flags);
trace_netfs_copy2cache(rreq, creq);
trace_netfs_write(creq, netfs_write_trace_copy_to_cache);
@@ -143,6 +168,14 @@ void netfs_pgpriv2_copy_to_cache(struct netfs_io_request *rreq, struct folio *fo
return;
}
+ if (!creq->spare) {
+ creq->spare = bvecq_alloc_one(BVECQ_POOL_SLOTS, creq->gfp, false);
+ if (!creq->spare) {
+ set_bit(NETFS_RREQ_CANCEL_CACHING, &creq->flags);
+ return;
+ }
+ }
+
trace_netfs_folio(folio, netfs_folio_trace_pgpriv2_copy);
netfs_pgpriv2_copy_folio(creq, folio);
}
@@ -173,16 +206,18 @@ void netfs_pgpriv2_end_copy_to_cache(struct netfs_io_request *rreq)
*/
bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *creq)
{
- struct bvecq *bq = creq->buffer.tail;
- unsigned int slot = creq->buffer.first_tail_slot;
+ struct bvecq *bq = creq->collect_cursor.bvecq;
+ unsigned int slot;
uoff_t collected_to = creq->collected_to;
bool made_progress = false;
+ slot = creq->collect_cursor.slot;
while (!bvecq_acquire_slot(bq, slot)) {
- bq = rolling_buffer_delete_spent(&creq->buffer);
- if (!bq)
- return false;
- slot = 0;
+ creq->collect_cursor.slot = slot;
+ if (!bvecq_delete_spent(&creq->collect_cursor))
+ goto out;
+ bq = creq->collect_cursor.bvecq;
+ slot = creq->collect_cursor.slot;
}
for (;;) {
@@ -213,25 +248,25 @@ bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *creq)
creq->cleaned_to = fpos + fsize;
made_progress = true;
- /* Clean up the head bq. If we clear an entire bq, then
- * we can get rid of it provided it's not also the tail bq
- * being filled by the issuer.
+ /* Clean up the head segment. If we clear an entire segment,
+ * then we can get rid of it provided it's not also the tail
+ * segment being filled by the issuer.
*/
bq->bv[slot].bv_page = NULL;
slot++;
while (!bvecq_acquire_slot(bq, slot)) {
- bq = rolling_buffer_delete_spent(&creq->buffer);
- if (!bq)
- goto done;
- slot = 0;
+ creq->collect_cursor.slot = slot;
+ if (!bvecq_delete_spent(&creq->collect_cursor))
+ goto out;
+ bq = creq->collect_cursor.bvecq;
+ slot = creq->collect_cursor.slot;
}
if (fpos + fsize >= collected_to)
break;
}
- creq->buffer.tail = bq;
-done:
- creq->buffer.first_tail_slot = slot;
+ creq->collect_cursor.slot = slot;
+out:
return made_progress;
}
diff --git a/fs/netfs/read_retry.c b/fs/netfs/read_retry.c
index 142c3fb8dab17..7490b9ee1bf7c 100644
--- a/fs/netfs/read_retry.c
+++ b/fs/netfs/read_retry.c
@@ -12,6 +12,10 @@
static void netfs_reissue_read(struct netfs_io_request *rreq,
struct netfs_io_subrequest *subreq)
{
+ iov_iter_bvec_queue(&subreq->io_iter, ITER_DEST, subreq->io_buffer.bvecq,
+ subreq->io_buffer.slot, subreq->io_buffer.offset, subreq->len);
+ iov_iter_advance(&subreq->io_iter, subreq->transferred);
+
subreq->error = 0;
__clear_bit(NETFS_SREQ_MADE_PROGRESS, &subreq->flags);
__set_bit(NETFS_SREQ_IN_PROGRESS, &subreq->flags);
@@ -27,6 +31,7 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
{
struct netfs_io_subrequest *subreq;
struct netfs_io_stream *stream = &rreq->io_streams[0];
+ struct bvecq_pos dispatch_cursor = {};
struct list_head *next;
_enter("R=%x", rreq->debug_id);
@@ -46,9 +51,7 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
if (test_bit(NETFS_SREQ_FAILED, &subreq->flags))
break;
if (__test_and_clear_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags)) {
- __clear_bit(NETFS_SREQ_MADE_PROGRESS, &subreq->flags);
subreq->retry_count++;
- netfs_reset_iter(subreq);
netfs_get_subrequest(subreq, netfs_sreq_trace_get_resubmit);
netfs_reissue_read(rreq, subreq);
}
@@ -74,11 +77,12 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
do {
struct netfs_io_subrequest *from, *to, *tmp;
- struct iov_iter source;
uoff_t start, len;
size_t part;
bool boundary = false, subreq_superfluous = false;
+ bvecq_pos_unset(&dispatch_cursor);
+
/* Go through the subreqs and find the next span of contiguous
* buffer that we then rejig (cifs, for example, needs the
* rsize renegotiating) and reissue.
@@ -105,7 +109,8 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
break;
subreq = list_entry(next, struct netfs_io_subrequest, rreq_link);
- if (subreq->start + subreq->transferred != start + len ||
+ if (subreq->start != start + len ||
+ subreq->transferred > 0 ||
test_bit(NETFS_SREQ_BOUNDARY, &subreq->flags) ||
!test_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags))
break;
@@ -118,11 +123,14 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
/* Determine the set of buffers we're going to use. Each
* subreq gets a subset of a single overall contiguous buffer.
*/
- netfs_reset_iter(from);
- source = from->io_iter;
- source.count = len;
+ bvecq_pos_transfer(&dispatch_cursor, &from->io_buffer);
+ bvecq_pos_advance(&dispatch_cursor, from->transferred);
+ from->transferred = 0;
- /* Work through the sublist. */
+ /* Work through the sublist. The chain of buffers we're going
+ * to fill is attached to dispatch_cursor and we need to read
+ * 'len' amount of data from 'start'.
+ */
subreq = from;
list_for_each_entry_from(subreq, &stream->subrequests, rreq_link) {
if (!len) {
@@ -130,16 +138,21 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
break;
}
subreq->source = NETFS_DOWNLOAD_FROM_SERVER;
- subreq->start = start - subreq->transferred;
- subreq->len = len + subreq->transferred;
+ subreq->start = start;
+ subreq->len = len;
__clear_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags);
__clear_bit(NETFS_SREQ_MADE_PROGRESS, &subreq->flags);
subreq->retry_count++;
+ subreq->transferred = 0;
+
+ bvecq_pos_unset(&subreq->io_buffer);
+ bvecq_pos_set(&subreq->io_buffer, &dispatch_cursor);
trace_netfs_sreq(subreq, netfs_sreq_trace_retry);
/* Renegotiate max_len (rsize) */
- stream->sreq_max_len = subreq->len;
+ stream->sreq_max_len = len;
+ stream->sreq_max_segs = INT_MAX;
if (rreq->netfs_ops->prepare_read &&
rreq->netfs_ops->prepare_read(subreq) < 0) {
trace_netfs_sreq(subreq, netfs_sreq_trace_reprep_failed);
@@ -147,13 +160,12 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
goto abandon;
}
- part = umin(len, stream->sreq_max_len);
- if (unlikely(stream->sreq_max_segs))
- part = netfs_limit_iter(&source, 0, part, stream->sreq_max_segs);
- subreq->len = subreq->transferred + part;
- subreq->io_iter = source;
- iov_iter_truncate(&subreq->io_iter, part);
- iov_iter_advance(&source, part);
+ part = bvecq_slice(&dispatch_cursor,
+ umin(len, stream->sreq_max_len),
+ stream->sreq_max_segs,
+ &subreq->nr_segs);
+ subreq->len = part;
+
len -= part;
start += part;
if (!len) {
@@ -216,9 +228,7 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
trace_netfs_sreq(subreq, netfs_sreq_trace_retry);
stream->sreq_max_len = umin(len, rreq->rsize);
- stream->sreq_max_segs = 0;
- if (unlikely(stream->sreq_max_segs))
- part = netfs_limit_iter(&source, 0, part, stream->sreq_max_segs);
+ stream->sreq_max_segs = INT_MAX;
netfs_stat(&netfs_n_rh_download);
if (rreq->netfs_ops->prepare_read(subreq) < 0) {
@@ -227,11 +237,12 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
goto abandon;
}
- part = umin(len, stream->sreq_max_len);
- subreq->len = subreq->transferred + part;
- subreq->io_iter = source;
- iov_iter_truncate(&subreq->io_iter, part);
- iov_iter_advance(&source, part);
+ bvecq_pos_set(&subreq->io_buffer, &dispatch_cursor);
+ part = bvecq_slice(&dispatch_cursor,
+ umin(len, stream->sreq_max_len),
+ stream->sreq_max_segs,
+ &subreq->nr_segs);
+ subreq->len = part;
len -= part;
start += part;
@@ -245,12 +256,14 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
} while (!list_is_head(next, &stream->subrequests));
+out:
+ bvecq_pos_unset(&dispatch_cursor);
return;
/* If we hit an error, fail all remaining incomplete subrequests */
abandon_after:
if (list_is_last(&subreq->rreq_link, &stream->subrequests))
- return;
+ goto out;
subreq = list_next_entry(subreq, rreq_link);
abandon:
list_for_each_entry_from(subreq, &stream->subrequests, rreq_link) {
@@ -261,6 +274,7 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
__set_bit(NETFS_SREQ_FAILED, &subreq->flags);
__clear_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags);
}
+ goto out;
}
/*
@@ -300,26 +314,24 @@ void netfs_unlock_abandoned_read_pages(struct netfs_io_request *rreq)
if (test_bit(NETFS_RREQ_NEED_PUT_RA_REFS, &rreq->flags))
netfs_wait_for_put_ra_refs(rreq);
- for (p = rreq->buffer.tail; p; p = p->next) {
- for (int slot = rreq->buffer.first_tail_slot;
- bvecq_acquire_slot(p, slot);
- slot++) {
- struct folio *folio;
+ for (p = rreq->collect_cursor.bvecq; p; p = bvecq_next(p)) {
+ unsigned int nr_slots = bvecq_nr_slots_acquire(p);
+ for (int slot = 0; slot < nr_slots; slot++) {
if (!p->bv[slot].bv_page)
continue;
- folio = bvec_folio(&p->bv[slot]);
+ struct folio *folio = bvec_folio(&p->bv[slot]);
+
netfs_cancel_copy_to_cache(rreq, folio);
if (folio == rreq->no_unlock_folio &&
test_bit(NETFS_RREQ_NO_UNLOCK_FOLIO, &rreq->flags)) {
_debug("no unlock");
- } else {
- trace_netfs_folio(folio, netfs_folio_trace_abandon);
- folio_unlock(folio);
+ continue;
}
+ trace_netfs_folio(folio, netfs_folio_trace_abandon);
+ folio_unlock(folio);
}
- rreq->buffer.first_tail_slot = 0;
}
}
diff --git a/fs/netfs/read_single.c b/fs/netfs/read_single.c
index b248e34bd0c86..c70941121de04 100644
--- a/fs/netfs/read_single.c
+++ b/fs/netfs/read_single.c
@@ -101,7 +101,11 @@ static int netfs_single_dispatch_read(struct netfs_io_request *rreq)
subreq->start = 0;
subreq->len = rreq->len;
- subreq->io_iter = rreq->buffer.iter;
+
+ bvecq_pos_set(&subreq->io_buffer, &rreq->dispatch_cursor);
+
+ iov_iter_bvec_queue(&subreq->io_iter, ITER_DEST, subreq->io_buffer.bvecq,
+ subreq->io_buffer.slot, subreq->io_buffer.offset, subreq->len);
netfs_queue_read(rreq, subreq);
@@ -174,6 +178,15 @@ ssize_t netfs_read_single(struct inode *inode, struct file *file, struct iov_ite
if (IS_ERR(rreq))
return PTR_ERR(rreq);
+ ret = netfs_extract_iter(iter, rreq->len, INT_MAX, &rreq->dispatch_cursor.bvecq,
+ 0, rreq->gfp);
+ if (ret < 0)
+ goto cleanup_free;
+ if (ret < rreq->len) {
+ ret = -EIO;
+ goto cleanup_free;
+ }
+
rreq->progress_at = rreq->len;
ret = netfs_single_begin_cache_read(rreq, ictx);
@@ -183,7 +196,6 @@ ssize_t netfs_read_single(struct inode *inode, struct file *file, struct iov_ite
netfs_stat(&netfs_n_rh_read_single);
trace_netfs_read(rreq, 0, rreq->len, netfs_read_trace_read_single);
- rreq->buffer.iter = *iter;
netfs_single_dispatch_read(rreq);
ret = netfs_wait_for_read(rreq);
diff --git a/fs/netfs/rolling_buffer.c b/fs/netfs/rolling_buffer.c
deleted file mode 100644
index 66ce9add40122..0000000000000
--- a/fs/netfs/rolling_buffer.c
+++ /dev/null
@@ -1,182 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/* Rolling buffer helpers
- *
- * Copyright (C) 2024 Red Hat, Inc. All Rights Reserved.
- * Written by David Howells (dhowells@redhat.com)
- */
-
-#include <linux/bitops.h>
-#include <linux/mempool.h>
-#include <linux/pagemap.h>
-#include <linux/rolling_buffer.h>
-#include <linux/slab.h>
-#include "internal.h"
-
-/*
- * Initialise a rolling buffer. We allocate an empty folio queue struct to so
- * that the pointers can be independently driven by the producer and the
- * consumer.
- */
-int rolling_buffer_init(struct rolling_buffer *roll, unsigned int direction,
- gfp_t gfp, bool for_writeback)
-{
- struct bvecq *bq;
-
- roll->for_writeback = for_writeback;
-
- bq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, for_writeback);
- if (!bq)
- return -ENOMEM;
-
- roll->head = bq;
- roll->tail = bq;
- iov_iter_bvec_queue(&roll->iter, direction, bq, 0, 0, 0);
- return 0;
-}
-
-/*
- * Add another bvecq to a rolling buffer if there's no space left.
- */
-int rolling_buffer_make_space(struct rolling_buffer *roll, gfp_t gfp)
-{
- struct bvecq *bq, *head = roll->head;
-
- if (!bvecq_is_full(head))
- return 0;
-
- bq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, roll->for_writeback);
- if (!bq)
- return -ENOMEM;
-
- roll->head = bq;
- if (bvecq_is_full(head)) {
- /* Make sure we don't leave the master iterator pointing to a
- * block that might get immediately consumed.
- */
- if (roll->iter.bvecq == head &&
- roll->iter.bvecq_slot == head->nr_slots) {
- roll->iter.bvecq = bq;
- roll->iter.bvecq_slot = 0;
- }
- }
-
- /* Make sure the initialisation is stored before the next pointer.
- *
- * [!] NOTE: After we set head->next, the consumer is at liberty to
- * immediately delete the old head.
- */
- bvecq_append(head, bq);
- return 0;
-}
-
-/*
- * Decant the entire list of folios to read into a rolling buffer.
- */
-ssize_t rolling_buffer_bulk_load_from_ra(struct rolling_buffer *roll,
- struct readahead_control *ractl,
- gfp_t gfp)
-{
- struct bvecq *bq;
- size_t loaded = 0;
-
- while (ractl->_nr_pages - ractl->_batch_count > 0) {
- struct page **pages;
- unsigned int nr;
-
- /* Allocate a bvecq to put some folios into and attach it to
- * the rolling buffer.
- */
- bq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, false);
- if (!bq)
- goto nomem_unlock;
- bq->mem_type = BVECQ_MEM_EXTERNAL; /* Folio cleanup handled separately. */
-
- if (!roll->tail)
- roll->tail = bq;
- else
- bvecq_append(roll->head, bq);
- roll->head = bq;
-
- /* Get a bunch of folios and note their sizes. */
- pages = (struct page **)(bq->bv + bq->max_slots);
- pages -= bq->max_slots;
- nr = __readahead_batch(ractl, pages, bq->max_slots);
- if (WARN_ON_ONCE(!nr))
- break;
-
- for (int slot = 0; slot < nr; slot++) {
- struct folio *folio = page_folio(pages[slot]);
- size_t len = folio_size(folio);
-
- bvec_set_folio(&bq->bv[slot], folio, len, 0);
- loaded += len;
- trace_netfs_folio(folio, netfs_folio_trace_read);
- }
-
- bvecq_filled_to(bq, nr);
- }
-
- WRITE_ONCE(roll->iter.count, loaded);
- iov_iter_bvec_queue(&roll->iter, ITER_DEST, roll->tail, 0, 0, loaded);
- return loaded;
-
-nomem_unlock:
- for (bq = roll->tail; bq; bq = bq->next) {
- for (int slot = 0; slot < bq->nr_slots; slot++) {
- struct folio *folio = bvec_folio(&bq->bv[slot]);
-
- folio_unlock(folio);
- folio_put(folio);
- }
- }
- rolling_buffer_clear(roll);
- roll->head = NULL;
- roll->tail = NULL;
- return -ENOMEM;
-}
-
-/*
- * Append a folio to the rolling buffer.
- */
-ssize_t rolling_buffer_append(struct rolling_buffer *roll, struct folio *folio,
- gfp_t gfp)
-{
- ssize_t size = folio_size(folio);
- int slot;
-
- if (rolling_buffer_make_space(roll, gfp) < 0)
- return -ENOMEM;
-
- slot = roll->head->nr_slots;
- bvec_set_folio(&roll->head->bv[slot], folio, size, 0);
- bvecq_filled_to(roll->head, slot + 1);
-
- WRITE_ONCE(roll->iter.count, roll->iter.count + size);
- return size;
-}
-
-/*
- * Delete a spent buffer from a rolling queue and return the next in line. We
- * don't return the last buffer to keep the pointers independent, but return
- * NULL instead.
- */
-struct bvecq *rolling_buffer_delete_spent(struct rolling_buffer *roll)
-{
- struct bvecq *spent = roll->tail, *next = bvecq_next(spent);
-
- if (!next)
- return NULL;
- next->prev = NULL;
- roll->tail = next;
- spent->next = NULL;
- bvecq_put(spent);
- return next;
-}
-
-/*
- * Clear out a rolling queue.
- */
-void rolling_buffer_clear(struct rolling_buffer *roll)
-{
- bvecq_put(roll->tail);
-}
diff --git a/fs/netfs/write_collect.c b/fs/netfs/write_collect.c
index 91b42820c8925..dcacbab254b92 100644
--- a/fs/netfs/write_collect.c
+++ b/fs/netfs/write_collect.c
@@ -114,12 +114,12 @@ int netfs_folio_written_back(struct folio *folio)
static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,
unsigned int *notes)
{
- struct bvecq *bq = wreq->buffer.tail;
- unsigned int slot = wreq->buffer.first_tail_slot;
+ struct bvecq *bq = wreq->collect_cursor.bvecq;
+ unsigned int slot = wreq->collect_cursor.slot;
uoff_t collected_to = wreq->collected_to;
if (WARN_ON_ONCE(!bq)) {
- pr_err("[!] Writeback unlock found empty rolling buffer!\n");
+ pr_err("[!] Writeback unlock found empty buffer!\n");
netfs_dump_request(wreq);
return;
}
@@ -130,19 +130,28 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,
return;
}
- while (!bvecq_acquire_slot(bq, slot)) {
- bq = rolling_buffer_delete_spent(&wreq->buffer);
- if (!bq)
- return;
- slot = 0;
- }
-
for (;;) {
struct folio *folio;
struct netfs_folio *finfo;
uoff_t fpos, fend;
size_t fsize, flen;
+ /* Try to clean up the head of the queue if it appears to be
+ * used up, but we need to be very careful - the cleanup can
+ * catch the dispatcher, which could lead to us having nothing
+ * left in the queue, causing the front and back pointers to
+ * end up on different tracks. To avoid this, we must always
+ * keep at least one segment in the queue.
+ */
+ if (!bvecq_acquire_slot(bq, slot)) {
+ wreq->collect_cursor.slot = slot;
+ if (!bvecq_delete_spent(&wreq->collect_cursor))
+ return;
+ bq = wreq->collect_cursor.bvecq;
+ slot = wreq->collect_cursor.slot;
+ continue;
+ }
+
folio = bvec_folio(&bq->bv[slot]);
if (WARN_ONCE(!folio_test_writeback(folio),
"R=%08x: folio %lx is not under writeback\n",
@@ -166,26 +175,13 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,
wreq->cleaned_to = fpos + fsize;
*notes |= MADE_PROGRESS;
- /* Clean up the head bq. If we clear an entire bq, then
- * we can get rid of it provided it's not also the tail bq
- * being filled by the issuer.
- */
bq->bv[slot].bv_page = NULL;
slot++;
- while (!bvecq_acquire_slot(bq, slot)) {
- bq = rolling_buffer_delete_spent(&wreq->buffer);
- if (!bq)
- goto done;
- slot = 0;
- }
-
if (fpos + fsize >= collected_to)
break;
}
- wreq->buffer.tail = bq;
-done:
- wreq->buffer.first_tail_slot = slot;
+ wreq->collect_cursor.slot = slot;
}
/*
@@ -230,7 +226,8 @@ static void netfs_collect_write_results(struct netfs_io_request *wreq)
trace_netfs_rreq(wreq, netfs_rreq_trace_collect);
reassess_streams:
- issued_to = atomic64_read(&wreq->issued_to);
+ /* Order reading the issued_to point before reading the queue it refers to. */
+ issued_to = atomic64_read_acquire(&wreq->issued_to);
smp_rmb();
collected_to = ULLONG_MAX;
if (wreq->origin == NETFS_WRITEBACK ||
@@ -560,8 +557,12 @@ void netfs_write_subrequest_terminated(void *_op, ssize_t transferred_or_error)
* data is tracked.
*/
netfs_stat(&netfs_n_wh_write_failed);
- if (test_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags))
- break;
+ if (test_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags)) {
+ /* We don't retry failed cache writes. */
+ __clear_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags);
+ if (!subreq->error)
+ subreq->error = -ENOBUFS;
+ }
trace_netfs_failure(wreq, subreq, transferred_or_error, netfs_fail_write);
__set_bit(NETFS_SREQ_CANCELLED, &subreq->flags);
diff --git a/fs/netfs/write_issue.c b/fs/netfs/write_issue.c
index f0f4786666512..8fab5cf00d7b6 100644
--- a/fs/netfs/write_issue.c
+++ b/fs/netfs/write_issue.c
@@ -107,10 +107,6 @@ struct netfs_io_request *netfs_create_write_req(struct address_space *mapping,
ictx = netfs_inode(wreq->inode);
if (is_cacheable)
fscache_begin_write_operation(&wreq->cache_resources, netfs_i_cookie(ictx));
- if (rolling_buffer_init(&wreq->buffer, ITER_SOURCE, wreq->gfp,
- (origin == NETFS_WRITEBACK ||
- origin == NETFS_WRITEBACK_SINGLE)) < 0)
- goto nomem;
wreq->cleaned_to = wreq->start;
if (wreq->cache_resources.dio_size > 1)
@@ -135,9 +131,6 @@ struct netfs_io_request *netfs_create_write_req(struct address_space *mapping,
}
return wreq;
-nomem:
- netfs_put_failed_request(wreq);
- return ERR_PTR(-ENOMEM);
}
/**
@@ -163,22 +156,14 @@ void netfs_prepare_write(struct netfs_io_request *wreq,
uoff_t start)
{
struct netfs_io_subrequest *subreq;
- struct iov_iter *wreq_iter = &wreq->buffer.iter;
-
- /* Make sure we don't point the iterator at a used-up bvecq struct
- * being used as a placeholder to prevent the queue from collapsing.
- * In such a case, extend the queue.
- */
- if (iov_iter_is_bvecq(wreq_iter) &&
- !bvecq_acquire_slot(wreq_iter->bvecq, wreq_iter->bvecq_slot))
- rolling_buffer_make_space(&wreq->buffer, wreq->gfp);
subreq = netfs_alloc_subrequest(wreq, stream->source);
if (!subreq)
return;
subreq->start = start;
subreq->stream_nr = stream->stream_nr;
- subreq->io_iter = *wreq_iter;
+
+ bvecq_pos_set(&subreq->io_buffer, &wreq->dispatch_cursor);
_enter("R=%x[%x]", wreq->debug_id, subreq->debug_index);
@@ -259,15 +244,14 @@ static void netfs_do_issue_write(struct netfs_io_stream *stream,
}
void netfs_reissue_write(struct netfs_io_stream *stream,
- struct netfs_io_subrequest *subreq,
- struct iov_iter *source)
+ struct netfs_io_subrequest *subreq)
{
- size_t size = subreq->len - subreq->transferred;
-
// TODO: Use encrypted buffer
- subreq->io_iter = *source;
- iov_iter_advance(source, size);
- iov_iter_truncate(&subreq->io_iter, size);
+ iov_iter_bvec_queue(&subreq->io_iter, ITER_SOURCE,
+ subreq->io_buffer.bvecq, subreq->io_buffer.slot,
+ subreq->io_buffer.offset,
+ subreq->len);
+ iov_iter_advance(&subreq->io_iter, subreq->transferred);
subreq->retry_count++;
subreq->error = 0;
@@ -285,8 +269,12 @@ void netfs_issue_write(struct netfs_io_request *wreq,
if (!subreq)
return;
+ iov_iter_bvec_queue(&subreq->io_iter, ITER_SOURCE,
+ subreq->io_buffer.bvecq, subreq->io_buffer.slot,
+ subreq->io_buffer.offset,
+ subreq->len);
+
stream->construct = NULL;
- subreq->io_iter.count = subreq->len;
netfs_do_issue_write(stream, subreq);
}
@@ -323,7 +311,6 @@ size_t netfs_advance_write(struct netfs_io_request *wreq,
_debug("part %zx/%zx %zx/%zx", subreq->len, stream->sreq_max_len, part, len);
subreq->len += part;
subreq->nr_segs++;
- stream->submit_extendable_to -= part;
if (subreq->len >= stream->sreq_max_len ||
subreq->nr_segs >= stream->sreq_max_segs ||
@@ -347,7 +334,8 @@ static int netfs_write_folio(struct netfs_io_request *wreq,
struct netfs_io_stream *stream;
struct netfs_group *fgroup; /* TODO: Use this with ceph */
struct netfs_folio *finfo;
- size_t iter_off = 0;
+ struct bvecq *queue = wreq->load_cursor.bvecq;
+ unsigned int slot;
size_t fsize = folio_size(folio), flen = fsize, foff = 0;
uoff_t fpos = folio_pos(folio), i_size;
bool to_eof = false, streamw = false;
@@ -355,12 +343,20 @@ static int netfs_write_folio(struct netfs_io_request *wreq,
_enter("");
- if (rolling_buffer_make_space(&wreq->buffer, wreq->gfp) < 0)
- return -ENOMEM;
+ if (!wreq->spare) {
+ wreq->spare = bvecq_alloc_one(BVECQ_POOL_SLOTS, wreq->gfp, true);
+ if (!wreq->spare)
+ return -ENOMEM;
+ }
- /* netfs_perform_write() may shift i_size around the page or from out
- * of the page to beyond it, but cannot move i_size into or through the
- * page since we have it locked.
+ /* netfs_perform_write() may shift i_size around the folio or from out
+ * of the folio to beyond it, but cannot move i_size into or through
+ * the folio since we have it locked.
+ *
+ * Truncate could in theory move i_size into or before the folio, but
+ * it should take steps to prevent writeback from happening
+ * concurrently and should wait for any in-progress writebacks before
+ * proceeding.
*/
i_size = i_size_read(wreq->inode);
@@ -452,8 +448,29 @@ static int netfs_write_folio(struct netfs_io_request *wreq,
trace_netfs_folio(folio, netfs_folio_trace_store_plus);
}
+ /* Institute a new bvec queue segment if the current one is full or if
+ * we encounter a discontiguity. The discontiguity break is important
+ * when it comes to bulk unlocking folios by file range.
+ */
+ if (bvecq_is_full(queue) ||
+ (fpos != wreq->last_end && wreq->last_end > 0)) {
+ bvecq_buffer_append(&wreq->load_cursor, wreq->spare);
+ wreq->spare = NULL;
+
+ queue = wreq->load_cursor.bvecq;
+ bvecq_pos_move(&wreq->dispatch_cursor, queue);
+ wreq->dispatch_cursor.slot = 0;
+ }
+
/* Attach the folio to the rolling buffer. */
- rolling_buffer_append(&wreq->buffer, folio, wreq->gfp);
+ slot = queue->nr_slots;
+ bvec_set_folio(&queue->bv[slot], folio, fsize, 0);
+ trace_netfs_bv_slot(queue, slot);
+ slot++;
+ bvecq_filled_to(queue, slot);
+ wreq->load_cursor.slot = slot;
+ wreq->load_cursor.offset = 0;
+ wreq->last_end = fpos + fsize;
/* Move the submission point forward to allow for write-streaming data
* not starting at the front of the page. We don't do write-streaming
@@ -462,10 +479,19 @@ static int netfs_write_folio(struct netfs_io_request *wreq,
* Also skip uploading for data that's been read and just needs copying
* to the cache.
*/
+ bvecq_pos_nudge(&wreq->dispatch_cursor);
+
for (int s = 0; s < NR_IO_STREAMS; s++) {
+ size_t soff = foff, slen = flen, alignment = 1;
+
stream = &wreq->io_streams[s];
- stream->submit_off = foff;
- stream->submit_len = flen;
+ if (stream->source == NETFS_WRITE_TO_CACHE)
+ alignment = wreq->cache_resources.dio_size;
+ stream = &wreq->io_streams[s];
+ stream->submit_off = round_down(soff, alignment);
+ slen += foff - stream->submit_off;
+ stream->submit_len = round_up(slen, alignment);
+
if (!stream->avail ||
(stream->source == NETFS_WRITE_TO_CACHE && streamw) ||
(stream->source == NETFS_UPLOAD_TO_SERVER &&
@@ -499,14 +525,10 @@ static int netfs_write_folio(struct netfs_io_request *wreq,
break;
stream = &wreq->io_streams[choose_s];
- /* Advance the iterator(s). */
- if (stream->submit_off > iter_off) {
- rolling_buffer_advance(&wreq->buffer, stream->submit_off - iter_off);
- iter_off = stream->submit_off;
- }
+ /* Advance the cursor. */
+ wreq->dispatch_cursor.offset = stream->submit_off;
atomic64_set(&wreq->issued_to, fpos + stream->submit_off);
- stream->submit_extendable_to = fsize - stream->submit_off;
part = netfs_advance_write(wreq, stream, fpos + stream->submit_off,
stream->submit_len, to_eof);
stream->submit_off += part;
@@ -518,9 +540,9 @@ static int netfs_write_folio(struct netfs_io_request *wreq,
debug = true;
}
- if (fsize > iter_off)
- rolling_buffer_advance(&wreq->buffer, fsize - iter_off);
- atomic64_set(&wreq->issued_to, fpos + fsize);
+ bvecq_pos_step(&wreq->dispatch_cursor);
+ /* Order loading the queue before updating the issue_to point */
+ atomic64_set_release(&wreq->issued_to, fpos + fsize);
if (!debug)
kdebug("R=%x: No submit", wreq->debug_id);
@@ -581,6 +603,11 @@ int netfs_writepages(struct address_space *mapping,
goto couldnt_start;
}
+ if (bvecq_buffer_init(&wreq->load_cursor, wreq->gfp, true) < 0)
+ goto nomem;
+ bvecq_pos_set(&wreq->dispatch_cursor, &wreq->load_cursor);
+ bvecq_pos_set(&wreq->collect_cursor, &wreq->dispatch_cursor);
+
__set_bit(NETFS_RREQ_OFFLOAD_COLLECTION, &wreq->flags);
trace_netfs_write(wreq, netfs_write_trace_writeback);
netfs_stat(&netfs_n_wh_writepages);
@@ -605,12 +632,17 @@ int netfs_writepages(struct address_space *mapping,
} while ((folio = writeback_iter(mapping, wbc, folio, &error)));
netfs_end_issue_write(wreq);
+ bvecq_pos_unset(&wreq->load_cursor);
+ bvecq_pos_unset(&wreq->dispatch_cursor);
netfs_wake_collector(wreq);
netfs_put_request(wreq, netfs_rreq_trace_put_return);
_leave(" = %d", error);
return error;
+nomem:
+ error = -ENOMEM;
+ netfs_put_failed_request(wreq);
couldnt_start:
if (error == -ENOMEM) {
folio_redirty_for_writepage(wbc, folio);
@@ -631,23 +663,28 @@ EXPORT_SYMBOL(netfs_writepages);
* netfs_writeback_single - Write back a monolithic payload
* @mapping: The mapping to write from
* @wbc: Hints from the VM
- * @iter: Data to write.
+ * @iter: Buffer to write from
+ * @len: Amount to write from buffer
*
* Write a monolithic, non-pagecache object back to the server and/or the
- * cache. The caller must explicitly set NETFS_RREQ_UPLOAD_TO_SERVER when
- * initialising the request if it wants the data to be written to the server
- * (for AFS directories and symlinks, this is not possible; things like mkdir,
- * symlink, rmdir and unlink must be used instead).
+ * cache. There's a maximum of one subrequest per stream. The buffer should be
+ * rounded out sufficiently that it can accommodate cache DIO rounding.
+ *
+ * The caller must explicitly set NETFS_RREQ_UPLOAD_TO_SERVER when initialising
+ * the request if it wants the data to be written to the server (for AFS
+ * directories and symlinks, this is not possible; things like mkdir, symlink,
+ * rmdir and unlink must be used instead).
*
* Return: 0 if successful; 1 if skipped due to lock conflict and WB_SYNC_NONE;
* or a negative error code.
*/
int netfs_writeback_single(struct address_space *mapping,
struct writeback_control *wbc,
- struct iov_iter *iter)
+ struct iov_iter *iter, size_t len)
{
struct netfs_io_request *wreq;
struct netfs_inode *ictx = netfs_inode(mapping->host);
+ size_t clen;
int ret;
if (!netfs_wb_begin(ictx, wbc->sync_mode == WB_SYNC_NONE)) {
@@ -661,10 +698,27 @@ int netfs_writeback_single(struct address_space *mapping,
ret = PTR_ERR(wreq);
goto couldnt_start;
}
+ wreq->len = len;
+ clen = len;
+
+ if (wreq->cache_resources.dio_size > 1) {
+ clen = round_up(len, wreq->cache_resources.dio_size);
+ if (clen > iov_iter_count(iter)) {
+ ret = -EIO;
+ goto cleanup_free;
+ }
+ }
- wreq->buffer.iter = *iter;
- wreq->len = iov_iter_count(iter);
- wreq->submitted = wreq->len;
+ ret = netfs_extract_iter(iter, clen, INT_MAX, &wreq->dispatch_cursor.bvecq,
+ 0, wreq->gfp);
+ if (ret < 0)
+ goto cleanup_free;
+ if (ret < clen) {
+ ret = -EIO;
+ goto cleanup_free;
+ }
+
+ bvecq_pos_set(&wreq->collect_cursor, &wreq->dispatch_cursor);
__set_bit(NETFS_RREQ_OFFLOAD_COLLECTION, &wreq->flags);
trace_netfs_write(wreq, netfs_write_trace_writeback_single);
@@ -685,12 +739,14 @@ int netfs_writeback_single(struct address_space *mapping,
subreq = stream->construct;
subreq->len = wreq->len;
+ if (stream->source == NETFS_WRITE_TO_CACHE)
+ subreq->len = clen;
stream->submit_len = subreq->len;
- stream->submit_extendable_to = round_up(wreq->len, PAGE_SIZE);
netfs_issue_write(wreq, stream);
}
+ wreq->submitted = wreq->len;
netfs_all_subreqs_queued(wreq);
netfs_wake_collector(wreq);
@@ -705,6 +761,8 @@ int netfs_writeback_single(struct address_space *mapping,
_leave(" = %d", ret);
return ret;
+cleanup_free:
+ netfs_put_failed_request(wreq);
couldnt_start:
netfs_wb_end(ictx);
_leave(" = %d", ret);
diff --git a/fs/netfs/write_retry.c b/fs/netfs/write_retry.c
index 2f20577563e14..235e75eb10914 100644
--- a/fs/netfs/write_retry.c
+++ b/fs/netfs/write_retry.c
@@ -17,15 +17,17 @@
static void netfs_retry_write_stream(struct netfs_io_request *wreq,
struct netfs_io_stream *stream)
{
+ struct bvecq_pos dispatch_cursor = {};
struct list_head *next;
_enter("R=%x[%x:]", wreq->debug_id, stream->stream_nr);
if (list_empty(&stream->subrequests))
return;
+ if (WARN_ON_ONCE(stream->source != NETFS_UPLOAD_TO_SERVER))
+ return; /* Shouldn't be retrying cache writes. */
- if (stream->source == NETFS_UPLOAD_TO_SERVER &&
- wreq->netfs_ops->retry_request)
+ if (wreq->netfs_ops->retry_request)
wreq->netfs_ops->retry_request(wreq, stream);
if (unlikely(stream->failed))
@@ -39,12 +41,8 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,
if (test_bit(NETFS_SREQ_FAILED, &subreq->flags))
break;
if (__test_and_clear_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags)) {
- struct iov_iter source;
-
- netfs_reset_iter(subreq);
- source = subreq->io_iter;
netfs_get_subrequest(subreq, netfs_sreq_trace_get_resubmit);
- netfs_reissue_write(stream, subreq, &source);
+ netfs_reissue_write(stream, subreq);
}
}
return;
@@ -54,11 +52,12 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,
do {
struct netfs_io_subrequest *subreq = NULL, *from, *to, *tmp;
- struct iov_iter source;
uoff_t start, len;
size_t part;
bool boundary = false;
+ bvecq_pos_unset(&dispatch_cursor);
+
/* Go through the stream and find the next span of contiguous
* data that we then rejig (cifs, for example, needs the wsize
* renegotiating) and reissue.
@@ -70,7 +69,7 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,
if (test_bit(NETFS_SREQ_FAILED, &from->flags) ||
!test_bit(NETFS_SREQ_NEED_RETRY, &from->flags))
- return;
+ goto out;
for (;;) {
/* Read pointer to subreq before reading subreq state. */
@@ -79,7 +78,8 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,
break;
subreq = list_entry(next, struct netfs_io_subrequest, rreq_link);
- if (subreq->start + subreq->transferred != start + len ||
+ if (subreq->start != start + len ||
+ subreq->transferred > 0 ||
test_bit(NETFS_SREQ_BOUNDARY, &subreq->flags) ||
!test_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags))
break;
@@ -90,11 +90,13 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,
/* Determine the set of buffers we're going to use. Each
* subreq gets a subset of a single overall contiguous buffer.
*/
- netfs_reset_iter(from);
- source = from->io_iter;
- source.count = len;
+ bvecq_pos_transfer(&dispatch_cursor, &from->io_buffer);
+ bvecq_pos_advance(&dispatch_cursor, from->transferred);
- /* Work through the sublist. */
+ /* Work through the sublist. The chain of buffers we're going
+ * to fill is attached to dispatch_cursor and we need to read
+ * 'len' amount of data from 'start'.
+ */
subreq = from;
list_for_each_entry_from(subreq, &stream->subrequests, rreq_link) {
if (!len)
@@ -104,16 +106,22 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,
subreq->len = len;
__clear_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags);
trace_netfs_sreq(subreq, netfs_sreq_trace_retry);
+ subreq->transferred = 0;
+
+ bvecq_pos_unset(&subreq->io_buffer);
/* Renegotiate max_len (wsize) */
stream->sreq_max_len = len;
+ stream->sreq_max_segs = INT_MAX;
stream->prepare_write(subreq);
- part = umin(len, stream->sreq_max_len);
- if (unlikely(stream->sreq_max_segs))
- part = netfs_limit_iter(&source, 0, part, stream->sreq_max_segs);
+ bvecq_pos_set(&subreq->io_buffer, &dispatch_cursor);
+ part = bvecq_slice(&dispatch_cursor,
+ umin(len, stream->sreq_max_len),
+ stream->sreq_max_segs,
+ &subreq->nr_segs);
subreq->len = part;
- subreq->transferred = 0;
+
len -= part;
start += part;
if (len && subreq == to &&
@@ -121,7 +129,7 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,
boundary = true;
netfs_get_subrequest(subreq, netfs_sreq_trace_get_resubmit);
- netfs_reissue_write(stream, subreq, &source);
+ netfs_reissue_write(stream, subreq);
if (subreq == to)
break;
}
@@ -172,17 +180,19 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,
netfs_stat(&netfs_n_wh_upload);
stream->sreq_max_len = umin(len, wreq->wsize);
break;
- case NETFS_WRITE_TO_CACHE:
- netfs_stat(&netfs_n_wh_write);
- break;
default:
WARN_ON_ONCE(1);
}
stream->prepare_write(subreq);
- part = umin(len, stream->sreq_max_len);
+ bvecq_pos_set(&subreq->io_buffer, &dispatch_cursor);
+ part = bvecq_slice(&dispatch_cursor,
+ umin(len, stream->sreq_max_len),
+ stream->sreq_max_segs,
+ &subreq->nr_segs);
subreq->len = subreq->transferred + part;
+
len -= part;
start += part;
if (!len && boundary) {
@@ -190,13 +200,16 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,
boundary = false;
}
- netfs_reissue_write(stream, subreq, &source);
+ netfs_reissue_write(stream, subreq);
if (!len)
break;
} while (len);
} while (!list_is_head(next, &stream->subrequests));
+
+out:
+ bvecq_pos_unset(&dispatch_cursor);
}
/*
diff --git a/include/linux/bvecq.h b/include/linux/bvecq.h
index b984aaa449088..389f6407cb846 100644
--- a/include/linux/bvecq.h
+++ b/include/linux/bvecq.h
@@ -54,6 +54,16 @@ struct bvecq {
/* Number of slots in a 4K bvecq. */
#define BVECQ_4KB_SLOTS ((4096 - sizeof(struct bvecq)) / sizeof(struct bio_vec))
+/*
+ * Position in a bio_vec queue. The bvecq holds a ref on the queue segment it
+ * points to.
+ */
+struct bvecq_pos {
+ struct bvecq *bvecq; /* The first bvecq */
+ unsigned int offset; /* The offset within the starting slot */
+ u16 slot; /* The starting slot */
+};
+
void bvecq_dump(const struct bvecq *bq);
struct bvecq *bvecq_alloc_one(size_t nr_slots, gfp_t gfp, bool for_writeback);
struct bvecq *bvecq_alloc_chain(size_t nr_slots, gfp_t gfp, bool for_writeback);
@@ -61,6 +71,13 @@ struct bvecq *bvecq_alloc_buffer2(size_t size, unsigned int pre_slots, gfp_t gfp
bool for_writeback);
void bvecq_put(struct bvecq *bq);
int bvecq_expand_buffer(struct bvecq **_buffer, size_t *_cur_size, size_t size, gfp_t gfp);
+int bvecq_buffer_init(struct bvecq_pos *pos, gfp_t gfp, bool for_writeback);
+void bvecq_buffer_append(struct bvecq_pos *pos, struct bvecq *bq);
+void bvecq_pos_advance(struct bvecq_pos *pos, size_t amount);
+ssize_t bvecq_zero(struct bvecq_pos *pos, size_t amount);
+size_t bvecq_slice(struct bvecq_pos *pos, size_t max_size,
+ unsigned int max_slots, unsigned int *_nr_slots);
+ssize_t bvecq_load_from_ra(struct bvecq_pos *pos, struct readahead_control *ractl);
/**
* bvecq_alloc_buffer - Allocate a bvecq chain and populate with buffers
@@ -163,4 +180,171 @@ static inline struct bvecq *bvecq_next(const struct bvecq *bq)
return smp_load_acquire(&bq->next);
}
+/**
+ * bvecq_pos_set - Set one position to be the same as another
+ * @pos: The position object to set
+ * @at: The source position.
+ *
+ * Set @pos to have the same position as @at. This may take a ref on the
+ * bvecq pointed to.
+ */
+static inline void bvecq_pos_set(struct bvecq_pos *pos, const struct bvecq_pos *at)
+{
+ *pos = *at;
+ bvecq_get(pos->bvecq);
+}
+
+/**
+ * bvecq_pos_unset - Unset a position
+ * @pos: The position object to unset
+ *
+ * Unset @pos. This does any needed ref cleanup.
+ */
+static inline void bvecq_pos_unset(struct bvecq_pos *pos)
+{
+ bvecq_put(pos->bvecq);
+ pos->bvecq = NULL;
+ pos->slot = 0;
+ pos->offset = 0;
+}
+
+/**
+ * bvecq_pos_transfer - Transfer one position to another, clearing the first
+ * @pos: The position object to set
+ * @from: The source position to clear.
+ *
+ * Set @pos to have the same position as @from and then clear @from. This may
+ * transfer a ref on the bvecq pointed to.
+ */
+static inline void bvecq_pos_transfer(struct bvecq_pos *pos, struct bvecq_pos *from)
+{
+ *pos = *from;
+ from->bvecq = NULL;
+ from->slot = 0;
+ from->offset = 0;
+}
+
+/**
+ * bvecq_pos_move - Update a position to a new bvecq
+ * @pos: The position object to update.
+ * @to: The new bvecq to point at.
+ *
+ * Update @pos to point to @to if it doesn't already do so. This may
+ * manipulate refs on the bvecqs pointed to.
+ */
+static inline void bvecq_pos_move(struct bvecq_pos *pos, struct bvecq *to)
+{
+ struct bvecq *old = pos->bvecq;
+
+ if (old != to) {
+ pos->bvecq = bvecq_get(to);
+ bvecq_put(old);
+ }
+}
+
+/**
+ * bvecq_pos_nudge - Nudge a position onto the next segment if current used up
+ * @pos: The position object to nudge.
+ *
+ * Update @pos to point to the next segment in the chain if we've used up the
+ * current segment. This may manipulate refs on the bvecqs pointed to.
+ *
+ * Return: true if found a new segment, false if hit the end.
+ */
+static inline bool bvecq_pos_nudge(struct bvecq_pos *pos)
+{
+ struct bvecq *bq = pos->bvecq;
+
+ for (;;) {
+ if (!bvecq_acquire_slot(bq, pos->slot)) {
+ bq = bvecq_next(bq);
+ if (!bq)
+ return false;
+ if (bvecq_acquire_slot(bq, pos->slot))
+ continue; /* More slots got added. */
+ bvecq_pos_move(pos, bq);
+ pos->slot = 0;
+ pos->offset = 0;
+ continue;
+ }
+ if (pos->offset >= bq->bv[pos->slot].bv_len) {
+ pos->slot++;
+ pos->offset = 0;
+ continue;
+ }
+ return true;
+ }
+}
+
+/**
+ * bvecq_pos_step - Step a position to the next slot if possible
+ * @pos: The position object to step.
+ *
+ * Update @pos to point to the next slot in the queue if not at the end. This
+ * may manipulate refs on the bvecqs pointed to.
+ *
+ * Return: true if successful, false if was at the end.
+ */
+static inline bool bvecq_pos_step(struct bvecq_pos *pos)
+{
+ struct bvecq *bq = pos->bvecq, *next;
+
+ pos->slot++;
+ pos->offset = 0;
+ if (bvecq_acquire_slot(bq, pos->slot))
+ return true;
+ next = bvecq_next(bq);
+ if (!next)
+ return false;
+ if (bvecq_acquire_slot(bq, pos->slot))
+ return true;
+ bvecq_pos_move(pos, next);
+ pos->slot = 0;
+ return true;
+}
+
+/**
+ * bvecq_delete_spent - Delete the bvecq at the front if possible
+ * @pos: The position object to update.
+ *
+ * Delete the used up bvecq at the front of the queue that @pos points to if it
+ * is not the last node in the queue; if it is the last node in the queue, it
+ * is kept so that the queue doesn't become detached from the other end. This
+ * may manipulate refs on the bvecqs pointed to. It is also possible that the
+ * producer will fill more slots in the current bvecq.
+ *
+ * Also, we have to be very careful: the consumer can catch the producer, which
+ * could lead to us having nothing left in the queue, causing the front and
+ * back pointers to end up on different tracks. To avoid this, we must always
+ * keep at least one segment in the queue.
+ *
+ * The caller must reload from @pos after calling this.
+ *
+ * Return: true if there's more available; false if not.
+ */
+static inline bool bvecq_delete_spent(struct bvecq_pos *pos)
+{
+ struct bvecq *spent = pos->bvecq;
+ struct bvecq *next;
+ unsigned int slot = pos->slot;
+
+again:
+ /* Read the contents of the queue node after the pointer to it. */
+ next = bvecq_next(spent);
+ if (!next)
+ return false; /* Nothing more to consume at the moment. */
+ if (slot < bvecq_nr_slots_acquire(spent))
+ return true; /* The producer added more. */
+ next->prev = NULL;
+ bvecq_pos_move(pos, next);
+ pos->slot = 0;
+ pos->offset = 0;
+ if (!bvecq_acquire_slot(next, 0)) {
+ spent = next;
+ slot = 0;
+ goto again;
+ }
+ return true;
+}
+
#endif /* _LINUX_BVECQ_H */
diff --git a/include/linux/netfs.h b/include/linux/netfs.h
index f1f85473b0eee..b3a58ce8115c7 100644
--- a/include/linux/netfs.h
+++ b/include/linux/netfs.h
@@ -19,10 +19,12 @@
#include <linux/pagemap.h>
#include <linux/bvecq.h>
#include <linux/uio.h>
-#include <linux/rolling_buffer.h>
enum netfs_sreq_ref_trace;
typedef struct mempool mempool_t;
+struct readahead_control;
+struct netfs_io_request;
+struct netfs_io_subrequest;
struct fscache_occupancy;
/**
@@ -144,7 +146,6 @@ struct netfs_io_stream {
unsigned int sreq_max_segs; /* 0 or max number of segments in an iterator */
unsigned int submit_off; /* Folio offset we're submitting from */
unsigned int submit_len; /* Amount of data left to submit */
- unsigned int submit_extendable_to; /* Amount I/O can be rounded up to */
void (*prepare_write)(struct netfs_io_subrequest *subreq);
void (*issue_write)(struct netfs_io_subrequest *subreq);
/* Collection tracking */
@@ -187,6 +188,7 @@ struct netfs_io_subrequest {
struct netfs_io_request *rreq; /* Supervising I/O request */
struct work_struct work;
struct list_head rreq_link; /* Link in rreq->subrequests */
+ struct bvecq_pos io_buffer; /* Bookmark in the combined queue of the start */
struct iov_iter io_iter; /* Iterator for this subrequest */
uoff_t start; /* Where to start the I/O */
size_t len; /* Size of the I/O */
@@ -247,11 +249,14 @@ struct netfs_io_request {
struct netfs_io_stream io_streams[2]; /* Streams of parallel I/O operations */
#define NR_IO_STREAMS 2 //wreq->nr_io_streams
struct netfs_group *group; /* Writeback group being written back */
- struct rolling_buffer buffer; /* Unencrypted buffer */
+ struct bvecq *spare; /* Advance allocation of bvecq */
+ struct bvecq_pos load_cursor; /* Point at which new folios are loaded in */
+ struct bvecq_pos dispatch_cursor; /* Point from which buffers are dispatched */
+ struct bvecq_pos collect_cursor; /* Clear-up point of I/O buffer */
wait_queue_head_t waitq; /* Processor waiter */
void *netfs_priv; /* Private data for the netfs */
void *netfs_priv2; /* Private data for the netfs */
- struct bio_vec *direct_bv; /* DIO buffer list (when handling iovec-iter) */
+ uoff_t last_end; /* End pos of last folio submitted */
uoff_t submitted; /* Amount submitted for I/O so far */
uoff_t len; /* Length of the request */
size_t transferred; /* Amount to be indicated as transferred */
@@ -266,7 +271,6 @@ struct netfs_io_request {
uoff_t abandon_to; /* Position to abandon folios to */
const struct folio *no_unlock_folio; /* Don't unlock this folio after read */
gfp_t gfp; /* GFP flags to use */
- unsigned int direct_bv_count; /* Number of elements in direct_bv[] */
unsigned int debug_id;
unsigned int rsize; /* Maximum read size (0 for none) */
unsigned int wsize; /* Maximum write size (0 for none) */
@@ -274,7 +278,6 @@ struct netfs_io_request {
unsigned int nr_group_rel; /* Number of refs to release on ->group */
spinlock_t lock; /* Lock for queuing subreqs */
enum netfs_io_origin origin; /* Origin of the request */
- bool direct_bv_unpin; /* T if direct_bv[] must be unpinned */
refcount_t ref;
unsigned long flags;
#define NETFS_RREQ_IN_PROGRESS 0 /* Unlocked when the request completes (has ref) */
@@ -425,7 +428,7 @@ void netfs_single_mark_inode_dirty(struct inode *inode);
ssize_t netfs_read_single(struct inode *inode, struct file *file, struct iov_iter *iter);
int netfs_writeback_single(struct address_space *mapping,
struct writeback_control *wbc,
- struct iov_iter *iter);
+ struct iov_iter *iter, size_t len);
/* Address operations API */
struct readahead_control;
@@ -452,11 +455,9 @@ void netfs_get_subrequest(struct netfs_io_subrequest *subreq,
enum netfs_sreq_ref_trace what);
void netfs_put_subrequest(struct netfs_io_subrequest *subreq,
enum netfs_sreq_ref_trace what);
-ssize_t netfs_extract_user_iter(struct iov_iter *orig, size_t orig_len,
- struct iov_iter *new,
- iov_iter_extraction_t extraction_flags);
-size_t netfs_limit_iter(const struct iov_iter *iter, size_t start_offset,
- size_t max_size, size_t max_segs);
+ssize_t netfs_extract_iter(struct iov_iter *orig, size_t max_len, size_t max_pages,
+ struct bvecq **_bvecq_head,
+ iov_iter_extraction_t extraction_flags, gfp_t gfp);
void netfs_prepare_write_failed(struct netfs_io_subrequest *subreq);
void netfs_write_subrequest_terminated(void *_op, ssize_t transferred_or_error);
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 0adfa6605653d..b7154b81d0d7c 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -1411,6 +1411,7 @@ struct readahead_control {
struct file_ra_state *ra;
/* private: use the readahead_* accessors instead */
pgoff_t _index;
+ unsigned int _nr_folios;
unsigned int _nr_pages;
unsigned int _batch_count;
bool dropbehind;
@@ -1590,6 +1591,15 @@ static inline size_t readahead_batch_length(const struct readahead_control *rac)
return rac->_batch_count * PAGE_SIZE;
}
+/**
+ * readahead_folio_count - Get the number of folios in this readahead request.
+ * @rac: The readahead request.
+ */
+static inline unsigned int readahead_folio_count(const struct readahead_control *rac)
+{
+ return rac->_nr_folios;
+}
+
static inline unsigned long dir_pages(const struct inode *inode)
{
return (unsigned long)(inode->i_size + PAGE_SIZE - 1) >>
diff --git a/include/linux/rolling_buffer.h b/include/linux/rolling_buffer.h
deleted file mode 100644
index 5c0bc4221f010..0000000000000
--- a/include/linux/rolling_buffer.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/* Rolling buffer of folios
- *
- * Copyright (C) 2024 Red Hat, Inc. All Rights Reserved.
- * Written by David Howells (dhowells@redhat.com)
- */
-
-#ifndef _ROLLING_BUFFER_H
-#define _ROLLING_BUFFER_H
-
-#include <linux/bvecq.h>
-#include <linux/uio.h>
-
-/*
- * Rolling buffer. Whilst the buffer is live and in use, folios and bvecq
- * segments can be added to one end by one thread and removed from the other
- * end by another thread. The buffer isn't allowed to be empty; it must always
- * have at least one bvecq in it so that neither side has to modify both queue
- * pointers.
- *
- * The iterator in the buffer is extended as buffers are inserted. It can be
- * snapshotted to use a segment of the buffer.
- */
-struct rolling_buffer {
- struct bvecq *head; /* Producer's insertion point */
- struct bvecq *tail; /* Consumer's removal point */
- struct iov_iter iter; /* Iterator tracking what's left in the buffer */
- u8 first_tail_slot; /* First slot in ->tail */
- bool for_writeback; /* T if being used for writeback */
-};
-
-int rolling_buffer_init(struct rolling_buffer *roll, unsigned int direction,
- gfp_t gfp, bool for_writeback);
-int rolling_buffer_make_space(struct rolling_buffer *roll, gfp_t gfp);
-ssize_t rolling_buffer_bulk_load_from_ra(struct rolling_buffer *roll,
- struct readahead_control *ractl,
- gfp_t gfp);
-ssize_t rolling_buffer_append(struct rolling_buffer *roll, struct folio *folio, gfp_t gfp);
-struct bvecq *rolling_buffer_delete_spent(struct rolling_buffer *roll);
-void rolling_buffer_clear(struct rolling_buffer *roll);
-
-static inline void rolling_buffer_advance(struct rolling_buffer *roll, size_t amount)
-{
- iov_iter_advance(&roll->iter, amount);
-}
-
-#endif /* _ROLLING_BUFFER_H */
diff --git a/include/trace/events/netfs.h b/include/trace/events/netfs.h
index e80c27c49ce25..81a3b7aaa187c 100644
--- a/include/trace/events/netfs.h
+++ b/include/trace/events/netfs.h
@@ -229,7 +229,9 @@
EM(netfs_folio_trace_sched_copy, "sched-copy") \
EM(netfs_folio_trace_store, "store") \
EM(netfs_folio_trace_store_copy, "store-copy") \
- E_(netfs_folio_trace_store_plus, "store+")
+ EM(netfs_folio_trace_store_plus, "store+") \
+ EM(netfs_folio_trace_zero, "zero") \
+ E_(netfs_folio_trace_zero_ra, "zero-ra")
#define netfs_collect_contig_traces \
EM(netfs_contig_trace_collect, "Collect") \
@@ -386,10 +388,10 @@ TRACE_EVENT(netfs_sreq,
__entry->len = sreq->len;
__entry->transferred = sreq->transferred;
__entry->start = sreq->start;
- __entry->slot = sreq->io_iter.bvecq_slot;
+ __entry->slot = sreq->io_buffer.slot;
),
- TP_printk("R=%08x[%x] %s %s f=%03x s=%llx %zx/%zx s=%u e=%d",
+ TP_printk("R=%08x[%x] %s %s f=%03x s=%llx %zx/%zx bv=%u e=%d",
__entry->rreq, __entry->index,
__print_symbolic(__entry->source, netfs_sreq_sources),
__print_symbolic(__entry->what, netfs_sreq_traces),
@@ -782,6 +784,30 @@ TRACE_EVENT(netfs_read_progress_at,
__entry->rreq, __entry->cleaned_to, __entry->progress_at)
);
+TRACE_EVENT(netfs_bv_slot,
+ TP_PROTO(const struct bvecq *bq, int slot),
+
+ TP_ARGS(bq, slot),
+
+ TP_STRUCT__entry(
+ __field(unsigned long, pfn)
+ __field(unsigned int, offset)
+ __field(unsigned int, len)
+ __field(unsigned int, slot)
+ ),
+
+ TP_fast_assign(
+ __entry->slot = slot;
+ __entry->pfn = page_to_pfn(bq->bv[slot].bv_page);
+ __entry->offset = bq->bv[slot].bv_offset;
+ __entry->len = bq->bv[slot].bv_len;
+ ),
+
+ TP_printk("bq[%x] p=%lx %x-%x",
+ __entry->slot,
+ __entry->pfn, __entry->offset, __entry->offset + __entry->len)
+ );
+
#undef EM
#undef E_
#endif /* _TRACE_NETFS_H */
diff --git a/mm/readahead.c b/mm/readahead.c
index 6e5563290287e..196542fb1c930 100644
--- a/mm/readahead.c
+++ b/mm/readahead.c
@@ -188,6 +188,7 @@ static void read_pages(struct readahead_control *rac)
if (unlikely(rac->_workingset))
psi_memstall_leave(&rac->_pflags);
rac->_workingset = false;
+ rac->_nr_folios = 0;
BUG_ON(readahead_count(rac));
}
@@ -303,6 +304,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl,
if (i == mark)
folio_set_readahead(folio);
ractl->_workingset |= folio_test_workingset(folio);
+ ractl->_nr_folios++;
ractl->_nr_pages += min_nrpages;
i += min_nrpages;
}
@@ -473,6 +475,7 @@ static inline int ra_alloc_folio(struct readahead_control *ractl, pgoff_t index,
return err;
}
+ ractl->_nr_folios++;
ractl->_nr_pages += 1UL << order;
ractl->_workingset |= folio_test_workingset(folio);
return 0;
@@ -822,6 +825,7 @@ void readahead_expand(struct readahead_control *ractl,
ractl->_workingset = true;
psi_memstall_enter(&ractl->_pflags);
}
+ ractl->_nr_folios++;
ractl->_nr_pages += min_nrpages;
ractl->_index = folio->index;
}
@@ -851,6 +855,7 @@ void readahead_expand(struct readahead_control *ractl,
ractl->_workingset = true;
psi_memstall_enter(&ractl->_pflags);
}
+ ractl->_nr_folios++;
ractl->_nr_pages += min_nrpages;
if (ra) {
ra->size += min_nrpages;
|
| 23/3 | 2026/10/05 07:34 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 46357 output: 36 thoughts: 1340 Thoughts: **KMSAN Fuzzing Evaluation for Patch Series** Okay, let's dive into this patch series. My initial goal is to determine if these changes warrant a dedicated KMSAN fuzzing session, in addition to our standard KASAN efforts. First, I need a solid understanding of what's being modified. The patch seems focused on refactoring `netfs` and `bvecq` functionality. I see significant changes to how buffered I/O is handled, particularly around `bvec` queue management, and cursors. Looking at the code diffs, `fs/afs/dir.c` and `fs/afs/symlink.c` have changed calls to `netfs_writeback_single` and associated iterator handling. There's also some cleanup in `fs/cachefiles/io.c`, with the removal of rounding logic, which is good. The rolling buffer is gone. That's been replaced by what looks like a more sophisticated use of `bvecq_pos` cursors, and helper functions in `bvecq.c`. I see functions like `bvecq_buffer_init`, `bvecq_buffer_append`, `bvecq_pos_advance`, `bvec_zero`, `bvecq_zero`, `bvecq_slice`, and `bvecq_load_from_ra` added in `bvecq.c`. This suggests a substantial shift in the internal data structures and read/write path. The changes in `buffered_read.c`, `direct_read.c`, and `direct_write.c` confirms this. Now, hold on. I need to take a closer look at the changes in `read_collect.c` and specifically `netfs_clear_unread`. Something's nagging at me. Okay, here's what I'm seeing: ```c iov_iter_bvec_queue(&iter, ITER_DEST, subreq->io_buffer.bvecq, subreq->io_buffer.slot, subreq->io_buffer.offset, subreq->len); iov_iter_advance(&iter, subreq->transferred); iov_iter_zero(subreq->len, &iter); ``` `iov_iter_bvec_queue` is used to initialize an `iov_iter`, using `subreq->len` as the buffer size. Then, `iov_iter_advance` moves the iterator forward by `subreq->transferred`. This means the remaining bytes of `iter` is now `subreq->len - subreq->transferred`. The critical part is the next line: `iov_iter_zero(subreq->len, &iter);`. This calls `iov_iter_zero` with a size of `subreq->len` and the now advanced iterator `iter`. This, potentially, could write beyond the current buffer described by the iterator if `subreq->transferred` is a larger value. We are zeroing up to `subreq->len` which is a larger value than the actual remaining buffer. I need to confirm if this potential out-of-bounds write is exploitable. Given the substantial changes to the `bvecq` internals, and the fact that we're dealing with buffer management in file systems, a potential out-of-bounds write here is a serious red flag. I want to check how `iov_iter_zero` is defined using a `grepper` tool to see how `iov_iter_zero` behaves, to confirm this is an issue. It looks like the `iov_iter_zero` is capping the `bytes` parameter based on the iter count. I need to dig into this specific sequence to determine if a KMSAN run is justified here. The complexity of these buffer management changes, coupled with a potential memory safety concern, strongly suggests that a dedicated KMSAN session is warranted to thoroughly assess the impact of these changes. |
| 24/3 | 2026/10/05 07:35 | tool | grepper |
0mArgs:{
"Expression": "size_t iov_iter_zero",
"PathPrefix": "lib/iov_iter.c"
}Results: {
"Output": "lib/iov_iter.c=458=size_t zero_to_iter(void *iter_to, size_t progress,\n--\nlib/iov_iter.c-464-\nlib/iov_iter.c:465:size_t iov_iter_zero(size_t bytes, struct iov_iter *i)\nlib/iov_iter.c-466-{\n"
} |
| 25/3 | 2026/10/05 07:35 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 48687 output: 35 thoughts: 27 Thoughts: Okay, let's dive into this. Here's my thought process on the matter: **Checking `iov_iter_zero` in `lib/iov_iter.c`** Alright, I need to get a handle on how `iov_iter_zero` is implemented. I'm going to jump into `lib/iov_iter.c`, specifically around line 465, to see what's going on. I know this code pretty well, but it's always good to refresh my memory and verify my understanding. I want to check for edge cases and any potential gotchas. I'll be looking for how it handles different `iov_iter` configurations and buffer sizes, and how it deals with the zeroing operation itself. I'm expecting some standard memory manipulation, but I want to see if they've implemented any optimizations or clever tricks. Let's see what they've done... I'm particularly interested in any synchronization or atomicity considerations if applicable. I also want to make sure I understand the context in which `iov_iter_zero` is being used, so I'll probably scan a little before and after that line to get the broader picture. |
| 26/3 | 2026/10/05 07:35 | tool | read-file |
0mArgs:{
"File": "lib/iov_iter.c",
"FirstLine": 465,
"LineCount": 25
}Results: {
"Contents": " 465:\tsize_t iov_iter_zero(size_t bytes, struct iov_iter *i)\n 466:\t{\n 467:\t\treturn iterate_and_advance(i, bytes, NULL,\n 468:\t\t\t\t\t zero_to_user_iter, zero_to_iter);\n 469:\t}\n 470:\tEXPORT_SYMBOL(iov_iter_zero);\n 471:\t\n 472:\tsize_t copy_folio_from_iter_atomic(struct folio *folio, size_t offset,\n 473:\t\t\tsize_t bytes, struct iov_iter *i)\n 474:\t{\n 475:\t\tsize_t n, copied = 0;\n 476:\t\n 477:\t\tif (!page_copy_sane(\u0026folio-\u003epage, offset, bytes))\n 478:\t\t\treturn 0;\n 479:\t\tif (WARN_ON_ONCE(!i-\u003edata_source))\n 480:\t\t\treturn 0;\n 481:\t\n 482:\t\tdo {\n 483:\t\t\tchar *to = kmap_local_folio(folio, offset);\n 484:\t\n 485:\t\t\tn = bytes - copied;\n 486:\t\t\tif (folio_test_partial_kmap(folio) \u0026\u0026\n 487:\t\t\t n \u003e PAGE_SIZE - offset_in_page(offset))\n 488:\t\t\t\tn = PAGE_SIZE - offset_in_page(offset);\n 489:\t\n"
} |
| 27/3 | 2026/10/05 07:35 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 49405 output: 37 thoughts: 319 Thoughts: **Analyzing Potential Uninitialized Memory Issues**
Okay, so `iterate_and_advance` is limited by `i->count`, that's the starting point. But, before I dive deep into this specific function, I need to understand the larger context of this patch. Let's step back and look at the bigger picture: what are the potential areas where uninitialized memory could be an issue?
The text outlines four key areas I need to focus on:
1. Kernel structures passed to user space. It could be `copy_to_user`, `put_user`, `netlink skb attributes`, `ioctl output arguments`, `socket options`, or `BPF buffers`. These are all vectors for uninitialized data leakage. Padding in structs, or uninitialized fields, could be exposed.
2. Conditional logic. I need to scrutinize any code that branches based on potentially uninitialized variables or struct fields. That's a classic vulnerability.
3. Allocation and initialization. Complex data structures, where uninitialized fields are read later, are also dangerous. I need to trace the allocation and initialization processes.
4. Bounds checks and logic. I have to look out for code that lets other sections of the buffer to be accessed. I have to examine the code that handles buffer sizes and lengths.
Right, with those potential issues in mind, let's look at `fs/netfs/iterator.c`. Specifically, `netfs_extract_iter`.
```c
ssize_t netfs_extract_iter(struct iov_iter *orig, size_t max_len, size_t max_pages,
struct bvecq **_bvecq_head,
iov_iter_extraction_t extraction_flags, gfp_t gfp)
{
...
```
Okay, it looks like `netfs_extract_iter` uses `bvecq`. Let's pause here and check how `bvecq_alloc_one` works. I need to be sure the `bvecq` allocation itself isn't introducing the very problem this patch is trying to fix. Back to `fs/netfs/bvecq.c` I go!
|
| 28/3 | 2026/10/05 07:35 | tool | grepper |
0mArgs:{
"Expression": "bvecq_alloc_one",
"PathPrefix": "fs/netfs/bvecq.c"
}Results: {
"Output": "fs/netfs/bvecq.c=37=EXPORT_SYMBOL(bvecq_dump);\n--\nfs/netfs/bvecq.c-39-/**\nfs/netfs/bvecq.c:40: * bvecq_alloc_one - Allocate a single bvecq node with unpopulated slots\nfs/netfs/bvecq.c-41- * @nr_slots: Number of slots to allocate\n--\nfs/netfs/bvecq.c-57- */\nfs/netfs/bvecq.c:58:struct bvecq *bvecq_alloc_one(size_t nr_slots, gfp_t gfp, bool for_writeback)\nfs/netfs/bvecq.c-59-{\n--\nfs/netfs/bvecq.c-100-}\nfs/netfs/bvecq.c:101:EXPORT_SYMBOL(bvecq_alloc_one);\nfs/netfs/bvecq.c-102-\n--\nfs/netfs/bvecq.c=114=struct bvecq *bvecq_alloc_chain(size_t nr_slots, gfp_t gfp, bool for_writeback)\n--\nfs/netfs/bvecq.c-122-\nfs/netfs/bvecq.c:123:\t\tbq = bvecq_alloc_one(min(nr_slots, BVECQ_4KB_SLOTS), gfp, for_writeback);\nfs/netfs/bvecq.c-124-\t\tif (!bq)\n--\nfs/netfs/bvecq.c=294=int bvecq_expand_buffer(struct bvecq **_buffer, size_t *_cur_size, size_t size, gfp_t gfp)\n--\nfs/netfs/bvecq.c-311-\nfs/netfs/bvecq.c:312:\t\t\tp = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, false);\nfs/netfs/bvecq.c-313-\t\t\tif (!p)\n--\nfs/netfs/bvecq.c=358=int bvecq_buffer_init(struct bvecq_pos *pos, gfp_t gfp, bool for_writeback)\n--\nfs/netfs/bvecq.c-361-\nfs/netfs/bvecq.c:362:\tbq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, for_writeback);\nfs/netfs/bvecq.c-363-\tif (!bq)\n"
} |
| 29/3 | 2026/10/05 07:35 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 50899 output: 37 thoughts: 22 Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience: **Diving into `bvecq.c`** Okay, time to get my hands dirty. Let's pull up `fs/netfs/bvecq.c` and zero in around line 58. I know this code pretty well, but a fresh look always helps when trying to pinpoint subtle issues or optimizations. I'm focusing on that specific area because... well, I have a feeling something relevant to the current problem resides there. Perhaps a subtle interaction with a particular queueing strategy, or an edge case in how bounce buffers are handled. We'll see. Time to start scanning the code and refresh my memory of the relevant data structures and functions. Gotta keep that mental model sharp. |
| 30/3 | 2026/10/05 07:35 | tool | read-file |
0mArgs:{
"File": "fs/netfs/bvecq.c",
"FirstLine": 40,
"LineCount": 60
}Results: {
"Contents": " 40:\t * bvecq_alloc_one - Allocate a single bvecq node with unpopulated slots\n 41:\t * @nr_slots: Number of slots to allocate\n 42:\t * @gfp: The allocation constraints.\n 43:\t * @for_writeback: True if allocating for writeback\n 44:\t *\n 45:\t * Allocate a single bvecq node and initialise the header. The allocation is\n 46:\t * rounded up to the size of the smallest slab granule that will accommodate it\n 47:\t * and all the remaining space is set as an inline slot array with max_slots\n 48:\t * set to the number of slots. The slot array is not initialised.\n 49:\t *\n 50:\t * If @for_writeback is set, then the emergency mempool may be used for\n 51:\t * allocation. If it does allocate from that pool, the maximum number of slots\n 52:\t * available will be BVECQ_POOL_SLOTS which may be less than requested. Also,\n 53:\t * if @for_writeback is set, the function will not fail - though it may have to\n 54:\t * wait.\n 55:\t *\n 56:\t * Return: The node pointer or NULL on allocation failure.\n 57:\t */\n 58:\tstruct bvecq *bvecq_alloc_one(size_t nr_slots, gfp_t gfp, bool for_writeback)\n 59:\t{\n 60:\t\tstruct bvecq *bq;\n 61:\t\tconst size_t pool_size = struct_size_t(struct bvecq, __bv, BVECQ_POOL_SLOTS);\n 62:\t\tsize_t size;\n 63:\t\tbool from_pool = false;\n 64:\t\n 65:\t\tsize = kmalloc_size_roundup(struct_size(bq, __bv, nr_slots));\n 66:\t\tgfp \u0026= ~(GFP_ZONEMASK | __GFP_THISNODE);\n 67:\t\n 68:\t\tif (for_writeback) {\n 69:\t\t\tif (size != pool_size) {\n 70:\t\t\t\tgfp_t gfp_temp = gfp;\n 71:\t\n 72:\t\t\t\tgfp_temp |= __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN;\n 73:\t\t\t\tgfp_temp \u0026= ~(__GFP_DIRECT_RECLAIM | __GFP_IO);\n 74:\t\t\t\tbq = kmalloc(size, gfp_temp);\n 75:\t\t\t\tif (bq)\n 76:\t\t\t\t\tgoto success;\n 77:\t\t\t}\n 78:\t\n 79:\t\t\tbq = mempool_alloc(\u0026netfs_bvecq_pool, gfp);\n 80:\t\t\tif (!bq)\n 81:\t\t\t\treturn bq;\n 82:\t\t\tfrom_pool = true;\n 83:\t\t\tsize = pool_size;\n 84:\t\t} else {\n 85:\t\t\tbq = kmalloc(size, gfp);\n 86:\t\t\tif (!bq)\n 87:\t\t\t\treturn bq;\n 88:\t\t}\n 89:\t\n 90:\tsuccess:\n 91:\t\t*bq = (struct bvecq) {\n 92:\t\t\t.ref\t\t= REFCOUNT_INIT(1),\n 93:\t\t\t.bv\t\t= bq-\u003e__bv,\n 94:\t\t\t.inline_bv\t= true,\n 95:\t\t\t.max_slots\t= (size - sizeof(*bq)) / sizeof(bq-\u003e__bv[0]),\n 96:\t\t\t.from_pool\t= from_pool,\n 97:\t\t};\n 98:\t\tnetfs_stat(\u0026netfs_n_bvecq);\n 99:\t\treturn bq;\n"
} |
| 31/3 | 2026/10/05 07:35 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 52082 output: 32 thoughts: 297 Thoughts: **Analyzing `struct bvecq_pos` and its Initialization** Okay, let's dive into this code. I'm looking at the definition of `struct bvecq_pos` in `include/linux/bvecq.h`. Right, it contains a pointer to a `bvecq`, an offset, and a slot. Straightforward enough, but I need to understand how this is actually initialized and used. Now, let's see... the `bvecq_buffer_init` function seems like a likely candidate. Yup, here it is. It allocates a `bvecq` using `bvecq_alloc_one`, then sets the `bvecq` pointer, `slot` to 0, and `offset` to 0. It's important to remember that `pos->bvecq` comes with a reference, which will matter for memory management later. So, I see that within `netfs_io_subrequest` a `struct bvecq_pos io_buffer;` is declared. I need to understand how *that* instance of the struct is allocated and initialized. Where does the `subreq` variable come from? Time to look at `netfs_alloc_subrequest`. That's where I need to look to figure out how the `io_buffer` within it is being used and managed. |
| 32/3 | 2026/10/05 07:35 | tool | grepper |
0mArgs:{
"Expression": "netfs_alloc_subrequest",
"PathPrefix": "fs/netfs/"
}Results: {
"Output": "fs/netfs/buffered_read.c=272=static void netfs_read_to_pagecache(struct netfs_io_request *rreq)\n--\nfs/netfs/buffered_read.c-382-\nfs/netfs/buffered_read.c:383:\t\tsubreq = netfs_alloc_subrequest(rreq, source);\nfs/netfs/buffered_read.c-384-\t\tif (!subreq) {\n--\nfs/netfs/direct_read.c=23=static void netfs_dispatch_unbuffered_reads(struct netfs_io_request *rreq)\n--\nfs/netfs/direct_read.c-34-\nfs/netfs/direct_read.c:35:\t\tsubreq = netfs_alloc_subrequest(rreq, NETFS_DOWNLOAD_FROM_SERVER);\nfs/netfs/direct_read.c-36-\t\tif (!subreq) {\n--\nfs/netfs/internal.h=93=void netfs_put_failed_request(struct netfs_io_request *rreq);\nfs/netfs/internal.h:94:struct netfs_io_subrequest *netfs_alloc_subrequest(struct netfs_io_request *rreq,\nfs/netfs/internal.h-95-\t\t\t\t\t\t enum netfs_io_source source);\n--\nfs/netfs/objects.c=187=void netfs_put_failed_request(struct netfs_io_request *rreq)\n--\nfs/netfs/objects.c-203- */\nfs/netfs/objects.c:204:struct netfs_io_subrequest *netfs_alloc_subrequest(struct netfs_io_request *rreq,\nfs/netfs/objects.c-205-\t\t\t\t\t\t enum netfs_io_source source)\n--\nfs/netfs/read_retry.c=30=static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)\n--\nfs/netfs/read_retry.c-209-\t\tdo {\nfs/netfs/read_retry.c:210:\t\t\tsubreq = netfs_alloc_subrequest(rreq, NETFS_DOWNLOAD_FROM_SERVER);\nfs/netfs/read_retry.c-211-\t\t\tif (!subreq) {\n--\nfs/netfs/read_single.c=76=static int netfs_single_dispatch_read(struct netfs_io_request *rreq)\n--\nfs/netfs/read_single.c-97-\nfs/netfs/read_single.c:98:\tsubreq = netfs_alloc_subrequest(rreq, source);\nfs/netfs/read_single.c-99-\tif (!subreq)\n--\nfs/netfs/write_issue.c=154=void netfs_prepare_write(struct netfs_io_request *wreq,\n--\nfs/netfs/write_issue.c-159-\nfs/netfs/write_issue.c:160:\tsubreq = netfs_alloc_subrequest(wreq, stream-\u003esource);\nfs/netfs/write_issue.c-161-\tif (!subreq)\n--\nfs/netfs/write_retry.c=17=static void netfs_retry_write_stream(struct netfs_io_request *wreq,\n--\nfs/netfs/write_retry.c-159-\t\tdo {\nfs/netfs/write_retry.c:160:\t\t\tsubreq = netfs_alloc_subrequest(wreq, stream-\u003esource);\nfs/netfs/write_retry.c-161-\t\t\tsubreq-\u003estart\t\t= start;\n"
} |
| 33/3 | 2026/10/05 07:35 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 53633 output: 36 thoughts: 24 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Diving into `netfs_alloc_subrequest`** Alright, let's get down to brass tacks. My initial thought is to zero in on `netfs_alloc_subrequest` within `fs/netfs/objects.c`. That function's where the rubber meets the road, as far as managing sub-requests within the netfs framework is concerned. I'm immediately interested in how it handles memory allocation for the subrequest structures and if there are any obvious areas for performance optimization, or, perhaps more importantly, any potential gotchas with resource exhaustion or race conditions. Knowing netfs, the devil's often in the details when it comes to concurrency and memory management across network interfaces. I anticipate having to look for potential leaks and areas where we can improve efficiency. I need to understand what's being initialized here and what the assumptions are about the caller. I'll be looking for synchronization primitives, too. |
| 34/3 | 2026/10/05 07:35 | tool | read-file |
0mArgs:{
"File": "fs/netfs/objects.c",
"FirstLine": 200,
"LineCount": 45
}Results: {
"Contents": " 200:\t\n 201:\t/*\n 202:\t * Allocate and partially initialise an I/O request structure.\n 203:\t */\n 204:\tstruct netfs_io_subrequest *netfs_alloc_subrequest(struct netfs_io_request *rreq,\n 205:\t\t\t\t\t\t\t enum netfs_io_source source)\n 206:\t{\n 207:\t\tstruct netfs_io_subrequest *subreq;\n 208:\t\tmempool_t *mempool = rreq-\u003enetfs_ops-\u003esubrequest_pool ?: \u0026netfs_subrequest_pool;\n 209:\t\tstruct kmem_cache *cache = mempool-\u003epool_data;\n 210:\t\n 211:\t\tif (rreq-\u003egfp == GFP_KERNEL)\n 212:\t\t\tsubreq = mempool_alloc_noreserve(mempool, rreq-\u003egfp);\n 213:\t\telse\n 214:\t\t\tsubreq = mempool_alloc(mempool, rreq-\u003egfp);\n 215:\t\tif (!subreq)\n 216:\t\t\treturn NULL;\n 217:\t\n 218:\t\tmemset(subreq, 0, kmem_cache_size(cache));\n 219:\t\tINIT_WORK(\u0026subreq-\u003ework, NULL);\n 220:\t\tINIT_LIST_HEAD(\u0026subreq-\u003erreq_link);\n 221:\t\trefcount_set(\u0026subreq-\u003eref, 2);\n 222:\t\tsubreq-\u003esource = source;\n 223:\t\tsubreq-\u003erreq = rreq;\n 224:\t\tsubreq-\u003edebug_index = atomic_inc_return(\u0026rreq-\u003esubreq_counter);\n 225:\t\tnetfs_get_request(rreq, netfs_rreq_trace_get_subreq);\n 226:\t\tnetfs_stat(\u0026netfs_n_rh_sreq);\n 227:\t\treturn subreq;\n 228:\t}\n 229:\t\n 230:\tvoid netfs_get_subrequest(struct netfs_io_subrequest *subreq,\n 231:\t\t\t\t enum netfs_sreq_ref_trace what)\n 232:\t{\n 233:\t\tint r;\n 234:\t\n 235:\t\t__refcount_inc(\u0026subreq-\u003eref, \u0026r);\n 236:\t\ttrace_netfs_sreq_ref(subreq-\u003erreq-\u003edebug_id, subreq-\u003edebug_index, r + 1,\n 237:\t\t\t\t what);\n 238:\t}\n 239:\t\n 240:\tstatic void netfs_free_subrequest(struct netfs_io_subrequest *subreq)\n 241:\t{\n 242:\t\tstruct netfs_io_request *rreq = subreq-\u003erreq;\n 243:\t\n 244:\t\ttrace_netfs_sreq(subreq, netfs_sreq_trace_free);\n"
} |
| 35/3 | 2026/10/05 07:35 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 54691 output: 34 thoughts: 67 Thoughts: Here's my summary, as though I'm thinking through this process: **Memory Allocation in netfs: A Quick Check** Okay, so `netfs_alloc_subrequest` is *definitely* zeroing out the allocated memory using `memset` – good to see that explicit clearing there. Always a good practice, preventing potential leaks or unintended data exposure. But, it's not enough to be complacent. I need to make sure that the equivalent function `netfs_alloc_request` is doing the same. It's a key point and there's a good chance that it is zeroing too, so I'll check it to be sure. I'll jump right into `fs/netfs/objects.c` to verify that assumption. Gotta make sure it's consistent. |
| 36/3 | 2026/10/05 07:35 | tool | grepper |
0mArgs:{
"Expression": "netfs_alloc_request",
"PathPrefix": "fs/netfs/objects.c"
}Results: {
"Output": "fs/netfs/objects.c=12=static void netfs_free_request(struct work_struct *work);\n--\nfs/netfs/objects.c-16- */\nfs/netfs/objects.c:17:struct netfs_io_request *netfs_alloc_request(struct address_space *mapping,\nfs/netfs/objects.c-18-\t\t\t\t\t struct file *file,\n--\nfs/netfs/objects.c=187=void netfs_put_failed_request(struct netfs_io_request *rreq)\n--\nfs/netfs/objects.c-191-\t/* new requests have two references (see\nfs/netfs/objects.c:192:\t * netfs_alloc_request(), and this function is only allowed on\nfs/netfs/objects.c-193-\t * new request objects\n"
} |
| 37/3 | 2026/10/05 07:35 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 55186 output: 35 thoughts: 22 Thoughts: Okay, let's dive into this. I'm going to start by examining the code located in `fs/netfs/objects.c`, specifically lines 17 through 60. My initial thought is to quickly ascertain the scope of this section. I need to understand what this segment of code is responsible for within the larger `netfs` context. Are we dealing with object creation, modification, deletion, or perhaps attribute management? Knowing this quickly will give me a framework for interpreting the individual lines. I'll be looking for key function calls, data structure definitions, and any conditional logic that defines the flow within this block. Specifically, I'll be trying to identify any potential lock contention or race conditions. I'm also looking for signs of how the network interaction, if any, is handled in this section. Are we dealing with synchronous I/O or something more asynchronous? Also, any error handling, and how they handle situations. Knowing the error handling strategy used is important. Any unusual memory management practices are something I'll be keeping an eye on. Finally, I'll scan the comments, if any, looking for any higher-level design intentions or design tradeoffs that the original author may have made. |
| 38/3 | 2026/10/05 07:35 | tool | read-file |
0mArgs:{
"File": "fs/netfs/objects.c",
"FirstLine": 17,
"LineCount": 45
}Results: {
"Contents": " 17:\tstruct netfs_io_request *netfs_alloc_request(struct address_space *mapping,\n 18:\t\t\t\t\t\t struct file *file,\n 19:\t\t\t\t\t\t uoff_t start, size_t len,\n 20:\t\t\t\t\t\t enum netfs_io_origin origin)\n 21:\t{\n 22:\t\tstatic atomic_t debug_ids;\n 23:\t\tstruct inode *inode = file ? file_inode(file) : mapping-\u003ehost;\n 24:\t\tstruct netfs_inode *ctx = netfs_inode(inode);\n 25:\t\tstruct netfs_io_request *rreq;\n 26:\t\tmempool_t *mempool = ctx-\u003eops-\u003erequest_pool ?: \u0026netfs_request_pool;\n 27:\t\tstruct kmem_cache *cache = mempool-\u003epool_data;\n 28:\t\tgfp_t gfp = GFP_KERNEL;\n 29:\t\tint ret;\n 30:\t\n 31:\t\t/* Writeback is part of memory reclaim and must not fail due to ENOMEM. */\n 32:\t\tif (origin == NETFS_WRITEBACK || origin == NETFS_WRITEBACK_SINGLE) {\n 33:\t\t\tgfp = GFP_NOFS; /* Allows use of mempools. */\n 34:\t\n 35:\t\t\trreq = mempool_alloc(mempool, gfp);\n 36:\t\t} else {\n 37:\t\t\trreq = mempool_alloc_noreserve(mempool, gfp);\n 38:\t\t\tif (!rreq)\n 39:\t\t\t\treturn ERR_PTR(-ENOMEM);\n 40:\t\t}\n 41:\t\n 42:\t\tmemset(rreq, 0, kmem_cache_size(cache));\n 43:\t\tINIT_WORK(\u0026rreq-\u003ecleanup_work, netfs_free_request);\n 44:\t\trreq-\u003egfp\t\t= gfp;\n 45:\t\trreq-\u003estart\t\t= start;\n 46:\t\trreq-\u003ecollected_to\t= start;\n 47:\t\trreq-\u003ecache_coll_to\t= start;\n 48:\t\trreq-\u003ecleaned_to\t= start;\n 49:\t\trreq-\u003elen\t\t= len;\n 50:\t\trreq-\u003eprogress_at\t= 0;\n 51:\t\trreq-\u003eorigin\t\t= origin;\n 52:\t\trreq-\u003enetfs_ops\t\t= ctx-\u003eops;\n 53:\t\trreq-\u003emapping\t\t= mapping;\n 54:\t\trreq-\u003einode\t\t= inode;\n 55:\t\trreq-\u003ei_size\t\t= i_size_read(inode);\n 56:\t\trreq-\u003edebug_id\t\t= atomic_inc_return(\u0026debug_ids);\n 57:\t\trreq-\u003ewsize\t\t= INT_MAX;\n 58:\t\trreq-\u003eio_streams[0].sreq_max_len = ULONG_MAX;\n 59:\t\trreq-\u003eio_streams[0].sreq_max_segs = 0;\n 60:\t\tspin_lock_init(\u0026rreq-\u003elock);\n 61:\t\tinit_waitqueue_head(\u0026rreq-\u003ewaitq);\n"
} |
| 39/3 | 2026/10/05 07:35 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 56294 output: 28 thoughts: 2304 Thoughts: **Analyzing NetFS Data Buffer Zeroing and Initialization**
Okay, so `netfs_alloc_request` is using `memset` to zero out the request structure, which is good for safety. Let's delve deeper into `struct bvecq` and its allocation. In `bvecq_alloc_one`, the `kmalloc` call seems straightforward, but what's key here is the initialization `*bq = (struct bvecq) { ... };`. This effectively zeroes out the entire `struct bvecq`, including fields like `next`, `nr_slots`, and `cur_slots`, which weren't explicitly set. Even though the `bq->__bv` slots array itself isn't initialized, we see that `nr_slots` is initialized to 0.
However, the slots are populated later via `bvec_set_folio`, `bvec_set_page`, etc., and the relevant counter, `nr_slots` or `cur_slots`, is updated after each population. Now, the existence of `bvecq_zero` in `bvecq.c` is suspicious. Let's dig deeper: the `bvecq_zero` function iterates through the buffer vectors and, in the case of reading the buffer, will then call `bvec_zero` which then calls `memset` on the destination pages, which is what we want!
Here's the crucial point: in `netfs_issue_read`, we're now using `bvecq_zero` to zero the *destination* buffer. This confirms that we're proactively cleaning the buffer before reading into it. So that means we're in good shape and don't need to manually clear the buffer before each read.
Now, let's look at `netfs_read_gaps`. Here, `bvecq_alloc_chain` is called, which allocates a chain of `bvecq` structures, but it does not zero the buffers. Then a loop populates `bvec_set_folio` to the buffers. Then, `bvecq_filled_to` gets called to signify a completed buffer. The question is: what is the initial state of the buffers? It's important to understand where the buffer is read to.
Ah, and here's a crucial point: `netfs_readahead` and `netfs_create_singular_buffer` both set the `collect_cursor` to the `dispatch_cursor`. Is `netfs_read_gaps` using these cursors? We see that the `rreq->collect_cursor` is set to the `dispatch_cursor`. This is how we should set up reads.
|
| 40/3 | 2026/10/05 07:35 | tool | grepper |
0mArgs:{
"Expression": "collect_cursor",
"PathPrefix": "fs/netfs/"
}Results: {
"Output": "fs/netfs/buffered_read.c=463=void netfs_readahead(struct readahead_control *ractl)\n--\nfs/netfs/buffered_read.c-501-\trreq-\u003ecleaned_to = rreq-\u003estart;\nfs/netfs/buffered_read.c:502:\tbvecq_pos_set(\u0026rreq-\u003ecollect_cursor, \u0026rreq-\u003edispatch_cursor);\nfs/netfs/buffered_read.c-503-\tnetfs_read_set_unlock_at(rreq);\n--\nfs/netfs/buffered_read.c=517=static int netfs_create_singular_buffer(struct netfs_io_request *rreq, struct folio *folio)\n--\nfs/netfs/buffered_read.c-531-\tbvecq_filled_to(bq, 1);\nfs/netfs/buffered_read.c:532:\tbvecq_pos_set(\u0026rreq-\u003ecollect_cursor, \u0026rreq-\u003edispatch_cursor);\nfs/netfs/buffered_read.c-533-\trreq-\u003esubmitted = rreq-\u003estart + fsize;\n--\nfs/netfs/direct_read.c=23=static void netfs_dispatch_unbuffered_reads(struct netfs_io_request *rreq)\n--\nfs/netfs/direct_read.c-29-\nfs/netfs/direct_read.c:30:\tbvecq_pos_set(\u0026rreq-\u003ecollect_cursor, \u0026rreq-\u003edispatch_cursor);\nfs/netfs/direct_read.c-31-\n--\nfs/netfs/direct_write.c=98=static int netfs_unbuffered_write(struct netfs_io_request *wreq)\n--\nfs/netfs/direct_write.c-105-\nfs/netfs/direct_write.c:106:\tbvecq_pos_set(\u0026wreq-\u003ecollect_cursor, \u0026wreq-\u003edispatch_cursor);\nfs/netfs/direct_write.c-107-\n--\nfs/netfs/objects.c=133=static void netfs_deinit_request(struct netfs_io_request *rreq)\n--\nfs/netfs/objects.c-151-\tbvecq_pos_unset(\u0026rreq-\u003edispatch_cursor);\nfs/netfs/objects.c:152:\tbvecq_pos_unset(\u0026rreq-\u003ecollect_cursor);\nfs/netfs/objects.c-153-\tbvecq_put(rreq-\u003espare);\n--\nfs/netfs/read_collect.c=127=void netfs_read_set_unlock_at(struct netfs_io_request *rreq)\nfs/netfs/read_collect.c-128-{\nfs/netfs/read_collect.c:129:\tconst struct bvecq *bq = rreq-\u003ecollect_cursor.bvecq;\nfs/netfs/read_collect.c:130:\tunsigned int slot = rreq-\u003ecollect_cursor.slot;\nfs/netfs/read_collect.c-131-\tsize_t cleaned_to = rreq-\u003ecleaned_to - rreq-\u003estart;\n--\nfs/netfs/read_collect.c=157=static void netfs_read_unlock_folios(struct netfs_io_request *rreq,\n--\nfs/netfs/read_collect.c-159-{\nfs/netfs/read_collect.c:160:\tstruct bvecq *bq = rreq-\u003ecollect_cursor.bvecq;\nfs/netfs/read_collect.c:161:\tunsigned int slot = rreq-\u003ecollect_cursor.slot;\nfs/netfs/read_collect.c-162-\tuoff_t collected_to = rreq-\u003ecollected_to;\n--\nfs/netfs/read_collect.c-185-\t\tif (!bvecq_acquire_slot(bq, slot)) {\nfs/netfs/read_collect.c:186:\t\t\trreq-\u003ecollect_cursor.slot = slot;\nfs/netfs/read_collect.c:187:\t\t\tif (!bvecq_delete_spent(\u0026rreq-\u003ecollect_cursor)) {\nfs/netfs/read_collect.c-188-\t\t\t\tWRITE_ONCE(rreq-\u003eprogress_at, rreq-\u003elen);\n--\nfs/netfs/read_collect.c-190-\t\t\t}\nfs/netfs/read_collect.c:191:\t\t\tbq = rreq-\u003ecollect_cursor.bvecq;\nfs/netfs/read_collect.c:192:\t\t\tslot = rreq-\u003ecollect_cursor.slot;\nfs/netfs/read_collect.c-193-\t\t\tcontinue;\n--\nfs/netfs/read_collect.c-219-\nfs/netfs/read_collect.c:220:\tbvecq_pos_move(\u0026rreq-\u003ecollect_cursor, bq);\nfs/netfs/read_collect.c:221:\trreq-\u003ecollect_cursor.slot = slot;\nfs/netfs/read_collect.c-222-\tnetfs_read_set_unlock_at(rreq);\n--\nfs/netfs/read_collect.c=390=static void netfs_rreq_assess_dio(struct netfs_io_request *rreq)\n--\nfs/netfs/read_collect.c-395-\t rreq-\u003eorigin == NETFS_DIO_READ) {\nfs/netfs/read_collect.c:396:\t\tfor (struct bvecq *bq = rreq-\u003ecollect_cursor.bvecq; bq; bq = bvecq_next(bq)) {\nfs/netfs/read_collect.c-397-\t\t\tunsigned int nr_slots = bvecq_nr_slots_acquire(bq);\n--\nfs/netfs/read_pgpriv2.c=118=static struct netfs_io_request *netfs_pgpriv2_begin_copy_to_cache(\n--\nfs/netfs/read_pgpriv2.c-136-\tbvecq_pos_set(\u0026creq-\u003edispatch_cursor, \u0026creq-\u003eload_cursor);\nfs/netfs/read_pgpriv2.c:137:\tbvecq_pos_set(\u0026creq-\u003ecollect_cursor, \u0026creq-\u003edispatch_cursor);\nfs/netfs/read_pgpriv2.c-138-\n--\nfs/netfs/read_pgpriv2.c=207=bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *creq)\nfs/netfs/read_pgpriv2.c-208-{\nfs/netfs/read_pgpriv2.c:209:\tstruct bvecq *bq = creq-\u003ecollect_cursor.bvecq;\nfs/netfs/read_pgpriv2.c-210-\tunsigned int slot;\n--\nfs/netfs/read_pgpriv2.c-213-\nfs/netfs/read_pgpriv2.c:214:\tslot = creq-\u003ecollect_cursor.slot;\nfs/netfs/read_pgpriv2.c-215-\twhile (!bvecq_acquire_slot(bq, slot)) {\nfs/netfs/read_pgpriv2.c:216:\t\tcreq-\u003ecollect_cursor.slot = slot;\nfs/netfs/read_pgpriv2.c:217:\t\tif (!bvecq_delete_spent(\u0026creq-\u003ecollect_cursor))\nfs/netfs/read_pgpriv2.c-218-\t\t\tgoto out;\nfs/netfs/read_pgpriv2.c:219:\t\tbq = creq-\u003ecollect_cursor.bvecq;\nfs/netfs/read_pgpriv2.c:220:\t\tslot = creq-\u003ecollect_cursor.slot;\nfs/netfs/read_pgpriv2.c-221-\t}\n--\nfs/netfs/read_pgpriv2.c-257-\t\twhile (!bvecq_acquire_slot(bq, slot)) {\nfs/netfs/read_pgpriv2.c:258:\t\t\tcreq-\u003ecollect_cursor.slot = slot;\nfs/netfs/read_pgpriv2.c:259:\t\t\tif (!bvecq_delete_spent(\u0026creq-\u003ecollect_cursor))\nfs/netfs/read_pgpriv2.c-260-\t\t\t\tgoto out;\nfs/netfs/read_pgpriv2.c:261:\t\t\tbq = creq-\u003ecollect_cursor.bvecq;\nfs/netfs/read_pgpriv2.c:262:\t\t\tslot = creq-\u003ecollect_cursor.slot;\nfs/netfs/read_pgpriv2.c-263-\t\t}\n--\nfs/netfs/read_pgpriv2.c-268-\nfs/netfs/read_pgpriv2.c:269:\tcreq-\u003ecollect_cursor.slot = slot;\nfs/netfs/read_pgpriv2.c-270-out:\n--\nfs/netfs/read_retry.c=306=void netfs_unlock_abandoned_read_pages(struct netfs_io_request *rreq)\n--\nfs/netfs/read_retry.c-316-\nfs/netfs/read_retry.c:317:\tfor (p = rreq-\u003ecollect_cursor.bvecq; p; p = bvecq_next(p)) {\nfs/netfs/read_retry.c-318-\t\tunsigned int nr_slots = bvecq_nr_slots_acquire(p);\n--\nfs/netfs/write_collect.c=114=static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,\n--\nfs/netfs/write_collect.c-116-{\nfs/netfs/write_collect.c:117:\tstruct bvecq *bq = wreq-\u003ecollect_cursor.bvecq;\nfs/netfs/write_collect.c:118:\tunsigned int slot = wreq-\u003ecollect_cursor.slot;\nfs/netfs/write_collect.c-119-\tuoff_t collected_to = wreq-\u003ecollected_to;\n--\nfs/netfs/write_collect.c-146-\t\tif (!bvecq_acquire_slot(bq, slot)) {\nfs/netfs/write_collect.c:147:\t\t\twreq-\u003ecollect_cursor.slot = slot;\nfs/netfs/write_collect.c:148:\t\t\tif (!bvecq_delete_spent(\u0026wreq-\u003ecollect_cursor))\nfs/netfs/write_collect.c-149-\t\t\t\treturn;\nfs/netfs/write_collect.c:150:\t\t\tbq = wreq-\u003ecollect_cursor.bvecq;\nfs/netfs/write_collect.c:151:\t\t\tslot = wreq-\u003ecollect_cursor.slot;\nfs/netfs/write_collect.c-152-\t\t\tcontinue;\n--\nfs/netfs/write_collect.c-183-\nfs/netfs/write_collect.c:184:\twreq-\u003ecollect_cursor.slot = slot;\nfs/netfs/write_collect.c-185-}\n--\nfs/netfs/write_issue.c=584=int netfs_writepages(struct address_space *mapping,\n--\nfs/netfs/write_issue.c-608-\tbvecq_pos_set(\u0026wreq-\u003edispatch_cursor, \u0026wreq-\u003eload_cursor);\nfs/netfs/write_issue.c:609:\tbvecq_pos_set(\u0026wreq-\u003ecollect_cursor, \u0026wreq-\u003edispatch_cursor);\nfs/netfs/write_issue.c-610-\n--\nfs/netfs/write_issue.c=681=int netfs_writeback_single(struct address_space *mapping,\n--\nfs/netfs/write_issue.c-720-\nfs/netfs/write_issue.c:721:\tbvecq_pos_set(\u0026wreq-\u003ecollect_cursor, \u0026wreq-\u003edispatch_cursor);\nfs/netfs/write_issue.c-722-\n"
} |
| 41/3 | 2026/10/05 07:35 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 62247 output: 38 thoughts: 54 Thoughts: Here's my summary, as though I'm thinking through this process: **Diving into `netfs_read_gaps`** Hold on a second! I need to zero in on `netfs_read_gaps`. That function is crucial for understanding how the network filesystem handles buffered reads, and I suspect it holds the key to the problem I'm trying to solve. Specifically, I'm thinking about lines 540 through 620 in `fs/netfs/buffered_read.c`. Those lines probably contain the core logic for... well, let's see. I need to refresh my memory on the implementation here, so I'll need to focus on those lines, and the surrounding code, to understand exactly how the file system handles reading gaps when it comes to buffered reads. This is my starting point. I know it. I have to see it! |
| 42/3 | 2026/10/05 07:35 | tool | read-file |
0mArgs:{
"File": "fs/netfs/buffered_read.c",
"FirstLine": 540,
"LineCount": 80
}Results: {
"Contents": " 540:\t */\n 541:\tstatic int netfs_read_gaps(struct file *file, struct folio *folio)\n 542:\t{\n 543:\t\tstruct netfs_io_request *rreq;\n 544:\t\tstruct address_space *mapping = folio-\u003emapping;\n 545:\t\tstruct netfs_group *group = netfs_folio_group(folio);\n 546:\t\tstruct netfs_folio *finfo = netfs_folio_info(folio);\n 547:\t\tstruct netfs_inode *ctx = netfs_inode(mapping-\u003ehost);\n 548:\t\tstruct bvecq *bq = NULL;\n 549:\t\tunsigned int from = finfo-\u003edirty_offset;\n 550:\t\tunsigned int to = from + finfo-\u003edirty_len;\n 551:\t\tunsigned int off = 0;\n 552:\t\tsize_t flen = folio_size(folio);\n 553:\t\tsize_t nr_bvec = flen / PAGE_SIZE + 2;\n 554:\t\tsize_t part;\n 555:\t\tint ret, i = 0;\n 556:\t\n 557:\t\t_enter(\"%lx\", folio-\u003eindex);\n 558:\t\n 559:\t\trreq = netfs_alloc_request(mapping, file, folio_pos(folio), flen, NETFS_READ_GAPS);\n 560:\t\tif (IS_ERR(rreq)) {\n 561:\t\t\tret = PTR_ERR(rreq);\n 562:\t\t\tgoto alloc_error;\n 563:\t\t}\n 564:\t\n 565:\t\tret = netfs_begin_cache_read(rreq, ctx);\n 566:\t\tif (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS)\n 567:\t\t\tgoto discard;\n 568:\t\n 569:\t\tnetfs_stat(\u0026netfs_n_rh_read_folio);\n 570:\t\ttrace_netfs_read(rreq, rreq-\u003estart, rreq-\u003elen, netfs_read_trace_read_gaps);\n 571:\t\n 572:\t\t/* Fiddle the buffer so that a gap at the beginning and/or a gap at the\n 573:\t\t * end get copied to, but the middle is discarded.\n 574:\t\t */\n 575:\t\tret = -ENOMEM;\n 576:\t\tbq = bvecq_alloc_chain(nr_bvec, rreq-\u003egfp, false);\n 577:\t\tif (!bq)\n 578:\t\t\tgoto discard;\n 579:\t\trreq-\u003edispatch_cursor.bvecq = bq;\n 580:\t\n 581:\t\ttrace_netfs_folio(folio, netfs_folio_trace_read_gaps);\n 582:\t\n 583:\t\tfor (struct bvecq *p = bq; p; p = p-\u003enext)\n 584:\t\t\tp-\u003emem_type = BVECQ_MEM_PAGECACHE;\n 585:\t\n 586:\t\tif (from \u003e 0) {\n 587:\t\t\tfolio_get(folio);\n 588:\t\t\tbvec_set_folio(\u0026bq-\u003ebv[i++], folio, from, 0);\n 589:\t\t\toff = from;\n 590:\t\t}\n 591:\t\twhile (off \u003c to) {\n 592:\t\t\tstruct folio *sink = folio_alloc(GFP_KERNEL, 0);\n 593:\t\n 594:\t\t\tif (!sink)\n 595:\t\t\t\tgoto discard;\n 596:\t\t\tif (i \u003e= bq-\u003emax_slots) {\n 597:\t\t\t\tbvecq_filled_to(bq, i);\n 598:\t\t\t\tbq = bq-\u003enext;\n 599:\t\t\t\ti = 0;\n 600:\t\t\t}\n 601:\t\t\tpart = min(to - off, PAGE_SIZE);\n 602:\t\t\tbvec_set_folio(\u0026bq-\u003ebv[i++], sink, part, 0);\n 603:\t\t\toff += part;\n 604:\t\t}\n 605:\t\tif (to \u003c flen) {\n 606:\t\t\tif (i \u003e= bq-\u003emax_slots) {\n 607:\t\t\t\tbvecq_filled_to(bq, i);\n 608:\t\t\t\tbq = bq-\u003enext;\n 609:\t\t\t\ti = 0;\n 610:\t\t\t}\n 611:\t\t\tfolio_get(folio);\n 612:\t\t\tbvec_set_folio(\u0026bq-\u003ebv[i++], folio, flen - to, to);\n 613:\t\t}\n 614:\t\tbvecq_filled_to(bq, i);\n 615:\t\n 616:\t\trreq-\u003esubmitted = rreq-\u003estart + flen;\n 617:\t\n 618:\t\tnetfs_read_to_pagecache(rreq);\n 619:\t\n"
} |
| 43/3 | 2026/10/05 07:35 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 63833 output: 35 thoughts: 992 Thoughts: **Deep Dive into `netfs_read_gaps` and Cursor Management**
Okay, so I'm digging into how `netfs_read_gaps` works, specifically focusing on cursor management and folio handling. It's time to thoroughly understand how reads are dispatched and completed, and how resources are freed.
First, I see in `netfs_read_gaps` that `rreq->dispatch_cursor.bvecq = bq` is set and then `netfs_read_to_pagecache(rreq)` is called. My immediate question: what exactly does that function do with these cursors? I need to trace the usage of `rreq->dispatch_cursor` to understand the flow.
Looking at lines 280-300, I see that a `mark_cursor` is set from the `rreq->dispatch_cursor` using `bvecq_pos_set`. That makes sense, so now I understand a snapshot is created.
I also need to understand the lifecycle of the folios involved, especially how they're unlocked and collected after `NETFS_READ_GAPS` completes. Examining `netfs_read_collection` shows that the unlock and cleanup operations depend on the `rreq->origin`. This seems important because for `NETFS_READ_GAPS`, `netfs_wait_for_read` is called.
Now, considering `NETFS_READ_GAPS` specifically, I see that after `netfs_wait_for_read` returns, the code flushes the dcache, marks the folio as uptodate, and *then* crucially, it calls `bvecq_pos_unset(&rreq->dispatch_cursor)` and `folio_unlock(folio)`. Importantly, `bvecq_pos_unset` is called and, critically, `rreq->dispatch_cursor` is *not* used for collection. This is a key observation.
Next, I jumped to `netfs_deinit_request` to verify the state of other cursors. I see that `bvecq_pos_unset` is called on `rreq->load_cursor`, `rreq->dispatch_cursor`, and `rreq->collect_cursor`. Since the request is zeroed on allocation, the `collect_cursor` is going to be all zeros (and `bvecq` will be `NULL`). Good! Then, I see `bvecq_pos_unset` handles `bvecq == NULL` safely: `bvecq_put(NULL)` does nothing, so it's a no-op!
Okay, so the `bvecq_pos` lifecycle is crucial here. Let's trace it carefully! `bvecq_pos_set`, `bvecq_pos_unset`, `bvecq_pos_transfer`, and `bvecq_pos_move` are the key functions I must understand. I checked `include/linux/bvecq.h` and the inline implementations confirm my understanding of the setting and unsetting process, especially the `bvecq_get` and `bvecq_put` calls.
And here is something important! Looking at `netfs_retry_read_subrequests` in `netfs_read_retry.c`, I see a local `struct bvecq_pos dispatch_cursor = {};`. This is initialized to `{}` (all zeros). Then, within the retry loop, `bvecq_pos_unset(&dispatch_cursor)` is called *before* `dispatch_cursor` is used. This means that the *first* time this code is executed, `dispatch_cursor.bvecq` will be `NULL`, and therefore `bvecq_put(NULL)` gets called. I should probably check to be completely sure about how `bvecq_put` handles `NULL`.
Alright, I think I have a solid grip on the flow, but I need to test that NULL `bvecq` check!
|
| 44/3 | 2026/10/05 07:36 | tool | grepper |
0mArgs:{
"Expression": "bvecq_put",
"PathPrefix": "fs/netfs/bvecq.c"
}Results: {
"Output": "fs/netfs/bvecq.c=114=struct bvecq *bvecq_alloc_chain(size_t nr_slots, gfp_t gfp, bool for_writeback)\n--\nfs/netfs/bvecq.c-138-oom:\nfs/netfs/bvecq.c:139:\tbvecq_put(head);\nfs/netfs/bvecq.c-140-\treturn NULL;\n--\nfs/netfs/bvecq.c=162=struct bvecq *bvecq_alloc_buffer2(size_t size, unsigned int pre_slots, gfp_t gfp,\n--\nfs/netfs/bvecq.c-222-oom:\nfs/netfs/bvecq.c:223:\tbvecq_put(head);\nfs/netfs/bvecq.c-224-\treturn NULL;\n--\nfs/netfs/bvecq.c=231=static void bvecq_free_slot(struct bvecq *bq, unsigned int slot)\n--\nfs/netfs/bvecq.c-256-/**\nfs/netfs/bvecq.c:257: * bvecq_put - Put a ref on a bvec queue\nfs/netfs/bvecq.c-258- * @bq: The start of the folio queue to free\n--\nfs/netfs/bvecq.c-262- */\nfs/netfs/bvecq.c:263:void bvecq_put(struct bvecq *bq)\nfs/netfs/bvecq.c-264-{\n--\nfs/netfs/bvecq.c-279-}\nfs/netfs/bvecq.c:280:EXPORT_SYMBOL(bvecq_put);\nfs/netfs/bvecq.c-281-\n--\nfs/netfs/bvecq.c=381=void bvecq_buffer_append(struct bvecq_pos *pos, struct bvecq *bq)\n--\nfs/netfs/bvecq.c-392-\tbvecq_append(head, bq);\nfs/netfs/bvecq.c:393:\tbvecq_put(head);\nfs/netfs/bvecq.c-394-}\n"
} |
| 45/3 | 2026/10/05 07:36 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 66316 output: 38 thoughts: 24 Thoughts: Okay, let's dive into this. Here's my take on understanding this `bvecq_put` function within the `fs/netfs/bvecq.c` context: **Dissecting `bvecq_put` in `fs/netfs/bvecq.c`** Alright, so I'm focusing on `bvecq_put` within the network filesystem (netfs) space, specifically in the `bvecq.c` file. Given my expertise, I'm already anticipating this function likely deals with the mechanics of putting data, represented as bio vectors (bvecs), onto some kind of queue. My immediate questions are: What kind of queue is this? Is it per-connection, per-file, or something else entirely? What's the context in the netfs operations where this is being called? Is it related to writing, or is this used elsewhere? I need to understand the data structures involved, the locks being used (if any), and the overall flow of data management. I'm looking for clues about how efficiently and safely this is handling the bvecs. I'm already mentally searching for related functions like `bvecq_get`, hoping to see the complementary operation to build a clearer picture of the overall design. Hopefully the code comments will be helpful! |
| 46/3 | 2026/10/05 07:36 | tool | read-file |
0mArgs:{
"File": "fs/netfs/bvecq.c",
"FirstLine": 257,
"LineCount": 25
}Results: {
"Contents": " 257:\t * bvecq_put - Put a ref on a bvec queue\n 258:\t * @bq: The start of the folio queue to free\n 259:\t *\n 260:\t * Put the ref(s) on the nodes in a bvec queue, freeing up the node and the\n 261:\t * page fragments it points to as the refcounts become zero.\n 262:\t */\n 263:\tvoid bvecq_put(struct bvecq *bq)\n 264:\t{\n 265:\t\tstruct bvecq *next;\n 266:\t\n 267:\t\tfor (; bq; bq = next) {\n 268:\t\t\tif (!refcount_dec_and_test(\u0026bq-\u003eref))\n 269:\t\t\t\tbreak;\n 270:\t\t\tfor (int slot = 0; slot \u003c bq-\u003enr_slots; slot++)\n 271:\t\t\t\tbvecq_free_slot(bq, slot);\n 272:\t\t\tnext = bq-\u003enext;\n 273:\t\t\tnetfs_stat_d(\u0026netfs_n_bvecq);\n 274:\t\t\tif (bq-\u003efrom_pool)\n 275:\t\t\t\tmempool_free(bq, \u0026netfs_bvecq_pool);\n 276:\t\t\telse\n 277:\t\t\t\tkfree(bq);\n 278:\t\t}\n 279:\t}\n 280:\tEXPORT_SYMBOL(bvecq_put);\n 281:\t\n"
} |
| 47/3 | 2026/10/05 07:36 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 67059 output: 34 thoughts: 44 Thoughts: Okay, here's my interpretation of this thought process, keeping in mind my expertise: **Examining a Loop's Termination and a Related Function** Alright, so the core of the snippet is a `for` loop, likely iterating through something. The loop's condition, `bq`, looks like the key to the iteration's control. If `bq` is `NULL`, then the loop body is skipped which is expected, but the nuance is to understand *why* it might be NULL. It's designed this way, so no issue there. My immediate thought is, "What specifically does `bq` represent here?" What kind of structure, queue, or data element are we dealing with? And since the focus is here, I'm already anticipating that the function might involve some kind of data retrieval from the structure, whatever `bq` is pointing to. And that leads directly to the question of *how* `bq` is updated. Is `next` a pointer within the structure it's pointing at? How is `next` assigned? I'm already visualizing potential scenarios: a linked list, maybe a circular buffer. This suggests `bvecq_get` probably plays a role in fetching or accessing data from whatever structure `bq` refers to. I need to refresh my understanding of how that function is implemented and how it interacts with the broader system to fully grasp what's happening. I'll need to go look into `bvecq_get`'s source code to have a good answer. |
| 48/3 | 2026/10/05 07:36 | tool | grepper |
0mArgs:{
"Expression": "bvecq_get",
"PathPrefix": "include/linux/bvecq.h"
}Results: {
"Output": "include/linux/bvecq.h=90=static inline struct bvecq *bvecq_alloc_buffer(size_t size, gfp_t gfp, bool for_writeback)\n--\ninclude/linux/bvecq.h-95-/**\ninclude/linux/bvecq.h:96: * bvecq_get - Get a ref on a bvecq\ninclude/linux/bvecq.h-97- * @bq: The bvecq to get a ref on\ninclude/linux/bvecq.h-98- */\ninclude/linux/bvecq.h:99:static inline struct bvecq *bvecq_get(struct bvecq *bq)\ninclude/linux/bvecq.h-100-{\n--\ninclude/linux/bvecq.h=191=static inline void bvecq_pos_set(struct bvecq_pos *pos, const struct bvecq_pos *at)\n--\ninclude/linux/bvecq.h-193-\t*pos = *at;\ninclude/linux/bvecq.h:194:\tbvecq_get(pos-\u003ebvecq);\ninclude/linux/bvecq.h-195-}\n--\ninclude/linux/bvecq.h=235=static inline void bvecq_pos_move(struct bvecq_pos *pos, struct bvecq *to)\n--\ninclude/linux/bvecq.h-239-\tif (old != to) {\ninclude/linux/bvecq.h:240:\t\tpos-\u003ebvecq = bvecq_get(to);\ninclude/linux/bvecq.h-241-\t\tbvecq_put(old);\n"
} |
| 49/3 | 2026/10/05 07:36 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 67889 output: 36 thoughts: 11 Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and rendered in the first person: **Analyzing `bvecq_get`** Alright, time to dig into `bvecq_get`. My initial thought is to just quickly verify its behavior and purpose within the broader context. What's the interface? What data structure does it work on? I need to understand its role. Is it a getter function for a bit-vector-based queue? Then the subsequent thought is to immediately consider edge cases: does it handle empty queues gracefully? What about concurrency? Does it adhere to any locking semantics if the queue is shared? Is there any overflow or underflow protection implemented? Next, I'd move to the implementation details. I'd like to understand how the element is retrieved. Does it involve a simple array index or more complex pointer arithmetic? What is the expected time complexity of the retrieval operation? Are there any potential bottlenecks I should be aware of? And most importantly, is this function optimized for my particular use-case? I need to quickly ascertain how efficient this retrieval function is relative to my application's performance profile. |
| 50/3 | 2026/10/05 07:36 | tool | read-file |
0mArgs:{
"File": "include/linux/bvecq.h",
"FirstLine": 96,
"LineCount": 15
}Results: {
"Contents": " 96:\t * bvecq_get - Get a ref on a bvecq\n 97:\t * @bq: The bvecq to get a ref on\n 98:\t */\n 99:\tstatic inline struct bvecq *bvecq_get(struct bvecq *bq)\n 100:\t{\n 101:\t\trefcount_inc(\u0026bq-\u003eref);\n 102:\t\treturn bq;\n 103:\t}\n 104:\t\n 105:\t/**\n 106:\t * bvecq_is_full - Determine if a bvecq is full\n 107:\t * @bvecq: The object to query\n 108:\t *\n 109:\t * Return: true if full; false if not.\n 110:\t */\n"
} |
| 51/3 | 2026/10/05 07:36 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 68396 output: 28 thoughts: 1540 Thoughts: **Diving into Potential Issues in the Bvecq and Netfs Code** Okay, first things first, let's look at `bvecq_get()`. The refcount increment seems straightforward, but what happens if the `pos->bvecq` is actually NULL? The potential for a NULL pointer dereference immediately raises a red flag in `bvecq_pos_set()`. Then, `bvecq_pos_move()` using a NULL `to` pointer has the same vulnerability. This is something KASAN/crash handlers would catch, which is good, but let's see how this affects other areas of the code. Now, on to the AFS and netfs interaction. I noticed some significant changes in the `fs/afs/dir.c` and `fs/afs/symlink.c` code. Specifically, the patch has changed how `iov_iter_bvec_queue()` is called. Why are we passing `dvnode->directory_size` or `PAGE_SIZE` to the `len` argument, instead of `i_size_read()`? The change indicates the cached DIO is being used. Specifically, the code rounds up the `len` value to be written to cachefiles: `clen = round_up(len, wreq->cache_resources.dio_size)`. So, the critical question is this: if `clen` (the rounded-up size) is greater than the actual data length (`len`), does this mean we're writing bytes beyond the intended data size to the cache? This is something to analyze further. Let's look at the allocation and initialization of `dvnode->directory` in AFS to fully understand the implication. |
| 52/3 | 2026/10/05 07:36 | tool | grepper |
0mArgs:{
"Expression": "dvnode-\u003edirectory",
"PathPrefix": "fs/afs/"
}Results: {
"Output": "fs/afs/dir.c=135=static void afs_dir_dump(struct afs_vnode *dvnode)\n--\nfs/afs/dir.c-142-\nfs/afs/dir.c:143:\tiov_iter_bvec_queue(\u0026iter, ITER_SOURCE, dvnode-\u003edirectory, 0, 0, i_size);\nfs/afs/dir.c-144-\titerate_bvecq(\u0026iter, iov_iter_count(\u0026iter), NULL, NULL,\n--\nfs/afs/dir.c=197=static int afs_dir_check(struct afs_vnode *dvnode)\n--\nfs/afs/dir.c-205-\nfs/afs/dir.c:206:\tiov_iter_bvec_queue(\u0026iter, ITER_SOURCE, dvnode-\u003edirectory, 0, 0, i_size);\nfs/afs/dir.c-207-\tchecked = iterate_bvecq(\u0026iter, iov_iter_count(\u0026iter), dvnode, NULL,\n--\nfs/afs/dir.c=235=static ssize_t afs_do_read_single(struct afs_vnode *dvnode, struct file *file)\n--\nfs/afs/dir.c-249-\t/* Expand the storage. TODO: Shrink the storage too. */\nfs/afs/dir.c:250:\tif (dvnode-\u003edirectory_size \u003c i_size) {\nfs/afs/dir.c:251:\t\tsize_t cur_size = dvnode-\u003edirectory_size;\nfs/afs/dir.c-252-\nfs/afs/dir.c:253:\t\tret = bvecq_expand_buffer(\u0026dvnode-\u003edirectory, \u0026cur_size,\nfs/afs/dir.c-254-\t\t\t\t\t round_up(i_size, PAGE_SIZE),\nfs/afs/dir.c-255-\t\t\t\t\t mapping_gfp_mask(dvnode-\u003enetfs.inode.i_mapping));\nfs/afs/dir.c:256:\t\tdvnode-\u003edirectory_size = cur_size;\nfs/afs/dir.c-257-\t\tif (ret \u003c 0)\n--\nfs/afs/dir.c-260-\nfs/afs/dir.c:261:\tiov_iter_bvec_queue(\u0026iter, ITER_DEST, dvnode-\u003edirectory, 0, 0, dvnode-\u003edirectory_size);\nfs/afs/dir.c-262-\n--\nfs/afs/dir.c=488=static int afs_dir_iterate_contents(struct inode *dir, struct dir_context *dir_ctx)\n--\nfs/afs/dir.c-500-\nfs/afs/dir.c:501:\tiov_iter_bvec_queue(\u0026iter, ITER_SOURCE, dvnode-\u003edirectory, 0, 0, i_size);\nfs/afs/dir.c-502-\tiov_iter_advance(\u0026iter, round_down(dir_ctx-\u003epos, AFS_DIR_BLOCK_SIZE));\n--\nfs/afs/dir.c=2211=static int afs_dir_writepages(struct address_space *mapping,\n--\nfs/afs/dir.c-2230-\tif (test_bit(AFS_VNODE_DIR_VALID, \u0026dvnode-\u003eflags)) {\nfs/afs/dir.c:2231:\t\tiov_iter_bvec_queue(\u0026iter, ITER_SOURCE, dvnode-\u003edirectory, 0, 0,\nfs/afs/dir.c:2232:\t\t\t\t dvnode-\u003edirectory_size);\nfs/afs/dir.c-2233-\t\tret = netfs_writeback_single(mapping, wbc, \u0026iter,\n--\nfs/afs/dir_edit.c=110=static union afs_xdr_dir_block *afs_dir_get_block(struct afs_dir_iter *iter, size_t block)\n--\nfs/afs/dir_edit.c-117-\nfs/afs/dir_edit.c:118:\tif (dvnode-\u003edirectory_size \u003c blend) {\nfs/afs/dir_edit.c:119:\t\tsize_t cur_size = dvnode-\u003edirectory_size;\nfs/afs/dir_edit.c-120-\nfs/afs/dir_edit.c:121:\t\tret = bvecq_expand_buffer(\u0026dvnode-\u003edirectory, \u0026cur_size, blend,\nfs/afs/dir_edit.c-122-\t\t\t\t\t mapping_gfp_mask(dvnode-\u003enetfs.inode.i_mapping));\nfs/afs/dir_edit.c:123:\t\tdvnode-\u003edirectory_size = cur_size;\nfs/afs/dir_edit.c-124-\t\tif (ret \u003c 0)\n--\nfs/afs/dir_edit.c-129-\tif (!bq)\nfs/afs/dir_edit.c:130:\t\tbq = dvnode-\u003edirectory;\nfs/afs/dir_edit.c-131-\n--\nfs/afs/dir_search.c=67=union afs_xdr_dir_block *afs_dir_find_block(struct afs_dir_iter *iter, size_t block)\n--\nfs/afs/dir_search.c-78-\nfs/afs/dir_search.c:79:\tif (dvnode-\u003edirectory_size \u003c blend)\nfs/afs/dir_search.c-80-\t\tgoto fail;\n--\nfs/afs/dir_search.c-82-\tif (!bq || blpos \u003c fpos) {\nfs/afs/dir_search.c:83:\t\tbq = dvnode-\u003edirectory;\nfs/afs/dir_search.c-84-\t\tslot = 0;\n"
} |
| 53/3 | 2026/10/05 07:36 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 71769 output: 37 thoughts: 26 Thoughts: Here's a summary of my thought process: **Diving into `bvecq_expand_buffer` for `dvnode->directory` Page Allocation** Okay, so I need to understand how the system's allocating pages for the `dvnode->directory` structure. Let's start by digging into `bvecq_expand_buffer`. My assumption is that this function is where the memory for the directory itself is allocated or extended. I'll focus on tracing the calls and data structures involved, specifically looking for the page allocation calls, likely through `alloc_pages` or related functions. I'm going to pay close attention to the parameters passed, size requests, and any potential allocation strategies or error handling related to page allocation. I need to figure out the mechanisms and possible considerations for growth and management of this directory structure. |
| 54/3 | 2026/10/05 07:36 | tool | grepper |
0mArgs:{
"Expression": "bvecq_expand_buffer",
"PathPrefix": "fs/netfs/bvecq.c"
}Results: {
"Output": "fs/netfs/bvecq.c=280=EXPORT_SYMBOL(bvecq_put);\n--\nfs/netfs/bvecq.c-282-/**\nfs/netfs/bvecq.c:283: * bvecq_expand_buffer - Allocate buffer space into a bvec queue\nfs/netfs/bvecq.c-284- * @_buffer: Pointer to the bvecq chain to expand (may point to a NULL; updated).\n--\nfs/netfs/bvecq.c-293- */\nfs/netfs/bvecq.c:294:int bvecq_expand_buffer(struct bvecq **_buffer, size_t *_cur_size, size_t size, gfp_t gfp)\nfs/netfs/bvecq.c-295-{\n--\nfs/netfs/bvecq.c-343-}\nfs/netfs/bvecq.c:344:EXPORT_SYMBOL(bvecq_expand_buffer);\nfs/netfs/bvecq.c-345-\n"
} |
| 55/3 | 2026/10/05 07:36 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 72285 output: 38 thoughts: 26 Thoughts: Okay, let's dive into this. I'm going to take a look at the `fs/netfs/bvecq.c` file, specifically lines 294-343. This probably deals with the block vector queue, which is a key data structure for I/O operations in network filesystems. Based on my experience, I expect this section to be the core of handling block I/O requests, likely including queueing, dequeuing, and possibly some form of request merging or splitting. I'll be looking for how the code manages these requests and the strategies employed to optimize I/O performance. I'm keen to see if they're using any smart queuing algorithms or if they're implementing more basic FIFO techniques. It will also be important to see how the code handles error scenarios, as network I/O is susceptible to a myriad of failures. |
| 56/3 | 2026/10/05 07:36 | tool | read-file |
0mArgs:{
"File": "fs/netfs/bvecq.c",
"FirstLine": 294,
"LineCount": 50
}Results: {
"Contents": " 294:\tint bvecq_expand_buffer(struct bvecq **_buffer, size_t *_cur_size, size_t size, gfp_t gfp)\n 295:\t{\n 296:\t\tstruct bvecq *tail = *_buffer;\n 297:\t\n 298:\t\tsize = round_up(size, PAGE_SIZE);\n 299:\t\tif (tail)\n 300:\t\t\twhile (tail-\u003enext)\n 301:\t\t\t\ttail = tail-\u003enext;\n 302:\t\n 303:\t\twhile (*_cur_size \u003c size) {\n 304:\t\t\tstruct page *page;\n 305:\t\t\tsize_t need = size - *_cur_size;\n 306:\t\t\tgfp_t gfp_add;\n 307:\t\t\tint order = 0;\n 308:\t\n 309:\t\t\tif (!tail || bvecq_is_full(tail) || tail-\u003emem_type != BVECQ_MEM_ALLOCED) {\n 310:\t\t\t\tstruct bvecq *p;\n 311:\t\n 312:\t\t\t\tp = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, false);\n 313:\t\t\t\tif (!p)\n 314:\t\t\t\t\treturn -ENOMEM;\n 315:\t\t\t\tif (tail)\n 316:\t\t\t\t\tbvecq_append(tail, p);\n 317:\t\t\t\telse\n 318:\t\t\t\t\t*_buffer = p;\n 319:\t\t\t\ttail = p;\n 320:\t\t\t\tp-\u003emem_type = BVECQ_MEM_ALLOCED;\n 321:\t\t\t}\n 322:\t\n 323:\t\t\tif (need \u003e PAGE_SIZE)\n 324:\t\t\t\torder = umin(ilog2(need) - PAGE_SHIFT, MAX_PAGECACHE_ORDER);\n 325:\t\n 326:\t\t\tgfp_add = 0;\n 327:\t\t\tif (order \u003e 0)\n 328:\t\t\t\tgfp_add |= __GFP_NORETRY | __GFP_NOWARN;\n 329:\t\t\tpage = alloc_pages(gfp | __GFP_COMP | gfp_add, order);\n 330:\t\t\tif (!page \u0026\u0026 order \u003e 0) {\n 331:\t\t\t\tpage = alloc_pages(gfp | __GFP_COMP, 0);\n 332:\t\t\t\torder = 0;\n 333:\t\t\t}\n 334:\t\t\tif (!page)\n 335:\t\t\t\treturn -ENOMEM;\n 336:\t\n 337:\t\t\tbvec_set_page(\u0026tail-\u003ebv[tail-\u003enr_slots], page, PAGE_SIZE \u003c\u003c order, 0);\n 338:\t\t\t*_cur_size += PAGE_SIZE \u003c\u003c order;\n 339:\t\t\tbvecq_filled_to(tail, tail-\u003enr_slots + 1);\n 340:\t\t}\n 341:\t\n 342:\t\treturn 0;\n 343:\t}\n"
} |
| 57/3 | 2026/10/05 07:36 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 73317 output: 29 thoughts: 29 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Investigating a Potential AFS Symlink Write Issue** Hold on a second...did we account for the `afs_symlink_writepages` function? This feels like a detail we might have glossed over in the broader analysis. Given the context, it's absolutely crucial to ensure that any potential write-related problem doesn't stem from how AFS handles symbolic links at the page level. We need to be thorough. Right, time to dig into the code. Specifically, let's head straight to `fs/afs/symlink.c`. That should be the definitive source for how AFS symlinks are implemented and how page writing interacts with them. I'll need to scrutinize that file carefully, looking for how `afs_symlink_writepages` is used, any potential race conditions, or anything else that looks like it might be a weak point, particularly around buffer management or permission checking. The devil is definitely in the details here, and a careful line-by-line inspection is warranted. |
| 58/3 | 2026/10/05 07:36 | tool | grepper |
0mArgs:{
"Expression": "directory",
"PathPrefix": "fs/afs/symlink.c"
}Results: {
"Output": "fs/afs/symlink.c=56=void afs_init_new_symlink(struct afs_vnode *vnode, struct afs_operation *op)\n--\nfs/afs/symlink.c-67-\nfs/afs/symlink.c:68:\tvnode-\u003edirectory =\nfs/afs/symlink.c-69-\t\tbvecq_alloc_buffer(PAGE_SIZE,\n--\nfs/afs/symlink.c-71-\t\t\t\t false);\nfs/afs/symlink.c:72:\tif (!vnode-\u003edirectory)\nfs/afs/symlink.c-73-\t\treturn;\nfs/afs/symlink.c-74-\nfs/afs/symlink.c:75:\tvnode-\u003edirectory_size = size;\nfs/afs/symlink.c:76:\tp = bvec_kmap_partial(\u0026vnode-\u003edirectory-\u003ebv[0], 0);\nfs/afs/symlink.c-77-\tmemcpy(p, symlink-\u003econtent, size);\n--\nfs/afs/symlink.c=87=static ssize_t afs_do_read_symlink(struct afs_vnode *vnode)\n--\nfs/afs/symlink.c-99-\nfs/afs/symlink.c:100:\tif (!vnode-\u003edirectory) {\nfs/afs/symlink.c:101:\t\tvnode-\u003edirectory = bvecq_alloc_buffer(\nfs/afs/symlink.c-102-\t\t\tPAGE_SIZE, mapping_gfp_mask(vnode-\u003enetfs.inode.i_mapping), false);\nfs/afs/symlink.c:103:\t\tif (!vnode-\u003edirectory)\nfs/afs/symlink.c-104-\t\t\treturn -ENOMEM;\n--\nfs/afs/symlink.c-106-\nfs/afs/symlink.c:107:\tiov_iter_bvec_queue(\u0026iter, ITER_DEST, vnode-\u003edirectory, 0, 0, PAGE_SIZE);\nfs/afs/symlink.c-108-\n--\nfs/afs/symlink.c-118-\t\t}\nfs/afs/symlink.c:119:\t\tvnode-\u003edirectory_size = i_size;\nfs/afs/symlink.c-120-\n--\nfs/afs/symlink.c-128-\nfs/afs/symlink.c:129:\t\tconst char *s = bvec_kmap_partial(\u0026vnode-\u003edirectory-\u003ebv[0], 0);\nfs/afs/symlink.c-130-\n--\nfs/afs/symlink.c-137-\tif (!fscache_cookie_enabled(netfs_i_cookie(\u0026vnode-\u003enetfs))) {\nfs/afs/symlink.c:138:\t\tbvecq_put(vnode-\u003edirectory);\nfs/afs/symlink.c:139:\t\tvnode-\u003edirectory = NULL;\nfs/afs/symlink.c:140:\t\tvnode-\u003edirectory_size = 0;\nfs/afs/symlink.c-141-\t}\n--\nfs/afs/symlink.c=233=int afs_symlink_writepages(struct address_space *mapping,\n--\nfs/afs/symlink.c-248-\nfs/afs/symlink.c:249:\tif (vnode-\u003edirectory \u0026\u0026\nfs/afs/symlink.c-250-\t atomic64_read(\u0026vnode-\u003ecb_expires_at) != AFS_NO_CB_PROMISE) {\nfs/afs/symlink.c:251:\t\tiov_iter_bvec_queue(\u0026iter, ITER_SOURCE, vnode-\u003edirectory, 0, 0, PAGE_SIZE);\nfs/afs/symlink.c-252-\t\tret = netfs_writeback_single(mapping, wbc, \u0026iter,\n--\nfs/afs/symlink.c-257-\t\tnetfs_wb_begin(\u0026vnode-\u003enetfs, false);\nfs/afs/symlink.c:258:\t\tbvecq_put(vnode-\u003edirectory);\nfs/afs/symlink.c:259:\t\tvnode-\u003edirectory = NULL;\nfs/afs/symlink.c:260:\t\tvnode-\u003edirectory_size = 0;\nfs/afs/symlink.c-261-\t\tnetfs_wb_end(\u0026vnode-\u003enetfs);\n"
} |
| 59/3 | 2026/10/05 07:36 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 74721 output: 38 thoughts: 32 Thoughts: Here's my analysis of the provided thought process, tailored for an expert audience: **Diving into Buffer Allocation** Okay, so I'm focusing in on `bvecq_alloc_buffer` and trying to get a handle on its internal mechanics. The immediate question is, how *exactly* does this thing go about allocating the buffer? My next step is clearly to trace it down. Let's see if `bvecq_alloc_buffer2` offers any more insights, given the likely naming convention that it's a variant of, or possibly a further function to call after. |
| 60/3 | 2026/10/05 07:36 | tool | grepper |
0mArgs:{
"Expression": "bvecq_alloc_buffer2",
"PathPrefix": "fs/netfs/bvecq.c"
}Results: {
"Output": "fs/netfs/bvecq.c=142=EXPORT_SYMBOL(bvecq_alloc_chain);\n--\nfs/netfs/bvecq.c-144-/**\nfs/netfs/bvecq.c:145: * bvecq_alloc_buffer2 - Allocate a bvecq chain and populate with buffers\nfs/netfs/bvecq.c-146- * @size: Target size of the buffer (can be 0 for an empty buffer)\n--\nfs/netfs/bvecq.c-161- */\nfs/netfs/bvecq.c:162:struct bvecq *bvecq_alloc_buffer2(size_t size, unsigned int pre_slots, gfp_t gfp,\nfs/netfs/bvecq.c-163-\t\t\t\t bool for_writeback)\n--\nfs/netfs/bvecq.c-225-}\nfs/netfs/bvecq.c:226:EXPORT_SYMBOL(bvecq_alloc_buffer2);\nfs/netfs/bvecq.c-227-\n"
} |
| 61/3 | 2026/10/05 07:36 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 75201 output: 38 thoughts: 27 Thoughts: Okay, let's dive into this. Here's my take on `bvecq_alloc_buffer2` within `fs/netfs/bvecq.c`: **Dissecting `bvecq_alloc_buffer2`** Alright, time to get my hands dirty. I'm looking at `bvecq_alloc_buffer2` in the `fs/netfs/bvecq.c` file. Specifically, I need to understand how this function is handling buffer allocation within this particular network file system context. Given my background, I'm already anticipating some of the key areas I'll need to focus on: the interplay between the `bvec` data structure, memory management (slab or page-based?), any potential synchronization issues, and the overall efficiency of buffer allocation and deallocation for network I/O. I'm keen to see if they're employing any clever tricks to minimize fragmentation or optimize for specific network workloads. I'll be paying close attention to any error handling to see how robust the design is, especially in situations where memory allocation fails. Let's start reading... I'll need to cross-reference this with the relevant data structures to gain complete context. |
| 62/3 | 2026/10/05 07:36 | tool | read-file |
0mArgs:{
"File": "fs/netfs/bvecq.c",
"FirstLine": 162,
"LineCount": 45
}Results: {
"Contents": " 162:\tstruct bvecq *bvecq_alloc_buffer2(size_t size, unsigned int pre_slots, gfp_t gfp,\n 163:\t\t\t\t\t bool for_writeback)\n 164:\t{\n 165:\t\tstruct bvecq *head = NULL, *p = NULL;\n 166:\t\tsize_t nr_per_bq = BVECQ_POOL_SLOTS;\n 167:\t\tsize_t count = pre_slots + DIV_ROUND_UP(size, PAGE_SIZE);\n 168:\t\n 169:\t\t_enter(\"%zx,%zx,%u\", size, count, pre_slots);\n 170:\t\n 171:\t\tif (WARN_ON_ONCE(pre_slots \u003e nr_per_bq))\n 172:\t\t\treturn NULL;\n 173:\t\n 174:\t\thead = bvecq_alloc_chain(count, gfp, for_writeback);\n 175:\t\tif (!head)\n 176:\t\t\treturn NULL;\n 177:\t\n 178:\t\tp = head;\n 179:\t\tdo {\n 180:\t\t\tstruct page **pages;\n 181:\t\t\tsize_t unused, want, got, slot;\n 182:\t\n 183:\t\t\tif (!count)\n 184:\t\t\t\tbreak;\n 185:\t\t\tif (WARN_ON_ONCE(!p))\n 186:\t\t\t\tgoto oom;\n 187:\t\n 188:\t\t\tif (p-\u003enr_slots == 0) {\n 189:\t\t\t\t/* Need to clear pre slots and pages[], so just clear all. */\n 190:\t\t\t\tmemset(p-\u003ebv, 0, p-\u003emax_slots * sizeof(p-\u003ebv[0]));\n 191:\t\t\t\tp-\u003emem_type = BVECQ_MEM_ALLOCED;\n 192:\t\t\t\tp-\u003enr_slots = pre_slots;\n 193:\t\t\t\tcount -= pre_slots;\n 194:\t\t\t\tpre_slots = 0;\n 195:\t\t\t\tif (!count)\n 196:\t\t\t\t\tbreak;\n 197:\t\t\t}\n 198:\t\n 199:\t\t\tif (p-\u003enr_slots \u003e= p-\u003emax_slots) {\n 200:\t\t\t\tp = p-\u003enext;\n 201:\t\t\t\tcontinue;\n 202:\t\t\t}\n 203:\t\t\tunused = p-\u003emax_slots - p-\u003enr_slots;\n 204:\t\n 205:\t\t\tpages = (struct page **)\u0026p-\u003ebv[p-\u003emax_slots];\n 206:\t\t\tpages -= unused;\n"
} |
| 63/3 | 2026/10/05 07:36 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 76206 output: 38 thoughts: 26 Thoughts: Okay, here's my interpretation of what's going through my mind as I approach this code snippet, rendered in the first person, assuming I'm a seasoned kernel developer: **Diving into `fs/netfs/bvecq.c`** Alright, time to crack open `fs/netfs/bvecq.c`. I'm specifically targeting lines 205-230. I'm assuming that this section deals with some aspect of buffer vector queuing within the netfs filesystem, but I need to quickly confirm what's being handled here to get context. My experience tells me that `bvecq` functions usually involve managing data transfers, likely for network I/O, so I'll be looking for things related to buffer allocation, queuing/dequeuing, perhaps some locking or synchronization to prevent race conditions. The goal here is to understand the control flow, how the function interacts with the data structures within the kernel, and ultimately, what problem is this particular piece of code trying to solve. Is this related to congestion control, memory management, or something else? I will need to understand the function’s inputs and outputs. Given the nature of networking, I’m also mentally preparing for potential issues like error handling, and timeout behavior, so I'll be ready to look for how this code deals with those potential issues as well. Let's see what the code reveals. |
| 64/3 | 2026/10/05 07:36 | tool | read-file |
0mArgs:{
"File": "fs/netfs/bvecq.c",
"FirstLine": 205,
"LineCount": 26
}Results: {
"Contents": " 205:\t\t\tpages = (struct page **)\u0026p-\u003ebv[p-\u003emax_slots];\n 206:\t\t\tpages -= unused;\n 207:\t\n 208:\t\t\twant = min(count, unused);\n 209:\t\t\tgot = alloc_pages_bulk(gfp, want, pages);\n 210:\t\t\tif (!got)\n 211:\t\t\t\tgoto oom;\n 212:\t\n 213:\t\t\tslot = p-\u003enr_slots;\n 214:\t\t\tfor (int i = 0; i \u003c got; i++)\n 215:\t\t\t\tbvec_set_page(\u0026p-\u003ebv[slot++], pages[i], PAGE_SIZE, 0);\n 216:\t\n 217:\t\t\tbvecq_filled_to(p, slot);\n 218:\t\t\tcount -= got;\n 219:\t\t} while (count \u003e 0);\n 220:\t\n 221:\t\treturn head;\n 222:\toom:\n 223:\t\tbvecq_put(head);\n 224:\t\treturn NULL;\n 225:\t}\n 226:\tEXPORT_SYMBOL(bvecq_alloc_buffer2);\n 227:\t\n 228:\t/*\n 229:\t * Free the page pointed to by a slot as necessary.\n 230:\t */\n"
} |
| 65/3 | 2026/10/05 07:36 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 76927 output: 35 thoughts: 47 Thoughts: Here's a breakdown of my thought process: **Diving into the `netfs_extract_iter` Implementation** Okay, so I need to understand how `netfs_extract_iter` works. My first step is to zero in on the source code. I'm heading directly to `fs/netfs/iterator.c`, specifically focusing on lines 20 through 150. I'll need to absorb the core logic of that function. That block should contain the main structure of the iterator, so I need to analyze how it's retrieving data, handling errors, and managing its internal state. I'll be looking for things like data structure usage, any locking mechanisms, and the overall flow control. Let's see what interesting techniques the developers used there. |
| 66/3 | 2026/10/05 07:36 | tool | read-file |
0mArgs:{
"File": "fs/netfs/iterator.c",
"FirstLine": 20,
"LineCount": 80
}Results: {
"Contents": " 20:\t * @max_pages: Maximum number of pages to extract\n 21:\t * @_bvecq_head: Where to cache the bvec queue\n 22:\t * @extraction_flags: Flags to qualify the request\n 23:\t * @gfp: Allocation mode for bvecq structs.\n 24:\t *\n 25:\t * Extract virtually contiguous page fragments from the source iterator up to\n 26:\t * the given maxima and build bvec queue that refers to all of those bits.\n 27:\t * This allows the original iterator to disposed of.\n 28:\t *\n 29:\t * @extraction_flags can have ITER_ALLOW_P2PDMA set to request peer-to-peer DMA\n 30:\t * be allowed on the pages extracted.\n 31:\t *\n 32:\t * On success or partial success, the amount of data in the bvec is returned,\n 33:\t * the original iterator will have been advanced by the amount extracted.\n 34:\t *\n 35:\t * If an error occurs and no pages are extracted, an error will be returned and\n 36:\t * any allocated bvecq will be freed. If there is no data to be extracted (or\n 37:\t * @max_len or @max_pages are zero), a single empty bvecq will be returned.\n 38:\t *\n 39:\t * The bvecq segments are marked with indications on how to get clean up the\n 40:\t * extracted fragments.\n 41:\t */\n 42:\tssize_t netfs_extract_iter(struct iov_iter *orig, size_t max_len, size_t max_pages,\n 43:\t\t\t\t struct bvecq **_bvecq_head,\n 44:\t\t\t\t iov_iter_extraction_t extraction_flags, gfp_t gfp)\n 45:\t{\n 46:\t\tstruct bvecq *bq_tail = NULL, *bq;\n 47:\t\tssize_t ret = 0;\n 48:\t\tsize_t extracted = 0;\n 49:\t\n 50:\t\t_enter(\"{%u,%zx},%zx\", orig-\u003eiter_type, orig-\u003ecount, max_len);\n 51:\t\n 52:\t\t*_bvecq_head = NULL;\n 53:\t\tif (max_len \u003e orig-\u003ecount)\n 54:\t\t\tmax_len = orig-\u003ecount;\n 55:\t\tif (!max_len || !max_pages)\n 56:\t\t\tgoto alloc_empty;\n 57:\t\tif (WARN_ON_ONCE(max_pages \u003e INT_MAX))\n 58:\t\t\tmax_pages = INT_MAX; /* Protect iov_iter_npages(). */\n 59:\t\n 60:\t\tmax_pages = iov_iter_npages(orig, max_pages);\n 61:\t\tif (!max_pages)\n 62:\t\t\tgoto alloc_empty;\n 63:\t\n 64:\t\tdo {\n 65:\t\t\tbq = bvecq_alloc_one(max_pages, gfp, false);\n 66:\t\t\tif (!bq) {\n 67:\t\t\t\tret = -ENOMEM;\n 68:\t\t\t\tbreak;\n 69:\t\t\t}\n 70:\t\t\tif (user_backed_iter(orig))\n 71:\t\t\t\tbq-\u003emem_type = iov_iter_extract_will_pin(orig) ?\n 72:\t\t\t\t\tBVECQ_MEM_GUP : BVECQ_MEM_PAGECACHE;\n 73:\t\n 74:\t\t\tif (bq_tail)\n 75:\t\t\t\tbvecq_append(bq_tail, bq);\n 76:\t\t\telse\n 77:\t\t\t\t*_bvecq_head = bq;\n 78:\t\t\tbq_tail = bq;\n 79:\t\n 80:\t\t\tif (max_len == 0)\n 81:\t\t\t\tbreak;\n 82:\t\n 83:\t\t\tstruct bio_vec *bv = bq-\u003ebv;\n 84:\t\t\tunsigned int slot = 0;\n 85:\t\t\tdo {\n 86:\t\t\t\tstruct page **pages;\n 87:\t\t\t\tssize_t got;\n 88:\t\t\t\tsize_t offset;\n 89:\t\t\t\tsize_t space = bq-\u003emax_slots - slot;\n 90:\t\t\t\tsize_t bv_size = array_size(bq-\u003emax_slots, sizeof(*bv));\n 91:\t\t\t\tsize_t pg_size = array_size(space, sizeof(*pages));\n 92:\t\n 93:\t\t\t\t/* Put the page list at the end of the bvec list\n 94:\t\t\t\t * storage. bvec elements are larger than page\n 95:\t\t\t\t * pointers, so as long as we work 0-\u003elast, we should\n 96:\t\t\t\t * be fine.\n 97:\t\t\t\t */\n 98:\t\t\t\tpages = (void *)bv + bv_size - pg_size;\n 99:\t\n"
} |
| 67/3 | 2026/10/05 07:36 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 78420 output: 36 thoughts: 26 Thoughts: Okay, here's my attempt at summarizing the thought process, as requested, geared toward an expert audience, and written in the first person: **Diving into `netfs_extract_iter`** Alright, let's get down to brass tacks. I need to fully grasp the implementation of `netfs_extract_iter` in `fs/netfs/iterator.c`. Given the context, I'm assuming we're dealing with some sort of networked filesystem traversal. I need to understand how it's extracting data. This means tracing the function call and seeing how it handles requests and interactions. I'll need to pay close attention to the data structures involved, the error handling, and any locking mechanisms used to ensure thread safety. Let's see what interesting techniques the original programmers used, and whether there may be optimizations available. I'm also on the lookout for potential performance bottlenecks or subtle race conditions. Time to dig in! |
| 68/3 | 2026/10/05 07:37 | tool | read-file |
0mArgs:{
"File": "fs/netfs/iterator.c",
"FirstLine": 100,
"LineCount": 55
}Results: {
"Contents": " 100:\t\t\t\tgot = iov_iter_extract_pages(orig, \u0026pages, max_len,\n 101:\t\t\t\t\t\t\t min(space, max_pages),\n 102:\t\t\t\t\t\t\t extraction_flags, \u0026offset);\n 103:\t\t\t\tif (got \u003c 0) {\n 104:\t\t\t\t\tret = got;\n 105:\t\t\t\t\tgoto out;\n 106:\t\t\t\t}\n 107:\t\n 108:\t\t\t\tif (got == 0) {\n 109:\t\t\t\t\tpr_err(\"extract_pages gave nothing from %zx, %zx\\n\",\n 110:\t\t\t\t\t extracted, max_len);\n 111:\t\t\t\t\tret = -EIO;\n 112:\t\t\t\t\tgoto out;\n 113:\t\t\t\t}\n 114:\t\n 115:\t\t\t\tif (WARN(got \u003e max_len,\n 116:\t\t\t\t\t \"%s: extract_pages overrun %zx \u003e %zx bytes\\n\",\n 117:\t\t\t\t\t __func__, got, max_len)) {\n 118:\t\t\t\t\tret = -EIO;\n 119:\t\t\t\t\tgoto out;\n 120:\t\t\t\t}\n 121:\t\n 122:\t\t\t\textracted += got;\n 123:\t\t\t\tmax_len -= got;\n 124:\t\n 125:\t\t\t\tdo {\n 126:\t\t\t\t\tsize_t len = umin(got, PAGE_SIZE - offset);\n 127:\t\n 128:\t\t\t\t\tBUG_ON(slot \u003e= bq-\u003emax_slots);\n 129:\t\n 130:\t\t\t\t\tbvec_set_page(\u0026bq-\u003ebv[slot], *pages++, len, offset);\n 131:\t\t\t\t\tslot++;\n 132:\t\t\t\t\tmax_pages--;\n 133:\t\t\t\t\tgot -= len;\n 134:\t\t\t\t\toffset = 0;\n 135:\t\t\t\t} while (got \u003e 0);\n 136:\t\n 137:\t\t\t\tbvecq_filled_to(bq, slot);\n 138:\t\t\t} while (max_len \u003e 0 \u0026\u0026 max_pages \u003e 0 \u0026\u0026 !bvecq_is_full(bq));\n 139:\t\n 140:\t\t} while (max_len \u003e 0 \u0026\u0026 max_pages \u003e 0);\n 141:\t\n 142:\tout:\n 143:\t\tif (extracted || ret == 0)\n 144:\t\t\treturn extracted;\n 145:\t\tbvecq_put(*_bvecq_head);\n 146:\t\t*_bvecq_head = NULL;\n 147:\t\treturn ret;\n 148:\t\n 149:\talloc_empty:\n 150:\t\tbq = bvecq_alloc_one(1, gfp, false);\n 151:\t\tif (!bq)\n 152:\t\t\treturn -ENOMEM;\n 153:\t\t*_bvecq_head = bq;\n 154:\t\treturn 0;\n"
} |
| 69/3 | 2026/10/05 07:37 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 79446 output: 36 thoughts: 2477 Thoughts: **Deep Dive into `bvecq` and its Uses in NetFS I/O** Okay, let's break down this `bvecq` situation within the NetFS implementation. Initially, I was looking at `netfs_extract_iter` and how it pulls pages from the original I/O vector. `iov_iter_extract_pages` does the extraction, and then `bvec_set_page` initializes the `bvec` slots within a `bvecq`. `bvecq_filled_to` is critical here; it seems to update `nr_slots` to the number of filled slots. The logic handles potential errors where nothing is extracted, potentially nullifying the `*_bvecq_head`. Conversely, an empty state allocates a single slot. But what about `bvecq_slice`? Let's analyze it. It looks like `bvecq_slice` relies heavily on `bvecq_nr_slots_acquire(bq)` to determine the valid slots. This is important since each slot, up to that number, is guaranteed to be initialized by a previous `bvecq_filled_to` call. The logic within `bvecq_slice` is focused on slicing portions of the `bvec` array, managing the offset and size, and ensuring we don't exceed the provided limits. There's a careful check with `bvecq_next`, but the assumption is that `bvecq_nr_slots_acquire` accurately reflects the state of the queue. Now, shifting gears, let's delve into `bvecq_load_from_ra`. Here, `bvecq_alloc_chain` is used to allocate the chain of `bvecq` structures, based on the number of folios (`ractl->_nr_folios`). This allocation and folio setup is critical to the chain construction. The code then iterates through the folios, setting up `bvec_set_folio` for each one, loading the data, and incrementing the slot count. The important part is making sure `bvecq_filled_to` is called as folios are loaded, ensuring that the counts are updated correctly. The size of the `ractl` struct is likely configured with some value, and a common use-case has folios chained together. Digging further, I observe `netfs_retry_read_subrequests` and `netfs_retry_write_stream`. A `dispatch_cursor` is on the stack, which is zero initialized. `bvecq_pos_transfer` and `bvecq_pos_advance` are used to update it. Then, `bvecq_slice` is employed to determine the subrequest size using `umin` to limit the size. So, the cursor is being advanced through the bvecq, and `bvecq_slice` is determining the next chunk. Then there are some calls to `bvecq_pos_set` to set the new cursor. It looks like the same pattern is also present in `netfs_read_to_pagecache`. `bvecq_pos_set` initializes the cursor from a previous cursor location, effectively copying its state and grabbing a reference. Finally, examining the `netfs_reissue_read`, `netfs_reissue_write`, and `netfs_clear_unread` functions, I can see how the `bvecq` and `iov_iter` interact during I/O retry and zeroing. `iov_iter_bvec_queue` is key here; it correctly initializes an `iov_iter` structure using the current state of the `bvecq` (the `bvecq`, `slot`, and `offset` fields in `io_buffer`). This allows for resumed reads and writes from the correct position. The important thing is that `iov_iter_bvec_queue` is fully initializing the `iov_iter` structure, allowing for clean iteration. I should probably double check the `iov_iter_bvec_queue` implementation. |
| 70/3 | 2026/10/05 07:38 | tool | grepper |
0mArgs:{
"Expression": "iov_iter_bvec_queue",
"PathPrefix": "include/linux/uio.h"
}Results: {
"Output": "include/linux/uio.h=296=void iov_iter_discard(struct iov_iter *i, unsigned int direction, size_t count);\ninclude/linux/uio.h:297:void iov_iter_bvec_queue(struct iov_iter *i, unsigned int direction,\ninclude/linux/uio.h-298-\t\t\t const struct bvecq *bvecq,\n"
} |
| 71/3 | 2026/10/05 07:38 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 82937 output: 35 thoughts: 24 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Diving into `iov_iter_bvec_queue` in `lib/iov_iter.c`** Alright, let's get down to brass tacks. I need to take a look at how `iov_iter_bvec_queue` is implemented. Specifically, I'm thinking about the low-level details of how it handles I/O vector iteration with block vectors. I want to quickly refresh my understanding of the data structures involved, and the mechanics of efficiently queuing these block vectors within the iovec iterator framework. I'm focusing on that specific function call, as this is likely where the core performance characteristics are defined. I’m thinking about the interplay between the `iov_iter` structure and the `bvec` structure and how this function bridges that gap, especially in heavy I/O workloads. Time to get my hands dirty and jump into the code. |
| 72/3 | 2026/10/05 07:38 | tool | grepper |
0mArgs:{
"Expression": "iov_iter_bvec_queue",
"PathPrefix": "lib/iov_iter.c"
}Results: {
"Output": "lib/iov_iter.c=739=EXPORT_SYMBOL(iov_iter_bvec);\n--\nlib/iov_iter.c-741-/**\nlib/iov_iter.c:742: * iov_iter_bvec_queue - Initialise an I/O iterator to use a segmented bvec queue\nlib/iov_iter.c-743- * @i: The iterator to initialise.\n--\nlib/iov_iter.c-753- */\nlib/iov_iter.c:754:void iov_iter_bvec_queue(struct iov_iter *i, unsigned int direction,\nlib/iov_iter.c-755-\t\t\t const struct bvecq *bvecq, unsigned int first_slot,\n--\nlib/iov_iter.c-767-}\nlib/iov_iter.c:768:EXPORT_SYMBOL(iov_iter_bvec_queue);\nlib/iov_iter.c-769-\n"
} |
| 73/3 | 2026/10/05 07:38 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 83448 output: 35 thoughts: 23 Thoughts: Okay, let's dive into this. Here's my take on those lines from `lib/iov_iter.c`, from my perspective: **Diving Deep into `lib/iov_iter.c`** Alright, I'm setting my sights on lines 754-768 of `lib/iov_iter.c`. I need to understand what's happening here within the `iov_iter` structure and its associated operations. Knowing the context of this specific section will be crucial. I'm guessing this might be related to handling IO vectors. Let me see what sort of specific operations are being performed here. Am I looking at initialization, iteration, data copying, or maybe something more complex like scatter-gather operations? Perhaps I'll find some insights regarding the underlying mechanisms for efficiently managing and processing data in memory. This is probably a good place to be, to gain a deeper understanding. I need to keep in mind the potential performance implications of this code. I should also watch out for any edge cases or potential concurrency issues. I will carefully consider the various data structures and algorithms involved. |
| 74/3 | 2026/10/05 07:38 | tool | read-file |
0mArgs:{
"File": "lib/iov_iter.c",
"FirstLine": 754,
"LineCount": 16
}Results: {
"Contents": " 754:\tvoid iov_iter_bvec_queue(struct iov_iter *i, unsigned int direction,\n 755:\t\t\t\t const struct bvecq *bvecq, unsigned int first_slot,\n 756:\t\t\t\t unsigned int offset, size_t count)\n 757:\t{\n 758:\t\tWARN_ON(direction \u0026 ~(READ | WRITE));\n 759:\t\t*i = (struct iov_iter) {\n 760:\t\t\t.iter_type\t= ITER_BVECQ,\n 761:\t\t\t.data_source\t= direction,\n 762:\t\t\t.bvecq\t\t= bvecq,\n 763:\t\t\t.bvecq_slot\t= first_slot,\n 764:\t\t\t.count\t\t= count,\n 765:\t\t\t.iov_offset\t= offset,\n 766:\t\t};\n 767:\t}\n 768:\tEXPORT_SYMBOL(iov_iter_bvec_queue);\n 769:\t\n"
} |
| 75/3 | 2026/10/05 07:38 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 84006 output: 34 thoughts: 1533 Thoughts: **Analysis of iov_iter and netfs Changes** Okay, so I'm diving into this `iov_iter` code and the related `netfs` changes. Initially, the code seems to fully initialize the `iter` struct via a zeroing operation, which is good. However, that immediately raised a flag regarding the `bvecq_pos` fields. I need to make sure those aren't somehow making their way into user space, which would be a security risk. After examining the `struct bvecq_pos` definition, it's clear it's an internal kernel structure used by `netfs` and `bvecq` internally and *never* exposed to user space through any of the usual avenues (copies, network, ioctls, etc.). That's a relief. The next thing to investigate is trace events. I checked `include/trace/events/netfs.h`, specifically the `netfs_sreq` trace event. It shows a change where `sreq->io_iter.bvecq_slot` has been changed to `sreq->io_buffer.slot`. That's important. It also now has the `netfs_bv_slot` trace event which assigns the `slot`, `pfn`, `offset`, and `len` explicitly, so there is no leakage of data. All the fields are explicitly assigned, and nothing concerning is exposed. Now, let's get into the *core* of it. The crucial change is in `netfs_unbuffered_read_iter_locked`. It appears they've shifted the way the iterator is handled. Before, there was a distinction between user-backed and kernel-backed iterators. If the iterator was user-backed, `netfs_extract_user_iter` was used. Otherwise, it simply copied the iterator. However, now `netfs_extract_iter` is called in both cases! This raises an important question: can `iov_iter_extract_pages`—which `netfs_extract_iter` uses—handle kernel iterators? If it can, then this change is fine. If not, this is a major problem and likely a functional change as well. I need to check `iov_iter_extract_pages` to confirm. It has potentially significant implications in how data is extracted from the iterator. I'll need to follow this up to make sure no data leaks and no changes in behavior occur. |
| 76/3 | 2026/10/05 07:38 | tool | grepper |
0mArgs:{
"Expression": "iov_iter_extract_pages",
"PathPrefix": "lib/iov_iter.c"
}Results: {
"Output": "lib/iov_iter.c=1817=static ssize_t iov_iter_extract_bvec_pages(struct iov_iter *i,\n--\nlib/iov_iter.c-1847-\t\t/*\nlib/iov_iter.c:1848:\t\t * The iov_iter_extract_pages interface only allows an offset\nlib/iov_iter.c-1849-\t\t * into the first page. Break out of the loop if we see an\nlib/iov_iter.c-1850-\t\t * offset into subsequent pages, the caller will have to call\nlib/iov_iter.c:1851:\t\t * iov_iter_extract_pages again for the reminder.\nlib/iov_iter.c-1852-\t\t */\n--\nlib/iov_iter.c-1869-\t\t * The caller will handle this with another call to\nlib/iov_iter.c:1870:\t\t * iov_iter_extract_pages.\nlib/iov_iter.c-1871-\t\t */\n--\nlib/iov_iter.c=1950=static ssize_t iov_iter_extract_user_pages(struct iov_iter *i,\n--\nlib/iov_iter.c-1990-/**\nlib/iov_iter.c:1991: * iov_iter_extract_pages - Extract a list of contiguous pages from an iterator\nlib/iov_iter.c-1992- * @i: The iterator to extract from\n--\nlib/iov_iter.c-2032- */\nlib/iov_iter.c:2033:ssize_t iov_iter_extract_pages(struct iov_iter *i,\nlib/iov_iter.c-2034-\t\t\t struct page ***pages,\n--\nlib/iov_iter.c-2065-}\nlib/iov_iter.c:2066:EXPORT_SYMBOL_GPL(iov_iter_extract_pages);\nlib/iov_iter.c-2067-\nlib/iov_iter.c=2068=static unsigned int get_contig_folio_len(struct page **pages,\n--\nlib/iov_iter.c-2111- *\nlib/iov_iter.c:2112: * Like iov_iter_extract_pages(), but returns physically contiguous ranges\nlib/iov_iter.c-2113- * contained in a single folio as a single bvec instead of multiple entries.\n--\nlib/iov_iter.c=2119=ssize_t iov_iter_extract_bvecs(struct iov_iter *iter, struct bio_vec *bv,\n--\nlib/iov_iter.c-2156-\nlib/iov_iter.c:2157:\tsize = iov_iter_extract_pages(iter, \u0026pages, max_size, entries_left,\nlib/iov_iter.c-2158-\t\t\textraction_flags, \u0026offset);\n"
} |
| 77/3 | 2026/10/05 07:38 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 86838 output: 27 thoughts: 780 Thoughts: **Delving into AFS Directory Writeback**
Okay, so I'm looking at how `iov_iter_extract_pages` handles different memory sources – bvecs, kvecs, xarrays, user pages, the whole lot. And I'm specifically drawn to `netfs_extract_iter` in this context. It's used in this context:
```c
if (user_backed_iter(orig))
bq->mem_type = iov_iter_extract_will_pin(orig) ?
BVECQ_MEM_GUP : BVECQ_MEM_PAGECACHE;
```
Interesting, if it's not user-backed, `bq->mem_type` is `BVECQ_MEM_NONE`, or 0.
But then I stumble upon `fs/afs/dir.c`. Here's where it gets interesting. I see a call to `iov_iter_bvec_queue` with `dvnode->directory` involved. It appears there is a recent change here, in particular, a call that looks like this:
```c
ret = netfs_writeback_single(mapping, wbc, &iter,
i_size_read(&dvnode->netfs.inode));
```
That's intriguing. I have to see how that `netfs_writeback_single` function works. Let's look inside that function.
```c
int netfs_writeback_single(struct address_space *mapping,
struct writeback_control *wbc,
struct iov_iter *iter, size_t len)
...
wreq->len = len;
clen = len;
if (wreq->cache_resources.dio_size > 1) {
clen = round_up(len, wreq->cache_resources.dio_size);
if (clen > iov_iter_count(iter)) {
ret = -EIO;
goto cleanup_free;
}
}
ret = netfs_extract_iter(iter, clen, INT_MAX, &wreq->dispatch_cursor.bvecq,
0, wreq->gfp);
...
```
Right, `netfs_writeback_single` takes an iterator and `len`, and aligns the write length (`clen`) to the cache's Direct I/O block size. Here's the key: if `clen` is *greater* than `len` (because of the alignment), the cache writes `clen` bytes:
```c
subreq = stream->construct;
subreq->len = wreq->len;
if (stream->source == NETFS_WRITE_TO_CACHE)
subreq->len = clen;
stream->submit_len = subreq->len;
netfs_issue_write(wreq, stream);
```
Okay, here's the critical question: Does `dvnode->directory` have initialized memory up to this aligned length, `clen`? Looking back at `afs_dir_writepages`, I see:
`iov_iter_bvec_queue(&iter, ITER_SOURCE, dvnode->directory, 0, 0, dvnode->directory_size);`
So `len` is actually `i_size_read(&dvnode->netfs.inode)`. And what about `dvnode->directory_size`?
I need to understand how big `dvnode->directory` actually is, and more importantly, how that memory is initialized. I need to know if we write more than the content of the directory? Is this safe? I'll have to investigate where `dvnode->directory` is written, and maybe how it's read to see where this is used. Let's start with `afs_do_read_single`. I'll search the code for any references to `dvnode->directory` within `fs/afs/dir.c`.
|
| 78/3 | 2026/10/05 07:38 | tool | grepper |
0mArgs:{
"Expression": "directory_size",
"PathPrefix": "fs/afs/"
}Results: {
"Output": "fs/afs/dir.c=235=static ssize_t afs_do_read_single(struct afs_vnode *dvnode, struct file *file)\n--\nfs/afs/dir.c-249-\t/* Expand the storage. TODO: Shrink the storage too. */\nfs/afs/dir.c:250:\tif (dvnode-\u003edirectory_size \u003c i_size) {\nfs/afs/dir.c:251:\t\tsize_t cur_size = dvnode-\u003edirectory_size;\nfs/afs/dir.c-252-\n--\nfs/afs/dir.c-255-\t\t\t\t\t mapping_gfp_mask(dvnode-\u003enetfs.inode.i_mapping));\nfs/afs/dir.c:256:\t\tdvnode-\u003edirectory_size = cur_size;\nfs/afs/dir.c-257-\t\tif (ret \u003c 0)\n--\nfs/afs/dir.c-260-\nfs/afs/dir.c:261:\tiov_iter_bvec_queue(\u0026iter, ITER_DEST, dvnode-\u003edirectory, 0, 0, dvnode-\u003edirectory_size);\nfs/afs/dir.c-262-\n--\nfs/afs/dir.c=2211=static int afs_dir_writepages(struct address_space *mapping,\n--\nfs/afs/dir.c-2231-\t\tiov_iter_bvec_queue(\u0026iter, ITER_SOURCE, dvnode-\u003edirectory, 0, 0,\nfs/afs/dir.c:2232:\t\t\t\t dvnode-\u003edirectory_size);\nfs/afs/dir.c-2233-\t\tret = netfs_writeback_single(mapping, wbc, \u0026iter,\n--\nfs/afs/dir_edit.c=110=static union afs_xdr_dir_block *afs_dir_get_block(struct afs_dir_iter *iter, size_t block)\n--\nfs/afs/dir_edit.c-117-\nfs/afs/dir_edit.c:118:\tif (dvnode-\u003edirectory_size \u003c blend) {\nfs/afs/dir_edit.c:119:\t\tsize_t cur_size = dvnode-\u003edirectory_size;\nfs/afs/dir_edit.c-120-\n--\nfs/afs/dir_edit.c-122-\t\t\t\t\t mapping_gfp_mask(dvnode-\u003enetfs.inode.i_mapping));\nfs/afs/dir_edit.c:123:\t\tdvnode-\u003edirectory_size = cur_size;\nfs/afs/dir_edit.c-124-\t\tif (ret \u003c 0)\n--\nfs/afs/dir_search.c=67=union afs_xdr_dir_block *afs_dir_find_block(struct afs_dir_iter *iter, size_t block)\n--\nfs/afs/dir_search.c-78-\nfs/afs/dir_search.c:79:\tif (dvnode-\u003edirectory_size \u003c blend)\nfs/afs/dir_search.c-80-\t\tgoto fail;\n--\nfs/afs/internal.h=687=struct afs_vnode {\n--\nfs/afs/internal.h-722-\tafs_lock_type_t\t\tlock_type : 8;\nfs/afs/internal.h:723:\tunsigned int\t\tdirectory_size;\t/* Amount of space in -\u003edirectory */\nfs/afs/internal.h-724-\n--\nfs/afs/super.c=670=static struct inode *afs_alloc_inode(struct super_block *sb)\n--\nfs/afs/super.c-688-\tvnode-\u003edirectory\t= NULL;\nfs/afs/super.c:689:\tvnode-\u003edirectory_size\t= 0;\nfs/afs/super.c-690-\n--\nfs/afs/symlink.c=56=void afs_init_new_symlink(struct afs_vnode *vnode, struct afs_operation *op)\n--\nfs/afs/symlink.c-74-\nfs/afs/symlink.c:75:\tvnode-\u003edirectory_size = size;\nfs/afs/symlink.c-76-\tp = bvec_kmap_partial(\u0026vnode-\u003edirectory-\u003ebv[0], 0);\n--\nfs/afs/symlink.c=87=static ssize_t afs_do_read_symlink(struct afs_vnode *vnode)\n--\nfs/afs/symlink.c-118-\t\t}\nfs/afs/symlink.c:119:\t\tvnode-\u003edirectory_size = i_size;\nfs/afs/symlink.c-120-\n--\nfs/afs/symlink.c-139-\t\tvnode-\u003edirectory = NULL;\nfs/afs/symlink.c:140:\t\tvnode-\u003edirectory_size = 0;\nfs/afs/symlink.c-141-\t}\n--\nfs/afs/symlink.c=233=int afs_symlink_writepages(struct address_space *mapping,\n--\nfs/afs/symlink.c-259-\t\tvnode-\u003edirectory = NULL;\nfs/afs/symlink.c:260:\t\tvnode-\u003edirectory_size = 0;\nfs/afs/symlink.c-261-\t\tnetfs_wb_end(\u0026vnode-\u003enetfs);\n"
} |
| 79/3 | 2026/10/05 07:38 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 89889 output: 37 thoughts: 371 Thoughts: **Analyzing the Single Read Path in AFS/NetFS** Alright, let's dive into this `afs_do_read_single` function. First, I see it's checking `dvnode->directory_size` against `i_size`. The crucial part here is the expansion of the `dvnode->directory` buffer if it's too small. It uses `bvecq_expand_buffer` with some interesting size calculations, rounding up `i_size` to the nearest page size. That's standard practice, of course, to avoid partial page reads. Then the iter is initialized with `iov_iter_bvec_queue`, using the expanded directory. Makes sense. Now, I need to see where this `afs_do_read_single` function goes after that. It calls `netfs_read_single`, and that's where the real I/O happens in this single read path. Inside `netfs_read_single` the `netfs_extract_iter` call looks important. It is going to handle the iteration/extraction. Then it dispatches it via `netfs_single_dispatch_read`. So, what does this `netfs_single_dispatch_read` actually *do*? I'll need to check the source file `fs/netfs/read_single.c` to understand that dispatch. That's the real core of the read operation. Time to go look. |
| 80/3 | 2026/10/05 07:39 | tool | read-file |
0mArgs:{
"File": "fs/netfs/read_single.c",
"FirstLine": 90,
"LineCount": 45
}Results: {
"Contents": " 90:\t\t/* Try to use the cache if the cache content matches the size of the\n 91:\t\t * remote file.\n 92:\t\t */\n 93:\t\tnetfs_read_query_cache(rreq, \u0026occ);\n 94:\t\tif (occ.cached_from[0] == 0 \u0026\u0026\n 95:\t\t occ.cached_to[0] \u003e= rreq-\u003elen)\n 96:\t\t\tsource = NETFS_READ_FROM_CACHE;\n 97:\t\n 98:\t\tsubreq = netfs_alloc_subrequest(rreq, source);\n 99:\t\tif (!subreq)\n 100:\t\t\treturn -ENOMEM;\n 101:\t\n 102:\t\tsubreq-\u003estart\t= 0;\n 103:\t\tsubreq-\u003elen\t= rreq-\u003elen;\n 104:\t\n 105:\t\tbvecq_pos_set(\u0026subreq-\u003eio_buffer, \u0026rreq-\u003edispatch_cursor);\n 106:\t\n 107:\t\tiov_iter_bvec_queue(\u0026subreq-\u003eio_iter, ITER_DEST, subreq-\u003eio_buffer.bvecq,\n 108:\t\t\t\t subreq-\u003eio_buffer.slot, subreq-\u003eio_buffer.offset, subreq-\u003elen);\n 109:\t\n 110:\t\tnetfs_queue_read(rreq, subreq);\n 111:\t\n 112:\t\tswitch (subreq-\u003esource) {\n 113:\t\tcase NETFS_DOWNLOAD_FROM_SERVER:\n 114:\t\t\tnetfs_stat(\u0026netfs_n_rh_download);\n 115:\t\t\tif (rreq-\u003enetfs_ops-\u003eprepare_read) {\n 116:\t\t\t\tret = rreq-\u003enetfs_ops-\u003eprepare_read(subreq);\n 117:\t\t\t\tif (ret \u003c 0)\n 118:\t\t\t\t\tgoto cancel;\n 119:\t\t\t}\n 120:\t\n 121:\t\t\tnetfs_all_subreqs_queued(rreq);\n 122:\t\t\trreq-\u003enetfs_ops-\u003eissue_read(subreq);\n 123:\t\t\trreq-\u003esubmitted += subreq-\u003elen;\n 124:\t\t\tbreak;\n 125:\t\tcase NETFS_READ_FROM_CACHE:\n 126:\t\t\tif (rreq-\u003ecache_resources.ops-\u003eprepare_read) {\n 127:\t\t\t\tret = rreq-\u003ecache_resources.ops-\u003eprepare_read(subreq);\n 128:\t\t\t\tif (ret \u003c 0)\n 129:\t\t\t\t\tgoto cancel;\n 130:\t\t\t}\n 131:\t\n 132:\t\t\tnetfs_all_subreqs_queued(rreq);\n 133:\t\t\ttrace_netfs_sreq(subreq, netfs_sreq_trace_submit);\n 134:\t\t\tnetfs_single_read_cache(rreq, subreq);\n"
} |
| 81/3 | 2026/10/05 07:39 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 91360 output: 38 thoughts: 27 Thoughts: Okay, here's my interpretation of what's going through my mind, delivered as a first-person summary, keeping in mind the expert user: **Deep Dive into `fs/netfs/read_single.c`** Alright, I'm already deep into this, but before I go much further, let's just make sure we haven't overlooked something fundamental. The core read operation, as I understand it, is handled within the `read_single.c` file of the netfs module, specifically lines 135 through 180. I need to briefly check what's happening there with the read operation, because it's the heart of the matter. We want to be certain about the flow, especially with regard to the interaction with the buffer, the network layer and any potential error handling at this stage. I'll need to pay close attention to the way the data is copied and how they ensure data integrity. Nothing groundbreaking, just a quick sanity check to establish my starting point. This section should cover error management and any race conditions. No sense in spinning our wheels further down the line if there's a problem here. Okay, let's see what's what. |
| 82/3 | 2026/10/05 07:39 | tool | read-file |
0mArgs:{
"File": "fs/netfs/read_single.c",
"FirstLine": 135,
"LineCount": 45
}Results: {
"Contents": " 135:\t\t\trreq-\u003esubmitted += subreq-\u003elen;\n 136:\t\t\tret = 0;\n 137:\t\t\tbreak;\n 138:\t\tdefault:\n 139:\t\t\tpr_warn(\"Unexpected single-read source %u\\n\", subreq-\u003esource);\n 140:\t\t\tWARN_ON_ONCE(true);\n 141:\t\t\tret = -EIO;\n 142:\t\t\tgoto cancel;\n 143:\t\t}\n 144:\t\n 145:\t\treturn ret;\n 146:\tcancel:\n 147:\t\tnetfs_cancel_read(subreq, ret);\n 148:\t\tnetfs_all_subreqs_queued(rreq);\n 149:\t\tnetfs_wake_collector(rreq);\n 150:\t\treturn ret;\n 151:\t}\n 152:\t\n 153:\t/**\n 154:\t * netfs_read_single - Synchronously read a single blob of pages.\n 155:\t * @inode: The inode to read from.\n 156:\t * @file: The file we're using to read or NULL.\n 157:\t * @iter: The buffer we're reading into.\n 158:\t *\n 159:\t * Fulfil a read request for a single monolithic object by drawing data from\n 160:\t * the cache if possible, or the netfs if not. The buffer may be larger than\n 161:\t * the file content; unused beyond the EOF will be zero-filled. The content\n 162:\t * will be read with a single I/O request (though this may be retried).\n 163:\t *\n 164:\t * The calling netfs must initialise a netfs context contiguous to the vfs\n 165:\t * inode before calling this.\n 166:\t *\n 167:\t * This is usable whether or not caching is enabled. If caching is enabled,\n 168:\t * the data will be stored as a single object into the cache.\n 169:\t */\n 170:\tssize_t netfs_read_single(struct inode *inode, struct file *file, struct iov_iter *iter)\n 171:\t{\n 172:\t\tstruct netfs_io_request *rreq;\n 173:\t\tstruct netfs_inode *ictx = netfs_inode(inode);\n 174:\t\tssize_t ret;\n 175:\t\n 176:\t\trreq = netfs_alloc_request(inode-\u003ei_mapping, file, 0, iov_iter_count(iter),\n 177:\t\t\t\t\t NETFS_READ_SINGLE);\n 178:\t\tif (IS_ERR(rreq))\n 179:\t\t\treturn PTR_ERR(rreq);\n"
} |
| 83/3 | 2026/10/05 07:39 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 92411 output: 26 thoughts: 1116 Thoughts: **KMSAN Needs Assessment for NetFS Changes**
Okay, let's break down this code and determine if these NetFS changes introduce any risks that KMSAN needs to flag. My focus is on potential uninitialized memory reads or leaks.
First, I looked at how data is read and written in this part of the filesystem. In `netfs_single_dispatch_read`, `rreq->len` is set from `iov_iter_count(iter)`, which corresponds to the `dvnode->directory_size`. I also noticed the server/cache interaction with `netfs_clear_unread` or `iov_iter_zero` zeroing the remaining bytes if the server/cache returns fewer bytes. Then, the symbolic link operations, like in `afs_symlink_writepages`, use `iov_iter_bvec_queue` with `PAGE_SIZE` allocations. `afs_init_new_symlink` allocates a zeroed buffer, which is good. Similar reads in `afs_do_read_symlink` with allocation and `netfs_read_single` are also present.
Now, let's apply the KMSAN criteria:
1. **Kernel structures sent to user space:** I'm not seeing any new kernel structures directly exposed to user space through the standard methods like `copy_to_user`, netlink, ioctl, or BPF. So, this doesn't look like an immediate concern.
2. **Conditional logic based on uninitialized data:** I need to make sure any conditional logic doesn't depend on uninitialized variables. This is the main thing to check.
3. **Allocation of complex data structures:** The allocation of `directory` in the symbolic link functions needs to be examined. However, it seems to be zeroed or initialized.
4. **Bounds checks and uninitialized byte access:** I'll verify if the changes allow surrounding code to access uninitialized bytes of existing buffers.
Now, let's meticulously check variable initialization:
* I see a zero-initialized `struct bvecq_pos dispatch_cursor = {};` in `netfs_retry_read_subrequests` and `netfs_retry_write_stream`. Good, the zero-initialization is what I want to see.
* `struct bvecq_pos mark_cursor` in `netfs_read_to_pagecache` is initialized immediately.
* `struct iov_iter iter` in `netfs_clear_unread` is also initialized immediately.
* In `fs/netfs/objects.c`, the `rreq` and `subreq` structures are zeroed via `memset`. Their new fields (`rreq->spare`, `rreq->load_cursor`, `rreq->dispatch_cursor`, `rreq->collect_cursor`, `rreq->last_end`, and `subreq->io_buffer`) are therefore also zero-initialized by that `memset`. Perfect.
* In `fs/netfs/bvecq.c`, `bvecq_alloc_one` appears safe, and also uses a constructor. Likewise, `bvecq_buffer_init`, `bvecq_load_from_ra`, and `bvecq_slice` appear safe.
* Regarding the `struct readahead_control`, the new field `ractl->_nr_folios` is initialized to 0. It is initialized upon allocation or by `read_pages`, so there are no issues.
**Conclusion:**
Based on this analysis, I'm not seeing any evidence of *uninitialized* variables or struct fields being introduced, or being read, within the scope of these changes, and there appears to be no information leak. Every structure is carefully zeroed or immediately initialized. This patch *does not* introduce any risk of uninitialized memory usage or info-leaks, based on the criteria. Therefore, **NeedsKMSAN=false**.
|
| 84/3 | 2026/10/05 07:40 | tool | grepper |
0mArgs:{
"Expression": "_nr_folios",
"PathPrefix": "mm/"
}Results: {
"Output": "mm/readahead.c=160=static void read_pages(struct readahead_control *rac)\n--\nmm/readahead.c-190-\trac-\u003e_workingset = false;\nmm/readahead.c:191:\trac-\u003e_nr_folios = 0;\nmm/readahead.c-192-\n--\nmm/readahead.c=223=void page_cache_ra_unbounded(struct readahead_control *ractl,\n--\nmm/readahead.c-306-\t\tractl-\u003e_workingset |= folio_test_workingset(folio);\nmm/readahead.c:307:\t\tractl-\u003e_nr_folios++;\nmm/readahead.c-308-\t\tractl-\u003e_nr_pages += min_nrpages;\n--\nmm/readahead.c=461=static inline int ra_alloc_folio(struct readahead_control *ractl, pgoff_t index,\n--\nmm/readahead.c-477-\nmm/readahead.c:478:\tractl-\u003e_nr_folios++;\nmm/readahead.c-479-\tractl-\u003e_nr_pages += 1UL \u003c\u003c order;\n--\nmm/readahead.c=789=void readahead_expand(struct readahead_control *ractl,\n--\nmm/readahead.c-827-\t\t}\nmm/readahead.c:828:\t\tractl-\u003e_nr_folios++;\nmm/readahead.c-829-\t\tractl-\u003e_nr_pages += min_nrpages;\n--\nmm/readahead.c-857-\t\t}\nmm/readahead.c:858:\t\tractl-\u003e_nr_folios++;\nmm/readahead.c-859-\t\tractl-\u003e_nr_pages += min_nrpages;\n"
} |
| 85/3 | 2026/10/05 07:40 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 94857 output: 31 thoughts: 30 Thoughts: Okay, let's dive into this. Here's how I'd approach that query, as my own thought process: **Investigating the Initialization of `struct readahead_control`** Alright, the core question is about how `struct readahead_control` is set up. Specifically, I need to understand its initialization across different contexts, including within `page_cache_ra_unbounded` and any other places it's used. This is likely crucial for understanding the overall readahead mechanism and, potentially, pinpointing any optimization opportunities or identifying potential areas for bugs. I'll need to trace its initialization path, paying close attention to any default values, derived values, or conditional logic that impacts its fields. Comparing initialization methods in different scenarios will likely provide valuable insights. For example, are there differences in settings used for bounded versus unbounded readahead? I need to look for any potential for inconsistencies or assumptions that might be invalid under specific workloads or file system configurations. I also need to be aware of the impact of those initial values on performance. So, let's start digging into the code and see what we can find. |
| 86/3 | 2026/10/05 07:40 | tool | grepper |
0mError:no matches Args: {
"Expression": "struct readahead_control ractl",
"PathPrefix": "mm/"
}Results: {
"error": "no matches"
} |
| 87/3 | 2026/10/05 07:40 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 95171 output: 30 thoughts: 20 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Investigating `readahead_control` in `mm/readahead.c`** Alright, let's dive in. I need to get my hands dirty and track down the implementation of `readahead_control`. My gut tells me it's going to reside within the memory management subsystem, specifically related to the readahead functionality. So, the logical place to start is within the `mm` directory. Given the specific function name, I'd expect it to be in `readahead.c`. It's a pretty common naming convention, and it's where I'd logically place it if I were writing this code myself. I'm making a mental note that there might be indirect references, perhaps through structures or macros, but my initial focus is on finding the direct definition first. This likely provides a core starting point for investigation. Let's see what we find! |
| 88/3 | 2026/10/05 07:40 | tool | grepper |
0mArgs:{
"Expression": "readahead_control",
"PathPrefix": "mm/readahead.c"
}Results: {
"Output": "mm/readahead.c=147=EXPORT_SYMBOL_GPL(file_ra_state_init);\n--\nmm/readahead.c-159- */\nmm/readahead.c:160:static void read_pages(struct readahead_control *rac)\nmm/readahead.c-161-{\n--\nmm/readahead.c-195-\nmm/readahead.c:196:static struct folio *ractl_alloc_folio(struct readahead_control *ractl,\nmm/readahead.c-197-\t\t\t\t gfp_t gfp_mask, unsigned int order)\n--\nmm/readahead.c-222- */\nmm/readahead.c:223:void page_cache_ra_unbounded(struct readahead_control *ractl,\nmm/readahead.c-224-\t\tunsigned long nr_to_read, unsigned long lookahead_size)\n--\nmm/readahead.c=320=EXPORT_SYMBOL_GPL(page_cache_ra_unbounded);\n--\nmm/readahead.c-327- */\nmm/readahead.c:328:static void do_page_cache_ra(struct readahead_control *ractl,\nmm/readahead.c-329-\t\tunsigned long nr_to_read, unsigned long lookahead_size)\n--\nmm/readahead.c-357- */\nmm/readahead.c:358:void force_page_cache_ra(struct readahead_control *ractl,\nmm/readahead.c-359-\t\tunsigned long nr_to_read)\n--\nmm/readahead.c=410=static unsigned long get_next_ra_size(struct file_ra_state *ra,\n--\nmm/readahead.c-460-\nmm/readahead.c:461:static inline int ra_alloc_folio(struct readahead_control *ractl, pgoff_t index,\nmm/readahead.c-462-\t\tpgoff_t mark, unsigned int order, gfp_t gfp)\n--\nmm/readahead.c-483-\nmm/readahead.c:484:void page_cache_ra_order(struct readahead_control *ractl,\nmm/readahead.c-485-\t\tstruct file_ra_state *ra)\n--\nmm/readahead.c-564-\nmm/readahead.c:565:static unsigned long ractl_max_pages(struct readahead_control *ractl,\nmm/readahead.c-566-\t\tunsigned long req_size)\n--\nmm/readahead.c-579-\nmm/readahead.c:580:void page_cache_sync_ra(struct readahead_control *ractl,\nmm/readahead.c-581-\t\tunsigned long req_count)\n--\nmm/readahead.c=654=EXPORT_SYMBOL_GPL(page_cache_sync_ra);\nmm/readahead.c-655-\nmm/readahead.c:656:void page_cache_async_ra(struct readahead_control *ractl,\nmm/readahead.c-657-\t\tstruct folio *folio, unsigned long req_count)\n--\nmm/readahead.c=765=COMPAT_SYSCALL_DEFINE4(readahead, int, fd, compat_arg_u64_dual(offset), size_t, count)\n--\nmm/readahead.c-788- */\nmm/readahead.c:789:void readahead_expand(struct readahead_control *ractl,\nmm/readahead.c-790-\t\t loff_t new_start, size_t new_len)\n"
} |
| 89/3 | 2026/10/05 07:40 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 96370 output: 19 thoughts: 15 Thoughts: Here's my take on those thoughts, tailored for an expert audience: **Investigating `readahead_control` Declarations** Alright, let's get down to brass tacks. I need to understand the scope and usage of `readahead_control`. My immediate task is to pinpoint exactly where these `readahead_control` instances are being *declared*. I'm thinking I'll need to trace through the code, probably starting with the header files to get a grip on the data structure itself and then move on to the implementation to look for the instantiations. I want to see how these are initialized, and where the specific parameters originate. Where are the `readahead_control` structures defined? Which files? How are they named? Are there any patterns or naming conventions to help me locate them efficiently? A careful examination of the source code is in order here. |
| 90/3 | 2026/10/05 07:41 | tool | grepper |
0mArgs:{
"Expression": "DEFINE_READAHEAD"
}Results: {
"Output": "fs/f2fs/file.c=4794=static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len)\nfs/f2fs/file.c-4795-{\nfs/f2fs/file.c:4796:\tDEFINE_READAHEAD(ractl, NULL, NULL, inode-\u003ei_mapping, page_idx);\nfs/f2fs/file.c-4797-\tstruct address_space *mapping = inode-\u003ei_mapping;\n--\nfs/verity/pagecache.c=42=void generic_readahead_merkle_tree(struct inode *inode, pgoff_t index,\n--\nfs/verity/pagecache.c-51-\t (!IS_ERR(folio) \u0026\u0026 !folio_test_uptodate(folio))) {\nfs/verity/pagecache.c:52:\t\tDEFINE_READAHEAD(ractl, NULL, NULL, inode-\u003ei_mapping, index);\nfs/verity/pagecache.c-53-\n--\ninclude/linux/pagemap.h=1408=struct readahead_control {\n--\ninclude/linux/pagemap.h-1421-\ninclude/linux/pagemap.h:1422:#define DEFINE_READAHEAD(ractl, f, r, m, i)\t\t\t\t\\\ninclude/linux/pagemap.h-1423-\tstruct readahead_control ractl = {\t\t\t\t\\\n--\ninclude/linux/pagemap.h=1454=void page_cache_sync_readahead(struct address_space *mapping,\n--\ninclude/linux/pagemap.h-1457-{\ninclude/linux/pagemap.h:1458:\tDEFINE_READAHEAD(ractl, file, ra, mapping, index);\ninclude/linux/pagemap.h-1459-\tpage_cache_sync_ra(\u0026ractl, req_count);\n--\ninclude/linux/pagemap.h=1476=void page_cache_async_readahead(struct address_space *mapping,\n--\ninclude/linux/pagemap.h-1479-{\ninclude/linux/pagemap.h:1480:\tDEFINE_READAHEAD(ractl, file, ra, mapping, folio-\u003eindex);\ninclude/linux/pagemap.h-1481-\tpage_cache_async_ra(\u0026ractl, folio, req_count);\n--\nmm/filemap.c=2672=static int filemap_readahead(struct kiocb *iocb, struct file *file,\n--\nmm/filemap.c-2675-{\nmm/filemap.c:2676:\tDEFINE_READAHEAD(ractl, file, \u0026file-\u003ef_ra, mapping, folio-\u003eindex);\nmm/filemap.c-2677-\n--\nmm/filemap.c=2686=static int filemap_get_pages(struct kiocb *iocb, size_t count,\n--\nmm/filemap.c-2705-\tif (!folio_batch_count(fbatch)) {\nmm/filemap.c:2706:\t\tDEFINE_READAHEAD(ractl, filp, \u0026filp-\u003ef_ra, mapping, index);\nmm/filemap.c-2707-\n--\nmm/filemap.c=3329=static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)\n--\nmm/filemap.c-3333-\tstruct address_space *mapping = file-\u003ef_mapping;\nmm/filemap.c:3334:\tDEFINE_READAHEAD(ractl, file, ra, mapping, vmf-\u003epgoff);\nmm/filemap.c-3335-\tstruct file *fpin = NULL;\n--\nmm/filemap.c=3452=static struct file *do_async_mmap_readahead(struct vm_fault *vmf,\n--\nmm/filemap.c-3456-\tstruct file_ra_state *ra = \u0026file-\u003ef_ra;\nmm/filemap.c:3457:\tDEFINE_READAHEAD(ractl, file, ra, file-\u003ef_mapping, vmf-\u003epgoff);\nmm/filemap.c-3458-\tstruct file *fpin = NULL;\n--\nmm/internal.h=615=static inline void force_page_cache_readahead(struct address_space *mapping,\n--\nmm/internal.h-617-{\nmm/internal.h:618:\tDEFINE_READAHEAD(ractl, file, \u0026file-\u003ef_ra, mapping, index);\nmm/internal.h-619-\tforce_page_cache_ra(\u0026ractl, nr_to_read);\n"
} |
| 91/3 | 2026/10/05 07:41 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 97786 output: 409 thoughts: 1082 Thoughts: **Memory Management Assessment - KMSAN Not Required**
Okay, let's break this down. Using designated initializers in `DEFINE_READAHEAD` ensures that any unmentioned fields, like `_nr_folios`, are implicitly zeroed. That's a good starting point. I need to make absolutely sure there aren't any sneaky uninitialized memory reads or information leaks to userspace.
First, the `bvecq_pos` struct: it's stack-allocated and properly initialized with `{}` or `bvecq_pos_set()`, or is part of a larger, zeroed struct, `netfs_io_request` or `netfs_io_subrequest`. No user-space interaction here, which is ideal.
Next, `bvecq_alloc_one`: the header fields are zeroed, and `bv` slots are written before `nr_slots` is updated, good. `bvecq_load_from_ra` allocates and fills the bvecq chain, setting `nr_slots` appropriately. `bvecq_zero` zeroes the pages via `bvec_zero` with `memset`, which is safe. `netfs_extract_iter` allocates, fills the bvecq, and also correctly initializes bvec slots before calling `bvecq_filled_to`.
The removal of `rolling_buffer.c` and replacement with `bvecq_pos` is straightforward; the `bvecq_pos` cursors are initialized as described above. The change in `cachefiles_issue_write` is similarly benign, and is handled correctly by other calls. AFS directory and symlink writepages are also using initialized data, passing appropriate sizes and lengths.
Crucially, **nothing** is being passed to userspace that could contain uninitialized data. There are no `copy_to_user`, `put_user`, or network calls with uninitialized memory. There are no conditionals that depend on uninitialized variables. All modified or new stack and heap structures are either completely zeroed or explicitly initialized before use.
The potential bugs introduced by this patch series are things I'm used to dealing with. Stuff like cursor sync issues, locking/concurrency bugs in bvec queues, slicing length mistakes, and NULL pointer dereferences fall into the category of logic errors, data corruption, or memory bounds errors – classic KASAN/LOCKDEP territory, and functional correctness issues. I'm not seeing any *uninitialized memory* risks here that would be exclusively caught by KMSAN.
So, according to the rule, KMSAN is not necessary here. The focus should be on standard KASAN fuzzing to catch any UAF, OOB, etc., that might be present. KMSAN's resource cost isn't worth it in this case. My reasoning is solid, contrasting KASAN vs KMSAN applicability, and I'm confident in setting `NeedsKMSAN=false`.
|
| 92/3 | 2026/10/05 07:41 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series refactors the netfs and AFS I/O buffering architecture by replacing the 'rolling_buffer' construct with 'bvecq_pos' cursors and bvec queue slicing/zeroing operations. \n\nEvaluating the changes for uninitialized memory risks and info-leaks:\n1. All newly introduced or modified structures on the stack and heap are properly initialized. 'struct bvecq_pos' local instances are explicitly zero-initialized (e.g., '= {}' or through 'bvecq_pos_set()'), while heap-allocated requests ('netfs_io_request' and 'netfs_io_subrequest') are zeroed using memset() during allocation in 'netfs_alloc_request()' and 'netfs_alloc_subrequest()'.\n2. The 'struct readahead_control' modifications add an internal counter '_nr_folios', which is zero-initialized by designated initializer macros (DEFINE_READAHEAD) and reset in 'read_pages()'.\n3. 'bvecq_zero()' explicitly clears destination buffer pages using memset() before signaling completion.\n4. No kernel structures, padding, or uninitialized buffers are copied to user space (no copy_to_user, put_user, netlink, ioctl, or BPF transfers).\n5. Any potential memory bugs introduced by this patch series (e.g., cursor pointer manipulation errors, reference counting on bvecq nodes, bounds on segment slicing, or concurrency bugs between producer and consumer cursors) would manifest as out-of-bounds accesses, use-after-free, or NULL pointer dereferences, all of which are already reliably detected by KASAN and standard bug detectors.\n\nTherefore, there are no uninitialized memory risks or info-leak vectors that warrant a dedicated KMSAN fuzzing session.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series refactors the netfs and AFS I/O buffering architecture by replacing the 'rolling_buffer' construct with 'bvecq_pos' cursors and bvec queue slicing/zeroing operations. \n\nEvaluating the changes for uninitialized memory risks and info-leaks:\n1. All newly introduced or modified structures on the stack and heap are properly initialized. 'struct bvecq_pos' local instances are explicitly zero-initialized (e.g., '= {}' or through 'bvecq_pos_set()'), while heap-allocated requests ('netfs_io_request' and 'netfs_io_subrequest') are zeroed using memset() during allocation in 'netfs_alloc_request()' and 'netfs_alloc_subrequest()'.\n2. The 'struct readahead_control' modifications add an internal counter '_nr_folios', which is zero-initialized by designated initializer macros (DEFINE_READAHEAD) and reset in 'read_pages()'.\n3. 'bvecq_zero()' explicitly clears destination buffer pages using memset() before signaling completion.\n4. No kernel structures, padding, or uninitialized buffers are copied to user space (no copy_to_user, put_user, netlink, ioctl, or BPF transfers).\n5. Any potential memory bugs introduced by this patch series (e.g., cursor pointer manipulation errors, reference counting on bvecq nodes, bounds on segment slicing, or concurrency bugs between producer and consumer cursors) would manifest as out-of-bounds accesses, use-after-free, or NULL pointer dereferences, all of which are already reliably detected by KASAN and standard bug detectors.\n\nTherefore, there are no uninitialized memory risks or info-leak vectors that warrant a dedicated KMSAN fuzzing session.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|