| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/11/10 17:50 | flow | patch-triage |
21mArgs:null Results: {
"EnableConfigs": [
"NETFS_SUPPORT",
"AFS_FS",
"CIFS",
"FSCACHE",
"AFS_FSCACHE",
"9P_FS"
],
"FocusSymbols": [
"bvecq_alloc_one",
"bvecq_alloc_chain",
"bvecq_alloc_buffer2",
"bvecq_put",
"bvecq_expand_buffer",
"iov_iter_bvec_queue",
"rolling_buffer_init",
"rolling_buffer_make_space",
"rolling_buffer_bulk_load_from_ra",
"rolling_buffer_append",
"rolling_buffer_delete_spent",
"netfs_writeback_single",
"netfs_read_unlock_folios",
"netfs_writeback_unlock_folios",
"netfs_limit_iter",
"afs_dir_get_block",
"afs_dir_find_block",
"afs_symlink_writepages"
],
"KMSANReasoning": "The patch series replaces the `folio_queue` data structure (`ITER_FOLIOQ`) with `bvecq` (`ITER_BVECQ`) across netfs, AFS, and CIFS/SMB. \n\n1. Allocation \u0026 Initialization: Newly introduced `struct bvecq` instances are allocated via `bvecq_alloc_one()` and fully initialized using a designated C99 struct literal `*bq = (struct bvecq) { ... }`, which guarantees that all unmentioned fields (such as `next`, `prev`, `nr_slots`, `priv`) are zero-initialized. When allocating pre-populated slot buffers (`bvecq_alloc_buffer2`), all slots in `p-\u003ebv` are explicitly zeroed with `memset` before population. In `bvecq_expand_buffer()`, each bio_vec slot is fully initialized via `bvec_set_page()` before `bvecq_filled_to()` updates `nr_slots`.\n2. Access \u0026 Boundaries: Accesses to slots in `bq-\u003ebv` are strictly bounded by `bq-\u003enr_slots` (or `bvecq_acquire_slot()`), preventing reads of uninitialized slots.\n3. Information Leaks \u0026 Userspace Copying: Neither `struct bvecq` nor its internal metadata is copied to userspace. In AFS directory and symlink handling, the patch explicitly adds zeroing of buffer padding (`iov_iter_zero`) before writeback/cache storage.\n4. Error surface: Any potential bugs introduced by this patch (e.g., iterator slot advancement/revert bounds bugs, list traversal issues, or refcounting errors) represent out-of-bounds accesses, use-after-free, or concurrency issues, which are comprehensively detected by KASAN and standard kernel debug facilities.\n\nTherefore, dedicated KMSAN fuzzing is not required.",
"NeedsKMSAN": false,
"Reasoning": "The patch series replaces the folio_queue abstraction with bvecq (segmented bio_vec queue) across netfs, iov_iter, scatterlist, afs, and smb/cifs. It introduces new memory management, refcounting, and queue manipulation helpers (bvecq_*), reworks rolling buffer management in netfs, modifies iteration and extraction primitives in lib/iov_iter.c, and updates read/write collection and directory/symlink handling in afs and cifs. These are reachable core and filesystem code paths that warrant fuzzing.",
"WorthFuzzing": true
} |
| 1/1 | 2026/11/10 17:50 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit fdcfc8440281f97bfd03cc621cb873b3b7b135ac\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Tue Nov 10 17:50:40 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/Documentation/core-api/bvecq.rst b/Documentation/core-api/bvecq.rst\nnew file mode 100644\nindex 00000000000000..4a2b3e28898220\n--- /dev/null\n+++ b/Documentation/core-api/bvecq.rst\n@@ -0,0 +1,229 @@\n+.. SPDX-License-Identifier: GPL-2.0\n+\n+=========================================\n+bvecq - Chainable bio_vec queue structure\n+=========================================\n+\n+Author: David Howells \u003cdhowells@redhat.com\u003e\n+\n+.. Contents:\n+\n+ * Overview\n+ * Allocating bvecqs\n+ * Refcounting\n+ * Expandable buffer\n+ * Producer functions\n+ * Consumer functions\n+ * Utility functions\n+ * I/O iterators\n+ * API Function Reference\n+\n+\n+Overview\n+========\n+\n+The ``bvecq`` struct can be used to form chains of arrays of ``bio_vec``\n+structures - kind of a single layer of indirection. Each bvecq segment points\n+to the previous and next bvecq segments in the chain, but is not intended to\n+form a circular queue as there are applications where the producer is adding to\n+one end whilst the consumer is taking off the other.\n+\n+To use this, the caller should do::\n+\n+\t#include \u003clinux/bvecq.h\u003e\n+\n+The publicly accessible members of the structure are::\n+\n+\tstruct bvecq {\n+\t\tstruct bvecq\t*next;\n+\t\tstruct bvecq\t*prev;\n+\t\tu32\t\tpriv;\n+\t\tu16\t\tnr_slots;\n+\t\tu16\t\tmax_slots;\n+\t\tenum bvecq_mem\tmem_type:3;\n+\t\tstruct bio_vec\t*bv;\n+\t\t...\n+\t};\n+\n+A pair of pointers are provided, ``next`` and ``prev``, that point to the\n+segments on either side of the segment being accessed. Whilst this is a\n+doubly-linked list, it is intentionally not a circular list; the outward\n+sibling pointers in terminal segments should be NULL.\n+\n+The ``priv`` member is for the owner of the bvecq to use as they will.\n+\n+The ``bv`` pointer points at an array of bio_vecs that list a number of regions\n+of memory. ``max_slots`` indicates how large the array is and ``nr_slots``\n+says how much of the array is being used. Note that there are access functions\n+for nr_slots that insert appropriate barriering in the case that there are\n+separate producer and consumer threads.\n+\n+The ``mem_type`` member informs bvecq_put() of how to clean up the bio_vecs\n+attached to this segment. It can be one of:\n+\n+ * ``BVECQ_MEM_EXTERNAL`` - Externally managed; no cleanup.\n+ * ``BVECQ_MEM_PAGECACHE`` - Part of pagecache; put_page() used.\n+ * ``BVECQ_MEM_GUP`` - Pinned userspace memory; unpin_user_page() used.\n+ * ``BVECQ_MEM_ALLOCED`` - Allocated page; __free_pages() used, may be pooled.\n+\n+\n+Allocating bvecqs\n+=================\n+\n+A number of functions are provided to allocate bvecqs::\n+\n+\tstruct bvecq *bvecq_alloc_one(size_t nr_slots,\n+\t\t\t\t gfp_t gfp,\n+\t\t\t\t bool for_writeback);\n+\tstruct bvecq *bvecq_alloc_chain(size_t nr_slots,\n+\t\t\t\t\tgfp_t gfp,\n+\t\t\t\t\tbool for_writeback);\n+\tstruct bvecq *bvecq_alloc_buffer(size_t size,\n+\t\t\t\t\t gfp_t gfp,\n+\t\t\t\t\t bool for_writeback);\n+\tstruct bvecq *bvecq_alloc_buffer2(size_t size,\n+\t\t\t\t\t unsigned int pre_slots,\n+\t\t\t\t\t gfp_t gfp,\n+\t\t\t\t\t bool for_writeback);\n+\n+The first of these, ``bvecq_alloc_one()`` allocates a single bvecq with at\n+least the requested number of inline slots. The size of the object is rounded\n+up to the size of the slab granule that it will be allocated in and the number\n+of slots increased appropriately to match. If ``for_writeback`` is set, then\n+the netfslib writeback bvecq pool will be used to backstop the allocation if\n+the initial slab request fails; in such a case, the number of slots will get\n+reduced to ``BVECQ_POOL_SLOTS``.\n+\n+Two convenience slot count constants are provided:\n+\n+ * ``BVECQ_POOL_SLOTS`` - The right number of slots to alloc from the mempool\n+ * ``BVECQ_4KB_SLOTS`` - The right number of slots to get a 4K allocation\n+\n+``bvecq_alloc_chain()`` will allocate a sufficiently large chain of bvecqs to\n+hold the requested number of slots, capping each allocation at 4K.\n+\n+``bvecq_alloc_buffer()`` will allocate a chain and populate it, allocating\n+sufficient pages to provide a buffer of the specified size attached to the\n+chain. ``bvecq_alloc_buffer2()`` is similar, but it reserves some unused\n+slots at the front of the chain. Note that these functions may add multipage\n+pages in the future.\n+\n+\n+Refcounting\n+===========\n+\n+Each bvecq has a refcount and two functions are provided to handle that::\n+\n+\tstruct bvecq *bvecq_get(struct bvecq *bq);\n+\tvoid bvecq_put(struct bvecq *bq);\n+\n+The first of these gets a new reference and the second drops a reference. When\n+the refcount hits zero, the second iteratively drops the refs along the chain\n+until it hits a segment that has a refcount that doesn't reduce to zero.\n+\n+\n+Expandable buffer\n+=================\n+\n+This facility provides a function to manage an expandable buffer::\n+\n+\tint bvecq_expand_buffer(struct bvecq **_buffer,\n+\t\t\t\tsize_t *_cur_size,\n+\t\t\t\tsize_t size,\n+\t\t\t\tgfp_t gfp);\n+\n+Pages are added to the bvecq chain and the chain expanded such that, on\n+returning, it holds ``size`` amount of space (without losing any content). The\n+caller needs to retain ``*_cur_size`` between calls as that tracks the amount\n+of space currently allocated. Note that pages in the chain may be allocated as\n+compound pages larger than PAGE_SIZE.\n+\n+\n+Producer functions\n+==================\n+\n+When building and filling a bvecq, there are a number of utility functions that\n+can be used to provide the correct barriering and to query the fields in the\n+bvecq currently being filled.\n+\n+Firstly, there's a function to check to see if a bvecq has any spare slots\n+left::\n+\n+\tbool bvecq_is_full(const struct bvecq *bvecq);\n+\n+If not, ``bvecq_alloc_one()`` can be called to allocate a new segment which can\n+be initialised and then added to the chain with::\n+\n+\tvoid bvecq_append(struct bvecq *to, struct bvecq *add);\n+\n+bio_vec slots in the segment can then be filled and the number of occupied\n+slots updated by calling::\n+\n+\tvoid bvecq_filled_to(struct bvecq *bvecq,\n+\t\t\t unsigned int to);\n+\n+to insert the appropriate barrier.\n+\n+\n+Consumer functions\n+==================\n+\n+When consuming and destroying a bvecq, there are some utility functions for\n+that too, providing the needed barriering. Firstly, there's a function to find\n+out how many slots have been used in the current bvecq::\n+\n+\tunsigned int bvecq_nr_slots_acquire(const struct bvecq *bvecq);\n+\n+Or, more conveniently, if the current slot position is valid within the bvecq::\n+\n+\tbool bvecq_acquire_slot(const struct bvecq *bvecq,\n+\t\t\t\tunsigned int slot);\n+\n+If this returns true, the slot is valid and can be looked at; if it returns\n+false, the bvecq may have been consumed. If it has, the next bvecq can be\n+obtained by calling::\n+\n+\tstruct bvecq *bvecq_next(const struct bvecq *bq);\n+\n+which inserts the appropriate barrier - though bvecq_acquire_slot should be\n+rechecked after calling this in case the producer added more slots and then\n+extended the list.\n+\n+\n+Utility functions\n+=================\n+\n+A utility function is provided to list the bio_vecs pointed to by a bvecq\n+chain::\n+\n+\tvoid bvecq_dump(const struct bvecq *bq);\n+\n+\n+I/O iterators\n+=============\n+\n+bvecq chains can be used with the ``iov_iter`` facility too. An iterator can\n+be initialised to point at a chain by calling::\n+\n+\tvoid iov_iter_bvec_queue(struct iov_iter *i,\n+\t\t\t\t unsigned int direction,\n+\t\t\t\t const struct bvecq *bvecq,\n+\t\t\t\t unsigned int first_slot,\n+\t\t\t\t unsigned int offset,\n+\t\t\t\t size_t count);\n+\n+In addition to setting the iterator, direction and count, the first bvecq in\n+the chain to be iterated over is set, along with the starting slot in that\n+iterator and the offset into the slot. Once the iterator is set up, it can be\n+treated like any other I/O iterator.\n+\n+In a producer/consumer environment, it is expected that when an iterator is set\n+up, all the bvecqs and all the slots within the count of the iterator must\n+exist and must be populated before this function is called.\n+\n+\n+API Function Reference\n+======================\n+\n+.. kernel-doc:: include/linux/bvecq.h\n+.. kernel-doc:: fs/netfs/bvecq.c\ndiff --git a/Documentation/core-api/folio_queue.rst b/Documentation/core-api/folio_queue.rst\ndeleted file mode 100644\nindex b7628896d2b695..00000000000000\n--- a/Documentation/core-api/folio_queue.rst\n+++ /dev/null\n@@ -1,209 +0,0 @@\n-.. SPDX-License-Identifier: GPL-2.0+\n-\n-===========\n-Folio Queue\n-===========\n-\n-:Author: David Howells \u003cdhowells@redhat.com\u003e\n-\n-.. Contents:\n-\n- * Overview\n- * Initialisation\n- * Adding and removing folios\n- * Querying information about a folio\n- * Querying information about a folio_queue\n- * Folio queue iteration\n- * Folio marks\n- * Lockless simultaneous production/consumption issues\n-\n-\n-Overview\n-========\n-\n-The folio_queue struct forms a single segment in a segmented list of folios\n-that can be used to form an I/O buffer. As such, the list can be iterated over\n-using the ITER_FOLIOQ iov_iter type.\n-\n-The publicly accessible members of the structure are::\n-\n-\tstruct folio_queue {\n-\t\tstruct folio_queue *next;\n-\t\tstruct folio_queue *prev;\n-\t\t...\n-\t};\n-\n-A pair of pointers are provided, ``next`` and ``prev``, that point to the\n-segments on either side of the segment being accessed. Whilst this is a\n-doubly-linked list, it is intentionally not a circular list; the outward\n-sibling pointers in terminal segments should be NULL.\n-\n-Each segment in the list also stores:\n-\n- * an ordered sequence of folio pointers,\n- * the size of each folio and\n- * three 1-bit marks per folio,\n-\n-but these should not be accessed directly as the underlying data structure may\n-change, but rather the access functions outlined below should be used.\n-\n-The facility can be made accessible by::\n-\n-\t#include \u003clinux/folio_queue.h\u003e\n-\n-and to use the iterator::\n-\n-\t#include \u003clinux/uio.h\u003e\n-\n-\n-Initialisation\n-==============\n-\n-A segment should be initialised by calling::\n-\n-\tvoid folioq_init(struct folio_queue *folioq);\n-\n-with a pointer to the segment to be initialised. Note that this will not\n-necessarily initialise all the folio pointers, so care must be taken to check\n-the number of folios added.\n-\n-\n-Adding and removing folios\n-==========================\n-\n-Folios can be set in the next unused slot in a segment struct by calling one\n-of::\n-\n-\tunsigned int folioq_append(struct folio_queue *folioq,\n-\t\t\t\t struct folio *folio);\n-\n-\tunsigned int folioq_append_mark(struct folio_queue *folioq,\n-\t\t\t\t\tstruct folio *folio);\n-\n-Both functions update the stored folio count, store the folio and note its\n-size. The second function also sets the first mark for the folio added. Both\n-functions return the number of the slot used. [!] Note that no attempt is made\n-to check that the capacity wasn't overrun and the list will not be extended\n-automatically.\n-\n-A folio can be excised by calling::\n-\n-\tvoid folioq_clear(struct folio_queue *folioq, unsigned int slot);\n-\n-This clears the slot in the array and also clears all the marks for that folio,\n-but doesn't change the folio count - so future accesses of that slot must check\n-if the slot is occupied.\n-\n-\n-Querying information about a folio\n-==================================\n-\n-Information about the folio in a particular slot may be queried by the\n-following function::\n-\n-\tstruct folio *folioq_folio(const struct folio_queue *folioq,\n-\t\t\t\t unsigned int slot);\n-\n-If a folio has not yet been set in that slot, this may yield an undefined\n-pointer. The size of the folio in a slot may be queried with either of::\n-\n-\tunsigned int folioq_folio_order(const struct folio_queue *folioq,\n-\t\t\t\t\tunsigned int slot);\n-\n-\tsize_t folioq_folio_size(const struct folio_queue *folioq,\n-\t\t\t\t unsigned int slot);\n-\n-The first function returns the size as an order and the second as a number of\n-bytes.\n-\n-\n-Querying information about a folio_queue\n-========================================\n-\n-Information may be retrieved about a particular segment with the following\n-functions::\n-\n-\tunsigned int folioq_nr_slots(const struct folio_queue *folioq);\n-\n-\tunsigned int folioq_count(struct folio_queue *folioq);\n-\n-\tbool folioq_full(struct folio_queue *folioq);\n-\n-The first function returns the maximum capacity of a segment. It must not be\n-assumed that this won't vary between segments. The second returns the number\n-of folios added to a segments and the third is a shorthand to indicate if the\n-segment has been filled to capacity.\n-\n-Not that the count and fullness are not affected by clearing folios from the\n-segment. These are more about indicating how many slots in the array have been\n-initialised, and it assumed that slots won't get reused, but rather the segment\n-will get discarded as the queue is consumed.\n-\n-\n-Folio marks\n-===========\n-\n-Folios within a queue can also have marks assigned to them. These marks can be\n-used to note information such as if a folio needs folio_put() calling upon it.\n-There are three marks available to be set for each folio.\n-\n-The marks can be set by::\n-\n-\tvoid folioq_mark(struct folio_queue *folioq, unsigned int slot);\n-\tvoid folioq_mark2(struct folio_queue *folioq, unsigned int slot);\n-\n-Cleared by::\n-\n-\tvoid folioq_unmark(struct folio_queue *folioq, unsigned int slot);\n-\tvoid folioq_unmark2(struct folio_queue *folioq, unsigned int slot);\n-\n-And the marks can be queried by::\n-\n-\tbool folioq_is_marked(const struct folio_queue *folioq, unsigned int slot);\n-\tbool folioq_is_marked2(const struct folio_queue *folioq, unsigned int slot);\n-\n-The marks can be used for any purpose and are not interpreted by this API.\n-\n-\n-Folio queue iteration\n-=====================\n-\n-A list of segments may be iterated over using the I/O iterator facility using\n-an ``iov_iter`` iterator of ``ITER_FOLIOQ`` type. The iterator may be\n-initialised with::\n-\n-\tvoid iov_iter_folio_queue(struct iov_iter *i, unsigned int direction,\n-\t\t\t\t const struct folio_queue *folioq,\n-\t\t\t\t unsigned int first_slot, unsigned int offset,\n-\t\t\t\t size_t count);\n-\n-This may be told to start at a particular segment, slot and offset within a\n-queue. The iov iterator functions will follow the next pointers when advancing\n-and prev pointers when reverting when needed.\n-\n-\n-Lockless simultaneous production/consumption issues\n-===================================================\n-\n-If properly managed, the list can be extended by the producer at the head end\n-and shortened by the consumer at the tail end simultaneously without the need\n-to take locks. The ITER_FOLIOQ iterator inserts appropriate barriers to aid\n-with this.\n-\n-Care must be taken when simultaneously producing and consuming a list. If the\n-last segment is reached and the folios it refers to are entirely consumed by\n-the IOV iterators, an iov_iter struct will be left pointing to the last segment\n-with a slot number equal to the capacity of that segment. The iterator will\n-try to continue on from this if there's another segment available when it is\n-used again, but care must be taken lest the segment got removed and freed by\n-the consumer before the iterator was advanced.\n-\n-It is recommended that the queue always contain at least one segment, even if\n-that segment has never been filled or is entirely spent. This prevents the\n-head and tail pointers from collapsing.\n-\n-\n-API Function Reference\n-======================\n-\n-.. kernel-doc:: include/linux/folio_queue.h\ndiff --git a/Documentation/core-api/index.rst b/Documentation/core-api/index.rst\nindex 92f91c6a0d79d6..bfc2f1afc28514 100644\n--- a/Documentation/core-api/index.rst\n+++ b/Documentation/core-api/index.rst\n@@ -39,7 +39,7 @@ Library functionality that is used throughout the kernel.\n kref\n cleanup\n assoc_array\n- folio_queue\n+ bvecq\n xarray\n maple_tree\n idr\ndiff --git a/Documentation/filesystems/netfs_library.rst b/Documentation/filesystems/netfs_library.rst\nindex 215a6621f3d346..1fe110ceb3f18e 100644\n--- a/Documentation/filesystems/netfs_library.rst\n+++ b/Documentation/filesystems/netfs_library.rst\n@@ -437,22 +437,43 @@ Monolithic Files API\n \n There is also a special API set for files for which the content must be read in\n a single RPC (and not written back) and is maintained as a monolithic blob\n-(e.g. an AFS directory), though it can be stored and updated in the local cache::\n+(e.g. an AFS directory), though it can be stored and updated in the local\n+cache.\n+\n+To start with, there's a function to synchronously read the contents of such a\n+file into a buffer in a single operation::\n+\n+\tssize_t netfs_read_single(struct inode *inode,\n+\t\t\t\t struct file *file,\n+\t\t\t\t struct iov_iter *iter);\n+\n+If such a file is modified locally, it can be marked dirty with::\n \n-\tssize_t netfs_read_single(struct inode *inode, struct file *file, struct iov_iter *iter);\n \tvoid netfs_single_mark_inode_dirty(struct inode *inode);\n+\n+which will schedule it for writeback later. When the writeback eventually\n+happens, the filesystem should call::\n+\n \tint netfs_writeback_single(struct address_space *mapping,\n \t\t\t\t struct writeback_control *wbc,\n-\t\t\t\t struct iov_iter *iter);\n+\t\t\t\t struct iov_iter *iter,\n+\t\t\t\t size_t len);\n+\n+to write the data to the cache from its writepages method.\n \n-The first function reads from a file into the given buffer, reading from the\n-cache in preference if the data is cached there; the second function allows the\n-inode to be marked dirty, causing a later writeback; and the third function can\n-be called from the writeback code to write the data to the cache, if there is\n-one.\n+In both the read and writeback functions, the buffer needs to be rounded up to\n+a multiple of the cache DIO size, with ``iter-\u003ecount`` indicating the size of\n+the buffer. For the write function, ``len`` should indicate the size of the\n+content which may be less than the buffer size. The gap between ``len`` and the\n+buffer size should be cleared by the filesystem as this will be used as padding\n+if the write size has to be increased (e.g. for the cache DIO).\n+\n+Note that, for the moment, rounding the buffer up to a multiple of PAGE_SIZE\n+instead of the cache DIO size should suffice. DIO size \u003e PAGE_SIZE is not\n+currently supported.\n \n The inode should be marked ``NETFS_ICTX_SINGLE_NO_UPLOAD`` if this API is to be\n-used. The writeback function requires the buffer to be of ITER_FOLIOQ type.\n+used.\n \n Clearing Stale Post-EOF Pagecache\n ---------------------------------\n@@ -859,12 +880,12 @@ The methods defined in the table are:\n paths to ask the filesystem to update its idea of the file size. If not\n given, netfslib will set i_size and i_blocks and update the local cache\n cookie.\n- \n+\n * ``post_modify()``\n \n [Optional] This is called after netfslib writes to the pagecache or when it\n allows an mmap'd page to be marked as writable.\n- \n+\n * ``begin_writeback()``\n \n [Optional] Netfslib calls this when processing a writeback request if it\n@@ -872,7 +893,7 @@ The methods defined in the table are:\n indicating it must be written to the server. This allows the filesystem to\n only set up writeback resources when it knows it's going to have to perform\n a write.\n- \n+\n * ``prepare_write()``\n \n [Optional] This is called to allow the filesystem to limit the size of a\n@@ -911,7 +932,7 @@ The methods defined in the table are:\n allows the filesystem to examine the state of the request, the subrequests\n in the indicated stream and of its own data and make adjustments or\n renegotiate resources.\n- \n+\n * ``invalidate_cache()``\n \n [Optional] This is called by netfslib to invalidate data stored in the local\ndiff --git a/MAINTAINERS b/MAINTAINERS\nindex 93abbb315065de..bdda4ad58ab4c2 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -10382,13 +10382,16 @@ M:\tPaulo Alcantara \u003cpc@manguebit.org\u003e\n L:\tnetfs@lists.linux.dev\n L:\tlinux-fsdevel@vger.kernel.org\n S:\tSupported\n+F:\tDocumentation/core-api/bvecq.rst\n F:\tDocumentation/filesystems/caching/\n F:\tDocumentation/filesystems/netfs_library.rst\n F:\tfs/netfs/\n+F:\tinclude/linux/bvecq.h\n F:\tinclude/linux/fscache*.h\n F:\tinclude/linux/netfs.h\n F:\tinclude/trace/events/fscache.h\n F:\tinclude/trace/events/netfs.h\n+F:\tlib/tests/kunit_bvecq.c\n \n FILESYSTEMS [STACKABLE]\n M:\tMiklos Szeredi \u003cmiklos@szeredi.hu\u003e\ndiff --git a/fs/afs/dir.c b/fs/afs/dir.c\nindex 75f8f70cfeff02..75a1951bddd054 100644\n--- a/fs/afs/dir.c\n+++ b/fs/afs/dir.c\n@@ -140,9 +140,9 @@ static void afs_dir_dump(struct afs_vnode *dvnode)\n \tpr_warn(\"DIR %llx:%llx is=%llx\\n\",\n \t\tdvnode-\u003efid.vid, dvnode-\u003efid.vnode, i_size);\n \n-\tiov_iter_folio_queue(\u0026iter, ITER_SOURCE, dvnode-\u003edirectory, 0, 0, i_size);\n-\titerate_folioq(\u0026iter, iov_iter_count(\u0026iter), NULL, NULL,\n-\t\t afs_dir_dump_step);\n+\tiov_iter_bvec_queue(\u0026iter, ITER_SOURCE, dvnode-\u003edirectory, 0, 0, i_size);\n+\titerate_bvecq(\u0026iter, iov_iter_count(\u0026iter), NULL, NULL,\n+\t\t afs_dir_dump_step);\n }\n \n /*\n@@ -203,9 +203,9 @@ static int afs_dir_check(struct afs_vnode *dvnode)\n \tif (unlikely(!i_size))\n \t\treturn 0;\n \n-\tiov_iter_folio_queue(\u0026iter, ITER_SOURCE, dvnode-\u003edirectory, 0, 0, i_size);\n-\tchecked = iterate_folioq(\u0026iter, iov_iter_count(\u0026iter), dvnode, NULL,\n-\t\t\t\t afs_dir_check_step);\n+\tiov_iter_bvec_queue(\u0026iter, ITER_SOURCE, dvnode-\u003edirectory, 0, 0, i_size);\n+\tchecked = iterate_bvecq(\u0026iter, iov_iter_count(\u0026iter), dvnode, NULL,\n+\t\t\t\tafs_dir_check_step);\n \tif (checked != i_size) {\n \t\tafs_dir_dump(dvnode);\n \t\treturn -EIO;\n@@ -250,15 +250,16 @@ static ssize_t afs_do_read_single(struct afs_vnode *dvnode, struct file *file)\n \tif (dvnode-\u003edirectory_size \u003c i_size) {\n \t\tsize_t cur_size = dvnode-\u003edirectory_size;\n \n-\t\tret = netfs_alloc_folioq_buffer(NULL,\n-\t\t\t\t\t\t\u0026dvnode-\u003edirectory, \u0026cur_size, i_size,\n-\t\t\t\t\t\tmapping_gfp_mask(dvnode-\u003enetfs.inode.i_mapping));\n+\t\tret = bvecq_expand_buffer(\u0026dvnode-\u003edirectory, \u0026cur_size,\n+\t\t\t\t\t round_up(i_size, PAGE_SIZE),\n+\t\t\t\t\t mapping_gfp_mask(dvnode-\u003enetfs.inode.i_mapping) |\n+\t\t\t\t\t __GFP_ZERO);\n \t\tdvnode-\u003edirectory_size = cur_size;\n \t\tif (ret \u003c 0)\n \t\t\treturn ret;\n \t}\n \n-\tiov_iter_folio_queue(\u0026iter, ITER_DEST, dvnode-\u003edirectory, 0, 0, dvnode-\u003edirectory_size);\n+\tiov_iter_bvec_queue(\u0026iter, ITER_DEST, dvnode-\u003edirectory, 0, 0, dvnode-\u003edirectory_size);\n \n \t/* AFS requires us to perform the read of a directory synchronously as\n \t * a single unit to avoid issues with the directory contents being\n@@ -278,6 +279,13 @@ static ssize_t afs_do_read_single(struct afs_vnode *dvnode, struct file *file)\n \t\t\tif (ret2 \u003c 0)\n \t\t\t\tret = ret2;\n \t\t}\n+\n+\t\tif (ret \u003e= 0 \u0026\u0026 ret \u003c dvnode-\u003edirectory_size) {\n+\t\t\tiov_iter_bvec_queue(\u0026iter, ITER_DEST, dvnode-\u003edirectory,\n+\t\t\t\t\t 0, 0, dvnode-\u003edirectory_size);\n+\t\t\tiov_iter_advance(\u0026iter, ret);\n+\t\t\tiov_iter_zero(dvnode-\u003edirectory_size - ret, \u0026iter);\n+\t\t}\n \t}\n \n \treturn ret;\n@@ -294,8 +302,8 @@ static ssize_t afs_read_single(struct afs_vnode *dvnode, struct file *file)\n }\n \n /*\n- * Read the directory into a folio_queue buffer in one go, scrubbing the\n- * previous contents. We return -ESTALE if the caller needs to call us again.\n+ * Read the directory into the buffer in one go, scrubbing the previous\n+ * contents. We return -ESTALE if the caller needs to call us again.\n */\n ssize_t afs_read_dir(struct afs_vnode *dvnode, struct file *file)\n \t__acquires(\u0026dvnode-\u003evalidate_lock)\n@@ -483,7 +491,7 @@ static size_t afs_dir_iterate_step(void *iter_base, size_t progress, size_t len,\n }\n \n /*\n- * Iterate through the directory folios.\n+ * Iterate through the directory content.\n */\n static int afs_dir_iterate_contents(struct inode *dir, struct dir_context *dir_ctx)\n {\n@@ -498,11 +506,11 @@ static int afs_dir_iterate_contents(struct inode *dir, struct dir_context *dir_c\n \tif (i_size \u003c= 0 || dir_ctx-\u003epos \u003e= i_size)\n \t\treturn 0;\n \n-\tiov_iter_folio_queue(\u0026iter, ITER_SOURCE, dvnode-\u003edirectory, 0, 0, i_size);\n+\tiov_iter_bvec_queue(\u0026iter, ITER_SOURCE, dvnode-\u003edirectory, 0, 0, i_size);\n \tiov_iter_advance(\u0026iter, round_down(dir_ctx-\u003epos, AFS_DIR_BLOCK_SIZE));\n \n-\titerate_folioq(\u0026iter, iov_iter_count(\u0026iter), dvnode, \u0026ctx,\n-\t\t afs_dir_iterate_step);\n+\titerate_bvecq(\u0026iter, iov_iter_count(\u0026iter), dvnode, \u0026ctx,\n+\t\t afs_dir_iterate_step);\n \n \tif (ctx.error == -ESTALE)\n \t\tafs_invalidate_dir(dvnode, afs_dir_invalid_iter_stale);\n@@ -2228,9 +2236,10 @@ static int afs_dir_writepages(struct address_space *mapping,\n \t}\n \n \tif (test_bit(AFS_VNODE_DIR_VALID, \u0026dvnode-\u003eflags)) {\n-\t\tiov_iter_folio_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\tiov_iter_bvec_queue(\u0026iter, ITER_SOURCE, dvnode-\u003edirectory,\n+\t\t\t\t 0, 0, 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/dir_edit.c b/fs/afs/dir_edit.c\nindex c31303059444ad..870921f32fc89a 100644\n--- a/fs/afs/dir_edit.c\n+++ b/fs/afs/dir_edit.c\n@@ -10,7 +10,6 @@\n #include \u003clinux/namei.h\u003e\n #include \u003clinux/pagemap.h\u003e\n #include \u003clinux/iversion.h\u003e\n-#include \u003clinux/folio_queue.h\u003e\n #include \"internal.h\"\n #include \"xdr_fs.h\"\n \n@@ -110,9 +109,8 @@ static void afs_clear_contig_bits(union afs_xdr_dir_block *block,\n */\n static union afs_xdr_dir_block *afs_dir_get_block(struct afs_dir_iter *iter, size_t block)\n {\n-\tstruct folio_queue *fq;\n \tstruct afs_vnode *dvnode = iter-\u003edvnode;\n-\tstruct folio *folio;\n+\tstruct bvecq *bq;\n \tsize_t blpos = block * AFS_DIR_BLOCK_SIZE;\n \tsize_t blend = (block + 1) * AFS_DIR_BLOCK_SIZE, fpos = iter-\u003efpos;\n \tint ret;\n@@ -120,41 +118,39 @@ static union afs_xdr_dir_block *afs_dir_get_block(struct afs_dir_iter *iter, siz\n \tif (dvnode-\u003edirectory_size \u003c blend) {\n \t\tsize_t cur_size = dvnode-\u003edirectory_size;\n \n-\t\tret = netfs_alloc_folioq_buffer(\n-\t\t\tNULL, \u0026dvnode-\u003edirectory, \u0026cur_size, blend,\n-\t\t\tmapping_gfp_mask(dvnode-\u003enetfs.inode.i_mapping));\n+\t\tret = bvecq_expand_buffer(\u0026dvnode-\u003edirectory, \u0026cur_size, blend,\n+\t\t\t\t\t mapping_gfp_mask(dvnode-\u003enetfs.inode.i_mapping) |\n+\t\t\t\t\t __GFP_ZERO);\n \t\tdvnode-\u003edirectory_size = cur_size;\n \t\tif (ret \u003c 0)\n \t\t\tgoto fail;\n \t}\n \n-\tfq = iter-\u003efq;\n-\tif (!fq)\n-\t\tfq = dvnode-\u003edirectory;\n+\tbq = iter-\u003ebq;\n+\tif (!bq)\n+\t\tbq = dvnode-\u003edirectory;\n \n-\t/* Search the folio queue for the folio containing the block... */\n-\tfor (; fq; fq = fq-\u003enext) {\n-\t\tfor (int s = iter-\u003efq_slot; s \u003c folioq_count(fq); s++) {\n-\t\t\tsize_t fsize = folioq_folio_size(fq, s);\n+\t/* Search the contents for the region containing the block... */\n+\tfor (; bq; bq = bq-\u003enext) {\n+\t\tfor (int s = iter-\u003ebq_slot; s \u003c bq-\u003enr_slots; s++) {\n+\t\t\tstruct bio_vec *bv = \u0026bq-\u003ebv[s];\n+\t\t\tsize_t bsize = bv-\u003ebv_len;\n \n-\t\t\tif (blend \u003c= fpos + fsize) {\n+\t\t\tif (blend \u003c= fpos + bsize) {\n \t\t\t\t/* ... and then return the mapped block. */\n-\t\t\t\tfolio = folioq_folio(fq, s);\n-\t\t\t\tif (WARN_ON_ONCE(folio_pos(folio) != fpos))\n-\t\t\t\t\tgoto fail;\n-\t\t\t\titer-\u003efq = fq;\n-\t\t\t\titer-\u003efq_slot = s;\n+\t\t\t\titer-\u003ebq = bq;\n+\t\t\t\titer-\u003ebq_slot = s;\n \t\t\t\titer-\u003efpos = fpos;\n-\t\t\t\treturn kmap_local_folio(folio, blpos - fpos);\n+\t\t\t\treturn bvec_kmap_partial(bv, blpos - fpos);\n \t\t\t}\n-\t\t\tfpos += fsize;\n+\t\t\tfpos += bsize;\n \t\t}\n-\t\titer-\u003efq_slot = 0;\n+\t\titer-\u003ebq_slot = 0;\n \t}\n \n fail:\n-\titer-\u003efq = NULL;\n-\titer-\u003efq_slot = 0;\n+\titer-\u003ebq = NULL;\n+\titer-\u003ebq_slot = 0;\n \tafs_invalidate_dir(dvnode, afs_dir_invalid_edit_get_block);\n \treturn NULL;\n }\ndiff --git a/fs/afs/dir_search.c b/fs/afs/dir_search.c\nindex 11ebdfffcb1d38..e1f91b3ac6e25e 100644\n--- a/fs/afs/dir_search.c\n+++ b/fs/afs/dir_search.c\n@@ -66,12 +66,11 @@ bool afs_dir_init_iter(struct afs_dir_iter *iter, const struct qstr *name)\n */\n union afs_xdr_dir_block *afs_dir_find_block(struct afs_dir_iter *iter, size_t block)\n {\n-\tstruct folio_queue *fq = iter-\u003efq;\n \tstruct afs_vnode *dvnode = iter-\u003edvnode;\n-\tstruct folio *folio;\n+\tstruct bvecq *bq = iter-\u003ebq;\n \tsize_t blpos = block * AFS_DIR_BLOCK_SIZE;\n \tsize_t blend = (block + 1) * AFS_DIR_BLOCK_SIZE, fpos = iter-\u003efpos;\n-\tint slot = iter-\u003efq_slot;\n+\tint slot = iter-\u003ebq_slot;\n \n \t_enter(\"%zx,%d\", block, slot);\n \n@@ -80,36 +79,34 @@ union afs_xdr_dir_block *afs_dir_find_block(struct afs_dir_iter *iter, size_t bl\n \tif (dvnode-\u003edirectory_size \u003c blend)\n \t\tgoto fail;\n \n-\tif (!fq || blpos \u003c fpos) {\n-\t\tfq = dvnode-\u003edirectory;\n+\tif (!bq || blpos \u003c fpos) {\n+\t\tbq = dvnode-\u003edirectory;\n \t\tslot = 0;\n \t\tfpos = 0;\n \t}\n \n \t/* Search the folio queue for the folio containing the block... */\n-\tfor (; fq; fq = fq-\u003enext) {\n-\t\tfor (; slot \u003c folioq_count(fq); slot++) {\n-\t\t\tsize_t fsize = folioq_folio_size(fq, slot);\n+\tfor (; bq; bq = bq-\u003enext) {\n+\t\tfor (; slot \u003c bq-\u003enr_slots; slot++) {\n+\t\t\tstruct bio_vec *bv = \u0026bq-\u003ebv[slot];\n+\t\t\tsize_t bsize = bv-\u003ebv_len;\n \n-\t\t\tif (blend \u003c= fpos + fsize) {\n+\t\t\tif (blend \u003c= fpos + bsize) {\n \t\t\t\t/* ... and then return the mapped block. */\n-\t\t\t\tfolio = folioq_folio(fq, slot);\n-\t\t\t\tif (WARN_ON_ONCE(folio_pos(folio) != fpos))\n-\t\t\t\t\tgoto fail;\n-\t\t\t\titer-\u003efq = fq;\n-\t\t\t\titer-\u003efq_slot = slot;\n+\t\t\t\titer-\u003ebq = bq;\n+\t\t\t\titer-\u003ebq_slot = slot;\n \t\t\t\titer-\u003efpos = fpos;\n-\t\t\t\titer-\u003eblock = kmap_local_folio(folio, blpos - fpos);\n+\t\t\t\titer-\u003eblock = bvec_kmap_partial(bv, blpos - fpos);\n \t\t\t\treturn iter-\u003eblock;\n \t\t\t}\n-\t\t\tfpos += fsize;\n+\t\t\tfpos += bsize;\n \t\t}\n \t\tslot = 0;\n \t}\n \n fail:\n-\titer-\u003efq = NULL;\n-\titer-\u003efq_slot = 0;\n+\titer-\u003ebq = NULL;\n+\titer-\u003ebq_slot = 0;\n \tafs_invalidate_dir(dvnode, afs_dir_invalid_edit_get_block);\n \treturn NULL;\n }\ndiff --git a/fs/afs/inode.c b/fs/afs/inode.c\nindex 0733abff77a5b9..af95640da03fa7 100644\n--- a/fs/afs/inode.c\n+++ b/fs/afs/inode.c\n@@ -683,7 +683,7 @@ void afs_evict_inode(struct inode *inode)\n \tflush_delayed_work(\u0026vnode-\u003elock_work);\n \tnetfs_wait_for_outstanding_io(inode);\n \ttruncate_inode_pages_final(\u0026inode-\u003ei_data);\n-\tnetfs_free_folioq_buffer(vnode-\u003edirectory);\n+\tbvecq_put(vnode-\u003edirectory);\n \tif (vnode-\u003esymlink)\n \t\tafs_evict_symlink(vnode);\n \ndiff --git a/fs/afs/internal.h b/fs/afs/internal.h\nindex 7cea5ba0d20d7d..2a8b029b4d69fb 100644\n--- a/fs/afs/internal.h\n+++ b/fs/afs/internal.h\n@@ -712,7 +712,7 @@ struct afs_vnode {\n #define AFS_VNODE_MODIFYING\t10\t\t/* Set if we're performing a modification op */\n #define AFS_VNODE_DIR_READ\t11\t\t/* Set if we've read a dir's contents */\n \n-\tstruct folio_queue\t*directory;\t/* Directory contents */\n+\tstruct bvecq\t\t*directory;\t/* Directory contents */\n \tstruct afs_symlink __rcu *symlink;\t/* Symlink content */\n \tstruct list_head\twb_keys;\t/* List of keys available for writeback */\n \tstruct list_head\tpending_locks;\t/* locks waiting to be granted */\n@@ -993,9 +993,9 @@ static inline void afs_invalidate_cache(struct afs_vnode *vnode, unsigned int fl\n struct afs_dir_iter {\n \tstruct afs_vnode\t*dvnode;\n \tunion afs_xdr_dir_block *block;\n-\tstruct folio_queue\t*fq;\n+\tstruct bvecq\t\t*bq;\n \tunsigned int\t\tfpos;\n-\tint\t\t\tfq_slot;\n+\tint\t\t\tbq_slot;\n \tunsigned int\t\tloop_check;\n \tu8\t\t\tnr_slots;\n \tu8\t\t\tbucket;\ndiff --git a/fs/afs/symlink.c b/fs/afs/symlink.c\nindex 6b8c122877ca2d..f437c3108c6cdb 100644\n--- a/fs/afs/symlink.c\n+++ b/fs/afs/symlink.c\n@@ -56,7 +56,6 @@ void afs_evict_symlink(struct afs_vnode *vnode)\n void afs_init_new_symlink(struct afs_vnode *vnode, struct afs_operation *op)\n {\n \tstruct afs_symlink *symlink = op-\u003ecreate.symlink;\n-\tsize_t dsize = 0;\n \tsize_t size = strlen(symlink-\u003econtent) + 1;\n \tchar *p;\n \n@@ -66,12 +65,15 @@ void afs_init_new_symlink(struct afs_vnode *vnode, struct afs_operation *op)\n \tif (!fscache_cookie_enabled(netfs_i_cookie(\u0026vnode-\u003enetfs)))\n \t\treturn;\n \n-\tif (netfs_alloc_folioq_buffer(NULL, \u0026vnode-\u003edirectory, \u0026dsize, size,\n-\t\t\t\t mapping_gfp_mask(vnode-\u003enetfs.inode.i_mapping)) \u003c 0)\n+\tvnode-\u003edirectory =\n+\t\tbvecq_alloc_buffer(PAGE_SIZE,\n+\t\t\t\t mapping_gfp_mask(vnode-\u003enetfs.inode.i_mapping),\n+\t\t\t\t false);\n+\tif (!vnode-\u003edirectory)\n \t\treturn;\n \n-\tvnode-\u003edirectory_size = dsize;\n-\tp = kmap_local_folio(folioq_folio(vnode-\u003edirectory, 0), 0);\n+\tvnode-\u003edirectory_size = PAGE_SIZE;\n+\tp = bvec_kmap_partial(\u0026vnode-\u003edirectory-\u003ebv[0], 0);\n \tmemcpy(p, symlink-\u003econtent, size);\n \tkunmap_local(p);\n \tnetfs_single_mark_inode_dirty(\u0026vnode-\u003enetfs.inode);\n@@ -94,17 +96,14 @@ static ssize_t afs_do_read_symlink(struct afs_vnode *vnode)\n \t}\n \n \tif (!vnode-\u003edirectory) {\n-\t\tsize_t cur_size = 0;\n-\n-\t\tret = netfs_alloc_folioq_buffer(NULL,\n-\t\t\t\t\t\t\u0026vnode-\u003edirectory, \u0026cur_size, PAGE_SIZE,\n-\t\t\t\t\t\tmapping_gfp_mask(vnode-\u003enetfs.inode.i_mapping));\n-\t\tvnode-\u003edirectory_size = PAGE_SIZE - 1;\n-\t\tif (ret \u003c 0)\n-\t\t\treturn ret;\n+\t\tvnode-\u003edirectory = bvecq_alloc_buffer(\n+\t\t\tPAGE_SIZE, mapping_gfp_mask(vnode-\u003enetfs.inode.i_mapping), false);\n+\t\tif (!vnode-\u003edirectory)\n+\t\t\treturn -ENOMEM;\n+\t\tvnode-\u003edirectory_size = PAGE_SIZE;\n \t}\n \n-\tiov_iter_folio_queue(\u0026iter, ITER_DEST, vnode-\u003edirectory, 0, 0, PAGE_SIZE);\n+\tiov_iter_bvec_queue(\u0026iter, ITER_DEST, vnode-\u003edirectory, 0, 0, PAGE_SIZE);\n \n \t/* AFS requires us to perform the read of a symlink as a single unit to\n \t * avoid issues with the content being changed between reads.\n@@ -116,7 +115,6 @@ static ssize_t afs_do_read_symlink(struct afs_vnode *vnode)\n \t\t\ttrace_afs_file_error(vnode, -EFBIG, afs_file_error_dir_big);\n \t\t\treturn -EFBIG;\n \t\t}\n-\t\tvnode-\u003edirectory_size = i_size;\n \n \t\t/* Copy the symlink. */\n \t\tsymlink = kmalloc_flex(struct afs_symlink, content, i_size + 1);\n@@ -126,7 +124,7 @@ static ssize_t afs_do_read_symlink(struct afs_vnode *vnode)\n \t\trefcount_set(\u0026symlink-\u003eref, 1);\n \t\tsymlink-\u003econtent[i_size] = 0;\n \n-\t\tconst char *s = kmap_local_folio(folioq_folio(vnode-\u003edirectory, 0), 0);\n+\t\tconst char *s = bvec_kmap_partial(\u0026vnode-\u003edirectory-\u003ebv[0], 0);\n \n \t\tmemcpy(symlink-\u003econtent, s, i_size);\n \t\tkunmap_local(s);\n@@ -135,7 +133,7 @@ static ssize_t afs_do_read_symlink(struct afs_vnode *vnode)\n \t}\n \n \tif (!fscache_cookie_enabled(netfs_i_cookie(\u0026vnode-\u003enetfs))) {\n-\t\tnetfs_free_folioq_buffer(vnode-\u003edirectory);\n+\t\tbvecq_put(vnode-\u003edirectory);\n \t\tvnode-\u003edirectory = NULL;\n \t\tvnode-\u003edirectory_size = 0;\n \t}\n@@ -196,7 +194,7 @@ const char *afs_get_link(struct dentry *dentry, struct inode *inode,\n \t}\n \n \tdowngrade_write(\u0026vnode-\u003evalidate_lock);\n-\t\n+\n good:\n \tsymlink = rcu_dereference_protected(vnode-\u003esymlink,\n \t\t\t\t\t lockdep_is_held(\u0026vnode-\u003evalidate_lock));\n@@ -229,6 +227,10 @@ int afs_readlink(struct dentry *dentry, char __user *buffer, int buflen)\n /*\n * Write the symlink contents to the cache as a single blob. We then throw\n * away the page we used to receive it.\n+ *\n+ * Note that the buffer tail is cleared under a shared lock on -\u003evalidate_lock\n+ * - though hopefully there won't be racing writers since the only\n+ * 'modification' is to be either read from the server or locally created.\n */\n int afs_symlink_writepages(struct address_space *mapping,\n \t\t\t struct writeback_control *wbc)\n@@ -248,14 +250,23 @@ 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_folio_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\tsize_t i_size = i_size_read(\u0026vnode-\u003enetfs.inode);\n+\n+\t\tif (i_size \u003c vnode-\u003edirectory_size) {\n+\t\t\tiov_iter_bvec_queue(\u0026iter, ITER_DEST, vnode-\u003edirectory, 0, 0,\n+\t\t\t\t\t vnode-\u003edirectory_size);\n+\t\t\tiov_iter_advance(\u0026iter, i_size);\n+\t\t\tiov_iter_zero(vnode-\u003edirectory_size - i_size, \u0026iter);\n+\t\t}\n+\n+\t\tiov_iter_bvec_queue(\u0026iter, ITER_SOURCE, vnode-\u003edirectory, 0, 0,\n+\t\t\t\t vnode-\u003edirectory_size);\n+\t\tret = netfs_writeback_single(mapping, wbc, \u0026iter, i_size);\n \t}\n \n \tif (ret == 0) {\n \t\tnetfs_wb_begin(\u0026vnode-\u003enetfs, false);\n-\t\tnetfs_free_folioq_buffer(vnode-\u003edirectory);\n+\t\tbvecq_put(vnode-\u003edirectory);\n \t\tvnode-\u003edirectory = NULL;\n \t\tvnode-\u003edirectory_size = 0;\n \t\tnetfs_wb_end(\u0026vnode-\u003enetfs);\ndiff --git a/fs/netfs/Makefile b/fs/netfs/Makefile\nindex 54834cde7e5686..b1ea4439c1bb4a 100644\n--- a/fs/netfs/Makefile\n+++ b/fs/netfs/Makefile\n@@ -3,6 +3,7 @@\n netfs-y := \\\n \tbuffered_read.o \\\n \tbuffered_write.o \\\n+\tbvecq.o \\\n \tdirect_read.o \\\n \tdirect_write.o \\\n \titerator.o \\\ndiff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c\nindex 69e68ef0652a72..61b44af6774b75 100644\n--- a/fs/netfs/buffered_read.c\n+++ b/fs/netfs/buffered_read.c\n@@ -215,7 +215,7 @@ 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 folio_queue **fq,\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@@ -225,21 +225,21 @@ static void netfs_mark_copy_to_cache(struct netfs_io_request *rreq,\n \t\tstruct folio *folio;\n \t\tsize_t fsize, overlap;\n \n-\t\tif (!*fq)\n+\t\tif (!*bq)\n \t\t\tbreak;\n-\t\tif (*slot \u003e= folioq_count(*fq)) {\n-\t\t\t*fq = (*fq)-\u003enext;\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\t\tcontinue;\n \t\t}\n \n \t\t/* Determine how much the subreq overlaps the folio, if at all. */\n-\t\tfsize = folioq_folio_size(*fq, *slot);\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 = folioq_folio(*fq, *slot);\n+\t\t\tfolio = bvec_folio(\u0026(*bq)-\u003ebv[*slot]);\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@@ -275,7 +275,7 @@ 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 folio_queue *fq = rreq-\u003ebuffer.tail;\n+\tstruct bvecq *bq = rreq-\u003ebuffer.tail;\n \tunsigned int offset = 0;\n \tssize_t size = rreq-\u003elen;\n \tuoff_t start = rreq-\u003estart;\n@@ -408,10 +408,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 (fq) {\n+\t\tif (bq) {\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, \u0026fq, \u0026slot, \u0026offset, slice, copy);\n+\t\t\tnetfs_mark_copy_to_cache(rreq, \u0026bq, \u0026slot, \u0026offset, slice, copy);\n \t\t}\n \n \t\ttrace_netfs_sreq(subreq, netfs_sreq_trace_submit);\n@@ -479,8 +479,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,\n-\t\t\t\t\t\t rreq-\u003edebug_id, rreq-\u003egfp);\n+\tadded = rolling_buffer_bulk_load_from_ra(\u0026rreq-\u003ebuffer, ractl, rreq-\u003egfp);\n \tif (added \u003c 0) {\n \t\tret = added;\n \t\tgoto cleanup_free;\n@@ -503,15 +502,14 @@ EXPORT_SYMBOL(netfs_readahead);\n /*\n * Create a rolling buffer with a single occupying folio.\n */\n-static int netfs_create_singular_buffer(struct netfs_io_request *rreq, struct folio *folio,\n-\t\t\t\t\tunsigned int rollbuf_flags)\n+static int netfs_create_singular_buffer(struct netfs_io_request *rreq, struct folio *folio)\n {\n \tssize_t added;\n \n-\tif (rolling_buffer_init(\u0026rreq-\u003ebuffer, rreq-\u003edebug_id, ITER_DEST, rreq-\u003egfp) \u003c 0)\n+\tif (rolling_buffer_init(\u0026rreq-\u003ebuffer, ITER_DEST, rreq-\u003egfp, false) \u003c 0)\n \t\treturn -ENOMEM;\n \n-\tadded = rolling_buffer_append(\u0026rreq-\u003ebuffer, folio, rollbuf_flags, rreq-\u003egfp);\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@@ -668,7 +666,7 @@ int netfs_read_folio(struct file *file, struct folio *folio)\n \ttrace_netfs_read(rreq, rreq-\u003estart, rreq-\u003elen, netfs_read_trace_readpage);\n \n \t/* Set up the output buffer */\n-\tret = netfs_create_singular_buffer(rreq, folio, 0);\n+\tret = netfs_create_singular_buffer(rreq, folio);\n \tif (ret \u003c 0)\n \t\tgoto discard;\n \n@@ -825,7 +823,7 @@ int netfs_write_begin(struct netfs_inode *ctx,\n \ttrace_netfs_read(rreq, pos, len, netfs_read_trace_write_begin);\n \n \t/* Set up the output buffer */\n-\tret = netfs_create_singular_buffer(rreq, folio, 0);\n+\tret = netfs_create_singular_buffer(rreq, folio);\n \tif (ret \u003c 0)\n \t\tgoto error_put;\n \n@@ -890,7 +888,7 @@ int netfs_prefetch_for_write(struct file *file, struct folio *folio,\n \ttrace_netfs_read(rreq, start, flen, netfs_read_trace_prefetch_for_write);\n \n \t/* Set up the output buffer */\n-\tret = netfs_create_singular_buffer(rreq, folio, NETFS_ROLLBUF_PAGECACHE_MARK);\n+\tret = netfs_create_singular_buffer(rreq, folio);\n \tif (ret \u003c 0)\n \t\tgoto error_put;\n \ndiff --git a/fs/netfs/bvecq.c b/fs/netfs/bvecq.c\nnew file mode 100644\nindex 00000000000000..91264337805cd6\n--- /dev/null\n+++ b/fs/netfs/bvecq.c\n@@ -0,0 +1,357 @@\n+// SPDX-License-Identifier: GPL-2.0-only\n+/* Buffering helpers for bvec queues\n+ *\n+ * Copyright (C) 2026 Red Hat, Inc. All Rights Reserved.\n+ * Written by David Howells (dhowells@redhat.com)\n+ *\n+ * See also Documentation/core-api/bvecq.rst\n+ */\n+\n+#include \u003clinux/bvecq.h\u003e\n+#include \"internal.h\"\n+\n+void bvecq_dump(const struct bvecq *bq)\n+{\n+\tint b = 0;\n+\n+\tfor (; bq; bq = bvecq_next(bq), b++) {\n+\t\tpr_notice(\"BQ[%u] %u/%u\\n\", b, bq-\u003enr_slots, bq-\u003emax_slots);\n+\t\tfor (int s = 0; s \u003c bq-\u003enr_slots; s++) {\n+\t\t\tconst struct bio_vec *bv = \u0026bq-\u003ebv[s];\n+\n+\t\t\tif (!IS_ERR_OR_NULL(bv-\u003ebv_page))\n+\t\t\t\tpr_notice(\"BQ[%u:%02u] %10lx %04x %04x %u\\n\",\n+\t\t\t\t\t b, s,\n+\t\t\t\t\t page_to_pfn(bv-\u003ebv_page),\n+\t\t\t\t\t bv-\u003ebv_offset, bv-\u003ebv_len,\n+\t\t\t\t\t page_count(bv-\u003ebv_page));\n+\t\t\telse\n+\t\t\t\tpr_notice(\"BQ[%u:%02u] - %04x %04x\\n\",\n+\t\t\t\t\t b, s, bv-\u003ebv_offset, bv-\u003ebv_len);\n+\t\t}\n+\t}\n+}\n+EXPORT_SYMBOL(bvecq_dump);\n+\n+/**\n+ * bvecq_alloc_one - Allocate a single bvecq node with unpopulated slots\n+ * @nr_slots: Number of slots to allocate\n+ * @gfp: The allocation constraints.\n+ * @for_writeback: True if allocating for writeback\n+ *\n+ * Allocate a single bvecq node and initialise the header. The allocation is\n+ * rounded up to the size of the smallest slab granule that will accommodate it\n+ * and all the remaining space is set as an inline slot array with max_slots\n+ * set to the number of slots. The slot array is not initialised.\n+ *\n+ * Note that the number of slots allocated is limited to USHRT_MAX. If more\n+ * than this are desired, a number of bvecqs should be chained.\n+ *\n+ * If @for_writeback is set, then the emergency mempool may be used for\n+ * allocation. If it does allocate from that pool, the maximum number of slots\n+ * available will be BVECQ_POOL_SLOTS which may be less than requested. Also,\n+ * if @for_writeback is set, the function will not fail - though it may have to\n+ * wait.\n+ *\n+ * Return: The node pointer or NULL on allocation failure.\n+ */\n+struct bvecq *bvecq_alloc_one(size_t nr_slots, gfp_t gfp, bool for_writeback)\n+{\n+\tstruct bvecq *bq;\n+\tsize_t size;\n+\tbool from_pool = false;\n+\n+\t/* Don't overrun -\u003emax_slots or -\u003enr_slots. */\n+\tif (nr_slots \u003e BVECQ_MAX_INLINE_SLOTS)\n+\t\tnr_slots = BVECQ_MAX_INLINE_SLOTS;\n+\n+\tsize = kmalloc_size_roundup(struct_size(bq, __bv, nr_slots));\n+\tgfp \u0026= ~(GFP_ZONEMASK | __GFP_THISNODE);\n+\n+\tif (for_writeback) {\n+\t\tif (size != BVECQ_POOL_SIZE) {\n+\t\t\tgfp_t gfp_temp = gfp;\n+\n+\t\t\tgfp_temp |= __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN;\n+\t\t\tgfp_temp \u0026= ~(__GFP_DIRECT_RECLAIM | __GFP_IO);\n+\t\t\tbq = kmalloc(size, gfp_temp);\n+\t\t\tif (bq)\n+\t\t\t\tgoto success;\n+\t\t}\n+\n+\t\tbq = mempool_alloc(\u0026netfs_bvecq_pool, gfp);\n+\t\tif (!bq)\n+\t\t\treturn bq;\n+\t\tfrom_pool = true;\n+\t\tsize = BVECQ_POOL_SIZE;\n+\t} else {\n+\t\tbq = kmalloc(size, gfp);\n+\t\tif (!bq)\n+\t\t\treturn bq;\n+\t}\n+\n+success:\n+\t*bq = (struct bvecq) {\n+\t\t.ref\t\t= REFCOUNT_INIT(1),\n+\t\t.bv\t\t= bq-\u003e__bv,\n+\t\t.inline_bv\t= true,\n+\t\t.max_slots\t= min((size - sizeof(*bq)) / sizeof(bq-\u003e__bv[0]),\n+\t\t\t\t BVECQ_MAX_INLINE_SLOTS),\n+\t\t.from_pool\t= from_pool,\n+\t};\n+\tnetfs_stat(\u0026netfs_n_bvecq);\n+\treturn bq;\n+}\n+EXPORT_SYMBOL(bvecq_alloc_one);\n+\n+/**\n+ * bvecq_alloc_chain - Allocate an unpopulated bvecq chain\n+ * @nr_slots: Number of slots to allocate\n+ * @gfp: The allocation constraints.\n+ * @for_writeback: True if allocating for writeback\n+ *\n+ * Allocate a chain of bvecq nodes providing at least the requested cumulative\n+ * number of slots. Each node is a maximum of 4KiB in size.\n+ *\n+ * Return: The first node pointer or NULL on allocation failure.\n+ */\n+struct bvecq *bvecq_alloc_chain(size_t nr_slots, gfp_t gfp, bool for_writeback)\n+{\n+\tstruct bvecq *head = NULL, *tail = NULL;\n+\n+\t_enter(\"%zu\", nr_slots);\n+\n+\tfor (;;) {\n+\t\tstruct bvecq *bq;\n+\n+\t\tbq = bvecq_alloc_one(min(nr_slots, BVECQ_4KB_SLOTS), gfp, for_writeback);\n+\t\tif (!bq)\n+\t\t\tgoto oom;\n+\n+\t\tif (tail)\n+\t\t\tbvecq_append(tail, bq);\n+\t\telse\n+\t\t\thead = bq;\n+\t\ttail = bq;\n+\t\tif (tail-\u003emax_slots \u003e= nr_slots)\n+\t\t\tbreak;\n+\t\tnr_slots -= tail-\u003emax_slots;\n+\t}\n+\n+\treturn head;\n+oom:\n+\tbvecq_put(head);\n+\treturn NULL;\n+}\n+EXPORT_SYMBOL(bvecq_alloc_chain);\n+\n+/**\n+ * bvecq_alloc_buffer2 - Allocate a bvecq chain and populate with buffers\n+ * @size: Target size of the buffer (can be 0 for an empty buffer)\n+ * @pre_slots: Number of preamble slots to set aside\n+ * @gfp: The allocation constraints.\n+ * @for_writeback: True if allocating for writeback\n+ *\n+ * Allocate a chain of bvecq nodes and populate the slots with sufficient pages\n+ * to provide at least the requested amount of space, leaving the first\n+ * @pre_slots slots unset. The pre-slots must all fit into the first bvecq.\n+ * Note that any memory segments set in the pre_slots will be freed as\n+ * specified by BVECQ_MEM_ALLOCED.\n+ *\n+ * The caller should assume that the pages allocated may be compound pages\n+ * larger than PAGE_SIZE and thus occupy fewer slots. The pages have their\n+ * refcounts set to 1 and can be passed to MSG_SPLICE_PAGES.\n+ *\n+ * Return: The first node pointer or NULL on allocation failure.\n+ */\n+struct bvecq *bvecq_alloc_buffer2(size_t size, unsigned int pre_slots, gfp_t gfp,\n+\t\t\t\t bool for_writeback)\n+{\n+\tstruct bvecq *head = NULL, *p = NULL;\n+\tsize_t nr_per_bq = BVECQ_POOL_SLOTS;\n+\tsize_t count = pre_slots + DIV_ROUND_UP(size, PAGE_SIZE);\n+\n+\t_enter(\"%zx,%zx,%u\", size, count, pre_slots);\n+\n+\tif (WARN_ON_ONCE(pre_slots \u003e nr_per_bq))\n+\t\treturn NULL;\n+\n+\thead = bvecq_alloc_chain(count, gfp, for_writeback);\n+\tif (!head)\n+\t\treturn NULL;\n+\n+\tp = head;\n+\tdo {\n+\t\tstruct page **pages;\n+\t\tsize_t unused, want, got, slot;\n+\n+\t\tif (!count)\n+\t\t\tbreak;\n+\t\tif (WARN_ON_ONCE(!p))\n+\t\t\tgoto oom;\n+\n+\t\tif (p-\u003enr_slots == 0) {\n+\t\t\t/* Need to clear pre slots and pages[], so just clear all. */\n+\t\t\tmemset(p-\u003ebv, 0, p-\u003emax_slots * sizeof(p-\u003ebv[0]));\n+\t\t\tp-\u003emem_type = BVECQ_MEM_ALLOCED;\n+\t\t\tp-\u003enr_slots = pre_slots;\n+\t\t\tcount -= pre_slots;\n+\t\t\tpre_slots = 0;\n+\t\t\tif (!count)\n+\t\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (p-\u003enr_slots \u003e= p-\u003emax_slots) {\n+\t\t\tp = p-\u003enext;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tunused = p-\u003emax_slots - p-\u003enr_slots;\n+\n+\t\t/* We can put pages[] at the tail of bv[] as the elements are\n+\t\t * smaller and we won't overrun if the slots are filled in\n+\t\t * ascending order.\n+\t\t */\n+\t\tpages = (struct page **)\u0026p-\u003ebv[p-\u003emax_slots];\n+\t\tpages -= unused;\n+\n+\t\twant = min(count, unused);\n+\t\tgot = alloc_pages_bulk(gfp, want, pages);\n+\t\tif (!got)\n+\t\t\tgoto oom;\n+\n+\t\tslot = p-\u003enr_slots;\n+\t\tfor (int i = 0; i \u003c got; i++)\n+\t\t\tbvec_set_page(\u0026p-\u003ebv[slot++], pages[i], PAGE_SIZE, 0);\n+\n+\t\tbvecq_filled_to(p, slot);\n+\t\tcount -= got;\n+\t} while (count \u003e 0);\n+\n+\treturn head;\n+oom:\n+\tbvecq_put(head);\n+\treturn NULL;\n+}\n+EXPORT_SYMBOL(bvecq_alloc_buffer2);\n+\n+/*\n+ * Free the page pointed to by a slot as necessary.\n+ */\n+static void bvecq_free_slot(struct bvecq *bq, unsigned int slot)\n+{\n+\tstruct page *page = bq-\u003ebv[slot].bv_page;\n+\n+\tif (!page)\n+\t\treturn;\n+\n+\tswitch (bq-\u003emem_type) {\n+\tcase BVECQ_MEM_EXTERNAL:\n+\t\tbreak;\n+\tcase BVECQ_MEM_PAGECACHE:\n+\t\tput_page(page);\n+\t\tbreak;\n+\tcase BVECQ_MEM_GUP:\n+\t\tunpin_user_page(page);\n+\t\tbreak;\n+\tcase BVECQ_MEM_ALLOCED:\n+\t\t__free_pages(page, compound_order(page));\n+\t\tbreak;\n+\tdefault:\n+\t\tWARN_ON_ONCE(1);\n+\t\tbreak;\n+\t}\n+}\n+\n+/**\n+ * bvecq_put - Put a ref on a bvec queue\n+ * @bq: The start of the folio queue to free\n+ *\n+ * Put the ref(s) on the nodes in a bvec queue, freeing up the node and the\n+ * page fragments it points to as the refcounts become zero.\n+ */\n+void bvecq_put(struct bvecq *bq)\n+{\n+\tstruct bvecq *next;\n+\n+\tfor (; bq; bq = next) {\n+\t\tif (!refcount_dec_and_test(\u0026bq-\u003eref))\n+\t\t\tbreak;\n+\t\tfor (int slot = 0; slot \u003c bq-\u003enr_slots; slot++)\n+\t\t\tbvecq_free_slot(bq, slot);\n+\t\tnext = bq-\u003enext;\n+\t\tnetfs_stat_d(\u0026netfs_n_bvecq);\n+\t\tif (bq-\u003efrom_pool)\n+\t\t\tmempool_free(bq, \u0026netfs_bvecq_pool);\n+\t\telse\n+\t\t\tkfree(bq);\n+\t}\n+}\n+EXPORT_SYMBOL(bvecq_put);\n+\n+/**\n+ * bvecq_expand_buffer - Allocate buffer space into a bvec queue\n+ * @_buffer: Pointer to the bvecq chain to expand (may point to a NULL; updated).\n+ * @_cur_size: Current size of the buffer (updated).\n+ * @size: Target size of the buffer.\n+ * @gfp: The allocation constraints.\n+ *\n+ * Append extra pages to a buffer to increase its capacity to the @size\n+ * specified. If the current tail has space, but is not of the\n+ * BVECQ_MEM_ALLOCED memory type, a separate bvecq will be allocated to hold\n+ * the new memory.\n+ *\n+ * Return: 0 on success or -ENOMEM on failure. Note that in the case of\n+ * failure, the buffer may have been partially expanded. In any event,\n+ * *@_cur_size will be updated to the new buffer size.\n+ */\n+int bvecq_expand_buffer(struct bvecq **_buffer, size_t *_cur_size, size_t size, gfp_t gfp)\n+{\n+\tstruct bvecq *tail = *_buffer;\n+\n+\tsize = round_up(size, PAGE_SIZE);\n+\tif (tail)\n+\t\twhile (tail-\u003enext)\n+\t\t\ttail = tail-\u003enext;\n+\n+\twhile (*_cur_size \u003c size) {\n+\t\tstruct page *page;\n+\t\tsize_t need = size - *_cur_size;\n+\t\tgfp_t gfp_add;\n+\t\tint order = 0;\n+\n+\t\tif (!tail || bvecq_is_full(tail) || tail-\u003emem_type != BVECQ_MEM_ALLOCED) {\n+\t\t\tstruct bvecq *p;\n+\n+\t\t\tp = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, false);\n+\t\t\tif (!p)\n+\t\t\t\treturn -ENOMEM;\n+\t\t\tif (tail)\n+\t\t\t\tbvecq_append(tail, p);\n+\t\t\telse\n+\t\t\t\t*_buffer = p;\n+\t\t\ttail = p;\n+\t\t\tp-\u003emem_type = BVECQ_MEM_ALLOCED;\n+\t\t}\n+\n+\t\tif (need \u003e PAGE_SIZE)\n+\t\t\torder = umin(ilog2(need) - PAGE_SHIFT, MAX_PAGECACHE_ORDER);\n+\n+\t\tgfp_add = 0;\n+\t\tif (order \u003e 0)\n+\t\t\tgfp_add |= __GFP_NORETRY | __GFP_NOWARN;\n+\t\tpage = alloc_pages(gfp | __GFP_COMP | gfp_add, order);\n+\t\tif (!page \u0026\u0026 order \u003e 0) {\n+\t\t\tpage = alloc_pages(gfp | __GFP_COMP, 0);\n+\t\t\torder = 0;\n+\t\t}\n+\t\tif (!page)\n+\t\t\treturn -ENOMEM;\n+\n+\t\tbvec_set_page(\u0026tail-\u003ebv[tail-\u003enr_slots], page, PAGE_SIZE \u003c\u003c order, 0);\n+\t\t*_cur_size += PAGE_SIZE \u003c\u003c order;\n+\t\tbvecq_filled_to(tail, tail-\u003enr_slots + 1);\n+\t}\n+\n+\treturn 0;\n+}\n+EXPORT_SYMBOL(bvecq_expand_buffer);\ndiff --git a/fs/netfs/internal.h b/fs/netfs/internal.h\nindex 6b583152132f0b..33d6cc23f54ad6 100644\n--- a/fs/netfs/internal.h\n+++ b/fs/netfs/internal.h\n@@ -7,10 +7,10 @@\n \n #include \u003clinux/slab.h\u003e\n #include \u003clinux/seq_file.h\u003e\n-#include \u003clinux/folio_queue.h\u003e\n #include \u003clinux/netfs.h\u003e\n #include \u003clinux/fscache.h\u003e\n #include \u003clinux/fscache-cache.h\u003e\n+#include \u003clinux/mempool.h\u003e\n #include \u003ctrace/events/netfs.h\u003e\n #include \u003ctrace/events/fscache.h\u003e\n \n@@ -45,7 +45,7 @@ extern struct list_head netfs_io_requests;\n extern spinlock_t netfs_proc_lock;\n extern mempool_t netfs_request_pool;\n extern mempool_t netfs_subrequest_pool;\n-extern mempool_t netfs_folioq_pool;\n+extern mempool_t netfs_bvecq_pool;\n \n #ifdef CONFIG_PROC_FS\n static inline void netfs_proc_add_rreq(struct netfs_io_request *rreq)\n@@ -70,8 +70,6 @@ static inline void netfs_proc_del_rreq(struct netfs_io_request *rreq) {}\n /*\n * misc.c\n */\n-struct folio_queue *netfs_buffer_make_space(struct netfs_io_request *rreq,\n-\t\t\t\t\t enum netfs_folioq_trace trace);\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@@ -204,7 +202,7 @@ extern atomic_t netfs_n_wh_retry_write_req;\n extern atomic_t netfs_n_wh_retry_write_subreq;\n extern atomic_t netfs_n_wb_lock_skip;\n extern atomic_t netfs_n_wb_lock_wait;\n-extern atomic_t netfs_n_folioq;\n+extern atomic_t netfs_n_bvecq;\n \n int netfs_stats_show(struct seq_file *m, void *v);\n \ndiff --git a/fs/netfs/iterator.c b/fs/netfs/iterator.c\nindex eb1efb17f53aaa..983d3e45c69801 100644\n--- a/fs/netfs/iterator.c\n+++ b/fs/netfs/iterator.c\n@@ -245,33 +245,37 @@ static size_t netfs_limit_xarray(const struct iov_iter *iter, size_t start_offse\n }\n \n /*\n- * Select the span of a folio queue iterator we're going to use. Limit it by\n- * both maximum size and maximum number of segments. Returns the size of the\n- * span in bytes.\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_folioq(const struct iov_iter *iter, size_t start_offset,\n-\t\t\t\t size_t max_size, size_t max_segs)\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 folio_queue *folioq = iter-\u003efolioq;\n+\tconst struct bvecq *bq = iter-\u003ebvecq;\n \tunsigned int nsegs = 0;\n-\tunsigned int slot = iter-\u003efolioq_slot;\n+\tunsigned int slot = iter-\u003ebvecq_slot;\n \tsize_t span = 0, n = iter-\u003ecount;\n \n-\tif (WARN_ON(!iov_iter_is_folioq(iter)) ||\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 (slot \u003e= folioq_nr_slots(folioq)) {\n-\t\tfolioq = folioq-\u003enext;\n-\t\tslot = 0;\n-\t}\n-\n \tstart_offset += iter-\u003eiov_offset;\n \tdo {\n-\t\tsize_t flen = folioq_folio_size(folioq, slot);\n+\t\tsize_t flen;\n \n+\t\tif (!bvecq_acquire_slot(bq, slot)) {\n+\t\t\tbq = bvecq_next(bq);\n+\t\t\tif (!bq)\n+\t\t\t\tbreak;\n+\t\t\tslot = 0;\n+\t\t\tcontinue;\n+\t\t}\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@@ -283,11 +287,7 @@ static size_t netfs_limit_folioq(const struct iov_iter *iter, size_t start_offse\n \t\t\tbreak;\n \n \t\tslot++;\n-\t\tif (slot \u003e= folioq_nr_slots(folioq)) {\n-\t\t\tfolioq = folioq-\u003enext;\n-\t\t\tslot = 0;\n-\t\t}\n-\t} while (folioq);\n+\t} while (bq);\n \n \treturn umin(span, max_size);\n }\n@@ -295,8 +295,8 @@ static size_t netfs_limit_folioq(const struct iov_iter *iter, size_t start_offse\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_folioq(iter))\n-\t\treturn netfs_limit_folioq(iter, start_offset, max_size, max_segs);\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))\ndiff --git a/fs/netfs/main.c b/fs/netfs/main.c\nindex 609e22e8f76a06..b1a7521b7210bd 100644\n--- a/fs/netfs/main.c\n+++ b/fs/netfs/main.c\n@@ -7,7 +7,6 @@\n \n #include \u003clinux/module.h\u003e\n #include \u003clinux/export.h\u003e\n-#include \u003clinux/mempool.h\u003e\n #include \u003clinux/proc_fs.h\u003e\n #include \u003clinux/seq_file.h\u003e\n #include \"internal.h\"\n@@ -28,7 +27,7 @@ static struct kmem_cache *netfs_request_slab;\n static struct kmem_cache *netfs_subrequest_slab;\n mempool_t netfs_request_pool;\n mempool_t netfs_subrequest_pool;\n-mempool_t netfs_folioq_pool;\n+mempool_t netfs_bvecq_pool;\n \n #ifdef CONFIG_PROC_FS\n LIST_HEAD(netfs_io_requests);\n@@ -108,8 +107,8 @@ static int __init netfs_init(void)\n {\n \tint ret = -ENOMEM;\n \n-\tif (mempool_init_kmalloc_pool(\u0026netfs_folioq_pool, 100, sizeof(struct folio_queue)) \u003c 0)\n-\t\tgoto error_folioq_pool;\n+\tif (mempool_init_kmalloc_pool(\u0026netfs_bvecq_pool, 100, BVECQ_POOL_SIZE) \u003c 0)\n+\t\tgoto error_bvecq_pool;\n \n \tnetfs_request_slab = kmem_cache_create(\"netfs_request\",\n \t\t\t\t\t sizeof(struct netfs_io_request), 0,\n@@ -163,8 +162,8 @@ static int __init netfs_init(void)\n error_reqpool:\n \tkmem_cache_destroy(netfs_request_slab);\n error_req:\n-\tmempool_exit(\u0026netfs_folioq_pool);\n-error_folioq_pool:\n+\tmempool_exit(\u0026netfs_bvecq_pool);\n+error_bvecq_pool:\n \treturn ret;\n }\n fs_initcall(netfs_init);\n@@ -177,6 +176,6 @@ static void __exit netfs_exit(void)\n \tkmem_cache_destroy(netfs_subrequest_slab);\n \tmempool_exit(\u0026netfs_request_pool);\n \tkmem_cache_destroy(netfs_request_slab);\n-\tmempool_exit(\u0026netfs_folioq_pool);\n+\tmempool_exit(\u0026netfs_bvecq_pool);\n }\n module_exit(netfs_exit);\ndiff --git a/fs/netfs/misc.c b/fs/netfs/misc.c\nindex 5465db834b9499..a0cc248a284d59 100644\n--- a/fs/netfs/misc.c\n+++ b/fs/netfs/misc.c\n@@ -9,102 +9,6 @@\n #include \u003clinux/rmap.h\u003e\n #include \"internal.h\"\n \n-/**\n- * netfs_alloc_folioq_buffer - Allocate buffer space into a folio queue\n- * @mapping: Address space to set on the folio (or NULL).\n- * @_buffer: Pointer to the folio queue to add to (may point to a NULL; updated).\n- * @_cur_size: Current size of the buffer (updated).\n- * @size: Target size of the buffer.\n- * @gfp: The allocation constraints.\n- */\n-int netfs_alloc_folioq_buffer(struct address_space *mapping,\n-\t\t\t struct folio_queue **_buffer,\n-\t\t\t size_t *_cur_size, ssize_t size, gfp_t gfp)\n-{\n-\tstruct folio_queue *tail = *_buffer, *p;\n-\n-\tsize = round_up(size, PAGE_SIZE);\n-\tif (*_cur_size \u003e= size)\n-\t\treturn 0;\n-\n-\tif (tail)\n-\t\twhile (tail-\u003enext)\n-\t\t\ttail = tail-\u003enext;\n-\n-\tdo {\n-\t\tstruct folio *folio;\n-\t\tint order = 0, slot;\n-\n-\t\tif (!tail || folioq_full(tail)) {\n-\t\t\tp = netfs_folioq_alloc(0, GFP_NOFS, netfs_trace_folioq_alloc_buffer);\n-\t\t\tif (!p)\n-\t\t\t\treturn -ENOMEM;\n-\t\t\tif (tail) {\n-\t\t\t\ttail-\u003enext = p;\n-\t\t\t\tp-\u003eprev = tail;\n-\t\t\t} else {\n-\t\t\t\t*_buffer = p;\n-\t\t\t}\n-\t\t\ttail = p;\n-\t\t}\n-\n-\t\tif (size - *_cur_size \u003e PAGE_SIZE)\n-\t\t\torder = umin(ilog2(size - *_cur_size) - PAGE_SHIFT,\n-\t\t\t\t MAX_PAGECACHE_ORDER);\n-\n-\t\tfolio = folio_alloc(gfp, order);\n-\t\tif (!folio \u0026\u0026 order \u003e 0)\n-\t\t\tfolio = folio_alloc(gfp, 0);\n-\t\tif (!folio)\n-\t\t\treturn -ENOMEM;\n-\n-\t\tfolio-\u003emapping = mapping;\n-\t\tfolio-\u003eindex = *_cur_size / PAGE_SIZE;\n-\t\ttrace_netfs_folio(folio, netfs_folio_trace_alloc_buffer);\n-\t\tslot = folioq_append_mark(tail, folio);\n-\t\t*_cur_size += folioq_folio_size(tail, slot);\n-\t} while (*_cur_size \u003c size);\n-\n-\treturn 0;\n-}\n-EXPORT_SYMBOL(netfs_alloc_folioq_buffer);\n-\n-/**\n- * netfs_free_folioq_buffer - Free a folio queue.\n- * @fq: The start of the folio queue to free\n- *\n- * Free up a chain of folio_queues and, if marked, the marked folios they point\n- * to.\n- */\n-void netfs_free_folioq_buffer(struct folio_queue *fq)\n-{\n-\tstruct folio_queue *next;\n-\tstruct folio_batch fbatch;\n-\n-\tfolio_batch_init(\u0026fbatch);\n-\n-\tfor (; fq; fq = next) {\n-\t\tfor (int slot = 0; slot \u003c folioq_count(fq); slot++) {\n-\t\t\tstruct folio *folio = folioq_folio(fq, slot);\n-\n-\t\t\tif (!folio ||\n-\t\t\t !folioq_is_marked(fq, slot))\n-\t\t\t\tcontinue;\n-\n-\t\t\ttrace_netfs_folio(folio, netfs_folio_trace_put);\n-\t\t\tif (folio_batch_add(\u0026fbatch, folio))\n-\t\t\t\tfolio_batch_release(\u0026fbatch);\n-\t\t}\n-\n-\t\tnetfs_stat_d(\u0026netfs_n_folioq);\n-\t\tnext = fq-\u003enext;\n-\t\tkfree(fq);\n-\t}\n-\n-\tfolio_batch_release(\u0026fbatch);\n-}\n-EXPORT_SYMBOL(netfs_free_folioq_buffer);\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\ndiff --git a/fs/netfs/objects.c b/fs/netfs/objects.c\nindex 4b8d20559b0e15..6d7839c0498d60 100644\n--- a/fs/netfs/objects.c\n+++ b/fs/netfs/objects.c\n@@ -6,7 +6,6 @@\n */\n \n #include \u003clinux/slab.h\u003e\n-#include \u003clinux/mempool.h\u003e\n #include \"internal.h\"\n \n static void netfs_free_request(struct work_struct *work);\ndiff --git a/fs/netfs/read_collect.c b/fs/netfs/read_collect.c\nindex be0f9d2f7e10f5..75c8874ec45953 100644\n--- a/fs/netfs/read_collect.c\n+++ b/fs/netfs/read_collect.c\n@@ -79,11 +79,11 @@ void netfs_cancel_copy_to_cache(struct netfs_io_request *rreq, struct folio *fol\n * dirty and let writeback handle it.\n */\n static void netfs_unlock_read_folio(struct netfs_io_request *rreq,\n-\t\t\t\t struct folio_queue *folioq,\n+\t\t\t\t struct bvecq *bq,\n \t\t\t\t int slot)\n {\n \tstruct netfs_folio *finfo;\n-\tstruct folio *folio = folioq_folio(folioq, slot);\n+\tstruct folio *folio = bvec_folio(\u0026bq-\u003ebv[slot]);\n \n \tif (unlikely(folio_pos(folio) \u003c rreq-\u003eabandon_to)) {\n \t\ttrace_netfs_folio(folio, netfs_folio_trace_abandon);\n@@ -114,7 +114,7 @@ static void netfs_unlock_read_folio(struct netfs_io_request *rreq,\n \t\t\ttrace_netfs_folio(folio, netfs_folio_trace_read_done);\n \t\t}\n \n-\t\tfolioq_clear(folioq, slot);\n+\t\tbq-\u003ebv[slot].bv_page = NULL;\n \t} else {\n \t\t// TODO: Use of PG_private_2 is deprecated.\n \t\tif (folio_test_private_2(folio))\n@@ -130,7 +130,7 @@ static void netfs_unlock_read_folio(struct netfs_io_request *rreq,\n \t\tfolio_unlock(folio);\n \t}\n \n-\tfolioq_clear(folioq, slot);\n+\tbq-\u003ebv[slot].bv_page = NULL;\n }\n \n /*\n@@ -138,21 +138,22 @@ 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-\tstruct folio_queue *folioq = rreq-\u003ebuffer.tail;\n+\tconst struct bvecq *bq = rreq-\u003ebuffer.tail;\n \tunsigned int slot = rreq-\u003ebuffer.first_tail_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 \n \twhile (progress_at \u003c rreq-\u003elen) {\n-\t\tif (slot \u003e= folioq_count(folioq)) {\n-\t\t\tfolioq = folioq-\u003enext;\n-\t\t\tif (!folioq)\n+\t\tif (!bvecq_acquire_slot(bq, slot)) {\n+\t\t\tbq = bvecq_next(bq);\n+\t\t\tif (!bq)\n \t\t\t\tbreak;\n \t\t\tslot = 0;\n+\t\t\tcontinue;\n \t\t}\n \n-\t\tprogress_at += folioq_folio_size(folioq, slot);\n+\t\tprogress_at += bq-\u003ebv[slot].bv_len;\n \t\tif (progress_at - cleaned_to \u003e= minimum)\n \t\t\tbreak;\n \t\tslot++;\n@@ -168,7 +169,7 @@ 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 folio_queue *folioq = rreq-\u003ebuffer.tail;\n+\tstruct bvecq *bq = rreq-\u003ebuffer.tail;\n \tunsigned int slot = rreq-\u003ebuffer.first_tail_slot;\n \tuoff_t collected_to = rreq-\u003ecollected_to;\n \n@@ -177,9 +178,9 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,\n \n \t// TODO: Begin decryption\n \n-\tif (slot \u003e= folioq_nr_slots(folioq)) {\n-\t\tfolioq = rolling_buffer_delete_spent(\u0026rreq-\u003ebuffer);\n-\t\tif (!folioq) {\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@@ -198,13 +199,13 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,\n \t\tuoff_t fpos, fend;\n \t\tsize_t fsize;\n \n-\t\tfolio = folioq_folio(folioq, slot);\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 \t\t\t rreq-\u003edebug_id, folio-\u003eindex))\n \t\t\ttrace_netfs_folio(folio, netfs_folio_trace_not_locked);\n \n-\t\tfsize = folioq_folio_size(folioq, slot);\n+\t\tfsize = bq-\u003ebv[slot].bv_len;\n \t\tfpos = folio_pos(folio);\n \t\tfend = fpos + fsize;\n \n@@ -214,29 +215,28 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,\n \t\tif (collected_to \u003c fend)\n \t\t\tbreak;\n \n-\t\tnetfs_unlock_read_folio(rreq, folioq, slot);\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 folioq. If we clear an entire folioq, then\n-\t\t * we can get rid of it provided it's not also the tail folioq\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\tfolioq_clear(folioq, slot);\n+\t\tbq-\u003ebv[slot].bv_page = NULL;\n \t\tslot++;\n-\t\tif (slot \u003e= folioq_nr_slots(folioq)) {\n-\t\t\tfolioq = rolling_buffer_delete_spent(\u0026rreq-\u003ebuffer);\n-\t\t\tif (!folioq)\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\ttrace_netfs_folioq(folioq, netfs_trace_folioq_read_progress);\n \t\t}\n \n \t\tif (fpos + fsize \u003e= collected_to)\n \t\t\tbreak;\n \t}\n \n-\trreq-\u003ebuffer.tail = folioq;\n+\trreq-\u003ebuffer.tail = bq;\n done:\n \trreq-\u003ebuffer.first_tail_slot = slot;\n \ndiff --git a/fs/netfs/read_pgpriv2.c b/fs/netfs/read_pgpriv2.c\nindex 5280b606fda410..f8e5667e278e1b 100644\n--- a/fs/netfs/read_pgpriv2.c\n+++ b/fs/netfs/read_pgpriv2.c\n@@ -53,7 +53,7 @@ static void netfs_pgpriv2_copy_folio(struct netfs_io_request *creq, struct folio\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, 0, creq-\u003egfp) \u003c 0) {\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@@ -173,13 +173,15 @@ 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 folio_queue *folioq = creq-\u003ebuffer.tail;\n+\tstruct bvecq *bq = creq-\u003ebuffer.tail;\n \tunsigned int slot = creq-\u003ebuffer.first_tail_slot;\n \tuoff_t collected_to = creq-\u003ecollected_to;\n \tbool made_progress = false;\n \n-\tif (slot \u003e= folioq_nr_slots(folioq)) {\n-\t\tfolioq = rolling_buffer_delete_spent(\u0026creq-\u003ebuffer);\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}\n \n@@ -188,7 +190,7 @@ bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *creq)\n \t\tuoff_t fpos, fend;\n \t\tsize_t fsize, flen;\n \n-\t\tfolio = folioq_folio(folioq, slot);\n+\t\tfolio = bvec_folio(\u0026bq-\u003ebv[slot]);\n \t\tif (WARN_ONCE(!folio_test_private_2(folio),\n \t\t\t \"R=%08x: folio %lx is not marked private_2\\n\",\n \t\t\t creq-\u003edebug_id, folio-\u003eindex))\n@@ -211,15 +213,15 @@ 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 folioq. If we clear an entire folioq, then\n-\t\t * we can get rid of it provided it's not also the tail folioq\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\tfolioq_clear(folioq, slot);\n+\t\tbq-\u003ebv[slot].bv_page = NULL;\n \t\tslot++;\n-\t\tif (slot \u003e= folioq_nr_slots(folioq)) {\n-\t\t\tfolioq = rolling_buffer_delete_spent(\u0026creq-\u003ebuffer);\n-\t\t\tif (!folioq)\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}\n@@ -228,7 +230,7 @@ bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *creq)\n \t\t\tbreak;\n \t}\n \n-\tcreq-\u003ebuffer.tail = folioq;\n+\tcreq-\u003ebuffer.tail = bq;\n done:\n \tcreq-\u003ebuffer.first_tail_slot = slot;\n \treturn made_progress;\ndiff --git a/fs/netfs/read_retry.c b/fs/netfs/read_retry.c\nindex 5bd8dee5a83467..142c3fb8dab17c 100644\n--- a/fs/netfs/read_retry.c\n+++ b/fs/netfs/read_retry.c\n@@ -291,7 +291,7 @@ void netfs_retry_reads(struct netfs_io_request *rreq)\n */\n void netfs_unlock_abandoned_read_pages(struct netfs_io_request *rreq)\n {\n-\tstruct folio_queue *p;\n+\tstruct bvecq *p;\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@@ -301,24 +301,25 @@ void netfs_unlock_abandoned_read_pages(struct netfs_io_request *rreq)\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 = 0; slot \u003c folioq_count(p); slot++) {\n-\t\t\tstruct folio *folio = folioq_folio(p, slot);\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 \n-\t\t\tif (!folio)\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\tnetfs_cancel_copy_to_cache(rreq, folio);\n \n-\t\t\tif (!folioq_is_marked2(p, slot)) {\n-\t\t\t\tif (folio == rreq-\u003eno_unlock_folio \u0026\u0026\n-\t\t\t\t test_bit(NETFS_RREQ_NO_UNLOCK_FOLIO,\n-\t\t\t\t\t \u0026rreq-\u003eflags)) {\n-\t\t\t\t\t_debug(\"no unlock\");\n-\t\t\t\t} else {\n-\t\t\t\t\ttrace_netfs_folio(folio,\n-\t\t\t\t\t\tnetfs_folio_trace_abandon);\n-\t\t\t\t\tfolio_unlock(folio);\n-\t\t\t\t}\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}\n \t\t}\n+\t\trreq-\u003ebuffer.first_tail_slot = 0;\n \t}\n }\ndiff --git a/fs/netfs/rolling_buffer.c b/fs/netfs/rolling_buffer.c\nindex d30d5ef6d86eca..e23d87c8d4b38e 100644\n--- a/fs/netfs/rolling_buffer.c\n+++ b/fs/netfs/rolling_buffer.c\n@@ -6,102 +6,56 @@\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-static atomic_t debug_ids;\n-\n-/**\n- * netfs_folioq_alloc - Allocate a folio_queue struct\n- * @rreq_id: Associated debugging ID for tracing purposes\n- * @gfp: Allocation constraints\n- * @trace: Trace tag to indicate the purpose of the allocation\n- *\n- * Allocate, initialise and account the folio_queue struct and log a trace line\n- * to mark the allocation.\n- */\n-struct folio_queue *netfs_folioq_alloc(unsigned int rreq_id, gfp_t gfp,\n-\t\t\t\t unsigned int /*enum netfs_folioq_trace*/ trace)\n-{\n-\tstruct folio_queue *fq;\n-\n-\tif (gfp == GFP_KERNEL)\n-\t\tfq = mempool_alloc_noreserve(\u0026netfs_folioq_pool, gfp);\n-\telse\n-\t\tfq = mempool_alloc(\u0026netfs_folioq_pool, gfp);\n-\tif (fq) {\n-\t\tnetfs_stat(\u0026netfs_n_folioq);\n-\t\tfolioq_init(fq, rreq_id);\n-\t\tfq-\u003edebug_id = atomic_inc_return(\u0026debug_ids);\n-\t\ttrace_netfs_folioq(fq, trace);\n-\t}\n-\treturn fq;\n-}\n-EXPORT_SYMBOL(netfs_folioq_alloc);\n-\n-/**\n- * netfs_folioq_free - Free a folio_queue struct\n- * @folioq: The object to free\n- * @trace: Trace tag to indicate which free\n- *\n- * Free and unaccount the folio_queue struct.\n- */\n-void netfs_folioq_free(struct folio_queue *folioq,\n-\t\t unsigned int /*enum netfs_trace_folioq*/ trace)\n-{\n-\ttrace_netfs_folioq(folioq, trace);\n-\tnetfs_stat_d(\u0026netfs_n_folioq);\n-\tmempool_free(folioq, \u0026netfs_folioq_pool);\n-}\n-EXPORT_SYMBOL(netfs_folioq_free);\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 rreq_id,\n-\t\t\tunsigned int direction, gfp_t gfp)\n+int rolling_buffer_init(struct rolling_buffer *roll, unsigned int direction,\n+\t\t\tgfp_t gfp, bool for_writeback)\n {\n-\tstruct folio_queue *fq;\n+\tstruct bvecq *bq;\n+\n+\troll-\u003efor_writeback = for_writeback;\n \n-\tfq = netfs_folioq_alloc(rreq_id, gfp, netfs_trace_folioq_rollbuf_init);\n-\tif (!fq)\n+\tbq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, for_writeback);\n+\tif (!bq)\n \t\treturn -ENOMEM;\n \n-\troll-\u003ehead = fq;\n-\troll-\u003etail = fq;\n-\tiov_iter_folio_queue(\u0026roll-\u003eiter, direction, fq, 0, 0, 0);\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 folio_queue to a rolling buffer if there's no space left.\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 folio_queue *fq, *head = roll-\u003ehead;\n+\tstruct bvecq *bq, *head = roll-\u003ehead;\n \n-\tif (!folioq_full(head))\n+\tif (!bvecq_is_full(head))\n \t\treturn 0;\n \n-\tfq = netfs_folioq_alloc(head-\u003erreq_id, gfp, netfs_trace_folioq_make_space);\n-\tif (!fq)\n+\tbq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, roll-\u003efor_writeback);\n+\tif (!bq)\n \t\treturn -ENOMEM;\n-\tfq-\u003eprev = head;\n \n-\troll-\u003ehead = fq;\n-\tif (folioq_full(head)) {\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.folioq == head \u0026\u0026\n-\t\t roll-\u003eiter.folioq_slot == folioq_nr_slots(head)) {\n-\t\t\troll-\u003eiter.folioq = fq;\n-\t\t\troll-\u003eiter.folioq_slot = 0;\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@@ -110,7 +64,7 @@ int rolling_buffer_make_space(struct rolling_buffer *roll, gfp_t gfp)\n \t * [!] NOTE: After we set head-\u003enext, the consumer is at liberty to\n \t * immediately delete the old head.\n \t */\n-\tsmp_store_release(\u0026head-\u003enext, fq);\n+\tbvecq_append(head, bq);\n \treturn 0;\n }\n \n@@ -119,55 +73,59 @@ int rolling_buffer_make_space(struct rolling_buffer *roll, gfp_t gfp)\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 unsigned int rreq_id, gfp_t gfp)\n+\t\t\t\t\t gfp_t gfp)\n {\n-\tstruct folio_queue *fq;\n-\tssize_t loaded = 0;\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 folioq to put some folios into and attach it to\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\tfq = netfs_folioq_alloc(rreq_id, gfp,\n-\t\t\t\t\tnetfs_trace_folioq_make_space);\n-\t\tif (!fq)\n+\t\tbq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, false);\n+\t\tif (!bq)\n \t\t\tgoto nomem_unlock;\n-\t\tfq-\u003eprev = roll-\u003ehead;\n+\t\tbq-\u003emem_type = BVECQ_MEM_EXTERNAL; /* Folio cleanup handled separately. */\n+\n \t\tif (!roll-\u003etail)\n-\t\t\troll-\u003etail = fq;\n+\t\t\troll-\u003etail = bq;\n \t\telse\n-\t\t\troll-\u003ehead-\u003enext = fq;\n-\t\troll-\u003ehead = fq;\n+\t\t\tbvecq_append(roll-\u003ehead, bq);\n+\t\troll-\u003ehead = bq;\n \n-\t\t/* Get a batch of folios and note their orders. */\n-\t\tnr = __readahead_batch(ractl, (struct page **)fq-\u003evec.folios,\n-\t\t\t\t folioq_nr_slots(fq));\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-\t\tfq-\u003evec.nr = nr;\n \n \t\tfor (int slot = 0; slot \u003c nr; slot++) {\n-\t\t\tstruct folio *folio = folioq_folio(fq, slot);\n-\t\t\tunsigned int order;\n+\t\t\tstruct folio *folio = page_folio(pages[slot]);\n+\t\t\tsize_t len = folio_size(folio);\n \n-\t\t\torder = folio_order(folio);\n-\t\t\tfq-\u003eorders[slot] = order;\n-\t\t\tloaded += PAGE_SIZE \u003c\u003c order;\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_folio_queue(\u0026roll-\u003eiter, ITER_DEST, roll-\u003etail, 0, 0, loaded);\n+\tiov_iter_bvec_queue(\u0026roll-\u003eiter, ITER_DEST, roll-\u003etail, 0, 0, loaded);\n \treturn loaded;\n \n nomem_unlock:\n-\tfor (fq = roll-\u003etail; fq; fq = fq-\u003enext) {\n-\t\tfor (int slot = 0; slot \u003c folioq_count(fq); slot++) {\n-\t\t\tfolio_unlock(fq-\u003evec.folios[slot]);\n-\t\t\tfolioq_mark(fq, slot);\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@@ -180,7 +138,7 @@ ssize_t rolling_buffer_bulk_load_from_ra(struct rolling_buffer *roll,\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 unsigned int flags, gfp_t gfp)\n+\t\t\t gfp_t gfp)\n {\n \tssize_t size = folio_size(folio);\n \tint slot;\n@@ -188,16 +146,11 @@ ssize_t rolling_buffer_append(struct rolling_buffer *roll, struct folio *folio,\n \tif (rolling_buffer_make_space(roll, gfp) \u003c 0)\n \t\treturn -ENOMEM;\n \n-\tslot = folioq_append(roll-\u003ehead, folio);\n-\tif (flags \u0026 ROLLBUF_MARK_1)\n-\t\tfolioq_mark(roll-\u003ehead, slot);\n-\tif (flags \u0026 ROLLBUF_MARK_2)\n-\t\tfolioq_mark2(roll-\u003ehead, slot);\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-\n-\t/* Store the counter after setting the slot. */\n-\tsmp_store_release(\u0026roll-\u003enext_head_slot, slot);\n \treturn size;\n }\n \n@@ -206,44 +159,23 @@ ssize_t rolling_buffer_append(struct rolling_buffer *roll, struct folio *folio,\n * don't return the last buffer to keep the pointers independent, but return\n * NULL instead.\n */\n-struct folio_queue *rolling_buffer_delete_spent(struct rolling_buffer *roll)\n+struct bvecq *rolling_buffer_delete_spent(struct rolling_buffer *roll)\n {\n-\tstruct folio_queue *spent = roll-\u003etail, *next = READ_ONCE(spent-\u003enext);\n+\tstruct bvecq *spent = roll-\u003etail, *next = bvecq_next(spent);\n \n \tif (!next)\n \t\treturn NULL;\n \tnext-\u003eprev = NULL;\n-\tnetfs_folioq_free(spent, netfs_trace_folioq_delete);\n \troll-\u003etail = next;\n+\tspent-\u003enext = NULL;\n+\tbvecq_put(spent);\n \treturn next;\n }\n \n /*\n- * Clear out a rolling queue. Folios that have mark 1 set are put.\n+ * Clear out a rolling queue.\n */\n void rolling_buffer_clear(struct rolling_buffer *roll)\n {\n-\tstruct folio_batch fbatch;\n-\tstruct folio_queue *p;\n-\n-\tfolio_batch_init(\u0026fbatch);\n-\n-\twhile ((p = roll-\u003etail)) {\n-\t\troll-\u003etail = p-\u003enext;\n-\t\tfor (int slot = 0; slot \u003c folioq_count(p); slot++) {\n-\t\t\tstruct folio *folio = folioq_folio(p, slot);\n-\n-\t\t\tif (!folio)\n-\t\t\t\tcontinue;\n-\t\t\tif (folioq_is_marked(p, slot)) {\n-\t\t\t\ttrace_netfs_folio(folio, netfs_folio_trace_put);\n-\t\t\t\tif (!folio_batch_add(\u0026fbatch, folio))\n-\t\t\t\t\tfolio_batch_release(\u0026fbatch);\n-\t\t\t}\n-\t\t}\n-\n-\t\tnetfs_folioq_free(p, netfs_trace_folioq_clear);\n-\t}\n-\n-\tfolio_batch_release(\u0026fbatch);\n+\tbvecq_put(roll-\u003etail);\n }\ndiff --git a/fs/netfs/stats.c b/fs/netfs/stats.c\nindex 9a607c4e62dda5..0ba6ce9295b257 100644\n--- a/fs/netfs/stats.c\n+++ b/fs/netfs/stats.c\n@@ -46,7 +46,7 @@ atomic_t netfs_n_wh_retry_write_req;\n atomic_t netfs_n_wh_retry_write_subreq;\n atomic_t netfs_n_wb_lock_skip;\n atomic_t netfs_n_wb_lock_wait;\n-atomic_t netfs_n_folioq;\n+atomic_t netfs_n_bvecq;\n \n int netfs_stats_show(struct seq_file *m, void *v)\n {\n@@ -88,10 +88,10 @@ int netfs_stats_show(struct seq_file *m, void *v)\n \t\t atomic_read(\u0026netfs_n_rh_retry_read_subreq),\n \t\t atomic_read(\u0026netfs_n_wh_retry_write_req),\n \t\t atomic_read(\u0026netfs_n_wh_retry_write_subreq));\n-\tseq_printf(m, \"Objs : rr=%u sr=%u foq=%u wsc=%u\\n\",\n+\tseq_printf(m, \"Objs : rr=%u sr=%u bq=%u wsc=%u\\n\",\n \t\t atomic_read(\u0026netfs_n_rh_rreq),\n \t\t atomic_read(\u0026netfs_n_rh_sreq),\n-\t\t atomic_read(\u0026netfs_n_folioq),\n+\t\t atomic_read(\u0026netfs_n_bvecq),\n \t\t atomic_read(\u0026netfs_n_wh_wstream_conflict));\n \tseq_printf(m, \"WbLock : skip=%u wait=%u\\n\",\n \t\t atomic_read(\u0026netfs_n_wb_lock_skip),\ndiff --git a/fs/netfs/write_collect.c b/fs/netfs/write_collect.c\nindex 6e8ea534230df0..91b42820c89252 100644\n--- a/fs/netfs/write_collect.c\n+++ b/fs/netfs/write_collect.c\n@@ -114,11 +114,11 @@ 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 folio_queue *folioq = wreq-\u003ebuffer.tail;\n+\tstruct bvecq *bq = wreq-\u003ebuffer.tail;\n \tunsigned int slot = wreq-\u003ebuffer.first_tail_slot;\n \tuoff_t collected_to = wreq-\u003ecollected_to;\n \n-\tif (WARN_ON_ONCE(!folioq)) {\n+\tif (WARN_ON_ONCE(!bq)) {\n \t\tpr_err(\"[!] Writeback unlock found empty rolling buffer!\\n\");\n \t\tnetfs_dump_request(wreq);\n \t\treturn;\n@@ -130,9 +130,9 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,\n \t\treturn;\n \t}\n \n-\tif (slot \u003e= folioq_nr_slots(folioq)) {\n-\t\tfolioq = rolling_buffer_delete_spent(\u0026wreq-\u003ebuffer);\n-\t\tif (!folioq)\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@@ -143,7 +143,7 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,\n \t\tuoff_t fpos, fend;\n \t\tsize_t fsize, flen;\n \n-\t\tfolio = folioq_folio(folioq, slot);\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 \t\t\t wreq-\u003edebug_id, folio-\u003eindex))\n@@ -166,15 +166,15 @@ 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 folioq. If we clear an entire folioq, then\n-\t\t * we can get rid of it provided it's not also the tail folioq\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\tfolioq_clear(folioq, slot);\n+\t\tbq-\u003ebv[slot].bv_page = NULL;\n \t\tslot++;\n-\t\tif (slot \u003e= folioq_nr_slots(folioq)) {\n-\t\t\tfolioq = rolling_buffer_delete_spent(\u0026wreq-\u003ebuffer);\n-\t\t\tif (!folioq)\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@@ -183,7 +183,7 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,\n \t\t\tbreak;\n \t}\n \n-\twreq-\u003ebuffer.tail = folioq;\n+\twreq-\u003ebuffer.tail = bq;\n done:\n \twreq-\u003ebuffer.first_tail_slot = slot;\n }\ndiff --git a/fs/netfs/write_issue.c b/fs/netfs/write_issue.c\nindex b8237e1314d8a4..37d1e5055c0ba5 100644\n--- a/fs/netfs/write_issue.c\n+++ b/fs/netfs/write_issue.c\n@@ -107,7 +107,9 @@ 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, wreq-\u003edebug_id, ITER_SOURCE, wreq-\u003egfp) \u003c 0)\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@@ -163,12 +165,12 @@ void netfs_prepare_write(struct netfs_io_request *wreq,\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 folio_queue\n-\t * struct being used as a placeholder to prevent the queue from\n-\t * collapsing. In such a case, extend the queue.\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_folioq(wreq_iter) \u0026\u0026\n-\t wreq_iter-\u003efolioq_slot \u003e= folioq_nr_slots(wreq_iter-\u003efolioq))\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@@ -451,7 +453,7 @@ static int netfs_write_folio(struct netfs_io_request *wreq,\n \t}\n \n \t/* Attach the folio to the rolling buffer. */\n-\trolling_buffer_append(\u0026wreq-\u003ebuffer, folio, 0, wreq-\u003egfp);\n+\trolling_buffer_append(\u0026wreq-\u003ebuffer, folio, wreq-\u003egfp);\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@@ -625,147 +627,32 @@ int netfs_writepages(struct address_space *mapping,\n }\n EXPORT_SYMBOL(netfs_writepages);\n \n-/*\n- * Write some of a pending folio data back to the server and/or the cache.\n- */\n-static int netfs_write_folio_single(struct netfs_io_request *wreq,\n-\t\t\t\t struct folio *folio)\n-{\n-\tstruct netfs_io_stream *upload = \u0026wreq-\u003eio_streams[0];\n-\tstruct netfs_io_stream *cache = \u0026wreq-\u003eio_streams[1];\n-\tstruct netfs_io_stream *stream;\n-\tsize_t iter_off = 0;\n-\tsize_t fsize = folio_size(folio), flen;\n-\tuoff_t fpos = folio_pos(folio);\n-\tssize_t ret;\n-\tbool to_eof = false;\n-\tbool no_debug = false;\n-\n-\t_enter(\"\");\n-\n-\tflen = folio_size(folio);\n-\tif (flen \u003e wreq-\u003ei_size - fpos) {\n-\t\tflen = wreq-\u003ei_size - fpos;\n-\t\tfolio_zero_segment(folio, flen, fsize);\n-\t\tto_eof = true;\n-\t} else if (flen == wreq-\u003ei_size - fpos) {\n-\t\tto_eof = true;\n-\t}\n-\n-\t_debug(\"folio %zx/%zx\", flen, fsize);\n-\n-\tif (!upload-\u003eavail \u0026\u0026 !cache-\u003eavail) {\n-\t\ttrace_netfs_folio(folio, netfs_folio_trace_cancel_store);\n-\t\treturn 0;\n-\t}\n-\n-\tif (!upload-\u003econstruct)\n-\t\ttrace_netfs_folio(folio, netfs_folio_trace_store);\n-\telse\n-\t\ttrace_netfs_folio(folio, netfs_folio_trace_store_plus);\n-\n-\t/* Attach the folio to the rolling buffer. */\n-\tfolio_get(folio);\n-\tret = rolling_buffer_append(\u0026wreq-\u003ebuffer, folio, NETFS_ROLLBUF_PUT_MARK, wreq-\u003egfp);\n-\tif (ret \u003c 0) {\n-\t\tfolio_put(folio);\n-\t\treturn ret;\n-\t}\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-\t * with the cache as the cache requires DIO alignment.\n-\t *\n-\t * Also skip uploading for data that's been read and just needs copying\n-\t * to the cache.\n-\t */\n-\tfor (int s = 0; s \u003c NR_IO_STREAMS; s++) {\n-\t\tstream = \u0026wreq-\u003eio_streams[s];\n-\t\tstream-\u003esubmit_off = 0;\n-\t\tstream-\u003esubmit_len = flen;\n-\t\tif (!stream-\u003eavail) {\n-\t\t\tstream-\u003esubmit_off = UINT_MAX;\n-\t\t\tstream-\u003esubmit_len = 0;\n-\t\t}\n-\t}\n-\n-\t/* Attach the folio to one or more subrequests. For a big folio, we\n-\t * could end up with thousands of subrequests if the wsize is small -\n-\t * but we might need to wait during the creation of subrequests for\n-\t * network resources (eg. SMB credits).\n-\t */\n-\tfor (;;) {\n-\t\tssize_t part;\n-\t\tsize_t lowest_off = ULONG_MAX;\n-\t\tint choose_s = -1;\n-\n-\t\t/* Always add to the lowest-submitted stream first. */\n-\t\tfor (int s = 0; s \u003c NR_IO_STREAMS; s++) {\n-\t\t\tstream = \u0026wreq-\u003eio_streams[s];\n-\t\t\tif (stream-\u003esubmit_len \u003e 0 \u0026\u0026\n-\t\t\t stream-\u003esubmit_off \u003c lowest_off) {\n-\t\t\t\tlowest_off = stream-\u003esubmit_off;\n-\t\t\t\tchoose_s = s;\n-\t\t\t}\n-\t\t}\n-\n-\t\tif (choose_s \u003c 0)\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-\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-\t\tif (part \u003e stream-\u003esubmit_len)\n-\t\t\tstream-\u003esubmit_len = 0;\n-\t\telse\n-\t\t\tstream-\u003esubmit_len -= part;\n-\t\tif (part \u003e 0)\n-\t\t\tno_debug = true;\n-\t}\n-\n-\twreq-\u003ebuffer.iter.iov_offset = 0;\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-\n-\tif (!no_debug)\n-\t\tkdebug(\"R=%x: No submit\", wreq-\u003edebug_id);\n-\t_leave(\" = 0\");\n-\treturn 0;\n-}\n-\n /**\n- * netfs_writeback_single - Write back a monolithic payload\n+ * netfs_writeback_single - Write back a monolithic payload to cache\n * @mapping: The mapping to write from\n * @wbc: Hints from the VM\n- * @iter: Data to write, must be ITER_FOLIOQ.\n+ * @iter: Data buffer to write from.\n+ * @len: Amount of data to write.\n+ *\n+ * Write a monolithic, non-pagecache object back to the cache only. The data\n+ * is not written to the server.\n *\n- * Write a monolithic, non-pagecache object back to the server and/or\n- * the cache.\n+ * The data buffer may be bigger than @len (as set in @iter's count), and if\n+ * so, this function will use the extra as needed to provide padding into the\n+ * cache to handle DIO rounding, so the caller should clear it.\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-\tstruct folio_queue *fq;\n-\tsize_t size = iov_iter_count(iter);\n \tint ret;\n \n-\tif (WARN_ON_ONCE(!iov_iter_is_folioq(iter)))\n+\tif (WARN_ON_ONCE(iov_iter_count(iter) \u003c len))\n \t\treturn -EIO;\n \n \tif (!netfs_wb_begin(ictx, wbc-\u003esync_mode == WB_SYNC_NONE)) {\n@@ -780,36 +667,42 @@ int netfs_writeback_single(struct address_space *mapping,\n \t\tgoto couldnt_start;\n \t}\n \n+\twreq-\u003ebuffer.iter = *iter;\n+\twreq-\u003elen = len;\n+\twreq-\u003esubmitted = wreq-\u003elen;\n+\n \t__set_bit(NETFS_RREQ_OFFLOAD_COLLECTION, \u0026wreq-\u003eflags);\n \ttrace_netfs_write(wreq, netfs_write_trace_writeback_single);\n \tnetfs_stat(\u0026netfs_n_wh_writepages);\n \n-\tif (__test_and_set_bit(NETFS_RREQ_UPLOAD_TO_SERVER, \u0026wreq-\u003eflags))\n-\t\twreq-\u003enetfs_ops-\u003ebegin_writeback(wreq);\n+\tfor (int s = 0; s \u003c NR_IO_STREAMS; s++) {\n+\t\tstruct netfs_io_subrequest *subreq;\n+\t\tstruct netfs_io_stream *stream = \u0026wreq-\u003eio_streams[s];\n+\n+\t\tif (!stream-\u003eavail)\n+\t\t\tcontinue;\n \n-\tfor (fq = (struct folio_queue *)iter-\u003efolioq; fq; fq = fq-\u003enext) {\n-\t\tfor (int slot = 0; slot \u003c folioq_count(fq); slot++) {\n-\t\t\tstruct folio *folio = folioq_folio(fq, slot);\n-\t\t\tsize_t part = umin(folioq_folio_size(fq, slot), size);\n+\t\tnetfs_prepare_write(wreq, stream, 0);\n+\t\t/* Allocation not allowed to fail in writeback. */\n \n-\t\t\t_debug(\"wbiter %lx %llx\", folio-\u003eindex, atomic64_read(\u0026wreq-\u003eissued_to));\n+\t\tsubreq = stream-\u003econstruct;\n+\t\tsubreq-\u003elen = wreq-\u003elen;\n+\t\tstream-\u003esubmit_len = subreq-\u003elen;\n+\t\tstream-\u003esubmit_extendable_to = iov_iter_count(iter) - len;\n \n-\t\t\tret = netfs_write_folio_single(wreq, folio);\n-\t\t\tif (ret \u003c 0)\n-\t\t\t\tgoto stop;\n-\t\t\tsize -= part;\n-\t\t\tif (size \u003c= 0)\n-\t\t\t\tgoto stop;\n-\t\t}\n+\t\tnetfs_issue_write(wreq, stream);\n \t}\n \n-stop:\n-\tfor (int s = 0; s \u003c NR_IO_STREAMS; s++)\n-\t\tnetfs_issue_write(wreq, \u0026wreq-\u003eio_streams[s]);\n \tnetfs_all_subreqs_queued(wreq);\n-\n \tnetfs_wake_collector(wreq);\n \n+\t/* TODO: Might want to be async here if WB_SYNC_NONE, but then need to\n+\t * wait before modifying.\n+\t */\n+\tret = netfs_wait_for_write(wreq);\n+\tif (ret \u003e 0)\n+\t\tret = 0;\n+\n \tnetfs_put_request(wreq, netfs_rreq_trace_put_return);\n \t_leave(\" = %d\", ret);\n \treturn ret;\ndiff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h\nindex d3ca688b6aba99..806242d9cce06a 100644\n--- a/fs/smb/client/cifsglob.h\n+++ b/fs/smb/client/cifsglob.h\n@@ -290,7 +290,7 @@ struct smb_rqst {\n \tstruct kvec\t*rq_iov;\t/* array of kvecs */\n \tunsigned int\trq_nvec;\t/* number of kvecs in array */\n \tstruct iov_iter\trq_iter;\t/* Data iterator */\n-\tstruct folio_queue *rq_buffer;\t/* Buffer for encryption */\n+\tstruct bvecq\t*rq_buffer;\t/* Buffer for encryption */\n };\n \n struct mid_q_entry;\ndiff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c\nindex dc55cd512616ab..9d462f6e896c33 100644\n--- a/fs/smb/client/smb2ops.c\n+++ b/fs/smb/client/smb2ops.c\n@@ -13,7 +13,7 @@\n #include \u003clinux/sort.h\u003e\n #include \u003ccrypto/aead.h\u003e\n #include \u003clinux/fiemap.h\u003e\n-#include \u003clinux/folio_queue.h\u003e\n+#include \u003clinux/bvecq.h\u003e\n #include \u003cuapi/linux/magic.h\u003e\n #include \"cifsfs.h\"\n #include \"cifsglob.h\"\n@@ -4918,19 +4918,18 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,\n }\n \n /*\n- * Copy data from an iterator to the folios in a folio queue buffer.\n+ * Copy data from an iterator to the pages in a bvec queue buffer.\n */\n-static bool cifs_copy_iter_to_folioq(struct iov_iter *iter, size_t size,\n-\t\t\t\t struct folio_queue *buffer)\n+static bool cifs_copy_iter_to_bvecq(struct iov_iter *iter, size_t size,\n+\t\t\t\t struct bvecq *buffer)\n {\n \tfor (; buffer; buffer = buffer-\u003enext) {\n-\t\tfor (int s = 0; s \u003c folioq_count(buffer); s++) {\n-\t\t\tstruct folio *folio = folioq_folio(buffer, s);\n-\t\t\tsize_t part = folioq_folio_size(buffer, s);\n+\t\tfor (int s = 0; s \u003c bvecq_nr_slots_acquire(buffer); s++) {\n+\t\t\tstruct bio_vec *bv = \u0026buffer-\u003ebv[s];\n+\t\t\tsize_t part = umin(bv-\u003ebv_len, size);\n \n-\t\t\tpart = umin(part, size);\n-\n-\t\t\tif (copy_folio_from_iter(folio, 0, part, iter) != part)\n+\t\t\tif (copy_page_from_iter(bv-\u003ebv_page, bv-\u003ebv_offset,\n+\t\t\t\t\t\tpart, iter) != part)\n \t\t\t\treturn false;\n \t\t\tsize -= part;\n \t\t}\n@@ -4942,7 +4941,7 @@ void\n smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)\n {\n \tfor (int i = 0; i \u003c num_rqst; i++)\n-\t\tnetfs_free_folioq_buffer(rqst[i].rq_buffer);\n+\t\tbvecq_put(rqst[i].rq_buffer);\n }\n \n /*\n@@ -4969,7 +4968,7 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,\n \tfor (int i = 1; i \u003c num_rqst; i++) {\n \t\tstruct smb_rqst *old = \u0026old_rq[i - 1];\n \t\tstruct smb_rqst *new = \u0026new_rq[i];\n-\t\tstruct folio_queue *buffer = NULL;\n+\t\tstruct bvecq *buffer = NULL;\n \t\tsize_t size = iov_iter_count(\u0026old-\u003erq_iter);\n \n \t\torig_len += smb_rqst_len(server, old);\n@@ -4977,17 +4976,16 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,\n \t\tnew-\u003erq_nvec = old-\u003erq_nvec;\n \n \t\tif (size \u003e 0) {\n-\t\t\tsize_t cur_size = 0;\n-\t\t\trc = netfs_alloc_folioq_buffer(NULL, \u0026buffer, \u0026cur_size,\n-\t\t\t\t\t\t size, GFP_NOFS);\n-\t\t\tnew-\u003erq_buffer = buffer;\n-\t\t\tif (rc \u003c 0)\n+\t\t\trc = -ENOMEM;\n+\t\t\tbuffer = bvecq_alloc_buffer(size, GFP_NOFS, true);\n+\t\t\tif (!buffer)\n \t\t\t\tgoto err_free;\n \n-\t\t\tiov_iter_folio_queue(\u0026new-\u003erq_iter, ITER_SOURCE,\n-\t\t\t\t\t buffer, 0, 0, size);\n+\t\t\tnew-\u003erq_buffer = buffer;\n+\t\t\tiov_iter_bvec_queue(\u0026new-\u003erq_iter, ITER_SOURCE,\n+\t\t\t\t\t buffer, 0, 0, size);\n \n-\t\t\tif (!cifs_copy_iter_to_folioq(\u0026old-\u003erq_iter, size, buffer)) {\n+\t\t\tif (!cifs_copy_iter_to_bvecq(\u0026old-\u003erq_iter, size, buffer)) {\n \t\t\t\trc = smb_EIO1(smb_eio_trace_tx_copy_iter_to_buf, size);\n \t\t\t\tgoto err_free;\n \t\t\t}\n@@ -5077,22 +5075,20 @@ decrypt_raw_data(struct TCP_Server_Info *server, char *buf,\n }\n \n static int\n-cifs_copy_folioq_to_iter(struct folio_queue *folioq, size_t data_size,\n-\t\t\t size_t skip, struct iov_iter *iter)\n+cifs_copy_bvecq_to_iter(struct bvecq *bq, size_t data_size,\n+\t\t\tsize_t skip, struct iov_iter *iter)\n {\n-\tfor (; folioq; folioq = folioq-\u003enext) {\n-\t\tfor (int s = 0; s \u003c folioq_count(folioq); s++) {\n-\t\t\tstruct folio *folio;\n-\t\t\tsize_t fsize, n, len;\n+\tfor (; bq; bq = bq-\u003enext) {\n+\t\tfor (int s = 0; s \u003c bvecq_nr_slots_acquire(bq); s++) {\n+\t\t\tstruct bio_vec *bv = \u0026bq-\u003ebv[s];\n+\t\t\tsize_t n, len;\n \n \t\t\tif (data_size == 0)\n \t\t\t\treturn 0;\n \n-\t\t\tfolio = folioq_folio(folioq, s);\n-\t\t\tfsize = folio_size(folio);\n-\t\t\tlen = umin(fsize - skip, data_size);\n+\t\t\tlen = umin(bv-\u003ebv_len - skip, data_size);\n \n-\t\t\tn = copy_folio_to_iter(folio, skip, len, iter);\n+\t\t\tn = copy_page_to_iter(bv-\u003ebv_page, bv-\u003ebv_offset + skip, len, iter);\n \t\t\tif (n != len) {\n \t\t\t\tcifs_dbg(VFS, \"%s: something went wrong\\n\", __func__);\n \t\t\t\treturn smb_EIO2(smb_eio_trace_rx_copy_to_iter,\n@@ -5114,7 +5110,7 @@ cifs_copy_folioq_to_iter(struct folio_queue *folioq, size_t data_size,\n \n static int\n handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,\n-\t\t char *buf, unsigned int buf_len, struct folio_queue *buffer,\n+\t\t char *buf, unsigned int buf_len, struct bvecq *buffer,\n \t\t unsigned int buffer_len, bool is_offloaded)\n {\n \tunsigned int data_offset;\n@@ -5224,8 +5220,8 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,\n \t\t}\n \n \t\t/* Copy the data to the output I/O iterator. */\n-\t\trdata-\u003eresult = cifs_copy_folioq_to_iter(buffer, data_len,\n-\t\t\t\t\t\t\t cur_off, \u0026rdata-\u003esubreq.io_iter);\n+\t\trdata-\u003eresult = cifs_copy_bvecq_to_iter(buffer, data_len,\n+\t\t\t\t\t\t\tcur_off, \u0026rdata-\u003esubreq.io_iter);\n \t\tif (rdata-\u003eresult != 0) {\n \t\t\tif (is_offloaded)\n \t\t\t\tmid-\u003emid_state = MID_RESPONSE_MALFORMED;\n@@ -5264,7 +5260,7 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,\n struct smb2_decrypt_work {\n \tstruct work_struct decrypt;\n \tstruct TCP_Server_Info *server;\n-\tstruct folio_queue *buffer;\n+\tstruct bvecq *buffer;\n \tchar *buf;\n \tunsigned int len;\n };\n@@ -5278,7 +5274,7 @@ static void smb2_decrypt_offload(struct work_struct *work)\n \tstruct mid_q_entry *mid;\n \tstruct iov_iter iter;\n \n-\tiov_iter_folio_queue(\u0026iter, ITER_DEST, dw-\u003ebuffer, 0, 0, dw-\u003elen);\n+\tiov_iter_bvec_queue(\u0026iter, ITER_DEST, dw-\u003ebuffer, 0, 0, dw-\u003elen);\n \trc = decrypt_raw_data(dw-\u003eserver, dw-\u003ebuf, dw-\u003eserver-\u003evals-\u003eread_rsp_size,\n \t\t\t \u0026iter, true);\n \tif (rc) {\n@@ -5328,7 +5324,7 @@ static void smb2_decrypt_offload(struct work_struct *work)\n \t}\n \n free_pages:\n-\tnetfs_free_folioq_buffer(dw-\u003ebuffer);\n+\tbvecq_put(dw-\u003ebuffer);\n \tcifs_small_buf_release(dw-\u003ebuf);\n \tkfree(dw);\n }\n@@ -5374,12 +5370,12 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,\n \tdw-\u003elen = len;\n \tlen = round_up(dw-\u003elen, PAGE_SIZE);\n \n-\tsize_t cur_size = 0;\n-\trc = netfs_alloc_folioq_buffer(NULL, \u0026dw-\u003ebuffer, \u0026cur_size, len, GFP_NOFS);\n-\tif (rc \u003c 0)\n+\trc = -ENOMEM;\n+\tdw-\u003ebuffer = bvecq_alloc_buffer(len, GFP_NOFS, false);\n+\tif (!dw-\u003ebuffer)\n \t\tgoto discard_data;\n \n-\tiov_iter_folio_queue(\u0026iter, ITER_DEST, dw-\u003ebuffer, 0, 0, len);\n+\tiov_iter_bvec_queue(\u0026iter, ITER_DEST, dw-\u003ebuffer, 0, 0, len);\n \n \t/* Read the data into the buffer and clear excess bufferage. */\n \trc = cifs_read_iter_from_socket(server, \u0026iter, dw-\u003elen);\n@@ -5439,7 +5435,7 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,\n \t}\n \n free_pages:\n-\tnetfs_free_folioq_buffer(dw-\u003ebuffer);\n+\tbvecq_put(dw-\u003ebuffer);\n free_dw:\n \tkfree(dw);\n \treturn rc;\ndiff --git a/fs/smb/smbdirect/connection.c b/fs/smb/smbdirect/connection.c\nindex e6c7b343fe8703..210e53495fe8f4 100644\n--- a/fs/smb/smbdirect/connection.c\n+++ b/fs/smb/smbdirect/connection.c\n@@ -5,7 +5,7 @@\n */\n \n #include \"internal.h\"\n-#include \u003clinux/folio_queue.h\u003e\n+#include \u003clinux/bvecq.h\u003e\n \n struct smbdirect_map_sges {\n \tstruct ib_sge *sge;\n@@ -2015,6 +2015,69 @@ static ssize_t smbdirect_map_sges_from_bvec(struct iov_iter *iter,\n \treturn ret;\n }\n \n+/*\n+ * Extract memory fragments from a BVECQ-class iterator and add them to an RDMA\n+ * list. The fragments are not pinned.\n+ */\n+static ssize_t smbdirect_map_sges_from_bvecq(struct iov_iter *iter,\n+\t\t\t\t\t struct smbdirect_map_sges *state,\n+\t\t\t\t\t ssize_t maxsize)\n+{\n+\tconst struct bvecq *bq = iter-\u003ebvecq, *next;\n+\tunsigned int slot = iter-\u003ebvecq_slot;\n+\tssize_t extracted = 0;\n+\tsize_t offset = iter-\u003eiov_offset;\n+\n+\tmaxsize = umin(maxsize, iov_iter_count(iter));\n+\n+\tdo {\n+\t\tstruct bio_vec *bv;\n+\t\tsize_t bsize;\n+\n+\t\twhile (slot \u003e= bq-\u003enr_slots) {\n+\t\t\tnext = bvecq_next(bq);\n+\t\t\tif (!next) {\n+\t\t\t\tif (WARN_ON_ONCE(maxsize \u003e 0))\n+\t\t\t\t\treturn -EIO;\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\t\t\tbq = next;\n+\t\t\tslot = 0;\n+\t\t}\n+\n+\t\tbv = \u0026bq-\u003ebv[slot];\n+\t\tbsize = bv-\u003ebv_len;\n+\n+\t\tif (offset \u003c bsize) {\n+\t\t\tsize_t part = umin(maxsize, bsize - offset);\n+\t\t\tbool ok;\n+\n+\t\t\tok = smbdirect_map_sges_single_page(state,\n+\t\t\t\t\t\t\t bv-\u003ebv_page,\n+\t\t\t\t\t\t\t bv-\u003ebv_offset + offset,\n+\t\t\t\t\t\t\t part);\n+\t\t\tif (!ok)\n+\t\t\t\treturn -EIO;\n+\n+\t\t\toffset += part;\n+\t\t\textracted += part;\n+\t\t\tmaxsize -= part;\n+\t\t}\n+\n+\t\tif (offset \u003e= bsize) {\n+\t\t\toffset = 0;\n+\t\t\tslot++;\n+\t\t}\n+\t} while (state-\u003enum_sge \u003c state-\u003emax_sge \u0026\u0026 maxsize \u003e 0);\n+\n+out:\n+\titer-\u003ebvecq = bq;\n+\titer-\u003ebvecq_slot = slot;\n+\titer-\u003eiov_offset = offset;\n+\titer-\u003ecount -= extracted;\n+\treturn extracted;\n+}\n+\n /*\n * Extract fragments from a KVEC-class iterator and add them to an ib_sge list.\n * This can deal with vmalloc'd buffers as well as kmalloc'd or static buffers.\n@@ -2076,70 +2139,6 @@ static ssize_t smbdirect_map_sges_from_kvec(struct iov_iter *iter,\n \treturn ret;\n }\n \n-/*\n- * Extract folio fragments from a FOLIOQ-class iterator and add them to an\n- * ib_sge list. The folios are not pinned.\n- */\n-static ssize_t smbdirect_map_sges_from_folioq(struct iov_iter *iter,\n-\t\t\t\t\t struct smbdirect_map_sges *state,\n-\t\t\t\t\t ssize_t maxsize)\n-{\n-\tconst struct folio_queue *folioq = iter-\u003efolioq;\n-\tunsigned int slot = iter-\u003efolioq_slot;\n-\tssize_t ret = 0;\n-\tsize_t offset = iter-\u003eiov_offset;\n-\n-\tif (WARN_ON_ONCE(!folioq))\n-\t\treturn -EIO;\n-\n-\tif (slot \u003e= folioq_nr_slots(folioq)) {\n-\t\tfolioq = folioq-\u003enext;\n-\t\tif (WARN_ON_ONCE(!folioq))\n-\t\t\treturn -EIO;\n-\t\tslot = 0;\n-\t}\n-\n-\tdo {\n-\t\tstruct folio *folio = folioq_folio(folioq, slot);\n-\t\tsize_t fsize = folioq_folio_size(folioq, slot);\n-\n-\t\tif (offset \u003c fsize) {\n-\t\t\tsize_t part = umin(maxsize, fsize - offset);\n-\t\t\tbool ok;\n-\n-\t\t\tok = smbdirect_map_sges_single_page(state,\n-\t\t\t\t\t\t\t folio_page(folio, 0),\n-\t\t\t\t\t\t\t offset,\n-\t\t\t\t\t\t\t part);\n-\t\t\tif (!ok)\n-\t\t\t\treturn -EIO;\n-\n-\t\t\toffset += part;\n-\t\t\tret += part;\n-\t\t\tmaxsize -= part;\n-\t\t}\n-\n-\t\tif (offset \u003e= fsize) {\n-\t\t\toffset = 0;\n-\t\t\tslot++;\n-\t\t\tif (slot \u003e= folioq_nr_slots(folioq)) {\n-\t\t\t\tif (!folioq-\u003enext) {\n-\t\t\t\t\tWARN_ON_ONCE(ret \u003c iter-\u003ecount);\n-\t\t\t\t\tbreak;\n-\t\t\t\t}\n-\t\t\t\tfolioq = folioq-\u003enext;\n-\t\t\t\tslot = 0;\n-\t\t\t}\n-\t\t}\n-\t} while (state-\u003enum_sge \u003c state-\u003emax_sge \u0026\u0026 maxsize \u003e 0);\n-\n-\titer-\u003efolioq = folioq;\n-\titer-\u003efolioq_slot = slot;\n-\titer-\u003eiov_offset = offset;\n-\titer-\u003ecount -= ret;\n-\treturn ret;\n-}\n-\n /*\n * Extract page fragments from up to the given amount of the source iterator\n * and build up an ib_sge list that refers to all of those bits. The ib_sge list\n@@ -2164,12 +2163,12 @@ static ssize_t smbdirect_map_sges_from_iter(struct iov_iter *iter, size_t len,\n \tcase ITER_BVEC:\n \t\tret = smbdirect_map_sges_from_bvec(iter, state, len);\n \t\tbreak;\n+\tcase ITER_BVECQ:\n+\t\tret = smbdirect_map_sges_from_bvecq(iter, state, len);\n+\t\tbreak;\n \tcase ITER_KVEC:\n \t\tret = smbdirect_map_sges_from_kvec(iter, state, len);\n \t\tbreak;\n-\tcase ITER_FOLIOQ:\n-\t\tret = smbdirect_map_sges_from_folioq(iter, state, len);\n-\t\tbreak;\n \tdefault:\n \t\tWARN_ONCE(1, \"iov_iter_type[%u]\\n\", iov_iter_type(iter));\n \t\treturn -EIO;\ndiff --git a/include/linux/bvec.h b/include/linux/bvec.h\nindex b63914ff56e33d..7ea62643cfb7cc 100644\n--- a/include/linux/bvec.h\n+++ b/include/linux/bvec.h\n@@ -344,4 +344,22 @@ static inline phys_addr_t bvec_phys(const struct bio_vec *bvec)\n \treturn page_to_phys(bvec-\u003ebv_page) + bvec-\u003ebv_offset;\n }\n \n+/**\n+ * bvec_kmap_partial - Map part of a bvec into the kernel virtual address space\n+ * @bvec: bvec to map\n+ * @offset: Offset into bvec\n+ *\n+ * Map the page containing the byte at @offset into the kernel virtual address\n+ * space. The caller is responsible for making sure this doesn't overrun.\n+ *\n+ * Call kunmap_local on the returned address to unmap.\n+ */\n+static inline void *bvec_kmap_partial(const struct bio_vec *bvec, size_t offset)\n+{\n+\toffset += bvec-\u003ebv_offset;\n+\n+\treturn kmap_local_page(bvec-\u003ebv_page + (offset \u003e\u003e PAGE_SHIFT)) +\n+\t\t(offset \u0026 ~PAGE_MASK);\n+}\n+\n #endif /* __LINUX_BVEC_H */\ndiff --git a/include/linux/bvecq.h b/include/linux/bvecq.h\nnew file mode 100644\nindex 00000000000000..90e6eb9588bf8b\n--- /dev/null\n+++ b/include/linux/bvecq.h\n@@ -0,0 +1,176 @@\n+/* SPDX-License-Identifier: GPL-2.0 */\n+/* Implementation of a segmented queue of bio_vec[].\n+ *\n+ * Copyright (C) 2026 Red Hat, Inc. All Rights Reserved.\n+ * Written by David Howells (dhowells@redhat.com)\n+ *\n+ * See also Documentation/core-api/bvecq.rst\n+ */\n+\n+#ifndef _LINUX_BVECQ_H\n+#define _LINUX_BVECQ_H\n+\n+#include \u003clinux/bvec.h\u003e\n+\n+/*\n+ * The type of memory retention used by the elements in bvecq-\u003ebv[] and how to\n+ * clean it up.\n+ */\n+enum bvecq_mem {\n+\tBVECQ_MEM_EXTERNAL,\t/* Externally retained memory - no freeing */\n+\tBVECQ_MEM_PAGECACHE,\t/* Ref'd pagecache pages - must put */\n+\tBVECQ_MEM_GUP,\t\t/* Pinned memory from get_user_pages() - unpin */\n+\tBVECQ_MEM_ALLOCED,\t/* Memory alloc'd by bvecq - can be freed/pooled */\n+} __mode(byte);\n+\n+/*\n+ * Segmented bio_vec queue.\n+ *\n+ * These can be linked together to form messages of indefinite length and\n+ * iterated over with an ITER_BVECQ iterator. The list is non-circular; next\n+ * and prev are NULL at the ends.\n+ *\n+ * The bv pointer points to the bio_vec array; this may be __bv if allocated\n+ * together. The caller is responsible for determining whether or not this is\n+ * the case as the array pointed to by bv may be follow on directly from the\n+ * bvecq by accident of allocation (ie. -\u003ebv == -\u003e__bv is *not* sufficient to\n+ * determine this).\n+ */\n+struct bvecq {\n+\tstruct bvecq\t*next;\t\t/* Next bvec in the list or NULL */\n+\tstruct bvecq\t*prev;\t\t/* Prev bvec in the list or NULL */\n+\trefcount_t\tref;\n+\tu32\t\tpriv;\t\t/* Private data */\n+\tu16\t\tnr_slots;\t/* Number of elements in bv[] used */\n+\tu16\t\tmax_slots;\t/* Number of elements allocated in bv[] */\n+\tenum bvecq_mem\tmem_type:3;\t/* What sort of memory and how to free it */\n+\tbool\t\tinline_bv:1;\t/* T if __bv[] is being used */\n+\tbool\t\tfrom_pool:1;\t/* T if bvecq from mempool */\n+\tstruct bio_vec\t*bv;\t\t/* Pointer to array of page fragments */\n+\tstruct bio_vec\t__bv[];\t\t/* Default array (if -\u003einline_bv) */\n+};\n+\n+/* Number of slots in a 512-byte mempool-backed bvecq. */\n+#define BVECQ_POOL_SIZE 512\n+#define BVECQ_POOL_SLOTS ((BVECQ_POOL_SIZE - sizeof(struct bvecq)) / sizeof(struct bio_vec))\n+\n+/* Number of slots in a 4K bvecq. */\n+#define BVECQ_4KB_SLOTS ((4096 - sizeof(struct bvecq)) / sizeof(struct bio_vec))\n+\n+/* Maximum number of slots in an inline allocation */\n+#define BVECQ_MAX_INLINE_SLOTS USHRT_MAX\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+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+\n+/**\n+ * bvecq_alloc_buffer - Allocate a bvecq chain and populate with buffers\n+ * @size: Target size of the buffer (can be 0 for an empty buffer)\n+ * @gfp: The allocation constraints.\n+ * @for_writeback: True if allocating for writeback\n+ *\n+ * Wrapper around ``bvecq_alloc_buffer2()``.\n+ *\n+ * Return: The first node pointer or NULL on allocation failure.\n+ */\n+static inline struct bvecq *bvecq_alloc_buffer(size_t size, gfp_t gfp, bool for_writeback)\n+{\n+\treturn bvecq_alloc_buffer2(size, 0, gfp, for_writeback);\n+}\n+\n+/**\n+ * bvecq_get - Get a ref on a bvecq\n+ * @bq: The bvecq to get a ref on\n+ *\n+ * Return: @bq.\n+ */\n+static inline struct bvecq *bvecq_get(struct bvecq *bq)\n+{\n+\trefcount_inc(\u0026bq-\u003eref);\n+\treturn bq;\n+}\n+\n+/**\n+ * bvecq_is_full - Determine if a bvecq is full\n+ * @bvecq: The object to query\n+ *\n+ * Return: true if full; false if not.\n+ */\n+static inline bool bvecq_is_full(const struct bvecq *bvecq)\n+{\n+\treturn bvecq-\u003enr_slots \u003e= bvecq-\u003emax_slots;\n+}\n+\n+/**\n+ * bvecq_filled_to - Release filled slots with release barrier\n+ * @bvecq: The object modified\n+ * @to: The latest slot filled + 1\n+ */\n+static inline void bvecq_filled_to(struct bvecq *bvecq, unsigned int to)\n+{\n+\t/* Set the slot counter after filling the slot */\n+\tsmp_store_release(\u0026bvecq-\u003enr_slots, to);\n+}\n+\n+/**\n+ * bvecq_nr_slots_acquire - Get the number of filled slots with acquire barrier\n+ * @bvecq: The object to query\n+ *\n+ * Return: The number of filled slots\n+ */\n+static inline unsigned int bvecq_nr_slots_acquire(const struct bvecq *bvecq)\n+{\n+\t/* Read the slot counter before looking at the slot */\n+\treturn smp_load_acquire(\u0026bvecq-\u003enr_slots);\n+}\n+\n+/**\n+ * bvecq_acquire_slot - Determine if a slot is valid with acquire barrier\n+ * @bvecq: The object to query\n+ * @slot: The next slot\n+ *\n+ * Return: true if valid; false if might not be valid\n+ */\n+static inline bool bvecq_acquire_slot(const struct bvecq *bvecq, unsigned int slot)\n+{\n+\t/* Read the slot counter before looking at the slot */\n+\treturn slot \u003c bvecq_nr_slots_acquire(bvecq);\n+}\n+\n+/**\n+ * bvecq_append - Get the next bvecq with appropriate barrier\n+ * @to: The bvecq to append to\n+ * @add: The bvecq to append\n+ *\n+ * Attach a new bvecq to a chain using an appropriate barrier to protect the\n+ * write.\n+ *\n+ * [!] Note that this function transfers the caller's ref to the chain.\n+ */\n+static inline void bvecq_append(struct bvecq *to, struct bvecq *add)\n+{\n+\tadd-\u003eprev = to;\n+\n+\t/* Make sure the initialisation is stored before the next pointer. */\n+\tsmp_store_release(\u0026to-\u003enext, add);\n+}\n+\n+/**\n+ * bvecq_next - Get the next bvecq with appropriate barrier\n+ * @bq: The bvecq to start from\n+ *\n+ * Return: The next bvecq in a chain, using an appropriate barrier to protect\n+ * the access.\n+ */\n+static inline struct bvecq *bvecq_next(const struct bvecq *bq)\n+{\n+\t/* Read the contents of the next node after the pointer to it. */\n+\treturn smp_load_acquire(\u0026bq-\u003enext);\n+}\n+\n+#endif /* _LINUX_BVECQ_H */\ndiff --git a/include/linux/folio_queue.h b/include/linux/folio_queue.h\ndeleted file mode 100644\nindex f6d5f1f127c9f3..00000000000000\n--- a/include/linux/folio_queue.h\n+++ /dev/null\n@@ -1,282 +0,0 @@\n-/* SPDX-License-Identifier: GPL-2.0-or-later */\n-/* Queue of folios definitions\n- *\n- * Copyright (C) 2024 Red Hat, Inc. All Rights Reserved.\n- * Written by David Howells (dhowells@redhat.com)\n- *\n- * See:\n- *\n- *\tDocumentation/core-api/folio_queue.rst\n- *\n- * for a description of the API.\n- */\n-\n-#ifndef _LINUX_FOLIO_QUEUE_H\n-#define _LINUX_FOLIO_QUEUE_H\n-\n-#include \u003clinux/folio_batch.h\u003e\n-#include \u003clinux/mm.h\u003e\n-\n-/*\n- * Segment in a queue of running buffers. Each segment can hold a number of\n- * folios and a portion of the queue can be referenced with the ITER_FOLIOQ\n- * iterator. The possibility exists of inserting non-folio elements into the\n- * queue (such as gaps).\n- *\n- * Explicit prev and next pointers are used instead of a list_head to make it\n- * easier to add segments to tail and remove them from the head without the\n- * need for a lock.\n- */\n-struct folio_queue {\n-\tstruct folio_batch\tvec;\t\t/* Folios in the queue segment */\n-\tu8\t\t\torders[FOLIO_BATCH_SIZE]; /* Order of each folio */\n-\tstruct folio_queue\t*next;\t\t/* Next queue segment or NULL */\n-\tstruct folio_queue\t*prev;\t\t/* Previous queue segment of NULL */\n-\tunsigned long\t\tmarks;\t\t/* 1-bit mark per folio */\n-\tunsigned long\t\tmarks2;\t\t/* Second 1-bit mark per folio */\n-#if FOLIO_BATCH_SIZE \u003e BITS_PER_LONG\n-#error marks is not big enough\n-#endif\n-\tunsigned int\t\trreq_id;\n-\tunsigned int\t\tdebug_id;\n-};\n-\n-/**\n- * folioq_init - Initialise a folio queue segment\n- * @folioq: The segment to initialise\n- * @rreq_id: The request identifier to use in tracelines.\n- *\n- * Initialise a folio queue segment and set an identifier to be used in traces.\n- *\n- * Note that the folio pointers are left uninitialised.\n- */\n-static inline void folioq_init(struct folio_queue *folioq, unsigned int rreq_id)\n-{\n-\tfolio_batch_init(\u0026folioq-\u003evec);\n-\tfolioq-\u003enext = NULL;\n-\tfolioq-\u003eprev = NULL;\n-\tfolioq-\u003emarks = 0;\n-\tfolioq-\u003emarks2 = 0;\n-\tfolioq-\u003erreq_id = rreq_id;\n-\tfolioq-\u003edebug_id = 0;\n-}\n-\n-/**\n- * folioq_nr_slots: Query the capacity of a folio queue segment\n- * @folioq: The segment to query\n- *\n- * Query the number of folios that a particular folio queue segment might hold.\n- * [!] NOTE: This must not be assumed to be the same for every segment!\n- */\n-static inline unsigned int folioq_nr_slots(const struct folio_queue *folioq)\n-{\n-\treturn FOLIO_BATCH_SIZE;\n-}\n-\n-/**\n- * folioq_count: Query the occupancy of a folio queue segment\n- * @folioq: The segment to query\n- *\n- * Query the number of folios that have been added to a folio queue segment.\n- * Note that this is not decreased as folios are removed from a segment.\n- */\n-static inline unsigned int folioq_count(struct folio_queue *folioq)\n-{\n-\treturn folio_batch_count(\u0026folioq-\u003evec);\n-}\n-\n-/**\n- * folioq_full: Query if a folio queue segment is full\n- * @folioq: The segment to query\n- *\n- * Query if a folio queue segment is fully occupied. Note that this does not\n- * change if folios are removed from a segment.\n- */\n-static inline bool folioq_full(struct folio_queue *folioq)\n-{\n-\t//return !folio_batch_space(\u0026folioq-\u003evec);\n-\treturn folioq_count(folioq) \u003e= folioq_nr_slots(folioq);\n-}\n-\n-/**\n- * folioq_is_marked: Check first folio mark in a folio queue segment\n- * @folioq: The segment to query\n- * @slot: The slot number of the folio to query\n- *\n- * Determine if the first mark is set for the folio in the specified slot in a\n- * folio queue segment.\n- */\n-static inline bool folioq_is_marked(const struct folio_queue *folioq, unsigned int slot)\n-{\n-\treturn test_bit(slot, \u0026folioq-\u003emarks);\n-}\n-\n-/**\n- * folioq_mark: Set the first mark on a folio in a folio queue segment\n- * @folioq: The segment to modify\n- * @slot: The slot number of the folio to modify\n- *\n- * Set the first mark for the folio in the specified slot in a folio queue\n- * segment.\n- */\n-static inline void folioq_mark(struct folio_queue *folioq, unsigned int slot)\n-{\n-\tset_bit(slot, \u0026folioq-\u003emarks);\n-}\n-\n-/**\n- * folioq_unmark: Clear the first mark on a folio in a folio queue segment\n- * @folioq: The segment to modify\n- * @slot: The slot number of the folio to modify\n- *\n- * Clear the first mark for the folio in the specified slot in a folio queue\n- * segment.\n- */\n-static inline void folioq_unmark(struct folio_queue *folioq, unsigned int slot)\n-{\n-\tclear_bit(slot, \u0026folioq-\u003emarks);\n-}\n-\n-/**\n- * folioq_is_marked2: Check second folio mark in a folio queue segment\n- * @folioq: The segment to query\n- * @slot: The slot number of the folio to query\n- *\n- * Determine if the second mark is set for the folio in the specified slot in a\n- * folio queue segment.\n- */\n-static inline bool folioq_is_marked2(const struct folio_queue *folioq, unsigned int slot)\n-{\n-\treturn test_bit(slot, \u0026folioq-\u003emarks2);\n-}\n-\n-/**\n- * folioq_mark2: Set the second mark on a folio in a folio queue segment\n- * @folioq: The segment to modify\n- * @slot: The slot number of the folio to modify\n- *\n- * Set the second mark for the folio in the specified slot in a folio queue\n- * segment.\n- */\n-static inline void folioq_mark2(struct folio_queue *folioq, unsigned int slot)\n-{\n-\tset_bit(slot, \u0026folioq-\u003emarks2);\n-}\n-\n-/**\n- * folioq_unmark2: Clear the second mark on a folio in a folio queue segment\n- * @folioq: The segment to modify\n- * @slot: The slot number of the folio to modify\n- *\n- * Clear the second mark for the folio in the specified slot in a folio queue\n- * segment.\n- */\n-static inline void folioq_unmark2(struct folio_queue *folioq, unsigned int slot)\n-{\n-\tclear_bit(slot, \u0026folioq-\u003emarks2);\n-}\n-\n-/**\n- * folioq_append: Add a folio to a folio queue segment\n- * @folioq: The segment to add to\n- * @folio: The folio to add\n- *\n- * Add a folio to the tail of the sequence in a folio queue segment, increasing\n- * the occupancy count and returning the slot number for the folio just added.\n- * The folio size is extracted and stored in the queue and the marks are left\n- * unmodified.\n- *\n- * Note that it's left up to the caller to check that the segment capacity will\n- * not be exceeded and to extend the queue.\n- */\n-static inline unsigned int folioq_append(struct folio_queue *folioq, struct folio *folio)\n-{\n-\tunsigned int slot = folioq-\u003evec.nr++;\n-\n-\tfolioq-\u003evec.folios[slot] = folio;\n-\tfolioq-\u003eorders[slot] = folio_order(folio);\n-\treturn slot;\n-}\n-\n-/**\n- * folioq_append_mark: Add a folio to a folio queue segment\n- * @folioq: The segment to add to\n- * @folio: The folio to add\n- *\n- * Add a folio to the tail of the sequence in a folio queue segment, increasing\n- * the occupancy count and returning the slot number for the folio just added.\n- * The folio size is extracted and stored in the queue, the first mark is set\n- * and and the second and third marks are left unmodified.\n- *\n- * Note that it's left up to the caller to check that the segment capacity will\n- * not be exceeded and to extend the queue.\n- */\n-static inline unsigned int folioq_append_mark(struct folio_queue *folioq, struct folio *folio)\n-{\n-\tunsigned int slot = folioq-\u003evec.nr++;\n-\n-\tfolioq-\u003evec.folios[slot] = folio;\n-\tfolioq-\u003eorders[slot] = folio_order(folio);\n-\tfolioq_mark(folioq, slot);\n-\treturn slot;\n-}\n-\n-/**\n- * folioq_folio: Get a folio from a folio queue segment\n- * @folioq: The segment to access\n- * @slot: The folio slot to access\n- *\n- * Retrieve the folio in the specified slot from a folio queue segment. Note\n- * that no bounds check is made and if the slot hasn't been added into yet, the\n- * pointer will be undefined. If the slot has been cleared, NULL will be\n- * returned.\n- */\n-static inline struct folio *folioq_folio(const struct folio_queue *folioq, unsigned int slot)\n-{\n-\treturn folioq-\u003evec.folios[slot];\n-}\n-\n-/**\n- * folioq_folio_order: Get the order of a folio from a folio queue segment\n- * @folioq: The segment to access\n- * @slot: The folio slot to access\n- *\n- * Retrieve the order of the folio in the specified slot from a folio queue\n- * segment. Note that no bounds check is made and if the slot hasn't been\n- * added into yet, the order returned will be 0.\n- */\n-static inline unsigned int folioq_folio_order(const struct folio_queue *folioq, unsigned int slot)\n-{\n-\treturn folioq-\u003eorders[slot];\n-}\n-\n-/**\n- * folioq_folio_size: Get the size of a folio from a folio queue segment\n- * @folioq: The segment to access\n- * @slot: The folio slot to access\n- *\n- * Retrieve the size of the folio in the specified slot from a folio queue\n- * segment. Note that no bounds check is made and if the slot hasn't been\n- * added into yet, the size returned will be PAGE_SIZE.\n- */\n-static inline size_t folioq_folio_size(const struct folio_queue *folioq, unsigned int slot)\n-{\n-\treturn PAGE_SIZE \u003c\u003c folioq_folio_order(folioq, slot);\n-}\n-\n-/**\n- * folioq_clear: Clear a folio from a folio queue segment\n- * @folioq: The segment to clear\n- * @slot: The folio slot to clear\n- *\n- * Clear a folio from a sequence in a folio queue segment and clear its marks.\n- * The occupancy count is left unchanged.\n- */\n-static inline void folioq_clear(struct folio_queue *folioq, unsigned int slot)\n-{\n-\tfolioq-\u003evec.folios[slot] = NULL;\n-\tfolioq_unmark(folioq, slot);\n-\tfolioq_unmark2(folioq, slot);\n-}\n-\n-#endif /* _LINUX_FOLIO_QUEUE_H */\ndiff --git a/include/linux/iov_iter.h b/include/linux/iov_iter.h\nindex 2f91884d733bfd..e88930af7f3695 100644\n--- a/include/linux/iov_iter.h\n+++ b/include/linux/iov_iter.h\n@@ -10,7 +10,7 @@\n \n #include \u003clinux/uio.h\u003e\n #include \u003clinux/bvec.h\u003e\n-#include \u003clinux/folio_queue.h\u003e\n+#include \u003clinux/bvecq.h\u003e\n \n typedef size_t (*iov_step_f)(void *iter_base, size_t progress, size_t len,\n \t\t\t void *priv, void *priv2);\n@@ -142,56 +142,65 @@ size_t iterate_bvec(struct iov_iter *iter, size_t len, void *priv, void *priv2,\n }\n \n /*\n- * Handle ITER_FOLIOQ.\n+ * Handle ITER_BVECQ.\n */\n static __always_inline\n-size_t iterate_folioq(struct iov_iter *iter, size_t len, void *priv, void *priv2,\n-\t\t iov_step_f step)\n+size_t iterate_bvecq(struct iov_iter *iter, size_t len, void *priv, void *priv2,\n+\t\t iov_step_f step)\n {\n-\tconst struct folio_queue *folioq = iter-\u003efolioq;\n-\tunsigned int slot = iter-\u003efolioq_slot;\n+\tconst struct bvecq *bq = iter-\u003ebvecq;\n+\tunsigned int slot = iter-\u003ebvecq_slot;\n \tsize_t progress = 0, skip = iter-\u003eiov_offset;\n \n-\tif (slot == folioq_nr_slots(folioq)) {\n-\t\t/* The iterator may have been extended. */\n-\t\tfolioq = folioq-\u003enext;\n-\t\tslot = 0;\n-\t}\n-\n \tdo {\n-\t\tstruct folio *folio = folioq_folio(folioq, slot);\n-\t\tsize_t part, remain = 0, consumed;\n-\t\tsize_t fsize;\n+\t\tconst struct bio_vec *bvec;\n+\t\tstruct page *page;\n+\t\tsize_t poff, plen;\n \t\tvoid *base;\n \n-\t\tif (!folio)\n-\t\t\tbreak;\n+\t\tif (slot \u003e= bq-\u003enr_slots) {\n+\t\t\tif (!bq-\u003enext)\n+\t\t\t\tbreak;\n+\t\t\tbq = bq-\u003enext;\n+\t\t\tslot = 0;\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tbvec = \u0026bq-\u003ebv[slot];\n+\t\t/*\n+\t\t * The caller must ensure that a slot with bv_len\u003e0 has a valid\n+\t\t * bv_page.\n+\t\t */\n+\t\tpage = bvec-\u003ebv_page + (bvec-\u003ebv_offset + skip) / PAGE_SIZE;\n+\t\tpoff = (bvec-\u003ebv_offset + skip) % PAGE_SIZE;\n+\t\tplen = min(bvec-\u003ebv_len - skip, len);\n+\n+\t\twhile (plen \u003e 0) {\n+\t\t\tsize_t part, remain, consumed;\n \n-\t\tfsize = folioq_folio_size(folioq, slot);\n-\t\tif (skip \u003c fsize) {\n-\t\t\tbase = kmap_local_folio(folio, skip);\n-\t\t\tpart = umin(len, PAGE_SIZE - skip % PAGE_SIZE);\n+\t\t\tpart = min(plen, PAGE_SIZE - poff);\n+\t\t\tbase = kmap_local_page(page) + poff;\n \t\t\tremain = step(base, progress, part, priv, priv2);\n \t\t\tkunmap_local(base);\n+\n \t\t\tconsumed = part - remain;\n-\t\t\tlen -= consumed;\n \t\t\tprogress += consumed;\n \t\t\tskip += consumed;\n+\t\t\tlen -= consumed;\n+\t\t\tif (!len || remain)\n+\t\t\t\tgoto stop;\n+\t\t\tpage++;\n+\t\t\tpoff = 0;\n+\t\t\tplen -= consumed;\n \t\t}\n-\t\tif (skip \u003e= fsize) {\n-\t\t\tskip = 0;\n-\t\t\tslot++;\n-\t\t\tif (slot == folioq_nr_slots(folioq) \u0026\u0026 folioq-\u003enext) {\n-\t\t\t\tfolioq = folioq-\u003enext;\n-\t\t\t\tslot = 0;\n-\t\t\t}\n-\t\t}\n-\t\tif (remain)\n-\t\t\tbreak;\n+\n+\t\tskip = 0;\n+\t\tslot++;\n \t} while (len);\n \n-\titer-\u003efolioq_slot = slot;\n-\titer-\u003efolioq = folioq;\n+stop:\n+\titer-\u003ebvecq_slot = slot;\n+\titer-\u003ebvecq = bq;\n \titer-\u003eiov_offset = skip;\n \titer-\u003ecount -= progress;\n \treturn progress;\n@@ -306,8 +315,8 @@ size_t iterate_and_advance2(struct iov_iter *iter, size_t len, void *priv,\n \t\treturn iterate_bvec(iter, len, priv, priv2, step);\n \tif (iov_iter_is_kvec(iter))\n \t\treturn iterate_kvec(iter, len, priv, priv2, step);\n-\tif (iov_iter_is_folioq(iter))\n-\t\treturn iterate_folioq(iter, len, priv, priv2, step);\n+\tif (iov_iter_is_bvecq(iter))\n+\t\treturn iterate_bvecq(iter, len, priv, priv2, step);\n \tif (iov_iter_is_xarray(iter))\n \t\treturn iterate_xarray(iter, len, priv, priv2, step);\n \tif (WARN_ON_ONCE(iov_iter_is_dmabuf_map(iter)))\n@@ -344,7 +353,7 @@ size_t iterate_and_advance(struct iov_iter *iter, size_t len, void *priv,\n * buffer is presented in segments, which for kernel iteration are broken up by\n * physical pages and mapped, with the mapped address being presented.\n *\n- * [!] Note This will only handle BVEC, KVEC, FOLIOQ, XARRAY and DISCARD-type\n+ * [!] Note This will only handle BVEC, KVEC, BVECQ, XARRAY and DISCARD-type\n * iterators; it will not handle UBUF or IOVEC-type iterators.\n *\n * A step functions, @step, must be provided, one for handling mapped kernel\n@@ -372,8 +381,8 @@ size_t iterate_and_advance_kernel(struct iov_iter *iter, size_t len, void *priv,\n \t\treturn iterate_bvec(iter, len, priv, priv2, step);\n \tif (iov_iter_is_kvec(iter))\n \t\treturn iterate_kvec(iter, len, priv, priv2, step);\n-\tif (iov_iter_is_folioq(iter))\n-\t\treturn iterate_folioq(iter, len, priv, priv2, step);\n+\tif (iov_iter_is_bvecq(iter))\n+\t\treturn iterate_bvecq(iter, len, priv, priv2, step);\n \tif (iov_iter_is_xarray(iter))\n \t\treturn iterate_xarray(iter, len, priv, priv2, step);\n \treturn iterate_discard(iter, len, priv, priv2, step);\ndiff --git a/include/linux/netfs.h b/include/linux/netfs.h\nindex e5961450f3f154..ac6a4470b60fd1 100644\n--- a/include/linux/netfs.h\n+++ b/include/linux/netfs.h\n@@ -17,13 +17,13 @@\n #include \u003clinux/workqueue.h\u003e\n #include \u003clinux/fs.h\u003e\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 fscache_occupancy;\n-struct folio_queue;\n \n /**\n * folio_start_private_2 - Start an fscache write on a folio. [DEPRECATED]\n@@ -248,8 +248,6 @@ struct netfs_io_request {\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-#define NETFS_ROLLBUF_PUT_MARK\t\tROLLBUF_MARK_1\n-#define NETFS_ROLLBUF_PAGECACHE_MARK\tROLLBUF_MARK_2\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@@ -429,7 +427,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@@ -471,18 +469,6 @@ void netfs_end_io_write(struct inode *inode);\n int netfs_start_io_direct(struct inode *inode);\n void netfs_end_io_direct(struct inode *inode);\n \n-/* Miscellaneous APIs. */\n-struct folio_queue *netfs_folioq_alloc(unsigned int rreq_id, gfp_t gfp,\n-\t\t\t\t unsigned int trace /*enum netfs_folioq_trace*/);\n-void netfs_folioq_free(struct folio_queue *folioq,\n-\t\t unsigned int trace /*enum netfs_trace_folioq*/);\n-\n-/* Buffer wrangling helpers API. */\n-int netfs_alloc_folioq_buffer(struct address_space *mapping,\n-\t\t\t struct folio_queue **_buffer,\n-\t\t\t size_t *_cur_size, ssize_t size, gfp_t gfp);\n-void netfs_free_folioq_buffer(struct folio_queue *fq);\n-\n /* Writeback exclusion API. */\n bool netfs_wb_begin(struct netfs_inode *ictx, bool nowait);\n void netfs_wb_end(struct netfs_inode *ictx);\ndiff --git a/include/linux/rolling_buffer.h b/include/linux/rolling_buffer.h\nindex a97f7cfaacaad7..5c0bc4221f010c 100644\n--- a/include/linux/rolling_buffer.h\n+++ b/include/linux/rolling_buffer.h\n@@ -8,49 +8,35 @@\n #ifndef _ROLLING_BUFFER_H\n #define _ROLLING_BUFFER_H\n \n-#include \u003clinux/folio_queue.h\u003e\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 folio\n- * queue segments can be added to one end by one thread and removed from the\n- * other end by another thread. The buffer isn't allowed to be empty; it must\n- * always have at least one folio_queue in it so that neither side has to\n- * modify both queue pointers.\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 folio_queue\t*head;\t\t/* Producer's insertion point */\n-\tstruct folio_queue\t*tail;\t\t/* Consumer's removal point */\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\tnext_head_slot;\t/* Next slot in -\u003ehead */\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-/*\n- * Snapshot of a rolling buffer.\n- */\n-struct rolling_buffer_snapshot {\n-\tstruct folio_queue\t*curr_folioq;\t/* Queue segment in which current folio resides */\n-\tunsigned char\t\tcurr_slot;\t/* Folio currently being read */\n-\tunsigned char\t\tcurr_order;\t/* Order of folio */\n-};\n-\n-/* Marks to store per-folio in the internal folio_queue structs. */\n-#define ROLLBUF_MARK_1\tBIT(0)\n-#define ROLLBUF_MARK_2\tBIT(1)\n-\n-int rolling_buffer_init(struct rolling_buffer *roll, unsigned int rreq_id,\n-\t\t\tunsigned int direction, gfp_t gfp);\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 unsigned int rreq_id, gfp_t gfp);\n-ssize_t rolling_buffer_append(struct rolling_buffer *roll, struct folio *folio,\n-\t\t\t unsigned int flags, gfp_t gfp);\n-struct folio_queue *rolling_buffer_delete_spent(struct rolling_buffer *roll);\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)\ndiff --git a/include/linux/uio.h b/include/linux/uio.h\nindex 638c1116e912e7..3fc98542922e31 100644\n--- a/include/linux/uio.h\n+++ b/include/linux/uio.h\n@@ -11,7 +11,6 @@\n #include \u003cuapi/linux/uio.h\u003e\n \n struct page;\n-struct folio_queue;\n struct dma_buf_io_map;\n \n typedef unsigned int __bitwise iov_iter_extraction_t;\n@@ -27,7 +26,7 @@ enum iter_type {\n \tITER_IOVEC,\n \tITER_BVEC,\n \tITER_KVEC,\n-\tITER_FOLIOQ,\n+\tITER_BVECQ,\n \tITER_XARRAY,\n \tITER_DISCARD,\n \tITER_DMABUF_MAP,\n@@ -70,7 +69,7 @@ struct iov_iter {\n \t\t\t\tconst struct iovec *__iov;\n \t\t\t\tconst struct kvec *kvec;\n \t\t\t\tconst struct bio_vec *bvec;\n-\t\t\t\tconst struct folio_queue *folioq;\n+\t\t\t\tconst struct bvecq *bvecq;\n \t\t\t\tstruct xarray *xarray;\n \t\t\t\tvoid __user *ubuf;\n \t\t\t\tstruct dma_buf_io_map *dmabuf_map;\n@@ -80,7 +79,7 @@ struct iov_iter {\n \t};\n \tunion {\n \t\tunsigned long nr_segs;\n-\t\tu8 folioq_slot;\n+\t\tu16 bvecq_slot;\n \t\tloff_t xarray_start;\n \t};\n };\n@@ -148,9 +147,9 @@ static inline bool iov_iter_is_discard(const struct iov_iter *i)\n \treturn iov_iter_type(i) == ITER_DISCARD;\n }\n \n-static inline bool iov_iter_is_folioq(const struct iov_iter *i)\n+static inline bool iov_iter_is_bvecq(const struct iov_iter *i)\n {\n-\treturn iov_iter_type(i) == ITER_FOLIOQ;\n+\treturn iov_iter_type(i) == ITER_BVECQ;\n }\n \n static inline bool iov_iter_is_xarray(const struct iov_iter *i)\n@@ -303,9 +302,9 @@ void iov_iter_kvec(struct iov_iter *i, unsigned int direction, const struct kvec\n void iov_iter_bvec(struct iov_iter *i, unsigned int direction, const struct bio_vec *bvec,\n \t\t\tunsigned long nr_segs, size_t count);\n void iov_iter_discard(struct iov_iter *i, unsigned int direction, size_t count);\n-void iov_iter_folio_queue(struct iov_iter *i, unsigned int direction,\n-\t\t\t const struct folio_queue *folioq,\n-\t\t\t unsigned int first_slot, unsigned int offset, size_t count);\n+void iov_iter_bvec_queue(struct iov_iter *i, unsigned int direction,\n+\t\t\t const struct bvecq *bvecq,\n+\t\t\t unsigned int first_slot, unsigned int offset, size_t count);\n void iov_iter_xarray(struct iov_iter *i, unsigned int direction, struct xarray *xarray,\n \t\t loff_t start, size_t count);\n void iov_iter_dmabuf_map(struct iov_iter *i, unsigned int direction,\ndiff --git a/include/trace/events/netfs.h b/include/trace/events/netfs.h\nindex bf1e1f185b05c4..e80c27c49ce259 100644\n--- a/include/trace/events/netfs.h\n+++ b/include/trace/events/netfs.h\n@@ -199,7 +199,6 @@\n \tEM(netfs_streaming_filled_page,\t\t\"mod-streamw-f\") \\\n \tEM(netfs_streaming_cont_filled_page,\t\"mod-streamw-f+\") \\\n \tEM(netfs_folio_trace_abandon,\t\t\"abandon\")\t\\\n-\tEM(netfs_folio_trace_alloc_buffer,\t\"alloc-buf\")\t\\\n \tEM(netfs_folio_trace_cancel_copy,\t\"cancel-copy\")\t\\\n \tEM(netfs_folio_trace_cancel_store,\t\"cancel-store\")\t\\\n \tEM(netfs_folio_trace_end_copy,\t\t\"end-copy\")\t\\\n@@ -222,7 +221,6 @@\n \tEM(netfs_folio_trace_not_locked,\t\"!locked\")\t\\\n \tEM(netfs_folio_trace_not_under_wback,\t\"!wback\")\t\\\n \tEM(netfs_folio_trace_pgpriv2_copy,\t\"pgpriv2-copy\")\t\\\n-\tEM(netfs_folio_trace_put,\t\t\"put\")\t\t\\\n \tEM(netfs_folio_trace_read,\t\t\"read\")\t\t\\\n \tEM(netfs_folio_trace_read_done,\t\t\"read-done\")\t\\\n \tEM(netfs_folio_trace_read_gaps,\t\t\"read-gaps\")\t\\\n@@ -244,14 +242,6 @@\n \tEM(netfs_trace_donate_to_next,\t\t\"to-next\")\t\\\n \tE_(netfs_trace_donate_to_deferred_next,\t\"defer-next\")\n \n-#define netfs_folioq_traces\t\t\t\t\t\\\n-\tEM(netfs_trace_folioq_alloc_buffer,\t\"alloc-buf\")\t\\\n-\tEM(netfs_trace_folioq_clear,\t\t\"clear\")\t\\\n-\tEM(netfs_trace_folioq_delete,\t\t\"delete\")\t\\\n-\tEM(netfs_trace_folioq_make_space,\t\"make-space\")\t\\\n-\tEM(netfs_trace_folioq_rollbuf_init,\t\"roll-init\")\t\\\n-\tE_(netfs_trace_folioq_read_progress,\t\"r-progress\")\n-\n #ifndef __NETFS_DECLARE_TRACE_ENUMS_ONCE_ONLY\n #define __NETFS_DECLARE_TRACE_ENUMS_ONCE_ONLY\n \n@@ -270,7 +260,6 @@ enum netfs_sreq_ref_trace { netfs_sreq_ref_traces } __mode(byte);\n enum netfs_folio_trace { netfs_folio_traces } __mode(byte);\n enum netfs_collect_contig_trace { netfs_collect_contig_traces } __mode(byte);\n enum netfs_donate_trace { netfs_donate_traces } __mode(byte);\n-enum netfs_folioq_trace { netfs_folioq_traces } __mode(byte);\n \n #endif\n \n@@ -294,7 +283,6 @@ netfs_sreq_ref_traces;\n netfs_folio_traces;\n netfs_collect_contig_traces;\n netfs_donate_traces;\n-netfs_folioq_traces;\n \n /*\n * Now redefine the EM() and E_() macros to map the enums to the strings that\n@@ -398,7 +386,7 @@ 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.folioq_slot;\n+\t\t __entry-\u003eslot\t= sreq-\u003eio_iter.bvecq_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@@ -773,29 +761,6 @@ TRACE_EVENT(netfs_collect_stream,\n \t\t __entry-\u003ecollected_to, __entry-\u003eissued_to)\n \t );\n \n-TRACE_EVENT(netfs_folioq,\n-\t TP_PROTO(const struct folio_queue *fq,\n-\t\t enum netfs_folioq_trace trace),\n-\n-\t TP_ARGS(fq, trace),\n-\n-\t TP_STRUCT__entry(\n-\t\t __field(unsigned int,\t\trreq)\n-\t\t __field(unsigned int,\t\tid)\n-\t\t __field(enum netfs_folioq_trace,\ttrace)\n-\t\t\t ),\n-\n-\t TP_fast_assign(\n-\t\t __entry-\u003erreq\t= fq ? fq-\u003erreq_id : 0;\n-\t\t __entry-\u003eid\t\t= fq ? fq-\u003edebug_id : 0;\n-\t\t __entry-\u003etrace\t= trace;\n-\t\t\t ),\n-\n-\t TP_printk(\"R=%08x fq=%x %s\",\n-\t\t __entry-\u003erreq, __entry-\u003eid,\n-\t\t __print_symbolic(__entry-\u003etrace, netfs_folioq_traces))\n-\t );\n-\n TRACE_EVENT(netfs_read_progress_at,\n \t TP_PROTO(const struct netfs_io_request *rreq),\n \ndiff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c\nindex 1be30487a2fa75..0fca0c3132fe29 100644\n--- a/kernel/bpf/btf.c\n+++ b/kernel/bpf/btf.c\n@@ -7344,8 +7344,6 @@ static const struct bpf_raw_tp_null_args raw_tp_null_args[] = {\n \t/* amdgpu */\n \t{ \"amdgpu_vm_bo_map\", 0x1 },\n \t{ \"amdgpu_vm_bo_unmap\", 0x1 },\n-\t/* netfs */\n-\t{ \"netfs_folioq\", 0x1 },\n \t/* xfs from xfs_defer_pending_class */\n \t{ \"xfs_defer_create_intent\", 0x1 },\n \t{ \"xfs_defer_cancel_list\", 0x1 },\ndiff --git a/lib/Kconfig.debug b/lib/Kconfig.debug\nindex 2d22638ec13a63..06b4546421a13e 100644\n--- a/lib/Kconfig.debug\n+++ b/lib/Kconfig.debug\n@@ -2385,6 +2385,19 @@ config TEST_IOV_ITER\n \n \t If unsure, say N.\n \n+config TEST_BVECQ\n+\ttristate \"Test bvecq operation\" if !KUNIT_ALL_TESTS\n+\tdepends on KUNIT\n+\tdepends on MMU\n+\tdepends on NETFS_SUPPORT\n+\tdefault KUNIT_ALL_TESTS\n+\thelp\n+\t Enable this to turn on testing of the operation of the bvecq\n+\t structure. This test is executed only once during system\n+\t boot (so affects only boot time), or at module load time.\n+\n+\t If unsure, say N.\n+\n config KPROBES_SANITY_TEST\n \ttristate \"Kprobes sanity tests\" if !KUNIT_ALL_TESTS\n \tdepends on DEBUG_KERNEL\ndiff --git a/lib/iov_iter.c b/lib/iov_iter.c\nindex fa4fe2e9238316..55525962a1d6dc 100644\n--- a/lib/iov_iter.c\n+++ b/lib/iov_iter.c\n@@ -538,37 +538,38 @@ static void iov_iter_iovec_advance(struct iov_iter *i, size_t size)\n \ti-\u003e__iov = iov;\n }\n \n-static void iov_iter_folioq_advance(struct iov_iter *i, size_t size)\n+static void iov_iter_bvecq_advance(struct iov_iter *i, size_t by)\n {\n-\tconst struct folio_queue *folioq = i-\u003efolioq;\n-\tunsigned int slot = i-\u003efolioq_slot;\n+\tconst struct bvecq *bq = i-\u003ebvecq;\n+\tunsigned int slot = i-\u003ebvecq_slot;\n \n \tif (!i-\u003ecount)\n \t\treturn;\n-\ti-\u003ecount -= size;\n-\n-\tif (slot \u003e= folioq_nr_slots(folioq)) {\n-\t\tfolioq = folioq-\u003enext;\n-\t\tslot = 0;\n-\t}\n+\ti-\u003ecount -= by;\n \n-\tsize += i-\u003eiov_offset; /* From beginning of current segment. */\n+\tby += i-\u003eiov_offset; /* From beginning of current segment. */\n \tdo {\n-\t\tsize_t fsize = folioq_folio_size(folioq, slot);\n+\t\tsize_t len;\n \n-\t\tif (likely(size \u003c fsize))\n-\t\t\tbreak;\n-\t\tsize -= fsize;\n-\t\tslot++;\n-\t\tif (slot \u003e= folioq_nr_slots(folioq) \u0026\u0026 folioq-\u003enext) {\n-\t\t\tfolioq = folioq-\u003enext;\n+\t\tif (slot \u003e= bq-\u003enr_slots) {\n+\t\t\tif (!bq-\u003enext)\n+\t\t\t\tbreak;\n+\t\t\tbq = bq-\u003enext;\n \t\t\tslot = 0;\n+\t\t\tcontinue;\n \t\t}\n-\t} while (size);\n \n-\ti-\u003eiov_offset = size;\n-\ti-\u003efolioq_slot = slot;\n-\ti-\u003efolioq = folioq;\n+\t\tlen = bq-\u003ebv[slot].bv_len;\n+\n+\t\tif (likely(by \u003c len))\n+\t\t\tbreak;\n+\t\tby -= len;\n+\t\tslot++;\n+\t} while (by);\n+\n+\ti-\u003eiov_offset = by;\n+\ti-\u003ebvecq_slot = slot;\n+\ti-\u003ebvecq = bq;\n }\n \n void iov_iter_advance(struct iov_iter *i, size_t size)\n@@ -584,38 +585,39 @@ void iov_iter_advance(struct iov_iter *i, size_t size)\n \t\tiov_iter_iovec_advance(i, size);\n \t} else if (iov_iter_is_bvec(i)) {\n \t\tiov_iter_bvec_advance(i, size);\n-\t} else if (iov_iter_is_folioq(i)) {\n-\t\tiov_iter_folioq_advance(i, size);\n+\t} else if (iov_iter_is_bvecq(i)) {\n+\t\tiov_iter_bvecq_advance(i, size);\n \t} else if (iov_iter_is_discard(i)) {\n \t\ti-\u003ecount -= size;\n \t}\n }\n EXPORT_SYMBOL(iov_iter_advance);\n \n-static void iov_iter_folioq_revert(struct iov_iter *i, size_t unroll)\n+static void iov_iter_bvecq_revert(struct iov_iter *i, size_t unroll)\n {\n-\tconst struct folio_queue *folioq = i-\u003efolioq;\n-\tunsigned int slot = i-\u003efolioq_slot;\n+\tconst struct bvecq *bq = i-\u003ebvecq;\n+\tunsigned int slot = i-\u003ebvecq_slot;\n \n \tfor (;;) {\n-\t\tsize_t fsize;\n+\t\tsize_t len;\n \n \t\tif (slot == 0) {\n-\t\t\tfolioq = folioq-\u003eprev;\n-\t\t\tslot = folioq_nr_slots(folioq);\n+\t\t\tbq = bq-\u003eprev;\n+\t\t\tslot = bq-\u003enr_slots;\n+\t\t\tcontinue;\n \t\t}\n \t\tslot--;\n \n-\t\tfsize = folioq_folio_size(folioq, slot);\n-\t\tif (unroll \u003c= fsize) {\n-\t\t\ti-\u003eiov_offset = fsize - unroll;\n+\t\tlen = bq-\u003ebv[slot].bv_len;\n+\t\tif (unroll \u003c= len) {\n+\t\t\ti-\u003eiov_offset = len - unroll;\n \t\t\tbreak;\n \t\t}\n-\t\tunroll -= fsize;\n+\t\tunroll -= len;\n \t}\n \n-\ti-\u003efolioq_slot = slot;\n-\ti-\u003efolioq = folioq;\n+\ti-\u003ebvecq_slot = slot;\n+\ti-\u003ebvecq = bq;\n }\n \n void iov_iter_revert(struct iov_iter *i, size_t unroll)\n@@ -650,9 +652,9 @@ void iov_iter_revert(struct iov_iter *i, size_t unroll)\n \t\t\t}\n \t\t\tunroll -= n;\n \t\t}\n-\t} else if (iov_iter_is_folioq(i)) {\n+\t} else if (iov_iter_is_bvecq(i)) {\n \t\ti-\u003eiov_offset = 0;\n-\t\tiov_iter_folioq_revert(i, unroll);\n+\t\tiov_iter_bvecq_revert(i, unroll);\n \t} else { /* same logics for iovec and kvec */\n \t\tconst struct iovec *iov = iter_iov(i);\n \t\twhile (1) {\n@@ -680,9 +682,28 @@ size_t iov_iter_single_seg_count(const struct iov_iter *i)\n \t\tif (iov_iter_is_bvec(i))\n \t\t\treturn min(i-\u003ecount, i-\u003ebvec-\u003ebv_len - i-\u003eiov_offset);\n \t}\n-\tif (unlikely(iov_iter_is_folioq(i)))\n-\t\treturn !i-\u003ecount ? 0 :\n-\t\t\tumin(folioq_folio_size(i-\u003efolioq, i-\u003efolioq_slot), i-\u003ecount);\n+\tif (!i-\u003ecount)\n+\t\treturn 0;\n+\tif (unlikely(iov_iter_is_bvecq(i))) {\n+\t\tconst struct bvecq *bq = i-\u003ebvecq;\n+\t\tunsigned int slot = i-\u003ebvecq_slot;\n+\t\tsize_t offset = i-\u003eiov_offset;\n+\n+\t\tfor (;;) {\n+\t\t\twhile (slot \u003e= bq-\u003enr_slots) {\n+\t\t\t\tbq = bq-\u003enext;\n+\t\t\t\tif (!bq)\n+\t\t\t\t\treturn 0;\n+\t\t\t\tslot = 0;\n+\t\t\t\toffset = 0;\n+\t\t\t}\n+\t\t\tif (bq-\u003ebv[slot].bv_len \u003e offset)\n+\t\t\t\tbreak;\n+\t\t\tslot++;\n+\t\t\toffset = 0;\n+\t\t}\n+\t\treturn min(i-\u003ecount, bq-\u003ebv[slot].bv_len - offset);\n+\t}\n \treturn i-\u003ecount;\n }\n EXPORT_SYMBOL(iov_iter_single_seg_count);\n@@ -720,34 +741,34 @@ void iov_iter_bvec(struct iov_iter *i, unsigned int direction,\n EXPORT_SYMBOL(iov_iter_bvec);\n \n /**\n- * iov_iter_folio_queue - Initialise an I/O iterator to use the folios in a folio queue\n+ * iov_iter_bvec_queue - Initialise an I/O iterator to use a segmented bvec queue\n * @i: The iterator to initialise.\n * @direction: The direction of the transfer.\n- * @folioq: The starting point in the folio queue.\n- * @first_slot: The first slot in the folio queue to use\n- * @offset: The offset into the folio in the first slot to start at\n+ * @bvecq: The starting point in the bvec queue.\n+ * @first_slot: The first slot in the bvec queue to use\n+ * @offset: The offset into the bvec in the first slot to start at\n * @count: The size of the I/O buffer in bytes.\n *\n- * Set up an I/O iterator to either draw data out of the pages attached to an\n- * inode or to inject data into those pages. The pages *must* be prevented\n- * from evaporation, either by taking a ref on them or locking them by the\n- * caller.\n+ * Set up an I/O iterator to either draw data out of the buffers attached to an\n+ * inode or to inject data into those buffers. The pages *must* be prevented\n+ * from evaporation by the caller, by taking a ref or a lock on them or by\n+ * cleaning them up after the I/O is complete.\n */\n-void iov_iter_folio_queue(struct iov_iter *i, unsigned int direction,\n-\t\t\t const struct folio_queue *folioq, unsigned int first_slot,\n-\t\t\t unsigned int offset, size_t count)\n+void iov_iter_bvec_queue(struct iov_iter *i, unsigned int direction,\n+\t\t\t const struct bvecq *bvecq, unsigned int first_slot,\n+\t\t\t unsigned int offset, size_t count)\n {\n-\tBUG_ON(direction \u0026 ~1);\n+\tWARN_ON(direction \u0026 ~(READ | WRITE));\n \t*i = (struct iov_iter) {\n-\t\t.iter_type = ITER_FOLIOQ,\n-\t\t.data_source = direction,\n-\t\t.folioq = folioq,\n-\t\t.folioq_slot = first_slot,\n-\t\t.count = count,\n-\t\t.iov_offset = offset,\n+\t\t.iter_type\t= ITER_BVECQ,\n+\t\t.data_source\t= direction,\n+\t\t.bvecq\t\t= bvecq,\n+\t\t.bvecq_slot\t= first_slot,\n+\t\t.count\t\t= count,\n+\t\t.iov_offset\t= offset,\n \t};\n }\n-EXPORT_SYMBOL(iov_iter_folio_queue);\n+EXPORT_SYMBOL(iov_iter_bvec_queue);\n \n /**\n * iov_iter_xarray - Initialise an I/O iterator to use the pages in an xarray\n@@ -855,6 +876,39 @@ static unsigned long iov_iter_alignment_bvec(const struct iov_iter *i)\n \treturn res;\n }\n \n+static unsigned long iov_iter_alignment_bvecq(const struct iov_iter *iter)\n+{\n+\tconst struct bvecq *bq;\n+\tunsigned long res = 0;\n+\tunsigned int slot = iter-\u003ebvecq_slot;\n+\tsize_t skip = iter-\u003eiov_offset;\n+\tsize_t size = iter-\u003ecount;\n+\n+\tif (!size)\n+\t\treturn res;\n+\n+\tfor (bq = iter-\u003ebvecq; bq; bq = bq-\u003enext) {\n+\t\tfor (; slot \u003c bq-\u003enr_slots; slot++) {\n+\t\t\tconst struct bio_vec *bvec = \u0026bq-\u003ebv[slot];\n+\t\t\tsize_t part = min(bvec-\u003ebv_len - skip, size);\n+\n+\t\t\tif (part) {\n+\t\t\t\tres |= bvec-\u003ebv_offset + skip;\n+\t\t\t\tres |= part;\n+\t\t\t}\n+\n+\t\t\tsize -= part;\n+\t\t\tif (size == 0)\n+\t\t\t\treturn res;\n+\t\t\tskip = 0;\n+\t\t}\n+\n+\t\tslot = 0;\n+\t}\n+\n+\treturn res;\n+}\n+\n unsigned long iov_iter_alignment(const struct iov_iter *i)\n {\n \tif (likely(iter_is_ubuf(i))) {\n@@ -874,9 +928,11 @@ unsigned long iov_iter_alignment(const struct iov_iter *i)\n \n \tif (iov_iter_is_bvec(i))\n \t\treturn iov_iter_alignment_bvec(i);\n+\tif (iov_iter_is_bvecq(i))\n+\t\treturn iov_iter_alignment_bvecq(i);\n \n-\t/* With both xarray and folioq types, we're dealing with whole folios. */\n-\tif (iov_iter_is_folioq(i) || iov_iter_is_dmabuf_map(i))\n+\t/* With the xarray type, we're dealing with whole folios. */\n+\tif (iov_iter_is_dmabuf_map(i))\n \t\treturn i-\u003eiov_offset | i-\u003ecount;\n \tif (iov_iter_is_xarray(i))\n \t\treturn (i-\u003exarray_start + i-\u003eiov_offset) | i-\u003ecount;\n@@ -930,62 +986,158 @@ static int want_pages_array(struct page ***res, size_t size,\n \treturn count;\n }\n \n-static ssize_t iter_folioq_get_pages(struct iov_iter *iter,\n-\t\t\t\t struct page ***ppages, size_t maxsize,\n-\t\t\t\t unsigned maxpages, size_t *_start_offset)\n+/*\n+ * Count the number of virtually contiguous pages coming up next in an\n+ * ITER_BVECQ iterator, up to the specified maxima.\n+ */\n+static unsigned int iter_count_bvecq_pages(const struct iov_iter *iter,\n+\t\t\t\t\t size_t maxsize,\n+\t\t\t\t\t unsigned int maxpages)\n {\n-\tconst struct folio_queue *folioq = iter-\u003efolioq;\n+\tconst struct bvecq *bvecq = iter-\u003ebvecq;\n+\tunsigned int slot = iter-\u003ebvecq_slot;\n+\tssize_t remain = umin(maxsize, iter-\u003ecount);\n+\tsize_t count = 0, offset = iter-\u003eiov_offset;\n+\n+\tdo {\n+\t\tconst struct bio_vec *bv;\n+\t\tsize_t boff, blen;\n+\n+\t\tif (slot \u003e= bvecq-\u003enr_slots) {\n+\t\t\tif (!bvecq-\u003enext) {\n+\t\t\t\tWARN_ON_ONCE(remain \u003e 0);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tbvecq = bvecq-\u003enext;\n+\t\t\tslot = 0;\n+\t\t\toffset = 0;\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tbv = \u0026bvecq-\u003ebv[slot++];\n+\t\tboff = bv-\u003ebv_offset;\n+\t\tblen = bv-\u003ebv_len;\n+\n+\t\t/* bv_page is not allowed to be NULL unless bv_len == 0. */\n+\t\tif (WARN_ON_ONCE(!bv-\u003ebv_page \u0026\u0026 blen \u003e 0))\n+\t\t\tbreak;\n+\t\tif (!PAGE_ALIGNED(boff) \u0026\u0026 count \u003e 0)\n+\t\t\tbreak;\n+\n+\t\tboff += offset;\n+\t\tblen -= offset;\n+\t\toffset = 0;\n+\t\tif (!blen)\n+\t\t\tcontinue;\n+\n+\t\tblen = umin(blen, remain);\n+\t\tremain -= blen;\n+\t\tblen += offset_in_page(boff);\n+\t\tcount += DIV_ROUND_UP(blen, PAGE_SIZE);\n+\n+\t\tif (!PAGE_ALIGNED(blen))\n+\t\t\tbreak;\n+\t} while (remain \u003e 0 \u0026\u0026 count \u003c maxpages);\n+\n+\treturn min(count, maxpages);\n+}\n+\n+/*\n+ * Get a list of virtually contiguous pages from an ITER_BVECQ iterator and pin\n+ * them.\n+ */\n+static ssize_t iter_bvecq_get_pages(struct iov_iter *iter,\n+\t\t\t\t struct page ***ppages, size_t maxsize,\n+\t\t\t\t unsigned int maxpages, size_t *_start_offset)\n+{\n+\tconst struct bvecq *bvecq = iter-\u003ebvecq;\n \tstruct page **pages;\n-\tunsigned int slot = iter-\u003efolioq_slot;\n-\tsize_t extracted = 0, count = iter-\u003ecount, iov_offset = iter-\u003eiov_offset;\n+\tunsigned int slot = iter-\u003ebvecq_slot, nr = 0;\n+\tsize_t extracted = 0, offset = iter-\u003eiov_offset;\n \n-\tif (slot \u003e= folioq_nr_slots(folioq)) {\n-\t\tfolioq = folioq-\u003enext;\n-\t\tslot = 0;\n-\t\tif (WARN_ON(iov_offset != 0))\n-\t\t\treturn -EIO;\n+\tfor (;;) {\n+\t\tif (slot \u003e= bvecq-\u003enr_slots) {\n+\t\t\tif (!bvecq-\u003enext)\n+\t\t\t\treturn 0;\n+\t\t\tbvecq = bvecq-\u003enext;\n+\t\t\tslot = 0;\n+\t\t\toffset = 0;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tif (offset \u003e= bvecq-\u003ebv[slot].bv_len) {\n+\t\t\tslot++;\n+\t\t\toffset = 0;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tbreak;\n \t}\n \n-\tmaxpages = want_pages_array(ppages, maxsize, iov_offset \u0026 ~PAGE_MASK, maxpages);\n+\t/* Count the next run of virtually contiguous pages. */\n+\tmaxpages = iter_count_bvecq_pages(iter, maxsize, maxpages);\n+\tif (!maxpages)\n+\t\treturn 0;\n+\n+\tmaxpages = want_pages_array(ppages, maxsize,\n+\t\t\t\t (bvecq-\u003ebv[slot].bv_offset + offset) \u0026 ~PAGE_MASK,\n+\t\t\t\t maxpages);\n \tif (!maxpages)\n \t\treturn -ENOMEM;\n-\t*_start_offset = iov_offset \u0026 ~PAGE_MASK;\n \tpages = *ppages;\n \n-\tfor (;;) {\n-\t\tstruct folio *folio = folioq_folio(folioq, slot);\n-\t\tsize_t offset = iov_offset, fsize = folioq_folio_size(folioq, slot);\n-\t\tsize_t part = PAGE_SIZE - offset % PAGE_SIZE;\n-\n-\t\tif (offset \u003c fsize) {\n-\t\t\tpart = umin(part, umin(maxsize - extracted, fsize - offset));\n-\t\t\tcount -= part;\n-\t\t\tiov_offset += part;\n-\t\t\textracted += part;\n+\t/* Now transcribe the page pointers. */\n+\tdo {\n+\t\tconst struct bio_vec *bv;\n+\t\tsize_t boff, blen;\n \n-\t\t\t*pages = folio_page(folio, offset / PAGE_SIZE);\n-\t\t\tget_page(*pages);\n-\t\t\tpages++;\n-\t\t\tmaxpages--;\n+\t\tif (slot \u003e= bvecq-\u003enr_slots) {\n+\t\t\tif (!bvecq-\u003enext) {\n+\t\t\t\tWARN_ON_ONCE(extracted \u003c iter-\u003ecount);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tbvecq = bvecq-\u003enext;\n+\t\t\tslot = 0;\n+\t\t\toffset = 0;\n+\t\t\tcontinue;\n \t\t}\n \n-\t\tif (maxpages == 0 || extracted \u003e= maxsize)\n-\t\t\tbreak;\n+\t\tbv = \u0026bvecq-\u003ebv[slot];\n+\t\tboff = bv-\u003ebv_offset;\n+\t\tblen = bv-\u003ebv_len;\n+\n+\t\t/* bv_page is not allowed to be NULL unless bv_len == 0. */\n+\n+\t\tif (offset \u003c blen) {\n+\t\t\tstruct folio *folio;\n+\t\t\tsize_t poff = (boff + offset) % PAGE_SIZE;\n+\t\t\tsize_t part = min(maxsize - extracted, blen - offset);\n+\t\t\tsize_t pix = (boff + offset) / PAGE_SIZE;\n+\n+\t\t\tif (poff + part \u003e PAGE_SIZE)\n+\t\t\t\tpart = PAGE_SIZE - poff;\n+\n+\t\t\tif (!extracted)\n+\t\t\t\t*_start_offset = poff;\n+\n+\t\t\t/* Get a ref on the page if it's not a slab page. */\n+\t\t\tfolio = page_folio(bv-\u003ebv_page + pix);\n+\t\t\tif (!folio_test_slab(folio))\n+\t\t\t\tfolio_get(folio);\n+\n+\t\t\tpages[nr++] = bv-\u003ebv_page + pix;\n+\t\t\toffset += part;\n+\t\t\textracted += part;\n+\t\t}\n \n-\t\tif (iov_offset \u003e= fsize) {\n-\t\t\tiov_offset = 0;\n+\t\tif (offset \u003e= blen) {\n+\t\t\toffset = 0;\n \t\t\tslot++;\n-\t\t\tif (slot == folioq_nr_slots(folioq) \u0026\u0026 folioq-\u003enext) {\n-\t\t\t\tfolioq = folioq-\u003enext;\n-\t\t\t\tslot = 0;\n-\t\t\t}\n \t\t}\n-\t}\n+\t} while (nr \u003c maxpages \u0026\u0026 extracted \u003c maxsize);\n \n-\titer-\u003ecount = count;\n-\titer-\u003eiov_offset = iov_offset;\n-\titer-\u003efolioq = folioq;\n-\titer-\u003efolioq_slot = slot;\n+\titer-\u003ebvecq = bvecq;\n+\titer-\u003ebvecq_slot = slot;\n+\titer-\u003eiov_offset = offset;\n+\titer-\u003ecount -= extracted;\n \treturn extracted;\n }\n \n@@ -1140,8 +1292,8 @@ static ssize_t __iov_iter_get_pages_alloc(struct iov_iter *i,\n \t\t}\n \t\treturn maxsize;\n \t}\n-\tif (iov_iter_is_folioq(i))\n-\t\treturn iter_folioq_get_pages(i, pages, maxsize, maxpages, start);\n+\tif (iov_iter_is_bvecq(i))\n+\t\treturn iter_bvecq_get_pages(i, pages, maxsize, maxpages, start);\n \tif (iov_iter_is_xarray(i))\n \t\treturn iter_xarray_get_pages(i, pages, maxsize, maxpages, start);\n \treturn -EFAULT;\n@@ -1212,6 +1364,38 @@ static int bvec_npages(const struct iov_iter *i, int maxpages)\n \treturn npages;\n }\n \n+static size_t iov_npages_bvecq(const struct iov_iter *iter, size_t maxpages)\n+{\n+\tconst struct bvecq *bq;\n+\tunsigned int slot = iter-\u003ebvecq_slot;\n+\tsize_t npages = 0;\n+\tsize_t skip = iter-\u003eiov_offset;\n+\tsize_t size = iter-\u003ecount;\n+\n+\tfor (bq = iter-\u003ebvecq; bq; bq = bq-\u003enext) {\n+\t\tfor (; slot \u003c bq-\u003enr_slots; slot++) {\n+\t\t\tconst struct bio_vec *bvec = \u0026bq-\u003ebv[slot];\n+\t\t\tsize_t offs = (bvec-\u003ebv_offset + skip) % PAGE_SIZE;\n+\t\t\tsize_t part = min(bvec-\u003ebv_len - skip, size);\n+\n+\t\t\tif (part) {\n+\t\t\t\tnpages += DIV_ROUND_UP(offs + part, PAGE_SIZE);\n+\t\t\t\tif (npages \u003e= maxpages)\n+\t\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tsize -= part;\n+\t\t\tif (!size)\n+\t\t\t\tgoto out;\n+\t\t\tskip = 0;\n+\t\t}\n+\n+\t\tslot = 0;\n+\t}\n+out:\n+\treturn umin(npages, maxpages);\n+}\n+\n int iov_iter_npages(const struct iov_iter *i, int maxpages)\n {\n \tif (unlikely(!i-\u003ecount))\n@@ -1226,11 +1410,8 @@ int iov_iter_npages(const struct iov_iter *i, int maxpages)\n \t\treturn iov_npages(i, maxpages);\n \tif (iov_iter_is_bvec(i))\n \t\treturn bvec_npages(i, maxpages);\n-\tif (iov_iter_is_folioq(i)) {\n-\t\tunsigned offset = i-\u003eiov_offset % PAGE_SIZE;\n-\t\tint npages = DIV_ROUND_UP(offset + i-\u003ecount, PAGE_SIZE);\n-\t\treturn min(npages, maxpages);\n-\t}\n+\tif (iov_iter_is_bvecq(i))\n+\t\treturn iov_npages_bvecq(i, maxpages);\n \tif (iov_iter_is_xarray(i)) {\n \t\tunsigned offset = (i-\u003exarray_start + i-\u003eiov_offset) % PAGE_SIZE;\n \t\tint npages = DIV_ROUND_UP(offset + i-\u003ecount, PAGE_SIZE);\n@@ -1515,64 +1696,86 @@ void iov_iter_restore(struct iov_iter *i, struct iov_iter_state *state)\n EXPORT_SYMBOL_FOR_MODULES(iov_iter_restore, \"vmw_vsock_virtio_transport_common\");\n \n /*\n- * Extract a list of contiguous pages from an ITER_FOLIOQ iterator. This does\n- * not get references on the pages, nor does it get a pin on them.\n+ * Extract a list of virtually contiguous pages from an ITER_BVECQ iterator.\n+ * This does not get references on the pages, nor does it get a pin on them.\n */\n-static ssize_t iov_iter_extract_folioq_pages(struct iov_iter *i,\n-\t\t\t\t\t struct page ***pages, size_t maxsize,\n-\t\t\t\t\t unsigned int maxpages,\n-\t\t\t\t\t iov_iter_extraction_t extraction_flags,\n-\t\t\t\t\t size_t *offset0)\n+static ssize_t iov_iter_extract_bvecq_pages(struct iov_iter *iter,\n+\t\t\t\t\t struct page ***pages, size_t maxsize,\n+\t\t\t\t\t unsigned int maxpages,\n+\t\t\t\t\t iov_iter_extraction_t extraction_flags,\n+\t\t\t\t\t size_t *offset0)\n {\n-\tconst struct folio_queue *folioq = i-\u003efolioq;\n+\tconst struct bvecq *bvecq;\n \tstruct page **p;\n-\tunsigned int nr = 0;\n-\tsize_t extracted = 0, offset, slot = i-\u003efolioq_slot;\n+\tunsigned int slot, nr = 0;\n+\tsize_t extracted = 0, offset;\n \n-\tif (slot \u003e= folioq_nr_slots(folioq)) {\n-\t\tfolioq = folioq-\u003enext;\n-\t\tslot = 0;\n-\t\tif (WARN_ON(i-\u003eiov_offset != 0))\n-\t\t\treturn -EIO;\n-\t}\n+\t/* Count the next run of virtually contiguous pages. */\n+\tmaxpages = iter_count_bvecq_pages(iter, maxsize, maxpages);\n+\tif (!maxpages)\n+\t\treturn 0;\n \n-\toffset = i-\u003eiov_offset \u0026 ~PAGE_MASK;\n-\t*offset0 = offset;\n+\tif (!*pages) {\n+\t\t*pages = kvmalloc_array(maxpages, sizeof(struct page *), GFP_KERNEL);\n+\t\tif (!*pages)\n+\t\t\treturn -ENOMEM;\n+\t}\n \n-\tmaxpages = want_pages_array(pages, maxsize, offset, maxpages);\n-\tif (!maxpages)\n-\t\treturn -ENOMEM;\n \tp = *pages;\n \n-\tfor (;;) {\n-\t\tstruct folio *folio = folioq_folio(folioq, slot);\n-\t\tsize_t offset = i-\u003eiov_offset, fsize = folioq_folio_size(folioq, slot);\n-\t\tsize_t part = PAGE_SIZE - offset % PAGE_SIZE;\n-\n-\t\tif (offset \u003c fsize) {\n-\t\t\tpart = umin(part, umin(maxsize - extracted, fsize - offset));\n-\t\t\ti-\u003ecount -= part;\n-\t\t\ti-\u003eiov_offset += part;\n-\t\t\textracted += part;\n+\t/* Now transcribe the page pointers. */\n+\textracted = 0;\n+\tbvecq = iter-\u003ebvecq;\n+\toffset = iter-\u003eiov_offset;\n+\tslot = iter-\u003ebvecq_slot;\n+\n+\tdo {\n+\t\tconst struct bio_vec *bv;\n+\t\tsize_t boff, blen;\n \n-\t\t\tp[nr++] = folio_page(folio, offset / PAGE_SIZE);\n+\t\tif (slot \u003e= bvecq-\u003enr_slots) {\n+\t\t\tif (!bvecq-\u003enext) {\n+\t\t\t\tWARN_ON_ONCE(extracted \u003c iter-\u003ecount);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tbvecq = bvecq-\u003enext;\n+\t\t\tslot = 0;\n+\t\t\toffset = 0;\n+\t\t\tcontinue;\n \t\t}\n \n-\t\tif (nr \u003e= maxpages || extracted \u003e= maxsize)\n-\t\t\tbreak;\n+\t\tbv = \u0026bvecq-\u003ebv[slot];\n+\t\tboff = bv-\u003ebv_offset;\n+\t\tblen = bv-\u003ebv_len;\n \n-\t\tif (i-\u003eiov_offset \u003e= fsize) {\n-\t\t\ti-\u003eiov_offset = 0;\n+\t\t/* bv_page is not allowed to be NULL unless bv_len == 0. */\n+\n+\t\tif (offset \u003c blen) {\n+\t\t\tsize_t part = umin(maxsize - extracted, blen - offset);\n+\t\t\tsize_t poff = (boff + offset) % PAGE_SIZE;\n+\t\t\tsize_t pix = (boff + offset) / PAGE_SIZE;\n+\n+\t\t\tif (poff + part \u003e PAGE_SIZE)\n+\t\t\t\tpart = PAGE_SIZE - poff;\n+\n+\t\t\tif (!extracted)\n+\t\t\t\t*offset0 = poff;\n+\n+\t\t\tp[nr++] = bv-\u003ebv_page + pix;\n+\t\t\toffset += part;\n+\t\t\textracted += part;\n+\t\t}\n+\n+\t\tif (offset \u003e= blen) {\n+\t\t\toffset = 0;\n \t\t\tslot++;\n-\t\t\tif (slot == folioq_nr_slots(folioq) \u0026\u0026 folioq-\u003enext) {\n-\t\t\t\tfolioq = folioq-\u003enext;\n-\t\t\t\tslot = 0;\n-\t\t\t}\n \t\t}\n-\t}\n+\t} while (nr \u003c maxpages \u0026\u0026 extracted \u003c maxsize);\n \n-\ti-\u003efolioq = folioq;\n-\ti-\u003efolioq_slot = slot;\n+\titer-\u003ebvecq = bvecq;\n+\titer-\u003ebvecq_slot = slot;\n+\titer-\u003eiov_offset = offset;\n+\titer-\u003ecount -= extracted;\n \treturn extracted;\n }\n \n@@ -1838,8 +2041,8 @@ static ssize_t iov_iter_extract_user_pages(struct iov_iter *i,\n * added to the pages, but refs will not be taken.\n * iov_iter_extract_will_pin() will return true.\n *\n- * (*) If the iterator is ITER_KVEC, ITER_BVEC, ITER_FOLIOQ or ITER_XARRAY, the\n- * pages are merely listed; no extra refs or pins are obtained.\n+ * (*) If the iterator is ITER_KVEC, ITER_BVEC, ITER_XARRAY, the pages are\n+ * merely listed; no extra refs or pins are obtained.\n * iov_iter_extract_will_pin() will return 0.\n *\n * Note also:\n@@ -1874,10 +2077,10 @@ ssize_t iov_iter_extract_pages(struct iov_iter *i,\n \t\treturn iov_iter_extract_bvec_pages(i, pages, maxsize,\n \t\t\t\t\t\t maxpages, extraction_flags,\n \t\t\t\t\t\t offset0);\n-\tif (iov_iter_is_folioq(i))\n-\t\treturn iov_iter_extract_folioq_pages(i, pages, maxsize,\n-\t\t\t\t\t\t maxpages, extraction_flags,\n-\t\t\t\t\t\t offset0);\n+\tif (iov_iter_is_bvecq(i))\n+\t\treturn iov_iter_extract_bvecq_pages(i, pages, maxsize,\n+\t\t\t\t\t\t maxpages, extraction_flags,\n+\t\t\t\t\t\t offset0);\n \tif (iov_iter_is_xarray(i))\n \t\treturn iov_iter_extract_xarray_pages(i, pages, maxsize,\n \t\t\t\t\t\t maxpages, extraction_flags,\ndiff --git a/lib/scatterlist.c b/lib/scatterlist.c\nindex 6ea40d2e624755..b9a7298306d95d 100644\n--- a/lib/scatterlist.c\n+++ b/lib/scatterlist.c\n@@ -10,8 +10,8 @@\n #include \u003clinux/highmem.h\u003e\n #include \u003clinux/kmemleak.h\u003e\n #include \u003clinux/bvec.h\u003e\n+#include \u003clinux/bvecq.h\u003e\n #include \u003clinux/uio.h\u003e\n-#include \u003clinux/folio_queue.h\u003e\n \n /**\n * sg_nents - return total count of entries in scatterlist\n@@ -1268,61 +1268,59 @@ static ssize_t extract_kvec_to_sg(struct iov_iter *iter,\n }\n \n /*\n- * Extract up to sg_max folios from an FOLIOQ-type iterator and add them to\n+ * Extract up to sg_max folios from an BVECQ-type iterator and add them to\n * the scatterlist. The pages are not pinned.\n */\n-static ssize_t extract_folioq_to_sg(struct iov_iter *iter,\n+static ssize_t extract_bvecq_to_sg(struct iov_iter *iter,\n \t\t\t\t ssize_t maxsize,\n \t\t\t\t struct sg_table *sgtable,\n \t\t\t\t unsigned int sg_max,\n \t\t\t\t iov_iter_extraction_t extraction_flags)\n {\n-\tconst struct folio_queue *folioq = iter-\u003efolioq;\n+\tconst struct bvecq *bvecq = iter-\u003ebvecq;\n \tstruct scatterlist *sg = sgtable-\u003esgl + sgtable-\u003enents;\n-\tunsigned int slot = iter-\u003efolioq_slot;\n+\tunsigned int slot = iter-\u003ebvecq_slot;\n \tssize_t ret = 0;\n \tsize_t offset = iter-\u003eiov_offset;\n \n-\tBUG_ON(!folioq);\n+\tmaxsize = umin(maxsize, iov_iter_count(iter));\n \n-\tif (slot \u003e= folioq_nr_slots(folioq)) {\n-\t\tfolioq = folioq-\u003enext;\n-\t\tif (WARN_ON_ONCE(!folioq))\n-\t\t\treturn 0;\n-\t\tslot = 0;\n-\t}\n-\n-\tdo {\n-\t\tstruct folio *folio = folioq_folio(folioq, slot);\n-\t\tsize_t fsize = folioq_folio_size(folioq, slot);\n+\twhile (sg_max \u003e 0 \u0026\u0026 ret \u003c maxsize) {\n+\t\tconst struct bio_vec *bv;\n+\t\tsize_t blen, part;\n \n-\t\tif (offset \u003c fsize) {\n-\t\t\tsize_t part = umin(maxsize - ret, fsize - offset);\n-\n-\t\t\tsg_set_page(sg, folio_page(folio, 0), part, offset);\n-\t\t\tsgtable-\u003enents++;\n-\t\t\tsg++;\n-\t\t\tsg_max--;\n-\t\t\toffset += part;\n-\t\t\tret += part;\n+\t\tif (slot \u003e= bvecq-\u003enr_slots) {\n+\t\t\tif (!bvecq-\u003enext) {\n+\t\t\t\tWARN_ON_ONCE(ret \u003c iter-\u003ecount);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tbvecq = bvecq-\u003enext;\n+\t\t\tslot = 0;\n+\t\t\toffset = 0;\n+\t\t\tcontinue;\n \t\t}\n \n-\t\tif (offset \u003e= fsize) {\n+\t\tbv = \u0026bvecq-\u003ebv[slot];\n+\t\tblen = bv-\u003ebv_len;\n+\n+\t\tif (offset \u003e= blen) {\n \t\t\toffset = 0;\n \t\t\tslot++;\n-\t\t\tif (slot \u003e= folioq_nr_slots(folioq)) {\n-\t\t\t\tif (!folioq-\u003enext) {\n-\t\t\t\t\tWARN_ON_ONCE(ret \u003c iter-\u003ecount);\n-\t\t\t\t\tbreak;\n-\t\t\t\t}\n-\t\t\t\tfolioq = folioq-\u003enext;\n-\t\t\t\tslot = 0;\n-\t\t\t}\n+\t\t\tcontinue;\n \t\t}\n-\t} while (sg_max \u003e 0 \u0026\u0026 ret \u003c maxsize);\n \n-\titer-\u003efolioq = folioq;\n-\titer-\u003efolioq_slot = slot;\n+\t\tpart = umin(maxsize - ret, blen - offset);\n+\n+\t\tsg_set_page(sg, bv-\u003ebv_page, part, bv-\u003ebv_offset + offset);\n+\t\tsgtable-\u003enents++;\n+\t\tsg++;\n+\t\tsg_max--;\n+\t\toffset += part;\n+\t\tret += part;\n+\t}\n+\n+\titer-\u003ebvecq = bvecq;\n+\titer-\u003ebvecq_slot = slot;\n \titer-\u003eiov_offset = offset;\n \titer-\u003ecount -= ret;\n \treturn ret;\n@@ -1391,8 +1389,8 @@ static ssize_t extract_xarray_to_sg(struct iov_iter *iter,\n * addition of @sg_max elements.\n *\n * The pages referred to by UBUF- and IOVEC-type iterators are extracted and\n- * pinned; BVEC-, KVEC-, FOLIOQ- and XARRAY-type are extracted but aren't\n- * pinned; DISCARD-type is not supported.\n+ * pinned; BVEC-, BVECQ-, KVEC-, XARRAY-type are extracted but aren't pinned;\n+ * DISCARD-type is not supported.\n *\n * No end mark is placed on the scatterlist; that's left to the caller.\n *\n@@ -1424,9 +1422,9 @@ ssize_t extract_iter_to_sg(struct iov_iter *iter, size_t maxsize,\n \tcase ITER_KVEC:\n \t\treturn extract_kvec_to_sg(iter, maxsize, sgtable, sg_max,\n \t\t\t\t\t extraction_flags);\n-\tcase ITER_FOLIOQ:\n-\t\treturn extract_folioq_to_sg(iter, maxsize, sgtable, sg_max,\n-\t\t\t\t\t extraction_flags);\n+\tcase ITER_BVECQ:\n+\t\treturn extract_bvecq_to_sg(iter, maxsize, sgtable, sg_max,\n+\t\t\t\t\t extraction_flags);\n \tcase ITER_XARRAY:\n \t\treturn extract_xarray_to_sg(iter, maxsize, sgtable, sg_max,\n \t\t\t\t\t extraction_flags);\ndiff --git a/lib/tests/Makefile b/lib/tests/Makefile\nindex df0537e1b91faf..85e3c5e1f7d292 100644\n--- a/lib/tests/Makefile\n+++ b/lib/tests/Makefile\n@@ -27,6 +27,7 @@ obj-$(CONFIG_GLOB_KUNIT_TEST) += glob_kunit.o\n obj-$(CONFIG_HASHTABLE_KUNIT_TEST) += hashtable_test.o\n obj-$(CONFIG_HASH_KUNIT_TEST) += test_hash.o\n obj-$(CONFIG_TEST_IOV_ITER) += kunit_iov_iter.o\n+obj-$(CONFIG_TEST_BVECQ) += kunit_bvecq.o\n obj-$(CONFIG_IS_SIGNED_TYPE_KUNIT_TEST) += is_signed_type_kunit.o\n obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o\n obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o\ndiff --git a/lib/tests/kunit_bvecq.c b/lib/tests/kunit_bvecq.c\nnew file mode 100644\nindex 00000000000000..7cdd455df69298\n--- /dev/null\n+++ b/lib/tests/kunit_bvecq.c\n@@ -0,0 +1,599 @@\n+// SPDX-License-Identifier: GPL-2.0-only\n+/* bvecq iterator tests. Exercises:\n+ *\t- advance\n+ *\t- revert\n+ *\t- npages\n+ *\t- alignment\n+ *\n+ * See also kunit_iov_iter.c for bvecq copy and extract tests.\n+ *\n+ * Copyright (C) 2026 Red Hat, Inc. All Rights Reserved.\n+ * Written by David Howells (dhowells@redhat.com)\n+ */\n+\n+#define pr_fmt(fmt) KBUILD_MODNAME \": \" fmt\n+\n+#include \u003clinux/module.h\u003e\n+#include \u003clinux/mm.h\u003e\n+#include \u003clinux/uio.h\u003e\n+#include \u003clinux/bvecq.h\u003e\n+#include \u003ckunit/test.h\u003e\n+\n+MODULE_DESCRIPTION(\"bvecq testing\");\n+MODULE_AUTHOR(\"David Howells \u003cdhowells@redhat.com\u003e\");\n+MODULE_LICENSE(\"GPL\");\n+\n+/*\n+ * Info for the fill pattern generator.\n+ */\n+static const u8 bvecq_kunit_orders[16] = {\n+\t0, 1, 2, 3,\n+\t0, 1, 3, 2,\n+\t0, 2, 1, 3,\n+\t2, 0, 3, 1\n+};\n+\n+static const s8 bvecq_kunit_fills[16] = {\n+\t1, 2, 3, 5, 7, 11, 13, 17,\n+\t-1, -2, -3, -5, -7, -11, -13, -17\n+};\n+static struct folio *bvecq_kunit_folios[16];\n+\n+/*\n+ * Info for the fill pattern predictor.\n+ */\n+struct bvecq_test_pagemap {\n+\tu32 pos;\n+\tu32 offset;\n+\tu8 folio;\n+\tu8 subpage;\n+};\n+\n+static struct bvecq_test_pagemap bvecq_kunit_pagemap[64];\n+static int bvecq_kunit_pagemap_nr;\n+\n+/*\n+ * bvecq assembly recipes.\n+ */\n+enum bvecq_test_cmd {\n+\tBVECQ_KUNIT_STOP,\t/* Stop loading */\n+\tBVECQ_KUNIT_ALLOC,\t/* Append new bvecq of size count and move to it */\n+\tBVECQ_KUNIT_LOAD,\t/* Load count segments into current bvecq */\n+\tBVECQ_KUNIT_EMPTY,\t/* Add count empty segments into current bvecq */\n+} __mode(byte);\n+\n+struct bvecq_test_recipe {\n+\tenum bvecq_test_cmd\tcmd;\n+\tu8\t\t\tcount;\n+};\n+\n+#define ALLOC(C) { .cmd = BVECQ_KUNIT_ALLOC, .count = C }\n+#define LOAD(C) { .cmd = BVECQ_KUNIT_LOAD, .count = C }\n+#define EMPTY(C) { .cmd = BVECQ_KUNIT_EMPTY, .count = C }\n+#define END\t { .cmd = BVECQ_KUNIT_STOP, }\n+\n+static const struct bvecq_test_recipe bvecq_test_recipe_0[] = {\n+\tALLOC(16), LOAD(16),\n+\tEND\n+};\n+\n+static const struct bvecq_test_recipe bvecq_test_recipe_1[] = {\n+\tALLOC(8), LOAD(8),\n+\tALLOC(8), LOAD(8),\n+\tEND\n+};\n+\n+static const struct bvecq_test_recipe bvecq_test_recipe_2[] = {\n+\tALLOC(9), LOAD(8), EMPTY(1),\n+\tALLOC(8), LOAD(8),\n+\tEND\n+};\n+\n+static const struct bvecq_test_recipe bvecq_test_recipe_3[] = {\n+\tALLOC(9), EMPTY(1), LOAD(2), EMPTY(2), LOAD(2), EMPTY(1),\n+\tALLOC(8), LOAD(4), EMPTY(2),\n+\tALLOC(8), EMPTY(1), LOAD(4),\n+\tALLOC(8), EMPTY(2), LOAD(4), EMPTY(1),\n+\tEND\n+};\n+\n+static const struct bvecq_test_recipe bvecq_test_recipe_4[] = {\n+\tALLOC(9), LOAD(2), EMPTY(1),\n+\tALLOC(2),\n+\tALLOC(2), LOAD(2),\n+\tALLOC(2), EMPTY(2),\n+\tALLOC(8), LOAD(8),\n+\tEND\n+};\n+\n+static const struct bvecq_test_recipe bvecq_test_recipe_5[] = {\n+\tALLOC(2),\n+\tALLOC(9), LOAD(2), EMPTY(1),\n+\tALLOC(2),\n+\tALLOC(2), LOAD(2),\n+\tALLOC(2), EMPTY(2),\n+\tALLOC(8), LOAD(8),\n+\tALLOC(2),\n+\tEND\n+};\n+\n+static const struct bvecq_test_recipe bvecq_test_recipe_6[] = {\n+\tALLOC(2), EMPTY(1),\n+\tALLOC(2),\n+\tALLOC(9), LOAD(2), EMPTY(1),\n+\tALLOC(2),\n+\tALLOC(2), LOAD(2),\n+\tALLOC(2), EMPTY(2),\n+\tALLOC(8), LOAD(8),\n+\tALLOC(2),\n+\tALLOC(2), EMPTY(1),\n+\tEND\n+};\n+\n+/*\n+ * Sets of variations of how much of each folio is added to the bvecq chain,\n+ * allowing a part of the folio to be excluded from each end.\n+ */\n+struct bvecq_test_partials {\n+\tu16\tadd_start;\t/* Amount to exclude from the low end */\n+\tu16\tsub_end;\t/* Amount to exclude from the high end */\n+};\n+\n+/* All whole folios. */\n+static const struct bvecq_test_partials bvecq_test_partials_full[16] = {\n+\t[0 ... 15] = { 0, 0 }\n+};\n+\n+/* Scattered partial folios, with some folios contiguous. */\n+static const struct bvecq_test_partials bvecq_test_partials_scattered[16] = {\n+\t//0, 1, 2, 3,\n+\t{ 0x277, 0x136 },\n+\t{ 0x999, 0x1011 },\n+\t{ 0x2020, 0x0 },\n+\t{ 0x0, 0x1123 },\n+\t//0, 1, 3, 2,\n+\t{ 0x0, 0x136 },\n+\t{ 0x27, 0x777 },\n+\t{ 0x771, 0x0 },\n+\t{ 0x555, 0x0 },\n+\t//0, 2, 1, 3,\n+\t{ 0x277, 0x136 },\n+\t{ 0x1123, 0x0 },\n+\t{ 0x0,\t 0x0 },\n+\t{ 0, 0x5011 },\n+\t//2, 0, 3, 1\n+\t{ 0x2020, 0x0 },\n+\t{ 0x277, 0x136 },\n+\t{ 0x1999, 0x1011 },\n+\t{ 0x0, 0x1010 },\n+};\n+\n+/* Partial folios, all with a byte excluded from each end. */\n+static const struct bvecq_test_partials bvecq_test_partials_edges[16] = {\n+\t[0 ... 15] = { 1, 1 }\n+};\n+\n+/*\n+ * Clean up routines.\n+ */\n+static void bvecq_kunit_release_folios(void *data)\n+{\n+\tstruct folio **folios = data;\n+\n+\trelease_pages(folios, ARRAY_SIZE(bvecq_kunit_folios));\n+\tmemset(bvecq_kunit_folios, 0, sizeof(bvecq_kunit_folios));\n+}\n+\n+static void bvecq_kunit_bvecq_put(void *data)\n+{\n+\tbvecq_put(data);\n+}\n+\n+/*\n+ * Calculate the fill pattern, for a particular byte of a particular subpage of\n+ * a particular folio.\n+ */\n+static inline u8 bvecq_kunit_pattern(unsigned int folio, int subpage, int offset)\n+{\n+\tint fill_step = bvecq_kunit_fills[folio];\n+\n+\treturn (subpage + offset * fill_step) \u0026 0xff;\n+}\n+\n+/*\n+ * Calculate the fill pattern, given the 'byte position' in the bvecq chain.\n+ * This looks up the folio, subpage and offset from a table generated whilst\n+ * the bvecq is being assembled.\n+ */\n+static inline u8 bvecq_kunit_predict(struct kunit *test, size_t pos)\n+{\n+\tsize_t last_pos = 0;\n+\n+\tfor (int i = 0; i \u003c bvecq_kunit_pagemap_nr; i++) {\n+\t\tif (pos \u003c bvecq_kunit_pagemap[i].pos)\n+\t\t\treturn bvecq_kunit_pattern(\n+\t\t\t\tbvecq_kunit_pagemap[i].folio,\n+\t\t\t\tbvecq_kunit_pagemap[i].subpage,\n+\t\t\t\tbvecq_kunit_pagemap[i].offset + (pos - last_pos));\n+\t\tlast_pos = bvecq_kunit_pagemap[i].pos;\n+\t}\n+\n+\tKUNIT_FAIL(test, \"Overran pagemap pos=%zx\\n\", pos);\n+\treturn 0;\n+}\n+\n+/*\n+ * Determine which page we're looking at, taking all the folios to be split\n+ * into pages. This can be used to determine what iov_iter_npages() will say.\n+ */\n+static inline int bvecq_kunit_pos2page(struct kunit *test, size_t pos)\n+{\n+\tfor (int i = 0; i \u003c bvecq_kunit_pagemap_nr; i++)\n+\t\tif (pos \u003c bvecq_kunit_pagemap[i].pos)\n+\t\t\treturn i;\n+\n+\tif (pos \u003e bvecq_kunit_pagemap[bvecq_kunit_pagemap_nr - 1].pos)\n+\t\tKUNIT_FAIL(test, \"Overran pagemap pos=%zx\\n\", pos);\n+\treturn bvecq_kunit_pagemap_nr;\n+}\n+\n+/*\n+ * Allocate a variety of folios of different orders and fill them with the\n+ * pattern set for each folio.\n+ */\n+static void __init iov_bvecq_alloc_folios(struct kunit *test)\n+{\n+\tstruct folio *folio, **folios = bvecq_kunit_folios;\n+\tconst int nr = ARRAY_SIZE(bvecq_kunit_folios);\n+\n+\tbvecq_kunit_pagemap_nr = 0;\n+\tmemset(bvecq_kunit_pagemap, 0, sizeof(bvecq_kunit_pagemap));\n+\tmemset(bvecq_kunit_folios, 0, sizeof(bvecq_kunit_folios));\n+\n+\tfor (int i = 0; i \u003c nr; i++) {\n+\t\tfolio = folio_alloc(GFP_KERNEL, bvecq_kunit_orders[i]);\n+\t\tKUNIT_ASSERT_NOT_NULL(test, folio);\n+\t\tfolios[i] = folio;\n+\n+\t\t/* Fill each subpage with a different but predictable pattern. */\n+\t\tfor (int j = 0; j \u003c folio_nr_pages(folio); j++) {\n+\t\t\tu8 *p = kmap_local_folio(folio, PAGE_SIZE * j);\n+\n+\t\t\tfor (int k = 0; k \u003c PAGE_SIZE; k++)\n+\t\t\t\tp[k] = bvecq_kunit_pattern(i, j, k);\n+\t\t\tkunmap_local(p);\n+\t\t}\n+\t}\n+\n+\tkunit_add_action_or_reset(test, bvecq_kunit_release_folios, folios);\n+}\n+\n+/*\n+ * Follow the specified recipe to allocate a bvecq chain and stick the folios\n+ * and empty gaps into it. Further, the offset into and length of each folio\n+ * is adjusted from the partials list. Each ALLOC command will append a new\n+ * bvecq to the chain and move to filling that.\n+ */\n+static struct bvecq *__init bvecq_kunit_load_chain(\n+\tstruct kunit *test,\n+\tconst struct bvecq_test_recipe *rec,\n+\tconst struct bvecq_test_partials *parts,\n+\tsize_t *size)\n+{\n+\tstruct bvecq *head = NULL, *bq = NULL, *p;\n+\tsize_t pos = 0;\n+\tint folio_index = 0;\n+\n+\t*size = 0;\n+\n+\tfor (; rec-\u003ecmd != BVECQ_KUNIT_STOP; rec++) {\n+\t\tif (!head)\n+\t\t\tKUNIT_ASSERT_EQ(test, rec-\u003ecmd, BVECQ_KUNIT_ALLOC);\n+\n+\t\tswitch (rec-\u003ecmd) {\n+\t\tcase BVECQ_KUNIT_STOP:\n+\t\t\tbreak;\n+\n+\t\tcase BVECQ_KUNIT_ALLOC:\n+\t\t\tp = bvecq_alloc_one(rec-\u003ecount, GFP_KERNEL, false);\n+\t\t\tKUNIT_ASSERT_NOT_NULL(test, p);\n+\n+\t\t\tif (!head) {\n+\t\t\t\thead = p;\n+\t\t\t\tkunit_add_action_or_reset(test, bvecq_kunit_bvecq_put, head);\n+\t\t\t\tbq = p;\n+\t\t\t} else {\n+\t\t\t\tbvecq_append(bq, p);\n+\t\t\t\tbq = p;\n+\t\t\t}\n+\t\t\tbreak;\n+\n+\t\tcase BVECQ_KUNIT_LOAD:\n+\t\t\tKUNIT_ASSERT_LE(test, folio_index + rec-\u003ecount,\n+\t\t\t\t\tARRAY_SIZE(bvecq_kunit_orders));\n+\t\t\tKUNIT_ASSERT_LE(test, bq-\u003enr_slots + rec-\u003ecount, bq-\u003emax_slots);\n+\t\t\tfor (int i = 0; i \u003c rec-\u003ecount; i++) {\n+\t\t\t\tstruct folio *folio = bvecq_kunit_folios[folio_index];\n+\t\t\t\tsize_t flen = PAGE_SIZE \u003c\u003c bvecq_kunit_orders[folio_index];\n+\t\t\t\tsize_t foff = 0;\n+\n+\t\t\t\tKUNIT_ASSERT_LE(test,\n+\t\t\t\t\t\tparts[folio_index].add_start +\n+\t\t\t\t\t\tparts[folio_index].sub_end,\n+\t\t\t\t\t\tflen);\n+\n+\t\t\t\tfoff += parts[folio_index].add_start;\n+\t\t\t\tflen -= parts[folio_index].add_start;\n+\t\t\t\tflen -= parts[folio_index].sub_end;\n+\n+\t\t\t\tbvec_set_page(\u0026bq-\u003ebv[bq-\u003enr_slots + i],\n+\t\t\t\t\t folio_page(folio, 0), flen, foff);\n+\t\t\t\t*size += flen;\n+\n+\t\t\t\tfor (int j = 0; j \u003c folio_nr_pages(folio); j++) {\n+\t\t\t\t\tstruct bvecq_test_pagemap *pm;\n+\t\t\t\t\tsize_t part;\n+\n+\t\t\t\t\tif (foff \u003e= PAGE_SIZE) {\n+\t\t\t\t\t\tfoff -= PAGE_SIZE;\n+\t\t\t\t\t\tcontinue;\n+\t\t\t\t\t}\n+\t\t\t\t\tpart = min(flen, PAGE_SIZE - foff);\n+\t\t\t\t\tpos += part;\n+\t\t\t\t\tpm = \u0026bvecq_kunit_pagemap[bvecq_kunit_pagemap_nr];\n+\t\t\t\t\tpm-\u003epos = pos;\n+\t\t\t\t\tpm-\u003efolio = folio_index;\n+\t\t\t\t\tpm-\u003esubpage = j;\n+\t\t\t\t\tpm-\u003eoffset = foff;\n+\t\t\t\t\tbvecq_kunit_pagemap_nr++;\n+\t\t\t\t\tflen -= part;\n+\t\t\t\t\tif (!flen)\n+\t\t\t\t\t\tbreak;\n+\t\t\t\t\tfoff = 0;\n+\t\t\t\t}\n+\n+\t\t\t\tfolio_index++;\n+\t\t\t}\n+\t\t\tbvecq_filled_to(bq, bq-\u003enr_slots + rec-\u003ecount);\n+\t\t\tbreak;\n+\n+\t\tcase BVECQ_KUNIT_EMPTY:\n+\t\t\tKUNIT_ASSERT_LE(test, bq-\u003enr_slots + rec-\u003ecount, bq-\u003emax_slots);\n+\t\t\tfor (int i = 0; i \u003c rec-\u003ecount; i++) {\n+\t\t\t\tbq-\u003ebv[bq-\u003enr_slots + i].bv_page = ERR_PTR(-EIO);\n+\t\t\t\tbq-\u003ebv[bq-\u003enr_slots + i].bv_offset = 0;\n+\t\t\t\tbq-\u003ebv[bq-\u003enr_slots + i].bv_len = 0;\n+\t\t\t}\n+\t\t\tbvecq_filled_to(bq, bq-\u003enr_slots + rec-\u003ecount);\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\treturn head;\n+}\n+\n+/*\n+ * Check the next few bytes of pattern from an iterator. Note that it is\n+ * permitted for the iterator to have less data remaining than the number to\n+ * check - in which case the copy is required to come up short.\n+ */\n+static void __init bvecq_kunit_check_next(struct kunit *test, struct iov_iter *iter,\n+\t\t\t\t\t size_t *pos, size_t *left, size_t nr)\n+{\n+\tsize_t part, n;\n+\tu8 buf[3], pred[3];\n+\n+\tKUNIT_ASSERT_EQ(test, iov_iter_count(iter), *left);\n+\n+\tpart = min(*left, nr);\n+\tn = copy_from_iter(buf, nr, iter);\n+\tKUNIT_ASSERT_EQ(test, n, part);\n+\t*left -= n;\n+\n+\tfor (size_t i = 0; i \u003c n; i++)\n+\t\tpred[i] = bvecq_kunit_predict(test, *pos + i);\n+\n+\tfor (size_t i = 0; i \u003c n; i++) {\n+\t\tif (buf[i] != pred[i]) {\n+\t\t\tpr_notice(\"\u003e\u003e\u003e pos=%05zx+%zx c=%zx buf=%*phN pred=%*phN\\n\",\n+\t\t\t\t *pos, i, iov_iter_count(iter) + n,\n+\t\t\t\t (int)n, buf, (int)n, pred);\n+\t\t}\n+\t\tKUNIT_ASSERT_EQ(test, buf[i], pred[i]);\n+\t}\n+\n+\t*pos += n;\n+}\n+\n+/*\n+ * Test advancing and reverting over a bvecq chain.\n+ *\n+ * The loop starts at each 'byte position' in the chain, advancing a small\n+ * amount, copying a few bytes of data, checking the fill pattern, reverting a\n+ * bit, checking, reverting, checking and then reverting to a byte position one\n+ * further on than the previous loop. Use small prime numbers for the advance\n+ * and first revert so that we should test crossing the edges of the folios.\n+ */\n+static void __init bvecq_kunit_advance(struct kunit *test,\n+\t\t\t\t const struct bvecq_test_recipe *recipe,\n+\t\t\t\t const struct bvecq_test_partials *parts)\n+{\n+\tstruct iov_iter iter;\n+\tstruct bvecq *bq, *p;\n+\tunsigned long bvec_align = 0;\n+\tsize_t size, pos = 0, from;\n+\tint npages;\n+\n+\tiov_bvecq_alloc_folios(test);\n+\tbq = bvecq_kunit_load_chain(test, recipe, parts, \u0026size);\n+\n+\t/* Compound up the alignments for ITER_BVEC on each individual bvecq\n+\t * span and compare that to the alignment for ITER_BVECQ. There is an\n+\t * issue in ITER_BVEC, however, in that it includes bv_offset from\n+\t * bio_vecs for which bv_len is 0, which ITER_BVECQ does not.\n+\t */\n+\tfor (p = bq; p; p = p-\u003enext) {\n+\t\tsize_t psize = 0;\n+\n+\t\tfor (int i = 0; i \u003c p-\u003enr_slots; i++)\n+\t\t\tpsize += p-\u003ebv[i].bv_len;\n+\n+\t\tif (!psize)\n+\t\t\tcontinue;\n+\t\tiov_iter_bvec(\u0026iter, ITER_SOURCE, p-\u003ebv, p-\u003enr_slots, psize);\n+\t\tbvec_align |= iov_iter_alignment(\u0026iter);\n+\t}\n+\n+\tiov_iter_bvec_queue(\u0026iter, ITER_SOURCE, bq, 0, 0, size);\n+\n+\tKUNIT_ASSERT_EQ(test, iov_iter_alignment(\u0026iter), bvec_align);\n+\n+\tnpages = iov_iter_npages(\u0026iter, INT_MAX);\n+\tfrom = iov_iter_count(\u0026iter);\n+\tdo {\n+\t\tsize_t left = from, part;\n+\n+\t\tKUNIT_ASSERT_EQ(test, iov_iter_npages(\u0026iter, INT_MAX),\n+\t\t\t\tnpages - bvecq_kunit_pos2page(test, pos));\n+\n+\t\t/* 3 steps forward. */\n+\t\tpart = min(left, 3);\n+\t\tiov_iter_advance(\u0026iter, 3); /* May be short. */\n+\t\tpos += part;\n+\t\tleft -= part;\n+\t\tbvecq_kunit_check_next(test, \u0026iter, \u0026pos, \u0026left, 3);\n+\n+\t\t/* 2 steps back */\n+\t\tpart = umin(2, left);\n+\t\tiov_iter_revert(\u0026iter, part);\n+\t\tpos -= part;\n+\t\tleft += part;\n+\t\tbvecq_kunit_check_next(test, \u0026iter, \u0026pos, \u0026left, 2);\n+\n+\t\t/* 1 more step back */\n+\t\tpart = umin(1, left);\n+\t\tiov_iter_revert(\u0026iter, part);\n+\t\tpos -= part;\n+\t\tleft += part;\n+\t\tbvecq_kunit_check_next(test, \u0026iter, \u0026pos, \u0026left, 1);\n+\n+\t\tKUNIT_ASSERT_EQ(test, left, iov_iter_count(\u0026iter));\n+\n+\t\t/* Move to one place on from the current loop. */\n+\t\tfrom--;\n+\t\tif (iov_iter_count(\u0026iter) \u003c from) {\n+\t\t\tpart = from - iov_iter_count(\u0026iter);\n+\t\t\tiov_iter_revert(\u0026iter, part);\n+\t\t\tpos -= part;\n+\t\t}\n+\t\tKUNIT_ASSERT_EQ(test, from, iov_iter_count(\u0026iter));\n+\t} while (from \u003e 0);\n+}\n+\n+/*\n+ * Test jumping around in a bvecq chain using advance and revert.\n+ *\n+ * The loop starts at the start of the chain, then jumps forwards through the\n+ * chain and then back again by large amounts, sampling the data each time.\n+ */\n+static void __init bvecq_kunit_jump(struct kunit *test,\n+\t\t\t\t const struct bvecq_test_recipe *recipe,\n+\t\t\t\t const struct bvecq_test_partials *parts)\n+{\n+\tstruct iov_iter iter;\n+\tstruct bvecq *bq;\n+\tsize_t size, pos = 0, step = 0x100;\n+\tbool dir = false;\n+\tint npages;\n+\n+\tiov_bvecq_alloc_folios(test);\n+\tbq = bvecq_kunit_load_chain(test, recipe, parts, \u0026size);\n+\n+\tiov_iter_bvec_queue(\u0026iter, ITER_SOURCE, bq, 0, 0, size);\n+\n+\tnpages = iov_iter_npages(\u0026iter, INT_MAX);\n+\twhile (step \u003c size) {\n+\t\tsize_t left = iov_iter_count(\u0026iter), part;\n+\n+\t\tKUNIT_ASSERT_EQ(test, iov_iter_npages(\u0026iter, INT_MAX),\n+\t\t\t\tnpages - bvecq_kunit_pos2page(test, pos));\n+\n+\t\tif (!dir) {\n+\t\t\t/* Advance by step and then 3 more in check. */\n+\t\t\tpart = min(left, step);\n+\t\t\tiov_iter_advance(\u0026iter, step); /* May be short. */\n+\t\t\tpos += part;\n+\t\t\tleft -= part;\n+\t\t\tbvecq_kunit_check_next(test, \u0026iter, \u0026pos, \u0026left, 3);\n+\n+\t\t\tKUNIT_ASSERT_EQ(test, left, iov_iter_count(\u0026iter));\n+\n+\t\t\tif (left == 0) {\n+\t\t\t\t/* Switch to reverting. */\n+\t\t\t\tdir = true;\n+\t\t\t\tstep += 3;\n+\t\t\t}\n+\t\t} else {\n+\t\t\t/* Revert by step and then advance by 3 in check. */\n+\t\t\tpart = min(size - left, step);\n+\t\t\tiov_iter_revert(\u0026iter, part);\n+\t\t\tpos -= part;\n+\t\t\tleft += part;\n+\t\t\tbvecq_kunit_check_next(test, \u0026iter, \u0026pos, \u0026left, 3);\n+\n+\t\t\tKUNIT_ASSERT_EQ(test, left, iov_iter_count(\u0026iter));\n+\n+\t\t\tif (pos \u003c= 3) {\n+\t\t\t\t/* Switch to advancing. */\n+\t\t\t\tdir = false;\n+\t\t\t\tstep *= 2;\n+\t\t\t}\n+\t\t}\n+\t}\n+}\n+\n+/*\n+ * Run the individual test combinations\n+ */\n+#define ADVANCE_TESTS_SET(CHECK, PARTIALS) \\\n+\tTEST(CHECK, PARTIALS, 0)\t\\\n+\tTEST(CHECK, PARTIALS, 1)\t\\\n+\tTEST(CHECK, PARTIALS, 2)\t\\\n+\tTEST(CHECK, PARTIALS, 3)\t\\\n+\tTEST(CHECK, PARTIALS, 4)\t\\\n+\tTEST(CHECK, PARTIALS, 5)\t\\\n+\tTEST(CHECK, PARTIALS, 6)\n+\n+#define ADVANCE_TESTS(CHECK)\t\t\t\\\n+\tADVANCE_TESTS_SET(CHECK, full)\t\t\\\n+\tADVANCE_TESTS_SET(CHECK, scattered)\t\\\n+\tADVANCE_TESTS_SET(CHECK, edges)\n+\n+#define TEST(CHECK, PARTIALS, RECIPE) \\\n+static void __init bvecq_kunit_##CHECK##_##PARTIALS##_##RECIPE(struct kunit *test) \\\n+{ \\\n+\tbvecq_kunit_##CHECK(test, \\\n+\t\t\t bvecq_test_recipe_##RECIPE,\t \\\n+\t\t\t bvecq_test_partials_##PARTIALS); \\\n+}\n+\n+/* Emit test stub functions. */\n+ADVANCE_TESTS(advance);\n+ADVANCE_TESTS(jump);\n+#undef TEST\n+\n+#define TEST(CHECK, PARTIALS, RECIPE)\t\t\t\t\\\n+\tKUNIT_CASE(bvecq_kunit_##CHECK##_##PARTIALS##_##RECIPE),\n+\n+static struct kunit_case __refdata bvecq_kunit_cases[] = {\n+\tADVANCE_TESTS(advance)\n+\tADVANCE_TESTS(jump)\n+\t{}\n+};\n+\n+static struct kunit_suite bvecq_kunit_suite = {\n+\t.name = \"bvecq\",\n+\t.test_cases = bvecq_kunit_cases,\n+};\n+\n+kunit_test_suites(\u0026bvecq_kunit_suite);\ndiff --git a/lib/tests/kunit_iov_iter.c b/lib/tests/kunit_iov_iter.c\nindex 32e42d8c7ca13e..19fc082e4cf3da 100644\n--- a/lib/tests/kunit_iov_iter.c\n+++ b/lib/tests/kunit_iov_iter.c\n@@ -12,7 +12,7 @@\n #include \u003clinux/mm.h\u003e\n #include \u003clinux/uio.h\u003e\n #include \u003clinux/bvec.h\u003e\n-#include \u003clinux/folio_queue.h\u003e\n+#include \u003clinux/bvecq.h\u003e\n #include \u003clinux/scatterlist.h\u003e\n #include \u003clinux/minmax.h\u003e\n #include \u003clinux/mman.h\u003e\n@@ -382,58 +382,67 @@ static void __init iov_kunit_copy_from_bvec(struct kunit *test)\n \tKUNIT_SUCCEED(test);\n }\n \n-static void iov_kunit_destroy_folioq(void *data)\n+static void iov_kunit_destroy_bvecq(void *data)\n {\n-\tstruct folio_queue *folioq, *next;\n+\tstruct bvecq *bq, *next;\n \n-\tfor (folioq = data; folioq; folioq = next) {\n-\t\tnext = folioq-\u003enext;\n-\t\tkfree(folioq);\n+\tfor (bq = data; bq; bq = next) {\n+\t\tnext = bq-\u003enext;\n+\t\t/* The pages are freed by vmap with VM_MAP_PUT_PAGES. */\n+\t\tkfree(bq);\n \t}\n }\n \n-static void __init iov_kunit_load_folioq(struct kunit *test,\n+static struct bvecq *iov_kunit_alloc_bvecq(struct kunit *test, unsigned int max_slots)\n+{\n+\tstruct bvecq *bq;\n+\n+\tbq = kzalloc(struct_size(bq, __bv, max_slots), GFP_KERNEL);\n+\tKUNIT_ASSERT_NOT_ERR_OR_NULL(test, bq);\n+\tbq-\u003emax_slots = max_slots;\n+\tbq-\u003ebv = bq-\u003e__bv;\n+\tbq-\u003einline_bv = true;\n+\treturn bq;\n+}\n+\n+static struct bvecq *iov_kunit_create_bvecq(struct kunit *test, unsigned int max_slots)\n+{\n+\tstruct bvecq *bq;\n+\n+\tbq = iov_kunit_alloc_bvecq(test, max_slots);\n+\tkunit_add_action_or_reset(test, iov_kunit_destroy_bvecq, bq);\n+\treturn bq;\n+}\n+\n+static void __init iov_kunit_load_bvecq(struct kunit *test,\n \t\t\t\t\tstruct iov_iter *iter, int dir,\n-\t\t\t\t\tstruct folio_queue *folioq,\n+\t\t\t\t\tstruct bvecq *bq_head,\n \t\t\t\t\tstruct page **pages, size_t npages)\n {\n-\tstruct folio_queue *p = folioq;\n+\tstruct bvecq *bq = bq_head;\n \tsize_t size = 0;\n-\tint i;\n \n-\tfor (i = 0; i \u003c npages; i++) {\n-\t\tif (folioq_full(p)) {\n-\t\t\tp-\u003enext = kzalloc_obj(struct folio_queue);\n-\t\t\tKUNIT_ASSERT_NOT_ERR_OR_NULL(test, p-\u003enext);\n-\t\t\tfolioq_init(p-\u003enext, 0);\n-\t\t\tp-\u003enext-\u003eprev = p;\n-\t\t\tp = p-\u003enext;\n+\tfor (int i = 0; i \u003c npages; i++) {\n+\t\tif (bq-\u003enr_slots \u003e= bq-\u003emax_slots) {\n+\t\t\tbq-\u003enext = iov_kunit_alloc_bvecq(test, 13);\n+\t\t\tbq-\u003enext-\u003eprev = bq;\n+\t\t\tbq = bq-\u003enext;\n \t\t}\n-\t\tfolioq_append(p, page_folio(pages[i]));\n+\t\tbvec_set_page(\u0026bq-\u003ebv[bq-\u003enr_slots], pages[i], PAGE_SIZE, 0);\n+\t\tbq-\u003enr_slots++;\n \t\tsize += PAGE_SIZE;\n \t}\n-\tiov_iter_folio_queue(iter, dir, folioq, 0, 0, size);\n-}\n-\n-static struct folio_queue *iov_kunit_create_folioq(struct kunit *test)\n-{\n-\tstruct folio_queue *folioq;\n-\n-\tfolioq = kzalloc_obj(struct folio_queue);\n-\tKUNIT_ASSERT_NOT_ERR_OR_NULL(test, folioq);\n-\tkunit_add_action_or_reset(test, iov_kunit_destroy_folioq, folioq);\n-\tfolioq_init(folioq, 0);\n-\treturn folioq;\n+\tiov_iter_bvec_queue(iter, dir, bq_head, 0, 0, size);\n }\n \n /*\n- * Test copying to a ITER_FOLIOQ-type iterator.\n+ * Test copying to a ITER_BVECQ-type iterator.\n */\n-static void __init iov_kunit_copy_to_folioq(struct kunit *test)\n+static void __init iov_kunit_copy_to_bvecq(struct kunit *test)\n {\n \tconst struct kvec_test_range *pr;\n \tstruct iov_iter iter;\n-\tstruct folio_queue *folioq;\n+\tstruct bvecq *bq;\n \tstruct page **spages, **bpages;\n \tu8 *scratch, *buffer;\n \tsize_t bufsize, npages, size, copied;\n@@ -442,7 +451,7 @@ static void __init iov_kunit_copy_to_folioq(struct kunit *test)\n \tbufsize = 0x100000;\n \tnpages = bufsize / PAGE_SIZE;\n \n-\tfolioq = iov_kunit_create_folioq(test);\n+\tbq = iov_kunit_create_bvecq(test, 13);\n \n \tscratch = iov_kunit_create_buffer(test, \u0026spages, npages);\n \tfor (i = 0; i \u003c bufsize; i++)\n@@ -451,20 +460,19 @@ static void __init iov_kunit_copy_to_folioq(struct kunit *test)\n \tbuffer = iov_kunit_create_buffer(test, \u0026bpages, npages);\n \tmemset(buffer, 0, bufsize);\n \n-\tiov_kunit_load_folioq(test, \u0026iter, READ, folioq, bpages, npages);\n+\tiov_kunit_load_bvecq(test, \u0026iter, READ, bq, bpages, npages);\n \n \ti = 0;\n \tfor (pr = kvec_test_ranges; pr-\u003efrom \u003e= 0; pr++) {\n \t\tsize = pr-\u003eto - pr-\u003efrom;\n \t\tKUNIT_ASSERT_LE(test, pr-\u003eto, bufsize);\n \n-\t\tiov_iter_folio_queue(\u0026iter, READ, folioq, 0, 0, pr-\u003eto);\n+\t\tiov_iter_bvec_queue(\u0026iter, READ, bq, 0, 0, pr-\u003eto);\n \t\tiov_iter_advance(\u0026iter, pr-\u003efrom);\n \t\tcopied = copy_to_iter(scratch + i, size, \u0026iter);\n \n \t\tKUNIT_EXPECT_EQ(test, copied, size);\n \t\tKUNIT_EXPECT_EQ(test, iter.count, 0);\n-\t\tKUNIT_EXPECT_EQ(test, iter.iov_offset, pr-\u003eto % PAGE_SIZE);\n \t\ti += size;\n \t\tif (test-\u003estatus == KUNIT_FAILURE)\n \t\t\tgoto stop;\n@@ -489,13 +497,13 @@ static void __init iov_kunit_copy_to_folioq(struct kunit *test)\n }\n \n /*\n- * Test copying from a ITER_FOLIOQ-type iterator.\n+ * Test copying from a ITER_BVECQ-type iterator.\n */\n-static void __init iov_kunit_copy_from_folioq(struct kunit *test)\n+static void __init iov_kunit_copy_from_bvecq(struct kunit *test)\n {\n \tconst struct kvec_test_range *pr;\n \tstruct iov_iter iter;\n-\tstruct folio_queue *folioq;\n+\tstruct bvecq *bq;\n \tstruct page **spages, **bpages;\n \tu8 *scratch, *buffer;\n \tsize_t bufsize, npages, size, copied;\n@@ -504,7 +512,7 @@ static void __init iov_kunit_copy_from_folioq(struct kunit *test)\n \tbufsize = 0x100000;\n \tnpages = bufsize / PAGE_SIZE;\n \n-\tfolioq = iov_kunit_create_folioq(test);\n+\tbq = iov_kunit_create_bvecq(test, 13);\n \n \tbuffer = iov_kunit_create_buffer(test, \u0026bpages, npages);\n \tfor (i = 0; i \u003c bufsize; i++)\n@@ -513,20 +521,19 @@ static void __init iov_kunit_copy_from_folioq(struct kunit *test)\n \tscratch = iov_kunit_create_buffer(test, \u0026spages, npages);\n \tmemset(scratch, 0, bufsize);\n \n-\tiov_kunit_load_folioq(test, \u0026iter, READ, folioq, bpages, npages);\n+\tiov_kunit_load_bvecq(test, \u0026iter, READ, bq, bpages, npages);\n \n \ti = 0;\n \tfor (pr = kvec_test_ranges; pr-\u003efrom \u003e= 0; pr++) {\n \t\tsize = pr-\u003eto - pr-\u003efrom;\n \t\tKUNIT_ASSERT_LE(test, pr-\u003eto, bufsize);\n \n-\t\tiov_iter_folio_queue(\u0026iter, WRITE, folioq, 0, 0, pr-\u003eto);\n+\t\tiov_iter_bvec_queue(\u0026iter, WRITE, bq, 0, 0, pr-\u003eto);\n \t\tiov_iter_advance(\u0026iter, pr-\u003efrom);\n \t\tcopied = copy_from_iter(scratch + i, size, \u0026iter);\n \n \t\tKUNIT_EXPECT_EQ(test, copied, size);\n \t\tKUNIT_EXPECT_EQ(test, iter.count, 0);\n-\t\tKUNIT_EXPECT_EQ(test, iter.iov_offset, pr-\u003eto % PAGE_SIZE);\n \t\ti += size;\n \t}\n \n@@ -868,13 +875,13 @@ static void __init iov_kunit_extract_pages_bvec(struct kunit *test)\n }\n \n /*\n- * Test the extraction of ITER_FOLIOQ-type iterators.\n+ * Test the extraction of ITER_BVECQ-type iterators.\n */\n-static void __init iov_kunit_extract_pages_folioq(struct kunit *test)\n+static void __init iov_kunit_extract_pages_bvecq(struct kunit *test)\n {\n \tconst struct kvec_test_range *pr;\n-\tstruct folio_queue *folioq;\n \tstruct iov_iter iter;\n+\tstruct bvecq *bq;\n \tstruct page **bpages, *pagelist[8], **pages = pagelist;\n \tssize_t len;\n \tsize_t bufsize, size = 0, npages;\n@@ -883,17 +890,17 @@ static void __init iov_kunit_extract_pages_folioq(struct kunit *test)\n \tbufsize = 0x100000;\n \tnpages = bufsize / PAGE_SIZE;\n \n-\tfolioq = iov_kunit_create_folioq(test);\n+\tbq = iov_kunit_create_bvecq(test, 13);\n \n \tiov_kunit_create_buffer(test, \u0026bpages, npages);\n-\tiov_kunit_load_folioq(test, \u0026iter, READ, folioq, bpages, npages);\n+\tiov_kunit_load_bvecq(test, \u0026iter, READ, bq, bpages, npages);\n \n \tfor (pr = kvec_test_ranges; pr-\u003efrom \u003e= 0; pr++) {\n \t\tfrom = pr-\u003efrom;\n \t\tsize = pr-\u003eto - from;\n \t\tKUNIT_ASSERT_LE(test, pr-\u003eto, bufsize);\n \n-\t\tiov_iter_folio_queue(\u0026iter, WRITE, folioq, 0, 0, pr-\u003eto);\n+\t\tiov_iter_bvec_queue(\u0026iter, WRITE, bq, 0, 0, pr-\u003eto);\n \t\tiov_iter_advance(\u0026iter, from);\n \n \t\tdo {\n@@ -1173,19 +1180,18 @@ static void __init iov_kunit_iter_to_sg_bvec(struct kunit *test)\n \tiov_kunit_iter_to_sg_check(test, \u0026iter, bufsize, \u0026data);\n }\n \n-static void __init iov_kunit_iter_to_sg_folioq(struct kunit *test)\n+static void __init iov_kunit_iter_to_sg_bvecq(struct kunit *test)\n {\n \tstruct iov_kunit_iter_to_sg_data data;\n-\tstruct folio_queue *folioq;\n \tstruct iov_iter iter;\n+\tstruct bvecq *bq;\n \tsize_t bufsize;\n \n \tbufsize = 0x200000;\n \tiov_kunit_iter_to_sg_init(test, bufsize, false, \u0026data);\n \n-\tfolioq = iov_kunit_create_folioq(test);\n-\tiov_kunit_load_folioq(test, \u0026iter, READ, folioq, data.pages,\n-\t\t\t data.npages);\n+\tbq = iov_kunit_create_bvecq(test, 13);\n+\tiov_kunit_load_bvecq(test, \u0026iter, READ, bq, data.pages, data.npages);\n \n \tiov_kunit_iter_to_sg_check(test, \u0026iter, bufsize, \u0026data);\n }\n@@ -1226,17 +1232,17 @@ static struct kunit_case __refdata iov_kunit_cases[] = {\n \tKUNIT_CASE(iov_kunit_copy_from_kvec),\n \tKUNIT_CASE(iov_kunit_copy_to_bvec),\n \tKUNIT_CASE(iov_kunit_copy_from_bvec),\n-\tKUNIT_CASE(iov_kunit_copy_to_folioq),\n-\tKUNIT_CASE(iov_kunit_copy_from_folioq),\n+\tKUNIT_CASE(iov_kunit_copy_to_bvecq),\n+\tKUNIT_CASE(iov_kunit_copy_from_bvecq),\n \tKUNIT_CASE(iov_kunit_copy_to_xarray),\n \tKUNIT_CASE(iov_kunit_copy_from_xarray),\n \tKUNIT_CASE(iov_kunit_extract_pages_kvec),\n \tKUNIT_CASE(iov_kunit_extract_pages_bvec),\n-\tKUNIT_CASE(iov_kunit_extract_pages_folioq),\n+\tKUNIT_CASE(iov_kunit_extract_pages_bvecq),\n \tKUNIT_CASE(iov_kunit_extract_pages_xarray),\n \tKUNIT_CASE(iov_kunit_iter_to_sg_kvec),\n \tKUNIT_CASE(iov_kunit_iter_to_sg_bvec),\n-\tKUNIT_CASE(iov_kunit_iter_to_sg_folioq),\n+\tKUNIT_CASE(iov_kunit_iter_to_sg_bvecq),\n \tKUNIT_CASE(iov_kunit_iter_to_sg_xarray),\n \tKUNIT_CASE(iov_kunit_iter_to_sg_ubuf),\n \t{}\n"
} |
| 2/1 | 2026/11/10 17:50 | agent | patch-evaluator |
16mModel:core Args: null Results: {
"EnableConfigs": [
"NETFS_SUPPORT",
"AFS_FS",
"CIFS",
"FSCACHE",
"AFS_FSCACHE",
"9P_FS"
],
"FocusSymbols": [
"bvecq_alloc_one",
"bvecq_alloc_chain",
"bvecq_alloc_buffer2",
"bvecq_put",
"bvecq_expand_buffer",
"iov_iter_bvec_queue",
"rolling_buffer_init",
"rolling_buffer_make_space",
"rolling_buffer_bulk_load_from_ra",
"rolling_buffer_append",
"rolling_buffer_delete_spent",
"netfs_writeback_single",
"netfs_read_unlock_folios",
"netfs_writeback_unlock_folios",
"netfs_limit_iter",
"afs_dir_get_block",
"afs_dir_find_block",
"afs_symlink_writepages"
],
"Reasoning": "The patch series replaces the folio_queue abstraction with bvecq (segmented bio_vec queue) across netfs, iov_iter, scatterlist, afs, and smb/cifs. It introduces new memory management, refcounting, and queue manipulation helpers (bvecq_*), reworks rolling buffer management in netfs, modifies iteration and extraction primitives in lib/iov_iter.c, and updates read/write collection and directory/symlink handling in afs and cifs. These are reachable core and filesystem code paths that warrant fuzzing.",
"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 fdcfc8440281f97bfd03cc621cb873b3b7b135ac
Author: syz-cluster <triage@syzkaller.com>
Date: Tue Nov 10 17:50:40 2026 +0000
syz-cluster: applied patch under review
diff --git a/Documentation/core-api/bvecq.rst b/Documentation/core-api/bvecq.rst
new file mode 100644
index 00000000000000..4a2b3e28898220
--- /dev/null
+++ b/Documentation/core-api/bvecq.rst
@@ -0,0 +1,229 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=========================================
+bvecq - Chainable bio_vec queue structure
+=========================================
+
+Author: David Howells <dhowells@redhat.com>
+
+.. Contents:
+
+ * Overview
+ * Allocating bvecqs
+ * Refcounting
+ * Expandable buffer
+ * Producer functions
+ * Consumer functions
+ * Utility functions
+ * I/O iterators
+ * API Function Reference
+
+
+Overview
+========
+
+The ``bvecq`` struct can be used to form chains of arrays of ``bio_vec``
+structures - kind of a single layer of indirection. Each bvecq segment points
+to the previous and next bvecq segments in the chain, but is not intended to
+form a circular queue as there are applications where the producer is adding to
+one end whilst the consumer is taking off the other.
+
+To use this, the caller should do::
+
+ #include <linux/bvecq.h>
+
+The publicly accessible members of the structure are::
+
+ struct bvecq {
+ struct bvecq *next;
+ struct bvecq *prev;
+ u32 priv;
+ u16 nr_slots;
+ u16 max_slots;
+ enum bvecq_mem mem_type:3;
+ struct bio_vec *bv;
+ ...
+ };
+
+A pair of pointers are provided, ``next`` and ``prev``, that point to the
+segments on either side of the segment being accessed. Whilst this is a
+doubly-linked list, it is intentionally not a circular list; the outward
+sibling pointers in terminal segments should be NULL.
+
+The ``priv`` member is for the owner of the bvecq to use as they will.
+
+The ``bv`` pointer points at an array of bio_vecs that list a number of regions
+of memory. ``max_slots`` indicates how large the array is and ``nr_slots``
+says how much of the array is being used. Note that there are access functions
+for nr_slots that insert appropriate barriering in the case that there are
+separate producer and consumer threads.
+
+The ``mem_type`` member informs bvecq_put() of how to clean up the bio_vecs
+attached to this segment. It can be one of:
+
+ * ``BVECQ_MEM_EXTERNAL`` - Externally managed; no cleanup.
+ * ``BVECQ_MEM_PAGECACHE`` - Part of pagecache; put_page() used.
+ * ``BVECQ_MEM_GUP`` - Pinned userspace memory; unpin_user_page() used.
+ * ``BVECQ_MEM_ALLOCED`` - Allocated page; __free_pages() used, may be pooled.
+
+
+Allocating bvecqs
+=================
+
+A number of functions are provided to allocate bvecqs::
+
+ 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);
+ struct bvecq *bvecq_alloc_buffer(size_t size,
+ gfp_t gfp,
+ bool for_writeback);
+ struct bvecq *bvecq_alloc_buffer2(size_t size,
+ unsigned int pre_slots,
+ gfp_t gfp,
+ bool for_writeback);
+
+The first of these, ``bvecq_alloc_one()`` allocates a single bvecq with at
+least the requested number of inline slots. The size of the object is rounded
+up to the size of the slab granule that it will be allocated in and the number
+of slots increased appropriately to match. If ``for_writeback`` is set, then
+the netfslib writeback bvecq pool will be used to backstop the allocation if
+the initial slab request fails; in such a case, the number of slots will get
+reduced to ``BVECQ_POOL_SLOTS``.
+
+Two convenience slot count constants are provided:
+
+ * ``BVECQ_POOL_SLOTS`` - The right number of slots to alloc from the mempool
+ * ``BVECQ_4KB_SLOTS`` - The right number of slots to get a 4K allocation
+
+``bvecq_alloc_chain()`` will allocate a sufficiently large chain of bvecqs to
+hold the requested number of slots, capping each allocation at 4K.
+
+``bvecq_alloc_buffer()`` will allocate a chain and populate it, allocating
+sufficient pages to provide a buffer of the specified size attached to the
+chain. ``bvecq_alloc_buffer2()`` is similar, but it reserves some unused
+slots at the front of the chain. Note that these functions may add multipage
+pages in the future.
+
+
+Refcounting
+===========
+
+Each bvecq has a refcount and two functions are provided to handle that::
+
+ struct bvecq *bvecq_get(struct bvecq *bq);
+ void bvecq_put(struct bvecq *bq);
+
+The first of these gets a new reference and the second drops a reference. When
+the refcount hits zero, the second iteratively drops the refs along the chain
+until it hits a segment that has a refcount that doesn't reduce to zero.
+
+
+Expandable buffer
+=================
+
+This facility provides a function to manage an expandable buffer::
+
+ int bvecq_expand_buffer(struct bvecq **_buffer,
+ size_t *_cur_size,
+ size_t size,
+ gfp_t gfp);
+
+Pages are added to the bvecq chain and the chain expanded such that, on
+returning, it holds ``size`` amount of space (without losing any content). The
+caller needs to retain ``*_cur_size`` between calls as that tracks the amount
+of space currently allocated. Note that pages in the chain may be allocated as
+compound pages larger than PAGE_SIZE.
+
+
+Producer functions
+==================
+
+When building and filling a bvecq, there are a number of utility functions that
+can be used to provide the correct barriering and to query the fields in the
+bvecq currently being filled.
+
+Firstly, there's a function to check to see if a bvecq has any spare slots
+left::
+
+ bool bvecq_is_full(const struct bvecq *bvecq);
+
+If not, ``bvecq_alloc_one()`` can be called to allocate a new segment which can
+be initialised and then added to the chain with::
+
+ void bvecq_append(struct bvecq *to, struct bvecq *add);
+
+bio_vec slots in the segment can then be filled and the number of occupied
+slots updated by calling::
+
+ void bvecq_filled_to(struct bvecq *bvecq,
+ unsigned int to);
+
+to insert the appropriate barrier.
+
+
+Consumer functions
+==================
+
+When consuming and destroying a bvecq, there are some utility functions for
+that too, providing the needed barriering. Firstly, there's a function to find
+out how many slots have been used in the current bvecq::
+
+ unsigned int bvecq_nr_slots_acquire(const struct bvecq *bvecq);
+
+Or, more conveniently, if the current slot position is valid within the bvecq::
+
+ bool bvecq_acquire_slot(const struct bvecq *bvecq,
+ unsigned int slot);
+
+If this returns true, the slot is valid and can be looked at; if it returns
+false, the bvecq may have been consumed. If it has, the next bvecq can be
+obtained by calling::
+
+ struct bvecq *bvecq_next(const struct bvecq *bq);
+
+which inserts the appropriate barrier - though bvecq_acquire_slot should be
+rechecked after calling this in case the producer added more slots and then
+extended the list.
+
+
+Utility functions
+=================
+
+A utility function is provided to list the bio_vecs pointed to by a bvecq
+chain::
+
+ void bvecq_dump(const struct bvecq *bq);
+
+
+I/O iterators
+=============
+
+bvecq chains can be used with the ``iov_iter`` facility too. An iterator can
+be initialised to point at a chain by calling::
+
+ void iov_iter_bvec_queue(struct iov_iter *i,
+ unsigned int direction,
+ const struct bvecq *bvecq,
+ unsigned int first_slot,
+ unsigned int offset,
+ size_t count);
+
+In addition to setting the iterator, direction and count, the first bvecq in
+the chain to be iterated over is set, along with the starting slot in that
+iterator and the offset into the slot. Once the iterator is set up, it can be
+treated like any other I/O iterator.
+
+In a producer/consumer environment, it is expected that when an iterator is set
+up, all the bvecqs and all the slots within the count of the iterator must
+exist and must be populated before this function is called.
+
+
+API Function Reference
+======================
+
+.. kernel-doc:: include/linux/bvecq.h
+.. kernel-doc:: fs/netfs/bvecq.c
diff --git a/Documentation/core-api/folio_queue.rst b/Documentation/core-api/folio_queue.rst
deleted file mode 100644
index b7628896d2b695..00000000000000
--- a/Documentation/core-api/folio_queue.rst
+++ /dev/null
@@ -1,209 +0,0 @@
-.. SPDX-License-Identifier: GPL-2.0+
-
-===========
-Folio Queue
-===========
-
-:Author: David Howells <dhowells@redhat.com>
-
-.. Contents:
-
- * Overview
- * Initialisation
- * Adding and removing folios
- * Querying information about a folio
- * Querying information about a folio_queue
- * Folio queue iteration
- * Folio marks
- * Lockless simultaneous production/consumption issues
-
-
-Overview
-========
-
-The folio_queue struct forms a single segment in a segmented list of folios
-that can be used to form an I/O buffer. As such, the list can be iterated over
-using the ITER_FOLIOQ iov_iter type.
-
-The publicly accessible members of the structure are::
-
- struct folio_queue {
- struct folio_queue *next;
- struct folio_queue *prev;
- ...
- };
-
-A pair of pointers are provided, ``next`` and ``prev``, that point to the
-segments on either side of the segment being accessed. Whilst this is a
-doubly-linked list, it is intentionally not a circular list; the outward
-sibling pointers in terminal segments should be NULL.
-
-Each segment in the list also stores:
-
- * an ordered sequence of folio pointers,
- * the size of each folio and
- * three 1-bit marks per folio,
-
-but these should not be accessed directly as the underlying data structure may
-change, but rather the access functions outlined below should be used.
-
-The facility can be made accessible by::
-
- #include <linux/folio_queue.h>
-
-and to use the iterator::
-
- #include <linux/uio.h>
-
-
-Initialisation
-==============
-
-A segment should be initialised by calling::
-
- void folioq_init(struct folio_queue *folioq);
-
-with a pointer to the segment to be initialised. Note that this will not
-necessarily initialise all the folio pointers, so care must be taken to check
-the number of folios added.
-
-
-Adding and removing folios
-==========================
-
-Folios can be set in the next unused slot in a segment struct by calling one
-of::
-
- unsigned int folioq_append(struct folio_queue *folioq,
- struct folio *folio);
-
- unsigned int folioq_append_mark(struct folio_queue *folioq,
- struct folio *folio);
-
-Both functions update the stored folio count, store the folio and note its
-size. The second function also sets the first mark for the folio added. Both
-functions return the number of the slot used. [!] Note that no attempt is made
-to check that the capacity wasn't overrun and the list will not be extended
-automatically.
-
-A folio can be excised by calling::
-
- void folioq_clear(struct folio_queue *folioq, unsigned int slot);
-
-This clears the slot in the array and also clears all the marks for that folio,
-but doesn't change the folio count - so future accesses of that slot must check
-if the slot is occupied.
-
-
-Querying information about a folio
-==================================
-
-Information about the folio in a particular slot may be queried by the
-following function::
-
- struct folio *folioq_folio(const struct folio_queue *folioq,
- unsigned int slot);
-
-If a folio has not yet been set in that slot, this may yield an undefined
-pointer. The size of the folio in a slot may be queried with either of::
-
- unsigned int folioq_folio_order(const struct folio_queue *folioq,
- unsigned int slot);
-
- size_t folioq_folio_size(const struct folio_queue *folioq,
- unsigned int slot);
-
-The first function returns the size as an order and the second as a number of
-bytes.
-
-
-Querying information about a folio_queue
-========================================
-
-Information may be retrieved about a particular segment with the following
-functions::
-
- unsigned int folioq_nr_slots(const struct folio_queue *folioq);
-
- unsigned int folioq_count(struct folio_queue *folioq);
-
- bool folioq_full(struct folio_queue *folioq);
-
-The first function returns the maximum capacity of a segment. It must not be
-assumed that this won't vary between segments. The second returns the number
-of folios added to a segments and the third is a shorthand to indicate if the
-segment has been filled to capacity.
-
-Not that the count and fullness are not affected by clearing folios from the
-segment. These are more about indicating how many slots in the array have been
-initialised, and it assumed that slots won't get reused, but rather the segment
-will get discarded as the queue is consumed.
-
-
-Folio marks
-===========
-
-Folios within a queue can also have marks assigned to them. These marks can be
-used to note information such as if a folio needs folio_put() calling upon it.
-There are three marks available to be set for each folio.
-
-The marks can be set by::
-
- void folioq_mark(struct folio_queue *folioq, unsigned int slot);
- void folioq_mark2(struct folio_queue *folioq, unsigned int slot);
-
-Cleared by::
-
- void folioq_unmark(struct folio_queue *folioq, unsigned int slot);
- void folioq_unmark2(struct folio_queue *folioq, unsigned int slot);
-
-And the marks can be queried by::
-
- bool folioq_is_marked(const struct folio_queue *folioq, unsigned int slot);
- bool folioq_is_marked2(const struct folio_queue *folioq, unsigned int slot);
-
-The marks can be used for any purpose and are not interpreted by this API.
-
-
-Folio queue iteration
-=====================
-
-A list of segments may be iterated over using the I/O iterator facility using
-an ``iov_iter`` iterator of ``ITER_FOLIOQ`` type. The iterator may be
-initialised with::
-
- void iov_iter_folio_queue(struct iov_iter *i, unsigned int direction,
- const struct folio_queue *folioq,
- unsigned int first_slot, unsigned int offset,
- size_t count);
-
-This may be told to start at a particular segment, slot and offset within a
-queue. The iov iterator functions will follow the next pointers when advancing
-and prev pointers when reverting when needed.
-
-
-Lockless simultaneous production/consumption issues
-===================================================
-
-If properly managed, the list can be extended by the producer at the head end
-and shortened by the consumer at the tail end simultaneously without the need
-to take locks. The ITER_FOLIOQ iterator inserts appropriate barriers to aid
-with this.
-
-Care must be taken when simultaneously producing and consuming a list. If the
-last segment is reached and the folios it refers to are entirely consumed by
-the IOV iterators, an iov_iter struct will be left pointing to the last segment
-with a slot number equal to the capacity of that segment. The iterator will
-try to continue on from this if there's another segment available when it is
-used again, but care must be taken lest the segment got removed and freed by
-the consumer before the iterator was advanced.
-
-It is recommended that the queue always contain at least one segment, even if
-that segment has never been filled or is entirely spent. This prevents the
-head and tail pointers from collapsing.
-
-
-API Function Reference
-======================
-
-.. kernel-doc:: include/linux/folio_queue.h
diff --git a/Documentation/core-api/index.rst b/Documentation/core-api/index.rst
index 92f91c6a0d79d6..bfc2f1afc28514 100644
--- a/Documentation/core-api/index.rst
+++ b/Documentation/core-api/index.rst
@@ -39,7 +39,7 @@ Library functionality that is used throughout the kernel.
kref
cleanup
assoc_array
- folio_queue
+ bvecq
xarray
maple_tree
idr
diff --git a/Documentation/filesystems/netfs_library.rst b/Documentation/filesystems/netfs_library.rst
index 215a6621f3d346..1fe110ceb3f18e 100644
--- a/Documentation/filesystems/netfs_library.rst
+++ b/Documentation/filesystems/netfs_library.rst
@@ -437,22 +437,43 @@ Monolithic Files API
There is also a special API set for files for which the content must be read in
a single RPC (and not written back) and is maintained as a monolithic blob
-(e.g. an AFS directory), though it can be stored and updated in the local cache::
+(e.g. an AFS directory), though it can be stored and updated in the local
+cache.
+
+To start with, there's a function to synchronously read the contents of such a
+file into a buffer in a single operation::
+
+ ssize_t netfs_read_single(struct inode *inode,
+ struct file *file,
+ struct iov_iter *iter);
+
+If such a file is modified locally, it can be marked dirty with::
- ssize_t netfs_read_single(struct inode *inode, struct file *file, struct iov_iter *iter);
void netfs_single_mark_inode_dirty(struct inode *inode);
+
+which will schedule it for writeback later. When the writeback eventually
+happens, the filesystem should call::
+
int netfs_writeback_single(struct address_space *mapping,
struct writeback_control *wbc,
- struct iov_iter *iter);
+ struct iov_iter *iter,
+ size_t len);
+
+to write the data to the cache from its writepages method.
-The first function reads from a file into the given buffer, reading from the
-cache in preference if the data is cached there; the second function allows the
-inode to be marked dirty, causing a later writeback; and the third function can
-be called from the writeback code to write the data to the cache, if there is
-one.
+In both the read and writeback functions, the buffer needs to be rounded up to
+a multiple of the cache DIO size, with ``iter->count`` indicating the size of
+the buffer. For the write function, ``len`` should indicate the size of the
+content which may be less than the buffer size. The gap between ``len`` and the
+buffer size should be cleared by the filesystem as this will be used as padding
+if the write size has to be increased (e.g. for the cache DIO).
+
+Note that, for the moment, rounding the buffer up to a multiple of PAGE_SIZE
+instead of the cache DIO size should suffice. DIO size > PAGE_SIZE is not
+currently supported.
The inode should be marked ``NETFS_ICTX_SINGLE_NO_UPLOAD`` if this API is to be
-used. The writeback function requires the buffer to be of ITER_FOLIOQ type.
+used.
Clearing Stale Post-EOF Pagecache
---------------------------------
@@ -859,12 +880,12 @@ The methods defined in the table are:
paths to ask the filesystem to update its idea of the file size. If not
given, netfslib will set i_size and i_blocks and update the local cache
cookie.
-
+
* ``post_modify()``
[Optional] This is called after netfslib writes to the pagecache or when it
allows an mmap'd page to be marked as writable.
-
+
* ``begin_writeback()``
[Optional] Netfslib calls this when processing a writeback request if it
@@ -872,7 +893,7 @@ The methods defined in the table are:
indicating it must be written to the server. This allows the filesystem to
only set up writeback resources when it knows it's going to have to perform
a write.
-
+
* ``prepare_write()``
[Optional] This is called to allow the filesystem to limit the size of a
@@ -911,7 +932,7 @@ The methods defined in the table are:
allows the filesystem to examine the state of the request, the subrequests
in the indicated stream and of its own data and make adjustments or
renegotiate resources.
-
+
* ``invalidate_cache()``
[Optional] This is called by netfslib to invalidate data stored in the local
diff --git a/MAINTAINERS b/MAINTAINERS
index 93abbb315065de..bdda4ad58ab4c2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10382,13 +10382,16 @@ M: Paulo Alcantara <pc@manguebit.org>
L: netfs@lists.linux.dev
L: linux-fsdevel@vger.kernel.org
S: Supported
+F: Documentation/core-api/bvecq.rst
F: Documentation/filesystems/caching/
F: Documentation/filesystems/netfs_library.rst
F: fs/netfs/
+F: include/linux/bvecq.h
F: include/linux/fscache*.h
F: include/linux/netfs.h
F: include/trace/events/fscache.h
F: include/trace/events/netfs.h
+F: lib/tests/kunit_bvecq.c
FILESYSTEMS [STACKABLE]
M: Miklos Szeredi <miklos@szeredi.hu>
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index 75f8f70cfeff02..75a1951bddd054 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -140,9 +140,9 @@ static void afs_dir_dump(struct afs_vnode *dvnode)
pr_warn("DIR %llx:%llx is=%llx\n",
dvnode->fid.vid, dvnode->fid.vnode, i_size);
- iov_iter_folio_queue(&iter, ITER_SOURCE, dvnode->directory, 0, 0, i_size);
- iterate_folioq(&iter, iov_iter_count(&iter), NULL, NULL,
- afs_dir_dump_step);
+ iov_iter_bvec_queue(&iter, ITER_SOURCE, dvnode->directory, 0, 0, i_size);
+ iterate_bvecq(&iter, iov_iter_count(&iter), NULL, NULL,
+ afs_dir_dump_step);
}
/*
@@ -203,9 +203,9 @@ static int afs_dir_check(struct afs_vnode *dvnode)
if (unlikely(!i_size))
return 0;
- iov_iter_folio_queue(&iter, ITER_SOURCE, dvnode->directory, 0, 0, i_size);
- checked = iterate_folioq(&iter, iov_iter_count(&iter), dvnode, NULL,
- afs_dir_check_step);
+ iov_iter_bvec_queue(&iter, ITER_SOURCE, dvnode->directory, 0, 0, i_size);
+ checked = iterate_bvecq(&iter, iov_iter_count(&iter), dvnode, NULL,
+ afs_dir_check_step);
if (checked != i_size) {
afs_dir_dump(dvnode);
return -EIO;
@@ -250,15 +250,16 @@ static ssize_t afs_do_read_single(struct afs_vnode *dvnode, struct file *file)
if (dvnode->directory_size < i_size) {
size_t cur_size = dvnode->directory_size;
- ret = netfs_alloc_folioq_buffer(NULL,
- &dvnode->directory, &cur_size, i_size,
- mapping_gfp_mask(dvnode->netfs.inode.i_mapping));
+ ret = bvecq_expand_buffer(&dvnode->directory, &cur_size,
+ round_up(i_size, PAGE_SIZE),
+ mapping_gfp_mask(dvnode->netfs.inode.i_mapping) |
+ __GFP_ZERO);
dvnode->directory_size = cur_size;
if (ret < 0)
return ret;
}
- iov_iter_folio_queue(&iter, ITER_DEST, dvnode->directory, 0, 0, dvnode->directory_size);
+ iov_iter_bvec_queue(&iter, ITER_DEST, dvnode->directory, 0, 0, dvnode->directory_size);
/* AFS requires us to perform the read of a directory synchronously as
* a single unit to avoid issues with the directory contents being
@@ -278,6 +279,13 @@ static ssize_t afs_do_read_single(struct afs_vnode *dvnode, struct file *file)
if (ret2 < 0)
ret = ret2;
}
+
+ if (ret >= 0 && ret < dvnode->directory_size) {
+ iov_iter_bvec_queue(&iter, ITER_DEST, dvnode->directory,
+ 0, 0, dvnode->directory_size);
+ iov_iter_advance(&iter, ret);
+ iov_iter_zero(dvnode->directory_size - ret, &iter);
+ }
}
return ret;
@@ -294,8 +302,8 @@ static ssize_t afs_read_single(struct afs_vnode *dvnode, struct file *file)
}
/*
- * Read the directory into a folio_queue buffer in one go, scrubbing the
- * previous contents. We return -ESTALE if the caller needs to call us again.
+ * Read the directory into the buffer in one go, scrubbing the previous
+ * contents. We return -ESTALE if the caller needs to call us again.
*/
ssize_t afs_read_dir(struct afs_vnode *dvnode, struct file *file)
__acquires(&dvnode->validate_lock)
@@ -483,7 +491,7 @@ static size_t afs_dir_iterate_step(void *iter_base, size_t progress, size_t len,
}
/*
- * Iterate through the directory folios.
+ * Iterate through the directory content.
*/
static int afs_dir_iterate_contents(struct inode *dir, struct dir_context *dir_ctx)
{
@@ -498,11 +506,11 @@ static int afs_dir_iterate_contents(struct inode *dir, struct dir_context *dir_c
if (i_size <= 0 || dir_ctx->pos >= i_size)
return 0;
- iov_iter_folio_queue(&iter, ITER_SOURCE, dvnode->directory, 0, 0, i_size);
+ iov_iter_bvec_queue(&iter, ITER_SOURCE, dvnode->directory, 0, 0, i_size);
iov_iter_advance(&iter, round_down(dir_ctx->pos, AFS_DIR_BLOCK_SIZE));
- iterate_folioq(&iter, iov_iter_count(&iter), dvnode, &ctx,
- afs_dir_iterate_step);
+ iterate_bvecq(&iter, iov_iter_count(&iter), dvnode, &ctx,
+ afs_dir_iterate_step);
if (ctx.error == -ESTALE)
afs_invalidate_dir(dvnode, afs_dir_invalid_iter_stale);
@@ -2228,9 +2236,10 @@ static int afs_dir_writepages(struct address_space *mapping,
}
if (test_bit(AFS_VNODE_DIR_VALID, &dvnode->flags)) {
- iov_iter_folio_queue(&iter, ITER_SOURCE, dvnode->directory, 0, 0,
- i_size_read(&dvnode->netfs.inode));
- ret = netfs_writeback_single(mapping, wbc, &iter);
+ iov_iter_bvec_queue(&iter, ITER_SOURCE, dvnode->directory,
+ 0, 0, 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/dir_edit.c b/fs/afs/dir_edit.c
index c31303059444ad..870921f32fc89a 100644
--- a/fs/afs/dir_edit.c
+++ b/fs/afs/dir_edit.c
@@ -10,7 +10,6 @@
#include <linux/namei.h>
#include <linux/pagemap.h>
#include <linux/iversion.h>
-#include <linux/folio_queue.h>
#include "internal.h"
#include "xdr_fs.h"
@@ -110,9 +109,8 @@ static void afs_clear_contig_bits(union afs_xdr_dir_block *block,
*/
static union afs_xdr_dir_block *afs_dir_get_block(struct afs_dir_iter *iter, size_t block)
{
- struct folio_queue *fq;
struct afs_vnode *dvnode = iter->dvnode;
- struct folio *folio;
+ struct bvecq *bq;
size_t blpos = block * AFS_DIR_BLOCK_SIZE;
size_t blend = (block + 1) * AFS_DIR_BLOCK_SIZE, fpos = iter->fpos;
int ret;
@@ -120,41 +118,39 @@ static union afs_xdr_dir_block *afs_dir_get_block(struct afs_dir_iter *iter, siz
if (dvnode->directory_size < blend) {
size_t cur_size = dvnode->directory_size;
- ret = netfs_alloc_folioq_buffer(
- NULL, &dvnode->directory, &cur_size, blend,
- mapping_gfp_mask(dvnode->netfs.inode.i_mapping));
+ ret = bvecq_expand_buffer(&dvnode->directory, &cur_size, blend,
+ mapping_gfp_mask(dvnode->netfs.inode.i_mapping) |
+ __GFP_ZERO);
dvnode->directory_size = cur_size;
if (ret < 0)
goto fail;
}
- fq = iter->fq;
- if (!fq)
- fq = dvnode->directory;
+ bq = iter->bq;
+ if (!bq)
+ bq = dvnode->directory;
- /* Search the folio queue for the folio containing the block... */
- for (; fq; fq = fq->next) {
- for (int s = iter->fq_slot; s < folioq_count(fq); s++) {
- size_t fsize = folioq_folio_size(fq, s);
+ /* Search the contents for the region containing the block... */
+ for (; bq; bq = bq->next) {
+ for (int s = iter->bq_slot; s < bq->nr_slots; s++) {
+ struct bio_vec *bv = &bq->bv[s];
+ size_t bsize = bv->bv_len;
- if (blend <= fpos + fsize) {
+ if (blend <= fpos + bsize) {
/* ... and then return the mapped block. */
- folio = folioq_folio(fq, s);
- if (WARN_ON_ONCE(folio_pos(folio) != fpos))
- goto fail;
- iter->fq = fq;
- iter->fq_slot = s;
+ iter->bq = bq;
+ iter->bq_slot = s;
iter->fpos = fpos;
- return kmap_local_folio(folio, blpos - fpos);
+ return bvec_kmap_partial(bv, blpos - fpos);
}
- fpos += fsize;
+ fpos += bsize;
}
- iter->fq_slot = 0;
+ iter->bq_slot = 0;
}
fail:
- iter->fq = NULL;
- iter->fq_slot = 0;
+ iter->bq = NULL;
+ iter->bq_slot = 0;
afs_invalidate_dir(dvnode, afs_dir_invalid_edit_get_block);
return NULL;
}
diff --git a/fs/afs/dir_search.c b/fs/afs/dir_search.c
index 11ebdfffcb1d38..e1f91b3ac6e25e 100644
--- a/fs/afs/dir_search.c
+++ b/fs/afs/dir_search.c
@@ -66,12 +66,11 @@ bool afs_dir_init_iter(struct afs_dir_iter *iter, const struct qstr *name)
*/
union afs_xdr_dir_block *afs_dir_find_block(struct afs_dir_iter *iter, size_t block)
{
- struct folio_queue *fq = iter->fq;
struct afs_vnode *dvnode = iter->dvnode;
- struct folio *folio;
+ struct bvecq *bq = iter->bq;
size_t blpos = block * AFS_DIR_BLOCK_SIZE;
size_t blend = (block + 1) * AFS_DIR_BLOCK_SIZE, fpos = iter->fpos;
- int slot = iter->fq_slot;
+ int slot = iter->bq_slot;
_enter("%zx,%d", block, slot);
@@ -80,36 +79,34 @@ union afs_xdr_dir_block *afs_dir_find_block(struct afs_dir_iter *iter, size_t bl
if (dvnode->directory_size < blend)
goto fail;
- if (!fq || blpos < fpos) {
- fq = dvnode->directory;
+ if (!bq || blpos < fpos) {
+ bq = dvnode->directory;
slot = 0;
fpos = 0;
}
/* Search the folio queue for the folio containing the block... */
- for (; fq; fq = fq->next) {
- for (; slot < folioq_count(fq); slot++) {
- size_t fsize = folioq_folio_size(fq, slot);
+ for (; bq; bq = bq->next) {
+ for (; slot < bq->nr_slots; slot++) {
+ struct bio_vec *bv = &bq->bv[slot];
+ size_t bsize = bv->bv_len;
- if (blend <= fpos + fsize) {
+ if (blend <= fpos + bsize) {
/* ... and then return the mapped block. */
- folio = folioq_folio(fq, slot);
- if (WARN_ON_ONCE(folio_pos(folio) != fpos))
- goto fail;
- iter->fq = fq;
- iter->fq_slot = slot;
+ iter->bq = bq;
+ iter->bq_slot = slot;
iter->fpos = fpos;
- iter->block = kmap_local_folio(folio, blpos - fpos);
+ iter->block = bvec_kmap_partial(bv, blpos - fpos);
return iter->block;
}
- fpos += fsize;
+ fpos += bsize;
}
slot = 0;
}
fail:
- iter->fq = NULL;
- iter->fq_slot = 0;
+ iter->bq = NULL;
+ iter->bq_slot = 0;
afs_invalidate_dir(dvnode, afs_dir_invalid_edit_get_block);
return NULL;
}
diff --git a/fs/afs/inode.c b/fs/afs/inode.c
index 0733abff77a5b9..af95640da03fa7 100644
--- a/fs/afs/inode.c
+++ b/fs/afs/inode.c
@@ -683,7 +683,7 @@ void afs_evict_inode(struct inode *inode)
flush_delayed_work(&vnode->lock_work);
netfs_wait_for_outstanding_io(inode);
truncate_inode_pages_final(&inode->i_data);
- netfs_free_folioq_buffer(vnode->directory);
+ bvecq_put(vnode->directory);
if (vnode->symlink)
afs_evict_symlink(vnode);
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index 7cea5ba0d20d7d..2a8b029b4d69fb 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -712,7 +712,7 @@ struct afs_vnode {
#define AFS_VNODE_MODIFYING 10 /* Set if we're performing a modification op */
#define AFS_VNODE_DIR_READ 11 /* Set if we've read a dir's contents */
- struct folio_queue *directory; /* Directory contents */
+ struct bvecq *directory; /* Directory contents */
struct afs_symlink __rcu *symlink; /* Symlink content */
struct list_head wb_keys; /* List of keys available for writeback */
struct list_head pending_locks; /* locks waiting to be granted */
@@ -993,9 +993,9 @@ static inline void afs_invalidate_cache(struct afs_vnode *vnode, unsigned int fl
struct afs_dir_iter {
struct afs_vnode *dvnode;
union afs_xdr_dir_block *block;
- struct folio_queue *fq;
+ struct bvecq *bq;
unsigned int fpos;
- int fq_slot;
+ int bq_slot;
unsigned int loop_check;
u8 nr_slots;
u8 bucket;
diff --git a/fs/afs/symlink.c b/fs/afs/symlink.c
index 6b8c122877ca2d..f437c3108c6cdb 100644
--- a/fs/afs/symlink.c
+++ b/fs/afs/symlink.c
@@ -56,7 +56,6 @@ void afs_evict_symlink(struct afs_vnode *vnode)
void afs_init_new_symlink(struct afs_vnode *vnode, struct afs_operation *op)
{
struct afs_symlink *symlink = op->create.symlink;
- size_t dsize = 0;
size_t size = strlen(symlink->content) + 1;
char *p;
@@ -66,12 +65,15 @@ void afs_init_new_symlink(struct afs_vnode *vnode, struct afs_operation *op)
if (!fscache_cookie_enabled(netfs_i_cookie(&vnode->netfs)))
return;
- if (netfs_alloc_folioq_buffer(NULL, &vnode->directory, &dsize, size,
- mapping_gfp_mask(vnode->netfs.inode.i_mapping)) < 0)
+ vnode->directory =
+ bvecq_alloc_buffer(PAGE_SIZE,
+ mapping_gfp_mask(vnode->netfs.inode.i_mapping),
+ false);
+ if (!vnode->directory)
return;
- vnode->directory_size = dsize;
- p = kmap_local_folio(folioq_folio(vnode->directory, 0), 0);
+ vnode->directory_size = PAGE_SIZE;
+ p = bvec_kmap_partial(&vnode->directory->bv[0], 0);
memcpy(p, symlink->content, size);
kunmap_local(p);
netfs_single_mark_inode_dirty(&vnode->netfs.inode);
@@ -94,17 +96,14 @@ static ssize_t afs_do_read_symlink(struct afs_vnode *vnode)
}
if (!vnode->directory) {
- size_t cur_size = 0;
-
- ret = netfs_alloc_folioq_buffer(NULL,
- &vnode->directory, &cur_size, PAGE_SIZE,
- mapping_gfp_mask(vnode->netfs.inode.i_mapping));
- vnode->directory_size = PAGE_SIZE - 1;
- if (ret < 0)
- return ret;
+ vnode->directory = bvecq_alloc_buffer(
+ PAGE_SIZE, mapping_gfp_mask(vnode->netfs.inode.i_mapping), false);
+ if (!vnode->directory)
+ return -ENOMEM;
+ vnode->directory_size = PAGE_SIZE;
}
- iov_iter_folio_queue(&iter, ITER_DEST, vnode->directory, 0, 0, PAGE_SIZE);
+ iov_iter_bvec_queue(&iter, ITER_DEST, vnode->directory, 0, 0, PAGE_SIZE);
/* AFS requires us to perform the read of a symlink as a single unit to
* avoid issues with the content being changed between reads.
@@ -116,7 +115,6 @@ static ssize_t afs_do_read_symlink(struct afs_vnode *vnode)
trace_afs_file_error(vnode, -EFBIG, afs_file_error_dir_big);
return -EFBIG;
}
- vnode->directory_size = i_size;
/* Copy the symlink. */
symlink = kmalloc_flex(struct afs_symlink, content, i_size + 1);
@@ -126,7 +124,7 @@ static ssize_t afs_do_read_symlink(struct afs_vnode *vnode)
refcount_set(&symlink->ref, 1);
symlink->content[i_size] = 0;
- const char *s = kmap_local_folio(folioq_folio(vnode->directory, 0), 0);
+ const char *s = bvec_kmap_partial(&vnode->directory->bv[0], 0);
memcpy(symlink->content, s, i_size);
kunmap_local(s);
@@ -135,7 +133,7 @@ static ssize_t afs_do_read_symlink(struct afs_vnode *vnode)
}
if (!fscache_cookie_enabled(netfs_i_cookie(&vnode->netfs))) {
- netfs_free_folioq_buffer(vnode->directory);
+ bvecq_put(vnode->directory);
vnode->directory = NULL;
vnode->directory_size = 0;
}
@@ -196,7 +194,7 @@ const char *afs_get_link(struct dentry *dentry, struct inode *inode,
}
downgrade_write(&vnode->validate_lock);
-
+
good:
symlink = rcu_dereference_protected(vnode->symlink,
lockdep_is_held(&vnode->validate_lock));
@@ -229,6 +227,10 @@ int afs_readlink(struct dentry *dentry, char __user *buffer, int buflen)
/*
* Write the symlink contents to the cache as a single blob. We then throw
* away the page we used to receive it.
+ *
+ * Note that the buffer tail is cleared under a shared lock on ->validate_lock
+ * - though hopefully there won't be racing writers since the only
+ * 'modification' is to be either read from the server or locally created.
*/
int afs_symlink_writepages(struct address_space *mapping,
struct writeback_control *wbc)
@@ -248,14 +250,23 @@ int afs_symlink_writepages(struct address_space *mapping,
if (vnode->directory &&
atomic64_read(&vnode->cb_expires_at) != AFS_NO_CB_PROMISE) {
- iov_iter_folio_queue(&iter, ITER_SOURCE, vnode->directory, 0, 0,
- i_size_read(&vnode->netfs.inode));
- ret = netfs_writeback_single(mapping, wbc, &iter);
+ size_t i_size = i_size_read(&vnode->netfs.inode);
+
+ if (i_size < vnode->directory_size) {
+ iov_iter_bvec_queue(&iter, ITER_DEST, vnode->directory, 0, 0,
+ vnode->directory_size);
+ iov_iter_advance(&iter, i_size);
+ iov_iter_zero(vnode->directory_size - i_size, &iter);
+ }
+
+ iov_iter_bvec_queue(&iter, ITER_SOURCE, vnode->directory, 0, 0,
+ vnode->directory_size);
+ ret = netfs_writeback_single(mapping, wbc, &iter, i_size);
}
if (ret == 0) {
netfs_wb_begin(&vnode->netfs, false);
- netfs_free_folioq_buffer(vnode->directory);
+ bvecq_put(vnode->directory);
vnode->directory = NULL;
vnode->directory_size = 0;
netfs_wb_end(&vnode->netfs);
diff --git a/fs/netfs/Makefile b/fs/netfs/Makefile
index 54834cde7e5686..b1ea4439c1bb4a 100644
--- a/fs/netfs/Makefile
+++ b/fs/netfs/Makefile
@@ -3,6 +3,7 @@
netfs-y := \
buffered_read.o \
buffered_write.o \
+ bvecq.o \
direct_read.o \
direct_write.o \
iterator.o \
diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c
index 69e68ef0652a72..61b44af6774b75 100644
--- a/fs/netfs/buffered_read.c
+++ b/fs/netfs/buffered_read.c
@@ -215,7 +215,7 @@ 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 folio_queue **fq,
+ struct bvecq **bq,
unsigned int *offset,
int *slot,
size_t len,
@@ -225,21 +225,21 @@ static void netfs_mark_copy_to_cache(struct netfs_io_request *rreq,
struct folio *folio;
size_t fsize, overlap;
- if (!*fq)
+ if (!*bq)
break;
- if (*slot >= folioq_count(*fq)) {
- *fq = (*fq)->next;
+ if (!bvecq_acquire_slot(*bq, *slot)) {
+ *bq = bvecq_next(*bq);
*slot = 0;
*offset = 0;
continue;
}
/* Determine how much the subreq overlaps the folio, if at all. */
- fsize = folioq_folio_size(*fq, *slot);
+ fsize = (*bq)->bv[*slot].bv_len;
overlap = min(len, fsize - *offset);
if (overlap > 0 && copy) {
- folio = folioq_folio(*fq, *slot);
+ folio = bvec_folio(&(*bq)->bv[*slot]);
if (netfs_using_pgpriv2(rreq)) {
if (!folio_test_private_2(folio))
folio_start_private_2(folio);
@@ -275,7 +275,7 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq)
.cached_to[1] = ULLONG_MAX,
};
struct fscache_occupancy *occ = &_occ;
- struct folio_queue *fq = rreq->buffer.tail;
+ struct bvecq *bq = rreq->buffer.tail;
unsigned int offset = 0;
ssize_t size = rreq->len;
uoff_t start = rreq->start;
@@ -408,10 +408,10 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq)
if (size <= 0)
netfs_all_subreqs_queued(rreq);
- if (fq) {
+ if (bq) {
/* 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, &fq, &slot, &offset, slice, copy);
+ netfs_mark_copy_to_cache(rreq, &bq, &slot, &offset, slice, copy);
}
trace_netfs_sreq(subreq, netfs_sreq_trace_submit);
@@ -479,8 +479,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->debug_id, rreq->gfp);
+ added = rolling_buffer_bulk_load_from_ra(&rreq->buffer, ractl, rreq->gfp);
if (added < 0) {
ret = added;
goto cleanup_free;
@@ -503,15 +502,14 @@ EXPORT_SYMBOL(netfs_readahead);
/*
* Create a rolling buffer with a single occupying folio.
*/
-static int netfs_create_singular_buffer(struct netfs_io_request *rreq, struct folio *folio,
- unsigned int rollbuf_flags)
+static int netfs_create_singular_buffer(struct netfs_io_request *rreq, struct folio *folio)
{
ssize_t added;
- if (rolling_buffer_init(&rreq->buffer, rreq->debug_id, ITER_DEST, rreq->gfp) < 0)
+ if (rolling_buffer_init(&rreq->buffer, ITER_DEST, rreq->gfp, false) < 0)
return -ENOMEM;
- added = rolling_buffer_append(&rreq->buffer, folio, rollbuf_flags, rreq->gfp);
+ added = rolling_buffer_append(&rreq->buffer, folio, rreq->gfp);
if (added < 0)
return added;
rreq->submitted = rreq->start + added;
@@ -668,7 +666,7 @@ int netfs_read_folio(struct file *file, struct folio *folio)
trace_netfs_read(rreq, rreq->start, rreq->len, netfs_read_trace_readpage);
/* Set up the output buffer */
- ret = netfs_create_singular_buffer(rreq, folio, 0);
+ ret = netfs_create_singular_buffer(rreq, folio);
if (ret < 0)
goto discard;
@@ -825,7 +823,7 @@ int netfs_write_begin(struct netfs_inode *ctx,
trace_netfs_read(rreq, pos, len, netfs_read_trace_write_begin);
/* Set up the output buffer */
- ret = netfs_create_singular_buffer(rreq, folio, 0);
+ ret = netfs_create_singular_buffer(rreq, folio);
if (ret < 0)
goto error_put;
@@ -890,7 +888,7 @@ int netfs_prefetch_for_write(struct file *file, struct folio *folio,
trace_netfs_read(rreq, start, flen, netfs_read_trace_prefetch_for_write);
/* Set up the output buffer */
- ret = netfs_create_singular_buffer(rreq, folio, NETFS_ROLLBUF_PAGECACHE_MARK);
+ ret = netfs_create_singular_buffer(rreq, folio);
if (ret < 0)
goto error_put;
diff --git a/fs/netfs/bvecq.c b/fs/netfs/bvecq.c
new file mode 100644
index 00000000000000..91264337805cd6
--- /dev/null
+++ b/fs/netfs/bvecq.c
@@ -0,0 +1,357 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Buffering helpers for bvec queues
+ *
+ * Copyright (C) 2026 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * See also Documentation/core-api/bvecq.rst
+ */
+
+#include <linux/bvecq.h>
+#include "internal.h"
+
+void bvecq_dump(const struct bvecq *bq)
+{
+ int b = 0;
+
+ for (; bq; bq = bvecq_next(bq), b++) {
+ pr_notice("BQ[%u] %u/%u\n", b, bq->nr_slots, bq->max_slots);
+ for (int s = 0; s < bq->nr_slots; s++) {
+ const struct bio_vec *bv = &bq->bv[s];
+
+ if (!IS_ERR_OR_NULL(bv->bv_page))
+ pr_notice("BQ[%u:%02u] %10lx %04x %04x %u\n",
+ b, s,
+ page_to_pfn(bv->bv_page),
+ bv->bv_offset, bv->bv_len,
+ page_count(bv->bv_page));
+ else
+ pr_notice("BQ[%u:%02u] - %04x %04x\n",
+ b, s, bv->bv_offset, bv->bv_len);
+ }
+ }
+}
+EXPORT_SYMBOL(bvecq_dump);
+
+/**
+ * bvecq_alloc_one - Allocate a single bvecq node with unpopulated slots
+ * @nr_slots: Number of slots to allocate
+ * @gfp: The allocation constraints.
+ * @for_writeback: True if allocating for writeback
+ *
+ * Allocate a single bvecq node and initialise the header. The allocation is
+ * rounded up to the size of the smallest slab granule that will accommodate it
+ * and all the remaining space is set as an inline slot array with max_slots
+ * set to the number of slots. The slot array is not initialised.
+ *
+ * Note that the number of slots allocated is limited to USHRT_MAX. If more
+ * than this are desired, a number of bvecqs should be chained.
+ *
+ * If @for_writeback is set, then the emergency mempool may be used for
+ * allocation. If it does allocate from that pool, the maximum number of slots
+ * available will be BVECQ_POOL_SLOTS which may be less than requested. Also,
+ * if @for_writeback is set, the function will not fail - though it may have to
+ * wait.
+ *
+ * Return: The node pointer or NULL on allocation failure.
+ */
+struct bvecq *bvecq_alloc_one(size_t nr_slots, gfp_t gfp, bool for_writeback)
+{
+ struct bvecq *bq;
+ size_t size;
+ bool from_pool = false;
+
+ /* Don't overrun ->max_slots or ->nr_slots. */
+ if (nr_slots > BVECQ_MAX_INLINE_SLOTS)
+ nr_slots = BVECQ_MAX_INLINE_SLOTS;
+
+ size = kmalloc_size_roundup(struct_size(bq, __bv, nr_slots));
+ gfp &= ~(GFP_ZONEMASK | __GFP_THISNODE);
+
+ if (for_writeback) {
+ if (size != BVECQ_POOL_SIZE) {
+ gfp_t gfp_temp = gfp;
+
+ gfp_temp |= __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN;
+ gfp_temp &= ~(__GFP_DIRECT_RECLAIM | __GFP_IO);
+ bq = kmalloc(size, gfp_temp);
+ if (bq)
+ goto success;
+ }
+
+ bq = mempool_alloc(&netfs_bvecq_pool, gfp);
+ if (!bq)
+ return bq;
+ from_pool = true;
+ size = BVECQ_POOL_SIZE;
+ } else {
+ bq = kmalloc(size, gfp);
+ if (!bq)
+ return bq;
+ }
+
+success:
+ *bq = (struct bvecq) {
+ .ref = REFCOUNT_INIT(1),
+ .bv = bq->__bv,
+ .inline_bv = true,
+ .max_slots = min((size - sizeof(*bq)) / sizeof(bq->__bv[0]),
+ BVECQ_MAX_INLINE_SLOTS),
+ .from_pool = from_pool,
+ };
+ netfs_stat(&netfs_n_bvecq);
+ return bq;
+}
+EXPORT_SYMBOL(bvecq_alloc_one);
+
+/**
+ * bvecq_alloc_chain - Allocate an unpopulated bvecq chain
+ * @nr_slots: Number of slots to allocate
+ * @gfp: The allocation constraints.
+ * @for_writeback: True if allocating for writeback
+ *
+ * Allocate a chain of bvecq nodes providing at least the requested cumulative
+ * number of slots. Each node is a maximum of 4KiB in size.
+ *
+ * Return: The first node pointer or NULL on allocation failure.
+ */
+struct bvecq *bvecq_alloc_chain(size_t nr_slots, gfp_t gfp, bool for_writeback)
+{
+ struct bvecq *head = NULL, *tail = NULL;
+
+ _enter("%zu", nr_slots);
+
+ for (;;) {
+ struct bvecq *bq;
+
+ bq = bvecq_alloc_one(min(nr_slots, BVECQ_4KB_SLOTS), gfp, for_writeback);
+ if (!bq)
+ goto oom;
+
+ if (tail)
+ bvecq_append(tail, bq);
+ else
+ head = bq;
+ tail = bq;
+ if (tail->max_slots >= nr_slots)
+ break;
+ nr_slots -= tail->max_slots;
+ }
+
+ return head;
+oom:
+ bvecq_put(head);
+ return NULL;
+}
+EXPORT_SYMBOL(bvecq_alloc_chain);
+
+/**
+ * bvecq_alloc_buffer2 - Allocate a bvecq chain and populate with buffers
+ * @size: Target size of the buffer (can be 0 for an empty buffer)
+ * @pre_slots: Number of preamble slots to set aside
+ * @gfp: The allocation constraints.
+ * @for_writeback: True if allocating for writeback
+ *
+ * Allocate a chain of bvecq nodes and populate the slots with sufficient pages
+ * to provide at least the requested amount of space, leaving the first
+ * @pre_slots slots unset. The pre-slots must all fit into the first bvecq.
+ * Note that any memory segments set in the pre_slots will be freed as
+ * specified by BVECQ_MEM_ALLOCED.
+ *
+ * The caller should assume that the pages allocated may be compound pages
+ * larger than PAGE_SIZE and thus occupy fewer slots. The pages have their
+ * refcounts set to 1 and can be passed to MSG_SPLICE_PAGES.
+ *
+ * Return: The first node pointer or NULL on allocation failure.
+ */
+struct bvecq *bvecq_alloc_buffer2(size_t size, unsigned int pre_slots, gfp_t gfp,
+ bool for_writeback)
+{
+ struct bvecq *head = NULL, *p = NULL;
+ size_t nr_per_bq = BVECQ_POOL_SLOTS;
+ size_t count = pre_slots + DIV_ROUND_UP(size, PAGE_SIZE);
+
+ _enter("%zx,%zx,%u", size, count, pre_slots);
+
+ if (WARN_ON_ONCE(pre_slots > nr_per_bq))
+ return NULL;
+
+ head = bvecq_alloc_chain(count, gfp, for_writeback);
+ if (!head)
+ return NULL;
+
+ p = head;
+ do {
+ struct page **pages;
+ size_t unused, want, got, slot;
+
+ if (!count)
+ break;
+ if (WARN_ON_ONCE(!p))
+ goto oom;
+
+ if (p->nr_slots == 0) {
+ /* Need to clear pre slots and pages[], so just clear all. */
+ memset(p->bv, 0, p->max_slots * sizeof(p->bv[0]));
+ p->mem_type = BVECQ_MEM_ALLOCED;
+ p->nr_slots = pre_slots;
+ count -= pre_slots;
+ pre_slots = 0;
+ if (!count)
+ break;
+ }
+
+ if (p->nr_slots >= p->max_slots) {
+ p = p->next;
+ continue;
+ }
+ unused = p->max_slots - p->nr_slots;
+
+ /* We can put pages[] at the tail of bv[] as the elements are
+ * smaller and we won't overrun if the slots are filled in
+ * ascending order.
+ */
+ pages = (struct page **)&p->bv[p->max_slots];
+ pages -= unused;
+
+ want = min(count, unused);
+ got = alloc_pages_bulk(gfp, want, pages);
+ if (!got)
+ goto oom;
+
+ slot = p->nr_slots;
+ for (int i = 0; i < got; i++)
+ bvec_set_page(&p->bv[slot++], pages[i], PAGE_SIZE, 0);
+
+ bvecq_filled_to(p, slot);
+ count -= got;
+ } while (count > 0);
+
+ return head;
+oom:
+ bvecq_put(head);
+ return NULL;
+}
+EXPORT_SYMBOL(bvecq_alloc_buffer2);
+
+/*
+ * Free the page pointed to by a slot as necessary.
+ */
+static void bvecq_free_slot(struct bvecq *bq, unsigned int slot)
+{
+ struct page *page = bq->bv[slot].bv_page;
+
+ if (!page)
+ return;
+
+ switch (bq->mem_type) {
+ case BVECQ_MEM_EXTERNAL:
+ break;
+ case BVECQ_MEM_PAGECACHE:
+ put_page(page);
+ break;
+ case BVECQ_MEM_GUP:
+ unpin_user_page(page);
+ break;
+ case BVECQ_MEM_ALLOCED:
+ __free_pages(page, compound_order(page));
+ break;
+ default:
+ WARN_ON_ONCE(1);
+ break;
+ }
+}
+
+/**
+ * bvecq_put - Put a ref on a bvec queue
+ * @bq: The start of the folio queue to free
+ *
+ * Put the ref(s) on the nodes in a bvec queue, freeing up the node and the
+ * page fragments it points to as the refcounts become zero.
+ */
+void bvecq_put(struct bvecq *bq)
+{
+ struct bvecq *next;
+
+ for (; bq; bq = next) {
+ if (!refcount_dec_and_test(&bq->ref))
+ break;
+ for (int slot = 0; slot < bq->nr_slots; slot++)
+ bvecq_free_slot(bq, slot);
+ next = bq->next;
+ netfs_stat_d(&netfs_n_bvecq);
+ if (bq->from_pool)
+ mempool_free(bq, &netfs_bvecq_pool);
+ else
+ kfree(bq);
+ }
+}
+EXPORT_SYMBOL(bvecq_put);
+
+/**
+ * bvecq_expand_buffer - Allocate buffer space into a bvec queue
+ * @_buffer: Pointer to the bvecq chain to expand (may point to a NULL; updated).
+ * @_cur_size: Current size of the buffer (updated).
+ * @size: Target size of the buffer.
+ * @gfp: The allocation constraints.
+ *
+ * Append extra pages to a buffer to increase its capacity to the @size
+ * specified. If the current tail has space, but is not of the
+ * BVECQ_MEM_ALLOCED memory type, a separate bvecq will be allocated to hold
+ * the new memory.
+ *
+ * Return: 0 on success or -ENOMEM on failure. Note that in the case of
+ * failure, the buffer may have been partially expanded. In any event,
+ * *@_cur_size will be updated to the new buffer size.
+ */
+int bvecq_expand_buffer(struct bvecq **_buffer, size_t *_cur_size, size_t size, gfp_t gfp)
+{
+ struct bvecq *tail = *_buffer;
+
+ size = round_up(size, PAGE_SIZE);
+ if (tail)
+ while (tail->next)
+ tail = tail->next;
+
+ while (*_cur_size < size) {
+ struct page *page;
+ size_t need = size - *_cur_size;
+ gfp_t gfp_add;
+ int order = 0;
+
+ if (!tail || bvecq_is_full(tail) || tail->mem_type != BVECQ_MEM_ALLOCED) {
+ struct bvecq *p;
+
+ p = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, false);
+ if (!p)
+ return -ENOMEM;
+ if (tail)
+ bvecq_append(tail, p);
+ else
+ *_buffer = p;
+ tail = p;
+ p->mem_type = BVECQ_MEM_ALLOCED;
+ }
+
+ if (need > PAGE_SIZE)
+ order = umin(ilog2(need) - PAGE_SHIFT, MAX_PAGECACHE_ORDER);
+
+ gfp_add = 0;
+ if (order > 0)
+ gfp_add |= __GFP_NORETRY | __GFP_NOWARN;
+ page = alloc_pages(gfp | __GFP_COMP | gfp_add, order);
+ if (!page && order > 0) {
+ page = alloc_pages(gfp | __GFP_COMP, 0);
+ order = 0;
+ }
+ if (!page)
+ return -ENOMEM;
+
+ bvec_set_page(&tail->bv[tail->nr_slots], page, PAGE_SIZE << order, 0);
+ *_cur_size += PAGE_SIZE << order;
+ bvecq_filled_to(tail, tail->nr_slots + 1);
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL(bvecq_expand_buffer);
diff --git a/fs/netfs/internal.h b/fs/netfs/internal.h
index 6b583152132f0b..33d6cc23f54ad6 100644
--- a/fs/netfs/internal.h
+++ b/fs/netfs/internal.h
@@ -7,10 +7,10 @@
#include <linux/slab.h>
#include <linux/seq_file.h>
-#include <linux/folio_queue.h>
#include <linux/netfs.h>
#include <linux/fscache.h>
#include <linux/fscache-cache.h>
+#include <linux/mempool.h>
#include <trace/events/netfs.h>
#include <trace/events/fscache.h>
@@ -45,7 +45,7 @@ extern struct list_head netfs_io_requests;
extern spinlock_t netfs_proc_lock;
extern mempool_t netfs_request_pool;
extern mempool_t netfs_subrequest_pool;
-extern mempool_t netfs_folioq_pool;
+extern mempool_t netfs_bvecq_pool;
#ifdef CONFIG_PROC_FS
static inline void netfs_proc_add_rreq(struct netfs_io_request *rreq)
@@ -70,8 +70,6 @@ static inline void netfs_proc_del_rreq(struct netfs_io_request *rreq) {}
/*
* misc.c
*/
-struct folio_queue *netfs_buffer_make_space(struct netfs_io_request *rreq,
- enum netfs_folioq_trace trace);
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);
@@ -204,7 +202,7 @@ extern atomic_t netfs_n_wh_retry_write_req;
extern atomic_t netfs_n_wh_retry_write_subreq;
extern atomic_t netfs_n_wb_lock_skip;
extern atomic_t netfs_n_wb_lock_wait;
-extern atomic_t netfs_n_folioq;
+extern atomic_t netfs_n_bvecq;
int netfs_stats_show(struct seq_file *m, void *v);
diff --git a/fs/netfs/iterator.c b/fs/netfs/iterator.c
index eb1efb17f53aaa..983d3e45c69801 100644
--- a/fs/netfs/iterator.c
+++ b/fs/netfs/iterator.c
@@ -245,33 +245,37 @@ static size_t netfs_limit_xarray(const struct iov_iter *iter, size_t start_offse
}
/*
- * Select the span of a folio queue 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.
+ * 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_folioq(const struct iov_iter *iter, size_t start_offset,
- size_t max_size, size_t max_segs)
+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 folio_queue *folioq = iter->folioq;
+ const struct bvecq *bq = iter->bvecq;
unsigned int nsegs = 0;
- unsigned int slot = iter->folioq_slot;
+ unsigned int slot = iter->bvecq_slot;
size_t span = 0, n = iter->count;
- if (WARN_ON(!iov_iter_is_folioq(iter)) ||
+ 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 (slot >= folioq_nr_slots(folioq)) {
- folioq = folioq->next;
- slot = 0;
- }
-
start_offset += iter->iov_offset;
do {
- size_t flen = folioq_folio_size(folioq, slot);
+ size_t flen;
+ if (!bvecq_acquire_slot(bq, slot)) {
+ bq = bvecq_next(bq);
+ if (!bq)
+ break;
+ slot = 0;
+ continue;
+ }
+
+ flen = bq->bv[slot].bv_len;
if (start_offset < flen) {
span += flen - start_offset;
nsegs++;
@@ -283,11 +287,7 @@ static size_t netfs_limit_folioq(const struct iov_iter *iter, size_t start_offse
break;
slot++;
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = folioq->next;
- slot = 0;
- }
- } while (folioq);
+ } while (bq);
return umin(span, max_size);
}
@@ -295,8 +295,8 @@ static size_t netfs_limit_folioq(const struct iov_iter *iter, size_t start_offse
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_folioq(iter))
- return netfs_limit_folioq(iter, start_offset, max_size, 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))
diff --git a/fs/netfs/main.c b/fs/netfs/main.c
index 609e22e8f76a06..b1a7521b7210bd 100644
--- a/fs/netfs/main.c
+++ b/fs/netfs/main.c
@@ -7,7 +7,6 @@
#include <linux/module.h>
#include <linux/export.h>
-#include <linux/mempool.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include "internal.h"
@@ -28,7 +27,7 @@ static struct kmem_cache *netfs_request_slab;
static struct kmem_cache *netfs_subrequest_slab;
mempool_t netfs_request_pool;
mempool_t netfs_subrequest_pool;
-mempool_t netfs_folioq_pool;
+mempool_t netfs_bvecq_pool;
#ifdef CONFIG_PROC_FS
LIST_HEAD(netfs_io_requests);
@@ -108,8 +107,8 @@ static int __init netfs_init(void)
{
int ret = -ENOMEM;
- if (mempool_init_kmalloc_pool(&netfs_folioq_pool, 100, sizeof(struct folio_queue)) < 0)
- goto error_folioq_pool;
+ if (mempool_init_kmalloc_pool(&netfs_bvecq_pool, 100, BVECQ_POOL_SIZE) < 0)
+ goto error_bvecq_pool;
netfs_request_slab = kmem_cache_create("netfs_request",
sizeof(struct netfs_io_request), 0,
@@ -163,8 +162,8 @@ static int __init netfs_init(void)
error_reqpool:
kmem_cache_destroy(netfs_request_slab);
error_req:
- mempool_exit(&netfs_folioq_pool);
-error_folioq_pool:
+ mempool_exit(&netfs_bvecq_pool);
+error_bvecq_pool:
return ret;
}
fs_initcall(netfs_init);
@@ -177,6 +176,6 @@ static void __exit netfs_exit(void)
kmem_cache_destroy(netfs_subrequest_slab);
mempool_exit(&netfs_request_pool);
kmem_cache_destroy(netfs_request_slab);
- mempool_exit(&netfs_folioq_pool);
+ mempool_exit(&netfs_bvecq_pool);
}
module_exit(netfs_exit);
diff --git a/fs/netfs/misc.c b/fs/netfs/misc.c
index 5465db834b9499..a0cc248a284d59 100644
--- a/fs/netfs/misc.c
+++ b/fs/netfs/misc.c
@@ -9,102 +9,6 @@
#include <linux/rmap.h>
#include "internal.h"
-/**
- * netfs_alloc_folioq_buffer - Allocate buffer space into a folio queue
- * @mapping: Address space to set on the folio (or NULL).
- * @_buffer: Pointer to the folio queue to add to (may point to a NULL; updated).
- * @_cur_size: Current size of the buffer (updated).
- * @size: Target size of the buffer.
- * @gfp: The allocation constraints.
- */
-int netfs_alloc_folioq_buffer(struct address_space *mapping,
- struct folio_queue **_buffer,
- size_t *_cur_size, ssize_t size, gfp_t gfp)
-{
- struct folio_queue *tail = *_buffer, *p;
-
- size = round_up(size, PAGE_SIZE);
- if (*_cur_size >= size)
- return 0;
-
- if (tail)
- while (tail->next)
- tail = tail->next;
-
- do {
- struct folio *folio;
- int order = 0, slot;
-
- if (!tail || folioq_full(tail)) {
- p = netfs_folioq_alloc(0, GFP_NOFS, netfs_trace_folioq_alloc_buffer);
- if (!p)
- return -ENOMEM;
- if (tail) {
- tail->next = p;
- p->prev = tail;
- } else {
- *_buffer = p;
- }
- tail = p;
- }
-
- if (size - *_cur_size > PAGE_SIZE)
- order = umin(ilog2(size - *_cur_size) - PAGE_SHIFT,
- MAX_PAGECACHE_ORDER);
-
- folio = folio_alloc(gfp, order);
- if (!folio && order > 0)
- folio = folio_alloc(gfp, 0);
- if (!folio)
- return -ENOMEM;
-
- folio->mapping = mapping;
- folio->index = *_cur_size / PAGE_SIZE;
- trace_netfs_folio(folio, netfs_folio_trace_alloc_buffer);
- slot = folioq_append_mark(tail, folio);
- *_cur_size += folioq_folio_size(tail, slot);
- } while (*_cur_size < size);
-
- return 0;
-}
-EXPORT_SYMBOL(netfs_alloc_folioq_buffer);
-
-/**
- * netfs_free_folioq_buffer - Free a folio queue.
- * @fq: The start of the folio queue to free
- *
- * Free up a chain of folio_queues and, if marked, the marked folios they point
- * to.
- */
-void netfs_free_folioq_buffer(struct folio_queue *fq)
-{
- struct folio_queue *next;
- struct folio_batch fbatch;
-
- folio_batch_init(&fbatch);
-
- for (; fq; fq = next) {
- for (int slot = 0; slot < folioq_count(fq); slot++) {
- struct folio *folio = folioq_folio(fq, slot);
-
- if (!folio ||
- !folioq_is_marked(fq, slot))
- continue;
-
- trace_netfs_folio(folio, netfs_folio_trace_put);
- if (folio_batch_add(&fbatch, folio))
- folio_batch_release(&fbatch);
- }
-
- netfs_stat_d(&netfs_n_folioq);
- next = fq->next;
- kfree(fq);
- }
-
- folio_batch_release(&fbatch);
-}
-EXPORT_SYMBOL(netfs_free_folioq_buffer);
-
/*
* 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
diff --git a/fs/netfs/objects.c b/fs/netfs/objects.c
index 4b8d20559b0e15..6d7839c0498d60 100644
--- a/fs/netfs/objects.c
+++ b/fs/netfs/objects.c
@@ -6,7 +6,6 @@
*/
#include <linux/slab.h>
-#include <linux/mempool.h>
#include "internal.h"
static void netfs_free_request(struct work_struct *work);
diff --git a/fs/netfs/read_collect.c b/fs/netfs/read_collect.c
index be0f9d2f7e10f5..75c8874ec45953 100644
--- a/fs/netfs/read_collect.c
+++ b/fs/netfs/read_collect.c
@@ -79,11 +79,11 @@ void netfs_cancel_copy_to_cache(struct netfs_io_request *rreq, struct folio *fol
* dirty and let writeback handle it.
*/
static void netfs_unlock_read_folio(struct netfs_io_request *rreq,
- struct folio_queue *folioq,
+ struct bvecq *bq,
int slot)
{
struct netfs_folio *finfo;
- struct folio *folio = folioq_folio(folioq, slot);
+ struct folio *folio = bvec_folio(&bq->bv[slot]);
if (unlikely(folio_pos(folio) < rreq->abandon_to)) {
trace_netfs_folio(folio, netfs_folio_trace_abandon);
@@ -114,7 +114,7 @@ static void netfs_unlock_read_folio(struct netfs_io_request *rreq,
trace_netfs_folio(folio, netfs_folio_trace_read_done);
}
- folioq_clear(folioq, slot);
+ bq->bv[slot].bv_page = NULL;
} else {
// TODO: Use of PG_private_2 is deprecated.
if (folio_test_private_2(folio))
@@ -130,7 +130,7 @@ static void netfs_unlock_read_folio(struct netfs_io_request *rreq,
folio_unlock(folio);
}
- folioq_clear(folioq, slot);
+ bq->bv[slot].bv_page = NULL;
}
/*
@@ -138,21 +138,22 @@ static void netfs_unlock_read_folio(struct netfs_io_request *rreq,
*/
void netfs_read_set_unlock_at(struct netfs_io_request *rreq)
{
- struct folio_queue *folioq = rreq->buffer.tail;
+ const struct bvecq *bq = rreq->buffer.tail;
unsigned int slot = rreq->buffer.first_tail_slot;
size_t cleaned_to = rreq->cleaned_to - rreq->start;
size_t progress_at = cleaned_to;
size_t minimum = 256 * 1024;
while (progress_at < rreq->len) {
- if (slot >= folioq_count(folioq)) {
- folioq = folioq->next;
- if (!folioq)
+ if (!bvecq_acquire_slot(bq, slot)) {
+ bq = bvecq_next(bq);
+ if (!bq)
break;
slot = 0;
+ continue;
}
- progress_at += folioq_folio_size(folioq, slot);
+ progress_at += bq->bv[slot].bv_len;
if (progress_at - cleaned_to >= minimum)
break;
slot++;
@@ -168,7 +169,7 @@ 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 folio_queue *folioq = rreq->buffer.tail;
+ struct bvecq *bq = rreq->buffer.tail;
unsigned int slot = rreq->buffer.first_tail_slot;
uoff_t collected_to = rreq->collected_to;
@@ -177,9 +178,9 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,
// TODO: Begin decryption
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = rolling_buffer_delete_spent(&rreq->buffer);
- if (!folioq) {
+ while (!bvecq_acquire_slot(bq, slot)) {
+ bq = rolling_buffer_delete_spent(&rreq->buffer);
+ if (!bq) {
WRITE_ONCE(rreq->progress_at, rreq->len);
return;
}
@@ -198,13 +199,13 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,
uoff_t fpos, fend;
size_t fsize;
- folio = folioq_folio(folioq, slot);
+ folio = bvec_folio(&bq->bv[slot]);
if (WARN_ONCE(!folio_test_locked(folio),
"R=%08x: folio %lx is not locked\n",
rreq->debug_id, folio->index))
trace_netfs_folio(folio, netfs_folio_trace_not_locked);
- fsize = folioq_folio_size(folioq, slot);
+ fsize = bq->bv[slot].bv_len;
fpos = folio_pos(folio);
fend = fpos + fsize;
@@ -214,29 +215,28 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,
if (collected_to < fend)
break;
- netfs_unlock_read_folio(rreq, folioq, slot);
+ netfs_unlock_read_folio(rreq, bq, slot);
WRITE_ONCE(rreq->cleaned_to, fpos + fsize);
*notes |= MADE_PROGRESS;
- /* Clean up the head folioq. If we clear an entire folioq, then
- * we can get rid of it provided it's not also the tail folioq
+ /* 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.
*/
- folioq_clear(folioq, slot);
+ bq->bv[slot].bv_page = NULL;
slot++;
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = rolling_buffer_delete_spent(&rreq->buffer);
- if (!folioq)
+ while (!bvecq_acquire_slot(bq, slot)) {
+ bq = rolling_buffer_delete_spent(&rreq->buffer);
+ if (!bq)
goto done;
slot = 0;
- trace_netfs_folioq(folioq, netfs_trace_folioq_read_progress);
}
if (fpos + fsize >= collected_to)
break;
}
- rreq->buffer.tail = folioq;
+ rreq->buffer.tail = bq;
done:
rreq->buffer.first_tail_slot = slot;
diff --git a/fs/netfs/read_pgpriv2.c b/fs/netfs/read_pgpriv2.c
index 5280b606fda410..f8e5667e278e1b 100644
--- a/fs/netfs/read_pgpriv2.c
+++ b/fs/netfs/read_pgpriv2.c
@@ -53,7 +53,7 @@ static void netfs_pgpriv2_copy_folio(struct netfs_io_request *creq, struct folio
trace_netfs_folio(folio, netfs_folio_trace_store_copy);
/* Attach the folio to the rolling buffer. */
- if (rolling_buffer_append(&creq->buffer, folio, 0, creq->gfp) < 0) {
+ if (rolling_buffer_append(&creq->buffer, folio, creq->gfp) < 0) {
set_bit(NETFS_RREQ_CANCEL_CACHING, &creq->flags);
folio_end_private_2(folio);
return;
@@ -173,13 +173,15 @@ void netfs_pgpriv2_end_copy_to_cache(struct netfs_io_request *rreq)
*/
bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *creq)
{
- struct folio_queue *folioq = creq->buffer.tail;
+ struct bvecq *bq = creq->buffer.tail;
unsigned int slot = creq->buffer.first_tail_slot;
uoff_t collected_to = creq->collected_to;
bool made_progress = false;
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = rolling_buffer_delete_spent(&creq->buffer);
+ while (!bvecq_acquire_slot(bq, slot)) {
+ bq = rolling_buffer_delete_spent(&creq->buffer);
+ if (!bq)
+ return false;
slot = 0;
}
@@ -188,7 +190,7 @@ bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *creq)
uoff_t fpos, fend;
size_t fsize, flen;
- folio = folioq_folio(folioq, slot);
+ folio = bvec_folio(&bq->bv[slot]);
if (WARN_ONCE(!folio_test_private_2(folio),
"R=%08x: folio %lx is not marked private_2\n",
creq->debug_id, folio->index))
@@ -211,15 +213,15 @@ bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *creq)
creq->cleaned_to = fpos + fsize;
made_progress = true;
- /* Clean up the head folioq. If we clear an entire folioq, then
- * we can get rid of it provided it's not also the tail folioq
+ /* 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.
*/
- folioq_clear(folioq, slot);
+ bq->bv[slot].bv_page = NULL;
slot++;
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = rolling_buffer_delete_spent(&creq->buffer);
- if (!folioq)
+ while (!bvecq_acquire_slot(bq, slot)) {
+ bq = rolling_buffer_delete_spent(&creq->buffer);
+ if (!bq)
goto done;
slot = 0;
}
@@ -228,7 +230,7 @@ bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *creq)
break;
}
- creq->buffer.tail = folioq;
+ creq->buffer.tail = bq;
done:
creq->buffer.first_tail_slot = slot;
return made_progress;
diff --git a/fs/netfs/read_retry.c b/fs/netfs/read_retry.c
index 5bd8dee5a83467..142c3fb8dab17c 100644
--- a/fs/netfs/read_retry.c
+++ b/fs/netfs/read_retry.c
@@ -291,7 +291,7 @@ void netfs_retry_reads(struct netfs_io_request *rreq)
*/
void netfs_unlock_abandoned_read_pages(struct netfs_io_request *rreq)
{
- struct folio_queue *p;
+ struct bvecq *p;
/* 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
@@ -301,24 +301,25 @@ void netfs_unlock_abandoned_read_pages(struct netfs_io_request *rreq)
netfs_wait_for_put_ra_refs(rreq);
for (p = rreq->buffer.tail; p; p = p->next) {
- for (int slot = 0; slot < folioq_count(p); slot++) {
- struct folio *folio = folioq_folio(p, slot);
+ for (int slot = rreq->buffer.first_tail_slot;
+ bvecq_acquire_slot(p, slot);
+ slot++) {
+ struct folio *folio;
- if (!folio)
+ if (!p->bv[slot].bv_page)
continue;
+
+ folio = bvec_folio(&p->bv[slot]);
netfs_cancel_copy_to_cache(rreq, folio);
- if (!folioq_is_marked2(p, slot)) {
- 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);
- }
+ 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);
}
}
+ rreq->buffer.first_tail_slot = 0;
}
}
diff --git a/fs/netfs/rolling_buffer.c b/fs/netfs/rolling_buffer.c
index d30d5ef6d86eca..e23d87c8d4b38e 100644
--- a/fs/netfs/rolling_buffer.c
+++ b/fs/netfs/rolling_buffer.c
@@ -6,102 +6,56 @@
*/
#include <linux/bitops.h>
-#include <linux/mempool.h>
#include <linux/pagemap.h>
#include <linux/rolling_buffer.h>
#include <linux/slab.h>
#include "internal.h"
-static atomic_t debug_ids;
-
-/**
- * netfs_folioq_alloc - Allocate a folio_queue struct
- * @rreq_id: Associated debugging ID for tracing purposes
- * @gfp: Allocation constraints
- * @trace: Trace tag to indicate the purpose of the allocation
- *
- * Allocate, initialise and account the folio_queue struct and log a trace line
- * to mark the allocation.
- */
-struct folio_queue *netfs_folioq_alloc(unsigned int rreq_id, gfp_t gfp,
- unsigned int /*enum netfs_folioq_trace*/ trace)
-{
- struct folio_queue *fq;
-
- if (gfp == GFP_KERNEL)
- fq = mempool_alloc_noreserve(&netfs_folioq_pool, gfp);
- else
- fq = mempool_alloc(&netfs_folioq_pool, gfp);
- if (fq) {
- netfs_stat(&netfs_n_folioq);
- folioq_init(fq, rreq_id);
- fq->debug_id = atomic_inc_return(&debug_ids);
- trace_netfs_folioq(fq, trace);
- }
- return fq;
-}
-EXPORT_SYMBOL(netfs_folioq_alloc);
-
-/**
- * netfs_folioq_free - Free a folio_queue struct
- * @folioq: The object to free
- * @trace: Trace tag to indicate which free
- *
- * Free and unaccount the folio_queue struct.
- */
-void netfs_folioq_free(struct folio_queue *folioq,
- unsigned int /*enum netfs_trace_folioq*/ trace)
-{
- trace_netfs_folioq(folioq, trace);
- netfs_stat_d(&netfs_n_folioq);
- mempool_free(folioq, &netfs_folioq_pool);
-}
-EXPORT_SYMBOL(netfs_folioq_free);
-
/*
* 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 rreq_id,
- unsigned int direction, gfp_t gfp)
+int rolling_buffer_init(struct rolling_buffer *roll, unsigned int direction,
+ gfp_t gfp, bool for_writeback)
{
- struct folio_queue *fq;
+ struct bvecq *bq;
+
+ roll->for_writeback = for_writeback;
- fq = netfs_folioq_alloc(rreq_id, gfp, netfs_trace_folioq_rollbuf_init);
- if (!fq)
+ bq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, for_writeback);
+ if (!bq)
return -ENOMEM;
- roll->head = fq;
- roll->tail = fq;
- iov_iter_folio_queue(&roll->iter, direction, fq, 0, 0, 0);
+ roll->head = bq;
+ roll->tail = bq;
+ iov_iter_bvec_queue(&roll->iter, direction, bq, 0, 0, 0);
return 0;
}
/*
- * Add another folio_queue to a rolling buffer if there's no space left.
+ * 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 folio_queue *fq, *head = roll->head;
+ struct bvecq *bq, *head = roll->head;
- if (!folioq_full(head))
+ if (!bvecq_is_full(head))
return 0;
- fq = netfs_folioq_alloc(head->rreq_id, gfp, netfs_trace_folioq_make_space);
- if (!fq)
+ bq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, roll->for_writeback);
+ if (!bq)
return -ENOMEM;
- fq->prev = head;
- roll->head = fq;
- if (folioq_full(head)) {
+ 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.folioq == head &&
- roll->iter.folioq_slot == folioq_nr_slots(head)) {
- roll->iter.folioq = fq;
- roll->iter.folioq_slot = 0;
+ if (roll->iter.bvecq == head &&
+ roll->iter.bvecq_slot == head->nr_slots) {
+ roll->iter.bvecq = bq;
+ roll->iter.bvecq_slot = 0;
}
}
@@ -110,7 +64,7 @@ int rolling_buffer_make_space(struct rolling_buffer *roll, gfp_t gfp)
* [!] NOTE: After we set head->next, the consumer is at liberty to
* immediately delete the old head.
*/
- smp_store_release(&head->next, fq);
+ bvecq_append(head, bq);
return 0;
}
@@ -119,55 +73,59 @@ 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,
- unsigned int rreq_id, gfp_t gfp)
+ gfp_t gfp)
{
- struct folio_queue *fq;
- ssize_t loaded = 0;
+ struct bvecq *bq;
+ size_t loaded = 0;
while (ractl->_nr_pages - ractl->_batch_count > 0) {
+ struct page **pages;
unsigned int nr;
- /* Allocate a folioq to put some folios into and attach it to
+ /* Allocate a bvecq to put some folios into and attach it to
* the rolling buffer.
*/
- fq = netfs_folioq_alloc(rreq_id, gfp,
- netfs_trace_folioq_make_space);
- if (!fq)
+ bq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, false);
+ if (!bq)
goto nomem_unlock;
- fq->prev = roll->head;
+ bq->mem_type = BVECQ_MEM_EXTERNAL; /* Folio cleanup handled separately. */
+
if (!roll->tail)
- roll->tail = fq;
+ roll->tail = bq;
else
- roll->head->next = fq;
- roll->head = fq;
+ bvecq_append(roll->head, bq);
+ roll->head = bq;
- /* Get a batch of folios and note their orders. */
- nr = __readahead_batch(ractl, (struct page **)fq->vec.folios,
- folioq_nr_slots(fq));
+ /* 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;
- fq->vec.nr = nr;
for (int slot = 0; slot < nr; slot++) {
- struct folio *folio = folioq_folio(fq, slot);
- unsigned int order;
+ struct folio *folio = page_folio(pages[slot]);
+ size_t len = folio_size(folio);
- order = folio_order(folio);
- fq->orders[slot] = order;
- loaded += PAGE_SIZE << order;
+ 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_folio_queue(&roll->iter, ITER_DEST, roll->tail, 0, 0, loaded);
+ iov_iter_bvec_queue(&roll->iter, ITER_DEST, roll->tail, 0, 0, loaded);
return loaded;
nomem_unlock:
- for (fq = roll->tail; fq; fq = fq->next) {
- for (int slot = 0; slot < folioq_count(fq); slot++) {
- folio_unlock(fq->vec.folios[slot]);
- folioq_mark(fq, slot);
+ 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);
@@ -180,7 +138,7 @@ ssize_t rolling_buffer_bulk_load_from_ra(struct rolling_buffer *roll,
* Append a folio to the rolling buffer.
*/
ssize_t rolling_buffer_append(struct rolling_buffer *roll, struct folio *folio,
- unsigned int flags, gfp_t gfp)
+ gfp_t gfp)
{
ssize_t size = folio_size(folio);
int slot;
@@ -188,16 +146,11 @@ ssize_t rolling_buffer_append(struct rolling_buffer *roll, struct folio *folio,
if (rolling_buffer_make_space(roll, gfp) < 0)
return -ENOMEM;
- slot = folioq_append(roll->head, folio);
- if (flags & ROLLBUF_MARK_1)
- folioq_mark(roll->head, slot);
- if (flags & ROLLBUF_MARK_2)
- folioq_mark2(roll->head, slot);
+ 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);
-
- /* Store the counter after setting the slot. */
- smp_store_release(&roll->next_head_slot, slot);
return size;
}
@@ -206,44 +159,23 @@ ssize_t rolling_buffer_append(struct rolling_buffer *roll, struct folio *folio,
* don't return the last buffer to keep the pointers independent, but return
* NULL instead.
*/
-struct folio_queue *rolling_buffer_delete_spent(struct rolling_buffer *roll)
+struct bvecq *rolling_buffer_delete_spent(struct rolling_buffer *roll)
{
- struct folio_queue *spent = roll->tail, *next = READ_ONCE(spent->next);
+ struct bvecq *spent = roll->tail, *next = bvecq_next(spent);
if (!next)
return NULL;
next->prev = NULL;
- netfs_folioq_free(spent, netfs_trace_folioq_delete);
roll->tail = next;
+ spent->next = NULL;
+ bvecq_put(spent);
return next;
}
/*
- * Clear out a rolling queue. Folios that have mark 1 set are put.
+ * Clear out a rolling queue.
*/
void rolling_buffer_clear(struct rolling_buffer *roll)
{
- struct folio_batch fbatch;
- struct folio_queue *p;
-
- folio_batch_init(&fbatch);
-
- while ((p = roll->tail)) {
- roll->tail = p->next;
- for (int slot = 0; slot < folioq_count(p); slot++) {
- struct folio *folio = folioq_folio(p, slot);
-
- if (!folio)
- continue;
- if (folioq_is_marked(p, slot)) {
- trace_netfs_folio(folio, netfs_folio_trace_put);
- if (!folio_batch_add(&fbatch, folio))
- folio_batch_release(&fbatch);
- }
- }
-
- netfs_folioq_free(p, netfs_trace_folioq_clear);
- }
-
- folio_batch_release(&fbatch);
+ bvecq_put(roll->tail);
}
diff --git a/fs/netfs/stats.c b/fs/netfs/stats.c
index 9a607c4e62dda5..0ba6ce9295b257 100644
--- a/fs/netfs/stats.c
+++ b/fs/netfs/stats.c
@@ -46,7 +46,7 @@ atomic_t netfs_n_wh_retry_write_req;
atomic_t netfs_n_wh_retry_write_subreq;
atomic_t netfs_n_wb_lock_skip;
atomic_t netfs_n_wb_lock_wait;
-atomic_t netfs_n_folioq;
+atomic_t netfs_n_bvecq;
int netfs_stats_show(struct seq_file *m, void *v)
{
@@ -88,10 +88,10 @@ int netfs_stats_show(struct seq_file *m, void *v)
atomic_read(&netfs_n_rh_retry_read_subreq),
atomic_read(&netfs_n_wh_retry_write_req),
atomic_read(&netfs_n_wh_retry_write_subreq));
- seq_printf(m, "Objs : rr=%u sr=%u foq=%u wsc=%u\n",
+ seq_printf(m, "Objs : rr=%u sr=%u bq=%u wsc=%u\n",
atomic_read(&netfs_n_rh_rreq),
atomic_read(&netfs_n_rh_sreq),
- atomic_read(&netfs_n_folioq),
+ atomic_read(&netfs_n_bvecq),
atomic_read(&netfs_n_wh_wstream_conflict));
seq_printf(m, "WbLock : skip=%u wait=%u\n",
atomic_read(&netfs_n_wb_lock_skip),
diff --git a/fs/netfs/write_collect.c b/fs/netfs/write_collect.c
index 6e8ea534230df0..91b42820c89252 100644
--- a/fs/netfs/write_collect.c
+++ b/fs/netfs/write_collect.c
@@ -114,11 +114,11 @@ int netfs_folio_written_back(struct folio *folio)
static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,
unsigned int *notes)
{
- struct folio_queue *folioq = wreq->buffer.tail;
+ struct bvecq *bq = wreq->buffer.tail;
unsigned int slot = wreq->buffer.first_tail_slot;
uoff_t collected_to = wreq->collected_to;
- if (WARN_ON_ONCE(!folioq)) {
+ if (WARN_ON_ONCE(!bq)) {
pr_err("[!] Writeback unlock found empty rolling buffer!\n");
netfs_dump_request(wreq);
return;
@@ -130,9 +130,9 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,
return;
}
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = rolling_buffer_delete_spent(&wreq->buffer);
- if (!folioq)
+ while (!bvecq_acquire_slot(bq, slot)) {
+ bq = rolling_buffer_delete_spent(&wreq->buffer);
+ if (!bq)
return;
slot = 0;
}
@@ -143,7 +143,7 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,
uoff_t fpos, fend;
size_t fsize, flen;
- folio = folioq_folio(folioq, slot);
+ folio = bvec_folio(&bq->bv[slot]);
if (WARN_ONCE(!folio_test_writeback(folio),
"R=%08x: folio %lx is not under writeback\n",
wreq->debug_id, folio->index))
@@ -166,15 +166,15 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,
wreq->cleaned_to = fpos + fsize;
*notes |= MADE_PROGRESS;
- /* Clean up the head folioq. If we clear an entire folioq, then
- * we can get rid of it provided it's not also the tail folioq
+ /* 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.
*/
- folioq_clear(folioq, slot);
+ bq->bv[slot].bv_page = NULL;
slot++;
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = rolling_buffer_delete_spent(&wreq->buffer);
- if (!folioq)
+ while (!bvecq_acquire_slot(bq, slot)) {
+ bq = rolling_buffer_delete_spent(&wreq->buffer);
+ if (!bq)
goto done;
slot = 0;
}
@@ -183,7 +183,7 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,
break;
}
- wreq->buffer.tail = folioq;
+ wreq->buffer.tail = bq;
done:
wreq->buffer.first_tail_slot = slot;
}
diff --git a/fs/netfs/write_issue.c b/fs/netfs/write_issue.c
index b8237e1314d8a4..37d1e5055c0ba5 100644
--- a/fs/netfs/write_issue.c
+++ b/fs/netfs/write_issue.c
@@ -107,7 +107,9 @@ 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, wreq->debug_id, ITER_SOURCE, wreq->gfp) < 0)
+ 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;
@@ -163,12 +165,12 @@ void netfs_prepare_write(struct netfs_io_request *wreq,
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 folio_queue
- * struct being used as a placeholder to prevent the queue from
- * collapsing. In such a case, extend the queue.
+ /* 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_folioq(wreq_iter) &&
- wreq_iter->folioq_slot >= folioq_nr_slots(wreq_iter->folioq))
+ 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);
@@ -451,7 +453,7 @@ static int netfs_write_folio(struct netfs_io_request *wreq,
}
/* Attach the folio to the rolling buffer. */
- rolling_buffer_append(&wreq->buffer, folio, 0, wreq->gfp);
+ rolling_buffer_append(&wreq->buffer, folio, wreq->gfp);
/* 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
@@ -625,147 +627,32 @@ int netfs_writepages(struct address_space *mapping,
}
EXPORT_SYMBOL(netfs_writepages);
-/*
- * Write some of a pending folio data back to the server and/or the cache.
- */
-static int netfs_write_folio_single(struct netfs_io_request *wreq,
- struct folio *folio)
-{
- struct netfs_io_stream *upload = &wreq->io_streams[0];
- struct netfs_io_stream *cache = &wreq->io_streams[1];
- struct netfs_io_stream *stream;
- size_t iter_off = 0;
- size_t fsize = folio_size(folio), flen;
- uoff_t fpos = folio_pos(folio);
- ssize_t ret;
- bool to_eof = false;
- bool no_debug = false;
-
- _enter("");
-
- flen = folio_size(folio);
- if (flen > wreq->i_size - fpos) {
- flen = wreq->i_size - fpos;
- folio_zero_segment(folio, flen, fsize);
- to_eof = true;
- } else if (flen == wreq->i_size - fpos) {
- to_eof = true;
- }
-
- _debug("folio %zx/%zx", flen, fsize);
-
- if (!upload->avail && !cache->avail) {
- trace_netfs_folio(folio, netfs_folio_trace_cancel_store);
- return 0;
- }
-
- if (!upload->construct)
- trace_netfs_folio(folio, netfs_folio_trace_store);
- else
- trace_netfs_folio(folio, netfs_folio_trace_store_plus);
-
- /* Attach the folio to the rolling buffer. */
- folio_get(folio);
- ret = rolling_buffer_append(&wreq->buffer, folio, NETFS_ROLLBUF_PUT_MARK, wreq->gfp);
- if (ret < 0) {
- folio_put(folio);
- return ret;
- }
-
- /* 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
- * with the cache as the cache requires DIO alignment.
- *
- * Also skip uploading for data that's been read and just needs copying
- * to the cache.
- */
- for (int s = 0; s < NR_IO_STREAMS; s++) {
- stream = &wreq->io_streams[s];
- stream->submit_off = 0;
- stream->submit_len = flen;
- if (!stream->avail) {
- stream->submit_off = UINT_MAX;
- stream->submit_len = 0;
- }
- }
-
- /* Attach the folio to one or more subrequests. For a big folio, we
- * could end up with thousands of subrequests if the wsize is small -
- * but we might need to wait during the creation of subrequests for
- * network resources (eg. SMB credits).
- */
- for (;;) {
- ssize_t part;
- size_t lowest_off = ULONG_MAX;
- int choose_s = -1;
-
- /* Always add to the lowest-submitted stream first. */
- for (int s = 0; s < NR_IO_STREAMS; s++) {
- stream = &wreq->io_streams[s];
- if (stream->submit_len > 0 &&
- stream->submit_off < lowest_off) {
- lowest_off = stream->submit_off;
- choose_s = s;
- }
- }
-
- if (choose_s < 0)
- 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;
- }
-
- 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;
- if (part > stream->submit_len)
- stream->submit_len = 0;
- else
- stream->submit_len -= part;
- if (part > 0)
- no_debug = true;
- }
-
- wreq->buffer.iter.iov_offset = 0;
- if (fsize > iter_off)
- rolling_buffer_advance(&wreq->buffer, fsize - iter_off);
- atomic64_set(&wreq->issued_to, fpos + fsize);
-
- if (!no_debug)
- kdebug("R=%x: No submit", wreq->debug_id);
- _leave(" = 0");
- return 0;
-}
-
/**
- * netfs_writeback_single - Write back a monolithic payload
+ * netfs_writeback_single - Write back a monolithic payload to cache
* @mapping: The mapping to write from
* @wbc: Hints from the VM
- * @iter: Data to write, must be ITER_FOLIOQ.
+ * @iter: Data buffer to write from.
+ * @len: Amount of data to write.
+ *
+ * Write a monolithic, non-pagecache object back to the cache only. The data
+ * is not written to the server.
*
- * Write a monolithic, non-pagecache object back to the server and/or
- * the cache.
+ * The data buffer may be bigger than @len (as set in @iter's count), and if
+ * so, this function will use the extra as needed to provide padding into the
+ * cache to handle DIO rounding, so the caller should clear it.
*
* 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);
- struct folio_queue *fq;
- size_t size = iov_iter_count(iter);
int ret;
- if (WARN_ON_ONCE(!iov_iter_is_folioq(iter)))
+ if (WARN_ON_ONCE(iov_iter_count(iter) < len))
return -EIO;
if (!netfs_wb_begin(ictx, wbc->sync_mode == WB_SYNC_NONE)) {
@@ -780,36 +667,42 @@ int netfs_writeback_single(struct address_space *mapping,
goto couldnt_start;
}
+ wreq->buffer.iter = *iter;
+ wreq->len = len;
+ wreq->submitted = wreq->len;
+
__set_bit(NETFS_RREQ_OFFLOAD_COLLECTION, &wreq->flags);
trace_netfs_write(wreq, netfs_write_trace_writeback_single);
netfs_stat(&netfs_n_wh_writepages);
- if (__test_and_set_bit(NETFS_RREQ_UPLOAD_TO_SERVER, &wreq->flags))
- wreq->netfs_ops->begin_writeback(wreq);
+ for (int s = 0; s < NR_IO_STREAMS; s++) {
+ struct netfs_io_subrequest *subreq;
+ struct netfs_io_stream *stream = &wreq->io_streams[s];
+
+ if (!stream->avail)
+ continue;
- for (fq = (struct folio_queue *)iter->folioq; fq; fq = fq->next) {
- for (int slot = 0; slot < folioq_count(fq); slot++) {
- struct folio *folio = folioq_folio(fq, slot);
- size_t part = umin(folioq_folio_size(fq, slot), size);
+ netfs_prepare_write(wreq, stream, 0);
+ /* Allocation not allowed to fail in writeback. */
- _debug("wbiter %lx %llx", folio->index, atomic64_read(&wreq->issued_to));
+ subreq = stream->construct;
+ subreq->len = wreq->len;
+ stream->submit_len = subreq->len;
+ stream->submit_extendable_to = iov_iter_count(iter) - len;
- ret = netfs_write_folio_single(wreq, folio);
- if (ret < 0)
- goto stop;
- size -= part;
- if (size <= 0)
- goto stop;
- }
+ netfs_issue_write(wreq, stream);
}
-stop:
- for (int s = 0; s < NR_IO_STREAMS; s++)
- netfs_issue_write(wreq, &wreq->io_streams[s]);
netfs_all_subreqs_queued(wreq);
-
netfs_wake_collector(wreq);
+ /* TODO: Might want to be async here if WB_SYNC_NONE, but then need to
+ * wait before modifying.
+ */
+ ret = netfs_wait_for_write(wreq);
+ if (ret > 0)
+ ret = 0;
+
netfs_put_request(wreq, netfs_rreq_trace_put_return);
_leave(" = %d", ret);
return ret;
diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h
index d3ca688b6aba99..806242d9cce06a 100644
--- a/fs/smb/client/cifsglob.h
+++ b/fs/smb/client/cifsglob.h
@@ -290,7 +290,7 @@ struct smb_rqst {
struct kvec *rq_iov; /* array of kvecs */
unsigned int rq_nvec; /* number of kvecs in array */
struct iov_iter rq_iter; /* Data iterator */
- struct folio_queue *rq_buffer; /* Buffer for encryption */
+ struct bvecq *rq_buffer; /* Buffer for encryption */
};
struct mid_q_entry;
diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c
index dc55cd512616ab..9d462f6e896c33 100644
--- a/fs/smb/client/smb2ops.c
+++ b/fs/smb/client/smb2ops.c
@@ -13,7 +13,7 @@
#include <linux/sort.h>
#include <crypto/aead.h>
#include <linux/fiemap.h>
-#include <linux/folio_queue.h>
+#include <linux/bvecq.h>
#include <uapi/linux/magic.h>
#include "cifsfs.h"
#include "cifsglob.h"
@@ -4918,19 +4918,18 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,
}
/*
- * Copy data from an iterator to the folios in a folio queue buffer.
+ * Copy data from an iterator to the pages in a bvec queue buffer.
*/
-static bool cifs_copy_iter_to_folioq(struct iov_iter *iter, size_t size,
- struct folio_queue *buffer)
+static bool cifs_copy_iter_to_bvecq(struct iov_iter *iter, size_t size,
+ struct bvecq *buffer)
{
for (; buffer; buffer = buffer->next) {
- for (int s = 0; s < folioq_count(buffer); s++) {
- struct folio *folio = folioq_folio(buffer, s);
- size_t part = folioq_folio_size(buffer, s);
+ for (int s = 0; s < bvecq_nr_slots_acquire(buffer); s++) {
+ struct bio_vec *bv = &buffer->bv[s];
+ size_t part = umin(bv->bv_len, size);
- part = umin(part, size);
-
- if (copy_folio_from_iter(folio, 0, part, iter) != part)
+ if (copy_page_from_iter(bv->bv_page, bv->bv_offset,
+ part, iter) != part)
return false;
size -= part;
}
@@ -4942,7 +4941,7 @@ void
smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
{
for (int i = 0; i < num_rqst; i++)
- netfs_free_folioq_buffer(rqst[i].rq_buffer);
+ bvecq_put(rqst[i].rq_buffer);
}
/*
@@ -4969,7 +4968,7 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
for (int i = 1; i < num_rqst; i++) {
struct smb_rqst *old = &old_rq[i - 1];
struct smb_rqst *new = &new_rq[i];
- struct folio_queue *buffer = NULL;
+ struct bvecq *buffer = NULL;
size_t size = iov_iter_count(&old->rq_iter);
orig_len += smb_rqst_len(server, old);
@@ -4977,17 +4976,16 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
new->rq_nvec = old->rq_nvec;
if (size > 0) {
- size_t cur_size = 0;
- rc = netfs_alloc_folioq_buffer(NULL, &buffer, &cur_size,
- size, GFP_NOFS);
- new->rq_buffer = buffer;
- if (rc < 0)
+ rc = -ENOMEM;
+ buffer = bvecq_alloc_buffer(size, GFP_NOFS, true);
+ if (!buffer)
goto err_free;
- iov_iter_folio_queue(&new->rq_iter, ITER_SOURCE,
- buffer, 0, 0, size);
+ new->rq_buffer = buffer;
+ iov_iter_bvec_queue(&new->rq_iter, ITER_SOURCE,
+ buffer, 0, 0, size);
- if (!cifs_copy_iter_to_folioq(&old->rq_iter, size, buffer)) {
+ if (!cifs_copy_iter_to_bvecq(&old->rq_iter, size, buffer)) {
rc = smb_EIO1(smb_eio_trace_tx_copy_iter_to_buf, size);
goto err_free;
}
@@ -5077,22 +5075,20 @@ decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
}
static int
-cifs_copy_folioq_to_iter(struct folio_queue *folioq, size_t data_size,
- size_t skip, struct iov_iter *iter)
+cifs_copy_bvecq_to_iter(struct bvecq *bq, size_t data_size,
+ size_t skip, struct iov_iter *iter)
{
- for (; folioq; folioq = folioq->next) {
- for (int s = 0; s < folioq_count(folioq); s++) {
- struct folio *folio;
- size_t fsize, n, len;
+ for (; bq; bq = bq->next) {
+ for (int s = 0; s < bvecq_nr_slots_acquire(bq); s++) {
+ struct bio_vec *bv = &bq->bv[s];
+ size_t n, len;
if (data_size == 0)
return 0;
- folio = folioq_folio(folioq, s);
- fsize = folio_size(folio);
- len = umin(fsize - skip, data_size);
+ len = umin(bv->bv_len - skip, data_size);
- n = copy_folio_to_iter(folio, skip, len, iter);
+ n = copy_page_to_iter(bv->bv_page, bv->bv_offset + skip, len, iter);
if (n != len) {
cifs_dbg(VFS, "%s: something went wrong\n", __func__);
return smb_EIO2(smb_eio_trace_rx_copy_to_iter,
@@ -5114,7 +5110,7 @@ cifs_copy_folioq_to_iter(struct folio_queue *folioq, size_t data_size,
static int
handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
- char *buf, unsigned int buf_len, struct folio_queue *buffer,
+ char *buf, unsigned int buf_len, struct bvecq *buffer,
unsigned int buffer_len, bool is_offloaded)
{
unsigned int data_offset;
@@ -5224,8 +5220,8 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
}
/* Copy the data to the output I/O iterator. */
- rdata->result = cifs_copy_folioq_to_iter(buffer, data_len,
- cur_off, &rdata->subreq.io_iter);
+ rdata->result = cifs_copy_bvecq_to_iter(buffer, data_len,
+ cur_off, &rdata->subreq.io_iter);
if (rdata->result != 0) {
if (is_offloaded)
mid->mid_state = MID_RESPONSE_MALFORMED;
@@ -5264,7 +5260,7 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
struct smb2_decrypt_work {
struct work_struct decrypt;
struct TCP_Server_Info *server;
- struct folio_queue *buffer;
+ struct bvecq *buffer;
char *buf;
unsigned int len;
};
@@ -5278,7 +5274,7 @@ static void smb2_decrypt_offload(struct work_struct *work)
struct mid_q_entry *mid;
struct iov_iter iter;
- iov_iter_folio_queue(&iter, ITER_DEST, dw->buffer, 0, 0, dw->len);
+ iov_iter_bvec_queue(&iter, ITER_DEST, dw->buffer, 0, 0, dw->len);
rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
&iter, true);
if (rc) {
@@ -5328,7 +5324,7 @@ static void smb2_decrypt_offload(struct work_struct *work)
}
free_pages:
- netfs_free_folioq_buffer(dw->buffer);
+ bvecq_put(dw->buffer);
cifs_small_buf_release(dw->buf);
kfree(dw);
}
@@ -5374,12 +5370,12 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
dw->len = len;
len = round_up(dw->len, PAGE_SIZE);
- size_t cur_size = 0;
- rc = netfs_alloc_folioq_buffer(NULL, &dw->buffer, &cur_size, len, GFP_NOFS);
- if (rc < 0)
+ rc = -ENOMEM;
+ dw->buffer = bvecq_alloc_buffer(len, GFP_NOFS, false);
+ if (!dw->buffer)
goto discard_data;
- iov_iter_folio_queue(&iter, ITER_DEST, dw->buffer, 0, 0, len);
+ iov_iter_bvec_queue(&iter, ITER_DEST, dw->buffer, 0, 0, len);
/* Read the data into the buffer and clear excess bufferage. */
rc = cifs_read_iter_from_socket(server, &iter, dw->len);
@@ -5439,7 +5435,7 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
}
free_pages:
- netfs_free_folioq_buffer(dw->buffer);
+ bvecq_put(dw->buffer);
free_dw:
kfree(dw);
return rc;
diff --git a/fs/smb/smbdirect/connection.c b/fs/smb/smbdirect/connection.c
index e6c7b343fe8703..210e53495fe8f4 100644
--- a/fs/smb/smbdirect/connection.c
+++ b/fs/smb/smbdirect/connection.c
@@ -5,7 +5,7 @@
*/
#include "internal.h"
-#include <linux/folio_queue.h>
+#include <linux/bvecq.h>
struct smbdirect_map_sges {
struct ib_sge *sge;
@@ -2015,6 +2015,69 @@ static ssize_t smbdirect_map_sges_from_bvec(struct iov_iter *iter,
return ret;
}
+/*
+ * Extract memory fragments from a BVECQ-class iterator and add them to an RDMA
+ * list. The fragments are not pinned.
+ */
+static ssize_t smbdirect_map_sges_from_bvecq(struct iov_iter *iter,
+ struct smbdirect_map_sges *state,
+ ssize_t maxsize)
+{
+ const struct bvecq *bq = iter->bvecq, *next;
+ unsigned int slot = iter->bvecq_slot;
+ ssize_t extracted = 0;
+ size_t offset = iter->iov_offset;
+
+ maxsize = umin(maxsize, iov_iter_count(iter));
+
+ do {
+ struct bio_vec *bv;
+ size_t bsize;
+
+ while (slot >= bq->nr_slots) {
+ next = bvecq_next(bq);
+ if (!next) {
+ if (WARN_ON_ONCE(maxsize > 0))
+ return -EIO;
+ goto out;
+ }
+ bq = next;
+ slot = 0;
+ }
+
+ bv = &bq->bv[slot];
+ bsize = bv->bv_len;
+
+ if (offset < bsize) {
+ size_t part = umin(maxsize, bsize - offset);
+ bool ok;
+
+ ok = smbdirect_map_sges_single_page(state,
+ bv->bv_page,
+ bv->bv_offset + offset,
+ part);
+ if (!ok)
+ return -EIO;
+
+ offset += part;
+ extracted += part;
+ maxsize -= part;
+ }
+
+ if (offset >= bsize) {
+ offset = 0;
+ slot++;
+ }
+ } while (state->num_sge < state->max_sge && maxsize > 0);
+
+out:
+ iter->bvecq = bq;
+ iter->bvecq_slot = slot;
+ iter->iov_offset = offset;
+ iter->count -= extracted;
+ return extracted;
+}
+
/*
* Extract fragments from a KVEC-class iterator and add them to an ib_sge list.
* This can deal with vmalloc'd buffers as well as kmalloc'd or static buffers.
@@ -2076,70 +2139,6 @@ static ssize_t smbdirect_map_sges_from_kvec(struct iov_iter *iter,
return ret;
}
-/*
- * Extract folio fragments from a FOLIOQ-class iterator and add them to an
- * ib_sge list. The folios are not pinned.
- */
-static ssize_t smbdirect_map_sges_from_folioq(struct iov_iter *iter,
- struct smbdirect_map_sges *state,
- ssize_t maxsize)
-{
- const struct folio_queue *folioq = iter->folioq;
- unsigned int slot = iter->folioq_slot;
- ssize_t ret = 0;
- size_t offset = iter->iov_offset;
-
- if (WARN_ON_ONCE(!folioq))
- return -EIO;
-
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = folioq->next;
- if (WARN_ON_ONCE(!folioq))
- return -EIO;
- slot = 0;
- }
-
- do {
- struct folio *folio = folioq_folio(folioq, slot);
- size_t fsize = folioq_folio_size(folioq, slot);
-
- if (offset < fsize) {
- size_t part = umin(maxsize, fsize - offset);
- bool ok;
-
- ok = smbdirect_map_sges_single_page(state,
- folio_page(folio, 0),
- offset,
- part);
- if (!ok)
- return -EIO;
-
- offset += part;
- ret += part;
- maxsize -= part;
- }
-
- if (offset >= fsize) {
- offset = 0;
- slot++;
- if (slot >= folioq_nr_slots(folioq)) {
- if (!folioq->next) {
- WARN_ON_ONCE(ret < iter->count);
- break;
- }
- folioq = folioq->next;
- slot = 0;
- }
- }
- } while (state->num_sge < state->max_sge && maxsize > 0);
-
- iter->folioq = folioq;
- iter->folioq_slot = slot;
- iter->iov_offset = offset;
- iter->count -= ret;
- return ret;
-}
-
/*
* Extract page fragments from up to the given amount of the source iterator
* and build up an ib_sge list that refers to all of those bits. The ib_sge list
@@ -2164,12 +2163,12 @@ static ssize_t smbdirect_map_sges_from_iter(struct iov_iter *iter, size_t len,
case ITER_BVEC:
ret = smbdirect_map_sges_from_bvec(iter, state, len);
break;
+ case ITER_BVECQ:
+ ret = smbdirect_map_sges_from_bvecq(iter, state, len);
+ break;
case ITER_KVEC:
ret = smbdirect_map_sges_from_kvec(iter, state, len);
break;
- case ITER_FOLIOQ:
- ret = smbdirect_map_sges_from_folioq(iter, state, len);
- break;
default:
WARN_ONCE(1, "iov_iter_type[%u]\n", iov_iter_type(iter));
return -EIO;
diff --git a/include/linux/bvec.h b/include/linux/bvec.h
index b63914ff56e33d..7ea62643cfb7cc 100644
--- a/include/linux/bvec.h
+++ b/include/linux/bvec.h
@@ -344,4 +344,22 @@ static inline phys_addr_t bvec_phys(const struct bio_vec *bvec)
return page_to_phys(bvec->bv_page) + bvec->bv_offset;
}
+/**
+ * bvec_kmap_partial - Map part of a bvec into the kernel virtual address space
+ * @bvec: bvec to map
+ * @offset: Offset into bvec
+ *
+ * Map the page containing the byte at @offset into the kernel virtual address
+ * space. The caller is responsible for making sure this doesn't overrun.
+ *
+ * Call kunmap_local on the returned address to unmap.
+ */
+static inline void *bvec_kmap_partial(const struct bio_vec *bvec, size_t offset)
+{
+ offset += bvec->bv_offset;
+
+ return kmap_local_page(bvec->bv_page + (offset >> PAGE_SHIFT)) +
+ (offset & ~PAGE_MASK);
+}
+
#endif /* __LINUX_BVEC_H */
diff --git a/include/linux/bvecq.h b/include/linux/bvecq.h
new file mode 100644
index 00000000000000..90e6eb9588bf8b
--- /dev/null
+++ b/include/linux/bvecq.h
@@ -0,0 +1,176 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Implementation of a segmented queue of bio_vec[].
+ *
+ * Copyright (C) 2026 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * See also Documentation/core-api/bvecq.rst
+ */
+
+#ifndef _LINUX_BVECQ_H
+#define _LINUX_BVECQ_H
+
+#include <linux/bvec.h>
+
+/*
+ * The type of memory retention used by the elements in bvecq->bv[] and how to
+ * clean it up.
+ */
+enum bvecq_mem {
+ BVECQ_MEM_EXTERNAL, /* Externally retained memory - no freeing */
+ BVECQ_MEM_PAGECACHE, /* Ref'd pagecache pages - must put */
+ BVECQ_MEM_GUP, /* Pinned memory from get_user_pages() - unpin */
+ BVECQ_MEM_ALLOCED, /* Memory alloc'd by bvecq - can be freed/pooled */
+} __mode(byte);
+
+/*
+ * Segmented bio_vec queue.
+ *
+ * These can be linked together to form messages of indefinite length and
+ * iterated over with an ITER_BVECQ iterator. The list is non-circular; next
+ * and prev are NULL at the ends.
+ *
+ * The bv pointer points to the bio_vec array; this may be __bv if allocated
+ * together. The caller is responsible for determining whether or not this is
+ * the case as the array pointed to by bv may be follow on directly from the
+ * bvecq by accident of allocation (ie. ->bv == ->__bv is *not* sufficient to
+ * determine this).
+ */
+struct bvecq {
+ struct bvecq *next; /* Next bvec in the list or NULL */
+ struct bvecq *prev; /* Prev bvec in the list or NULL */
+ refcount_t ref;
+ u32 priv; /* Private data */
+ u16 nr_slots; /* Number of elements in bv[] used */
+ u16 max_slots; /* Number of elements allocated in bv[] */
+ enum bvecq_mem mem_type:3; /* What sort of memory and how to free it */
+ bool inline_bv:1; /* T if __bv[] is being used */
+ bool from_pool:1; /* T if bvecq from mempool */
+ struct bio_vec *bv; /* Pointer to array of page fragments */
+ struct bio_vec __bv[]; /* Default array (if ->inline_bv) */
+};
+
+/* Number of slots in a 512-byte mempool-backed bvecq. */
+#define BVECQ_POOL_SIZE 512
+#define BVECQ_POOL_SLOTS ((BVECQ_POOL_SIZE - sizeof(struct bvecq)) / sizeof(struct bio_vec))
+
+/* Number of slots in a 4K bvecq. */
+#define BVECQ_4KB_SLOTS ((4096 - sizeof(struct bvecq)) / sizeof(struct bio_vec))
+
+/* Maximum number of slots in an inline allocation */
+#define BVECQ_MAX_INLINE_SLOTS USHRT_MAX
+
+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);
+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);
+
+/**
+ * bvecq_alloc_buffer - Allocate a bvecq chain and populate with buffers
+ * @size: Target size of the buffer (can be 0 for an empty buffer)
+ * @gfp: The allocation constraints.
+ * @for_writeback: True if allocating for writeback
+ *
+ * Wrapper around ``bvecq_alloc_buffer2()``.
+ *
+ * Return: The first node pointer or NULL on allocation failure.
+ */
+static inline struct bvecq *bvecq_alloc_buffer(size_t size, gfp_t gfp, bool for_writeback)
+{
+ return bvecq_alloc_buffer2(size, 0, gfp, for_writeback);
+}
+
+/**
+ * bvecq_get - Get a ref on a bvecq
+ * @bq: The bvecq to get a ref on
+ *
+ * Return: @bq.
+ */
+static inline struct bvecq *bvecq_get(struct bvecq *bq)
+{
+ refcount_inc(&bq->ref);
+ return bq;
+}
+
+/**
+ * bvecq_is_full - Determine if a bvecq is full
+ * @bvecq: The object to query
+ *
+ * Return: true if full; false if not.
+ */
+static inline bool bvecq_is_full(const struct bvecq *bvecq)
+{
+ return bvecq->nr_slots >= bvecq->max_slots;
+}
+
+/**
+ * bvecq_filled_to - Release filled slots with release barrier
+ * @bvecq: The object modified
+ * @to: The latest slot filled + 1
+ */
+static inline void bvecq_filled_to(struct bvecq *bvecq, unsigned int to)
+{
+ /* Set the slot counter after filling the slot */
+ smp_store_release(&bvecq->nr_slots, to);
+}
+
+/**
+ * bvecq_nr_slots_acquire - Get the number of filled slots with acquire barrier
+ * @bvecq: The object to query
+ *
+ * Return: The number of filled slots
+ */
+static inline unsigned int bvecq_nr_slots_acquire(const struct bvecq *bvecq)
+{
+ /* Read the slot counter before looking at the slot */
+ return smp_load_acquire(&bvecq->nr_slots);
+}
+
+/**
+ * bvecq_acquire_slot - Determine if a slot is valid with acquire barrier
+ * @bvecq: The object to query
+ * @slot: The next slot
+ *
+ * Return: true if valid; false if might not be valid
+ */
+static inline bool bvecq_acquire_slot(const struct bvecq *bvecq, unsigned int slot)
+{
+ /* Read the slot counter before looking at the slot */
+ return slot < bvecq_nr_slots_acquire(bvecq);
+}
+
+/**
+ * bvecq_append - Get the next bvecq with appropriate barrier
+ * @to: The bvecq to append to
+ * @add: The bvecq to append
+ *
+ * Attach a new bvecq to a chain using an appropriate barrier to protect the
+ * write.
+ *
+ * [!] Note that this function transfers the caller's ref to the chain.
+ */
+static inline void bvecq_append(struct bvecq *to, struct bvecq *add)
+{
+ add->prev = to;
+
+ /* Make sure the initialisation is stored before the next pointer. */
+ smp_store_release(&to->next, add);
+}
+
+/**
+ * bvecq_next - Get the next bvecq with appropriate barrier
+ * @bq: The bvecq to start from
+ *
+ * Return: The next bvecq in a chain, using an appropriate barrier to protect
+ * the access.
+ */
+static inline struct bvecq *bvecq_next(const struct bvecq *bq)
+{
+ /* Read the contents of the next node after the pointer to it. */
+ return smp_load_acquire(&bq->next);
+}
+
+#endif /* _LINUX_BVECQ_H */
diff --git a/include/linux/folio_queue.h b/include/linux/folio_queue.h
deleted file mode 100644
index f6d5f1f127c9f3..00000000000000
--- a/include/linux/folio_queue.h
+++ /dev/null
@@ -1,282 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/* Queue of folios definitions
- *
- * Copyright (C) 2024 Red Hat, Inc. All Rights Reserved.
- * Written by David Howells (dhowells@redhat.com)
- *
- * See:
- *
- * Documentation/core-api/folio_queue.rst
- *
- * for a description of the API.
- */
-
-#ifndef _LINUX_FOLIO_QUEUE_H
-#define _LINUX_FOLIO_QUEUE_H
-
-#include <linux/folio_batch.h>
-#include <linux/mm.h>
-
-/*
- * Segment in a queue of running buffers. Each segment can hold a number of
- * folios and a portion of the queue can be referenced with the ITER_FOLIOQ
- * iterator. The possibility exists of inserting non-folio elements into the
- * queue (such as gaps).
- *
- * Explicit prev and next pointers are used instead of a list_head to make it
- * easier to add segments to tail and remove them from the head without the
- * need for a lock.
- */
-struct folio_queue {
- struct folio_batch vec; /* Folios in the queue segment */
- u8 orders[FOLIO_BATCH_SIZE]; /* Order of each folio */
- struct folio_queue *next; /* Next queue segment or NULL */
- struct folio_queue *prev; /* Previous queue segment of NULL */
- unsigned long marks; /* 1-bit mark per folio */
- unsigned long marks2; /* Second 1-bit mark per folio */
-#if FOLIO_BATCH_SIZE > BITS_PER_LONG
-#error marks is not big enough
-#endif
- unsigned int rreq_id;
- unsigned int debug_id;
-};
-
-/**
- * folioq_init - Initialise a folio queue segment
- * @folioq: The segment to initialise
- * @rreq_id: The request identifier to use in tracelines.
- *
- * Initialise a folio queue segment and set an identifier to be used in traces.
- *
- * Note that the folio pointers are left uninitialised.
- */
-static inline void folioq_init(struct folio_queue *folioq, unsigned int rreq_id)
-{
- folio_batch_init(&folioq->vec);
- folioq->next = NULL;
- folioq->prev = NULL;
- folioq->marks = 0;
- folioq->marks2 = 0;
- folioq->rreq_id = rreq_id;
- folioq->debug_id = 0;
-}
-
-/**
- * folioq_nr_slots: Query the capacity of a folio queue segment
- * @folioq: The segment to query
- *
- * Query the number of folios that a particular folio queue segment might hold.
- * [!] NOTE: This must not be assumed to be the same for every segment!
- */
-static inline unsigned int folioq_nr_slots(const struct folio_queue *folioq)
-{
- return FOLIO_BATCH_SIZE;
-}
-
-/**
- * folioq_count: Query the occupancy of a folio queue segment
- * @folioq: The segment to query
- *
- * Query the number of folios that have been added to a folio queue segment.
- * Note that this is not decreased as folios are removed from a segment.
- */
-static inline unsigned int folioq_count(struct folio_queue *folioq)
-{
- return folio_batch_count(&folioq->vec);
-}
-
-/**
- * folioq_full: Query if a folio queue segment is full
- * @folioq: The segment to query
- *
- * Query if a folio queue segment is fully occupied. Note that this does not
- * change if folios are removed from a segment.
- */
-static inline bool folioq_full(struct folio_queue *folioq)
-{
- //return !folio_batch_space(&folioq->vec);
- return folioq_count(folioq) >= folioq_nr_slots(folioq);
-}
-
-/**
- * folioq_is_marked: Check first folio mark in a folio queue segment
- * @folioq: The segment to query
- * @slot: The slot number of the folio to query
- *
- * Determine if the first mark is set for the folio in the specified slot in a
- * folio queue segment.
- */
-static inline bool folioq_is_marked(const struct folio_queue *folioq, unsigned int slot)
-{
- return test_bit(slot, &folioq->marks);
-}
-
-/**
- * folioq_mark: Set the first mark on a folio in a folio queue segment
- * @folioq: The segment to modify
- * @slot: The slot number of the folio to modify
- *
- * Set the first mark for the folio in the specified slot in a folio queue
- * segment.
- */
-static inline void folioq_mark(struct folio_queue *folioq, unsigned int slot)
-{
- set_bit(slot, &folioq->marks);
-}
-
-/**
- * folioq_unmark: Clear the first mark on a folio in a folio queue segment
- * @folioq: The segment to modify
- * @slot: The slot number of the folio to modify
- *
- * Clear the first mark for the folio in the specified slot in a folio queue
- * segment.
- */
-static inline void folioq_unmark(struct folio_queue *folioq, unsigned int slot)
-{
- clear_bit(slot, &folioq->marks);
-}
-
-/**
- * folioq_is_marked2: Check second folio mark in a folio queue segment
- * @folioq: The segment to query
- * @slot: The slot number of the folio to query
- *
- * Determine if the second mark is set for the folio in the specified slot in a
- * folio queue segment.
- */
-static inline bool folioq_is_marked2(const struct folio_queue *folioq, unsigned int slot)
-{
- return test_bit(slot, &folioq->marks2);
-}
-
-/**
- * folioq_mark2: Set the second mark on a folio in a folio queue segment
- * @folioq: The segment to modify
- * @slot: The slot number of the folio to modify
- *
- * Set the second mark for the folio in the specified slot in a folio queue
- * segment.
- */
-static inline void folioq_mark2(struct folio_queue *folioq, unsigned int slot)
-{
- set_bit(slot, &folioq->marks2);
-}
-
-/**
- * folioq_unmark2: Clear the second mark on a folio in a folio queue segment
- * @folioq: The segment to modify
- * @slot: The slot number of the folio to modify
- *
- * Clear the second mark for the folio in the specified slot in a folio queue
- * segment.
- */
-static inline void folioq_unmark2(struct folio_queue *folioq, unsigned int slot)
-{
- clear_bit(slot, &folioq->marks2);
-}
-
-/**
- * folioq_append: Add a folio to a folio queue segment
- * @folioq: The segment to add to
- * @folio: The folio to add
- *
- * Add a folio to the tail of the sequence in a folio queue segment, increasing
- * the occupancy count and returning the slot number for the folio just added.
- * The folio size is extracted and stored in the queue and the marks are left
- * unmodified.
- *
- * Note that it's left up to the caller to check that the segment capacity will
- * not be exceeded and to extend the queue.
- */
-static inline unsigned int folioq_append(struct folio_queue *folioq, struct folio *folio)
-{
- unsigned int slot = folioq->vec.nr++;
-
- folioq->vec.folios[slot] = folio;
- folioq->orders[slot] = folio_order(folio);
- return slot;
-}
-
-/**
- * folioq_append_mark: Add a folio to a folio queue segment
- * @folioq: The segment to add to
- * @folio: The folio to add
- *
- * Add a folio to the tail of the sequence in a folio queue segment, increasing
- * the occupancy count and returning the slot number for the folio just added.
- * The folio size is extracted and stored in the queue, the first mark is set
- * and and the second and third marks are left unmodified.
- *
- * Note that it's left up to the caller to check that the segment capacity will
- * not be exceeded and to extend the queue.
- */
-static inline unsigned int folioq_append_mark(struct folio_queue *folioq, struct folio *folio)
-{
- unsigned int slot = folioq->vec.nr++;
-
- folioq->vec.folios[slot] = folio;
- folioq->orders[slot] = folio_order(folio);
- folioq_mark(folioq, slot);
- return slot;
-}
-
-/**
- * folioq_folio: Get a folio from a folio queue segment
- * @folioq: The segment to access
- * @slot: The folio slot to access
- *
- * Retrieve the folio in the specified slot from a folio queue segment. Note
- * that no bounds check is made and if the slot hasn't been added into yet, the
- * pointer will be undefined. If the slot has been cleared, NULL will be
- * returned.
- */
-static inline struct folio *folioq_folio(const struct folio_queue *folioq, unsigned int slot)
-{
- return folioq->vec.folios[slot];
-}
-
-/**
- * folioq_folio_order: Get the order of a folio from a folio queue segment
- * @folioq: The segment to access
- * @slot: The folio slot to access
- *
- * Retrieve the order of the folio in the specified slot from a folio queue
- * segment. Note that no bounds check is made and if the slot hasn't been
- * added into yet, the order returned will be 0.
- */
-static inline unsigned int folioq_folio_order(const struct folio_queue *folioq, unsigned int slot)
-{
- return folioq->orders[slot];
-}
-
-/**
- * folioq_folio_size: Get the size of a folio from a folio queue segment
- * @folioq: The segment to access
- * @slot: The folio slot to access
- *
- * Retrieve the size of the folio in the specified slot from a folio queue
- * segment. Note that no bounds check is made and if the slot hasn't been
- * added into yet, the size returned will be PAGE_SIZE.
- */
-static inline size_t folioq_folio_size(const struct folio_queue *folioq, unsigned int slot)
-{
- return PAGE_SIZE << folioq_folio_order(folioq, slot);
-}
-
-/**
- * folioq_clear: Clear a folio from a folio queue segment
- * @folioq: The segment to clear
- * @slot: The folio slot to clear
- *
- * Clear a folio from a sequence in a folio queue segment and clear its marks.
- * The occupancy count is left unchanged.
- */
-static inline void folioq_clear(struct folio_queue *folioq, unsigned int slot)
-{
- folioq->vec.folios[slot] = NULL;
- folioq_unmark(folioq, slot);
- folioq_unmark2(folioq, slot);
-}
-
-#endif /* _LINUX_FOLIO_QUEUE_H */
diff --git a/include/linux/iov_iter.h b/include/linux/iov_iter.h
index 2f91884d733bfd..e88930af7f3695 100644
--- a/include/linux/iov_iter.h
+++ b/include/linux/iov_iter.h
@@ -10,7 +10,7 @@
#include <linux/uio.h>
#include <linux/bvec.h>
-#include <linux/folio_queue.h>
+#include <linux/bvecq.h>
typedef size_t (*iov_step_f)(void *iter_base, size_t progress, size_t len,
void *priv, void *priv2);
@@ -142,56 +142,65 @@ size_t iterate_bvec(struct iov_iter *iter, size_t len, void *priv, void *priv2,
}
/*
- * Handle ITER_FOLIOQ.
+ * Handle ITER_BVECQ.
*/
static __always_inline
-size_t iterate_folioq(struct iov_iter *iter, size_t len, void *priv, void *priv2,
- iov_step_f step)
+size_t iterate_bvecq(struct iov_iter *iter, size_t len, void *priv, void *priv2,
+ iov_step_f step)
{
- const struct folio_queue *folioq = iter->folioq;
- unsigned int slot = iter->folioq_slot;
+ const struct bvecq *bq = iter->bvecq;
+ unsigned int slot = iter->bvecq_slot;
size_t progress = 0, skip = iter->iov_offset;
- if (slot == folioq_nr_slots(folioq)) {
- /* The iterator may have been extended. */
- folioq = folioq->next;
- slot = 0;
- }
-
do {
- struct folio *folio = folioq_folio(folioq, slot);
- size_t part, remain = 0, consumed;
- size_t fsize;
+ const struct bio_vec *bvec;
+ struct page *page;
+ size_t poff, plen;
void *base;
- if (!folio)
- break;
+ if (slot >= bq->nr_slots) {
+ if (!bq->next)
+ break;
+ bq = bq->next;
+ slot = 0;
+ continue;
+ }
+
+ bvec = &bq->bv[slot];
+ /*
+ * The caller must ensure that a slot with bv_len>0 has a valid
+ * bv_page.
+ */
+ page = bvec->bv_page + (bvec->bv_offset + skip) / PAGE_SIZE;
+ poff = (bvec->bv_offset + skip) % PAGE_SIZE;
+ plen = min(bvec->bv_len - skip, len);
+
+ while (plen > 0) {
+ size_t part, remain, consumed;
- fsize = folioq_folio_size(folioq, slot);
- if (skip < fsize) {
- base = kmap_local_folio(folio, skip);
- part = umin(len, PAGE_SIZE - skip % PAGE_SIZE);
+ part = min(plen, PAGE_SIZE - poff);
+ base = kmap_local_page(page) + poff;
remain = step(base, progress, part, priv, priv2);
kunmap_local(base);
+
consumed = part - remain;
- len -= consumed;
progress += consumed;
skip += consumed;
+ len -= consumed;
+ if (!len || remain)
+ goto stop;
+ page++;
+ poff = 0;
+ plen -= consumed;
}
- if (skip >= fsize) {
- skip = 0;
- slot++;
- if (slot == folioq_nr_slots(folioq) && folioq->next) {
- folioq = folioq->next;
- slot = 0;
- }
- }
- if (remain)
- break;
+
+ skip = 0;
+ slot++;
} while (len);
- iter->folioq_slot = slot;
- iter->folioq = folioq;
+stop:
+ iter->bvecq_slot = slot;
+ iter->bvecq = bq;
iter->iov_offset = skip;
iter->count -= progress;
return progress;
@@ -306,8 +315,8 @@ size_t iterate_and_advance2(struct iov_iter *iter, size_t len, void *priv,
return iterate_bvec(iter, len, priv, priv2, step);
if (iov_iter_is_kvec(iter))
return iterate_kvec(iter, len, priv, priv2, step);
- if (iov_iter_is_folioq(iter))
- return iterate_folioq(iter, len, priv, priv2, step);
+ if (iov_iter_is_bvecq(iter))
+ return iterate_bvecq(iter, len, priv, priv2, step);
if (iov_iter_is_xarray(iter))
return iterate_xarray(iter, len, priv, priv2, step);
if (WARN_ON_ONCE(iov_iter_is_dmabuf_map(iter)))
@@ -344,7 +353,7 @@ size_t iterate_and_advance(struct iov_iter *iter, size_t len, void *priv,
* buffer is presented in segments, which for kernel iteration are broken up by
* physical pages and mapped, with the mapped address being presented.
*
- * [!] Note This will only handle BVEC, KVEC, FOLIOQ, XARRAY and DISCARD-type
+ * [!] Note This will only handle BVEC, KVEC, BVECQ, XARRAY and DISCARD-type
* iterators; it will not handle UBUF or IOVEC-type iterators.
*
* A step functions, @step, must be provided, one for handling mapped kernel
@@ -372,8 +381,8 @@ size_t iterate_and_advance_kernel(struct iov_iter *iter, size_t len, void *priv,
return iterate_bvec(iter, len, priv, priv2, step);
if (iov_iter_is_kvec(iter))
return iterate_kvec(iter, len, priv, priv2, step);
- if (iov_iter_is_folioq(iter))
- return iterate_folioq(iter, len, priv, priv2, step);
+ if (iov_iter_is_bvecq(iter))
+ return iterate_bvecq(iter, len, priv, priv2, step);
if (iov_iter_is_xarray(iter))
return iterate_xarray(iter, len, priv, priv2, step);
return iterate_discard(iter, len, priv, priv2, step);
diff --git a/include/linux/netfs.h b/include/linux/netfs.h
index e5961450f3f154..ac6a4470b60fd1 100644
--- a/include/linux/netfs.h
+++ b/include/linux/netfs.h
@@ -17,13 +17,13 @@
#include <linux/workqueue.h>
#include <linux/fs.h>
#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 fscache_occupancy;
-struct folio_queue;
/**
* folio_start_private_2 - Start an fscache write on a folio. [DEPRECATED]
@@ -248,8 +248,6 @@ struct netfs_io_request {
#define NR_IO_STREAMS 2 //wreq->nr_io_streams
struct netfs_group *group; /* Writeback group being written back */
struct rolling_buffer buffer; /* Unencrypted buffer */
-#define NETFS_ROLLBUF_PUT_MARK ROLLBUF_MARK_1
-#define NETFS_ROLLBUF_PAGECACHE_MARK ROLLBUF_MARK_2
wait_queue_head_t waitq; /* Processor waiter */
void *netfs_priv; /* Private data for the netfs */
void *netfs_priv2; /* Private data for the netfs */
@@ -429,7 +427,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;
@@ -471,18 +469,6 @@ void netfs_end_io_write(struct inode *inode);
int netfs_start_io_direct(struct inode *inode);
void netfs_end_io_direct(struct inode *inode);
-/* Miscellaneous APIs. */
-struct folio_queue *netfs_folioq_alloc(unsigned int rreq_id, gfp_t gfp,
- unsigned int trace /*enum netfs_folioq_trace*/);
-void netfs_folioq_free(struct folio_queue *folioq,
- unsigned int trace /*enum netfs_trace_folioq*/);
-
-/* Buffer wrangling helpers API. */
-int netfs_alloc_folioq_buffer(struct address_space *mapping,
- struct folio_queue **_buffer,
- size_t *_cur_size, ssize_t size, gfp_t gfp);
-void netfs_free_folioq_buffer(struct folio_queue *fq);
-
/* Writeback exclusion API. */
bool netfs_wb_begin(struct netfs_inode *ictx, bool nowait);
void netfs_wb_end(struct netfs_inode *ictx);
diff --git a/include/linux/rolling_buffer.h b/include/linux/rolling_buffer.h
index a97f7cfaacaad7..5c0bc4221f010c 100644
--- a/include/linux/rolling_buffer.h
+++ b/include/linux/rolling_buffer.h
@@ -8,49 +8,35 @@
#ifndef _ROLLING_BUFFER_H
#define _ROLLING_BUFFER_H
-#include <linux/folio_queue.h>
+#include <linux/bvecq.h>
#include <linux/uio.h>
/*
- * Rolling buffer. Whilst the buffer is live and in use, folios and folio
- * queue 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 folio_queue in it so that neither side has to
- * modify both queue pointers.
+ * 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 folio_queue *head; /* Producer's insertion point */
- struct folio_queue *tail; /* Consumer's removal point */
+ 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 next_head_slot; /* Next slot in ->head */
u8 first_tail_slot; /* First slot in ->tail */
+ bool for_writeback; /* T if being used for writeback */
};
-/*
- * Snapshot of a rolling buffer.
- */
-struct rolling_buffer_snapshot {
- struct folio_queue *curr_folioq; /* Queue segment in which current folio resides */
- unsigned char curr_slot; /* Folio currently being read */
- unsigned char curr_order; /* Order of folio */
-};
-
-/* Marks to store per-folio in the internal folio_queue structs. */
-#define ROLLBUF_MARK_1 BIT(0)
-#define ROLLBUF_MARK_2 BIT(1)
-
-int rolling_buffer_init(struct rolling_buffer *roll, unsigned int rreq_id,
- unsigned int direction, gfp_t gfp);
+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,
- unsigned int rreq_id, gfp_t gfp);
-ssize_t rolling_buffer_append(struct rolling_buffer *roll, struct folio *folio,
- unsigned int flags, gfp_t gfp);
-struct folio_queue *rolling_buffer_delete_spent(struct rolling_buffer *roll);
+ 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)
diff --git a/include/linux/uio.h b/include/linux/uio.h
index 638c1116e912e7..3fc98542922e31 100644
--- a/include/linux/uio.h
+++ b/include/linux/uio.h
@@ -11,7 +11,6 @@
#include <uapi/linux/uio.h>
struct page;
-struct folio_queue;
struct dma_buf_io_map;
typedef unsigned int __bitwise iov_iter_extraction_t;
@@ -27,7 +26,7 @@ enum iter_type {
ITER_IOVEC,
ITER_BVEC,
ITER_KVEC,
- ITER_FOLIOQ,
+ ITER_BVECQ,
ITER_XARRAY,
ITER_DISCARD,
ITER_DMABUF_MAP,
@@ -70,7 +69,7 @@ struct iov_iter {
const struct iovec *__iov;
const struct kvec *kvec;
const struct bio_vec *bvec;
- const struct folio_queue *folioq;
+ const struct bvecq *bvecq;
struct xarray *xarray;
void __user *ubuf;
struct dma_buf_io_map *dmabuf_map;
@@ -80,7 +79,7 @@ struct iov_iter {
};
union {
unsigned long nr_segs;
- u8 folioq_slot;
+ u16 bvecq_slot;
loff_t xarray_start;
};
};
@@ -148,9 +147,9 @@ static inline bool iov_iter_is_discard(const struct iov_iter *i)
return iov_iter_type(i) == ITER_DISCARD;
}
-static inline bool iov_iter_is_folioq(const struct iov_iter *i)
+static inline bool iov_iter_is_bvecq(const struct iov_iter *i)
{
- return iov_iter_type(i) == ITER_FOLIOQ;
+ return iov_iter_type(i) == ITER_BVECQ;
}
static inline bool iov_iter_is_xarray(const struct iov_iter *i)
@@ -303,9 +302,9 @@ void iov_iter_kvec(struct iov_iter *i, unsigned int direction, const struct kvec
void iov_iter_bvec(struct iov_iter *i, unsigned int direction, const struct bio_vec *bvec,
unsigned long nr_segs, size_t count);
void iov_iter_discard(struct iov_iter *i, unsigned int direction, size_t count);
-void iov_iter_folio_queue(struct iov_iter *i, unsigned int direction,
- const struct folio_queue *folioq,
- unsigned int first_slot, unsigned int offset, size_t count);
+void iov_iter_bvec_queue(struct iov_iter *i, unsigned int direction,
+ const struct bvecq *bvecq,
+ unsigned int first_slot, unsigned int offset, size_t count);
void iov_iter_xarray(struct iov_iter *i, unsigned int direction, struct xarray *xarray,
loff_t start, size_t count);
void iov_iter_dmabuf_map(struct iov_iter *i, unsigned int direction,
diff --git a/include/trace/events/netfs.h b/include/trace/events/netfs.h
index bf1e1f185b05c4..e80c27c49ce259 100644
--- a/include/trace/events/netfs.h
+++ b/include/trace/events/netfs.h
@@ -199,7 +199,6 @@
EM(netfs_streaming_filled_page, "mod-streamw-f") \
EM(netfs_streaming_cont_filled_page, "mod-streamw-f+") \
EM(netfs_folio_trace_abandon, "abandon") \
- EM(netfs_folio_trace_alloc_buffer, "alloc-buf") \
EM(netfs_folio_trace_cancel_copy, "cancel-copy") \
EM(netfs_folio_trace_cancel_store, "cancel-store") \
EM(netfs_folio_trace_end_copy, "end-copy") \
@@ -222,7 +221,6 @@
EM(netfs_folio_trace_not_locked, "!locked") \
EM(netfs_folio_trace_not_under_wback, "!wback") \
EM(netfs_folio_trace_pgpriv2_copy, "pgpriv2-copy") \
- EM(netfs_folio_trace_put, "put") \
EM(netfs_folio_trace_read, "read") \
EM(netfs_folio_trace_read_done, "read-done") \
EM(netfs_folio_trace_read_gaps, "read-gaps") \
@@ -244,14 +242,6 @@
EM(netfs_trace_donate_to_next, "to-next") \
E_(netfs_trace_donate_to_deferred_next, "defer-next")
-#define netfs_folioq_traces \
- EM(netfs_trace_folioq_alloc_buffer, "alloc-buf") \
- EM(netfs_trace_folioq_clear, "clear") \
- EM(netfs_trace_folioq_delete, "delete") \
- EM(netfs_trace_folioq_make_space, "make-space") \
- EM(netfs_trace_folioq_rollbuf_init, "roll-init") \
- E_(netfs_trace_folioq_read_progress, "r-progress")
-
#ifndef __NETFS_DECLARE_TRACE_ENUMS_ONCE_ONLY
#define __NETFS_DECLARE_TRACE_ENUMS_ONCE_ONLY
@@ -270,7 +260,6 @@ enum netfs_sreq_ref_trace { netfs_sreq_ref_traces } __mode(byte);
enum netfs_folio_trace { netfs_folio_traces } __mode(byte);
enum netfs_collect_contig_trace { netfs_collect_contig_traces } __mode(byte);
enum netfs_donate_trace { netfs_donate_traces } __mode(byte);
-enum netfs_folioq_trace { netfs_folioq_traces } __mode(byte);
#endif
@@ -294,7 +283,6 @@ netfs_sreq_ref_traces;
netfs_folio_traces;
netfs_collect_contig_traces;
netfs_donate_traces;
-netfs_folioq_traces;
/*
* Now redefine the EM() and E_() macros to map the enums to the strings that
@@ -398,7 +386,7 @@ TRACE_EVENT(netfs_sreq,
__entry->len = sreq->len;
__entry->transferred = sreq->transferred;
__entry->start = sreq->start;
- __entry->slot = sreq->io_iter.folioq_slot;
+ __entry->slot = sreq->io_iter.bvecq_slot;
),
TP_printk("R=%08x[%x] %s %s f=%03x s=%llx %zx/%zx s=%u e=%d",
@@ -773,29 +761,6 @@ TRACE_EVENT(netfs_collect_stream,
__entry->collected_to, __entry->issued_to)
);
-TRACE_EVENT(netfs_folioq,
- TP_PROTO(const struct folio_queue *fq,
- enum netfs_folioq_trace trace),
-
- TP_ARGS(fq, trace),
-
- TP_STRUCT__entry(
- __field(unsigned int, rreq)
- __field(unsigned int, id)
- __field(enum netfs_folioq_trace, trace)
- ),
-
- TP_fast_assign(
- __entry->rreq = fq ? fq->rreq_id : 0;
- __entry->id = fq ? fq->debug_id : 0;
- __entry->trace = trace;
- ),
-
- TP_printk("R=%08x fq=%x %s",
- __entry->rreq, __entry->id,
- __print_symbolic(__entry->trace, netfs_folioq_traces))
- );
-
TRACE_EVENT(netfs_read_progress_at,
TP_PROTO(const struct netfs_io_request *rreq),
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 1be30487a2fa75..0fca0c3132fe29 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -7344,8 +7344,6 @@ static const struct bpf_raw_tp_null_args raw_tp_null_args[] = {
/* amdgpu */
{ "amdgpu_vm_bo_map", 0x1 },
{ "amdgpu_vm_bo_unmap", 0x1 },
- /* netfs */
- { "netfs_folioq", 0x1 },
/* xfs from xfs_defer_pending_class */
{ "xfs_defer_create_intent", 0x1 },
{ "xfs_defer_cancel_list", 0x1 },
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 2d22638ec13a63..06b4546421a13e 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2385,6 +2385,19 @@ config TEST_IOV_ITER
If unsure, say N.
+config TEST_BVECQ
+ tristate "Test bvecq operation" if !KUNIT_ALL_TESTS
+ depends on KUNIT
+ depends on MMU
+ depends on NETFS_SUPPORT
+ default KUNIT_ALL_TESTS
+ help
+ Enable this to turn on testing of the operation of the bvecq
+ structure. This test is executed only once during system
+ boot (so affects only boot time), or at module load time.
+
+ If unsure, say N.
+
config KPROBES_SANITY_TEST
tristate "Kprobes sanity tests" if !KUNIT_ALL_TESTS
depends on DEBUG_KERNEL
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index fa4fe2e9238316..55525962a1d6dc 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -538,37 +538,38 @@ static void iov_iter_iovec_advance(struct iov_iter *i, size_t size)
i->__iov = iov;
}
-static void iov_iter_folioq_advance(struct iov_iter *i, size_t size)
+static void iov_iter_bvecq_advance(struct iov_iter *i, size_t by)
{
- const struct folio_queue *folioq = i->folioq;
- unsigned int slot = i->folioq_slot;
+ const struct bvecq *bq = i->bvecq;
+ unsigned int slot = i->bvecq_slot;
if (!i->count)
return;
- i->count -= size;
-
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = folioq->next;
- slot = 0;
- }
+ i->count -= by;
- size += i->iov_offset; /* From beginning of current segment. */
+ by += i->iov_offset; /* From beginning of current segment. */
do {
- size_t fsize = folioq_folio_size(folioq, slot);
+ size_t len;
- if (likely(size < fsize))
- break;
- size -= fsize;
- slot++;
- if (slot >= folioq_nr_slots(folioq) && folioq->next) {
- folioq = folioq->next;
+ if (slot >= bq->nr_slots) {
+ if (!bq->next)
+ break;
+ bq = bq->next;
slot = 0;
+ continue;
}
- } while (size);
- i->iov_offset = size;
- i->folioq_slot = slot;
- i->folioq = folioq;
+ len = bq->bv[slot].bv_len;
+
+ if (likely(by < len))
+ break;
+ by -= len;
+ slot++;
+ } while (by);
+
+ i->iov_offset = by;
+ i->bvecq_slot = slot;
+ i->bvecq = bq;
}
void iov_iter_advance(struct iov_iter *i, size_t size)
@@ -584,38 +585,39 @@ void iov_iter_advance(struct iov_iter *i, size_t size)
iov_iter_iovec_advance(i, size);
} else if (iov_iter_is_bvec(i)) {
iov_iter_bvec_advance(i, size);
- } else if (iov_iter_is_folioq(i)) {
- iov_iter_folioq_advance(i, size);
+ } else if (iov_iter_is_bvecq(i)) {
+ iov_iter_bvecq_advance(i, size);
} else if (iov_iter_is_discard(i)) {
i->count -= size;
}
}
EXPORT_SYMBOL(iov_iter_advance);
-static void iov_iter_folioq_revert(struct iov_iter *i, size_t unroll)
+static void iov_iter_bvecq_revert(struct iov_iter *i, size_t unroll)
{
- const struct folio_queue *folioq = i->folioq;
- unsigned int slot = i->folioq_slot;
+ const struct bvecq *bq = i->bvecq;
+ unsigned int slot = i->bvecq_slot;
for (;;) {
- size_t fsize;
+ size_t len;
if (slot == 0) {
- folioq = folioq->prev;
- slot = folioq_nr_slots(folioq);
+ bq = bq->prev;
+ slot = bq->nr_slots;
+ continue;
}
slot--;
- fsize = folioq_folio_size(folioq, slot);
- if (unroll <= fsize) {
- i->iov_offset = fsize - unroll;
+ len = bq->bv[slot].bv_len;
+ if (unroll <= len) {
+ i->iov_offset = len - unroll;
break;
}
- unroll -= fsize;
+ unroll -= len;
}
- i->folioq_slot = slot;
- i->folioq = folioq;
+ i->bvecq_slot = slot;
+ i->bvecq = bq;
}
void iov_iter_revert(struct iov_iter *i, size_t unroll)
@@ -650,9 +652,9 @@ void iov_iter_revert(struct iov_iter *i, size_t unroll)
}
unroll -= n;
}
- } else if (iov_iter_is_folioq(i)) {
+ } else if (iov_iter_is_bvecq(i)) {
i->iov_offset = 0;
- iov_iter_folioq_revert(i, unroll);
+ iov_iter_bvecq_revert(i, unroll);
} else { /* same logics for iovec and kvec */
const struct iovec *iov = iter_iov(i);
while (1) {
@@ -680,9 +682,28 @@ size_t iov_iter_single_seg_count(const struct iov_iter *i)
if (iov_iter_is_bvec(i))
return min(i->count, i->bvec->bv_len - i->iov_offset);
}
- if (unlikely(iov_iter_is_folioq(i)))
- return !i->count ? 0 :
- umin(folioq_folio_size(i->folioq, i->folioq_slot), i->count);
+ if (!i->count)
+ return 0;
+ if (unlikely(iov_iter_is_bvecq(i))) {
+ const struct bvecq *bq = i->bvecq;
+ unsigned int slot = i->bvecq_slot;
+ size_t offset = i->iov_offset;
+
+ for (;;) {
+ while (slot >= bq->nr_slots) {
+ bq = bq->next;
+ if (!bq)
+ return 0;
+ slot = 0;
+ offset = 0;
+ }
+ if (bq->bv[slot].bv_len > offset)
+ break;
+ slot++;
+ offset = 0;
+ }
+ return min(i->count, bq->bv[slot].bv_len - offset);
+ }
return i->count;
}
EXPORT_SYMBOL(iov_iter_single_seg_count);
@@ -720,34 +741,34 @@ void iov_iter_bvec(struct iov_iter *i, unsigned int direction,
EXPORT_SYMBOL(iov_iter_bvec);
/**
- * iov_iter_folio_queue - Initialise an I/O iterator to use the folios in a folio queue
+ * iov_iter_bvec_queue - Initialise an I/O iterator to use a segmented bvec queue
* @i: The iterator to initialise.
* @direction: The direction of the transfer.
- * @folioq: The starting point in the folio queue.
- * @first_slot: The first slot in the folio queue to use
- * @offset: The offset into the folio in the first slot to start at
+ * @bvecq: The starting point in the bvec queue.
+ * @first_slot: The first slot in the bvec queue to use
+ * @offset: The offset into the bvec in the first slot to start at
* @count: The size of the I/O buffer in bytes.
*
- * Set up an I/O iterator to either draw data out of the pages attached to an
- * inode or to inject data into those pages. The pages *must* be prevented
- * from evaporation, either by taking a ref on them or locking them by the
- * caller.
+ * Set up an I/O iterator to either draw data out of the buffers attached to an
+ * inode or to inject data into those buffers. The pages *must* be prevented
+ * from evaporation by the caller, by taking a ref or a lock on them or by
+ * cleaning them up after the I/O is complete.
*/
-void iov_iter_folio_queue(struct iov_iter *i, unsigned int direction,
- const struct folio_queue *folioq, unsigned int first_slot,
- unsigned int offset, size_t count)
+void iov_iter_bvec_queue(struct iov_iter *i, unsigned int direction,
+ const struct bvecq *bvecq, unsigned int first_slot,
+ unsigned int offset, size_t count)
{
- BUG_ON(direction & ~1);
+ WARN_ON(direction & ~(READ | WRITE));
*i = (struct iov_iter) {
- .iter_type = ITER_FOLIOQ,
- .data_source = direction,
- .folioq = folioq,
- .folioq_slot = first_slot,
- .count = count,
- .iov_offset = offset,
+ .iter_type = ITER_BVECQ,
+ .data_source = direction,
+ .bvecq = bvecq,
+ .bvecq_slot = first_slot,
+ .count = count,
+ .iov_offset = offset,
};
}
-EXPORT_SYMBOL(iov_iter_folio_queue);
+EXPORT_SYMBOL(iov_iter_bvec_queue);
/**
* iov_iter_xarray - Initialise an I/O iterator to use the pages in an xarray
@@ -855,6 +876,39 @@ static unsigned long iov_iter_alignment_bvec(const struct iov_iter *i)
return res;
}
+static unsigned long iov_iter_alignment_bvecq(const struct iov_iter *iter)
+{
+ const struct bvecq *bq;
+ unsigned long res = 0;
+ unsigned int slot = iter->bvecq_slot;
+ size_t skip = iter->iov_offset;
+ size_t size = iter->count;
+
+ if (!size)
+ return res;
+
+ for (bq = iter->bvecq; bq; bq = bq->next) {
+ for (; slot < bq->nr_slots; slot++) {
+ const struct bio_vec *bvec = &bq->bv[slot];
+ size_t part = min(bvec->bv_len - skip, size);
+
+ if (part) {
+ res |= bvec->bv_offset + skip;
+ res |= part;
+ }
+
+ size -= part;
+ if (size == 0)
+ return res;
+ skip = 0;
+ }
+
+ slot = 0;
+ }
+
+ return res;
+}
+
unsigned long iov_iter_alignment(const struct iov_iter *i)
{
if (likely(iter_is_ubuf(i))) {
@@ -874,9 +928,11 @@ unsigned long iov_iter_alignment(const struct iov_iter *i)
if (iov_iter_is_bvec(i))
return iov_iter_alignment_bvec(i);
+ if (iov_iter_is_bvecq(i))
+ return iov_iter_alignment_bvecq(i);
- /* With both xarray and folioq types, we're dealing with whole folios. */
- if (iov_iter_is_folioq(i) || iov_iter_is_dmabuf_map(i))
+ /* With the xarray type, we're dealing with whole folios. */
+ if (iov_iter_is_dmabuf_map(i))
return i->iov_offset | i->count;
if (iov_iter_is_xarray(i))
return (i->xarray_start + i->iov_offset) | i->count;
@@ -930,62 +986,158 @@ static int want_pages_array(struct page ***res, size_t size,
return count;
}
-static ssize_t iter_folioq_get_pages(struct iov_iter *iter,
- struct page ***ppages, size_t maxsize,
- unsigned maxpages, size_t *_start_offset)
+/*
+ * Count the number of virtually contiguous pages coming up next in an
+ * ITER_BVECQ iterator, up to the specified maxima.
+ */
+static unsigned int iter_count_bvecq_pages(const struct iov_iter *iter,
+ size_t maxsize,
+ unsigned int maxpages)
{
- const struct folio_queue *folioq = iter->folioq;
+ const struct bvecq *bvecq = iter->bvecq;
+ unsigned int slot = iter->bvecq_slot;
+ ssize_t remain = umin(maxsize, iter->count);
+ size_t count = 0, offset = iter->iov_offset;
+
+ do {
+ const struct bio_vec *bv;
+ size_t boff, blen;
+
+ if (slot >= bvecq->nr_slots) {
+ if (!bvecq->next) {
+ WARN_ON_ONCE(remain > 0);
+ break;
+ }
+ bvecq = bvecq->next;
+ slot = 0;
+ offset = 0;
+ continue;
+ }
+
+ bv = &bvecq->bv[slot++];
+ boff = bv->bv_offset;
+ blen = bv->bv_len;
+
+ /* bv_page is not allowed to be NULL unless bv_len == 0. */
+ if (WARN_ON_ONCE(!bv->bv_page && blen > 0))
+ break;
+ if (!PAGE_ALIGNED(boff) && count > 0)
+ break;
+
+ boff += offset;
+ blen -= offset;
+ offset = 0;
+ if (!blen)
+ continue;
+
+ blen = umin(blen, remain);
+ remain -= blen;
+ blen += offset_in_page(boff);
+ count += DIV_ROUND_UP(blen, PAGE_SIZE);
+
+ if (!PAGE_ALIGNED(blen))
+ break;
+ } while (remain > 0 && count < maxpages);
+
+ return min(count, maxpages);
+}
+
+/*
+ * Get a list of virtually contiguous pages from an ITER_BVECQ iterator and pin
+ * them.
+ */
+static ssize_t iter_bvecq_get_pages(struct iov_iter *iter,
+ struct page ***ppages, size_t maxsize,
+ unsigned int maxpages, size_t *_start_offset)
+{
+ const struct bvecq *bvecq = iter->bvecq;
struct page **pages;
- unsigned int slot = iter->folioq_slot;
- size_t extracted = 0, count = iter->count, iov_offset = iter->iov_offset;
+ unsigned int slot = iter->bvecq_slot, nr = 0;
+ size_t extracted = 0, offset = iter->iov_offset;
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = folioq->next;
- slot = 0;
- if (WARN_ON(iov_offset != 0))
- return -EIO;
+ for (;;) {
+ if (slot >= bvecq->nr_slots) {
+ if (!bvecq->next)
+ return 0;
+ bvecq = bvecq->next;
+ slot = 0;
+ offset = 0;
+ continue;
+ }
+ if (offset >= bvecq->bv[slot].bv_len) {
+ slot++;
+ offset = 0;
+ continue;
+ }
+ break;
}
- maxpages = want_pages_array(ppages, maxsize, iov_offset & ~PAGE_MASK, maxpages);
+ /* Count the next run of virtually contiguous pages. */
+ maxpages = iter_count_bvecq_pages(iter, maxsize, maxpages);
+ if (!maxpages)
+ return 0;
+
+ maxpages = want_pages_array(ppages, maxsize,
+ (bvecq->bv[slot].bv_offset + offset) & ~PAGE_MASK,
+ maxpages);
if (!maxpages)
return -ENOMEM;
- *_start_offset = iov_offset & ~PAGE_MASK;
pages = *ppages;
- for (;;) {
- struct folio *folio = folioq_folio(folioq, slot);
- size_t offset = iov_offset, fsize = folioq_folio_size(folioq, slot);
- size_t part = PAGE_SIZE - offset % PAGE_SIZE;
-
- if (offset < fsize) {
- part = umin(part, umin(maxsize - extracted, fsize - offset));
- count -= part;
- iov_offset += part;
- extracted += part;
+ /* Now transcribe the page pointers. */
+ do {
+ const struct bio_vec *bv;
+ size_t boff, blen;
- *pages = folio_page(folio, offset / PAGE_SIZE);
- get_page(*pages);
- pages++;
- maxpages--;
+ if (slot >= bvecq->nr_slots) {
+ if (!bvecq->next) {
+ WARN_ON_ONCE(extracted < iter->count);
+ break;
+ }
+ bvecq = bvecq->next;
+ slot = 0;
+ offset = 0;
+ continue;
}
- if (maxpages == 0 || extracted >= maxsize)
- break;
+ bv = &bvecq->bv[slot];
+ boff = bv->bv_offset;
+ blen = bv->bv_len;
+
+ /* bv_page is not allowed to be NULL unless bv_len == 0. */
+
+ if (offset < blen) {
+ struct folio *folio;
+ size_t poff = (boff + offset) % PAGE_SIZE;
+ size_t part = min(maxsize - extracted, blen - offset);
+ size_t pix = (boff + offset) / PAGE_SIZE;
+
+ if (poff + part > PAGE_SIZE)
+ part = PAGE_SIZE - poff;
+
+ if (!extracted)
+ *_start_offset = poff;
+
+ /* Get a ref on the page if it's not a slab page. */
+ folio = page_folio(bv->bv_page + pix);
+ if (!folio_test_slab(folio))
+ folio_get(folio);
+
+ pages[nr++] = bv->bv_page + pix;
+ offset += part;
+ extracted += part;
+ }
- if (iov_offset >= fsize) {
- iov_offset = 0;
+ if (offset >= blen) {
+ offset = 0;
slot++;
- if (slot == folioq_nr_slots(folioq) && folioq->next) {
- folioq = folioq->next;
- slot = 0;
- }
}
- }
+ } while (nr < maxpages && extracted < maxsize);
- iter->count = count;
- iter->iov_offset = iov_offset;
- iter->folioq = folioq;
- iter->folioq_slot = slot;
+ iter->bvecq = bvecq;
+ iter->bvecq_slot = slot;
+ iter->iov_offset = offset;
+ iter->count -= extracted;
return extracted;
}
@@ -1140,8 +1292,8 @@ static ssize_t __iov_iter_get_pages_alloc(struct iov_iter *i,
}
return maxsize;
}
- if (iov_iter_is_folioq(i))
- return iter_folioq_get_pages(i, pages, maxsize, maxpages, start);
+ if (iov_iter_is_bvecq(i))
+ return iter_bvecq_get_pages(i, pages, maxsize, maxpages, start);
if (iov_iter_is_xarray(i))
return iter_xarray_get_pages(i, pages, maxsize, maxpages, start);
return -EFAULT;
@@ -1212,6 +1364,38 @@ static int bvec_npages(const struct iov_iter *i, int maxpages)
return npages;
}
+static size_t iov_npages_bvecq(const struct iov_iter *iter, size_t maxpages)
+{
+ const struct bvecq *bq;
+ unsigned int slot = iter->bvecq_slot;
+ size_t npages = 0;
+ size_t skip = iter->iov_offset;
+ size_t size = iter->count;
+
+ for (bq = iter->bvecq; bq; bq = bq->next) {
+ for (; slot < bq->nr_slots; slot++) {
+ const struct bio_vec *bvec = &bq->bv[slot];
+ size_t offs = (bvec->bv_offset + skip) % PAGE_SIZE;
+ size_t part = min(bvec->bv_len - skip, size);
+
+ if (part) {
+ npages += DIV_ROUND_UP(offs + part, PAGE_SIZE);
+ if (npages >= maxpages)
+ goto out;
+ }
+
+ size -= part;
+ if (!size)
+ goto out;
+ skip = 0;
+ }
+
+ slot = 0;
+ }
+out:
+ return umin(npages, maxpages);
+}
+
int iov_iter_npages(const struct iov_iter *i, int maxpages)
{
if (unlikely(!i->count))
@@ -1226,11 +1410,8 @@ int iov_iter_npages(const struct iov_iter *i, int maxpages)
return iov_npages(i, maxpages);
if (iov_iter_is_bvec(i))
return bvec_npages(i, maxpages);
- if (iov_iter_is_folioq(i)) {
- unsigned offset = i->iov_offset % PAGE_SIZE;
- int npages = DIV_ROUND_UP(offset + i->count, PAGE_SIZE);
- return min(npages, maxpages);
- }
+ if (iov_iter_is_bvecq(i))
+ return iov_npages_bvecq(i, maxpages);
if (iov_iter_is_xarray(i)) {
unsigned offset = (i->xarray_start + i->iov_offset) % PAGE_SIZE;
int npages = DIV_ROUND_UP(offset + i->count, PAGE_SIZE);
@@ -1515,64 +1696,86 @@ void iov_iter_restore(struct iov_iter *i, struct iov_iter_state *state)
EXPORT_SYMBOL_FOR_MODULES(iov_iter_restore, "vmw_vsock_virtio_transport_common");
/*
- * Extract a list of contiguous pages from an ITER_FOLIOQ iterator. This does
- * not get references on the pages, nor does it get a pin on them.
+ * Extract a list of virtually contiguous pages from an ITER_BVECQ iterator.
+ * This does not get references on the pages, nor does it get a pin on them.
*/
-static ssize_t iov_iter_extract_folioq_pages(struct iov_iter *i,
- struct page ***pages, size_t maxsize,
- unsigned int maxpages,
- iov_iter_extraction_t extraction_flags,
- size_t *offset0)
+static ssize_t iov_iter_extract_bvecq_pages(struct iov_iter *iter,
+ struct page ***pages, size_t maxsize,
+ unsigned int maxpages,
+ iov_iter_extraction_t extraction_flags,
+ size_t *offset0)
{
- const struct folio_queue *folioq = i->folioq;
+ const struct bvecq *bvecq;
struct page **p;
- unsigned int nr = 0;
- size_t extracted = 0, offset, slot = i->folioq_slot;
+ unsigned int slot, nr = 0;
+ size_t extracted = 0, offset;
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = folioq->next;
- slot = 0;
- if (WARN_ON(i->iov_offset != 0))
- return -EIO;
- }
+ /* Count the next run of virtually contiguous pages. */
+ maxpages = iter_count_bvecq_pages(iter, maxsize, maxpages);
+ if (!maxpages)
+ return 0;
- offset = i->iov_offset & ~PAGE_MASK;
- *offset0 = offset;
+ if (!*pages) {
+ *pages = kvmalloc_array(maxpages, sizeof(struct page *), GFP_KERNEL);
+ if (!*pages)
+ return -ENOMEM;
+ }
- maxpages = want_pages_array(pages, maxsize, offset, maxpages);
- if (!maxpages)
- return -ENOMEM;
p = *pages;
- for (;;) {
- struct folio *folio = folioq_folio(folioq, slot);
- size_t offset = i->iov_offset, fsize = folioq_folio_size(folioq, slot);
- size_t part = PAGE_SIZE - offset % PAGE_SIZE;
-
- if (offset < fsize) {
- part = umin(part, umin(maxsize - extracted, fsize - offset));
- i->count -= part;
- i->iov_offset += part;
- extracted += part;
+ /* Now transcribe the page pointers. */
+ extracted = 0;
+ bvecq = iter->bvecq;
+ offset = iter->iov_offset;
+ slot = iter->bvecq_slot;
+
+ do {
+ const struct bio_vec *bv;
+ size_t boff, blen;
- p[nr++] = folio_page(folio, offset / PAGE_SIZE);
+ if (slot >= bvecq->nr_slots) {
+ if (!bvecq->next) {
+ WARN_ON_ONCE(extracted < iter->count);
+ break;
+ }
+ bvecq = bvecq->next;
+ slot = 0;
+ offset = 0;
+ continue;
}
- if (nr >= maxpages || extracted >= maxsize)
- break;
+ bv = &bvecq->bv[slot];
+ boff = bv->bv_offset;
+ blen = bv->bv_len;
- if (i->iov_offset >= fsize) {
- i->iov_offset = 0;
+ /* bv_page is not allowed to be NULL unless bv_len == 0. */
+
+ if (offset < blen) {
+ size_t part = umin(maxsize - extracted, blen - offset);
+ size_t poff = (boff + offset) % PAGE_SIZE;
+ size_t pix = (boff + offset) / PAGE_SIZE;
+
+ if (poff + part > PAGE_SIZE)
+ part = PAGE_SIZE - poff;
+
+ if (!extracted)
+ *offset0 = poff;
+
+ p[nr++] = bv->bv_page + pix;
+ offset += part;
+ extracted += part;
+ }
+
+ if (offset >= blen) {
+ offset = 0;
slot++;
- if (slot == folioq_nr_slots(folioq) && folioq->next) {
- folioq = folioq->next;
- slot = 0;
- }
}
- }
+ } while (nr < maxpages && extracted < maxsize);
- i->folioq = folioq;
- i->folioq_slot = slot;
+ iter->bvecq = bvecq;
+ iter->bvecq_slot = slot;
+ iter->iov_offset = offset;
+ iter->count -= extracted;
return extracted;
}
@@ -1838,8 +2041,8 @@ static ssize_t iov_iter_extract_user_pages(struct iov_iter *i,
* added to the pages, but refs will not be taken.
* iov_iter_extract_will_pin() will return true.
*
- * (*) If the iterator is ITER_KVEC, ITER_BVEC, ITER_FOLIOQ or ITER_XARRAY, the
- * pages are merely listed; no extra refs or pins are obtained.
+ * (*) If the iterator is ITER_KVEC, ITER_BVEC, ITER_XARRAY, the pages are
+ * merely listed; no extra refs or pins are obtained.
* iov_iter_extract_will_pin() will return 0.
*
* Note also:
@@ -1874,10 +2077,10 @@ ssize_t iov_iter_extract_pages(struct iov_iter *i,
return iov_iter_extract_bvec_pages(i, pages, maxsize,
maxpages, extraction_flags,
offset0);
- if (iov_iter_is_folioq(i))
- return iov_iter_extract_folioq_pages(i, pages, maxsize,
- maxpages, extraction_flags,
- offset0);
+ if (iov_iter_is_bvecq(i))
+ return iov_iter_extract_bvecq_pages(i, pages, maxsize,
+ maxpages, extraction_flags,
+ offset0);
if (iov_iter_is_xarray(i))
return iov_iter_extract_xarray_pages(i, pages, maxsize,
maxpages, extraction_flags,
diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index 6ea40d2e624755..b9a7298306d95d 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -10,8 +10,8 @@
#include <linux/highmem.h>
#include <linux/kmemleak.h>
#include <linux/bvec.h>
+#include <linux/bvecq.h>
#include <linux/uio.h>
-#include <linux/folio_queue.h>
/**
* sg_nents - return total count of entries in scatterlist
@@ -1268,61 +1268,59 @@ static ssize_t extract_kvec_to_sg(struct iov_iter *iter,
}
/*
- * Extract up to sg_max folios from an FOLIOQ-type iterator and add them to
+ * Extract up to sg_max folios from an BVECQ-type iterator and add them to
* the scatterlist. The pages are not pinned.
*/
-static ssize_t extract_folioq_to_sg(struct iov_iter *iter,
+static ssize_t extract_bvecq_to_sg(struct iov_iter *iter,
ssize_t maxsize,
struct sg_table *sgtable,
unsigned int sg_max,
iov_iter_extraction_t extraction_flags)
{
- const struct folio_queue *folioq = iter->folioq;
+ const struct bvecq *bvecq = iter->bvecq;
struct scatterlist *sg = sgtable->sgl + sgtable->nents;
- unsigned int slot = iter->folioq_slot;
+ unsigned int slot = iter->bvecq_slot;
ssize_t ret = 0;
size_t offset = iter->iov_offset;
- BUG_ON(!folioq);
+ maxsize = umin(maxsize, iov_iter_count(iter));
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = folioq->next;
- if (WARN_ON_ONCE(!folioq))
- return 0;
- slot = 0;
- }
-
- do {
- struct folio *folio = folioq_folio(folioq, slot);
- size_t fsize = folioq_folio_size(folioq, slot);
+ while (sg_max > 0 && ret < maxsize) {
+ const struct bio_vec *bv;
+ size_t blen, part;
- if (offset < fsize) {
- size_t part = umin(maxsize - ret, fsize - offset);
-
- sg_set_page(sg, folio_page(folio, 0), part, offset);
- sgtable->nents++;
- sg++;
- sg_max--;
- offset += part;
- ret += part;
+ if (slot >= bvecq->nr_slots) {
+ if (!bvecq->next) {
+ WARN_ON_ONCE(ret < iter->count);
+ break;
+ }
+ bvecq = bvecq->next;
+ slot = 0;
+ offset = 0;
+ continue;
}
- if (offset >= fsize) {
+ bv = &bvecq->bv[slot];
+ blen = bv->bv_len;
+
+ if (offset >= blen) {
offset = 0;
slot++;
- if (slot >= folioq_nr_slots(folioq)) {
- if (!folioq->next) {
- WARN_ON_ONCE(ret < iter->count);
- break;
- }
- folioq = folioq->next;
- slot = 0;
- }
+ continue;
}
- } while (sg_max > 0 && ret < maxsize);
- iter->folioq = folioq;
- iter->folioq_slot = slot;
+ part = umin(maxsize - ret, blen - offset);
+
+ sg_set_page(sg, bv->bv_page, part, bv->bv_offset + offset);
+ sgtable->nents++;
+ sg++;
+ sg_max--;
+ offset += part;
+ ret += part;
+ }
+
+ iter->bvecq = bvecq;
+ iter->bvecq_slot = slot;
iter->iov_offset = offset;
iter->count -= ret;
return ret;
@@ -1391,8 +1389,8 @@ static ssize_t extract_xarray_to_sg(struct iov_iter *iter,
* addition of @sg_max elements.
*
* The pages referred to by UBUF- and IOVEC-type iterators are extracted and
- * pinned; BVEC-, KVEC-, FOLIOQ- and XARRAY-type are extracted but aren't
- * pinned; DISCARD-type is not supported.
+ * pinned; BVEC-, BVECQ-, KVEC-, XARRAY-type are extracted but aren't pinned;
+ * DISCARD-type is not supported.
*
* No end mark is placed on the scatterlist; that's left to the caller.
*
@@ -1424,9 +1422,9 @@ ssize_t extract_iter_to_sg(struct iov_iter *iter, size_t maxsize,
case ITER_KVEC:
return extract_kvec_to_sg(iter, maxsize, sgtable, sg_max,
extraction_flags);
- case ITER_FOLIOQ:
- return extract_folioq_to_sg(iter, maxsize, sgtable, sg_max,
- extraction_flags);
+ case ITER_BVECQ:
+ return extract_bvecq_to_sg(iter, maxsize, sgtable, sg_max,
+ extraction_flags);
case ITER_XARRAY:
return extract_xarray_to_sg(iter, maxsize, sgtable, sg_max,
extraction_flags);
diff --git a/lib/tests/Makefile b/lib/tests/Makefile
index df0537e1b91faf..85e3c5e1f7d292 100644
--- a/lib/tests/Makefile
+++ b/lib/tests/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_GLOB_KUNIT_TEST) += glob_kunit.o
obj-$(CONFIG_HASHTABLE_KUNIT_TEST) += hashtable_test.o
obj-$(CONFIG_HASH_KUNIT_TEST) += test_hash.o
obj-$(CONFIG_TEST_IOV_ITER) += kunit_iov_iter.o
+obj-$(CONFIG_TEST_BVECQ) += kunit_bvecq.o
obj-$(CONFIG_IS_SIGNED_TYPE_KUNIT_TEST) += is_signed_type_kunit.o
obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o
obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o
diff --git a/lib/tests/kunit_bvecq.c b/lib/tests/kunit_bvecq.c
new file mode 100644
index 00000000000000..7cdd455df69298
--- /dev/null
+++ b/lib/tests/kunit_bvecq.c
@@ -0,0 +1,599 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* bvecq iterator tests. Exercises:
+ * - advance
+ * - revert
+ * - npages
+ * - alignment
+ *
+ * See also kunit_iov_iter.c for bvecq copy and extract tests.
+ *
+ * Copyright (C) 2026 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/module.h>
+#include <linux/mm.h>
+#include <linux/uio.h>
+#include <linux/bvecq.h>
+#include <kunit/test.h>
+
+MODULE_DESCRIPTION("bvecq testing");
+MODULE_AUTHOR("David Howells <dhowells@redhat.com>");
+MODULE_LICENSE("GPL");
+
+/*
+ * Info for the fill pattern generator.
+ */
+static const u8 bvecq_kunit_orders[16] = {
+ 0, 1, 2, 3,
+ 0, 1, 3, 2,
+ 0, 2, 1, 3,
+ 2, 0, 3, 1
+};
+
+static const s8 bvecq_kunit_fills[16] = {
+ 1, 2, 3, 5, 7, 11, 13, 17,
+ -1, -2, -3, -5, -7, -11, -13, -17
+};
+static struct folio *bvecq_kunit_folios[16];
+
+/*
+ * Info for the fill pattern predictor.
+ */
+struct bvecq_test_pagemap {
+ u32 pos;
+ u32 offset;
+ u8 folio;
+ u8 subpage;
+};
+
+static struct bvecq_test_pagemap bvecq_kunit_pagemap[64];
+static int bvecq_kunit_pagemap_nr;
+
+/*
+ * bvecq assembly recipes.
+ */
+enum bvecq_test_cmd {
+ BVECQ_KUNIT_STOP, /* Stop loading */
+ BVECQ_KUNIT_ALLOC, /* Append new bvecq of size count and move to it */
+ BVECQ_KUNIT_LOAD, /* Load count segments into current bvecq */
+ BVECQ_KUNIT_EMPTY, /* Add count empty segments into current bvecq */
+} __mode(byte);
+
+struct bvecq_test_recipe {
+ enum bvecq_test_cmd cmd;
+ u8 count;
+};
+
+#define ALLOC(C) { .cmd = BVECQ_KUNIT_ALLOC, .count = C }
+#define LOAD(C) { .cmd = BVECQ_KUNIT_LOAD, .count = C }
+#define EMPTY(C) { .cmd = BVECQ_KUNIT_EMPTY, .count = C }
+#define END { .cmd = BVECQ_KUNIT_STOP, }
+
+static const struct bvecq_test_recipe bvecq_test_recipe_0[] = {
+ ALLOC(16), LOAD(16),
+ END
+};
+
+static const struct bvecq_test_recipe bvecq_test_recipe_1[] = {
+ ALLOC(8), LOAD(8),
+ ALLOC(8), LOAD(8),
+ END
+};
+
+static const struct bvecq_test_recipe bvecq_test_recipe_2[] = {
+ ALLOC(9), LOAD(8), EMPTY(1),
+ ALLOC(8), LOAD(8),
+ END
+};
+
+static const struct bvecq_test_recipe bvecq_test_recipe_3[] = {
+ ALLOC(9), EMPTY(1), LOAD(2), EMPTY(2), LOAD(2), EMPTY(1),
+ ALLOC(8), LOAD(4), EMPTY(2),
+ ALLOC(8), EMPTY(1), LOAD(4),
+ ALLOC(8), EMPTY(2), LOAD(4), EMPTY(1),
+ END
+};
+
+static const struct bvecq_test_recipe bvecq_test_recipe_4[] = {
+ ALLOC(9), LOAD(2), EMPTY(1),
+ ALLOC(2),
+ ALLOC(2), LOAD(2),
+ ALLOC(2), EMPTY(2),
+ ALLOC(8), LOAD(8),
+ END
+};
+
+static const struct bvecq_test_recipe bvecq_test_recipe_5[] = {
+ ALLOC(2),
+ ALLOC(9), LOAD(2), EMPTY(1),
+ ALLOC(2),
+ ALLOC(2), LOAD(2),
+ ALLOC(2), EMPTY(2),
+ ALLOC(8), LOAD(8),
+ ALLOC(2),
+ END
+};
+
+static const struct bvecq_test_recipe bvecq_test_recipe_6[] = {
+ ALLOC(2), EMPTY(1),
+ ALLOC(2),
+ ALLOC(9), LOAD(2), EMPTY(1),
+ ALLOC(2),
+ ALLOC(2), LOAD(2),
+ ALLOC(2), EMPTY(2),
+ ALLOC(8), LOAD(8),
+ ALLOC(2),
+ ALLOC(2), EMPTY(1),
+ END
+};
+
+/*
+ * Sets of variations of how much of each folio is added to the bvecq chain,
+ * allowing a part of the folio to be excluded from each end.
+ */
+struct bvecq_test_partials {
+ u16 add_start; /* Amount to exclude from the low end */
+ u16 sub_end; /* Amount to exclude from the high end */
+};
+
+/* All whole folios. */
+static const struct bvecq_test_partials bvecq_test_partials_full[16] = {
+ [0 ... 15] = { 0, 0 }
+};
+
+/* Scattered partial folios, with some folios contiguous. */
+static const struct bvecq_test_partials bvecq_test_partials_scattered[16] = {
+ //0, 1, 2, 3,
+ { 0x277, 0x136 },
+ { 0x999, 0x1011 },
+ { 0x2020, 0x0 },
+ { 0x0, 0x1123 },
+ //0, 1, 3, 2,
+ { 0x0, 0x136 },
+ { 0x27, 0x777 },
+ { 0x771, 0x0 },
+ { 0x555, 0x0 },
+ //0, 2, 1, 3,
+ { 0x277, 0x136 },
+ { 0x1123, 0x0 },
+ { 0x0, 0x0 },
+ { 0, 0x5011 },
+ //2, 0, 3, 1
+ { 0x2020, 0x0 },
+ { 0x277, 0x136 },
+ { 0x1999, 0x1011 },
+ { 0x0, 0x1010 },
+};
+
+/* Partial folios, all with a byte excluded from each end. */
+static const struct bvecq_test_partials bvecq_test_partials_edges[16] = {
+ [0 ... 15] = { 1, 1 }
+};
+
+/*
+ * Clean up routines.
+ */
+static void bvecq_kunit_release_folios(void *data)
+{
+ struct folio **folios = data;
+
+ release_pages(folios, ARRAY_SIZE(bvecq_kunit_folios));
+ memset(bvecq_kunit_folios, 0, sizeof(bvecq_kunit_folios));
+}
+
+static void bvecq_kunit_bvecq_put(void *data)
+{
+ bvecq_put(data);
+}
+
+/*
+ * Calculate the fill pattern, for a particular byte of a particular subpage of
+ * a particular folio.
+ */
+static inline u8 bvecq_kunit_pattern(unsigned int folio, int subpage, int offset)
+{
+ int fill_step = bvecq_kunit_fills[folio];
+
+ return (subpage + offset * fill_step) & 0xff;
+}
+
+/*
+ * Calculate the fill pattern, given the 'byte position' in the bvecq chain.
+ * This looks up the folio, subpage and offset from a table generated whilst
+ * the bvecq is being assembled.
+ */
+static inline u8 bvecq_kunit_predict(struct kunit *test, size_t pos)
+{
+ size_t last_pos = 0;
+
+ for (int i = 0; i < bvecq_kunit_pagemap_nr; i++) {
+ if (pos < bvecq_kunit_pagemap[i].pos)
+ return bvecq_kunit_pattern(
+ bvecq_kunit_pagemap[i].folio,
+ bvecq_kunit_pagemap[i].subpage,
+ bvecq_kunit_pagemap[i].offset + (pos - last_pos));
+ last_pos = bvecq_kunit_pagemap[i].pos;
+ }
+
+ KUNIT_FAIL(test, "Overran pagemap pos=%zx\n", pos);
+ return 0;
+}
+
+/*
+ * Determine which page we're looking at, taking all the folios to be split
+ * into pages. This can be used to determine what iov_iter_npages() will say.
+ */
+static inline int bvecq_kunit_pos2page(struct kunit *test, size_t pos)
+{
+ for (int i = 0; i < bvecq_kunit_pagemap_nr; i++)
+ if (pos < bvecq_kunit_pagemap[i].pos)
+ return i;
+
+ if (pos > bvecq_kunit_pagemap[bvecq_kunit_pagemap_nr - 1].pos)
+ KUNIT_FAIL(test, "Overran pagemap pos=%zx\n", pos);
+ return bvecq_kunit_pagemap_nr;
+}
+
+/*
+ * Allocate a variety of folios of different orders and fill them with the
+ * pattern set for each folio.
+ */
+static void __init iov_bvecq_alloc_folios(struct kunit *test)
+{
+ struct folio *folio, **folios = bvecq_kunit_folios;
+ const int nr = ARRAY_SIZE(bvecq_kunit_folios);
+
+ bvecq_kunit_pagemap_nr = 0;
+ memset(bvecq_kunit_pagemap, 0, sizeof(bvecq_kunit_pagemap));
+ memset(bvecq_kunit_folios, 0, sizeof(bvecq_kunit_folios));
+
+ for (int i = 0; i < nr; i++) {
+ folio = folio_alloc(GFP_KERNEL, bvecq_kunit_orders[i]);
+ KUNIT_ASSERT_NOT_NULL(test, folio);
+ folios[i] = folio;
+
+ /* Fill each subpage with a different but predictable pattern. */
+ for (int j = 0; j < folio_nr_pages(folio); j++) {
+ u8 *p = kmap_local_folio(folio, PAGE_SIZE * j);
+
+ for (int k = 0; k < PAGE_SIZE; k++)
+ p[k] = bvecq_kunit_pattern(i, j, k);
+ kunmap_local(p);
+ }
+ }
+
+ kunit_add_action_or_reset(test, bvecq_kunit_release_folios, folios);
+}
+
+/*
+ * Follow the specified recipe to allocate a bvecq chain and stick the folios
+ * and empty gaps into it. Further, the offset into and length of each folio
+ * is adjusted from the partials list. Each ALLOC command will append a new
+ * bvecq to the chain and move to filling that.
+ */
+static struct bvecq *__init bvecq_kunit_load_chain(
+ struct kunit *test,
+ const struct bvecq_test_recipe *rec,
+ const struct bvecq_test_partials *parts,
+ size_t *size)
+{
+ struct bvecq *head = NULL, *bq = NULL, *p;
+ size_t pos = 0;
+ int folio_index = 0;
+
+ *size = 0;
+
+ for (; rec->cmd != BVECQ_KUNIT_STOP; rec++) {
+ if (!head)
+ KUNIT_ASSERT_EQ(test, rec->cmd, BVECQ_KUNIT_ALLOC);
+
+ switch (rec->cmd) {
+ case BVECQ_KUNIT_STOP:
+ break;
+
+ case BVECQ_KUNIT_ALLOC:
+ p = bvecq_alloc_one(rec->count, GFP_KERNEL, false);
+ KUNIT_ASSERT_NOT_NULL(test, p);
+
+ if (!head) {
+ head = p;
+ kunit_add_action_or_reset(test, bvecq_kunit_bvecq_put, head);
+ bq = p;
+ } else {
+ bvecq_append(bq, p);
+ bq = p;
+ }
+ break;
+
+ case BVECQ_KUNIT_LOAD:
+ KUNIT_ASSERT_LE(test, folio_index + rec->count,
+ ARRAY_SIZE(bvecq_kunit_orders));
+ KUNIT_ASSERT_LE(test, bq->nr_slots + rec->count, bq->max_slots);
+ for (int i = 0; i < rec->count; i++) {
+ struct folio *folio = bvecq_kunit_folios[folio_index];
+ size_t flen = PAGE_SIZE << bvecq_kunit_orders[folio_index];
+ size_t foff = 0;
+
+ KUNIT_ASSERT_LE(test,
+ parts[folio_index].add_start +
+ parts[folio_index].sub_end,
+ flen);
+
+ foff += parts[folio_index].add_start;
+ flen -= parts[folio_index].add_start;
+ flen -= parts[folio_index].sub_end;
+
+ bvec_set_page(&bq->bv[bq->nr_slots + i],
+ folio_page(folio, 0), flen, foff);
+ *size += flen;
+
+ for (int j = 0; j < folio_nr_pages(folio); j++) {
+ struct bvecq_test_pagemap *pm;
+ size_t part;
+
+ if (foff >= PAGE_SIZE) {
+ foff -= PAGE_SIZE;
+ continue;
+ }
+ part = min(flen, PAGE_SIZE - foff);
+ pos += part;
+ pm = &bvecq_kunit_pagemap[bvecq_kunit_pagemap_nr];
+ pm->pos = pos;
+ pm->folio = folio_index;
+ pm->subpage = j;
+ pm->offset = foff;
+ bvecq_kunit_pagemap_nr++;
+ flen -= part;
+ if (!flen)
+ break;
+ foff = 0;
+ }
+
+ folio_index++;
+ }
+ bvecq_filled_to(bq, bq->nr_slots + rec->count);
+ break;
+
+ case BVECQ_KUNIT_EMPTY:
+ KUNIT_ASSERT_LE(test, bq->nr_slots + rec->count, bq->max_slots);
+ for (int i = 0; i < rec->count; i++) {
+ bq->bv[bq->nr_slots + i].bv_page = ERR_PTR(-EIO);
+ bq->bv[bq->nr_slots + i].bv_offset = 0;
+ bq->bv[bq->nr_slots + i].bv_len = 0;
+ }
+ bvecq_filled_to(bq, bq->nr_slots + rec->count);
+ break;
+ }
+ }
+
+ return head;
+}
+
+/*
+ * Check the next few bytes of pattern from an iterator. Note that it is
+ * permitted for the iterator to have less data remaining than the number to
+ * check - in which case the copy is required to come up short.
+ */
+static void __init bvecq_kunit_check_next(struct kunit *test, struct iov_iter *iter,
+ size_t *pos, size_t *left, size_t nr)
+{
+ size_t part, n;
+ u8 buf[3], pred[3];
+
+ KUNIT_ASSERT_EQ(test, iov_iter_count(iter), *left);
+
+ part = min(*left, nr);
+ n = copy_from_iter(buf, nr, iter);
+ KUNIT_ASSERT_EQ(test, n, part);
+ *left -= n;
+
+ for (size_t i = 0; i < n; i++)
+ pred[i] = bvecq_kunit_predict(test, *pos + i);
+
+ for (size_t i = 0; i < n; i++) {
+ if (buf[i] != pred[i]) {
+ pr_notice(">>> pos=%05zx+%zx c=%zx buf=%*phN pred=%*phN\n",
+ *pos, i, iov_iter_count(iter) + n,
+ (int)n, buf, (int)n, pred);
+ }
+ KUNIT_ASSERT_EQ(test, buf[i], pred[i]);
+ }
+
+ *pos += n;
+}
+
+/*
+ * Test advancing and reverting over a bvecq chain.
+ *
+ * The loop starts at each 'byte position' in the chain, advancing a small
+ * amount, copying a few bytes of data, checking the fill pattern, reverting a
+ * bit, checking, reverting, checking and then reverting to a byte position one
+ * further on than the previous loop. Use small prime numbers for the advance
+ * and first revert so that we should test crossing the edges of the folios.
+ */
+static void __init bvecq_kunit_advance(struct kunit *test,
+ const struct bvecq_test_recipe *recipe,
+ const struct bvecq_test_partials *parts)
+{
+ struct iov_iter iter;
+ struct bvecq *bq, *p;
+ unsigned long bvec_align = 0;
+ size_t size, pos = 0, from;
+ int npages;
+
+ iov_bvecq_alloc_folios(test);
+ bq = bvecq_kunit_load_chain(test, recipe, parts, &size);
+
+ /* Compound up the alignments for ITER_BVEC on each individual bvecq
+ * span and compare that to the alignment for ITER_BVECQ. There is an
+ * issue in ITER_BVEC, however, in that it includes bv_offset from
+ * bio_vecs for which bv_len is 0, which ITER_BVECQ does not.
+ */
+ for (p = bq; p; p = p->next) {
+ size_t psize = 0;
+
+ for (int i = 0; i < p->nr_slots; i++)
+ psize += p->bv[i].bv_len;
+
+ if (!psize)
+ continue;
+ iov_iter_bvec(&iter, ITER_SOURCE, p->bv, p->nr_slots, psize);
+ bvec_align |= iov_iter_alignment(&iter);
+ }
+
+ iov_iter_bvec_queue(&iter, ITER_SOURCE, bq, 0, 0, size);
+
+ KUNIT_ASSERT_EQ(test, iov_iter_alignment(&iter), bvec_align);
+
+ npages = iov_iter_npages(&iter, INT_MAX);
+ from = iov_iter_count(&iter);
+ do {
+ size_t left = from, part;
+
+ KUNIT_ASSERT_EQ(test, iov_iter_npages(&iter, INT_MAX),
+ npages - bvecq_kunit_pos2page(test, pos));
+
+ /* 3 steps forward. */
+ part = min(left, 3);
+ iov_iter_advance(&iter, 3); /* May be short. */
+ pos += part;
+ left -= part;
+ bvecq_kunit_check_next(test, &iter, &pos, &left, 3);
+
+ /* 2 steps back */
+ part = umin(2, left);
+ iov_iter_revert(&iter, part);
+ pos -= part;
+ left += part;
+ bvecq_kunit_check_next(test, &iter, &pos, &left, 2);
+
+ /* 1 more step back */
+ part = umin(1, left);
+ iov_iter_revert(&iter, part);
+ pos -= part;
+ left += part;
+ bvecq_kunit_check_next(test, &iter, &pos, &left, 1);
+
+ KUNIT_ASSERT_EQ(test, left, iov_iter_count(&iter));
+
+ /* Move to one place on from the current loop. */
+ from--;
+ if (iov_iter_count(&iter) < from) {
+ part = from - iov_iter_count(&iter);
+ iov_iter_revert(&iter, part);
+ pos -= part;
+ }
+ KUNIT_ASSERT_EQ(test, from, iov_iter_count(&iter));
+ } while (from > 0);
+}
+
+/*
+ * Test jumping around in a bvecq chain using advance and revert.
+ *
+ * The loop starts at the start of the chain, then jumps forwards through the
+ * chain and then back again by large amounts, sampling the data each time.
+ */
+static void __init bvecq_kunit_jump(struct kunit *test,
+ const struct bvecq_test_recipe *recipe,
+ const struct bvecq_test_partials *parts)
+{
+ struct iov_iter iter;
+ struct bvecq *bq;
+ size_t size, pos = 0, step = 0x100;
+ bool dir = false;
+ int npages;
+
+ iov_bvecq_alloc_folios(test);
+ bq = bvecq_kunit_load_chain(test, recipe, parts, &size);
+
+ iov_iter_bvec_queue(&iter, ITER_SOURCE, bq, 0, 0, size);
+
+ npages = iov_iter_npages(&iter, INT_MAX);
+ while (step < size) {
+ size_t left = iov_iter_count(&iter), part;
+
+ KUNIT_ASSERT_EQ(test, iov_iter_npages(&iter, INT_MAX),
+ npages - bvecq_kunit_pos2page(test, pos));
+
+ if (!dir) {
+ /* Advance by step and then 3 more in check. */
+ part = min(left, step);
+ iov_iter_advance(&iter, step); /* May be short. */
+ pos += part;
+ left -= part;
+ bvecq_kunit_check_next(test, &iter, &pos, &left, 3);
+
+ KUNIT_ASSERT_EQ(test, left, iov_iter_count(&iter));
+
+ if (left == 0) {
+ /* Switch to reverting. */
+ dir = true;
+ step += 3;
+ }
+ } else {
+ /* Revert by step and then advance by 3 in check. */
+ part = min(size - left, step);
+ iov_iter_revert(&iter, part);
+ pos -= part;
+ left += part;
+ bvecq_kunit_check_next(test, &iter, &pos, &left, 3);
+
+ KUNIT_ASSERT_EQ(test, left, iov_iter_count(&iter));
+
+ if (pos <= 3) {
+ /* Switch to advancing. */
+ dir = false;
+ step *= 2;
+ }
+ }
+ }
+}
+
+/*
+ * Run the individual test combinations
+ */
+#define ADVANCE_TESTS_SET(CHECK, PARTIALS) \
+ TEST(CHECK, PARTIALS, 0) \
+ TEST(CHECK, PARTIALS, 1) \
+ TEST(CHECK, PARTIALS, 2) \
+ TEST(CHECK, PARTIALS, 3) \
+ TEST(CHECK, PARTIALS, 4) \
+ TEST(CHECK, PARTIALS, 5) \
+ TEST(CHECK, PARTIALS, 6)
+
+#define ADVANCE_TESTS(CHECK) \
+ ADVANCE_TESTS_SET(CHECK, full) \
+ ADVANCE_TESTS_SET(CHECK, scattered) \
+ ADVANCE_TESTS_SET(CHECK, edges)
+
+#define TEST(CHECK, PARTIALS, RECIPE) \
+static void __init bvecq_kunit_##CHECK##_##PARTIALS##_##RECIPE(struct kunit *test) \
+{ \
+ bvecq_kunit_##CHECK(test, \
+ bvecq_test_recipe_##RECIPE, \
+ bvecq_test_partials_##PARTIALS); \
+}
+
+/* Emit test stub functions. */
+ADVANCE_TESTS(advance);
+ADVANCE_TESTS(jump);
+#undef TEST
+
+#define TEST(CHECK, PARTIALS, RECIPE) \
+ KUNIT_CASE(bvecq_kunit_##CHECK##_##PARTIALS##_##RECIPE),
+
+static struct kunit_case __refdata bvecq_kunit_cases[] = {
+ ADVANCE_TESTS(advance)
+ ADVANCE_TESTS(jump)
+ {}
+};
+
+static struct kunit_suite bvecq_kunit_suite = {
+ .name = "bvecq",
+ .test_cases = bvecq_kunit_cases,
+};
+
+kunit_test_suites(&bvecq_kunit_suite);
diff --git a/lib/tests/kunit_iov_iter.c b/lib/tests/kunit_iov_iter.c
index 32e42d8c7ca13e..19fc082e4cf3da 100644
--- a/lib/tests/kunit_iov_iter.c
+++ b/lib/tests/kunit_iov_iter.c
@@ -12,7 +12,7 @@
#include <linux/mm.h>
#include <linux/uio.h>
#include <linux/bvec.h>
-#include <linux/folio_queue.h>
+#include <linux/bvecq.h>
#include <linux/scatterlist.h>
#include <linux/minmax.h>
#include <linux/mman.h>
@@ -382,58 +382,67 @@ static void __init iov_kunit_copy_from_bvec(struct kunit *test)
KUNIT_SUCCEED(test);
}
-static void iov_kunit_destroy_folioq(void *data)
+static void iov_kunit_destroy_bvecq(void *data)
{
- struct folio_queue *folioq, *next;
+ struct bvecq *bq, *next;
- for (folioq = data; folioq; folioq = next) {
- next = folioq->next;
- kfree(folioq);
+ for (bq = data; bq; bq = next) {
+ next = bq->next;
+ /* The pages are freed by vmap with VM_MAP_PUT_PAGES. */
+ kfree(bq);
}
}
-static void __init iov_kunit_load_folioq(struct kunit *test,
+static struct bvecq *iov_kunit_alloc_bvecq(struct kunit *test, unsigned int max_slots)
+{
+ struct bvecq *bq;
+
+ bq = kzalloc(struct_size(bq, __bv, max_slots), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bq);
+ bq->max_slots = max_slots;
+ bq->bv = bq->__bv;
+ bq->inline_bv = true;
+ return bq;
+}
+
+static struct bvecq *iov_kunit_create_bvecq(struct kunit *test, unsigned int max_slots)
+{
+ struct bvecq *bq;
+
+ bq = iov_kunit_alloc_bvecq(test, max_slots);
+ kunit_add_action_or_reset(test, iov_kunit_destroy_bvecq, bq);
+ return bq;
+}
+
+static void __init iov_kunit_load_bvecq(struct kunit *test,
struct iov_iter *iter, int dir,
- struct folio_queue *folioq,
+ struct bvecq *bq_head,
struct page **pages, size_t npages)
{
- struct folio_queue *p = folioq;
+ struct bvecq *bq = bq_head;
size_t size = 0;
- int i;
- for (i = 0; i < npages; i++) {
- if (folioq_full(p)) {
- p->next = kzalloc_obj(struct folio_queue);
- KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p->next);
- folioq_init(p->next, 0);
- p->next->prev = p;
- p = p->next;
+ for (int i = 0; i < npages; i++) {
+ if (bq->nr_slots >= bq->max_slots) {
+ bq->next = iov_kunit_alloc_bvecq(test, 13);
+ bq->next->prev = bq;
+ bq = bq->next;
}
- folioq_append(p, page_folio(pages[i]));
+ bvec_set_page(&bq->bv[bq->nr_slots], pages[i], PAGE_SIZE, 0);
+ bq->nr_slots++;
size += PAGE_SIZE;
}
- iov_iter_folio_queue(iter, dir, folioq, 0, 0, size);
-}
-
-static struct folio_queue *iov_kunit_create_folioq(struct kunit *test)
-{
- struct folio_queue *folioq;
-
- folioq = kzalloc_obj(struct folio_queue);
- KUNIT_ASSERT_NOT_ERR_OR_NULL(test, folioq);
- kunit_add_action_or_reset(test, iov_kunit_destroy_folioq, folioq);
- folioq_init(folioq, 0);
- return folioq;
+ iov_iter_bvec_queue(iter, dir, bq_head, 0, 0, size);
}
/*
- * Test copying to a ITER_FOLIOQ-type iterator.
+ * Test copying to a ITER_BVECQ-type iterator.
*/
-static void __init iov_kunit_copy_to_folioq(struct kunit *test)
+static void __init iov_kunit_copy_to_bvecq(struct kunit *test)
{
const struct kvec_test_range *pr;
struct iov_iter iter;
- struct folio_queue *folioq;
+ struct bvecq *bq;
struct page **spages, **bpages;
u8 *scratch, *buffer;
size_t bufsize, npages, size, copied;
@@ -442,7 +451,7 @@ static void __init iov_kunit_copy_to_folioq(struct kunit *test)
bufsize = 0x100000;
npages = bufsize / PAGE_SIZE;
- folioq = iov_kunit_create_folioq(test);
+ bq = iov_kunit_create_bvecq(test, 13);
scratch = iov_kunit_create_buffer(test, &spages, npages);
for (i = 0; i < bufsize; i++)
@@ -451,20 +460,19 @@ static void __init iov_kunit_copy_to_folioq(struct kunit *test)
buffer = iov_kunit_create_buffer(test, &bpages, npages);
memset(buffer, 0, bufsize);
- iov_kunit_load_folioq(test, &iter, READ, folioq, bpages, npages);
+ iov_kunit_load_bvecq(test, &iter, READ, bq, bpages, npages);
i = 0;
for (pr = kvec_test_ranges; pr->from >= 0; pr++) {
size = pr->to - pr->from;
KUNIT_ASSERT_LE(test, pr->to, bufsize);
- iov_iter_folio_queue(&iter, READ, folioq, 0, 0, pr->to);
+ iov_iter_bvec_queue(&iter, READ, bq, 0, 0, pr->to);
iov_iter_advance(&iter, pr->from);
copied = copy_to_iter(scratch + i, size, &iter);
KUNIT_EXPECT_EQ(test, copied, size);
KUNIT_EXPECT_EQ(test, iter.count, 0);
- KUNIT_EXPECT_EQ(test, iter.iov_offset, pr->to % PAGE_SIZE);
i += size;
if (test->status == KUNIT_FAILURE)
goto stop;
@@ -489,13 +497,13 @@ static void __init iov_kunit_copy_to_folioq(struct kunit *test)
}
/*
- * Test copying from a ITER_FOLIOQ-type iterator.
+ * Test copying from a ITER_BVECQ-type iterator.
*/
-static void __init iov_kunit_copy_from_folioq(struct kunit *test)
+static void __init iov_kunit_copy_from_bvecq(struct kunit *test)
{
const struct kvec_test_range *pr;
struct iov_iter iter;
- struct folio_queue *folioq;
+ struct bvecq *bq;
struct page **spages, **bpages;
u8 *scratch, *buffer;
size_t bufsize, npages, size, copied;
@@ -504,7 +512,7 @@ static void __init iov_kunit_copy_from_folioq(struct kunit *test)
bufsize = 0x100000;
npages = bufsize / PAGE_SIZE;
- folioq = iov_kunit_create_folioq(test);
+ bq = iov_kunit_create_bvecq(test, 13);
buffer = iov_kunit_create_buffer(test, &bpages, npages);
for (i = 0; i < bufsize; i++)
@@ -513,20 +521,19 @@ static void __init iov_kunit_copy_from_folioq(struct kunit *test)
scratch = iov_kunit_create_buffer(test, &spages, npages);
memset(scratch, 0, bufsize);
- iov_kunit_load_folioq(test, &iter, READ, folioq, bpages, npages);
+ iov_kunit_load_bvecq(test, &iter, READ, bq, bpages, npages);
i = 0;
for (pr = kvec_test_ranges; pr->from >= 0; pr++) {
size = pr->to - pr->from;
KUNIT_ASSERT_LE(test, pr->to, bufsize);
- iov_iter_folio_queue(&iter, WRITE, folioq, 0, 0, pr->to);
+ iov_iter_bvec_queue(&iter, WRITE, bq, 0, 0, pr->to);
iov_iter_advance(&iter, pr->from);
copied = copy_from_iter(scratch + i, size, &iter);
KUNIT_EXPECT_EQ(test, copied, size);
KUNIT_EXPECT_EQ(test, iter.count, 0);
- KUNIT_EXPECT_EQ(test, iter.iov_offset, pr->to % PAGE_SIZE);
i += size;
}
@@ -868,13 +875,13 @@ static void __init iov_kunit_extract_pages_bvec(struct kunit *test)
}
/*
- * Test the extraction of ITER_FOLIOQ-type iterators.
+ * Test the extraction of ITER_BVECQ-type iterators.
*/
-static void __init iov_kunit_extract_pages_folioq(struct kunit *test)
+static void __init iov_kunit_extract_pages_bvecq(struct kunit *test)
{
const struct kvec_test_range *pr;
- struct folio_queue *folioq;
struct iov_iter iter;
+ struct bvecq *bq;
struct page **bpages, *pagelist[8], **pages = pagelist;
ssize_t len;
size_t bufsize, size = 0, npages;
@@ -883,17 +890,17 @@ static void __init iov_kunit_extract_pages_folioq(struct kunit *test)
bufsize = 0x100000;
npages = bufsize / PAGE_SIZE;
- folioq = iov_kunit_create_folioq(test);
+ bq = iov_kunit_create_bvecq(test, 13);
iov_kunit_create_buffer(test, &bpages, npages);
- iov_kunit_load_folioq(test, &iter, READ, folioq, bpages, npages);
+ iov_kunit_load_bvecq(test, &iter, READ, bq, bpages, npages);
for (pr = kvec_test_ranges; pr->from >= 0; pr++) {
from = pr->from;
size = pr->to - from;
KUNIT_ASSERT_LE(test, pr->to, bufsize);
- iov_iter_folio_queue(&iter, WRITE, folioq, 0, 0, pr->to);
+ iov_iter_bvec_queue(&iter, WRITE, bq, 0, 0, pr->to);
iov_iter_advance(&iter, from);
do {
@@ -1173,19 +1180,18 @@ static void __init iov_kunit_iter_to_sg_bvec(struct kunit *test)
iov_kunit_iter_to_sg_check(test, &iter, bufsize, &data);
}
-static void __init iov_kunit_iter_to_sg_folioq(struct kunit *test)
+static void __init iov_kunit_iter_to_sg_bvecq(struct kunit *test)
{
struct iov_kunit_iter_to_sg_data data;
- struct folio_queue *folioq;
struct iov_iter iter;
+ struct bvecq *bq;
size_t bufsize;
bufsize = 0x200000;
iov_kunit_iter_to_sg_init(test, bufsize, false, &data);
- folioq = iov_kunit_create_folioq(test);
- iov_kunit_load_folioq(test, &iter, READ, folioq, data.pages,
- data.npages);
+ bq = iov_kunit_create_bvecq(test, 13);
+ iov_kunit_load_bvecq(test, &iter, READ, bq, data.pages, data.npages);
iov_kunit_iter_to_sg_check(test, &iter, bufsize, &data);
}
@@ -1226,17 +1232,17 @@ static struct kunit_case __refdata iov_kunit_cases[] = {
KUNIT_CASE(iov_kunit_copy_from_kvec),
KUNIT_CASE(iov_kunit_copy_to_bvec),
KUNIT_CASE(iov_kunit_copy_from_bvec),
- KUNIT_CASE(iov_kunit_copy_to_folioq),
- KUNIT_CASE(iov_kunit_copy_from_folioq),
+ KUNIT_CASE(iov_kunit_copy_to_bvecq),
+ KUNIT_CASE(iov_kunit_copy_from_bvecq),
KUNIT_CASE(iov_kunit_copy_to_xarray),
KUNIT_CASE(iov_kunit_copy_from_xarray),
KUNIT_CASE(iov_kunit_extract_pages_kvec),
KUNIT_CASE(iov_kunit_extract_pages_bvec),
- KUNIT_CASE(iov_kunit_extract_pages_folioq),
+ KUNIT_CASE(iov_kunit_extract_pages_bvecq),
KUNIT_CASE(iov_kunit_extract_pages_xarray),
KUNIT_CASE(iov_kunit_iter_to_sg_kvec),
KUNIT_CASE(iov_kunit_iter_to_sg_bvec),
- KUNIT_CASE(iov_kunit_iter_to_sg_folioq),
+ KUNIT_CASE(iov_kunit_iter_to_sg_bvecq),
KUNIT_CASE(iov_kunit_iter_to_sg_xarray),
KUNIT_CASE(iov_kunit_iter_to_sg_ubuf),
{}
|
| 3/2 | 2026/11/10 17:50 | llm | patch-evaluator |
2mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 75556 output: 27 thoughts: 560 Thoughts: **Analyzing the Patch's Potential for Fuzzing** Okay, let's break this down. My initial instinct is to assess whether this patch is a good candidate for fuzzing. To do that, I need a clear understanding of what it actually *does*. Scanning the diff, I see the core change is a replacement of `folio_queue` and its related iterator (`ITER_FOLIOQ`) with `bvecq` and `ITER_BVECQ`. It looks like we're deprecating the `folio` implementation and moving towards something based on `bvecq`. The patch introduces new header files (`bvecq.h`), source files (`bvecq.c`), and documentation (`bvecq.rst`), along with the removal of the old `folio` counterparts. Beyond the core change, I see an extensive list of files being touched: various `afs` files, a large number of `netfs` files, and several `smb` files. We are also changing a few core include files such as `bvec.h`, `iov_iter.h`, `netfs.h`, and `uio.h`. Plus, several `lib` functions and tests are being updated. Now, the real question is reachability. Based on the triage philosophy, reachability is the primary gate for fuzzing. Is `netfs` something that's likely to be exercised in a fuzzing environment? Absolutely. `netfs` is leveraged by various network filesystems. Thinking out loud, I see that it's related to cifs/smb, afs, ceph, and even 9p. So, it's quite reachable, especially in a virtualized context. I'll need to confirm what specifically uses `netfs` or the new `iov_iter_bvec_queue` or `bvecq` directly, but that part is definitely reachable. I need to make sure this is reachable using the methods and tools that I have in place. I need to confirm reachability, and will grep for users or configs to be extra sure! |
| 4/2 | 2026/11/10 17:53 | tool | grepper |
0mArgs:{
"Expression": "CONFIG_NETFS",
"PathPrefixes": [
"fs/"
]
}Results: {
"Output": "fs/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/netfs/Makefile=3=netfs-y := \\\n--\nfs/netfs/Makefile-21-\nfs/netfs/Makefile:22:netfs-$(CONFIG_NETFS_PGPRIV2) += read_pgpriv2.o\nfs/netfs/Makefile:23:netfs-$(CONFIG_NETFS_STATS) += stats.o\nfs/netfs/Makefile-24-\n--\nfs/netfs/Makefile=35=netfs-$(CONFIG_FSCACHE_STATS) += fscache_stats.o\nfs/netfs/Makefile-36-\nfs/netfs/Makefile:37:obj-$(CONFIG_NETFS_SUPPORT) += netfs.o\n--\nfs/netfs/internal.h=121=void netfs_cache_read_terminated(void *priv, ssize_t transferred_or_error);\n--\nfs/netfs/internal.h-125- */\nfs/netfs/internal.h:126:#ifdef CONFIG_NETFS_PGPRIV2\nfs/netfs/internal.h-127-int netfs_prepare_pgpriv2_write_buffer(struct netfs_io_subrequest *subreq,\n--\nfs/netfs/internal.h=162=void netfs_unlock_abandoned_read_pages(struct netfs_io_request *rreq);\n--\nfs/netfs/internal.h-166- */\nfs/netfs/internal.h:167:#ifdef CONFIG_NETFS_STATS\nfs/netfs/internal.h-168-extern atomic_t netfs_n_rh_dio_read;\n--\nfs/netfs/internal.h=505=void fscache_create_volume(struct fscache_volume *volume, bool wait);\n--\nfs/netfs/internal.h-548-\nfs/netfs/internal.h:549:#elif defined(CONFIG_NETFS_DEBUG)\nfs/netfs/internal.h-550-#define _enter(FMT, ...)\t\t\t\\\n"
} |
| 5/2 | 2026/11/10 17:53 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 77177 output: 19 thoughts: 17 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Analyzing Filesystem Dependencies on NETFS_SUPPORT** Alright, let's dive in. My immediate thought is to trace the relationships between filesystems and `NETFS_SUPPORT`. I need to figure out which filesystems have a hard dependency on it, or perhaps, which ones "select" it implicitly. This likely means examining the Kconfig files for each filesystem in the kernel configuration. I'll need to look for `depends on` statements that explicitly mention `NETFS_SUPPORT` or any `select` statements that might be pulling it in as a consequence of choosing another option. I'm especially interested in any potential circular dependencies or subtle interactions that might not be immediately obvious. This exercise is crucial for understanding how network file system support is integrated and how it might impact the configuration process and any implications for module loading. |
| 6/2 | 2026/11/10 17:54 | tool | grepper |
0mArgs:{
"Expression": "select NETFS_SUPPORT"
}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/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/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/nfs/Kconfig=188=config NFS_FSCACHE\n--\nfs/nfs/Kconfig-190-\tdepends on NFS_FS\nfs/nfs/Kconfig:191:\tselect NETFS_SUPPORT\nfs/nfs/Kconfig-192-\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--\nnet/9p/Kconfig=6=menuconfig NET_9P\nnet/9p/Kconfig-7-\ttristate \"Plan 9 Resource Sharing Support (9P2000)\"\nnet/9p/Kconfig:8:\tselect NETFS_SUPPORT\nnet/9p/Kconfig-9-\thelp\n"
} |
| 7/2 | 2026/11/10 17:54 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 77855 output: 28 thoughts: 1015 Thoughts: **Fuzzing Decision: Worth the Effort** Okay, so I'm looking at this patch and my initial thought is, "This is big." It's touching a *lot* of things – all those `NETFS_SUPPORT` filesystems like 9P, CIFS, AFS, CEPH, and NFS_FSCACHE. And syzkaller is *already* fuzzing those filesystems, which is a good sign. But it's not just the network filesystems themselves; this patch digs into `lib/iov_iter.c`, `lib/scatterlist.c`, and the related headers. That's core stuff. I see things like `iov_iter_bvecq_advance`, `iterate_bvecq`, and a whole slew of `bvecq_` functions across multiple directories. It also touches some specific AFS and SMB code as well. The patch instructions are pretty clear: "DO NOT BLINDLY TRUST 'NO FUNCTIONAL CHANGE' (NFCI) OR 'REFACTORING' CLAIMS." This looks like a refactoring. It looks like a redesign – folio_queue is being replaced with bvecq. We need to be careful. Let's apply the rule set: 1. Is this code reachable? Yes. Network filesystems like AFS, 9P, and CIFS are *standard* in virtualized environments. I can mount these, read, write, search directories, the works. And the `iov_iter` code? That's core I/O logic, used *everywhere*. 2. The instructions also say: "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." Yup, that's what we have here. "NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED" – need to keep an eye out for that too. 3. The return value of "WorthFuzzing" is true because: "Refactorings and Code Cleanups - Any restructuring of reachable data structures, helper abstractions, or algorithm flows." Alright, so the answer is clear. `WorthFuzzing = true`. No question. Now, let's look at the fuzzing strategy. I need to figure out the right `EnableConfigs`, `FocusSymbols`, and the specific reasoning behind them. The obvious first step is to check which configuration options are relevant to ensure all the appropriate code is available. I need to check where `NETFS_SUPPORT` is defined. |
| 8/2 | 2026/11/10 17:54 | tool | grepper |
0mArgs:{
"Expression": "config NETFS_SUPPORT",
"PathPrefixes": [
"fs/"
]
}Results: {
"Output": "fs/netfs/Kconfig-2-\nfs/netfs/Kconfig:3:config NETFS_SUPPORT\nfs/netfs/Kconfig-4-\ttristate\n"
} |
| 9/2 | 2026/11/10 17:54 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 79513 output: 33 thoughts: 13 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Diving into `fs/netfs/Kconfig`** Alright, let's get down to brass tacks. My initial thought is to zero in on `fs/netfs/Kconfig`. It's where the rubber meets the road, so to speak, in terms of configuring network filesystem support within this kernel. I need to understand what's being offered, what dependencies are in play, and frankly, what *isn't* being offered. This configuration file is the architect's blueprint for what the end user can enable or disable, and how that impacts the build. I'm looking for the standard Kconfig constructs: `config` blocks, `depends on` statements, `select` statements, `bool`, `tristate` options, `default` values, the whole shebang. I'll be paying particularly close attention to: * **Dependencies:** Are there any unexpected or limiting dependencies on other kernel subsystems? I'm thinking specific network protocols, security features, or even core filesystem code that might introduce complications or conflicts. * **Granularity:** How finely is the network filesystem support controlled? Are there high-level options that encompass a bunch of features, or are the knobs and dials exposed at a more granular level? A good configuration is flexible. * **Defaults:** What are the default values for the various options? Do they represent a reasonable balance between usability and security, performance and footprint? I may be reviewing these. * **Help text:** Is the help text clear, concise, and accurate? A well-written Kconfig is self-documenting. If it's not well written, it's immediately suspect. I'm going to look at these texts carefully for clarity and for any potential gotchas. I might even suggest some improvements. * **Conflicts:** Are there any obvious conflicts between different network filesystem options or with other kernel features? This is a key area to identify potential configuration landmines. I'm essentially looking for the "shape" of the network filesystem support: its complexity, its flexibility, and its potential pitfalls. I'm expecting this `Kconfig` to reveal the design philosophy behind the integration of this network filesystem and how it all fits in with the other supported filesystems. Let's see what's in there. |
| 10/2 | 2026/11/10 17:56 | tool | read-file |
0mArgs:{
"File": "fs/netfs/Kconfig",
"FirstLine": 1,
"LineCount": 40
}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"
} |
| 11/2 | 2026/11/10 17:56 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 80600 output: 32 thoughts: 93 Thoughts: **Investigating the Unprompted NETFS_SUPPORT Tristate** Okay, so `NETFS_SUPPORT` is a tristate, but it lacks a direct prompt. That's a bit unusual. It looks like several filesystems, namely `AFS_FS`, `CIFS`, `9P_FS`, and `CEPH_FS`, select it. I need to understand this better. I'll focus on `AFS_FS`, `CIFS`, and `9P_FS` for now, ignoring `CEPH_FS` as a start. My next step is to examine their individual configurations. I'll dig into `fs/afs/Kconfig` and `fs/smb/client/Kconfig` to see how they're set up and how they interact with `NETFS_SUPPORT`. I suspect these Kconfig files hold the key to understanding why this tristate is being selected behind the scenes. |
| 12/2 | 2026/11/10 17:58 | tool | read-file |
0mArgs:{
"File": "fs/afs/Kconfig",
"FirstLine": 1,
"LineCount": 40
}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 26:\t\n 27:\tconfig AFS_FSCACHE\n 28:\t\tbool \"Provide AFS client caching support\"\n 29:\t\tdepends on AFS_FS=m \u0026\u0026 FSCACHE || AFS_FS=y \u0026\u0026 FSCACHE=y\n 30:\t\thelp\n 31:\t\t Say Y here if you want AFS data to be cached locally on disk through\n 32:\t\t the generic filesystem cache manager\n 33:\t\n 34:\tconfig AFS_DEBUG_CURSOR\n 35:\t\tbool \"AFS server cursor debugging\"\n 36:\t\tdepends on AFS_FS\n 37:\t\thelp\n 38:\t\t Say Y here to cause the contents of a server cursor to be dumped to\n 39:\t\t the dmesg log if the server rotation algorithm fails to successfully\n 40:\t\t contact a server.\n"
} |
| 13/2 | 2026/11/10 17:58 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 81453 output: 35 thoughts: 54 Thoughts: Okay, here's my take on those thoughts, framed as my own mental processing: **Examining File System Configuration Dependencies** Alright, I see `AFS_FS` is pulling in a bunch of related components: `AF_RXRPC`, `DNS_RESOLVER`, `NETFS_SUPPORT`, and `CRYPTO_KRB5`. That makes sense; AFS has a pretty specific set of networking and authentication requirements. Now, I'm getting curious about the relationship to `CIFS`. It makes me want to check the `fs/smb/client/Kconfig` file. I'm thinking the configuration might be related, and this will tell me how. |
| 14/2 | 2026/11/10 17:58 | tool | read-file |
0mArgs:{
"File": "fs/smb/client/Kconfig",
"FirstLine": 1,
"LineCount": 40
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0-only\n 2:\tconfig CIFS\n 3:\t\ttristate \"SMB3 and CIFS support (advanced network filesystem)\"\n 4:\t\tdepends on INET\n 5:\t\tselect NLS\n 6:\t\tselect NLS_UCS2_UTILS\n 7:\t\tselect CRYPTO\n 8:\t\tselect CRYPTO_AEAD2\n 9:\t\tselect CRYPTO_CCM\n 10:\t\tselect CRYPTO_GCM\n 11:\t\tselect CRYPTO_AES\n 12:\t\tselect CRYPTO_LIB_AES_CBC_MACS\n 13:\t\tselect CRYPTO_LIB_ARC4\n 14:\t\tselect CRYPTO_LIB_MD5\n 15:\t\tselect CRYPTO_LIB_SHA256\n 16:\t\tselect CRYPTO_LIB_SHA512\n 17:\t\tselect KEYS\n 18:\t\tselect DNS_RESOLVER\n 19:\t\tselect ASN1\n 20:\t\tselect OID_REGISTRY\n 21:\t\tselect NETFS_SUPPORT\n 22:\t\thelp\n 23:\t\t This is the client VFS module for the SMB3 family of network file\n 24:\t\t protocols (including the most recent, most secure dialect SMB3.1.1).\n 25:\t\t This module also includes support for earlier dialects such as\n 26:\t\t SMB2.1, SMB2 and even the old Common Internet File System (CIFS)\n 27:\t\t protocol. CIFS was the successor to the original network filesystem\n 28:\t\t protocol, Server Message Block (SMB ie SMB1), the native file sharing\n 29:\t\t mechanism for most early PC operating systems.\n 30:\t\n 31:\t\t The SMB3.1.1 protocol is supported by most modern operating systems\n 32:\t\t and NAS appliances (e.g. Samba, Windows 11, Windows Server 2022,\n 33:\t\t MacOS) and even in the cloud (e.g. Microsoft Azure) and also by the\n 34:\t\t Linux kernel server, ksmbd. Support for the older CIFS protocol was\n 35:\t\t included in Windows NT4, 2000 and XP (and later). Use of dialects\n 36:\t\t older than SMB2.1 is often discouraged on public networks.\n 37:\t\t This module also provides limited support for OS/2 and Windows ME\n 38:\t\t and similar very old servers.\n 39:\t\n 40:\t\t This module provides an advanced network file system client for\n"
} |
| 15/2 | 2026/11/10 17:58 | llm | patch-evaluator |
2mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 82323 output: 37 thoughts: 2158 Thoughts: **Focusing on NetFS and Related File System Operations** Okay, let's break this down for a fuzzing configuration. My primary goal here is to identify the critical kernel symbols impacted by this patchset and determine the relevant Kconfig options that control their inclusion. First, I need to understand the dependencies. `9P_FS` looks like a good starting point, as it depends on `NET_9P` which selects `NETFS_SUPPORT`. Aha! `NETFS_SUPPORT` is key, and it seems like enabling it also brings in `bvecq.c` and `rolling_buffer.c`, along with various `netfs-*` files, and `lib/iov_iter.c` which I suspect is used ubiquitously. I should also note that `AFS_FS` and `CIFS` also depend on `NETFS_SUPPORT`. The `EnableConfigs` should absolutely include `NETFS_SUPPORT` alongside `AFS_FS`, `CIFS`, `9P_FS`, and `FSCACHE`. The note about `NETFS_SUPPORT` being directly listed is important. Listing it directly is good even if it doesn't have a prompt. And, wait, there's `AFS_FSCACHE` and the `fscache_cookie_enabled` call! That suggests `FSCACHE` is critical for some code paths, especially for `afs_symlink_writepages` and `netfs_writeback_single`. `AFS_FSCACHE` specifically depends on `AFS_FS` and `FSCACHE`, and this needs to be captured too. Now, the juicy part: the `FocusSymbols`. I need to avoid ubiquitous functions – no general memory allocators, page fault handlers, or core synchronization primitives. I'm targeting specific feature logic and entrypoints. Looking at the patch, I've got a list of symbols I need to evaluate carefully, grouping by file. 1. `fs/netfs/bvecq.c`: All the `bvecq_alloc_...` and `bvecq_put`, `bvecq_expand_buffer`, `bvecq_dump` are good candidates. 2. `lib/iov_iter.c`: **Crucially, I need to avoid `iov_iter_advance` and `iov_iter_revert`. These are too generic, part of any IO. However, `iov_iter_bvec_queue` is a *specific* entrypoint to set up an `ITER_BVECQ` iterator.** `iov_iter_single_seg_count`, `iov_iter_alignment_bvecq`, `iter_bvecq_get_pages`, `iov_iter_npages_bvecq` and `iov_iter_extract_bvecq_pages` are also relevant. 3. `fs/netfs/rolling_buffer.c`: `rolling_buffer_init`, `rolling_buffer_make_space`, `rolling_buffer_bulk_load_from_ra`, `rolling_buffer_append`, `rolling_buffer_delete_spent`, `rolling_buffer_clear`. 4. `fs/netfs/write_issue.c`: `netfs_writeback_single` (especially with the signature change and removal of `netfs_write_folio_single`), plus `netfs_prepare_write`, `netfs_create_write_req`, and `netfs_writepages`. 5. `fs/netfs/buffered_read.c`: `netfs_readahead`, `netfs_read_folio`, `netfs_read_to_pagecache`, `netfs_mark_copy_to_cache`. 6. `fs/netfs/read_collect.c`: `netfs_read_unlock_folios`, `netfs_unlock_read_folio`, `netfs_read_set_unlock_at`. 7. `fs/netfs/read_retry.c`: `netfs_unlock_abandoned_read_pages`. 8. `fs/netfs/write_collect.c`: `netfs_writeback_unlock_folios`. 9. `fs/netfs/iterator.c`: `netfs_limit_iter`, `netfs_limit_bvecq`. 10. `fs/afs/dir.c`: `afs_read_dir`, `afs_do_read_single`, `afs_dir_iterate_contents`, `afs_dir_check`, `afs_dir_dump`, `afs_dir_writepages`. 11. `fs/afs/dir_edit.c`: `afs_dir_get_block`. 12. `fs/afs/dir |
| 16/2 | 2026/11/10 18:01 | tool | grepper |
0mArgs:{
"Expression": "bvecq_alloc_",
"PathPrefixes": [
"fs/netfs/bvecq.c"
]
}Results: {
"Output": "fs/netfs/bvecq.c=34=EXPORT_SYMBOL(bvecq_dump);\n--\nfs/netfs/bvecq.c-36-/**\nfs/netfs/bvecq.c:37: * bvecq_alloc_one - Allocate a single bvecq node with unpopulated slots\nfs/netfs/bvecq.c-38- * @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-104-}\nfs/netfs/bvecq.c:105:EXPORT_SYMBOL(bvecq_alloc_one);\nfs/netfs/bvecq.c-106-\nfs/netfs/bvecq.c-107-/**\nfs/netfs/bvecq.c:108: * bvecq_alloc_chain - Allocate an unpopulated bvecq chain\nfs/netfs/bvecq.c-109- * @nr_slots: Number of slots to allocate\n--\nfs/netfs/bvecq.c-117- */\nfs/netfs/bvecq.c:118:struct bvecq *bvecq_alloc_chain(size_t nr_slots, gfp_t gfp, bool for_writeback)\nfs/netfs/bvecq.c-119-{\n--\nfs/netfs/bvecq.c-126-\nfs/netfs/bvecq.c:127:\t\tbq = bvecq_alloc_one(min(nr_slots, BVECQ_4KB_SLOTS), gfp, for_writeback);\nfs/netfs/bvecq.c-128-\t\tif (!bq)\n--\nfs/netfs/bvecq.c-145-}\nfs/netfs/bvecq.c:146:EXPORT_SYMBOL(bvecq_alloc_chain);\nfs/netfs/bvecq.c-147-\nfs/netfs/bvecq.c-148-/**\nfs/netfs/bvecq.c:149: * bvecq_alloc_buffer2 - Allocate a bvecq chain and populate with buffers\nfs/netfs/bvecq.c-150- * @size: Target size of the buffer (can be 0 for an empty buffer)\n--\nfs/netfs/bvecq.c-166- */\nfs/netfs/bvecq.c:167:struct bvecq *bvecq_alloc_buffer2(size_t size, unsigned int pre_slots, gfp_t gfp,\nfs/netfs/bvecq.c-168-\t\t\t\t bool for_writeback)\n--\nfs/netfs/bvecq.c-178-\nfs/netfs/bvecq.c:179:\thead = bvecq_alloc_chain(count, gfp, for_writeback);\nfs/netfs/bvecq.c-180-\tif (!head)\n--\nfs/netfs/bvecq.c-234-}\nfs/netfs/bvecq.c:235:EXPORT_SYMBOL(bvecq_alloc_buffer2);\nfs/netfs/bvecq.c-236-\n--\nfs/netfs/bvecq.c=307=int bvecq_expand_buffer(struct bvecq **_buffer, size_t *_cur_size, size_t size, gfp_t gfp)\n--\nfs/netfs/bvecq.c-324-\nfs/netfs/bvecq.c:325:\t\t\tp = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, false);\nfs/netfs/bvecq.c-326-\t\t\tif (!p)\n"
} |
| 17/2 | 2026/11/10 18:01 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 86568 output: 36 thoughts: 108 Thoughts: **Analyzing Block Vector Queue Interactions** Okay, let's dive into this. My first thought is to verify the exported functions in `fs/netfs/bvecq.c`. I need a quick overview. Let's list those out: `bvecq_alloc_one`, `bvecq_alloc_chain`, `bvecq_alloc_buffer2`, `bvecq_put`, `bvecq_expand_buffer`, and `bvecq_dump`. Got it. Now, given my knowledge, that tells me the core operations involved in managing this block vector queue. Next, I need to check how these block vectors actually get *iterated* on. Given the nature of block I/O, I'm going to quickly look at `lib/iov_iter.c` to see if there's an `iov_iter_bvec_queue` function defined within that context. I know this is often where these things are managed, so I'll check that next. I need to understand how the queued block vectors are translated into I/O requests. |
| 18/2 | 2026/11/10 18:02 | tool | grepper |
0mArgs:{
"Expression": "iov_iter_bvec_queue",
"PathPrefixes": [
"lib/iov_iter.c"
]
}Results: {
"Output": "lib/iov_iter.c=741=EXPORT_SYMBOL(iov_iter_bvec);\n--\nlib/iov_iter.c-743-/**\nlib/iov_iter.c:744: * iov_iter_bvec_queue - Initialise an I/O iterator to use a segmented bvec queue\nlib/iov_iter.c-745- * @i: The iterator to initialise.\n--\nlib/iov_iter.c-756- */\nlib/iov_iter.c:757:void iov_iter_bvec_queue(struct iov_iter *i, unsigned int direction,\nlib/iov_iter.c-758-\t\t\t const struct bvecq *bvecq, unsigned int first_slot,\n--\nlib/iov_iter.c-770-}\nlib/iov_iter.c:771:EXPORT_SYMBOL(iov_iter_bvec_queue);\nlib/iov_iter.c-772-\n"
} |
| 19/2 | 2026/11/10 18:02 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 87192 output: 35 thoughts: 16 Thoughts: Okay, let's dive into this. Here's my thought process on this one: **Investigating `fs/netfs/rolling_buffer.c`** Alright, I'm thinking, where do I start with this network file system issue? Okay, first things first, let's take a look at the code. Specifically, let's examine the `fs/netfs/rolling_buffer.c` file. This is the place to start, as a rolling buffer seems like a very likely candidate to cause some issues related to network filesystems. Let's see what we can find. I expect to find some interesting logic related to data buffering and I am hoping for some insight into what the code is attempting to achieve in network file IO, or potential errors. This is the obvious starting point. Now, let's get into the code and see what surprises it holds. |
| 20/2 | 2026/11/10 18:03 | tool | grepper |
0mArgs:{
"Expression": "rolling_buffer_",
"PathPrefixes": [
"fs/netfs/rolling_buffer.c"
]
}Results: {
"Output": "fs/netfs/rolling_buffer.c-18- */\nfs/netfs/rolling_buffer.c:19:int rolling_buffer_init(struct rolling_buffer *roll, unsigned int direction,\nfs/netfs/rolling_buffer.c-20-\t\t\tgfp_t gfp, bool for_writeback)\n--\nfs/netfs/rolling_buffer.c-38- */\nfs/netfs/rolling_buffer.c:39:int rolling_buffer_make_space(struct rolling_buffer *roll, gfp_t gfp)\nfs/netfs/rolling_buffer.c-40-{\n--\nfs/netfs/rolling_buffer.c-73- */\nfs/netfs/rolling_buffer.c:74:ssize_t rolling_buffer_bulk_load_from_ra(struct rolling_buffer *roll,\nfs/netfs/rolling_buffer.c-75-\t\t\t\t\t struct readahead_control *ractl,\n--\nfs/netfs/rolling_buffer.c-130-\t}\nfs/netfs/rolling_buffer.c:131:\trolling_buffer_clear(roll);\nfs/netfs/rolling_buffer.c-132-\troll-\u003ehead = NULL;\n--\nfs/netfs/rolling_buffer.c-139- */\nfs/netfs/rolling_buffer.c:140:ssize_t rolling_buffer_append(struct rolling_buffer *roll, struct folio *folio,\nfs/netfs/rolling_buffer.c-141-\t\t\t gfp_t gfp)\n--\nfs/netfs/rolling_buffer.c-145-\nfs/netfs/rolling_buffer.c:146:\tif (rolling_buffer_make_space(roll, gfp) \u003c 0)\nfs/netfs/rolling_buffer.c-147-\t\treturn -ENOMEM;\n--\nfs/netfs/rolling_buffer.c-161- */\nfs/netfs/rolling_buffer.c:162:struct bvecq *rolling_buffer_delete_spent(struct rolling_buffer *roll)\nfs/netfs/rolling_buffer.c-163-{\n--\nfs/netfs/rolling_buffer.c-177- */\nfs/netfs/rolling_buffer.c:178:void rolling_buffer_clear(struct rolling_buffer *roll)\nfs/netfs/rolling_buffer.c-179-{\n"
} |
| 21/2 | 2026/11/10 18:03 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 88036 output: 33 thoughts: 26 Thoughts: Here's my summary, as though I'm thinking through this process: **Diving into `netfs_writeback_single`** Okay, time to dig into this writeback issue. Let's start with `netfs_writeback_single`. That's in `fs/netfs/write_issue.c`, right? Just want to confirm the source location. Need to see how individual writebacks are handled within the `netfs` filesystem. I'm expecting to find the core logic for pushing data out across the network here, likely some interaction with the network stack, and probably some handling of errors or retries. I'll be looking for any hints about how data is batched, prioritized, and synchronized. Let's see what's actually going on in there. |
| 22/2 | 2026/11/10 18:03 | tool | grepper |
0mArgs:{
"Expression": "netfs_writeback_single",
"PathPrefixes": [
"fs/netfs/"
]
}Results: {
"Output": "fs/netfs/write_issue.c=628=EXPORT_SYMBOL(netfs_writepages);\n--\nfs/netfs/write_issue.c-630-/**\nfs/netfs/write_issue.c:631: * netfs_writeback_single - Write back a monolithic payload to cache\nfs/netfs/write_issue.c-632- * @mapping: The mapping to write from\n--\nfs/netfs/write_issue.c-646- */\nfs/netfs/write_issue.c:647:int netfs_writeback_single(struct address_space *mapping,\nfs/netfs/write_issue.c-648-\t\t\t struct writeback_control *wbc,\n--\nfs/netfs/write_issue.c-714-}\nfs/netfs/write_issue.c:715:EXPORT_SYMBOL(netfs_writeback_single);\n"
} |
| 23/2 | 2026/11/10 18:03 | llm | patch-evaluator |
2mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 88503 output: 32 thoughts: 12 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience and presented in the first person: **Diving into `netfs_limit_iter`** Right, let's get down to brass tacks and take a closer look at `netfs_limit_iter`. I'm immediately interested in the specifics. What are its performance characteristics? Where is it used, and how frequently? Are there any known bottlenecks or areas for potential optimization associated with this particular iterator? I need to understand its role within the broader `netfs` context to assess its impact. Specifically, does it interact with other critical components, and, if so, how? Let's trace its dependencies. The goal is to fully understand how and when this function is being used. |
| 24/2 | 2026/11/10 18:05 | tool | grepper |
0mArgs:{
"Expression": "netfs_limit_iter",
"PathPrefixes": [
"fs/netfs/"
]
}Results: {
"Output": "fs/netfs/buffered_read.c=114=static ssize_t netfs_prepare_read_iterator(struct netfs_io_subrequest *subreq)\n--\nfs/netfs/buffered_read.c-123-\tif (unlikely(rreq-\u003eio_streams[0].sreq_max_segs)) {\nfs/netfs/buffered_read.c:124:\t\tsize_t limit = netfs_limit_iter(\u0026rreq-\u003ebuffer.iter, 0, rsize,\nfs/netfs/buffered_read.c-125-\t\t\t\t\t\trreq-\u003eio_streams[0].sreq_max_segs);\n--\nfs/netfs/direct_read.c=19=static void netfs_prepare_dio_read_iterator(struct netfs_io_subrequest *subreq)\n--\nfs/netfs/direct_read.c-27-\tif (unlikely(rreq-\u003eio_streams[0].sreq_max_segs)) {\nfs/netfs/direct_read.c:28:\t\tsize_t limit = netfs_limit_iter(\u0026rreq-\u003ebuffer.iter, 0, rsize,\nfs/netfs/direct_read.c-29-\t\t\t\t\t\trreq-\u003eio_streams[0].sreq_max_segs);\n--\nfs/netfs/direct_write.c=94=static int netfs_unbuffered_write(struct netfs_io_request *wreq)\n--\nfs/netfs/direct_write.c-137-\nfs/netfs/direct_write.c:138:\t\tsubreq-\u003elen = netfs_limit_iter(\u0026subreq-\u003eio_iter, 0,\nfs/netfs/direct_write.c-139-\t\t\t\t\t stream-\u003esreq_max_len,\n--\nfs/netfs/iterator.c=252=static size_t netfs_limit_bvecq(const struct iov_iter *iter, size_t start_offset,\n--\nfs/netfs/iterator.c-294-\nfs/netfs/iterator.c:295:size_t netfs_limit_iter(const struct iov_iter *iter, size_t start_offset,\nfs/netfs/iterator.c-296-\t\t\tsize_t max_size, size_t max_segs)\n--\nfs/netfs/iterator.c-307-}\nfs/netfs/iterator.c:308:EXPORT_SYMBOL(netfs_limit_iter);\n--\nfs/netfs/read_retry.c=26=static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)\n--\nfs/netfs/read_retry.c-151-\t\t\tif (unlikely(stream-\u003esreq_max_segs))\nfs/netfs/read_retry.c:152:\t\t\t\tpart = netfs_limit_iter(\u0026source, 0, part, stream-\u003esreq_max_segs);\nfs/netfs/read_retry.c-153-\t\t\tsubreq-\u003elen = subreq-\u003etransferred + part;\n--\nfs/netfs/read_retry.c-220-\t\t\tif (unlikely(stream-\u003esreq_max_segs))\nfs/netfs/read_retry.c:221:\t\t\t\tpart = netfs_limit_iter(\u0026source, 0, part, stream-\u003esreq_max_segs);\nfs/netfs/read_retry.c-222-\n--\nfs/netfs/write_retry.c=17=static void netfs_retry_write_stream(struct netfs_io_request *wreq,\n--\nfs/netfs/write_retry.c-113-\t\t\tif (unlikely(stream-\u003esreq_max_segs))\nfs/netfs/write_retry.c:114:\t\t\t\tpart = netfs_limit_iter(\u0026source, 0, part, stream-\u003esreq_max_segs);\nfs/netfs/write_retry.c-115-\t\t\tsubreq-\u003elen = part;\n"
} |
| 25/2 | 2026/11/10 18:05 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 89711 output: 364 thoughts: 1768 Thoughts: **Analysis of File System Code for Fuzzing** Alright, let's break this down. My goal here is to identify the critical functions and configurations relevant for fuzzing this patch. First, I went through the code, meticulously listing functions in `fs/afs`, `fs/netfs`, and associated libraries (`lib/iov_iter.c`, `lib/scatterlist.c`). The initial list included everything touched: `afs_dir_iterate_contents`, `afs_do_read_single`, `afs_dir_check`, `afs_dir_dump`, `afs_dir_writepages`, `afs_dir_get_block`, `afs_dir_find_block`, `afs_init_new_symlink`, `afs_do_read_symlink`, `afs_symlink_writepages`, `netfs_read_unlock_folios`, `netfs_read_set_unlock_at`, `netfs_writeback_unlock_folios`, `netfs_unlock_abandoned_read_pages`. Then, I did a crucial filtering step: I eliminated anything ubiquitous. Things like generic allocators are too general to target, so I excluded them. This led me to focus on functions specific to `bvecq`, `netfs`, `afs`, and `cifs`, as these are the core components being modified. Specifically, I'm interested in the new functions that implement the novel logic or interact directly with the changes introduced by this patch. This process yielded a list of functions that warrant special attention: `bvecq_alloc_one`, `bvecq_alloc_chain`, `bvecq_alloc_buffer2`, `bvecq_put`, `bvecq_expand_buffer`, `iov_iter_bvec_queue`, `rolling_buffer_init`, `rolling_buffer_append`, `rolling_buffer_make_space`, `rolling_buffer_bulk_load_from_ra`, `rolling_buffer_delete_spent`, `netfs_writeback_single`, `netfs_read_unlock_folios`, `netfs_writeback_unlock_folios`, `netfs_limit_iter`, `afs_dir_get_block`, `afs_dir_find_block`, and `afs_symlink_writepages`. I also checked to see if any of the supporting iov_iter functions were appropriate to include - especially non-static, non-ubiquitous ones like `iov_iter_bvec_queue`, `iov_iter_single_seg_count`, and `extract_iter_to_sg`. I then made sure I included *all* the new bvecq and rolling_buffer functions: And `rolling_buffer_init` `rolling_buffer_make_space` `rolling_buffer_bulk_load_from_ra` `rolling_buffer_append` `rolling_buffer_delete_spent` `rolling_buffer_clear` And `netfs_writeback_single` `netfs_limit_iter` `netfs_read_unlock_folios` `netfs_writeback_unlock_folios` `netfs_unlock_abandoned_read_pages` And `afs_dir_get_block` `afs_dir_find_block` `afs_do_read_single` `afs_symlink_writepages` `afs_dir_writepages` Next, I turned my attention to configurations. I need to ensure that the fuzzing target can be built correctly. I identified the necessary kernel configuration options: `NETFS_SUPPORT`, `AFS_FS`, `CIFS`, `FSCACHE`, `AFS_FSCACHE`, and `9P_FS`. I also verified that no other dependencies (like `INET`) are needed by any of those options. Finally, I confirmed that all requirements are met: This code is worth fuzzing because it touches core and network filesystem code. The fuzz targets will cover `netfs`, `iov_iter`, `scatterlist`, `afs`, and `cifs`. These functions are directly involved in buffer management, iterator traversal, and read/write operations, so they're excellent targets for fuzzing. The defined configs and symbols are accurate. I'm satisfied. Now, let's call `set-results`. |
| 26/2 | 2026/11/10 18:07 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"NETFS_SUPPORT",
"AFS_FS",
"CIFS",
"FSCACHE",
"AFS_FSCACHE",
"9P_FS"
],
"FocusSymbols": [
"bvecq_alloc_one",
"bvecq_alloc_chain",
"bvecq_alloc_buffer2",
"bvecq_put",
"bvecq_expand_buffer",
"iov_iter_bvec_queue",
"rolling_buffer_init",
"rolling_buffer_make_space",
"rolling_buffer_bulk_load_from_ra",
"rolling_buffer_append",
"rolling_buffer_delete_spent",
"netfs_writeback_single",
"netfs_read_unlock_folios",
"netfs_writeback_unlock_folios",
"netfs_limit_iter",
"afs_dir_get_block",
"afs_dir_find_block",
"afs_symlink_writepages"
],
"Reasoning": "The patch series replaces the folio_queue abstraction with bvecq (segmented bio_vec queue) across netfs, iov_iter, scatterlist, afs, and smb/cifs. It introduces new memory management, refcounting, and queue manipulation helpers (bvecq_*), reworks rolling buffer management in netfs, modifies iteration and extraction primitives in lib/iov_iter.c, and updates read/write collection and directory/symlink handling in afs and cifs. These are reachable core and filesystem code paths that warrant fuzzing.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"NETFS_SUPPORT",
"AFS_FS",
"CIFS",
"FSCACHE",
"AFS_FSCACHE",
"9P_FS"
],
"FocusSymbols": [
"bvecq_alloc_one",
"bvecq_alloc_chain",
"bvecq_alloc_buffer2",
"bvecq_put",
"bvecq_expand_buffer",
"iov_iter_bvec_queue",
"rolling_buffer_init",
"rolling_buffer_make_space",
"rolling_buffer_bulk_load_from_ra",
"rolling_buffer_append",
"rolling_buffer_delete_spent",
"netfs_writeback_single",
"netfs_read_unlock_folios",
"netfs_writeback_unlock_folios",
"netfs_limit_iter",
"afs_dir_get_block",
"afs_dir_find_block",
"afs_symlink_writepages"
],
"Reasoning": "The patch series replaces the folio_queue abstraction with bvecq (segmented bio_vec queue) across netfs, iov_iter, scatterlist, afs, and smb/cifs. It introduces new memory management, refcounting, and queue manipulation helpers (bvecq_*), reworks rolling buffer management in netfs, modifies iteration and extraction primitives in lib/iov_iter.c, and updates read/write collection and directory/symlink handling in afs and cifs. These are reachable core and filesystem code paths that warrant fuzzing.",
"WorthFuzzing": true
} |
| 27/1 | 2026/11/10 18:07 | action | If |
4mArgs:{
"WorthFuzzing": true
}Results: null |
| 28/2 | 2026/11/10 18:07 | agent | kmsan-evaluator |
4mModel:core Args: null Results: {
"KMSANReasoning": "The patch series replaces the `folio_queue` data structure (`ITER_FOLIOQ`) with `bvecq` (`ITER_BVECQ`) across netfs, AFS, and CIFS/SMB. \n\n1. Allocation \u0026 Initialization: Newly introduced `struct bvecq` instances are allocated via `bvecq_alloc_one()` and fully initialized using a designated C99 struct literal `*bq = (struct bvecq) { ... }`, which guarantees that all unmentioned fields (such as `next`, `prev`, `nr_slots`, `priv`) are zero-initialized. When allocating pre-populated slot buffers (`bvecq_alloc_buffer2`), all slots in `p-\u003ebv` are explicitly zeroed with `memset` before population. In `bvecq_expand_buffer()`, each bio_vec slot is fully initialized via `bvec_set_page()` before `bvecq_filled_to()` updates `nr_slots`.\n2. Access \u0026 Boundaries: Accesses to slots in `bq-\u003ebv` are strictly bounded by `bq-\u003enr_slots` (or `bvecq_acquire_slot()`), preventing reads of uninitialized slots.\n3. Information Leaks \u0026 Userspace Copying: Neither `struct bvecq` nor its internal metadata is copied to userspace. In AFS directory and symlink handling, the patch explicitly adds zeroing of buffer padding (`iov_iter_zero`) before writeback/cache storage.\n4. Error surface: Any potential bugs introduced by this patch (e.g., iterator slot advancement/revert bounds bugs, list traversal issues, or refcounting errors) represent out-of-bounds accesses, use-after-free, or concurrency issues, which are comprehensively detected by KASAN and standard kernel debug facilities.\n\nTherefore, dedicated KMSAN fuzzing is not required.",
"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 fdcfc8440281f97bfd03cc621cb873b3b7b135ac
Author: syz-cluster <triage@syzkaller.com>
Date: Tue Nov 10 17:50:40 2026 +0000
syz-cluster: applied patch under review
diff --git a/Documentation/core-api/bvecq.rst b/Documentation/core-api/bvecq.rst
new file mode 100644
index 00000000000000..4a2b3e28898220
--- /dev/null
+++ b/Documentation/core-api/bvecq.rst
@@ -0,0 +1,229 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=========================================
+bvecq - Chainable bio_vec queue structure
+=========================================
+
+Author: David Howells <dhowells@redhat.com>
+
+.. Contents:
+
+ * Overview
+ * Allocating bvecqs
+ * Refcounting
+ * Expandable buffer
+ * Producer functions
+ * Consumer functions
+ * Utility functions
+ * I/O iterators
+ * API Function Reference
+
+
+Overview
+========
+
+The ``bvecq`` struct can be used to form chains of arrays of ``bio_vec``
+structures - kind of a single layer of indirection. Each bvecq segment points
+to the previous and next bvecq segments in the chain, but is not intended to
+form a circular queue as there are applications where the producer is adding to
+one end whilst the consumer is taking off the other.
+
+To use this, the caller should do::
+
+ #include <linux/bvecq.h>
+
+The publicly accessible members of the structure are::
+
+ struct bvecq {
+ struct bvecq *next;
+ struct bvecq *prev;
+ u32 priv;
+ u16 nr_slots;
+ u16 max_slots;
+ enum bvecq_mem mem_type:3;
+ struct bio_vec *bv;
+ ...
+ };
+
+A pair of pointers are provided, ``next`` and ``prev``, that point to the
+segments on either side of the segment being accessed. Whilst this is a
+doubly-linked list, it is intentionally not a circular list; the outward
+sibling pointers in terminal segments should be NULL.
+
+The ``priv`` member is for the owner of the bvecq to use as they will.
+
+The ``bv`` pointer points at an array of bio_vecs that list a number of regions
+of memory. ``max_slots`` indicates how large the array is and ``nr_slots``
+says how much of the array is being used. Note that there are access functions
+for nr_slots that insert appropriate barriering in the case that there are
+separate producer and consumer threads.
+
+The ``mem_type`` member informs bvecq_put() of how to clean up the bio_vecs
+attached to this segment. It can be one of:
+
+ * ``BVECQ_MEM_EXTERNAL`` - Externally managed; no cleanup.
+ * ``BVECQ_MEM_PAGECACHE`` - Part of pagecache; put_page() used.
+ * ``BVECQ_MEM_GUP`` - Pinned userspace memory; unpin_user_page() used.
+ * ``BVECQ_MEM_ALLOCED`` - Allocated page; __free_pages() used, may be pooled.
+
+
+Allocating bvecqs
+=================
+
+A number of functions are provided to allocate bvecqs::
+
+ 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);
+ struct bvecq *bvecq_alloc_buffer(size_t size,
+ gfp_t gfp,
+ bool for_writeback);
+ struct bvecq *bvecq_alloc_buffer2(size_t size,
+ unsigned int pre_slots,
+ gfp_t gfp,
+ bool for_writeback);
+
+The first of these, ``bvecq_alloc_one()`` allocates a single bvecq with at
+least the requested number of inline slots. The size of the object is rounded
+up to the size of the slab granule that it will be allocated in and the number
+of slots increased appropriately to match. If ``for_writeback`` is set, then
+the netfslib writeback bvecq pool will be used to backstop the allocation if
+the initial slab request fails; in such a case, the number of slots will get
+reduced to ``BVECQ_POOL_SLOTS``.
+
+Two convenience slot count constants are provided:
+
+ * ``BVECQ_POOL_SLOTS`` - The right number of slots to alloc from the mempool
+ * ``BVECQ_4KB_SLOTS`` - The right number of slots to get a 4K allocation
+
+``bvecq_alloc_chain()`` will allocate a sufficiently large chain of bvecqs to
+hold the requested number of slots, capping each allocation at 4K.
+
+``bvecq_alloc_buffer()`` will allocate a chain and populate it, allocating
+sufficient pages to provide a buffer of the specified size attached to the
+chain. ``bvecq_alloc_buffer2()`` is similar, but it reserves some unused
+slots at the front of the chain. Note that these functions may add multipage
+pages in the future.
+
+
+Refcounting
+===========
+
+Each bvecq has a refcount and two functions are provided to handle that::
+
+ struct bvecq *bvecq_get(struct bvecq *bq);
+ void bvecq_put(struct bvecq *bq);
+
+The first of these gets a new reference and the second drops a reference. When
+the refcount hits zero, the second iteratively drops the refs along the chain
+until it hits a segment that has a refcount that doesn't reduce to zero.
+
+
+Expandable buffer
+=================
+
+This facility provides a function to manage an expandable buffer::
+
+ int bvecq_expand_buffer(struct bvecq **_buffer,
+ size_t *_cur_size,
+ size_t size,
+ gfp_t gfp);
+
+Pages are added to the bvecq chain and the chain expanded such that, on
+returning, it holds ``size`` amount of space (without losing any content). The
+caller needs to retain ``*_cur_size`` between calls as that tracks the amount
+of space currently allocated. Note that pages in the chain may be allocated as
+compound pages larger than PAGE_SIZE.
+
+
+Producer functions
+==================
+
+When building and filling a bvecq, there are a number of utility functions that
+can be used to provide the correct barriering and to query the fields in the
+bvecq currently being filled.
+
+Firstly, there's a function to check to see if a bvecq has any spare slots
+left::
+
+ bool bvecq_is_full(const struct bvecq *bvecq);
+
+If not, ``bvecq_alloc_one()`` can be called to allocate a new segment which can
+be initialised and then added to the chain with::
+
+ void bvecq_append(struct bvecq *to, struct bvecq *add);
+
+bio_vec slots in the segment can then be filled and the number of occupied
+slots updated by calling::
+
+ void bvecq_filled_to(struct bvecq *bvecq,
+ unsigned int to);
+
+to insert the appropriate barrier.
+
+
+Consumer functions
+==================
+
+When consuming and destroying a bvecq, there are some utility functions for
+that too, providing the needed barriering. Firstly, there's a function to find
+out how many slots have been used in the current bvecq::
+
+ unsigned int bvecq_nr_slots_acquire(const struct bvecq *bvecq);
+
+Or, more conveniently, if the current slot position is valid within the bvecq::
+
+ bool bvecq_acquire_slot(const struct bvecq *bvecq,
+ unsigned int slot);
+
+If this returns true, the slot is valid and can be looked at; if it returns
+false, the bvecq may have been consumed. If it has, the next bvecq can be
+obtained by calling::
+
+ struct bvecq *bvecq_next(const struct bvecq *bq);
+
+which inserts the appropriate barrier - though bvecq_acquire_slot should be
+rechecked after calling this in case the producer added more slots and then
+extended the list.
+
+
+Utility functions
+=================
+
+A utility function is provided to list the bio_vecs pointed to by a bvecq
+chain::
+
+ void bvecq_dump(const struct bvecq *bq);
+
+
+I/O iterators
+=============
+
+bvecq chains can be used with the ``iov_iter`` facility too. An iterator can
+be initialised to point at a chain by calling::
+
+ void iov_iter_bvec_queue(struct iov_iter *i,
+ unsigned int direction,
+ const struct bvecq *bvecq,
+ unsigned int first_slot,
+ unsigned int offset,
+ size_t count);
+
+In addition to setting the iterator, direction and count, the first bvecq in
+the chain to be iterated over is set, along with the starting slot in that
+iterator and the offset into the slot. Once the iterator is set up, it can be
+treated like any other I/O iterator.
+
+In a producer/consumer environment, it is expected that when an iterator is set
+up, all the bvecqs and all the slots within the count of the iterator must
+exist and must be populated before this function is called.
+
+
+API Function Reference
+======================
+
+.. kernel-doc:: include/linux/bvecq.h
+.. kernel-doc:: fs/netfs/bvecq.c
diff --git a/Documentation/core-api/folio_queue.rst b/Documentation/core-api/folio_queue.rst
deleted file mode 100644
index b7628896d2b695..00000000000000
--- a/Documentation/core-api/folio_queue.rst
+++ /dev/null
@@ -1,209 +0,0 @@
-.. SPDX-License-Identifier: GPL-2.0+
-
-===========
-Folio Queue
-===========
-
-:Author: David Howells <dhowells@redhat.com>
-
-.. Contents:
-
- * Overview
- * Initialisation
- * Adding and removing folios
- * Querying information about a folio
- * Querying information about a folio_queue
- * Folio queue iteration
- * Folio marks
- * Lockless simultaneous production/consumption issues
-
-
-Overview
-========
-
-The folio_queue struct forms a single segment in a segmented list of folios
-that can be used to form an I/O buffer. As such, the list can be iterated over
-using the ITER_FOLIOQ iov_iter type.
-
-The publicly accessible members of the structure are::
-
- struct folio_queue {
- struct folio_queue *next;
- struct folio_queue *prev;
- ...
- };
-
-A pair of pointers are provided, ``next`` and ``prev``, that point to the
-segments on either side of the segment being accessed. Whilst this is a
-doubly-linked list, it is intentionally not a circular list; the outward
-sibling pointers in terminal segments should be NULL.
-
-Each segment in the list also stores:
-
- * an ordered sequence of folio pointers,
- * the size of each folio and
- * three 1-bit marks per folio,
-
-but these should not be accessed directly as the underlying data structure may
-change, but rather the access functions outlined below should be used.
-
-The facility can be made accessible by::
-
- #include <linux/folio_queue.h>
-
-and to use the iterator::
-
- #include <linux/uio.h>
-
-
-Initialisation
-==============
-
-A segment should be initialised by calling::
-
- void folioq_init(struct folio_queue *folioq);
-
-with a pointer to the segment to be initialised. Note that this will not
-necessarily initialise all the folio pointers, so care must be taken to check
-the number of folios added.
-
-
-Adding and removing folios
-==========================
-
-Folios can be set in the next unused slot in a segment struct by calling one
-of::
-
- unsigned int folioq_append(struct folio_queue *folioq,
- struct folio *folio);
-
- unsigned int folioq_append_mark(struct folio_queue *folioq,
- struct folio *folio);
-
-Both functions update the stored folio count, store the folio and note its
-size. The second function also sets the first mark for the folio added. Both
-functions return the number of the slot used. [!] Note that no attempt is made
-to check that the capacity wasn't overrun and the list will not be extended
-automatically.
-
-A folio can be excised by calling::
-
- void folioq_clear(struct folio_queue *folioq, unsigned int slot);
-
-This clears the slot in the array and also clears all the marks for that folio,
-but doesn't change the folio count - so future accesses of that slot must check
-if the slot is occupied.
-
-
-Querying information about a folio
-==================================
-
-Information about the folio in a particular slot may be queried by the
-following function::
-
- struct folio *folioq_folio(const struct folio_queue *folioq,
- unsigned int slot);
-
-If a folio has not yet been set in that slot, this may yield an undefined
-pointer. The size of the folio in a slot may be queried with either of::
-
- unsigned int folioq_folio_order(const struct folio_queue *folioq,
- unsigned int slot);
-
- size_t folioq_folio_size(const struct folio_queue *folioq,
- unsigned int slot);
-
-The first function returns the size as an order and the second as a number of
-bytes.
-
-
-Querying information about a folio_queue
-========================================
-
-Information may be retrieved about a particular segment with the following
-functions::
-
- unsigned int folioq_nr_slots(const struct folio_queue *folioq);
-
- unsigned int folioq_count(struct folio_queue *folioq);
-
- bool folioq_full(struct folio_queue *folioq);
-
-The first function returns the maximum capacity of a segment. It must not be
-assumed that this won't vary between segments. The second returns the number
-of folios added to a segments and the third is a shorthand to indicate if the
-segment has been filled to capacity.
-
-Not that the count and fullness are not affected by clearing folios from the
-segment. These are more about indicating how many slots in the array have been
-initialised, and it assumed that slots won't get reused, but rather the segment
-will get discarded as the queue is consumed.
-
-
-Folio marks
-===========
-
-Folios within a queue can also have marks assigned to them. These marks can be
-used to note information such as if a folio needs folio_put() calling upon it.
-There are three marks available to be set for each folio.
-
-The marks can be set by::
-
- void folioq_mark(struct folio_queue *folioq, unsigned int slot);
- void folioq_mark2(struct folio_queue *folioq, unsigned int slot);
-
-Cleared by::
-
- void folioq_unmark(struct folio_queue *folioq, unsigned int slot);
- void folioq_unmark2(struct folio_queue *folioq, unsigned int slot);
-
-And the marks can be queried by::
-
- bool folioq_is_marked(const struct folio_queue *folioq, unsigned int slot);
- bool folioq_is_marked2(const struct folio_queue *folioq, unsigned int slot);
-
-The marks can be used for any purpose and are not interpreted by this API.
-
-
-Folio queue iteration
-=====================
-
-A list of segments may be iterated over using the I/O iterator facility using
-an ``iov_iter`` iterator of ``ITER_FOLIOQ`` type. The iterator may be
-initialised with::
-
- void iov_iter_folio_queue(struct iov_iter *i, unsigned int direction,
- const struct folio_queue *folioq,
- unsigned int first_slot, unsigned int offset,
- size_t count);
-
-This may be told to start at a particular segment, slot and offset within a
-queue. The iov iterator functions will follow the next pointers when advancing
-and prev pointers when reverting when needed.
-
-
-Lockless simultaneous production/consumption issues
-===================================================
-
-If properly managed, the list can be extended by the producer at the head end
-and shortened by the consumer at the tail end simultaneously without the need
-to take locks. The ITER_FOLIOQ iterator inserts appropriate barriers to aid
-with this.
-
-Care must be taken when simultaneously producing and consuming a list. If the
-last segment is reached and the folios it refers to are entirely consumed by
-the IOV iterators, an iov_iter struct will be left pointing to the last segment
-with a slot number equal to the capacity of that segment. The iterator will
-try to continue on from this if there's another segment available when it is
-used again, but care must be taken lest the segment got removed and freed by
-the consumer before the iterator was advanced.
-
-It is recommended that the queue always contain at least one segment, even if
-that segment has never been filled or is entirely spent. This prevents the
-head and tail pointers from collapsing.
-
-
-API Function Reference
-======================
-
-.. kernel-doc:: include/linux/folio_queue.h
diff --git a/Documentation/core-api/index.rst b/Documentation/core-api/index.rst
index 92f91c6a0d79d6..bfc2f1afc28514 100644
--- a/Documentation/core-api/index.rst
+++ b/Documentation/core-api/index.rst
@@ -39,7 +39,7 @@ Library functionality that is used throughout the kernel.
kref
cleanup
assoc_array
- folio_queue
+ bvecq
xarray
maple_tree
idr
diff --git a/Documentation/filesystems/netfs_library.rst b/Documentation/filesystems/netfs_library.rst
index 215a6621f3d346..1fe110ceb3f18e 100644
--- a/Documentation/filesystems/netfs_library.rst
+++ b/Documentation/filesystems/netfs_library.rst
@@ -437,22 +437,43 @@ Monolithic Files API
There is also a special API set for files for which the content must be read in
a single RPC (and not written back) and is maintained as a monolithic blob
-(e.g. an AFS directory), though it can be stored and updated in the local cache::
+(e.g. an AFS directory), though it can be stored and updated in the local
+cache.
+
+To start with, there's a function to synchronously read the contents of such a
+file into a buffer in a single operation::
+
+ ssize_t netfs_read_single(struct inode *inode,
+ struct file *file,
+ struct iov_iter *iter);
+
+If such a file is modified locally, it can be marked dirty with::
- ssize_t netfs_read_single(struct inode *inode, struct file *file, struct iov_iter *iter);
void netfs_single_mark_inode_dirty(struct inode *inode);
+
+which will schedule it for writeback later. When the writeback eventually
+happens, the filesystem should call::
+
int netfs_writeback_single(struct address_space *mapping,
struct writeback_control *wbc,
- struct iov_iter *iter);
+ struct iov_iter *iter,
+ size_t len);
+
+to write the data to the cache from its writepages method.
-The first function reads from a file into the given buffer, reading from the
-cache in preference if the data is cached there; the second function allows the
-inode to be marked dirty, causing a later writeback; and the third function can
-be called from the writeback code to write the data to the cache, if there is
-one.
+In both the read and writeback functions, the buffer needs to be rounded up to
+a multiple of the cache DIO size, with ``iter->count`` indicating the size of
+the buffer. For the write function, ``len`` should indicate the size of the
+content which may be less than the buffer size. The gap between ``len`` and the
+buffer size should be cleared by the filesystem as this will be used as padding
+if the write size has to be increased (e.g. for the cache DIO).
+
+Note that, for the moment, rounding the buffer up to a multiple of PAGE_SIZE
+instead of the cache DIO size should suffice. DIO size > PAGE_SIZE is not
+currently supported.
The inode should be marked ``NETFS_ICTX_SINGLE_NO_UPLOAD`` if this API is to be
-used. The writeback function requires the buffer to be of ITER_FOLIOQ type.
+used.
Clearing Stale Post-EOF Pagecache
---------------------------------
@@ -859,12 +880,12 @@ The methods defined in the table are:
paths to ask the filesystem to update its idea of the file size. If not
given, netfslib will set i_size and i_blocks and update the local cache
cookie.
-
+
* ``post_modify()``
[Optional] This is called after netfslib writes to the pagecache or when it
allows an mmap'd page to be marked as writable.
-
+
* ``begin_writeback()``
[Optional] Netfslib calls this when processing a writeback request if it
@@ -872,7 +893,7 @@ The methods defined in the table are:
indicating it must be written to the server. This allows the filesystem to
only set up writeback resources when it knows it's going to have to perform
a write.
-
+
* ``prepare_write()``
[Optional] This is called to allow the filesystem to limit the size of a
@@ -911,7 +932,7 @@ The methods defined in the table are:
allows the filesystem to examine the state of the request, the subrequests
in the indicated stream and of its own data and make adjustments or
renegotiate resources.
-
+
* ``invalidate_cache()``
[Optional] This is called by netfslib to invalidate data stored in the local
diff --git a/MAINTAINERS b/MAINTAINERS
index 93abbb315065de..bdda4ad58ab4c2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10382,13 +10382,16 @@ M: Paulo Alcantara <pc@manguebit.org>
L: netfs@lists.linux.dev
L: linux-fsdevel@vger.kernel.org
S: Supported
+F: Documentation/core-api/bvecq.rst
F: Documentation/filesystems/caching/
F: Documentation/filesystems/netfs_library.rst
F: fs/netfs/
+F: include/linux/bvecq.h
F: include/linux/fscache*.h
F: include/linux/netfs.h
F: include/trace/events/fscache.h
F: include/trace/events/netfs.h
+F: lib/tests/kunit_bvecq.c
FILESYSTEMS [STACKABLE]
M: Miklos Szeredi <miklos@szeredi.hu>
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index 75f8f70cfeff02..75a1951bddd054 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -140,9 +140,9 @@ static void afs_dir_dump(struct afs_vnode *dvnode)
pr_warn("DIR %llx:%llx is=%llx\n",
dvnode->fid.vid, dvnode->fid.vnode, i_size);
- iov_iter_folio_queue(&iter, ITER_SOURCE, dvnode->directory, 0, 0, i_size);
- iterate_folioq(&iter, iov_iter_count(&iter), NULL, NULL,
- afs_dir_dump_step);
+ iov_iter_bvec_queue(&iter, ITER_SOURCE, dvnode->directory, 0, 0, i_size);
+ iterate_bvecq(&iter, iov_iter_count(&iter), NULL, NULL,
+ afs_dir_dump_step);
}
/*
@@ -203,9 +203,9 @@ static int afs_dir_check(struct afs_vnode *dvnode)
if (unlikely(!i_size))
return 0;
- iov_iter_folio_queue(&iter, ITER_SOURCE, dvnode->directory, 0, 0, i_size);
- checked = iterate_folioq(&iter, iov_iter_count(&iter), dvnode, NULL,
- afs_dir_check_step);
+ iov_iter_bvec_queue(&iter, ITER_SOURCE, dvnode->directory, 0, 0, i_size);
+ checked = iterate_bvecq(&iter, iov_iter_count(&iter), dvnode, NULL,
+ afs_dir_check_step);
if (checked != i_size) {
afs_dir_dump(dvnode);
return -EIO;
@@ -250,15 +250,16 @@ static ssize_t afs_do_read_single(struct afs_vnode *dvnode, struct file *file)
if (dvnode->directory_size < i_size) {
size_t cur_size = dvnode->directory_size;
- ret = netfs_alloc_folioq_buffer(NULL,
- &dvnode->directory, &cur_size, i_size,
- mapping_gfp_mask(dvnode->netfs.inode.i_mapping));
+ ret = bvecq_expand_buffer(&dvnode->directory, &cur_size,
+ round_up(i_size, PAGE_SIZE),
+ mapping_gfp_mask(dvnode->netfs.inode.i_mapping) |
+ __GFP_ZERO);
dvnode->directory_size = cur_size;
if (ret < 0)
return ret;
}
- iov_iter_folio_queue(&iter, ITER_DEST, dvnode->directory, 0, 0, dvnode->directory_size);
+ iov_iter_bvec_queue(&iter, ITER_DEST, dvnode->directory, 0, 0, dvnode->directory_size);
/* AFS requires us to perform the read of a directory synchronously as
* a single unit to avoid issues with the directory contents being
@@ -278,6 +279,13 @@ static ssize_t afs_do_read_single(struct afs_vnode *dvnode, struct file *file)
if (ret2 < 0)
ret = ret2;
}
+
+ if (ret >= 0 && ret < dvnode->directory_size) {
+ iov_iter_bvec_queue(&iter, ITER_DEST, dvnode->directory,
+ 0, 0, dvnode->directory_size);
+ iov_iter_advance(&iter, ret);
+ iov_iter_zero(dvnode->directory_size - ret, &iter);
+ }
}
return ret;
@@ -294,8 +302,8 @@ static ssize_t afs_read_single(struct afs_vnode *dvnode, struct file *file)
}
/*
- * Read the directory into a folio_queue buffer in one go, scrubbing the
- * previous contents. We return -ESTALE if the caller needs to call us again.
+ * Read the directory into the buffer in one go, scrubbing the previous
+ * contents. We return -ESTALE if the caller needs to call us again.
*/
ssize_t afs_read_dir(struct afs_vnode *dvnode, struct file *file)
__acquires(&dvnode->validate_lock)
@@ -483,7 +491,7 @@ static size_t afs_dir_iterate_step(void *iter_base, size_t progress, size_t len,
}
/*
- * Iterate through the directory folios.
+ * Iterate through the directory content.
*/
static int afs_dir_iterate_contents(struct inode *dir, struct dir_context *dir_ctx)
{
@@ -498,11 +506,11 @@ static int afs_dir_iterate_contents(struct inode *dir, struct dir_context *dir_c
if (i_size <= 0 || dir_ctx->pos >= i_size)
return 0;
- iov_iter_folio_queue(&iter, ITER_SOURCE, dvnode->directory, 0, 0, i_size);
+ iov_iter_bvec_queue(&iter, ITER_SOURCE, dvnode->directory, 0, 0, i_size);
iov_iter_advance(&iter, round_down(dir_ctx->pos, AFS_DIR_BLOCK_SIZE));
- iterate_folioq(&iter, iov_iter_count(&iter), dvnode, &ctx,
- afs_dir_iterate_step);
+ iterate_bvecq(&iter, iov_iter_count(&iter), dvnode, &ctx,
+ afs_dir_iterate_step);
if (ctx.error == -ESTALE)
afs_invalidate_dir(dvnode, afs_dir_invalid_iter_stale);
@@ -2228,9 +2236,10 @@ static int afs_dir_writepages(struct address_space *mapping,
}
if (test_bit(AFS_VNODE_DIR_VALID, &dvnode->flags)) {
- iov_iter_folio_queue(&iter, ITER_SOURCE, dvnode->directory, 0, 0,
- i_size_read(&dvnode->netfs.inode));
- ret = netfs_writeback_single(mapping, wbc, &iter);
+ iov_iter_bvec_queue(&iter, ITER_SOURCE, dvnode->directory,
+ 0, 0, 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/dir_edit.c b/fs/afs/dir_edit.c
index c31303059444ad..870921f32fc89a 100644
--- a/fs/afs/dir_edit.c
+++ b/fs/afs/dir_edit.c
@@ -10,7 +10,6 @@
#include <linux/namei.h>
#include <linux/pagemap.h>
#include <linux/iversion.h>
-#include <linux/folio_queue.h>
#include "internal.h"
#include "xdr_fs.h"
@@ -110,9 +109,8 @@ static void afs_clear_contig_bits(union afs_xdr_dir_block *block,
*/
static union afs_xdr_dir_block *afs_dir_get_block(struct afs_dir_iter *iter, size_t block)
{
- struct folio_queue *fq;
struct afs_vnode *dvnode = iter->dvnode;
- struct folio *folio;
+ struct bvecq *bq;
size_t blpos = block * AFS_DIR_BLOCK_SIZE;
size_t blend = (block + 1) * AFS_DIR_BLOCK_SIZE, fpos = iter->fpos;
int ret;
@@ -120,41 +118,39 @@ static union afs_xdr_dir_block *afs_dir_get_block(struct afs_dir_iter *iter, siz
if (dvnode->directory_size < blend) {
size_t cur_size = dvnode->directory_size;
- ret = netfs_alloc_folioq_buffer(
- NULL, &dvnode->directory, &cur_size, blend,
- mapping_gfp_mask(dvnode->netfs.inode.i_mapping));
+ ret = bvecq_expand_buffer(&dvnode->directory, &cur_size, blend,
+ mapping_gfp_mask(dvnode->netfs.inode.i_mapping) |
+ __GFP_ZERO);
dvnode->directory_size = cur_size;
if (ret < 0)
goto fail;
}
- fq = iter->fq;
- if (!fq)
- fq = dvnode->directory;
+ bq = iter->bq;
+ if (!bq)
+ bq = dvnode->directory;
- /* Search the folio queue for the folio containing the block... */
- for (; fq; fq = fq->next) {
- for (int s = iter->fq_slot; s < folioq_count(fq); s++) {
- size_t fsize = folioq_folio_size(fq, s);
+ /* Search the contents for the region containing the block... */
+ for (; bq; bq = bq->next) {
+ for (int s = iter->bq_slot; s < bq->nr_slots; s++) {
+ struct bio_vec *bv = &bq->bv[s];
+ size_t bsize = bv->bv_len;
- if (blend <= fpos + fsize) {
+ if (blend <= fpos + bsize) {
/* ... and then return the mapped block. */
- folio = folioq_folio(fq, s);
- if (WARN_ON_ONCE(folio_pos(folio) != fpos))
- goto fail;
- iter->fq = fq;
- iter->fq_slot = s;
+ iter->bq = bq;
+ iter->bq_slot = s;
iter->fpos = fpos;
- return kmap_local_folio(folio, blpos - fpos);
+ return bvec_kmap_partial(bv, blpos - fpos);
}
- fpos += fsize;
+ fpos += bsize;
}
- iter->fq_slot = 0;
+ iter->bq_slot = 0;
}
fail:
- iter->fq = NULL;
- iter->fq_slot = 0;
+ iter->bq = NULL;
+ iter->bq_slot = 0;
afs_invalidate_dir(dvnode, afs_dir_invalid_edit_get_block);
return NULL;
}
diff --git a/fs/afs/dir_search.c b/fs/afs/dir_search.c
index 11ebdfffcb1d38..e1f91b3ac6e25e 100644
--- a/fs/afs/dir_search.c
+++ b/fs/afs/dir_search.c
@@ -66,12 +66,11 @@ bool afs_dir_init_iter(struct afs_dir_iter *iter, const struct qstr *name)
*/
union afs_xdr_dir_block *afs_dir_find_block(struct afs_dir_iter *iter, size_t block)
{
- struct folio_queue *fq = iter->fq;
struct afs_vnode *dvnode = iter->dvnode;
- struct folio *folio;
+ struct bvecq *bq = iter->bq;
size_t blpos = block * AFS_DIR_BLOCK_SIZE;
size_t blend = (block + 1) * AFS_DIR_BLOCK_SIZE, fpos = iter->fpos;
- int slot = iter->fq_slot;
+ int slot = iter->bq_slot;
_enter("%zx,%d", block, slot);
@@ -80,36 +79,34 @@ union afs_xdr_dir_block *afs_dir_find_block(struct afs_dir_iter *iter, size_t bl
if (dvnode->directory_size < blend)
goto fail;
- if (!fq || blpos < fpos) {
- fq = dvnode->directory;
+ if (!bq || blpos < fpos) {
+ bq = dvnode->directory;
slot = 0;
fpos = 0;
}
/* Search the folio queue for the folio containing the block... */
- for (; fq; fq = fq->next) {
- for (; slot < folioq_count(fq); slot++) {
- size_t fsize = folioq_folio_size(fq, slot);
+ for (; bq; bq = bq->next) {
+ for (; slot < bq->nr_slots; slot++) {
+ struct bio_vec *bv = &bq->bv[slot];
+ size_t bsize = bv->bv_len;
- if (blend <= fpos + fsize) {
+ if (blend <= fpos + bsize) {
/* ... and then return the mapped block. */
- folio = folioq_folio(fq, slot);
- if (WARN_ON_ONCE(folio_pos(folio) != fpos))
- goto fail;
- iter->fq = fq;
- iter->fq_slot = slot;
+ iter->bq = bq;
+ iter->bq_slot = slot;
iter->fpos = fpos;
- iter->block = kmap_local_folio(folio, blpos - fpos);
+ iter->block = bvec_kmap_partial(bv, blpos - fpos);
return iter->block;
}
- fpos += fsize;
+ fpos += bsize;
}
slot = 0;
}
fail:
- iter->fq = NULL;
- iter->fq_slot = 0;
+ iter->bq = NULL;
+ iter->bq_slot = 0;
afs_invalidate_dir(dvnode, afs_dir_invalid_edit_get_block);
return NULL;
}
diff --git a/fs/afs/inode.c b/fs/afs/inode.c
index 0733abff77a5b9..af95640da03fa7 100644
--- a/fs/afs/inode.c
+++ b/fs/afs/inode.c
@@ -683,7 +683,7 @@ void afs_evict_inode(struct inode *inode)
flush_delayed_work(&vnode->lock_work);
netfs_wait_for_outstanding_io(inode);
truncate_inode_pages_final(&inode->i_data);
- netfs_free_folioq_buffer(vnode->directory);
+ bvecq_put(vnode->directory);
if (vnode->symlink)
afs_evict_symlink(vnode);
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index 7cea5ba0d20d7d..2a8b029b4d69fb 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -712,7 +712,7 @@ struct afs_vnode {
#define AFS_VNODE_MODIFYING 10 /* Set if we're performing a modification op */
#define AFS_VNODE_DIR_READ 11 /* Set if we've read a dir's contents */
- struct folio_queue *directory; /* Directory contents */
+ struct bvecq *directory; /* Directory contents */
struct afs_symlink __rcu *symlink; /* Symlink content */
struct list_head wb_keys; /* List of keys available for writeback */
struct list_head pending_locks; /* locks waiting to be granted */
@@ -993,9 +993,9 @@ static inline void afs_invalidate_cache(struct afs_vnode *vnode, unsigned int fl
struct afs_dir_iter {
struct afs_vnode *dvnode;
union afs_xdr_dir_block *block;
- struct folio_queue *fq;
+ struct bvecq *bq;
unsigned int fpos;
- int fq_slot;
+ int bq_slot;
unsigned int loop_check;
u8 nr_slots;
u8 bucket;
diff --git a/fs/afs/symlink.c b/fs/afs/symlink.c
index 6b8c122877ca2d..f437c3108c6cdb 100644
--- a/fs/afs/symlink.c
+++ b/fs/afs/symlink.c
@@ -56,7 +56,6 @@ void afs_evict_symlink(struct afs_vnode *vnode)
void afs_init_new_symlink(struct afs_vnode *vnode, struct afs_operation *op)
{
struct afs_symlink *symlink = op->create.symlink;
- size_t dsize = 0;
size_t size = strlen(symlink->content) + 1;
char *p;
@@ -66,12 +65,15 @@ void afs_init_new_symlink(struct afs_vnode *vnode, struct afs_operation *op)
if (!fscache_cookie_enabled(netfs_i_cookie(&vnode->netfs)))
return;
- if (netfs_alloc_folioq_buffer(NULL, &vnode->directory, &dsize, size,
- mapping_gfp_mask(vnode->netfs.inode.i_mapping)) < 0)
+ vnode->directory =
+ bvecq_alloc_buffer(PAGE_SIZE,
+ mapping_gfp_mask(vnode->netfs.inode.i_mapping),
+ false);
+ if (!vnode->directory)
return;
- vnode->directory_size = dsize;
- p = kmap_local_folio(folioq_folio(vnode->directory, 0), 0);
+ vnode->directory_size = PAGE_SIZE;
+ p = bvec_kmap_partial(&vnode->directory->bv[0], 0);
memcpy(p, symlink->content, size);
kunmap_local(p);
netfs_single_mark_inode_dirty(&vnode->netfs.inode);
@@ -94,17 +96,14 @@ static ssize_t afs_do_read_symlink(struct afs_vnode *vnode)
}
if (!vnode->directory) {
- size_t cur_size = 0;
-
- ret = netfs_alloc_folioq_buffer(NULL,
- &vnode->directory, &cur_size, PAGE_SIZE,
- mapping_gfp_mask(vnode->netfs.inode.i_mapping));
- vnode->directory_size = PAGE_SIZE - 1;
- if (ret < 0)
- return ret;
+ vnode->directory = bvecq_alloc_buffer(
+ PAGE_SIZE, mapping_gfp_mask(vnode->netfs.inode.i_mapping), false);
+ if (!vnode->directory)
+ return -ENOMEM;
+ vnode->directory_size = PAGE_SIZE;
}
- iov_iter_folio_queue(&iter, ITER_DEST, vnode->directory, 0, 0, PAGE_SIZE);
+ iov_iter_bvec_queue(&iter, ITER_DEST, vnode->directory, 0, 0, PAGE_SIZE);
/* AFS requires us to perform the read of a symlink as a single unit to
* avoid issues with the content being changed between reads.
@@ -116,7 +115,6 @@ static ssize_t afs_do_read_symlink(struct afs_vnode *vnode)
trace_afs_file_error(vnode, -EFBIG, afs_file_error_dir_big);
return -EFBIG;
}
- vnode->directory_size = i_size;
/* Copy the symlink. */
symlink = kmalloc_flex(struct afs_symlink, content, i_size + 1);
@@ -126,7 +124,7 @@ static ssize_t afs_do_read_symlink(struct afs_vnode *vnode)
refcount_set(&symlink->ref, 1);
symlink->content[i_size] = 0;
- const char *s = kmap_local_folio(folioq_folio(vnode->directory, 0), 0);
+ const char *s = bvec_kmap_partial(&vnode->directory->bv[0], 0);
memcpy(symlink->content, s, i_size);
kunmap_local(s);
@@ -135,7 +133,7 @@ static ssize_t afs_do_read_symlink(struct afs_vnode *vnode)
}
if (!fscache_cookie_enabled(netfs_i_cookie(&vnode->netfs))) {
- netfs_free_folioq_buffer(vnode->directory);
+ bvecq_put(vnode->directory);
vnode->directory = NULL;
vnode->directory_size = 0;
}
@@ -196,7 +194,7 @@ const char *afs_get_link(struct dentry *dentry, struct inode *inode,
}
downgrade_write(&vnode->validate_lock);
-
+
good:
symlink = rcu_dereference_protected(vnode->symlink,
lockdep_is_held(&vnode->validate_lock));
@@ -229,6 +227,10 @@ int afs_readlink(struct dentry *dentry, char __user *buffer, int buflen)
/*
* Write the symlink contents to the cache as a single blob. We then throw
* away the page we used to receive it.
+ *
+ * Note that the buffer tail is cleared under a shared lock on ->validate_lock
+ * - though hopefully there won't be racing writers since the only
+ * 'modification' is to be either read from the server or locally created.
*/
int afs_symlink_writepages(struct address_space *mapping,
struct writeback_control *wbc)
@@ -248,14 +250,23 @@ int afs_symlink_writepages(struct address_space *mapping,
if (vnode->directory &&
atomic64_read(&vnode->cb_expires_at) != AFS_NO_CB_PROMISE) {
- iov_iter_folio_queue(&iter, ITER_SOURCE, vnode->directory, 0, 0,
- i_size_read(&vnode->netfs.inode));
- ret = netfs_writeback_single(mapping, wbc, &iter);
+ size_t i_size = i_size_read(&vnode->netfs.inode);
+
+ if (i_size < vnode->directory_size) {
+ iov_iter_bvec_queue(&iter, ITER_DEST, vnode->directory, 0, 0,
+ vnode->directory_size);
+ iov_iter_advance(&iter, i_size);
+ iov_iter_zero(vnode->directory_size - i_size, &iter);
+ }
+
+ iov_iter_bvec_queue(&iter, ITER_SOURCE, vnode->directory, 0, 0,
+ vnode->directory_size);
+ ret = netfs_writeback_single(mapping, wbc, &iter, i_size);
}
if (ret == 0) {
netfs_wb_begin(&vnode->netfs, false);
- netfs_free_folioq_buffer(vnode->directory);
+ bvecq_put(vnode->directory);
vnode->directory = NULL;
vnode->directory_size = 0;
netfs_wb_end(&vnode->netfs);
diff --git a/fs/netfs/Makefile b/fs/netfs/Makefile
index 54834cde7e5686..b1ea4439c1bb4a 100644
--- a/fs/netfs/Makefile
+++ b/fs/netfs/Makefile
@@ -3,6 +3,7 @@
netfs-y := \
buffered_read.o \
buffered_write.o \
+ bvecq.o \
direct_read.o \
direct_write.o \
iterator.o \
diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c
index 69e68ef0652a72..61b44af6774b75 100644
--- a/fs/netfs/buffered_read.c
+++ b/fs/netfs/buffered_read.c
@@ -215,7 +215,7 @@ 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 folio_queue **fq,
+ struct bvecq **bq,
unsigned int *offset,
int *slot,
size_t len,
@@ -225,21 +225,21 @@ static void netfs_mark_copy_to_cache(struct netfs_io_request *rreq,
struct folio *folio;
size_t fsize, overlap;
- if (!*fq)
+ if (!*bq)
break;
- if (*slot >= folioq_count(*fq)) {
- *fq = (*fq)->next;
+ if (!bvecq_acquire_slot(*bq, *slot)) {
+ *bq = bvecq_next(*bq);
*slot = 0;
*offset = 0;
continue;
}
/* Determine how much the subreq overlaps the folio, if at all. */
- fsize = folioq_folio_size(*fq, *slot);
+ fsize = (*bq)->bv[*slot].bv_len;
overlap = min(len, fsize - *offset);
if (overlap > 0 && copy) {
- folio = folioq_folio(*fq, *slot);
+ folio = bvec_folio(&(*bq)->bv[*slot]);
if (netfs_using_pgpriv2(rreq)) {
if (!folio_test_private_2(folio))
folio_start_private_2(folio);
@@ -275,7 +275,7 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq)
.cached_to[1] = ULLONG_MAX,
};
struct fscache_occupancy *occ = &_occ;
- struct folio_queue *fq = rreq->buffer.tail;
+ struct bvecq *bq = rreq->buffer.tail;
unsigned int offset = 0;
ssize_t size = rreq->len;
uoff_t start = rreq->start;
@@ -408,10 +408,10 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq)
if (size <= 0)
netfs_all_subreqs_queued(rreq);
- if (fq) {
+ if (bq) {
/* 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, &fq, &slot, &offset, slice, copy);
+ netfs_mark_copy_to_cache(rreq, &bq, &slot, &offset, slice, copy);
}
trace_netfs_sreq(subreq, netfs_sreq_trace_submit);
@@ -479,8 +479,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->debug_id, rreq->gfp);
+ added = rolling_buffer_bulk_load_from_ra(&rreq->buffer, ractl, rreq->gfp);
if (added < 0) {
ret = added;
goto cleanup_free;
@@ -503,15 +502,14 @@ EXPORT_SYMBOL(netfs_readahead);
/*
* Create a rolling buffer with a single occupying folio.
*/
-static int netfs_create_singular_buffer(struct netfs_io_request *rreq, struct folio *folio,
- unsigned int rollbuf_flags)
+static int netfs_create_singular_buffer(struct netfs_io_request *rreq, struct folio *folio)
{
ssize_t added;
- if (rolling_buffer_init(&rreq->buffer, rreq->debug_id, ITER_DEST, rreq->gfp) < 0)
+ if (rolling_buffer_init(&rreq->buffer, ITER_DEST, rreq->gfp, false) < 0)
return -ENOMEM;
- added = rolling_buffer_append(&rreq->buffer, folio, rollbuf_flags, rreq->gfp);
+ added = rolling_buffer_append(&rreq->buffer, folio, rreq->gfp);
if (added < 0)
return added;
rreq->submitted = rreq->start + added;
@@ -668,7 +666,7 @@ int netfs_read_folio(struct file *file, struct folio *folio)
trace_netfs_read(rreq, rreq->start, rreq->len, netfs_read_trace_readpage);
/* Set up the output buffer */
- ret = netfs_create_singular_buffer(rreq, folio, 0);
+ ret = netfs_create_singular_buffer(rreq, folio);
if (ret < 0)
goto discard;
@@ -825,7 +823,7 @@ int netfs_write_begin(struct netfs_inode *ctx,
trace_netfs_read(rreq, pos, len, netfs_read_trace_write_begin);
/* Set up the output buffer */
- ret = netfs_create_singular_buffer(rreq, folio, 0);
+ ret = netfs_create_singular_buffer(rreq, folio);
if (ret < 0)
goto error_put;
@@ -890,7 +888,7 @@ int netfs_prefetch_for_write(struct file *file, struct folio *folio,
trace_netfs_read(rreq, start, flen, netfs_read_trace_prefetch_for_write);
/* Set up the output buffer */
- ret = netfs_create_singular_buffer(rreq, folio, NETFS_ROLLBUF_PAGECACHE_MARK);
+ ret = netfs_create_singular_buffer(rreq, folio);
if (ret < 0)
goto error_put;
diff --git a/fs/netfs/bvecq.c b/fs/netfs/bvecq.c
new file mode 100644
index 00000000000000..91264337805cd6
--- /dev/null
+++ b/fs/netfs/bvecq.c
@@ -0,0 +1,357 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Buffering helpers for bvec queues
+ *
+ * Copyright (C) 2026 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * See also Documentation/core-api/bvecq.rst
+ */
+
+#include <linux/bvecq.h>
+#include "internal.h"
+
+void bvecq_dump(const struct bvecq *bq)
+{
+ int b = 0;
+
+ for (; bq; bq = bvecq_next(bq), b++) {
+ pr_notice("BQ[%u] %u/%u\n", b, bq->nr_slots, bq->max_slots);
+ for (int s = 0; s < bq->nr_slots; s++) {
+ const struct bio_vec *bv = &bq->bv[s];
+
+ if (!IS_ERR_OR_NULL(bv->bv_page))
+ pr_notice("BQ[%u:%02u] %10lx %04x %04x %u\n",
+ b, s,
+ page_to_pfn(bv->bv_page),
+ bv->bv_offset, bv->bv_len,
+ page_count(bv->bv_page));
+ else
+ pr_notice("BQ[%u:%02u] - %04x %04x\n",
+ b, s, bv->bv_offset, bv->bv_len);
+ }
+ }
+}
+EXPORT_SYMBOL(bvecq_dump);
+
+/**
+ * bvecq_alloc_one - Allocate a single bvecq node with unpopulated slots
+ * @nr_slots: Number of slots to allocate
+ * @gfp: The allocation constraints.
+ * @for_writeback: True if allocating for writeback
+ *
+ * Allocate a single bvecq node and initialise the header. The allocation is
+ * rounded up to the size of the smallest slab granule that will accommodate it
+ * and all the remaining space is set as an inline slot array with max_slots
+ * set to the number of slots. The slot array is not initialised.
+ *
+ * Note that the number of slots allocated is limited to USHRT_MAX. If more
+ * than this are desired, a number of bvecqs should be chained.
+ *
+ * If @for_writeback is set, then the emergency mempool may be used for
+ * allocation. If it does allocate from that pool, the maximum number of slots
+ * available will be BVECQ_POOL_SLOTS which may be less than requested. Also,
+ * if @for_writeback is set, the function will not fail - though it may have to
+ * wait.
+ *
+ * Return: The node pointer or NULL on allocation failure.
+ */
+struct bvecq *bvecq_alloc_one(size_t nr_slots, gfp_t gfp, bool for_writeback)
+{
+ struct bvecq *bq;
+ size_t size;
+ bool from_pool = false;
+
+ /* Don't overrun ->max_slots or ->nr_slots. */
+ if (nr_slots > BVECQ_MAX_INLINE_SLOTS)
+ nr_slots = BVECQ_MAX_INLINE_SLOTS;
+
+ size = kmalloc_size_roundup(struct_size(bq, __bv, nr_slots));
+ gfp &= ~(GFP_ZONEMASK | __GFP_THISNODE);
+
+ if (for_writeback) {
+ if (size != BVECQ_POOL_SIZE) {
+ gfp_t gfp_temp = gfp;
+
+ gfp_temp |= __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN;
+ gfp_temp &= ~(__GFP_DIRECT_RECLAIM | __GFP_IO);
+ bq = kmalloc(size, gfp_temp);
+ if (bq)
+ goto success;
+ }
+
+ bq = mempool_alloc(&netfs_bvecq_pool, gfp);
+ if (!bq)
+ return bq;
+ from_pool = true;
+ size = BVECQ_POOL_SIZE;
+ } else {
+ bq = kmalloc(size, gfp);
+ if (!bq)
+ return bq;
+ }
+
+success:
+ *bq = (struct bvecq) {
+ .ref = REFCOUNT_INIT(1),
+ .bv = bq->__bv,
+ .inline_bv = true,
+ .max_slots = min((size - sizeof(*bq)) / sizeof(bq->__bv[0]),
+ BVECQ_MAX_INLINE_SLOTS),
+ .from_pool = from_pool,
+ };
+ netfs_stat(&netfs_n_bvecq);
+ return bq;
+}
+EXPORT_SYMBOL(bvecq_alloc_one);
+
+/**
+ * bvecq_alloc_chain - Allocate an unpopulated bvecq chain
+ * @nr_slots: Number of slots to allocate
+ * @gfp: The allocation constraints.
+ * @for_writeback: True if allocating for writeback
+ *
+ * Allocate a chain of bvecq nodes providing at least the requested cumulative
+ * number of slots. Each node is a maximum of 4KiB in size.
+ *
+ * Return: The first node pointer or NULL on allocation failure.
+ */
+struct bvecq *bvecq_alloc_chain(size_t nr_slots, gfp_t gfp, bool for_writeback)
+{
+ struct bvecq *head = NULL, *tail = NULL;
+
+ _enter("%zu", nr_slots);
+
+ for (;;) {
+ struct bvecq *bq;
+
+ bq = bvecq_alloc_one(min(nr_slots, BVECQ_4KB_SLOTS), gfp, for_writeback);
+ if (!bq)
+ goto oom;
+
+ if (tail)
+ bvecq_append(tail, bq);
+ else
+ head = bq;
+ tail = bq;
+ if (tail->max_slots >= nr_slots)
+ break;
+ nr_slots -= tail->max_slots;
+ }
+
+ return head;
+oom:
+ bvecq_put(head);
+ return NULL;
+}
+EXPORT_SYMBOL(bvecq_alloc_chain);
+
+/**
+ * bvecq_alloc_buffer2 - Allocate a bvecq chain and populate with buffers
+ * @size: Target size of the buffer (can be 0 for an empty buffer)
+ * @pre_slots: Number of preamble slots to set aside
+ * @gfp: The allocation constraints.
+ * @for_writeback: True if allocating for writeback
+ *
+ * Allocate a chain of bvecq nodes and populate the slots with sufficient pages
+ * to provide at least the requested amount of space, leaving the first
+ * @pre_slots slots unset. The pre-slots must all fit into the first bvecq.
+ * Note that any memory segments set in the pre_slots will be freed as
+ * specified by BVECQ_MEM_ALLOCED.
+ *
+ * The caller should assume that the pages allocated may be compound pages
+ * larger than PAGE_SIZE and thus occupy fewer slots. The pages have their
+ * refcounts set to 1 and can be passed to MSG_SPLICE_PAGES.
+ *
+ * Return: The first node pointer or NULL on allocation failure.
+ */
+struct bvecq *bvecq_alloc_buffer2(size_t size, unsigned int pre_slots, gfp_t gfp,
+ bool for_writeback)
+{
+ struct bvecq *head = NULL, *p = NULL;
+ size_t nr_per_bq = BVECQ_POOL_SLOTS;
+ size_t count = pre_slots + DIV_ROUND_UP(size, PAGE_SIZE);
+
+ _enter("%zx,%zx,%u", size, count, pre_slots);
+
+ if (WARN_ON_ONCE(pre_slots > nr_per_bq))
+ return NULL;
+
+ head = bvecq_alloc_chain(count, gfp, for_writeback);
+ if (!head)
+ return NULL;
+
+ p = head;
+ do {
+ struct page **pages;
+ size_t unused, want, got, slot;
+
+ if (!count)
+ break;
+ if (WARN_ON_ONCE(!p))
+ goto oom;
+
+ if (p->nr_slots == 0) {
+ /* Need to clear pre slots and pages[], so just clear all. */
+ memset(p->bv, 0, p->max_slots * sizeof(p->bv[0]));
+ p->mem_type = BVECQ_MEM_ALLOCED;
+ p->nr_slots = pre_slots;
+ count -= pre_slots;
+ pre_slots = 0;
+ if (!count)
+ break;
+ }
+
+ if (p->nr_slots >= p->max_slots) {
+ p = p->next;
+ continue;
+ }
+ unused = p->max_slots - p->nr_slots;
+
+ /* We can put pages[] at the tail of bv[] as the elements are
+ * smaller and we won't overrun if the slots are filled in
+ * ascending order.
+ */
+ pages = (struct page **)&p->bv[p->max_slots];
+ pages -= unused;
+
+ want = min(count, unused);
+ got = alloc_pages_bulk(gfp, want, pages);
+ if (!got)
+ goto oom;
+
+ slot = p->nr_slots;
+ for (int i = 0; i < got; i++)
+ bvec_set_page(&p->bv[slot++], pages[i], PAGE_SIZE, 0);
+
+ bvecq_filled_to(p, slot);
+ count -= got;
+ } while (count > 0);
+
+ return head;
+oom:
+ bvecq_put(head);
+ return NULL;
+}
+EXPORT_SYMBOL(bvecq_alloc_buffer2);
+
+/*
+ * Free the page pointed to by a slot as necessary.
+ */
+static void bvecq_free_slot(struct bvecq *bq, unsigned int slot)
+{
+ struct page *page = bq->bv[slot].bv_page;
+
+ if (!page)
+ return;
+
+ switch (bq->mem_type) {
+ case BVECQ_MEM_EXTERNAL:
+ break;
+ case BVECQ_MEM_PAGECACHE:
+ put_page(page);
+ break;
+ case BVECQ_MEM_GUP:
+ unpin_user_page(page);
+ break;
+ case BVECQ_MEM_ALLOCED:
+ __free_pages(page, compound_order(page));
+ break;
+ default:
+ WARN_ON_ONCE(1);
+ break;
+ }
+}
+
+/**
+ * bvecq_put - Put a ref on a bvec queue
+ * @bq: The start of the folio queue to free
+ *
+ * Put the ref(s) on the nodes in a bvec queue, freeing up the node and the
+ * page fragments it points to as the refcounts become zero.
+ */
+void bvecq_put(struct bvecq *bq)
+{
+ struct bvecq *next;
+
+ for (; bq; bq = next) {
+ if (!refcount_dec_and_test(&bq->ref))
+ break;
+ for (int slot = 0; slot < bq->nr_slots; slot++)
+ bvecq_free_slot(bq, slot);
+ next = bq->next;
+ netfs_stat_d(&netfs_n_bvecq);
+ if (bq->from_pool)
+ mempool_free(bq, &netfs_bvecq_pool);
+ else
+ kfree(bq);
+ }
+}
+EXPORT_SYMBOL(bvecq_put);
+
+/**
+ * bvecq_expand_buffer - Allocate buffer space into a bvec queue
+ * @_buffer: Pointer to the bvecq chain to expand (may point to a NULL; updated).
+ * @_cur_size: Current size of the buffer (updated).
+ * @size: Target size of the buffer.
+ * @gfp: The allocation constraints.
+ *
+ * Append extra pages to a buffer to increase its capacity to the @size
+ * specified. If the current tail has space, but is not of the
+ * BVECQ_MEM_ALLOCED memory type, a separate bvecq will be allocated to hold
+ * the new memory.
+ *
+ * Return: 0 on success or -ENOMEM on failure. Note that in the case of
+ * failure, the buffer may have been partially expanded. In any event,
+ * *@_cur_size will be updated to the new buffer size.
+ */
+int bvecq_expand_buffer(struct bvecq **_buffer, size_t *_cur_size, size_t size, gfp_t gfp)
+{
+ struct bvecq *tail = *_buffer;
+
+ size = round_up(size, PAGE_SIZE);
+ if (tail)
+ while (tail->next)
+ tail = tail->next;
+
+ while (*_cur_size < size) {
+ struct page *page;
+ size_t need = size - *_cur_size;
+ gfp_t gfp_add;
+ int order = 0;
+
+ if (!tail || bvecq_is_full(tail) || tail->mem_type != BVECQ_MEM_ALLOCED) {
+ struct bvecq *p;
+
+ p = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, false);
+ if (!p)
+ return -ENOMEM;
+ if (tail)
+ bvecq_append(tail, p);
+ else
+ *_buffer = p;
+ tail = p;
+ p->mem_type = BVECQ_MEM_ALLOCED;
+ }
+
+ if (need > PAGE_SIZE)
+ order = umin(ilog2(need) - PAGE_SHIFT, MAX_PAGECACHE_ORDER);
+
+ gfp_add = 0;
+ if (order > 0)
+ gfp_add |= __GFP_NORETRY | __GFP_NOWARN;
+ page = alloc_pages(gfp | __GFP_COMP | gfp_add, order);
+ if (!page && order > 0) {
+ page = alloc_pages(gfp | __GFP_COMP, 0);
+ order = 0;
+ }
+ if (!page)
+ return -ENOMEM;
+
+ bvec_set_page(&tail->bv[tail->nr_slots], page, PAGE_SIZE << order, 0);
+ *_cur_size += PAGE_SIZE << order;
+ bvecq_filled_to(tail, tail->nr_slots + 1);
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL(bvecq_expand_buffer);
diff --git a/fs/netfs/internal.h b/fs/netfs/internal.h
index 6b583152132f0b..33d6cc23f54ad6 100644
--- a/fs/netfs/internal.h
+++ b/fs/netfs/internal.h
@@ -7,10 +7,10 @@
#include <linux/slab.h>
#include <linux/seq_file.h>
-#include <linux/folio_queue.h>
#include <linux/netfs.h>
#include <linux/fscache.h>
#include <linux/fscache-cache.h>
+#include <linux/mempool.h>
#include <trace/events/netfs.h>
#include <trace/events/fscache.h>
@@ -45,7 +45,7 @@ extern struct list_head netfs_io_requests;
extern spinlock_t netfs_proc_lock;
extern mempool_t netfs_request_pool;
extern mempool_t netfs_subrequest_pool;
-extern mempool_t netfs_folioq_pool;
+extern mempool_t netfs_bvecq_pool;
#ifdef CONFIG_PROC_FS
static inline void netfs_proc_add_rreq(struct netfs_io_request *rreq)
@@ -70,8 +70,6 @@ static inline void netfs_proc_del_rreq(struct netfs_io_request *rreq) {}
/*
* misc.c
*/
-struct folio_queue *netfs_buffer_make_space(struct netfs_io_request *rreq,
- enum netfs_folioq_trace trace);
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);
@@ -204,7 +202,7 @@ extern atomic_t netfs_n_wh_retry_write_req;
extern atomic_t netfs_n_wh_retry_write_subreq;
extern atomic_t netfs_n_wb_lock_skip;
extern atomic_t netfs_n_wb_lock_wait;
-extern atomic_t netfs_n_folioq;
+extern atomic_t netfs_n_bvecq;
int netfs_stats_show(struct seq_file *m, void *v);
diff --git a/fs/netfs/iterator.c b/fs/netfs/iterator.c
index eb1efb17f53aaa..983d3e45c69801 100644
--- a/fs/netfs/iterator.c
+++ b/fs/netfs/iterator.c
@@ -245,33 +245,37 @@ static size_t netfs_limit_xarray(const struct iov_iter *iter, size_t start_offse
}
/*
- * Select the span of a folio queue 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.
+ * 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_folioq(const struct iov_iter *iter, size_t start_offset,
- size_t max_size, size_t max_segs)
+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 folio_queue *folioq = iter->folioq;
+ const struct bvecq *bq = iter->bvecq;
unsigned int nsegs = 0;
- unsigned int slot = iter->folioq_slot;
+ unsigned int slot = iter->bvecq_slot;
size_t span = 0, n = iter->count;
- if (WARN_ON(!iov_iter_is_folioq(iter)) ||
+ 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 (slot >= folioq_nr_slots(folioq)) {
- folioq = folioq->next;
- slot = 0;
- }
-
start_offset += iter->iov_offset;
do {
- size_t flen = folioq_folio_size(folioq, slot);
+ size_t flen;
+ if (!bvecq_acquire_slot(bq, slot)) {
+ bq = bvecq_next(bq);
+ if (!bq)
+ break;
+ slot = 0;
+ continue;
+ }
+
+ flen = bq->bv[slot].bv_len;
if (start_offset < flen) {
span += flen - start_offset;
nsegs++;
@@ -283,11 +287,7 @@ static size_t netfs_limit_folioq(const struct iov_iter *iter, size_t start_offse
break;
slot++;
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = folioq->next;
- slot = 0;
- }
- } while (folioq);
+ } while (bq);
return umin(span, max_size);
}
@@ -295,8 +295,8 @@ static size_t netfs_limit_folioq(const struct iov_iter *iter, size_t start_offse
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_folioq(iter))
- return netfs_limit_folioq(iter, start_offset, max_size, 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))
diff --git a/fs/netfs/main.c b/fs/netfs/main.c
index 609e22e8f76a06..b1a7521b7210bd 100644
--- a/fs/netfs/main.c
+++ b/fs/netfs/main.c
@@ -7,7 +7,6 @@
#include <linux/module.h>
#include <linux/export.h>
-#include <linux/mempool.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include "internal.h"
@@ -28,7 +27,7 @@ static struct kmem_cache *netfs_request_slab;
static struct kmem_cache *netfs_subrequest_slab;
mempool_t netfs_request_pool;
mempool_t netfs_subrequest_pool;
-mempool_t netfs_folioq_pool;
+mempool_t netfs_bvecq_pool;
#ifdef CONFIG_PROC_FS
LIST_HEAD(netfs_io_requests);
@@ -108,8 +107,8 @@ static int __init netfs_init(void)
{
int ret = -ENOMEM;
- if (mempool_init_kmalloc_pool(&netfs_folioq_pool, 100, sizeof(struct folio_queue)) < 0)
- goto error_folioq_pool;
+ if (mempool_init_kmalloc_pool(&netfs_bvecq_pool, 100, BVECQ_POOL_SIZE) < 0)
+ goto error_bvecq_pool;
netfs_request_slab = kmem_cache_create("netfs_request",
sizeof(struct netfs_io_request), 0,
@@ -163,8 +162,8 @@ static int __init netfs_init(void)
error_reqpool:
kmem_cache_destroy(netfs_request_slab);
error_req:
- mempool_exit(&netfs_folioq_pool);
-error_folioq_pool:
+ mempool_exit(&netfs_bvecq_pool);
+error_bvecq_pool:
return ret;
}
fs_initcall(netfs_init);
@@ -177,6 +176,6 @@ static void __exit netfs_exit(void)
kmem_cache_destroy(netfs_subrequest_slab);
mempool_exit(&netfs_request_pool);
kmem_cache_destroy(netfs_request_slab);
- mempool_exit(&netfs_folioq_pool);
+ mempool_exit(&netfs_bvecq_pool);
}
module_exit(netfs_exit);
diff --git a/fs/netfs/misc.c b/fs/netfs/misc.c
index 5465db834b9499..a0cc248a284d59 100644
--- a/fs/netfs/misc.c
+++ b/fs/netfs/misc.c
@@ -9,102 +9,6 @@
#include <linux/rmap.h>
#include "internal.h"
-/**
- * netfs_alloc_folioq_buffer - Allocate buffer space into a folio queue
- * @mapping: Address space to set on the folio (or NULL).
- * @_buffer: Pointer to the folio queue to add to (may point to a NULL; updated).
- * @_cur_size: Current size of the buffer (updated).
- * @size: Target size of the buffer.
- * @gfp: The allocation constraints.
- */
-int netfs_alloc_folioq_buffer(struct address_space *mapping,
- struct folio_queue **_buffer,
- size_t *_cur_size, ssize_t size, gfp_t gfp)
-{
- struct folio_queue *tail = *_buffer, *p;
-
- size = round_up(size, PAGE_SIZE);
- if (*_cur_size >= size)
- return 0;
-
- if (tail)
- while (tail->next)
- tail = tail->next;
-
- do {
- struct folio *folio;
- int order = 0, slot;
-
- if (!tail || folioq_full(tail)) {
- p = netfs_folioq_alloc(0, GFP_NOFS, netfs_trace_folioq_alloc_buffer);
- if (!p)
- return -ENOMEM;
- if (tail) {
- tail->next = p;
- p->prev = tail;
- } else {
- *_buffer = p;
- }
- tail = p;
- }
-
- if (size - *_cur_size > PAGE_SIZE)
- order = umin(ilog2(size - *_cur_size) - PAGE_SHIFT,
- MAX_PAGECACHE_ORDER);
-
- folio = folio_alloc(gfp, order);
- if (!folio && order > 0)
- folio = folio_alloc(gfp, 0);
- if (!folio)
- return -ENOMEM;
-
- folio->mapping = mapping;
- folio->index = *_cur_size / PAGE_SIZE;
- trace_netfs_folio(folio, netfs_folio_trace_alloc_buffer);
- slot = folioq_append_mark(tail, folio);
- *_cur_size += folioq_folio_size(tail, slot);
- } while (*_cur_size < size);
-
- return 0;
-}
-EXPORT_SYMBOL(netfs_alloc_folioq_buffer);
-
-/**
- * netfs_free_folioq_buffer - Free a folio queue.
- * @fq: The start of the folio queue to free
- *
- * Free up a chain of folio_queues and, if marked, the marked folios they point
- * to.
- */
-void netfs_free_folioq_buffer(struct folio_queue *fq)
-{
- struct folio_queue *next;
- struct folio_batch fbatch;
-
- folio_batch_init(&fbatch);
-
- for (; fq; fq = next) {
- for (int slot = 0; slot < folioq_count(fq); slot++) {
- struct folio *folio = folioq_folio(fq, slot);
-
- if (!folio ||
- !folioq_is_marked(fq, slot))
- continue;
-
- trace_netfs_folio(folio, netfs_folio_trace_put);
- if (folio_batch_add(&fbatch, folio))
- folio_batch_release(&fbatch);
- }
-
- netfs_stat_d(&netfs_n_folioq);
- next = fq->next;
- kfree(fq);
- }
-
- folio_batch_release(&fbatch);
-}
-EXPORT_SYMBOL(netfs_free_folioq_buffer);
-
/*
* 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
diff --git a/fs/netfs/objects.c b/fs/netfs/objects.c
index 4b8d20559b0e15..6d7839c0498d60 100644
--- a/fs/netfs/objects.c
+++ b/fs/netfs/objects.c
@@ -6,7 +6,6 @@
*/
#include <linux/slab.h>
-#include <linux/mempool.h>
#include "internal.h"
static void netfs_free_request(struct work_struct *work);
diff --git a/fs/netfs/read_collect.c b/fs/netfs/read_collect.c
index be0f9d2f7e10f5..75c8874ec45953 100644
--- a/fs/netfs/read_collect.c
+++ b/fs/netfs/read_collect.c
@@ -79,11 +79,11 @@ void netfs_cancel_copy_to_cache(struct netfs_io_request *rreq, struct folio *fol
* dirty and let writeback handle it.
*/
static void netfs_unlock_read_folio(struct netfs_io_request *rreq,
- struct folio_queue *folioq,
+ struct bvecq *bq,
int slot)
{
struct netfs_folio *finfo;
- struct folio *folio = folioq_folio(folioq, slot);
+ struct folio *folio = bvec_folio(&bq->bv[slot]);
if (unlikely(folio_pos(folio) < rreq->abandon_to)) {
trace_netfs_folio(folio, netfs_folio_trace_abandon);
@@ -114,7 +114,7 @@ static void netfs_unlock_read_folio(struct netfs_io_request *rreq,
trace_netfs_folio(folio, netfs_folio_trace_read_done);
}
- folioq_clear(folioq, slot);
+ bq->bv[slot].bv_page = NULL;
} else {
// TODO: Use of PG_private_2 is deprecated.
if (folio_test_private_2(folio))
@@ -130,7 +130,7 @@ static void netfs_unlock_read_folio(struct netfs_io_request *rreq,
folio_unlock(folio);
}
- folioq_clear(folioq, slot);
+ bq->bv[slot].bv_page = NULL;
}
/*
@@ -138,21 +138,22 @@ static void netfs_unlock_read_folio(struct netfs_io_request *rreq,
*/
void netfs_read_set_unlock_at(struct netfs_io_request *rreq)
{
- struct folio_queue *folioq = rreq->buffer.tail;
+ const struct bvecq *bq = rreq->buffer.tail;
unsigned int slot = rreq->buffer.first_tail_slot;
size_t cleaned_to = rreq->cleaned_to - rreq->start;
size_t progress_at = cleaned_to;
size_t minimum = 256 * 1024;
while (progress_at < rreq->len) {
- if (slot >= folioq_count(folioq)) {
- folioq = folioq->next;
- if (!folioq)
+ if (!bvecq_acquire_slot(bq, slot)) {
+ bq = bvecq_next(bq);
+ if (!bq)
break;
slot = 0;
+ continue;
}
- progress_at += folioq_folio_size(folioq, slot);
+ progress_at += bq->bv[slot].bv_len;
if (progress_at - cleaned_to >= minimum)
break;
slot++;
@@ -168,7 +169,7 @@ 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 folio_queue *folioq = rreq->buffer.tail;
+ struct bvecq *bq = rreq->buffer.tail;
unsigned int slot = rreq->buffer.first_tail_slot;
uoff_t collected_to = rreq->collected_to;
@@ -177,9 +178,9 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,
// TODO: Begin decryption
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = rolling_buffer_delete_spent(&rreq->buffer);
- if (!folioq) {
+ while (!bvecq_acquire_slot(bq, slot)) {
+ bq = rolling_buffer_delete_spent(&rreq->buffer);
+ if (!bq) {
WRITE_ONCE(rreq->progress_at, rreq->len);
return;
}
@@ -198,13 +199,13 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,
uoff_t fpos, fend;
size_t fsize;
- folio = folioq_folio(folioq, slot);
+ folio = bvec_folio(&bq->bv[slot]);
if (WARN_ONCE(!folio_test_locked(folio),
"R=%08x: folio %lx is not locked\n",
rreq->debug_id, folio->index))
trace_netfs_folio(folio, netfs_folio_trace_not_locked);
- fsize = folioq_folio_size(folioq, slot);
+ fsize = bq->bv[slot].bv_len;
fpos = folio_pos(folio);
fend = fpos + fsize;
@@ -214,29 +215,28 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,
if (collected_to < fend)
break;
- netfs_unlock_read_folio(rreq, folioq, slot);
+ netfs_unlock_read_folio(rreq, bq, slot);
WRITE_ONCE(rreq->cleaned_to, fpos + fsize);
*notes |= MADE_PROGRESS;
- /* Clean up the head folioq. If we clear an entire folioq, then
- * we can get rid of it provided it's not also the tail folioq
+ /* 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.
*/
- folioq_clear(folioq, slot);
+ bq->bv[slot].bv_page = NULL;
slot++;
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = rolling_buffer_delete_spent(&rreq->buffer);
- if (!folioq)
+ while (!bvecq_acquire_slot(bq, slot)) {
+ bq = rolling_buffer_delete_spent(&rreq->buffer);
+ if (!bq)
goto done;
slot = 0;
- trace_netfs_folioq(folioq, netfs_trace_folioq_read_progress);
}
if (fpos + fsize >= collected_to)
break;
}
- rreq->buffer.tail = folioq;
+ rreq->buffer.tail = bq;
done:
rreq->buffer.first_tail_slot = slot;
diff --git a/fs/netfs/read_pgpriv2.c b/fs/netfs/read_pgpriv2.c
index 5280b606fda410..f8e5667e278e1b 100644
--- a/fs/netfs/read_pgpriv2.c
+++ b/fs/netfs/read_pgpriv2.c
@@ -53,7 +53,7 @@ static void netfs_pgpriv2_copy_folio(struct netfs_io_request *creq, struct folio
trace_netfs_folio(folio, netfs_folio_trace_store_copy);
/* Attach the folio to the rolling buffer. */
- if (rolling_buffer_append(&creq->buffer, folio, 0, creq->gfp) < 0) {
+ if (rolling_buffer_append(&creq->buffer, folio, creq->gfp) < 0) {
set_bit(NETFS_RREQ_CANCEL_CACHING, &creq->flags);
folio_end_private_2(folio);
return;
@@ -173,13 +173,15 @@ void netfs_pgpriv2_end_copy_to_cache(struct netfs_io_request *rreq)
*/
bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *creq)
{
- struct folio_queue *folioq = creq->buffer.tail;
+ struct bvecq *bq = creq->buffer.tail;
unsigned int slot = creq->buffer.first_tail_slot;
uoff_t collected_to = creq->collected_to;
bool made_progress = false;
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = rolling_buffer_delete_spent(&creq->buffer);
+ while (!bvecq_acquire_slot(bq, slot)) {
+ bq = rolling_buffer_delete_spent(&creq->buffer);
+ if (!bq)
+ return false;
slot = 0;
}
@@ -188,7 +190,7 @@ bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *creq)
uoff_t fpos, fend;
size_t fsize, flen;
- folio = folioq_folio(folioq, slot);
+ folio = bvec_folio(&bq->bv[slot]);
if (WARN_ONCE(!folio_test_private_2(folio),
"R=%08x: folio %lx is not marked private_2\n",
creq->debug_id, folio->index))
@@ -211,15 +213,15 @@ bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *creq)
creq->cleaned_to = fpos + fsize;
made_progress = true;
- /* Clean up the head folioq. If we clear an entire folioq, then
- * we can get rid of it provided it's not also the tail folioq
+ /* 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.
*/
- folioq_clear(folioq, slot);
+ bq->bv[slot].bv_page = NULL;
slot++;
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = rolling_buffer_delete_spent(&creq->buffer);
- if (!folioq)
+ while (!bvecq_acquire_slot(bq, slot)) {
+ bq = rolling_buffer_delete_spent(&creq->buffer);
+ if (!bq)
goto done;
slot = 0;
}
@@ -228,7 +230,7 @@ bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *creq)
break;
}
- creq->buffer.tail = folioq;
+ creq->buffer.tail = bq;
done:
creq->buffer.first_tail_slot = slot;
return made_progress;
diff --git a/fs/netfs/read_retry.c b/fs/netfs/read_retry.c
index 5bd8dee5a83467..142c3fb8dab17c 100644
--- a/fs/netfs/read_retry.c
+++ b/fs/netfs/read_retry.c
@@ -291,7 +291,7 @@ void netfs_retry_reads(struct netfs_io_request *rreq)
*/
void netfs_unlock_abandoned_read_pages(struct netfs_io_request *rreq)
{
- struct folio_queue *p;
+ struct bvecq *p;
/* 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
@@ -301,24 +301,25 @@ void netfs_unlock_abandoned_read_pages(struct netfs_io_request *rreq)
netfs_wait_for_put_ra_refs(rreq);
for (p = rreq->buffer.tail; p; p = p->next) {
- for (int slot = 0; slot < folioq_count(p); slot++) {
- struct folio *folio = folioq_folio(p, slot);
+ for (int slot = rreq->buffer.first_tail_slot;
+ bvecq_acquire_slot(p, slot);
+ slot++) {
+ struct folio *folio;
- if (!folio)
+ if (!p->bv[slot].bv_page)
continue;
+
+ folio = bvec_folio(&p->bv[slot]);
netfs_cancel_copy_to_cache(rreq, folio);
- if (!folioq_is_marked2(p, slot)) {
- 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);
- }
+ 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);
}
}
+ rreq->buffer.first_tail_slot = 0;
}
}
diff --git a/fs/netfs/rolling_buffer.c b/fs/netfs/rolling_buffer.c
index d30d5ef6d86eca..e23d87c8d4b38e 100644
--- a/fs/netfs/rolling_buffer.c
+++ b/fs/netfs/rolling_buffer.c
@@ -6,102 +6,56 @@
*/
#include <linux/bitops.h>
-#include <linux/mempool.h>
#include <linux/pagemap.h>
#include <linux/rolling_buffer.h>
#include <linux/slab.h>
#include "internal.h"
-static atomic_t debug_ids;
-
-/**
- * netfs_folioq_alloc - Allocate a folio_queue struct
- * @rreq_id: Associated debugging ID for tracing purposes
- * @gfp: Allocation constraints
- * @trace: Trace tag to indicate the purpose of the allocation
- *
- * Allocate, initialise and account the folio_queue struct and log a trace line
- * to mark the allocation.
- */
-struct folio_queue *netfs_folioq_alloc(unsigned int rreq_id, gfp_t gfp,
- unsigned int /*enum netfs_folioq_trace*/ trace)
-{
- struct folio_queue *fq;
-
- if (gfp == GFP_KERNEL)
- fq = mempool_alloc_noreserve(&netfs_folioq_pool, gfp);
- else
- fq = mempool_alloc(&netfs_folioq_pool, gfp);
- if (fq) {
- netfs_stat(&netfs_n_folioq);
- folioq_init(fq, rreq_id);
- fq->debug_id = atomic_inc_return(&debug_ids);
- trace_netfs_folioq(fq, trace);
- }
- return fq;
-}
-EXPORT_SYMBOL(netfs_folioq_alloc);
-
-/**
- * netfs_folioq_free - Free a folio_queue struct
- * @folioq: The object to free
- * @trace: Trace tag to indicate which free
- *
- * Free and unaccount the folio_queue struct.
- */
-void netfs_folioq_free(struct folio_queue *folioq,
- unsigned int /*enum netfs_trace_folioq*/ trace)
-{
- trace_netfs_folioq(folioq, trace);
- netfs_stat_d(&netfs_n_folioq);
- mempool_free(folioq, &netfs_folioq_pool);
-}
-EXPORT_SYMBOL(netfs_folioq_free);
-
/*
* 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 rreq_id,
- unsigned int direction, gfp_t gfp)
+int rolling_buffer_init(struct rolling_buffer *roll, unsigned int direction,
+ gfp_t gfp, bool for_writeback)
{
- struct folio_queue *fq;
+ struct bvecq *bq;
+
+ roll->for_writeback = for_writeback;
- fq = netfs_folioq_alloc(rreq_id, gfp, netfs_trace_folioq_rollbuf_init);
- if (!fq)
+ bq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, for_writeback);
+ if (!bq)
return -ENOMEM;
- roll->head = fq;
- roll->tail = fq;
- iov_iter_folio_queue(&roll->iter, direction, fq, 0, 0, 0);
+ roll->head = bq;
+ roll->tail = bq;
+ iov_iter_bvec_queue(&roll->iter, direction, bq, 0, 0, 0);
return 0;
}
/*
- * Add another folio_queue to a rolling buffer if there's no space left.
+ * 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 folio_queue *fq, *head = roll->head;
+ struct bvecq *bq, *head = roll->head;
- if (!folioq_full(head))
+ if (!bvecq_is_full(head))
return 0;
- fq = netfs_folioq_alloc(head->rreq_id, gfp, netfs_trace_folioq_make_space);
- if (!fq)
+ bq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, roll->for_writeback);
+ if (!bq)
return -ENOMEM;
- fq->prev = head;
- roll->head = fq;
- if (folioq_full(head)) {
+ 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.folioq == head &&
- roll->iter.folioq_slot == folioq_nr_slots(head)) {
- roll->iter.folioq = fq;
- roll->iter.folioq_slot = 0;
+ if (roll->iter.bvecq == head &&
+ roll->iter.bvecq_slot == head->nr_slots) {
+ roll->iter.bvecq = bq;
+ roll->iter.bvecq_slot = 0;
}
}
@@ -110,7 +64,7 @@ int rolling_buffer_make_space(struct rolling_buffer *roll, gfp_t gfp)
* [!] NOTE: After we set head->next, the consumer is at liberty to
* immediately delete the old head.
*/
- smp_store_release(&head->next, fq);
+ bvecq_append(head, bq);
return 0;
}
@@ -119,55 +73,59 @@ 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,
- unsigned int rreq_id, gfp_t gfp)
+ gfp_t gfp)
{
- struct folio_queue *fq;
- ssize_t loaded = 0;
+ struct bvecq *bq;
+ size_t loaded = 0;
while (ractl->_nr_pages - ractl->_batch_count > 0) {
+ struct page **pages;
unsigned int nr;
- /* Allocate a folioq to put some folios into and attach it to
+ /* Allocate a bvecq to put some folios into and attach it to
* the rolling buffer.
*/
- fq = netfs_folioq_alloc(rreq_id, gfp,
- netfs_trace_folioq_make_space);
- if (!fq)
+ bq = bvecq_alloc_one(BVECQ_POOL_SLOTS, gfp, false);
+ if (!bq)
goto nomem_unlock;
- fq->prev = roll->head;
+ bq->mem_type = BVECQ_MEM_EXTERNAL; /* Folio cleanup handled separately. */
+
if (!roll->tail)
- roll->tail = fq;
+ roll->tail = bq;
else
- roll->head->next = fq;
- roll->head = fq;
+ bvecq_append(roll->head, bq);
+ roll->head = bq;
- /* Get a batch of folios and note their orders. */
- nr = __readahead_batch(ractl, (struct page **)fq->vec.folios,
- folioq_nr_slots(fq));
+ /* 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;
- fq->vec.nr = nr;
for (int slot = 0; slot < nr; slot++) {
- struct folio *folio = folioq_folio(fq, slot);
- unsigned int order;
+ struct folio *folio = page_folio(pages[slot]);
+ size_t len = folio_size(folio);
- order = folio_order(folio);
- fq->orders[slot] = order;
- loaded += PAGE_SIZE << order;
+ 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_folio_queue(&roll->iter, ITER_DEST, roll->tail, 0, 0, loaded);
+ iov_iter_bvec_queue(&roll->iter, ITER_DEST, roll->tail, 0, 0, loaded);
return loaded;
nomem_unlock:
- for (fq = roll->tail; fq; fq = fq->next) {
- for (int slot = 0; slot < folioq_count(fq); slot++) {
- folio_unlock(fq->vec.folios[slot]);
- folioq_mark(fq, slot);
+ 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);
@@ -180,7 +138,7 @@ ssize_t rolling_buffer_bulk_load_from_ra(struct rolling_buffer *roll,
* Append a folio to the rolling buffer.
*/
ssize_t rolling_buffer_append(struct rolling_buffer *roll, struct folio *folio,
- unsigned int flags, gfp_t gfp)
+ gfp_t gfp)
{
ssize_t size = folio_size(folio);
int slot;
@@ -188,16 +146,11 @@ ssize_t rolling_buffer_append(struct rolling_buffer *roll, struct folio *folio,
if (rolling_buffer_make_space(roll, gfp) < 0)
return -ENOMEM;
- slot = folioq_append(roll->head, folio);
- if (flags & ROLLBUF_MARK_1)
- folioq_mark(roll->head, slot);
- if (flags & ROLLBUF_MARK_2)
- folioq_mark2(roll->head, slot);
+ 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);
-
- /* Store the counter after setting the slot. */
- smp_store_release(&roll->next_head_slot, slot);
return size;
}
@@ -206,44 +159,23 @@ ssize_t rolling_buffer_append(struct rolling_buffer *roll, struct folio *folio,
* don't return the last buffer to keep the pointers independent, but return
* NULL instead.
*/
-struct folio_queue *rolling_buffer_delete_spent(struct rolling_buffer *roll)
+struct bvecq *rolling_buffer_delete_spent(struct rolling_buffer *roll)
{
- struct folio_queue *spent = roll->tail, *next = READ_ONCE(spent->next);
+ struct bvecq *spent = roll->tail, *next = bvecq_next(spent);
if (!next)
return NULL;
next->prev = NULL;
- netfs_folioq_free(spent, netfs_trace_folioq_delete);
roll->tail = next;
+ spent->next = NULL;
+ bvecq_put(spent);
return next;
}
/*
- * Clear out a rolling queue. Folios that have mark 1 set are put.
+ * Clear out a rolling queue.
*/
void rolling_buffer_clear(struct rolling_buffer *roll)
{
- struct folio_batch fbatch;
- struct folio_queue *p;
-
- folio_batch_init(&fbatch);
-
- while ((p = roll->tail)) {
- roll->tail = p->next;
- for (int slot = 0; slot < folioq_count(p); slot++) {
- struct folio *folio = folioq_folio(p, slot);
-
- if (!folio)
- continue;
- if (folioq_is_marked(p, slot)) {
- trace_netfs_folio(folio, netfs_folio_trace_put);
- if (!folio_batch_add(&fbatch, folio))
- folio_batch_release(&fbatch);
- }
- }
-
- netfs_folioq_free(p, netfs_trace_folioq_clear);
- }
-
- folio_batch_release(&fbatch);
+ bvecq_put(roll->tail);
}
diff --git a/fs/netfs/stats.c b/fs/netfs/stats.c
index 9a607c4e62dda5..0ba6ce9295b257 100644
--- a/fs/netfs/stats.c
+++ b/fs/netfs/stats.c
@@ -46,7 +46,7 @@ atomic_t netfs_n_wh_retry_write_req;
atomic_t netfs_n_wh_retry_write_subreq;
atomic_t netfs_n_wb_lock_skip;
atomic_t netfs_n_wb_lock_wait;
-atomic_t netfs_n_folioq;
+atomic_t netfs_n_bvecq;
int netfs_stats_show(struct seq_file *m, void *v)
{
@@ -88,10 +88,10 @@ int netfs_stats_show(struct seq_file *m, void *v)
atomic_read(&netfs_n_rh_retry_read_subreq),
atomic_read(&netfs_n_wh_retry_write_req),
atomic_read(&netfs_n_wh_retry_write_subreq));
- seq_printf(m, "Objs : rr=%u sr=%u foq=%u wsc=%u\n",
+ seq_printf(m, "Objs : rr=%u sr=%u bq=%u wsc=%u\n",
atomic_read(&netfs_n_rh_rreq),
atomic_read(&netfs_n_rh_sreq),
- atomic_read(&netfs_n_folioq),
+ atomic_read(&netfs_n_bvecq),
atomic_read(&netfs_n_wh_wstream_conflict));
seq_printf(m, "WbLock : skip=%u wait=%u\n",
atomic_read(&netfs_n_wb_lock_skip),
diff --git a/fs/netfs/write_collect.c b/fs/netfs/write_collect.c
index 6e8ea534230df0..91b42820c89252 100644
--- a/fs/netfs/write_collect.c
+++ b/fs/netfs/write_collect.c
@@ -114,11 +114,11 @@ int netfs_folio_written_back(struct folio *folio)
static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,
unsigned int *notes)
{
- struct folio_queue *folioq = wreq->buffer.tail;
+ struct bvecq *bq = wreq->buffer.tail;
unsigned int slot = wreq->buffer.first_tail_slot;
uoff_t collected_to = wreq->collected_to;
- if (WARN_ON_ONCE(!folioq)) {
+ if (WARN_ON_ONCE(!bq)) {
pr_err("[!] Writeback unlock found empty rolling buffer!\n");
netfs_dump_request(wreq);
return;
@@ -130,9 +130,9 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,
return;
}
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = rolling_buffer_delete_spent(&wreq->buffer);
- if (!folioq)
+ while (!bvecq_acquire_slot(bq, slot)) {
+ bq = rolling_buffer_delete_spent(&wreq->buffer);
+ if (!bq)
return;
slot = 0;
}
@@ -143,7 +143,7 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,
uoff_t fpos, fend;
size_t fsize, flen;
- folio = folioq_folio(folioq, slot);
+ folio = bvec_folio(&bq->bv[slot]);
if (WARN_ONCE(!folio_test_writeback(folio),
"R=%08x: folio %lx is not under writeback\n",
wreq->debug_id, folio->index))
@@ -166,15 +166,15 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,
wreq->cleaned_to = fpos + fsize;
*notes |= MADE_PROGRESS;
- /* Clean up the head folioq. If we clear an entire folioq, then
- * we can get rid of it provided it's not also the tail folioq
+ /* 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.
*/
- folioq_clear(folioq, slot);
+ bq->bv[slot].bv_page = NULL;
slot++;
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = rolling_buffer_delete_spent(&wreq->buffer);
- if (!folioq)
+ while (!bvecq_acquire_slot(bq, slot)) {
+ bq = rolling_buffer_delete_spent(&wreq->buffer);
+ if (!bq)
goto done;
slot = 0;
}
@@ -183,7 +183,7 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,
break;
}
- wreq->buffer.tail = folioq;
+ wreq->buffer.tail = bq;
done:
wreq->buffer.first_tail_slot = slot;
}
diff --git a/fs/netfs/write_issue.c b/fs/netfs/write_issue.c
index b8237e1314d8a4..37d1e5055c0ba5 100644
--- a/fs/netfs/write_issue.c
+++ b/fs/netfs/write_issue.c
@@ -107,7 +107,9 @@ 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, wreq->debug_id, ITER_SOURCE, wreq->gfp) < 0)
+ 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;
@@ -163,12 +165,12 @@ void netfs_prepare_write(struct netfs_io_request *wreq,
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 folio_queue
- * struct being used as a placeholder to prevent the queue from
- * collapsing. In such a case, extend the queue.
+ /* 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_folioq(wreq_iter) &&
- wreq_iter->folioq_slot >= folioq_nr_slots(wreq_iter->folioq))
+ 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);
@@ -451,7 +453,7 @@ static int netfs_write_folio(struct netfs_io_request *wreq,
}
/* Attach the folio to the rolling buffer. */
- rolling_buffer_append(&wreq->buffer, folio, 0, wreq->gfp);
+ rolling_buffer_append(&wreq->buffer, folio, wreq->gfp);
/* 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
@@ -625,147 +627,32 @@ int netfs_writepages(struct address_space *mapping,
}
EXPORT_SYMBOL(netfs_writepages);
-/*
- * Write some of a pending folio data back to the server and/or the cache.
- */
-static int netfs_write_folio_single(struct netfs_io_request *wreq,
- struct folio *folio)
-{
- struct netfs_io_stream *upload = &wreq->io_streams[0];
- struct netfs_io_stream *cache = &wreq->io_streams[1];
- struct netfs_io_stream *stream;
- size_t iter_off = 0;
- size_t fsize = folio_size(folio), flen;
- uoff_t fpos = folio_pos(folio);
- ssize_t ret;
- bool to_eof = false;
- bool no_debug = false;
-
- _enter("");
-
- flen = folio_size(folio);
- if (flen > wreq->i_size - fpos) {
- flen = wreq->i_size - fpos;
- folio_zero_segment(folio, flen, fsize);
- to_eof = true;
- } else if (flen == wreq->i_size - fpos) {
- to_eof = true;
- }
-
- _debug("folio %zx/%zx", flen, fsize);
-
- if (!upload->avail && !cache->avail) {
- trace_netfs_folio(folio, netfs_folio_trace_cancel_store);
- return 0;
- }
-
- if (!upload->construct)
- trace_netfs_folio(folio, netfs_folio_trace_store);
- else
- trace_netfs_folio(folio, netfs_folio_trace_store_plus);
-
- /* Attach the folio to the rolling buffer. */
- folio_get(folio);
- ret = rolling_buffer_append(&wreq->buffer, folio, NETFS_ROLLBUF_PUT_MARK, wreq->gfp);
- if (ret < 0) {
- folio_put(folio);
- return ret;
- }
-
- /* 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
- * with the cache as the cache requires DIO alignment.
- *
- * Also skip uploading for data that's been read and just needs copying
- * to the cache.
- */
- for (int s = 0; s < NR_IO_STREAMS; s++) {
- stream = &wreq->io_streams[s];
- stream->submit_off = 0;
- stream->submit_len = flen;
- if (!stream->avail) {
- stream->submit_off = UINT_MAX;
- stream->submit_len = 0;
- }
- }
-
- /* Attach the folio to one or more subrequests. For a big folio, we
- * could end up with thousands of subrequests if the wsize is small -
- * but we might need to wait during the creation of subrequests for
- * network resources (eg. SMB credits).
- */
- for (;;) {
- ssize_t part;
- size_t lowest_off = ULONG_MAX;
- int choose_s = -1;
-
- /* Always add to the lowest-submitted stream first. */
- for (int s = 0; s < NR_IO_STREAMS; s++) {
- stream = &wreq->io_streams[s];
- if (stream->submit_len > 0 &&
- stream->submit_off < lowest_off) {
- lowest_off = stream->submit_off;
- choose_s = s;
- }
- }
-
- if (choose_s < 0)
- 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;
- }
-
- 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;
- if (part > stream->submit_len)
- stream->submit_len = 0;
- else
- stream->submit_len -= part;
- if (part > 0)
- no_debug = true;
- }
-
- wreq->buffer.iter.iov_offset = 0;
- if (fsize > iter_off)
- rolling_buffer_advance(&wreq->buffer, fsize - iter_off);
- atomic64_set(&wreq->issued_to, fpos + fsize);
-
- if (!no_debug)
- kdebug("R=%x: No submit", wreq->debug_id);
- _leave(" = 0");
- return 0;
-}
-
/**
- * netfs_writeback_single - Write back a monolithic payload
+ * netfs_writeback_single - Write back a monolithic payload to cache
* @mapping: The mapping to write from
* @wbc: Hints from the VM
- * @iter: Data to write, must be ITER_FOLIOQ.
+ * @iter: Data buffer to write from.
+ * @len: Amount of data to write.
+ *
+ * Write a monolithic, non-pagecache object back to the cache only. The data
+ * is not written to the server.
*
- * Write a monolithic, non-pagecache object back to the server and/or
- * the cache.
+ * The data buffer may be bigger than @len (as set in @iter's count), and if
+ * so, this function will use the extra as needed to provide padding into the
+ * cache to handle DIO rounding, so the caller should clear it.
*
* 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);
- struct folio_queue *fq;
- size_t size = iov_iter_count(iter);
int ret;
- if (WARN_ON_ONCE(!iov_iter_is_folioq(iter)))
+ if (WARN_ON_ONCE(iov_iter_count(iter) < len))
return -EIO;
if (!netfs_wb_begin(ictx, wbc->sync_mode == WB_SYNC_NONE)) {
@@ -780,36 +667,42 @@ int netfs_writeback_single(struct address_space *mapping,
goto couldnt_start;
}
+ wreq->buffer.iter = *iter;
+ wreq->len = len;
+ wreq->submitted = wreq->len;
+
__set_bit(NETFS_RREQ_OFFLOAD_COLLECTION, &wreq->flags);
trace_netfs_write(wreq, netfs_write_trace_writeback_single);
netfs_stat(&netfs_n_wh_writepages);
- if (__test_and_set_bit(NETFS_RREQ_UPLOAD_TO_SERVER, &wreq->flags))
- wreq->netfs_ops->begin_writeback(wreq);
+ for (int s = 0; s < NR_IO_STREAMS; s++) {
+ struct netfs_io_subrequest *subreq;
+ struct netfs_io_stream *stream = &wreq->io_streams[s];
+
+ if (!stream->avail)
+ continue;
- for (fq = (struct folio_queue *)iter->folioq; fq; fq = fq->next) {
- for (int slot = 0; slot < folioq_count(fq); slot++) {
- struct folio *folio = folioq_folio(fq, slot);
- size_t part = umin(folioq_folio_size(fq, slot), size);
+ netfs_prepare_write(wreq, stream, 0);
+ /* Allocation not allowed to fail in writeback. */
- _debug("wbiter %lx %llx", folio->index, atomic64_read(&wreq->issued_to));
+ subreq = stream->construct;
+ subreq->len = wreq->len;
+ stream->submit_len = subreq->len;
+ stream->submit_extendable_to = iov_iter_count(iter) - len;
- ret = netfs_write_folio_single(wreq, folio);
- if (ret < 0)
- goto stop;
- size -= part;
- if (size <= 0)
- goto stop;
- }
+ netfs_issue_write(wreq, stream);
}
-stop:
- for (int s = 0; s < NR_IO_STREAMS; s++)
- netfs_issue_write(wreq, &wreq->io_streams[s]);
netfs_all_subreqs_queued(wreq);
-
netfs_wake_collector(wreq);
+ /* TODO: Might want to be async here if WB_SYNC_NONE, but then need to
+ * wait before modifying.
+ */
+ ret = netfs_wait_for_write(wreq);
+ if (ret > 0)
+ ret = 0;
+
netfs_put_request(wreq, netfs_rreq_trace_put_return);
_leave(" = %d", ret);
return ret;
diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h
index d3ca688b6aba99..806242d9cce06a 100644
--- a/fs/smb/client/cifsglob.h
+++ b/fs/smb/client/cifsglob.h
@@ -290,7 +290,7 @@ struct smb_rqst {
struct kvec *rq_iov; /* array of kvecs */
unsigned int rq_nvec; /* number of kvecs in array */
struct iov_iter rq_iter; /* Data iterator */
- struct folio_queue *rq_buffer; /* Buffer for encryption */
+ struct bvecq *rq_buffer; /* Buffer for encryption */
};
struct mid_q_entry;
diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c
index dc55cd512616ab..9d462f6e896c33 100644
--- a/fs/smb/client/smb2ops.c
+++ b/fs/smb/client/smb2ops.c
@@ -13,7 +13,7 @@
#include <linux/sort.h>
#include <crypto/aead.h>
#include <linux/fiemap.h>
-#include <linux/folio_queue.h>
+#include <linux/bvecq.h>
#include <uapi/linux/magic.h>
#include "cifsfs.h"
#include "cifsglob.h"
@@ -4918,19 +4918,18 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,
}
/*
- * Copy data from an iterator to the folios in a folio queue buffer.
+ * Copy data from an iterator to the pages in a bvec queue buffer.
*/
-static bool cifs_copy_iter_to_folioq(struct iov_iter *iter, size_t size,
- struct folio_queue *buffer)
+static bool cifs_copy_iter_to_bvecq(struct iov_iter *iter, size_t size,
+ struct bvecq *buffer)
{
for (; buffer; buffer = buffer->next) {
- for (int s = 0; s < folioq_count(buffer); s++) {
- struct folio *folio = folioq_folio(buffer, s);
- size_t part = folioq_folio_size(buffer, s);
+ for (int s = 0; s < bvecq_nr_slots_acquire(buffer); s++) {
+ struct bio_vec *bv = &buffer->bv[s];
+ size_t part = umin(bv->bv_len, size);
- part = umin(part, size);
-
- if (copy_folio_from_iter(folio, 0, part, iter) != part)
+ if (copy_page_from_iter(bv->bv_page, bv->bv_offset,
+ part, iter) != part)
return false;
size -= part;
}
@@ -4942,7 +4941,7 @@ void
smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
{
for (int i = 0; i < num_rqst; i++)
- netfs_free_folioq_buffer(rqst[i].rq_buffer);
+ bvecq_put(rqst[i].rq_buffer);
}
/*
@@ -4969,7 +4968,7 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
for (int i = 1; i < num_rqst; i++) {
struct smb_rqst *old = &old_rq[i - 1];
struct smb_rqst *new = &new_rq[i];
- struct folio_queue *buffer = NULL;
+ struct bvecq *buffer = NULL;
size_t size = iov_iter_count(&old->rq_iter);
orig_len += smb_rqst_len(server, old);
@@ -4977,17 +4976,16 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
new->rq_nvec = old->rq_nvec;
if (size > 0) {
- size_t cur_size = 0;
- rc = netfs_alloc_folioq_buffer(NULL, &buffer, &cur_size,
- size, GFP_NOFS);
- new->rq_buffer = buffer;
- if (rc < 0)
+ rc = -ENOMEM;
+ buffer = bvecq_alloc_buffer(size, GFP_NOFS, true);
+ if (!buffer)
goto err_free;
- iov_iter_folio_queue(&new->rq_iter, ITER_SOURCE,
- buffer, 0, 0, size);
+ new->rq_buffer = buffer;
+ iov_iter_bvec_queue(&new->rq_iter, ITER_SOURCE,
+ buffer, 0, 0, size);
- if (!cifs_copy_iter_to_folioq(&old->rq_iter, size, buffer)) {
+ if (!cifs_copy_iter_to_bvecq(&old->rq_iter, size, buffer)) {
rc = smb_EIO1(smb_eio_trace_tx_copy_iter_to_buf, size);
goto err_free;
}
@@ -5077,22 +5075,20 @@ decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
}
static int
-cifs_copy_folioq_to_iter(struct folio_queue *folioq, size_t data_size,
- size_t skip, struct iov_iter *iter)
+cifs_copy_bvecq_to_iter(struct bvecq *bq, size_t data_size,
+ size_t skip, struct iov_iter *iter)
{
- for (; folioq; folioq = folioq->next) {
- for (int s = 0; s < folioq_count(folioq); s++) {
- struct folio *folio;
- size_t fsize, n, len;
+ for (; bq; bq = bq->next) {
+ for (int s = 0; s < bvecq_nr_slots_acquire(bq); s++) {
+ struct bio_vec *bv = &bq->bv[s];
+ size_t n, len;
if (data_size == 0)
return 0;
- folio = folioq_folio(folioq, s);
- fsize = folio_size(folio);
- len = umin(fsize - skip, data_size);
+ len = umin(bv->bv_len - skip, data_size);
- n = copy_folio_to_iter(folio, skip, len, iter);
+ n = copy_page_to_iter(bv->bv_page, bv->bv_offset + skip, len, iter);
if (n != len) {
cifs_dbg(VFS, "%s: something went wrong\n", __func__);
return smb_EIO2(smb_eio_trace_rx_copy_to_iter,
@@ -5114,7 +5110,7 @@ cifs_copy_folioq_to_iter(struct folio_queue *folioq, size_t data_size,
static int
handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
- char *buf, unsigned int buf_len, struct folio_queue *buffer,
+ char *buf, unsigned int buf_len, struct bvecq *buffer,
unsigned int buffer_len, bool is_offloaded)
{
unsigned int data_offset;
@@ -5224,8 +5220,8 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
}
/* Copy the data to the output I/O iterator. */
- rdata->result = cifs_copy_folioq_to_iter(buffer, data_len,
- cur_off, &rdata->subreq.io_iter);
+ rdata->result = cifs_copy_bvecq_to_iter(buffer, data_len,
+ cur_off, &rdata->subreq.io_iter);
if (rdata->result != 0) {
if (is_offloaded)
mid->mid_state = MID_RESPONSE_MALFORMED;
@@ -5264,7 +5260,7 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
struct smb2_decrypt_work {
struct work_struct decrypt;
struct TCP_Server_Info *server;
- struct folio_queue *buffer;
+ struct bvecq *buffer;
char *buf;
unsigned int len;
};
@@ -5278,7 +5274,7 @@ static void smb2_decrypt_offload(struct work_struct *work)
struct mid_q_entry *mid;
struct iov_iter iter;
- iov_iter_folio_queue(&iter, ITER_DEST, dw->buffer, 0, 0, dw->len);
+ iov_iter_bvec_queue(&iter, ITER_DEST, dw->buffer, 0, 0, dw->len);
rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
&iter, true);
if (rc) {
@@ -5328,7 +5324,7 @@ static void smb2_decrypt_offload(struct work_struct *work)
}
free_pages:
- netfs_free_folioq_buffer(dw->buffer);
+ bvecq_put(dw->buffer);
cifs_small_buf_release(dw->buf);
kfree(dw);
}
@@ -5374,12 +5370,12 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
dw->len = len;
len = round_up(dw->len, PAGE_SIZE);
- size_t cur_size = 0;
- rc = netfs_alloc_folioq_buffer(NULL, &dw->buffer, &cur_size, len, GFP_NOFS);
- if (rc < 0)
+ rc = -ENOMEM;
+ dw->buffer = bvecq_alloc_buffer(len, GFP_NOFS, false);
+ if (!dw->buffer)
goto discard_data;
- iov_iter_folio_queue(&iter, ITER_DEST, dw->buffer, 0, 0, len);
+ iov_iter_bvec_queue(&iter, ITER_DEST, dw->buffer, 0, 0, len);
/* Read the data into the buffer and clear excess bufferage. */
rc = cifs_read_iter_from_socket(server, &iter, dw->len);
@@ -5439,7 +5435,7 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
}
free_pages:
- netfs_free_folioq_buffer(dw->buffer);
+ bvecq_put(dw->buffer);
free_dw:
kfree(dw);
return rc;
diff --git a/fs/smb/smbdirect/connection.c b/fs/smb/smbdirect/connection.c
index e6c7b343fe8703..210e53495fe8f4 100644
--- a/fs/smb/smbdirect/connection.c
+++ b/fs/smb/smbdirect/connection.c
@@ -5,7 +5,7 @@
*/
#include "internal.h"
-#include <linux/folio_queue.h>
+#include <linux/bvecq.h>
struct smbdirect_map_sges {
struct ib_sge *sge;
@@ -2015,6 +2015,69 @@ static ssize_t smbdirect_map_sges_from_bvec(struct iov_iter *iter,
return ret;
}
+/*
+ * Extract memory fragments from a BVECQ-class iterator and add them to an RDMA
+ * list. The fragments are not pinned.
+ */
+static ssize_t smbdirect_map_sges_from_bvecq(struct iov_iter *iter,
+ struct smbdirect_map_sges *state,
+ ssize_t maxsize)
+{
+ const struct bvecq *bq = iter->bvecq, *next;
+ unsigned int slot = iter->bvecq_slot;
+ ssize_t extracted = 0;
+ size_t offset = iter->iov_offset;
+
+ maxsize = umin(maxsize, iov_iter_count(iter));
+
+ do {
+ struct bio_vec *bv;
+ size_t bsize;
+
+ while (slot >= bq->nr_slots) {
+ next = bvecq_next(bq);
+ if (!next) {
+ if (WARN_ON_ONCE(maxsize > 0))
+ return -EIO;
+ goto out;
+ }
+ bq = next;
+ slot = 0;
+ }
+
+ bv = &bq->bv[slot];
+ bsize = bv->bv_len;
+
+ if (offset < bsize) {
+ size_t part = umin(maxsize, bsize - offset);
+ bool ok;
+
+ ok = smbdirect_map_sges_single_page(state,
+ bv->bv_page,
+ bv->bv_offset + offset,
+ part);
+ if (!ok)
+ return -EIO;
+
+ offset += part;
+ extracted += part;
+ maxsize -= part;
+ }
+
+ if (offset >= bsize) {
+ offset = 0;
+ slot++;
+ }
+ } while (state->num_sge < state->max_sge && maxsize > 0);
+
+out:
+ iter->bvecq = bq;
+ iter->bvecq_slot = slot;
+ iter->iov_offset = offset;
+ iter->count -= extracted;
+ return extracted;
+}
+
/*
* Extract fragments from a KVEC-class iterator and add them to an ib_sge list.
* This can deal with vmalloc'd buffers as well as kmalloc'd or static buffers.
@@ -2076,70 +2139,6 @@ static ssize_t smbdirect_map_sges_from_kvec(struct iov_iter *iter,
return ret;
}
-/*
- * Extract folio fragments from a FOLIOQ-class iterator and add them to an
- * ib_sge list. The folios are not pinned.
- */
-static ssize_t smbdirect_map_sges_from_folioq(struct iov_iter *iter,
- struct smbdirect_map_sges *state,
- ssize_t maxsize)
-{
- const struct folio_queue *folioq = iter->folioq;
- unsigned int slot = iter->folioq_slot;
- ssize_t ret = 0;
- size_t offset = iter->iov_offset;
-
- if (WARN_ON_ONCE(!folioq))
- return -EIO;
-
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = folioq->next;
- if (WARN_ON_ONCE(!folioq))
- return -EIO;
- slot = 0;
- }
-
- do {
- struct folio *folio = folioq_folio(folioq, slot);
- size_t fsize = folioq_folio_size(folioq, slot);
-
- if (offset < fsize) {
- size_t part = umin(maxsize, fsize - offset);
- bool ok;
-
- ok = smbdirect_map_sges_single_page(state,
- folio_page(folio, 0),
- offset,
- part);
- if (!ok)
- return -EIO;
-
- offset += part;
- ret += part;
- maxsize -= part;
- }
-
- if (offset >= fsize) {
- offset = 0;
- slot++;
- if (slot >= folioq_nr_slots(folioq)) {
- if (!folioq->next) {
- WARN_ON_ONCE(ret < iter->count);
- break;
- }
- folioq = folioq->next;
- slot = 0;
- }
- }
- } while (state->num_sge < state->max_sge && maxsize > 0);
-
- iter->folioq = folioq;
- iter->folioq_slot = slot;
- iter->iov_offset = offset;
- iter->count -= ret;
- return ret;
-}
-
/*
* Extract page fragments from up to the given amount of the source iterator
* and build up an ib_sge list that refers to all of those bits. The ib_sge list
@@ -2164,12 +2163,12 @@ static ssize_t smbdirect_map_sges_from_iter(struct iov_iter *iter, size_t len,
case ITER_BVEC:
ret = smbdirect_map_sges_from_bvec(iter, state, len);
break;
+ case ITER_BVECQ:
+ ret = smbdirect_map_sges_from_bvecq(iter, state, len);
+ break;
case ITER_KVEC:
ret = smbdirect_map_sges_from_kvec(iter, state, len);
break;
- case ITER_FOLIOQ:
- ret = smbdirect_map_sges_from_folioq(iter, state, len);
- break;
default:
WARN_ONCE(1, "iov_iter_type[%u]\n", iov_iter_type(iter));
return -EIO;
diff --git a/include/linux/bvec.h b/include/linux/bvec.h
index b63914ff56e33d..7ea62643cfb7cc 100644
--- a/include/linux/bvec.h
+++ b/include/linux/bvec.h
@@ -344,4 +344,22 @@ static inline phys_addr_t bvec_phys(const struct bio_vec *bvec)
return page_to_phys(bvec->bv_page) + bvec->bv_offset;
}
+/**
+ * bvec_kmap_partial - Map part of a bvec into the kernel virtual address space
+ * @bvec: bvec to map
+ * @offset: Offset into bvec
+ *
+ * Map the page containing the byte at @offset into the kernel virtual address
+ * space. The caller is responsible for making sure this doesn't overrun.
+ *
+ * Call kunmap_local on the returned address to unmap.
+ */
+static inline void *bvec_kmap_partial(const struct bio_vec *bvec, size_t offset)
+{
+ offset += bvec->bv_offset;
+
+ return kmap_local_page(bvec->bv_page + (offset >> PAGE_SHIFT)) +
+ (offset & ~PAGE_MASK);
+}
+
#endif /* __LINUX_BVEC_H */
diff --git a/include/linux/bvecq.h b/include/linux/bvecq.h
new file mode 100644
index 00000000000000..90e6eb9588bf8b
--- /dev/null
+++ b/include/linux/bvecq.h
@@ -0,0 +1,176 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Implementation of a segmented queue of bio_vec[].
+ *
+ * Copyright (C) 2026 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * See also Documentation/core-api/bvecq.rst
+ */
+
+#ifndef _LINUX_BVECQ_H
+#define _LINUX_BVECQ_H
+
+#include <linux/bvec.h>
+
+/*
+ * The type of memory retention used by the elements in bvecq->bv[] and how to
+ * clean it up.
+ */
+enum bvecq_mem {
+ BVECQ_MEM_EXTERNAL, /* Externally retained memory - no freeing */
+ BVECQ_MEM_PAGECACHE, /* Ref'd pagecache pages - must put */
+ BVECQ_MEM_GUP, /* Pinned memory from get_user_pages() - unpin */
+ BVECQ_MEM_ALLOCED, /* Memory alloc'd by bvecq - can be freed/pooled */
+} __mode(byte);
+
+/*
+ * Segmented bio_vec queue.
+ *
+ * These can be linked together to form messages of indefinite length and
+ * iterated over with an ITER_BVECQ iterator. The list is non-circular; next
+ * and prev are NULL at the ends.
+ *
+ * The bv pointer points to the bio_vec array; this may be __bv if allocated
+ * together. The caller is responsible for determining whether or not this is
+ * the case as the array pointed to by bv may be follow on directly from the
+ * bvecq by accident of allocation (ie. ->bv == ->__bv is *not* sufficient to
+ * determine this).
+ */
+struct bvecq {
+ struct bvecq *next; /* Next bvec in the list or NULL */
+ struct bvecq *prev; /* Prev bvec in the list or NULL */
+ refcount_t ref;
+ u32 priv; /* Private data */
+ u16 nr_slots; /* Number of elements in bv[] used */
+ u16 max_slots; /* Number of elements allocated in bv[] */
+ enum bvecq_mem mem_type:3; /* What sort of memory and how to free it */
+ bool inline_bv:1; /* T if __bv[] is being used */
+ bool from_pool:1; /* T if bvecq from mempool */
+ struct bio_vec *bv; /* Pointer to array of page fragments */
+ struct bio_vec __bv[]; /* Default array (if ->inline_bv) */
+};
+
+/* Number of slots in a 512-byte mempool-backed bvecq. */
+#define BVECQ_POOL_SIZE 512
+#define BVECQ_POOL_SLOTS ((BVECQ_POOL_SIZE - sizeof(struct bvecq)) / sizeof(struct bio_vec))
+
+/* Number of slots in a 4K bvecq. */
+#define BVECQ_4KB_SLOTS ((4096 - sizeof(struct bvecq)) / sizeof(struct bio_vec))
+
+/* Maximum number of slots in an inline allocation */
+#define BVECQ_MAX_INLINE_SLOTS USHRT_MAX
+
+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);
+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);
+
+/**
+ * bvecq_alloc_buffer - Allocate a bvecq chain and populate with buffers
+ * @size: Target size of the buffer (can be 0 for an empty buffer)
+ * @gfp: The allocation constraints.
+ * @for_writeback: True if allocating for writeback
+ *
+ * Wrapper around ``bvecq_alloc_buffer2()``.
+ *
+ * Return: The first node pointer or NULL on allocation failure.
+ */
+static inline struct bvecq *bvecq_alloc_buffer(size_t size, gfp_t gfp, bool for_writeback)
+{
+ return bvecq_alloc_buffer2(size, 0, gfp, for_writeback);
+}
+
+/**
+ * bvecq_get - Get a ref on a bvecq
+ * @bq: The bvecq to get a ref on
+ *
+ * Return: @bq.
+ */
+static inline struct bvecq *bvecq_get(struct bvecq *bq)
+{
+ refcount_inc(&bq->ref);
+ return bq;
+}
+
+/**
+ * bvecq_is_full - Determine if a bvecq is full
+ * @bvecq: The object to query
+ *
+ * Return: true if full; false if not.
+ */
+static inline bool bvecq_is_full(const struct bvecq *bvecq)
+{
+ return bvecq->nr_slots >= bvecq->max_slots;
+}
+
+/**
+ * bvecq_filled_to - Release filled slots with release barrier
+ * @bvecq: The object modified
+ * @to: The latest slot filled + 1
+ */
+static inline void bvecq_filled_to(struct bvecq *bvecq, unsigned int to)
+{
+ /* Set the slot counter after filling the slot */
+ smp_store_release(&bvecq->nr_slots, to);
+}
+
+/**
+ * bvecq_nr_slots_acquire - Get the number of filled slots with acquire barrier
+ * @bvecq: The object to query
+ *
+ * Return: The number of filled slots
+ */
+static inline unsigned int bvecq_nr_slots_acquire(const struct bvecq *bvecq)
+{
+ /* Read the slot counter before looking at the slot */
+ return smp_load_acquire(&bvecq->nr_slots);
+}
+
+/**
+ * bvecq_acquire_slot - Determine if a slot is valid with acquire barrier
+ * @bvecq: The object to query
+ * @slot: The next slot
+ *
+ * Return: true if valid; false if might not be valid
+ */
+static inline bool bvecq_acquire_slot(const struct bvecq *bvecq, unsigned int slot)
+{
+ /* Read the slot counter before looking at the slot */
+ return slot < bvecq_nr_slots_acquire(bvecq);
+}
+
+/**
+ * bvecq_append - Get the next bvecq with appropriate barrier
+ * @to: The bvecq to append to
+ * @add: The bvecq to append
+ *
+ * Attach a new bvecq to a chain using an appropriate barrier to protect the
+ * write.
+ *
+ * [!] Note that this function transfers the caller's ref to the chain.
+ */
+static inline void bvecq_append(struct bvecq *to, struct bvecq *add)
+{
+ add->prev = to;
+
+ /* Make sure the initialisation is stored before the next pointer. */
+ smp_store_release(&to->next, add);
+}
+
+/**
+ * bvecq_next - Get the next bvecq with appropriate barrier
+ * @bq: The bvecq to start from
+ *
+ * Return: The next bvecq in a chain, using an appropriate barrier to protect
+ * the access.
+ */
+static inline struct bvecq *bvecq_next(const struct bvecq *bq)
+{
+ /* Read the contents of the next node after the pointer to it. */
+ return smp_load_acquire(&bq->next);
+}
+
+#endif /* _LINUX_BVECQ_H */
diff --git a/include/linux/folio_queue.h b/include/linux/folio_queue.h
deleted file mode 100644
index f6d5f1f127c9f3..00000000000000
--- a/include/linux/folio_queue.h
+++ /dev/null
@@ -1,282 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/* Queue of folios definitions
- *
- * Copyright (C) 2024 Red Hat, Inc. All Rights Reserved.
- * Written by David Howells (dhowells@redhat.com)
- *
- * See:
- *
- * Documentation/core-api/folio_queue.rst
- *
- * for a description of the API.
- */
-
-#ifndef _LINUX_FOLIO_QUEUE_H
-#define _LINUX_FOLIO_QUEUE_H
-
-#include <linux/folio_batch.h>
-#include <linux/mm.h>
-
-/*
- * Segment in a queue of running buffers. Each segment can hold a number of
- * folios and a portion of the queue can be referenced with the ITER_FOLIOQ
- * iterator. The possibility exists of inserting non-folio elements into the
- * queue (such as gaps).
- *
- * Explicit prev and next pointers are used instead of a list_head to make it
- * easier to add segments to tail and remove them from the head without the
- * need for a lock.
- */
-struct folio_queue {
- struct folio_batch vec; /* Folios in the queue segment */
- u8 orders[FOLIO_BATCH_SIZE]; /* Order of each folio */
- struct folio_queue *next; /* Next queue segment or NULL */
- struct folio_queue *prev; /* Previous queue segment of NULL */
- unsigned long marks; /* 1-bit mark per folio */
- unsigned long marks2; /* Second 1-bit mark per folio */
-#if FOLIO_BATCH_SIZE > BITS_PER_LONG
-#error marks is not big enough
-#endif
- unsigned int rreq_id;
- unsigned int debug_id;
-};
-
-/**
- * folioq_init - Initialise a folio queue segment
- * @folioq: The segment to initialise
- * @rreq_id: The request identifier to use in tracelines.
- *
- * Initialise a folio queue segment and set an identifier to be used in traces.
- *
- * Note that the folio pointers are left uninitialised.
- */
-static inline void folioq_init(struct folio_queue *folioq, unsigned int rreq_id)
-{
- folio_batch_init(&folioq->vec);
- folioq->next = NULL;
- folioq->prev = NULL;
- folioq->marks = 0;
- folioq->marks2 = 0;
- folioq->rreq_id = rreq_id;
- folioq->debug_id = 0;
-}
-
-/**
- * folioq_nr_slots: Query the capacity of a folio queue segment
- * @folioq: The segment to query
- *
- * Query the number of folios that a particular folio queue segment might hold.
- * [!] NOTE: This must not be assumed to be the same for every segment!
- */
-static inline unsigned int folioq_nr_slots(const struct folio_queue *folioq)
-{
- return FOLIO_BATCH_SIZE;
-}
-
-/**
- * folioq_count: Query the occupancy of a folio queue segment
- * @folioq: The segment to query
- *
- * Query the number of folios that have been added to a folio queue segment.
- * Note that this is not decreased as folios are removed from a segment.
- */
-static inline unsigned int folioq_count(struct folio_queue *folioq)
-{
- return folio_batch_count(&folioq->vec);
-}
-
-/**
- * folioq_full: Query if a folio queue segment is full
- * @folioq: The segment to query
- *
- * Query if a folio queue segment is fully occupied. Note that this does not
- * change if folios are removed from a segment.
- */
-static inline bool folioq_full(struct folio_queue *folioq)
-{
- //return !folio_batch_space(&folioq->vec);
- return folioq_count(folioq) >= folioq_nr_slots(folioq);
-}
-
-/**
- * folioq_is_marked: Check first folio mark in a folio queue segment
- * @folioq: The segment to query
- * @slot: The slot number of the folio to query
- *
- * Determine if the first mark is set for the folio in the specified slot in a
- * folio queue segment.
- */
-static inline bool folioq_is_marked(const struct folio_queue *folioq, unsigned int slot)
-{
- return test_bit(slot, &folioq->marks);
-}
-
-/**
- * folioq_mark: Set the first mark on a folio in a folio queue segment
- * @folioq: The segment to modify
- * @slot: The slot number of the folio to modify
- *
- * Set the first mark for the folio in the specified slot in a folio queue
- * segment.
- */
-static inline void folioq_mark(struct folio_queue *folioq, unsigned int slot)
-{
- set_bit(slot, &folioq->marks);
-}
-
-/**
- * folioq_unmark: Clear the first mark on a folio in a folio queue segment
- * @folioq: The segment to modify
- * @slot: The slot number of the folio to modify
- *
- * Clear the first mark for the folio in the specified slot in a folio queue
- * segment.
- */
-static inline void folioq_unmark(struct folio_queue *folioq, unsigned int slot)
-{
- clear_bit(slot, &folioq->marks);
-}
-
-/**
- * folioq_is_marked2: Check second folio mark in a folio queue segment
- * @folioq: The segment to query
- * @slot: The slot number of the folio to query
- *
- * Determine if the second mark is set for the folio in the specified slot in a
- * folio queue segment.
- */
-static inline bool folioq_is_marked2(const struct folio_queue *folioq, unsigned int slot)
-{
- return test_bit(slot, &folioq->marks2);
-}
-
-/**
- * folioq_mark2: Set the second mark on a folio in a folio queue segment
- * @folioq: The segment to modify
- * @slot: The slot number of the folio to modify
- *
- * Set the second mark for the folio in the specified slot in a folio queue
- * segment.
- */
-static inline void folioq_mark2(struct folio_queue *folioq, unsigned int slot)
-{
- set_bit(slot, &folioq->marks2);
-}
-
-/**
- * folioq_unmark2: Clear the second mark on a folio in a folio queue segment
- * @folioq: The segment to modify
- * @slot: The slot number of the folio to modify
- *
- * Clear the second mark for the folio in the specified slot in a folio queue
- * segment.
- */
-static inline void folioq_unmark2(struct folio_queue *folioq, unsigned int slot)
-{
- clear_bit(slot, &folioq->marks2);
-}
-
-/**
- * folioq_append: Add a folio to a folio queue segment
- * @folioq: The segment to add to
- * @folio: The folio to add
- *
- * Add a folio to the tail of the sequence in a folio queue segment, increasing
- * the occupancy count and returning the slot number for the folio just added.
- * The folio size is extracted and stored in the queue and the marks are left
- * unmodified.
- *
- * Note that it's left up to the caller to check that the segment capacity will
- * not be exceeded and to extend the queue.
- */
-static inline unsigned int folioq_append(struct folio_queue *folioq, struct folio *folio)
-{
- unsigned int slot = folioq->vec.nr++;
-
- folioq->vec.folios[slot] = folio;
- folioq->orders[slot] = folio_order(folio);
- return slot;
-}
-
-/**
- * folioq_append_mark: Add a folio to a folio queue segment
- * @folioq: The segment to add to
- * @folio: The folio to add
- *
- * Add a folio to the tail of the sequence in a folio queue segment, increasing
- * the occupancy count and returning the slot number for the folio just added.
- * The folio size is extracted and stored in the queue, the first mark is set
- * and and the second and third marks are left unmodified.
- *
- * Note that it's left up to the caller to check that the segment capacity will
- * not be exceeded and to extend the queue.
- */
-static inline unsigned int folioq_append_mark(struct folio_queue *folioq, struct folio *folio)
-{
- unsigned int slot = folioq->vec.nr++;
-
- folioq->vec.folios[slot] = folio;
- folioq->orders[slot] = folio_order(folio);
- folioq_mark(folioq, slot);
- return slot;
-}
-
-/**
- * folioq_folio: Get a folio from a folio queue segment
- * @folioq: The segment to access
- * @slot: The folio slot to access
- *
- * Retrieve the folio in the specified slot from a folio queue segment. Note
- * that no bounds check is made and if the slot hasn't been added into yet, the
- * pointer will be undefined. If the slot has been cleared, NULL will be
- * returned.
- */
-static inline struct folio *folioq_folio(const struct folio_queue *folioq, unsigned int slot)
-{
- return folioq->vec.folios[slot];
-}
-
-/**
- * folioq_folio_order: Get the order of a folio from a folio queue segment
- * @folioq: The segment to access
- * @slot: The folio slot to access
- *
- * Retrieve the order of the folio in the specified slot from a folio queue
- * segment. Note that no bounds check is made and if the slot hasn't been
- * added into yet, the order returned will be 0.
- */
-static inline unsigned int folioq_folio_order(const struct folio_queue *folioq, unsigned int slot)
-{
- return folioq->orders[slot];
-}
-
-/**
- * folioq_folio_size: Get the size of a folio from a folio queue segment
- * @folioq: The segment to access
- * @slot: The folio slot to access
- *
- * Retrieve the size of the folio in the specified slot from a folio queue
- * segment. Note that no bounds check is made and if the slot hasn't been
- * added into yet, the size returned will be PAGE_SIZE.
- */
-static inline size_t folioq_folio_size(const struct folio_queue *folioq, unsigned int slot)
-{
- return PAGE_SIZE << folioq_folio_order(folioq, slot);
-}
-
-/**
- * folioq_clear: Clear a folio from a folio queue segment
- * @folioq: The segment to clear
- * @slot: The folio slot to clear
- *
- * Clear a folio from a sequence in a folio queue segment and clear its marks.
- * The occupancy count is left unchanged.
- */
-static inline void folioq_clear(struct folio_queue *folioq, unsigned int slot)
-{
- folioq->vec.folios[slot] = NULL;
- folioq_unmark(folioq, slot);
- folioq_unmark2(folioq, slot);
-}
-
-#endif /* _LINUX_FOLIO_QUEUE_H */
diff --git a/include/linux/iov_iter.h b/include/linux/iov_iter.h
index 2f91884d733bfd..e88930af7f3695 100644
--- a/include/linux/iov_iter.h
+++ b/include/linux/iov_iter.h
@@ -10,7 +10,7 @@
#include <linux/uio.h>
#include <linux/bvec.h>
-#include <linux/folio_queue.h>
+#include <linux/bvecq.h>
typedef size_t (*iov_step_f)(void *iter_base, size_t progress, size_t len,
void *priv, void *priv2);
@@ -142,56 +142,65 @@ size_t iterate_bvec(struct iov_iter *iter, size_t len, void *priv, void *priv2,
}
/*
- * Handle ITER_FOLIOQ.
+ * Handle ITER_BVECQ.
*/
static __always_inline
-size_t iterate_folioq(struct iov_iter *iter, size_t len, void *priv, void *priv2,
- iov_step_f step)
+size_t iterate_bvecq(struct iov_iter *iter, size_t len, void *priv, void *priv2,
+ iov_step_f step)
{
- const struct folio_queue *folioq = iter->folioq;
- unsigned int slot = iter->folioq_slot;
+ const struct bvecq *bq = iter->bvecq;
+ unsigned int slot = iter->bvecq_slot;
size_t progress = 0, skip = iter->iov_offset;
- if (slot == folioq_nr_slots(folioq)) {
- /* The iterator may have been extended. */
- folioq = folioq->next;
- slot = 0;
- }
-
do {
- struct folio *folio = folioq_folio(folioq, slot);
- size_t part, remain = 0, consumed;
- size_t fsize;
+ const struct bio_vec *bvec;
+ struct page *page;
+ size_t poff, plen;
void *base;
- if (!folio)
- break;
+ if (slot >= bq->nr_slots) {
+ if (!bq->next)
+ break;
+ bq = bq->next;
+ slot = 0;
+ continue;
+ }
+
+ bvec = &bq->bv[slot];
+ /*
+ * The caller must ensure that a slot with bv_len>0 has a valid
+ * bv_page.
+ */
+ page = bvec->bv_page + (bvec->bv_offset + skip) / PAGE_SIZE;
+ poff = (bvec->bv_offset + skip) % PAGE_SIZE;
+ plen = min(bvec->bv_len - skip, len);
+
+ while (plen > 0) {
+ size_t part, remain, consumed;
- fsize = folioq_folio_size(folioq, slot);
- if (skip < fsize) {
- base = kmap_local_folio(folio, skip);
- part = umin(len, PAGE_SIZE - skip % PAGE_SIZE);
+ part = min(plen, PAGE_SIZE - poff);
+ base = kmap_local_page(page) + poff;
remain = step(base, progress, part, priv, priv2);
kunmap_local(base);
+
consumed = part - remain;
- len -= consumed;
progress += consumed;
skip += consumed;
+ len -= consumed;
+ if (!len || remain)
+ goto stop;
+ page++;
+ poff = 0;
+ plen -= consumed;
}
- if (skip >= fsize) {
- skip = 0;
- slot++;
- if (slot == folioq_nr_slots(folioq) && folioq->next) {
- folioq = folioq->next;
- slot = 0;
- }
- }
- if (remain)
- break;
+
+ skip = 0;
+ slot++;
} while (len);
- iter->folioq_slot = slot;
- iter->folioq = folioq;
+stop:
+ iter->bvecq_slot = slot;
+ iter->bvecq = bq;
iter->iov_offset = skip;
iter->count -= progress;
return progress;
@@ -306,8 +315,8 @@ size_t iterate_and_advance2(struct iov_iter *iter, size_t len, void *priv,
return iterate_bvec(iter, len, priv, priv2, step);
if (iov_iter_is_kvec(iter))
return iterate_kvec(iter, len, priv, priv2, step);
- if (iov_iter_is_folioq(iter))
- return iterate_folioq(iter, len, priv, priv2, step);
+ if (iov_iter_is_bvecq(iter))
+ return iterate_bvecq(iter, len, priv, priv2, step);
if (iov_iter_is_xarray(iter))
return iterate_xarray(iter, len, priv, priv2, step);
if (WARN_ON_ONCE(iov_iter_is_dmabuf_map(iter)))
@@ -344,7 +353,7 @@ size_t iterate_and_advance(struct iov_iter *iter, size_t len, void *priv,
* buffer is presented in segments, which for kernel iteration are broken up by
* physical pages and mapped, with the mapped address being presented.
*
- * [!] Note This will only handle BVEC, KVEC, FOLIOQ, XARRAY and DISCARD-type
+ * [!] Note This will only handle BVEC, KVEC, BVECQ, XARRAY and DISCARD-type
* iterators; it will not handle UBUF or IOVEC-type iterators.
*
* A step functions, @step, must be provided, one for handling mapped kernel
@@ -372,8 +381,8 @@ size_t iterate_and_advance_kernel(struct iov_iter *iter, size_t len, void *priv,
return iterate_bvec(iter, len, priv, priv2, step);
if (iov_iter_is_kvec(iter))
return iterate_kvec(iter, len, priv, priv2, step);
- if (iov_iter_is_folioq(iter))
- return iterate_folioq(iter, len, priv, priv2, step);
+ if (iov_iter_is_bvecq(iter))
+ return iterate_bvecq(iter, len, priv, priv2, step);
if (iov_iter_is_xarray(iter))
return iterate_xarray(iter, len, priv, priv2, step);
return iterate_discard(iter, len, priv, priv2, step);
diff --git a/include/linux/netfs.h b/include/linux/netfs.h
index e5961450f3f154..ac6a4470b60fd1 100644
--- a/include/linux/netfs.h
+++ b/include/linux/netfs.h
@@ -17,13 +17,13 @@
#include <linux/workqueue.h>
#include <linux/fs.h>
#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 fscache_occupancy;
-struct folio_queue;
/**
* folio_start_private_2 - Start an fscache write on a folio. [DEPRECATED]
@@ -248,8 +248,6 @@ struct netfs_io_request {
#define NR_IO_STREAMS 2 //wreq->nr_io_streams
struct netfs_group *group; /* Writeback group being written back */
struct rolling_buffer buffer; /* Unencrypted buffer */
-#define NETFS_ROLLBUF_PUT_MARK ROLLBUF_MARK_1
-#define NETFS_ROLLBUF_PAGECACHE_MARK ROLLBUF_MARK_2
wait_queue_head_t waitq; /* Processor waiter */
void *netfs_priv; /* Private data for the netfs */
void *netfs_priv2; /* Private data for the netfs */
@@ -429,7 +427,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;
@@ -471,18 +469,6 @@ void netfs_end_io_write(struct inode *inode);
int netfs_start_io_direct(struct inode *inode);
void netfs_end_io_direct(struct inode *inode);
-/* Miscellaneous APIs. */
-struct folio_queue *netfs_folioq_alloc(unsigned int rreq_id, gfp_t gfp,
- unsigned int trace /*enum netfs_folioq_trace*/);
-void netfs_folioq_free(struct folio_queue *folioq,
- unsigned int trace /*enum netfs_trace_folioq*/);
-
-/* Buffer wrangling helpers API. */
-int netfs_alloc_folioq_buffer(struct address_space *mapping,
- struct folio_queue **_buffer,
- size_t *_cur_size, ssize_t size, gfp_t gfp);
-void netfs_free_folioq_buffer(struct folio_queue *fq);
-
/* Writeback exclusion API. */
bool netfs_wb_begin(struct netfs_inode *ictx, bool nowait);
void netfs_wb_end(struct netfs_inode *ictx);
diff --git a/include/linux/rolling_buffer.h b/include/linux/rolling_buffer.h
index a97f7cfaacaad7..5c0bc4221f010c 100644
--- a/include/linux/rolling_buffer.h
+++ b/include/linux/rolling_buffer.h
@@ -8,49 +8,35 @@
#ifndef _ROLLING_BUFFER_H
#define _ROLLING_BUFFER_H
-#include <linux/folio_queue.h>
+#include <linux/bvecq.h>
#include <linux/uio.h>
/*
- * Rolling buffer. Whilst the buffer is live and in use, folios and folio
- * queue 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 folio_queue in it so that neither side has to
- * modify both queue pointers.
+ * 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 folio_queue *head; /* Producer's insertion point */
- struct folio_queue *tail; /* Consumer's removal point */
+ 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 next_head_slot; /* Next slot in ->head */
u8 first_tail_slot; /* First slot in ->tail */
+ bool for_writeback; /* T if being used for writeback */
};
-/*
- * Snapshot of a rolling buffer.
- */
-struct rolling_buffer_snapshot {
- struct folio_queue *curr_folioq; /* Queue segment in which current folio resides */
- unsigned char curr_slot; /* Folio currently being read */
- unsigned char curr_order; /* Order of folio */
-};
-
-/* Marks to store per-folio in the internal folio_queue structs. */
-#define ROLLBUF_MARK_1 BIT(0)
-#define ROLLBUF_MARK_2 BIT(1)
-
-int rolling_buffer_init(struct rolling_buffer *roll, unsigned int rreq_id,
- unsigned int direction, gfp_t gfp);
+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,
- unsigned int rreq_id, gfp_t gfp);
-ssize_t rolling_buffer_append(struct rolling_buffer *roll, struct folio *folio,
- unsigned int flags, gfp_t gfp);
-struct folio_queue *rolling_buffer_delete_spent(struct rolling_buffer *roll);
+ 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)
diff --git a/include/linux/uio.h b/include/linux/uio.h
index 638c1116e912e7..3fc98542922e31 100644
--- a/include/linux/uio.h
+++ b/include/linux/uio.h
@@ -11,7 +11,6 @@
#include <uapi/linux/uio.h>
struct page;
-struct folio_queue;
struct dma_buf_io_map;
typedef unsigned int __bitwise iov_iter_extraction_t;
@@ -27,7 +26,7 @@ enum iter_type {
ITER_IOVEC,
ITER_BVEC,
ITER_KVEC,
- ITER_FOLIOQ,
+ ITER_BVECQ,
ITER_XARRAY,
ITER_DISCARD,
ITER_DMABUF_MAP,
@@ -70,7 +69,7 @@ struct iov_iter {
const struct iovec *__iov;
const struct kvec *kvec;
const struct bio_vec *bvec;
- const struct folio_queue *folioq;
+ const struct bvecq *bvecq;
struct xarray *xarray;
void __user *ubuf;
struct dma_buf_io_map *dmabuf_map;
@@ -80,7 +79,7 @@ struct iov_iter {
};
union {
unsigned long nr_segs;
- u8 folioq_slot;
+ u16 bvecq_slot;
loff_t xarray_start;
};
};
@@ -148,9 +147,9 @@ static inline bool iov_iter_is_discard(const struct iov_iter *i)
return iov_iter_type(i) == ITER_DISCARD;
}
-static inline bool iov_iter_is_folioq(const struct iov_iter *i)
+static inline bool iov_iter_is_bvecq(const struct iov_iter *i)
{
- return iov_iter_type(i) == ITER_FOLIOQ;
+ return iov_iter_type(i) == ITER_BVECQ;
}
static inline bool iov_iter_is_xarray(const struct iov_iter *i)
@@ -303,9 +302,9 @@ void iov_iter_kvec(struct iov_iter *i, unsigned int direction, const struct kvec
void iov_iter_bvec(struct iov_iter *i, unsigned int direction, const struct bio_vec *bvec,
unsigned long nr_segs, size_t count);
void iov_iter_discard(struct iov_iter *i, unsigned int direction, size_t count);
-void iov_iter_folio_queue(struct iov_iter *i, unsigned int direction,
- const struct folio_queue *folioq,
- unsigned int first_slot, unsigned int offset, size_t count);
+void iov_iter_bvec_queue(struct iov_iter *i, unsigned int direction,
+ const struct bvecq *bvecq,
+ unsigned int first_slot, unsigned int offset, size_t count);
void iov_iter_xarray(struct iov_iter *i, unsigned int direction, struct xarray *xarray,
loff_t start, size_t count);
void iov_iter_dmabuf_map(struct iov_iter *i, unsigned int direction,
diff --git a/include/trace/events/netfs.h b/include/trace/events/netfs.h
index bf1e1f185b05c4..e80c27c49ce259 100644
--- a/include/trace/events/netfs.h
+++ b/include/trace/events/netfs.h
@@ -199,7 +199,6 @@
EM(netfs_streaming_filled_page, "mod-streamw-f") \
EM(netfs_streaming_cont_filled_page, "mod-streamw-f+") \
EM(netfs_folio_trace_abandon, "abandon") \
- EM(netfs_folio_trace_alloc_buffer, "alloc-buf") \
EM(netfs_folio_trace_cancel_copy, "cancel-copy") \
EM(netfs_folio_trace_cancel_store, "cancel-store") \
EM(netfs_folio_trace_end_copy, "end-copy") \
@@ -222,7 +221,6 @@
EM(netfs_folio_trace_not_locked, "!locked") \
EM(netfs_folio_trace_not_under_wback, "!wback") \
EM(netfs_folio_trace_pgpriv2_copy, "pgpriv2-copy") \
- EM(netfs_folio_trace_put, "put") \
EM(netfs_folio_trace_read, "read") \
EM(netfs_folio_trace_read_done, "read-done") \
EM(netfs_folio_trace_read_gaps, "read-gaps") \
@@ -244,14 +242,6 @@
EM(netfs_trace_donate_to_next, "to-next") \
E_(netfs_trace_donate_to_deferred_next, "defer-next")
-#define netfs_folioq_traces \
- EM(netfs_trace_folioq_alloc_buffer, "alloc-buf") \
- EM(netfs_trace_folioq_clear, "clear") \
- EM(netfs_trace_folioq_delete, "delete") \
- EM(netfs_trace_folioq_make_space, "make-space") \
- EM(netfs_trace_folioq_rollbuf_init, "roll-init") \
- E_(netfs_trace_folioq_read_progress, "r-progress")
-
#ifndef __NETFS_DECLARE_TRACE_ENUMS_ONCE_ONLY
#define __NETFS_DECLARE_TRACE_ENUMS_ONCE_ONLY
@@ -270,7 +260,6 @@ enum netfs_sreq_ref_trace { netfs_sreq_ref_traces } __mode(byte);
enum netfs_folio_trace { netfs_folio_traces } __mode(byte);
enum netfs_collect_contig_trace { netfs_collect_contig_traces } __mode(byte);
enum netfs_donate_trace { netfs_donate_traces } __mode(byte);
-enum netfs_folioq_trace { netfs_folioq_traces } __mode(byte);
#endif
@@ -294,7 +283,6 @@ netfs_sreq_ref_traces;
netfs_folio_traces;
netfs_collect_contig_traces;
netfs_donate_traces;
-netfs_folioq_traces;
/*
* Now redefine the EM() and E_() macros to map the enums to the strings that
@@ -398,7 +386,7 @@ TRACE_EVENT(netfs_sreq,
__entry->len = sreq->len;
__entry->transferred = sreq->transferred;
__entry->start = sreq->start;
- __entry->slot = sreq->io_iter.folioq_slot;
+ __entry->slot = sreq->io_iter.bvecq_slot;
),
TP_printk("R=%08x[%x] %s %s f=%03x s=%llx %zx/%zx s=%u e=%d",
@@ -773,29 +761,6 @@ TRACE_EVENT(netfs_collect_stream,
__entry->collected_to, __entry->issued_to)
);
-TRACE_EVENT(netfs_folioq,
- TP_PROTO(const struct folio_queue *fq,
- enum netfs_folioq_trace trace),
-
- TP_ARGS(fq, trace),
-
- TP_STRUCT__entry(
- __field(unsigned int, rreq)
- __field(unsigned int, id)
- __field(enum netfs_folioq_trace, trace)
- ),
-
- TP_fast_assign(
- __entry->rreq = fq ? fq->rreq_id : 0;
- __entry->id = fq ? fq->debug_id : 0;
- __entry->trace = trace;
- ),
-
- TP_printk("R=%08x fq=%x %s",
- __entry->rreq, __entry->id,
- __print_symbolic(__entry->trace, netfs_folioq_traces))
- );
-
TRACE_EVENT(netfs_read_progress_at,
TP_PROTO(const struct netfs_io_request *rreq),
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 1be30487a2fa75..0fca0c3132fe29 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -7344,8 +7344,6 @@ static const struct bpf_raw_tp_null_args raw_tp_null_args[] = {
/* amdgpu */
{ "amdgpu_vm_bo_map", 0x1 },
{ "amdgpu_vm_bo_unmap", 0x1 },
- /* netfs */
- { "netfs_folioq", 0x1 },
/* xfs from xfs_defer_pending_class */
{ "xfs_defer_create_intent", 0x1 },
{ "xfs_defer_cancel_list", 0x1 },
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 2d22638ec13a63..06b4546421a13e 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2385,6 +2385,19 @@ config TEST_IOV_ITER
If unsure, say N.
+config TEST_BVECQ
+ tristate "Test bvecq operation" if !KUNIT_ALL_TESTS
+ depends on KUNIT
+ depends on MMU
+ depends on NETFS_SUPPORT
+ default KUNIT_ALL_TESTS
+ help
+ Enable this to turn on testing of the operation of the bvecq
+ structure. This test is executed only once during system
+ boot (so affects only boot time), or at module load time.
+
+ If unsure, say N.
+
config KPROBES_SANITY_TEST
tristate "Kprobes sanity tests" if !KUNIT_ALL_TESTS
depends on DEBUG_KERNEL
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index fa4fe2e9238316..55525962a1d6dc 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -538,37 +538,38 @@ static void iov_iter_iovec_advance(struct iov_iter *i, size_t size)
i->__iov = iov;
}
-static void iov_iter_folioq_advance(struct iov_iter *i, size_t size)
+static void iov_iter_bvecq_advance(struct iov_iter *i, size_t by)
{
- const struct folio_queue *folioq = i->folioq;
- unsigned int slot = i->folioq_slot;
+ const struct bvecq *bq = i->bvecq;
+ unsigned int slot = i->bvecq_slot;
if (!i->count)
return;
- i->count -= size;
-
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = folioq->next;
- slot = 0;
- }
+ i->count -= by;
- size += i->iov_offset; /* From beginning of current segment. */
+ by += i->iov_offset; /* From beginning of current segment. */
do {
- size_t fsize = folioq_folio_size(folioq, slot);
+ size_t len;
- if (likely(size < fsize))
- break;
- size -= fsize;
- slot++;
- if (slot >= folioq_nr_slots(folioq) && folioq->next) {
- folioq = folioq->next;
+ if (slot >= bq->nr_slots) {
+ if (!bq->next)
+ break;
+ bq = bq->next;
slot = 0;
+ continue;
}
- } while (size);
- i->iov_offset = size;
- i->folioq_slot = slot;
- i->folioq = folioq;
+ len = bq->bv[slot].bv_len;
+
+ if (likely(by < len))
+ break;
+ by -= len;
+ slot++;
+ } while (by);
+
+ i->iov_offset = by;
+ i->bvecq_slot = slot;
+ i->bvecq = bq;
}
void iov_iter_advance(struct iov_iter *i, size_t size)
@@ -584,38 +585,39 @@ void iov_iter_advance(struct iov_iter *i, size_t size)
iov_iter_iovec_advance(i, size);
} else if (iov_iter_is_bvec(i)) {
iov_iter_bvec_advance(i, size);
- } else if (iov_iter_is_folioq(i)) {
- iov_iter_folioq_advance(i, size);
+ } else if (iov_iter_is_bvecq(i)) {
+ iov_iter_bvecq_advance(i, size);
} else if (iov_iter_is_discard(i)) {
i->count -= size;
}
}
EXPORT_SYMBOL(iov_iter_advance);
-static void iov_iter_folioq_revert(struct iov_iter *i, size_t unroll)
+static void iov_iter_bvecq_revert(struct iov_iter *i, size_t unroll)
{
- const struct folio_queue *folioq = i->folioq;
- unsigned int slot = i->folioq_slot;
+ const struct bvecq *bq = i->bvecq;
+ unsigned int slot = i->bvecq_slot;
for (;;) {
- size_t fsize;
+ size_t len;
if (slot == 0) {
- folioq = folioq->prev;
- slot = folioq_nr_slots(folioq);
+ bq = bq->prev;
+ slot = bq->nr_slots;
+ continue;
}
slot--;
- fsize = folioq_folio_size(folioq, slot);
- if (unroll <= fsize) {
- i->iov_offset = fsize - unroll;
+ len = bq->bv[slot].bv_len;
+ if (unroll <= len) {
+ i->iov_offset = len - unroll;
break;
}
- unroll -= fsize;
+ unroll -= len;
}
- i->folioq_slot = slot;
- i->folioq = folioq;
+ i->bvecq_slot = slot;
+ i->bvecq = bq;
}
void iov_iter_revert(struct iov_iter *i, size_t unroll)
@@ -650,9 +652,9 @@ void iov_iter_revert(struct iov_iter *i, size_t unroll)
}
unroll -= n;
}
- } else if (iov_iter_is_folioq(i)) {
+ } else if (iov_iter_is_bvecq(i)) {
i->iov_offset = 0;
- iov_iter_folioq_revert(i, unroll);
+ iov_iter_bvecq_revert(i, unroll);
} else { /* same logics for iovec and kvec */
const struct iovec *iov = iter_iov(i);
while (1) {
@@ -680,9 +682,28 @@ size_t iov_iter_single_seg_count(const struct iov_iter *i)
if (iov_iter_is_bvec(i))
return min(i->count, i->bvec->bv_len - i->iov_offset);
}
- if (unlikely(iov_iter_is_folioq(i)))
- return !i->count ? 0 :
- umin(folioq_folio_size(i->folioq, i->folioq_slot), i->count);
+ if (!i->count)
+ return 0;
+ if (unlikely(iov_iter_is_bvecq(i))) {
+ const struct bvecq *bq = i->bvecq;
+ unsigned int slot = i->bvecq_slot;
+ size_t offset = i->iov_offset;
+
+ for (;;) {
+ while (slot >= bq->nr_slots) {
+ bq = bq->next;
+ if (!bq)
+ return 0;
+ slot = 0;
+ offset = 0;
+ }
+ if (bq->bv[slot].bv_len > offset)
+ break;
+ slot++;
+ offset = 0;
+ }
+ return min(i->count, bq->bv[slot].bv_len - offset);
+ }
return i->count;
}
EXPORT_SYMBOL(iov_iter_single_seg_count);
@@ -720,34 +741,34 @@ void iov_iter_bvec(struct iov_iter *i, unsigned int direction,
EXPORT_SYMBOL(iov_iter_bvec);
/**
- * iov_iter_folio_queue - Initialise an I/O iterator to use the folios in a folio queue
+ * iov_iter_bvec_queue - Initialise an I/O iterator to use a segmented bvec queue
* @i: The iterator to initialise.
* @direction: The direction of the transfer.
- * @folioq: The starting point in the folio queue.
- * @first_slot: The first slot in the folio queue to use
- * @offset: The offset into the folio in the first slot to start at
+ * @bvecq: The starting point in the bvec queue.
+ * @first_slot: The first slot in the bvec queue to use
+ * @offset: The offset into the bvec in the first slot to start at
* @count: The size of the I/O buffer in bytes.
*
- * Set up an I/O iterator to either draw data out of the pages attached to an
- * inode or to inject data into those pages. The pages *must* be prevented
- * from evaporation, either by taking a ref on them or locking them by the
- * caller.
+ * Set up an I/O iterator to either draw data out of the buffers attached to an
+ * inode or to inject data into those buffers. The pages *must* be prevented
+ * from evaporation by the caller, by taking a ref or a lock on them or by
+ * cleaning them up after the I/O is complete.
*/
-void iov_iter_folio_queue(struct iov_iter *i, unsigned int direction,
- const struct folio_queue *folioq, unsigned int first_slot,
- unsigned int offset, size_t count)
+void iov_iter_bvec_queue(struct iov_iter *i, unsigned int direction,
+ const struct bvecq *bvecq, unsigned int first_slot,
+ unsigned int offset, size_t count)
{
- BUG_ON(direction & ~1);
+ WARN_ON(direction & ~(READ | WRITE));
*i = (struct iov_iter) {
- .iter_type = ITER_FOLIOQ,
- .data_source = direction,
- .folioq = folioq,
- .folioq_slot = first_slot,
- .count = count,
- .iov_offset = offset,
+ .iter_type = ITER_BVECQ,
+ .data_source = direction,
+ .bvecq = bvecq,
+ .bvecq_slot = first_slot,
+ .count = count,
+ .iov_offset = offset,
};
}
-EXPORT_SYMBOL(iov_iter_folio_queue);
+EXPORT_SYMBOL(iov_iter_bvec_queue);
/**
* iov_iter_xarray - Initialise an I/O iterator to use the pages in an xarray
@@ -855,6 +876,39 @@ static unsigned long iov_iter_alignment_bvec(const struct iov_iter *i)
return res;
}
+static unsigned long iov_iter_alignment_bvecq(const struct iov_iter *iter)
+{
+ const struct bvecq *bq;
+ unsigned long res = 0;
+ unsigned int slot = iter->bvecq_slot;
+ size_t skip = iter->iov_offset;
+ size_t size = iter->count;
+
+ if (!size)
+ return res;
+
+ for (bq = iter->bvecq; bq; bq = bq->next) {
+ for (; slot < bq->nr_slots; slot++) {
+ const struct bio_vec *bvec = &bq->bv[slot];
+ size_t part = min(bvec->bv_len - skip, size);
+
+ if (part) {
+ res |= bvec->bv_offset + skip;
+ res |= part;
+ }
+
+ size -= part;
+ if (size == 0)
+ return res;
+ skip = 0;
+ }
+
+ slot = 0;
+ }
+
+ return res;
+}
+
unsigned long iov_iter_alignment(const struct iov_iter *i)
{
if (likely(iter_is_ubuf(i))) {
@@ -874,9 +928,11 @@ unsigned long iov_iter_alignment(const struct iov_iter *i)
if (iov_iter_is_bvec(i))
return iov_iter_alignment_bvec(i);
+ if (iov_iter_is_bvecq(i))
+ return iov_iter_alignment_bvecq(i);
- /* With both xarray and folioq types, we're dealing with whole folios. */
- if (iov_iter_is_folioq(i) || iov_iter_is_dmabuf_map(i))
+ /* With the xarray type, we're dealing with whole folios. */
+ if (iov_iter_is_dmabuf_map(i))
return i->iov_offset | i->count;
if (iov_iter_is_xarray(i))
return (i->xarray_start + i->iov_offset) | i->count;
@@ -930,62 +986,158 @@ static int want_pages_array(struct page ***res, size_t size,
return count;
}
-static ssize_t iter_folioq_get_pages(struct iov_iter *iter,
- struct page ***ppages, size_t maxsize,
- unsigned maxpages, size_t *_start_offset)
+/*
+ * Count the number of virtually contiguous pages coming up next in an
+ * ITER_BVECQ iterator, up to the specified maxima.
+ */
+static unsigned int iter_count_bvecq_pages(const struct iov_iter *iter,
+ size_t maxsize,
+ unsigned int maxpages)
{
- const struct folio_queue *folioq = iter->folioq;
+ const struct bvecq *bvecq = iter->bvecq;
+ unsigned int slot = iter->bvecq_slot;
+ ssize_t remain = umin(maxsize, iter->count);
+ size_t count = 0, offset = iter->iov_offset;
+
+ do {
+ const struct bio_vec *bv;
+ size_t boff, blen;
+
+ if (slot >= bvecq->nr_slots) {
+ if (!bvecq->next) {
+ WARN_ON_ONCE(remain > 0);
+ break;
+ }
+ bvecq = bvecq->next;
+ slot = 0;
+ offset = 0;
+ continue;
+ }
+
+ bv = &bvecq->bv[slot++];
+ boff = bv->bv_offset;
+ blen = bv->bv_len;
+
+ /* bv_page is not allowed to be NULL unless bv_len == 0. */
+ if (WARN_ON_ONCE(!bv->bv_page && blen > 0))
+ break;
+ if (!PAGE_ALIGNED(boff) && count > 0)
+ break;
+
+ boff += offset;
+ blen -= offset;
+ offset = 0;
+ if (!blen)
+ continue;
+
+ blen = umin(blen, remain);
+ remain -= blen;
+ blen += offset_in_page(boff);
+ count += DIV_ROUND_UP(blen, PAGE_SIZE);
+
+ if (!PAGE_ALIGNED(blen))
+ break;
+ } while (remain > 0 && count < maxpages);
+
+ return min(count, maxpages);
+}
+
+/*
+ * Get a list of virtually contiguous pages from an ITER_BVECQ iterator and pin
+ * them.
+ */
+static ssize_t iter_bvecq_get_pages(struct iov_iter *iter,
+ struct page ***ppages, size_t maxsize,
+ unsigned int maxpages, size_t *_start_offset)
+{
+ const struct bvecq *bvecq = iter->bvecq;
struct page **pages;
- unsigned int slot = iter->folioq_slot;
- size_t extracted = 0, count = iter->count, iov_offset = iter->iov_offset;
+ unsigned int slot = iter->bvecq_slot, nr = 0;
+ size_t extracted = 0, offset = iter->iov_offset;
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = folioq->next;
- slot = 0;
- if (WARN_ON(iov_offset != 0))
- return -EIO;
+ for (;;) {
+ if (slot >= bvecq->nr_slots) {
+ if (!bvecq->next)
+ return 0;
+ bvecq = bvecq->next;
+ slot = 0;
+ offset = 0;
+ continue;
+ }
+ if (offset >= bvecq->bv[slot].bv_len) {
+ slot++;
+ offset = 0;
+ continue;
+ }
+ break;
}
- maxpages = want_pages_array(ppages, maxsize, iov_offset & ~PAGE_MASK, maxpages);
+ /* Count the next run of virtually contiguous pages. */
+ maxpages = iter_count_bvecq_pages(iter, maxsize, maxpages);
+ if (!maxpages)
+ return 0;
+
+ maxpages = want_pages_array(ppages, maxsize,
+ (bvecq->bv[slot].bv_offset + offset) & ~PAGE_MASK,
+ maxpages);
if (!maxpages)
return -ENOMEM;
- *_start_offset = iov_offset & ~PAGE_MASK;
pages = *ppages;
- for (;;) {
- struct folio *folio = folioq_folio(folioq, slot);
- size_t offset = iov_offset, fsize = folioq_folio_size(folioq, slot);
- size_t part = PAGE_SIZE - offset % PAGE_SIZE;
-
- if (offset < fsize) {
- part = umin(part, umin(maxsize - extracted, fsize - offset));
- count -= part;
- iov_offset += part;
- extracted += part;
+ /* Now transcribe the page pointers. */
+ do {
+ const struct bio_vec *bv;
+ size_t boff, blen;
- *pages = folio_page(folio, offset / PAGE_SIZE);
- get_page(*pages);
- pages++;
- maxpages--;
+ if (slot >= bvecq->nr_slots) {
+ if (!bvecq->next) {
+ WARN_ON_ONCE(extracted < iter->count);
+ break;
+ }
+ bvecq = bvecq->next;
+ slot = 0;
+ offset = 0;
+ continue;
}
- if (maxpages == 0 || extracted >= maxsize)
- break;
+ bv = &bvecq->bv[slot];
+ boff = bv->bv_offset;
+ blen = bv->bv_len;
+
+ /* bv_page is not allowed to be NULL unless bv_len == 0. */
+
+ if (offset < blen) {
+ struct folio *folio;
+ size_t poff = (boff + offset) % PAGE_SIZE;
+ size_t part = min(maxsize - extracted, blen - offset);
+ size_t pix = (boff + offset) / PAGE_SIZE;
+
+ if (poff + part > PAGE_SIZE)
+ part = PAGE_SIZE - poff;
+
+ if (!extracted)
+ *_start_offset = poff;
+
+ /* Get a ref on the page if it's not a slab page. */
+ folio = page_folio(bv->bv_page + pix);
+ if (!folio_test_slab(folio))
+ folio_get(folio);
+
+ pages[nr++] = bv->bv_page + pix;
+ offset += part;
+ extracted += part;
+ }
- if (iov_offset >= fsize) {
- iov_offset = 0;
+ if (offset >= blen) {
+ offset = 0;
slot++;
- if (slot == folioq_nr_slots(folioq) && folioq->next) {
- folioq = folioq->next;
- slot = 0;
- }
}
- }
+ } while (nr < maxpages && extracted < maxsize);
- iter->count = count;
- iter->iov_offset = iov_offset;
- iter->folioq = folioq;
- iter->folioq_slot = slot;
+ iter->bvecq = bvecq;
+ iter->bvecq_slot = slot;
+ iter->iov_offset = offset;
+ iter->count -= extracted;
return extracted;
}
@@ -1140,8 +1292,8 @@ static ssize_t __iov_iter_get_pages_alloc(struct iov_iter *i,
}
return maxsize;
}
- if (iov_iter_is_folioq(i))
- return iter_folioq_get_pages(i, pages, maxsize, maxpages, start);
+ if (iov_iter_is_bvecq(i))
+ return iter_bvecq_get_pages(i, pages, maxsize, maxpages, start);
if (iov_iter_is_xarray(i))
return iter_xarray_get_pages(i, pages, maxsize, maxpages, start);
return -EFAULT;
@@ -1212,6 +1364,38 @@ static int bvec_npages(const struct iov_iter *i, int maxpages)
return npages;
}
+static size_t iov_npages_bvecq(const struct iov_iter *iter, size_t maxpages)
+{
+ const struct bvecq *bq;
+ unsigned int slot = iter->bvecq_slot;
+ size_t npages = 0;
+ size_t skip = iter->iov_offset;
+ size_t size = iter->count;
+
+ for (bq = iter->bvecq; bq; bq = bq->next) {
+ for (; slot < bq->nr_slots; slot++) {
+ const struct bio_vec *bvec = &bq->bv[slot];
+ size_t offs = (bvec->bv_offset + skip) % PAGE_SIZE;
+ size_t part = min(bvec->bv_len - skip, size);
+
+ if (part) {
+ npages += DIV_ROUND_UP(offs + part, PAGE_SIZE);
+ if (npages >= maxpages)
+ goto out;
+ }
+
+ size -= part;
+ if (!size)
+ goto out;
+ skip = 0;
+ }
+
+ slot = 0;
+ }
+out:
+ return umin(npages, maxpages);
+}
+
int iov_iter_npages(const struct iov_iter *i, int maxpages)
{
if (unlikely(!i->count))
@@ -1226,11 +1410,8 @@ int iov_iter_npages(const struct iov_iter *i, int maxpages)
return iov_npages(i, maxpages);
if (iov_iter_is_bvec(i))
return bvec_npages(i, maxpages);
- if (iov_iter_is_folioq(i)) {
- unsigned offset = i->iov_offset % PAGE_SIZE;
- int npages = DIV_ROUND_UP(offset + i->count, PAGE_SIZE);
- return min(npages, maxpages);
- }
+ if (iov_iter_is_bvecq(i))
+ return iov_npages_bvecq(i, maxpages);
if (iov_iter_is_xarray(i)) {
unsigned offset = (i->xarray_start + i->iov_offset) % PAGE_SIZE;
int npages = DIV_ROUND_UP(offset + i->count, PAGE_SIZE);
@@ -1515,64 +1696,86 @@ void iov_iter_restore(struct iov_iter *i, struct iov_iter_state *state)
EXPORT_SYMBOL_FOR_MODULES(iov_iter_restore, "vmw_vsock_virtio_transport_common");
/*
- * Extract a list of contiguous pages from an ITER_FOLIOQ iterator. This does
- * not get references on the pages, nor does it get a pin on them.
+ * Extract a list of virtually contiguous pages from an ITER_BVECQ iterator.
+ * This does not get references on the pages, nor does it get a pin on them.
*/
-static ssize_t iov_iter_extract_folioq_pages(struct iov_iter *i,
- struct page ***pages, size_t maxsize,
- unsigned int maxpages,
- iov_iter_extraction_t extraction_flags,
- size_t *offset0)
+static ssize_t iov_iter_extract_bvecq_pages(struct iov_iter *iter,
+ struct page ***pages, size_t maxsize,
+ unsigned int maxpages,
+ iov_iter_extraction_t extraction_flags,
+ size_t *offset0)
{
- const struct folio_queue *folioq = i->folioq;
+ const struct bvecq *bvecq;
struct page **p;
- unsigned int nr = 0;
- size_t extracted = 0, offset, slot = i->folioq_slot;
+ unsigned int slot, nr = 0;
+ size_t extracted = 0, offset;
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = folioq->next;
- slot = 0;
- if (WARN_ON(i->iov_offset != 0))
- return -EIO;
- }
+ /* Count the next run of virtually contiguous pages. */
+ maxpages = iter_count_bvecq_pages(iter, maxsize, maxpages);
+ if (!maxpages)
+ return 0;
- offset = i->iov_offset & ~PAGE_MASK;
- *offset0 = offset;
+ if (!*pages) {
+ *pages = kvmalloc_array(maxpages, sizeof(struct page *), GFP_KERNEL);
+ if (!*pages)
+ return -ENOMEM;
+ }
- maxpages = want_pages_array(pages, maxsize, offset, maxpages);
- if (!maxpages)
- return -ENOMEM;
p = *pages;
- for (;;) {
- struct folio *folio = folioq_folio(folioq, slot);
- size_t offset = i->iov_offset, fsize = folioq_folio_size(folioq, slot);
- size_t part = PAGE_SIZE - offset % PAGE_SIZE;
-
- if (offset < fsize) {
- part = umin(part, umin(maxsize - extracted, fsize - offset));
- i->count -= part;
- i->iov_offset += part;
- extracted += part;
+ /* Now transcribe the page pointers. */
+ extracted = 0;
+ bvecq = iter->bvecq;
+ offset = iter->iov_offset;
+ slot = iter->bvecq_slot;
+
+ do {
+ const struct bio_vec *bv;
+ size_t boff, blen;
- p[nr++] = folio_page(folio, offset / PAGE_SIZE);
+ if (slot >= bvecq->nr_slots) {
+ if (!bvecq->next) {
+ WARN_ON_ONCE(extracted < iter->count);
+ break;
+ }
+ bvecq = bvecq->next;
+ slot = 0;
+ offset = 0;
+ continue;
}
- if (nr >= maxpages || extracted >= maxsize)
- break;
+ bv = &bvecq->bv[slot];
+ boff = bv->bv_offset;
+ blen = bv->bv_len;
- if (i->iov_offset >= fsize) {
- i->iov_offset = 0;
+ /* bv_page is not allowed to be NULL unless bv_len == 0. */
+
+ if (offset < blen) {
+ size_t part = umin(maxsize - extracted, blen - offset);
+ size_t poff = (boff + offset) % PAGE_SIZE;
+ size_t pix = (boff + offset) / PAGE_SIZE;
+
+ if (poff + part > PAGE_SIZE)
+ part = PAGE_SIZE - poff;
+
+ if (!extracted)
+ *offset0 = poff;
+
+ p[nr++] = bv->bv_page + pix;
+ offset += part;
+ extracted += part;
+ }
+
+ if (offset >= blen) {
+ offset = 0;
slot++;
- if (slot == folioq_nr_slots(folioq) && folioq->next) {
- folioq = folioq->next;
- slot = 0;
- }
}
- }
+ } while (nr < maxpages && extracted < maxsize);
- i->folioq = folioq;
- i->folioq_slot = slot;
+ iter->bvecq = bvecq;
+ iter->bvecq_slot = slot;
+ iter->iov_offset = offset;
+ iter->count -= extracted;
return extracted;
}
@@ -1838,8 +2041,8 @@ static ssize_t iov_iter_extract_user_pages(struct iov_iter *i,
* added to the pages, but refs will not be taken.
* iov_iter_extract_will_pin() will return true.
*
- * (*) If the iterator is ITER_KVEC, ITER_BVEC, ITER_FOLIOQ or ITER_XARRAY, the
- * pages are merely listed; no extra refs or pins are obtained.
+ * (*) If the iterator is ITER_KVEC, ITER_BVEC, ITER_XARRAY, the pages are
+ * merely listed; no extra refs or pins are obtained.
* iov_iter_extract_will_pin() will return 0.
*
* Note also:
@@ -1874,10 +2077,10 @@ ssize_t iov_iter_extract_pages(struct iov_iter *i,
return iov_iter_extract_bvec_pages(i, pages, maxsize,
maxpages, extraction_flags,
offset0);
- if (iov_iter_is_folioq(i))
- return iov_iter_extract_folioq_pages(i, pages, maxsize,
- maxpages, extraction_flags,
- offset0);
+ if (iov_iter_is_bvecq(i))
+ return iov_iter_extract_bvecq_pages(i, pages, maxsize,
+ maxpages, extraction_flags,
+ offset0);
if (iov_iter_is_xarray(i))
return iov_iter_extract_xarray_pages(i, pages, maxsize,
maxpages, extraction_flags,
diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index 6ea40d2e624755..b9a7298306d95d 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -10,8 +10,8 @@
#include <linux/highmem.h>
#include <linux/kmemleak.h>
#include <linux/bvec.h>
+#include <linux/bvecq.h>
#include <linux/uio.h>
-#include <linux/folio_queue.h>
/**
* sg_nents - return total count of entries in scatterlist
@@ -1268,61 +1268,59 @@ static ssize_t extract_kvec_to_sg(struct iov_iter *iter,
}
/*
- * Extract up to sg_max folios from an FOLIOQ-type iterator and add them to
+ * Extract up to sg_max folios from an BVECQ-type iterator and add them to
* the scatterlist. The pages are not pinned.
*/
-static ssize_t extract_folioq_to_sg(struct iov_iter *iter,
+static ssize_t extract_bvecq_to_sg(struct iov_iter *iter,
ssize_t maxsize,
struct sg_table *sgtable,
unsigned int sg_max,
iov_iter_extraction_t extraction_flags)
{
- const struct folio_queue *folioq = iter->folioq;
+ const struct bvecq *bvecq = iter->bvecq;
struct scatterlist *sg = sgtable->sgl + sgtable->nents;
- unsigned int slot = iter->folioq_slot;
+ unsigned int slot = iter->bvecq_slot;
ssize_t ret = 0;
size_t offset = iter->iov_offset;
- BUG_ON(!folioq);
+ maxsize = umin(maxsize, iov_iter_count(iter));
- if (slot >= folioq_nr_slots(folioq)) {
- folioq = folioq->next;
- if (WARN_ON_ONCE(!folioq))
- return 0;
- slot = 0;
- }
-
- do {
- struct folio *folio = folioq_folio(folioq, slot);
- size_t fsize = folioq_folio_size(folioq, slot);
+ while (sg_max > 0 && ret < maxsize) {
+ const struct bio_vec *bv;
+ size_t blen, part;
- if (offset < fsize) {
- size_t part = umin(maxsize - ret, fsize - offset);
-
- sg_set_page(sg, folio_page(folio, 0), part, offset);
- sgtable->nents++;
- sg++;
- sg_max--;
- offset += part;
- ret += part;
+ if (slot >= bvecq->nr_slots) {
+ if (!bvecq->next) {
+ WARN_ON_ONCE(ret < iter->count);
+ break;
+ }
+ bvecq = bvecq->next;
+ slot = 0;
+ offset = 0;
+ continue;
}
- if (offset >= fsize) {
+ bv = &bvecq->bv[slot];
+ blen = bv->bv_len;
+
+ if (offset >= blen) {
offset = 0;
slot++;
- if (slot >= folioq_nr_slots(folioq)) {
- if (!folioq->next) {
- WARN_ON_ONCE(ret < iter->count);
- break;
- }
- folioq = folioq->next;
- slot = 0;
- }
+ continue;
}
- } while (sg_max > 0 && ret < maxsize);
- iter->folioq = folioq;
- iter->folioq_slot = slot;
+ part = umin(maxsize - ret, blen - offset);
+
+ sg_set_page(sg, bv->bv_page, part, bv->bv_offset + offset);
+ sgtable->nents++;
+ sg++;
+ sg_max--;
+ offset += part;
+ ret += part;
+ }
+
+ iter->bvecq = bvecq;
+ iter->bvecq_slot = slot;
iter->iov_offset = offset;
iter->count -= ret;
return ret;
@@ -1391,8 +1389,8 @@ static ssize_t extract_xarray_to_sg(struct iov_iter *iter,
* addition of @sg_max elements.
*
* The pages referred to by UBUF- and IOVEC-type iterators are extracted and
- * pinned; BVEC-, KVEC-, FOLIOQ- and XARRAY-type are extracted but aren't
- * pinned; DISCARD-type is not supported.
+ * pinned; BVEC-, BVECQ-, KVEC-, XARRAY-type are extracted but aren't pinned;
+ * DISCARD-type is not supported.
*
* No end mark is placed on the scatterlist; that's left to the caller.
*
@@ -1424,9 +1422,9 @@ ssize_t extract_iter_to_sg(struct iov_iter *iter, size_t maxsize,
case ITER_KVEC:
return extract_kvec_to_sg(iter, maxsize, sgtable, sg_max,
extraction_flags);
- case ITER_FOLIOQ:
- return extract_folioq_to_sg(iter, maxsize, sgtable, sg_max,
- extraction_flags);
+ case ITER_BVECQ:
+ return extract_bvecq_to_sg(iter, maxsize, sgtable, sg_max,
+ extraction_flags);
case ITER_XARRAY:
return extract_xarray_to_sg(iter, maxsize, sgtable, sg_max,
extraction_flags);
diff --git a/lib/tests/Makefile b/lib/tests/Makefile
index df0537e1b91faf..85e3c5e1f7d292 100644
--- a/lib/tests/Makefile
+++ b/lib/tests/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_GLOB_KUNIT_TEST) += glob_kunit.o
obj-$(CONFIG_HASHTABLE_KUNIT_TEST) += hashtable_test.o
obj-$(CONFIG_HASH_KUNIT_TEST) += test_hash.o
obj-$(CONFIG_TEST_IOV_ITER) += kunit_iov_iter.o
+obj-$(CONFIG_TEST_BVECQ) += kunit_bvecq.o
obj-$(CONFIG_IS_SIGNED_TYPE_KUNIT_TEST) += is_signed_type_kunit.o
obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o
obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o
diff --git a/lib/tests/kunit_bvecq.c b/lib/tests/kunit_bvecq.c
new file mode 100644
index 00000000000000..7cdd455df69298
--- /dev/null
+++ b/lib/tests/kunit_bvecq.c
@@ -0,0 +1,599 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* bvecq iterator tests. Exercises:
+ * - advance
+ * - revert
+ * - npages
+ * - alignment
+ *
+ * See also kunit_iov_iter.c for bvecq copy and extract tests.
+ *
+ * Copyright (C) 2026 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/module.h>
+#include <linux/mm.h>
+#include <linux/uio.h>
+#include <linux/bvecq.h>
+#include <kunit/test.h>
+
+MODULE_DESCRIPTION("bvecq testing");
+MODULE_AUTHOR("David Howells <dhowells@redhat.com>");
+MODULE_LICENSE("GPL");
+
+/*
+ * Info for the fill pattern generator.
+ */
+static const u8 bvecq_kunit_orders[16] = {
+ 0, 1, 2, 3,
+ 0, 1, 3, 2,
+ 0, 2, 1, 3,
+ 2, 0, 3, 1
+};
+
+static const s8 bvecq_kunit_fills[16] = {
+ 1, 2, 3, 5, 7, 11, 13, 17,
+ -1, -2, -3, -5, -7, -11, -13, -17
+};
+static struct folio *bvecq_kunit_folios[16];
+
+/*
+ * Info for the fill pattern predictor.
+ */
+struct bvecq_test_pagemap {
+ u32 pos;
+ u32 offset;
+ u8 folio;
+ u8 subpage;
+};
+
+static struct bvecq_test_pagemap bvecq_kunit_pagemap[64];
+static int bvecq_kunit_pagemap_nr;
+
+/*
+ * bvecq assembly recipes.
+ */
+enum bvecq_test_cmd {
+ BVECQ_KUNIT_STOP, /* Stop loading */
+ BVECQ_KUNIT_ALLOC, /* Append new bvecq of size count and move to it */
+ BVECQ_KUNIT_LOAD, /* Load count segments into current bvecq */
+ BVECQ_KUNIT_EMPTY, /* Add count empty segments into current bvecq */
+} __mode(byte);
+
+struct bvecq_test_recipe {
+ enum bvecq_test_cmd cmd;
+ u8 count;
+};
+
+#define ALLOC(C) { .cmd = BVECQ_KUNIT_ALLOC, .count = C }
+#define LOAD(C) { .cmd = BVECQ_KUNIT_LOAD, .count = C }
+#define EMPTY(C) { .cmd = BVECQ_KUNIT_EMPTY, .count = C }
+#define END { .cmd = BVECQ_KUNIT_STOP, }
+
+static const struct bvecq_test_recipe bvecq_test_recipe_0[] = {
+ ALLOC(16), LOAD(16),
+ END
+};
+
+static const struct bvecq_test_recipe bvecq_test_recipe_1[] = {
+ ALLOC(8), LOAD(8),
+ ALLOC(8), LOAD(8),
+ END
+};
+
+static const struct bvecq_test_recipe bvecq_test_recipe_2[] = {
+ ALLOC(9), LOAD(8), EMPTY(1),
+ ALLOC(8), LOAD(8),
+ END
+};
+
+static const struct bvecq_test_recipe bvecq_test_recipe_3[] = {
+ ALLOC(9), EMPTY(1), LOAD(2), EMPTY(2), LOAD(2), EMPTY(1),
+ ALLOC(8), LOAD(4), EMPTY(2),
+ ALLOC(8), EMPTY(1), LOAD(4),
+ ALLOC(8), EMPTY(2), LOAD(4), EMPTY(1),
+ END
+};
+
+static const struct bvecq_test_recipe bvecq_test_recipe_4[] = {
+ ALLOC(9), LOAD(2), EMPTY(1),
+ ALLOC(2),
+ ALLOC(2), LOAD(2),
+ ALLOC(2), EMPTY(2),
+ ALLOC(8), LOAD(8),
+ END
+};
+
+static const struct bvecq_test_recipe bvecq_test_recipe_5[] = {
+ ALLOC(2),
+ ALLOC(9), LOAD(2), EMPTY(1),
+ ALLOC(2),
+ ALLOC(2), LOAD(2),
+ ALLOC(2), EMPTY(2),
+ ALLOC(8), LOAD(8),
+ ALLOC(2),
+ END
+};
+
+static const struct bvecq_test_recipe bvecq_test_recipe_6[] = {
+ ALLOC(2), EMPTY(1),
+ ALLOC(2),
+ ALLOC(9), LOAD(2), EMPTY(1),
+ ALLOC(2),
+ ALLOC(2), LOAD(2),
+ ALLOC(2), EMPTY(2),
+ ALLOC(8), LOAD(8),
+ ALLOC(2),
+ ALLOC(2), EMPTY(1),
+ END
+};
+
+/*
+ * Sets of variations of how much of each folio is added to the bvecq chain,
+ * allowing a part of the folio to be excluded from each end.
+ */
+struct bvecq_test_partials {
+ u16 add_start; /* Amount to exclude from the low end */
+ u16 sub_end; /* Amount to exclude from the high end */
+};
+
+/* All whole folios. */
+static const struct bvecq_test_partials bvecq_test_partials_full[16] = {
+ [0 ... 15] = { 0, 0 }
+};
+
+/* Scattered partial folios, with some folios contiguous. */
+static const struct bvecq_test_partials bvecq_test_partials_scattered[16] = {
+ //0, 1, 2, 3,
+ { 0x277, 0x136 },
+ { 0x999, 0x1011 },
+ { 0x2020, 0x0 },
+ { 0x0, 0x1123 },
+ //0, 1, 3, 2,
+ { 0x0, 0x136 },
+ { 0x27, 0x777 },
+ { 0x771, 0x0 },
+ { 0x555, 0x0 },
+ //0, 2, 1, 3,
+ { 0x277, 0x136 },
+ { 0x1123, 0x0 },
+ { 0x0, 0x0 },
+ { 0, 0x5011 },
+ //2, 0, 3, 1
+ { 0x2020, 0x0 },
+ { 0x277, 0x136 },
+ { 0x1999, 0x1011 },
+ { 0x0, 0x1010 },
+};
+
+/* Partial folios, all with a byte excluded from each end. */
+static const struct bvecq_test_partials bvecq_test_partials_edges[16] = {
+ [0 ... 15] = { 1, 1 }
+};
+
+/*
+ * Clean up routines.
+ */
+static void bvecq_kunit_release_folios(void *data)
+{
+ struct folio **folios = data;
+
+ release_pages(folios, ARRAY_SIZE(bvecq_kunit_folios));
+ memset(bvecq_kunit_folios, 0, sizeof(bvecq_kunit_folios));
+}
+
+static void bvecq_kunit_bvecq_put(void *data)
+{
+ bvecq_put(data);
+}
+
+/*
+ * Calculate the fill pattern, for a particular byte of a particular subpage of
+ * a particular folio.
+ */
+static inline u8 bvecq_kunit_pattern(unsigned int folio, int subpage, int offset)
+{
+ int fill_step = bvecq_kunit_fills[folio];
+
+ return (subpage + offset * fill_step) & 0xff;
+}
+
+/*
+ * Calculate the fill pattern, given the 'byte position' in the bvecq chain.
+ * This looks up the folio, subpage and offset from a table generated whilst
+ * the bvecq is being assembled.
+ */
+static inline u8 bvecq_kunit_predict(struct kunit *test, size_t pos)
+{
+ size_t last_pos = 0;
+
+ for (int i = 0; i < bvecq_kunit_pagemap_nr; i++) {
+ if (pos < bvecq_kunit_pagemap[i].pos)
+ return bvecq_kunit_pattern(
+ bvecq_kunit_pagemap[i].folio,
+ bvecq_kunit_pagemap[i].subpage,
+ bvecq_kunit_pagemap[i].offset + (pos - last_pos));
+ last_pos = bvecq_kunit_pagemap[i].pos;
+ }
+
+ KUNIT_FAIL(test, "Overran pagemap pos=%zx\n", pos);
+ return 0;
+}
+
+/*
+ * Determine which page we're looking at, taking all the folios to be split
+ * into pages. This can be used to determine what iov_iter_npages() will say.
+ */
+static inline int bvecq_kunit_pos2page(struct kunit *test, size_t pos)
+{
+ for (int i = 0; i < bvecq_kunit_pagemap_nr; i++)
+ if (pos < bvecq_kunit_pagemap[i].pos)
+ return i;
+
+ if (pos > bvecq_kunit_pagemap[bvecq_kunit_pagemap_nr - 1].pos)
+ KUNIT_FAIL(test, "Overran pagemap pos=%zx\n", pos);
+ return bvecq_kunit_pagemap_nr;
+}
+
+/*
+ * Allocate a variety of folios of different orders and fill them with the
+ * pattern set for each folio.
+ */
+static void __init iov_bvecq_alloc_folios(struct kunit *test)
+{
+ struct folio *folio, **folios = bvecq_kunit_folios;
+ const int nr = ARRAY_SIZE(bvecq_kunit_folios);
+
+ bvecq_kunit_pagemap_nr = 0;
+ memset(bvecq_kunit_pagemap, 0, sizeof(bvecq_kunit_pagemap));
+ memset(bvecq_kunit_folios, 0, sizeof(bvecq_kunit_folios));
+
+ for (int i = 0; i < nr; i++) {
+ folio = folio_alloc(GFP_KERNEL, bvecq_kunit_orders[i]);
+ KUNIT_ASSERT_NOT_NULL(test, folio);
+ folios[i] = folio;
+
+ /* Fill each subpage with a different but predictable pattern. */
+ for (int j = 0; j < folio_nr_pages(folio); j++) {
+ u8 *p = kmap_local_folio(folio, PAGE_SIZE * j);
+
+ for (int k = 0; k < PAGE_SIZE; k++)
+ p[k] = bvecq_kunit_pattern(i, j, k);
+ kunmap_local(p);
+ }
+ }
+
+ kunit_add_action_or_reset(test, bvecq_kunit_release_folios, folios);
+}
+
+/*
+ * Follow the specified recipe to allocate a bvecq chain and stick the folios
+ * and empty gaps into it. Further, the offset into and length of each folio
+ * is adjusted from the partials list. Each ALLOC command will append a new
+ * bvecq to the chain and move to filling that.
+ */
+static struct bvecq *__init bvecq_kunit_load_chain(
+ struct kunit *test,
+ const struct bvecq_test_recipe *rec,
+ const struct bvecq_test_partials *parts,
+ size_t *size)
+{
+ struct bvecq *head = NULL, *bq = NULL, *p;
+ size_t pos = 0;
+ int folio_index = 0;
+
+ *size = 0;
+
+ for (; rec->cmd != BVECQ_KUNIT_STOP; rec++) {
+ if (!head)
+ KUNIT_ASSERT_EQ(test, rec->cmd, BVECQ_KUNIT_ALLOC);
+
+ switch (rec->cmd) {
+ case BVECQ_KUNIT_STOP:
+ break;
+
+ case BVECQ_KUNIT_ALLOC:
+ p = bvecq_alloc_one(rec->count, GFP_KERNEL, false);
+ KUNIT_ASSERT_NOT_NULL(test, p);
+
+ if (!head) {
+ head = p;
+ kunit_add_action_or_reset(test, bvecq_kunit_bvecq_put, head);
+ bq = p;
+ } else {
+ bvecq_append(bq, p);
+ bq = p;
+ }
+ break;
+
+ case BVECQ_KUNIT_LOAD:
+ KUNIT_ASSERT_LE(test, folio_index + rec->count,
+ ARRAY_SIZE(bvecq_kunit_orders));
+ KUNIT_ASSERT_LE(test, bq->nr_slots + rec->count, bq->max_slots);
+ for (int i = 0; i < rec->count; i++) {
+ struct folio *folio = bvecq_kunit_folios[folio_index];
+ size_t flen = PAGE_SIZE << bvecq_kunit_orders[folio_index];
+ size_t foff = 0;
+
+ KUNIT_ASSERT_LE(test,
+ parts[folio_index].add_start +
+ parts[folio_index].sub_end,
+ flen);
+
+ foff += parts[folio_index].add_start;
+ flen -= parts[folio_index].add_start;
+ flen -= parts[folio_index].sub_end;
+
+ bvec_set_page(&bq->bv[bq->nr_slots + i],
+ folio_page(folio, 0), flen, foff);
+ *size += flen;
+
+ for (int j = 0; j < folio_nr_pages(folio); j++) {
+ struct bvecq_test_pagemap *pm;
+ size_t part;
+
+ if (foff >= PAGE_SIZE) {
+ foff -= PAGE_SIZE;
+ continue;
+ }
+ part = min(flen, PAGE_SIZE - foff);
+ pos += part;
+ pm = &bvecq_kunit_pagemap[bvecq_kunit_pagemap_nr];
+ pm->pos = pos;
+ pm->folio = folio_index;
+ pm->subpage = j;
+ pm->offset = foff;
+ bvecq_kunit_pagemap_nr++;
+ flen -= part;
+ if (!flen)
+ break;
+ foff = 0;
+ }
+
+ folio_index++;
+ }
+ bvecq_filled_to(bq, bq->nr_slots + rec->count);
+ break;
+
+ case BVECQ_KUNIT_EMPTY:
+ KUNIT_ASSERT_LE(test, bq->nr_slots + rec->count, bq->max_slots);
+ for (int i = 0; i < rec->count; i++) {
+ bq->bv[bq->nr_slots + i].bv_page = ERR_PTR(-EIO);
+ bq->bv[bq->nr_slots + i].bv_offset = 0;
+ bq->bv[bq->nr_slots + i].bv_len = 0;
+ }
+ bvecq_filled_to(bq, bq->nr_slots + rec->count);
+ break;
+ }
+ }
+
+ return head;
+}
+
+/*
+ * Check the next few bytes of pattern from an iterator. Note that it is
+ * permitted for the iterator to have less data remaining than the number to
+ * check - in which case the copy is required to come up short.
+ */
+static void __init bvecq_kunit_check_next(struct kunit *test, struct iov_iter *iter,
+ size_t *pos, size_t *left, size_t nr)
+{
+ size_t part, n;
+ u8 buf[3], pred[3];
+
+ KUNIT_ASSERT_EQ(test, iov_iter_count(iter), *left);
+
+ part = min(*left, nr);
+ n = copy_from_iter(buf, nr, iter);
+ KUNIT_ASSERT_EQ(test, n, part);
+ *left -= n;
+
+ for (size_t i = 0; i < n; i++)
+ pred[i] = bvecq_kunit_predict(test, *pos + i);
+
+ for (size_t i = 0; i < n; i++) {
+ if (buf[i] != pred[i]) {
+ pr_notice(">>> pos=%05zx+%zx c=%zx buf=%*phN pred=%*phN\n",
+ *pos, i, iov_iter_count(iter) + n,
+ (int)n, buf, (int)n, pred);
+ }
+ KUNIT_ASSERT_EQ(test, buf[i], pred[i]);
+ }
+
+ *pos += n;
+}
+
+/*
+ * Test advancing and reverting over a bvecq chain.
+ *
+ * The loop starts at each 'byte position' in the chain, advancing a small
+ * amount, copying a few bytes of data, checking the fill pattern, reverting a
+ * bit, checking, reverting, checking and then reverting to a byte position one
+ * further on than the previous loop. Use small prime numbers for the advance
+ * and first revert so that we should test crossing the edges of the folios.
+ */
+static void __init bvecq_kunit_advance(struct kunit *test,
+ const struct bvecq_test_recipe *recipe,
+ const struct bvecq_test_partials *parts)
+{
+ struct iov_iter iter;
+ struct bvecq *bq, *p;
+ unsigned long bvec_align = 0;
+ size_t size, pos = 0, from;
+ int npages;
+
+ iov_bvecq_alloc_folios(test);
+ bq = bvecq_kunit_load_chain(test, recipe, parts, &size);
+
+ /* Compound up the alignments for ITER_BVEC on each individual bvecq
+ * span and compare that to the alignment for ITER_BVECQ. There is an
+ * issue in ITER_BVEC, however, in that it includes bv_offset from
+ * bio_vecs for which bv_len is 0, which ITER_BVECQ does not.
+ */
+ for (p = bq; p; p = p->next) {
+ size_t psize = 0;
+
+ for (int i = 0; i < p->nr_slots; i++)
+ psize += p->bv[i].bv_len;
+
+ if (!psize)
+ continue;
+ iov_iter_bvec(&iter, ITER_SOURCE, p->bv, p->nr_slots, psize);
+ bvec_align |= iov_iter_alignment(&iter);
+ }
+
+ iov_iter_bvec_queue(&iter, ITER_SOURCE, bq, 0, 0, size);
+
+ KUNIT_ASSERT_EQ(test, iov_iter_alignment(&iter), bvec_align);
+
+ npages = iov_iter_npages(&iter, INT_MAX);
+ from = iov_iter_count(&iter);
+ do {
+ size_t left = from, part;
+
+ KUNIT_ASSERT_EQ(test, iov_iter_npages(&iter, INT_MAX),
+ npages - bvecq_kunit_pos2page(test, pos));
+
+ /* 3 steps forward. */
+ part = min(left, 3);
+ iov_iter_advance(&iter, 3); /* May be short. */
+ pos += part;
+ left -= part;
+ bvecq_kunit_check_next(test, &iter, &pos, &left, 3);
+
+ /* 2 steps back */
+ part = umin(2, left);
+ iov_iter_revert(&iter, part);
+ pos -= part;
+ left += part;
+ bvecq_kunit_check_next(test, &iter, &pos, &left, 2);
+
+ /* 1 more step back */
+ part = umin(1, left);
+ iov_iter_revert(&iter, part);
+ pos -= part;
+ left += part;
+ bvecq_kunit_check_next(test, &iter, &pos, &left, 1);
+
+ KUNIT_ASSERT_EQ(test, left, iov_iter_count(&iter));
+
+ /* Move to one place on from the current loop. */
+ from--;
+ if (iov_iter_count(&iter) < from) {
+ part = from - iov_iter_count(&iter);
+ iov_iter_revert(&iter, part);
+ pos -= part;
+ }
+ KUNIT_ASSERT_EQ(test, from, iov_iter_count(&iter));
+ } while (from > 0);
+}
+
+/*
+ * Test jumping around in a bvecq chain using advance and revert.
+ *
+ * The loop starts at the start of the chain, then jumps forwards through the
+ * chain and then back again by large amounts, sampling the data each time.
+ */
+static void __init bvecq_kunit_jump(struct kunit *test,
+ const struct bvecq_test_recipe *recipe,
+ const struct bvecq_test_partials *parts)
+{
+ struct iov_iter iter;
+ struct bvecq *bq;
+ size_t size, pos = 0, step = 0x100;
+ bool dir = false;
+ int npages;
+
+ iov_bvecq_alloc_folios(test);
+ bq = bvecq_kunit_load_chain(test, recipe, parts, &size);
+
+ iov_iter_bvec_queue(&iter, ITER_SOURCE, bq, 0, 0, size);
+
+ npages = iov_iter_npages(&iter, INT_MAX);
+ while (step < size) {
+ size_t left = iov_iter_count(&iter), part;
+
+ KUNIT_ASSERT_EQ(test, iov_iter_npages(&iter, INT_MAX),
+ npages - bvecq_kunit_pos2page(test, pos));
+
+ if (!dir) {
+ /* Advance by step and then 3 more in check. */
+ part = min(left, step);
+ iov_iter_advance(&iter, step); /* May be short. */
+ pos += part;
+ left -= part;
+ bvecq_kunit_check_next(test, &iter, &pos, &left, 3);
+
+ KUNIT_ASSERT_EQ(test, left, iov_iter_count(&iter));
+
+ if (left == 0) {
+ /* Switch to reverting. */
+ dir = true;
+ step += 3;
+ }
+ } else {
+ /* Revert by step and then advance by 3 in check. */
+ part = min(size - left, step);
+ iov_iter_revert(&iter, part);
+ pos -= part;
+ left += part;
+ bvecq_kunit_check_next(test, &iter, &pos, &left, 3);
+
+ KUNIT_ASSERT_EQ(test, left, iov_iter_count(&iter));
+
+ if (pos <= 3) {
+ /* Switch to advancing. */
+ dir = false;
+ step *= 2;
+ }
+ }
+ }
+}
+
+/*
+ * Run the individual test combinations
+ */
+#define ADVANCE_TESTS_SET(CHECK, PARTIALS) \
+ TEST(CHECK, PARTIALS, 0) \
+ TEST(CHECK, PARTIALS, 1) \
+ TEST(CHECK, PARTIALS, 2) \
+ TEST(CHECK, PARTIALS, 3) \
+ TEST(CHECK, PARTIALS, 4) \
+ TEST(CHECK, PARTIALS, 5) \
+ TEST(CHECK, PARTIALS, 6)
+
+#define ADVANCE_TESTS(CHECK) \
+ ADVANCE_TESTS_SET(CHECK, full) \
+ ADVANCE_TESTS_SET(CHECK, scattered) \
+ ADVANCE_TESTS_SET(CHECK, edges)
+
+#define TEST(CHECK, PARTIALS, RECIPE) \
+static void __init bvecq_kunit_##CHECK##_##PARTIALS##_##RECIPE(struct kunit *test) \
+{ \
+ bvecq_kunit_##CHECK(test, \
+ bvecq_test_recipe_##RECIPE, \
+ bvecq_test_partials_##PARTIALS); \
+}
+
+/* Emit test stub functions. */
+ADVANCE_TESTS(advance);
+ADVANCE_TESTS(jump);
+#undef TEST
+
+#define TEST(CHECK, PARTIALS, RECIPE) \
+ KUNIT_CASE(bvecq_kunit_##CHECK##_##PARTIALS##_##RECIPE),
+
+static struct kunit_case __refdata bvecq_kunit_cases[] = {
+ ADVANCE_TESTS(advance)
+ ADVANCE_TESTS(jump)
+ {}
+};
+
+static struct kunit_suite bvecq_kunit_suite = {
+ .name = "bvecq",
+ .test_cases = bvecq_kunit_cases,
+};
+
+kunit_test_suites(&bvecq_kunit_suite);
diff --git a/lib/tests/kunit_iov_iter.c b/lib/tests/kunit_iov_iter.c
index 32e42d8c7ca13e..19fc082e4cf3da 100644
--- a/lib/tests/kunit_iov_iter.c
+++ b/lib/tests/kunit_iov_iter.c
@@ -12,7 +12,7 @@
#include <linux/mm.h>
#include <linux/uio.h>
#include <linux/bvec.h>
-#include <linux/folio_queue.h>
+#include <linux/bvecq.h>
#include <linux/scatterlist.h>
#include <linux/minmax.h>
#include <linux/mman.h>
@@ -382,58 +382,67 @@ static void __init iov_kunit_copy_from_bvec(struct kunit *test)
KUNIT_SUCCEED(test);
}
-static void iov_kunit_destroy_folioq(void *data)
+static void iov_kunit_destroy_bvecq(void *data)
{
- struct folio_queue *folioq, *next;
+ struct bvecq *bq, *next;
- for (folioq = data; folioq; folioq = next) {
- next = folioq->next;
- kfree(folioq);
+ for (bq = data; bq; bq = next) {
+ next = bq->next;
+ /* The pages are freed by vmap with VM_MAP_PUT_PAGES. */
+ kfree(bq);
}
}
-static void __init iov_kunit_load_folioq(struct kunit *test,
+static struct bvecq *iov_kunit_alloc_bvecq(struct kunit *test, unsigned int max_slots)
+{
+ struct bvecq *bq;
+
+ bq = kzalloc(struct_size(bq, __bv, max_slots), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bq);
+ bq->max_slots = max_slots;
+ bq->bv = bq->__bv;
+ bq->inline_bv = true;
+ return bq;
+}
+
+static struct bvecq *iov_kunit_create_bvecq(struct kunit *test, unsigned int max_slots)
+{
+ struct bvecq *bq;
+
+ bq = iov_kunit_alloc_bvecq(test, max_slots);
+ kunit_add_action_or_reset(test, iov_kunit_destroy_bvecq, bq);
+ return bq;
+}
+
+static void __init iov_kunit_load_bvecq(struct kunit *test,
struct iov_iter *iter, int dir,
- struct folio_queue *folioq,
+ struct bvecq *bq_head,
struct page **pages, size_t npages)
{
- struct folio_queue *p = folioq;
+ struct bvecq *bq = bq_head;
size_t size = 0;
- int i;
- for (i = 0; i < npages; i++) {
- if (folioq_full(p)) {
- p->next = kzalloc_obj(struct folio_queue);
- KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p->next);
- folioq_init(p->next, 0);
- p->next->prev = p;
- p = p->next;
+ for (int i = 0; i < npages; i++) {
+ if (bq->nr_slots >= bq->max_slots) {
+ bq->next = iov_kunit_alloc_bvecq(test, 13);
+ bq->next->prev = bq;
+ bq = bq->next;
}
- folioq_append(p, page_folio(pages[i]));
+ bvec_set_page(&bq->bv[bq->nr_slots], pages[i], PAGE_SIZE, 0);
+ bq->nr_slots++;
size += PAGE_SIZE;
}
- iov_iter_folio_queue(iter, dir, folioq, 0, 0, size);
-}
-
-static struct folio_queue *iov_kunit_create_folioq(struct kunit *test)
-{
- struct folio_queue *folioq;
-
- folioq = kzalloc_obj(struct folio_queue);
- KUNIT_ASSERT_NOT_ERR_OR_NULL(test, folioq);
- kunit_add_action_or_reset(test, iov_kunit_destroy_folioq, folioq);
- folioq_init(folioq, 0);
- return folioq;
+ iov_iter_bvec_queue(iter, dir, bq_head, 0, 0, size);
}
/*
- * Test copying to a ITER_FOLIOQ-type iterator.
+ * Test copying to a ITER_BVECQ-type iterator.
*/
-static void __init iov_kunit_copy_to_folioq(struct kunit *test)
+static void __init iov_kunit_copy_to_bvecq(struct kunit *test)
{
const struct kvec_test_range *pr;
struct iov_iter iter;
- struct folio_queue *folioq;
+ struct bvecq *bq;
struct page **spages, **bpages;
u8 *scratch, *buffer;
size_t bufsize, npages, size, copied;
@@ -442,7 +451,7 @@ static void __init iov_kunit_copy_to_folioq(struct kunit *test)
bufsize = 0x100000;
npages = bufsize / PAGE_SIZE;
- folioq = iov_kunit_create_folioq(test);
+ bq = iov_kunit_create_bvecq(test, 13);
scratch = iov_kunit_create_buffer(test, &spages, npages);
for (i = 0; i < bufsize; i++)
@@ -451,20 +460,19 @@ static void __init iov_kunit_copy_to_folioq(struct kunit *test)
buffer = iov_kunit_create_buffer(test, &bpages, npages);
memset(buffer, 0, bufsize);
- iov_kunit_load_folioq(test, &iter, READ, folioq, bpages, npages);
+ iov_kunit_load_bvecq(test, &iter, READ, bq, bpages, npages);
i = 0;
for (pr = kvec_test_ranges; pr->from >= 0; pr++) {
size = pr->to - pr->from;
KUNIT_ASSERT_LE(test, pr->to, bufsize);
- iov_iter_folio_queue(&iter, READ, folioq, 0, 0, pr->to);
+ iov_iter_bvec_queue(&iter, READ, bq, 0, 0, pr->to);
iov_iter_advance(&iter, pr->from);
copied = copy_to_iter(scratch + i, size, &iter);
KUNIT_EXPECT_EQ(test, copied, size);
KUNIT_EXPECT_EQ(test, iter.count, 0);
- KUNIT_EXPECT_EQ(test, iter.iov_offset, pr->to % PAGE_SIZE);
i += size;
if (test->status == KUNIT_FAILURE)
goto stop;
@@ -489,13 +497,13 @@ static void __init iov_kunit_copy_to_folioq(struct kunit *test)
}
/*
- * Test copying from a ITER_FOLIOQ-type iterator.
+ * Test copying from a ITER_BVECQ-type iterator.
*/
-static void __init iov_kunit_copy_from_folioq(struct kunit *test)
+static void __init iov_kunit_copy_from_bvecq(struct kunit *test)
{
const struct kvec_test_range *pr;
struct iov_iter iter;
- struct folio_queue *folioq;
+ struct bvecq *bq;
struct page **spages, **bpages;
u8 *scratch, *buffer;
size_t bufsize, npages, size, copied;
@@ -504,7 +512,7 @@ static void __init iov_kunit_copy_from_folioq(struct kunit *test)
bufsize = 0x100000;
npages = bufsize / PAGE_SIZE;
- folioq = iov_kunit_create_folioq(test);
+ bq = iov_kunit_create_bvecq(test, 13);
buffer = iov_kunit_create_buffer(test, &bpages, npages);
for (i = 0; i < bufsize; i++)
@@ -513,20 +521,19 @@ static void __init iov_kunit_copy_from_folioq(struct kunit *test)
scratch = iov_kunit_create_buffer(test, &spages, npages);
memset(scratch, 0, bufsize);
- iov_kunit_load_folioq(test, &iter, READ, folioq, bpages, npages);
+ iov_kunit_load_bvecq(test, &iter, READ, bq, bpages, npages);
i = 0;
for (pr = kvec_test_ranges; pr->from >= 0; pr++) {
size = pr->to - pr->from;
KUNIT_ASSERT_LE(test, pr->to, bufsize);
- iov_iter_folio_queue(&iter, WRITE, folioq, 0, 0, pr->to);
+ iov_iter_bvec_queue(&iter, WRITE, bq, 0, 0, pr->to);
iov_iter_advance(&iter, pr->from);
copied = copy_from_iter(scratch + i, size, &iter);
KUNIT_EXPECT_EQ(test, copied, size);
KUNIT_EXPECT_EQ(test, iter.count, 0);
- KUNIT_EXPECT_EQ(test, iter.iov_offset, pr->to % PAGE_SIZE);
i += size;
}
@@ -868,13 +875,13 @@ static void __init iov_kunit_extract_pages_bvec(struct kunit *test)
}
/*
- * Test the extraction of ITER_FOLIOQ-type iterators.
+ * Test the extraction of ITER_BVECQ-type iterators.
*/
-static void __init iov_kunit_extract_pages_folioq(struct kunit *test)
+static void __init iov_kunit_extract_pages_bvecq(struct kunit *test)
{
const struct kvec_test_range *pr;
- struct folio_queue *folioq;
struct iov_iter iter;
+ struct bvecq *bq;
struct page **bpages, *pagelist[8], **pages = pagelist;
ssize_t len;
size_t bufsize, size = 0, npages;
@@ -883,17 +890,17 @@ static void __init iov_kunit_extract_pages_folioq(struct kunit *test)
bufsize = 0x100000;
npages = bufsize / PAGE_SIZE;
- folioq = iov_kunit_create_folioq(test);
+ bq = iov_kunit_create_bvecq(test, 13);
iov_kunit_create_buffer(test, &bpages, npages);
- iov_kunit_load_folioq(test, &iter, READ, folioq, bpages, npages);
+ iov_kunit_load_bvecq(test, &iter, READ, bq, bpages, npages);
for (pr = kvec_test_ranges; pr->from >= 0; pr++) {
from = pr->from;
size = pr->to - from;
KUNIT_ASSERT_LE(test, pr->to, bufsize);
- iov_iter_folio_queue(&iter, WRITE, folioq, 0, 0, pr->to);
+ iov_iter_bvec_queue(&iter, WRITE, bq, 0, 0, pr->to);
iov_iter_advance(&iter, from);
do {
@@ -1173,19 +1180,18 @@ static void __init iov_kunit_iter_to_sg_bvec(struct kunit *test)
iov_kunit_iter_to_sg_check(test, &iter, bufsize, &data);
}
-static void __init iov_kunit_iter_to_sg_folioq(struct kunit *test)
+static void __init iov_kunit_iter_to_sg_bvecq(struct kunit *test)
{
struct iov_kunit_iter_to_sg_data data;
- struct folio_queue *folioq;
struct iov_iter iter;
+ struct bvecq *bq;
size_t bufsize;
bufsize = 0x200000;
iov_kunit_iter_to_sg_init(test, bufsize, false, &data);
- folioq = iov_kunit_create_folioq(test);
- iov_kunit_load_folioq(test, &iter, READ, folioq, data.pages,
- data.npages);
+ bq = iov_kunit_create_bvecq(test, 13);
+ iov_kunit_load_bvecq(test, &iter, READ, bq, data.pages, data.npages);
iov_kunit_iter_to_sg_check(test, &iter, bufsize, &data);
}
@@ -1226,17 +1232,17 @@ static struct kunit_case __refdata iov_kunit_cases[] = {
KUNIT_CASE(iov_kunit_copy_from_kvec),
KUNIT_CASE(iov_kunit_copy_to_bvec),
KUNIT_CASE(iov_kunit_copy_from_bvec),
- KUNIT_CASE(iov_kunit_copy_to_folioq),
- KUNIT_CASE(iov_kunit_copy_from_folioq),
+ KUNIT_CASE(iov_kunit_copy_to_bvecq),
+ KUNIT_CASE(iov_kunit_copy_from_bvecq),
KUNIT_CASE(iov_kunit_copy_to_xarray),
KUNIT_CASE(iov_kunit_copy_from_xarray),
KUNIT_CASE(iov_kunit_extract_pages_kvec),
KUNIT_CASE(iov_kunit_extract_pages_bvec),
- KUNIT_CASE(iov_kunit_extract_pages_folioq),
+ KUNIT_CASE(iov_kunit_extract_pages_bvecq),
KUNIT_CASE(iov_kunit_extract_pages_xarray),
KUNIT_CASE(iov_kunit_iter_to_sg_kvec),
KUNIT_CASE(iov_kunit_iter_to_sg_bvec),
- KUNIT_CASE(iov_kunit_iter_to_sg_folioq),
+ KUNIT_CASE(iov_kunit_iter_to_sg_bvecq),
KUNIT_CASE(iov_kunit_iter_to_sg_xarray),
KUNIT_CASE(iov_kunit_iter_to_sg_ubuf),
{}
|
| 29/3 | 2026/11/10 18:07 | llm | kmsan-evaluator |
2mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 74768 output: 42 thoughts: 8749 Thoughts: **Analysis of `folio_queue` to `bvecq` Transition for Uninitialized Memory Risks** Okay, so I'm diving into this patch that swaps out `folio_queue` with `bvecq` across various netfs components. My immediate concern, as always, is whether this introduces any risks of reading uninitialized memory, or potentially leaking kernel data to user space. Given the criteria laid out for KMSAN use, I need to methodically check this. KASAN is my first line of defense, but if this touches uninitialized memory that *only* KMSAN would catch, then I need to set `NeedsKMSAN=true`. First, the allocation and initialization of `bvecq` itself. I see a `bvecq_alloc_one` function, and the designated initializer looks to initialize the `struct bvecq`, but importantly, the documentation states explicitly that the underlying slot array `__bv` is *not* initialized. Now I immediately check where those slots are read or written. The critical thing that I see is that `bvecq_alloc_buffer2` *does* initialize the underlying `bv`! If `p->nr_slots == 0`, it calls `memset` on the slots of `p->bv`, which would make `p->nr_slots = pre_slots`. Then, it allocates a number of pages and sets up the `bio_vec`s and associates the pages with those slots. Crucially, the code checks whether the page allocation fails, and has the `oom` label. I then see `rolling_buffer_bulk_load_from_ra`. Here, the pages are allocated with `alloc_pages_bulk`. Again, there's no explicit zeroing of memory at the `bvecq` level. However, a lot of careful pointer arithmetic in `rolling_buffer_bulk_load_from_ra` determines the offset for each slot. The loop appears to initialize each slot using `bvec_set_folio`. I've carefully checked the relationship between the `pages` array, which points to the underlying `bvecq`'s buffer using pointer arithmetic, and the `bv` itself. It seems the slot write will never overwrite the `pages` read and therefore, uninitialized memory won't be exposed. And, if allocation fails, the slots in the bvec will be cleaned. I check how `bvecq_expand_buffer` is implemented. It also uses `alloc_pages` directly; however, it *appends* pages to the `bvecq`. Further, when the `bvecq` is used in AFS, in particular, it looks like `bvecq_expand_buffer` *does* initialize buffers, and zero-fills unread areas of memory. I'm seeing that the code calls `bvecq_expand_buffer` to increase the size of the underlying buffer with `__GFP_ZERO` flag. This suggests that it should zero the contents of newly allocated pages. Now, let's zoom in on SMB. Here, `cifs_copy_iter_to_bvecq` and `cifs_copy_bvecq_to_iter` are key. These functions copy data *to* and *from* `bvecq`s. I'm concerned about the potential for uninitialized data being copied *to* user space by `cifs_copy_bvecq_to_iter`. The pages underlying the bvecq are allocated with `alloc_pages_bulk(GFP_NOFS, ...)` in `receive_encrypted_read`. If `GFP_NOFS` is used, the pages will *not* be zeroed. It *reads* data, then copies the data from kernel space to user space using `copy_page_to_iter`, which *could* leak uninitialized kernel memory. Crucially, I see that the code says to "Read the data into the buffer and clear excess bufferage." Based on all of this, let's see which criterion could be satisfied and if `NeedsKMSAN=true`. I need to ensure that no information is being leaked to user-space in the copy operation, so I can ensure the code will behave and meet the criteria for not having any uninitialized data! |
| 30/3 | 2026/11/10 18:09 | tool | read-file |
0mArgs:{
"File": "fs/smb/client/smb2ops.c",
"FirstLine": 5365,
"LineCount": 50
}Results: {
"Contents": "5365:\t\t\trc = -EINVAL;\n5366:\t\t\tgoto discard_data;\n5367:\t\t}\n5368:\t\tlen = le32_to_cpu(tr_hdr-\u003eOriginalMessageSize) -\n5369:\t\t\tserver-\u003evals-\u003eread_rsp_size;\n5370:\t\tdw-\u003elen = len;\n5371:\t\tlen = round_up(dw-\u003elen, PAGE_SIZE);\n5372:\t\n5373:\t\trc = -ENOMEM;\n5374:\t\tdw-\u003ebuffer = bvecq_alloc_buffer(len, GFP_NOFS, false);\n5375:\t\tif (!dw-\u003ebuffer)\n5376:\t\t\tgoto discard_data;\n5377:\t\n5378:\t\tiov_iter_bvec_queue(\u0026iter, ITER_DEST, dw-\u003ebuffer, 0, 0, len);\n5379:\t\n5380:\t\t/* Read the data into the buffer and clear excess bufferage. */\n5381:\t\trc = cifs_read_iter_from_socket(server, \u0026iter, dw-\u003elen);\n5382:\t\tif (rc \u003c 0)\n5383:\t\t\tgoto discard_data;\n5384:\t\n5385:\t\tserver-\u003etotal_read += rc;\n5386:\t\tif (rc \u003c len) {\n5387:\t\t\tstruct iov_iter tmp = iter;\n5388:\t\n5389:\t\t\tiov_iter_advance(\u0026tmp, rc);\n5390:\t\t\tiov_iter_zero(len - rc, \u0026tmp);\n5391:\t\t}\n5392:\t\tiov_iter_truncate(\u0026iter, dw-\u003elen);\n5393:\t\n5394:\t\trc = cifs_discard_remaining_data(server);\n5395:\t\tif (rc)\n5396:\t\t\tgoto free_pages;\n5397:\t\n5398:\t\t/*\n5399:\t\t * For large reads, offload to different thread for better performance,\n5400:\t\t * use more cores decrypting which can be expensive\n5401:\t\t */\n5402:\t\n5403:\t\tif ((server-\u003emin_offload) \u0026\u0026 (server-\u003ein_flight \u003e 1) \u0026\u0026\n5404:\t\t (server-\u003epdu_size \u003e= server-\u003emin_offload)) {\n5405:\t\t\tdw-\u003ebuf = server-\u003esmallbuf;\n5406:\t\t\tserver-\u003esmallbuf = (char *)cifs_small_buf_get();\n5407:\t\n5408:\t\t\tqueue_work(decrypt_wq, \u0026dw-\u003edecrypt);\n5409:\t\t\t*num_mids = 0; /* worker thread takes care of finding mid */\n5410:\t\t\treturn -1;\n5411:\t\t}\n5412:\t\n5413:\t\trc = decrypt_raw_data(server, buf, server-\u003evals-\u003eread_rsp_size,\n5414:\t\t\t\t \u0026iter, false);\n"
} |
| 31/3 | 2026/11/10 18:09 | llm | kmsan-evaluator |
2mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 85243 output: 422 thoughts: 10223 Thoughts: **Summary of Thought Process** Alright, let's break down this code and determine if we need to flag it for KMSAN. My initial thought is to scrutinize lines 5386-5391 to understand how any "excess" data is handled after a read operation, as it explicitly zeroes this excess with `iov_iter_zero`. I immediately recall similar logic in `netfs_alloc_folioq_buffer`, where unused space is also explicitly handled. This makes me consider if similar safety measures are maintained with the switch to `bvecq` (bio vector queue) and `iov_iter`. I then dig into the `iterate_bvecq` function (found in `include/linux/iov_iter.h`). The core loop and calculations around `page`, `poff`, and `plen` demand close inspection. I'm looking for anything that could potentially lead to reading uninitialized memory, or accessing pages incorrectly within compound pages. I must make sure that `bvec->bv_page + n` will *always* be valid for all `n`. I double check `bvecq_expand_buffer` which allocates pages, and realize that compound pages *are* physically contiguous, so I'm safe there. I follow up on `bvecq_alloc_buffer2`, which allocates multiple single pages at once with `alloc_pages_bulk`. If `bv_len > PAGE_SIZE`, then it's a compound page (or hugetlb) which IS valid, and `page++` is correct because of the `PAGE_SIZE` constraint from the allocation. And standard kernel `bio_vec` requires contiguous physical pages (or compound page / hugetlb) if `bv_len > PAGE_SIZE`. I then investigate `iov_iter_bvecq_advance` and `iov_iter_bvecq_revert`, and worry about how they handle the `slot` index and the `by` variable. I have to ensure there are no off-by-one or out-of-bounds accesses during iteration or reversion, and any potential issues with double freeing or other memory management problems. It looks like `slot` may equal `bq->nr_slots` and needs to be handled properly. I then check `iov_iter_extract_bvecq_pages` and `iter_count_bvecq_pages`, in `lib/iov_iter.c`, to check for any uninitialized memory or out-of-bounds access. The potential for the `pages` array to be accessed incorrectly is significant in this code, so I analyze the indexing, and review the code to see if the right pages are acquired, and that the `struct page**` and `struct page***` are correct and being used properly. I check for any uninitialized memory issues based on four specific rules. 1. I scan the diff for code that sends kernel structures to user space. I check the diff for any instances of `copy_to_user`, `put_user`, netlink calls, `ioctl` outputs, socket options, or BPF buffers. I then check `afs_readlink` and surrounding code, but see that it's unmodified, only the comments above are updated. 2. I consider what changes are made to `afs_init_new_symlink`, `afs_symlink_writepages`, `afs_do_read_single`, and surrounding code. I see that the patch replaces the use of `netfs_alloc_folioq_buffer` with `bvecq_alloc_buffer` and similar. Crucially, I notice that the patch *adds* zeroing with `iov_iter_zero` in several places, *preventing* uninitialized memory from being written to the cache. I also see calls to `mapping_gfp_mask` were added to initialize data. This is very good, as it proactively prevents any potential information leaks. 3. I check whether the allocation initializes memory or not. I dig into the allocation functions: `bvecq_alloc_one()` uses struct initializers, `bvecq_alloc_buffer2` zeroes its pages, and `bvecq_expand_buffer` sets each slot, so all is good. The code also checks that slots are within bounds. 4. I look for bounds checks to prevent access to uninitialized buffers. The logic is fine here. I review the `struct iov_iter` and `struct bvecq` to ensure their values are initialized when created. Both the `iov_iter` and `bvecq` are properly initialized. In short, there's no data being transmitted to userspace, and buffers are correctly initialized and their bounds are checked. I check `iov_iter_bvecq_advance`, `iov_iter_b |
| 32/3 | 2026/11/10 18:11 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series replaces the `folio_queue` data structure (`ITER_FOLIOQ`) with `bvecq` (`ITER_BVECQ`) across netfs, AFS, and CIFS/SMB. \n\n1. Allocation \u0026 Initialization: Newly introduced `struct bvecq` instances are allocated via `bvecq_alloc_one()` and fully initialized using a designated C99 struct literal `*bq = (struct bvecq) { ... }`, which guarantees that all unmentioned fields (such as `next`, `prev`, `nr_slots`, `priv`) are zero-initialized. When allocating pre-populated slot buffers (`bvecq_alloc_buffer2`), all slots in `p-\u003ebv` are explicitly zeroed with `memset` before population. In `bvecq_expand_buffer()`, each bio_vec slot is fully initialized via `bvec_set_page()` before `bvecq_filled_to()` updates `nr_slots`.\n2. Access \u0026 Boundaries: Accesses to slots in `bq-\u003ebv` are strictly bounded by `bq-\u003enr_slots` (or `bvecq_acquire_slot()`), preventing reads of uninitialized slots.\n3. Information Leaks \u0026 Userspace Copying: Neither `struct bvecq` nor its internal metadata is copied to userspace. In AFS directory and symlink handling, the patch explicitly adds zeroing of buffer padding (`iov_iter_zero`) before writeback/cache storage.\n4. Error surface: Any potential bugs introduced by this patch (e.g., iterator slot advancement/revert bounds bugs, list traversal issues, or refcounting errors) represent out-of-bounds accesses, use-after-free, or concurrency issues, which are comprehensively detected by KASAN and standard kernel debug facilities.\n\nTherefore, dedicated KMSAN fuzzing is not required.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series replaces the `folio_queue` data structure (`ITER_FOLIOQ`) with `bvecq` (`ITER_BVECQ`) across netfs, AFS, and CIFS/SMB. \n\n1. Allocation \u0026 Initialization: Newly introduced `struct bvecq` instances are allocated via `bvecq_alloc_one()` and fully initialized using a designated C99 struct literal `*bq = (struct bvecq) { ... }`, which guarantees that all unmentioned fields (such as `next`, `prev`, `nr_slots`, `priv`) are zero-initialized. When allocating pre-populated slot buffers (`bvecq_alloc_buffer2`), all slots in `p-\u003ebv` are explicitly zeroed with `memset` before population. In `bvecq_expand_buffer()`, each bio_vec slot is fully initialized via `bvec_set_page()` before `bvecq_filled_to()` updates `nr_slots`.\n2. Access \u0026 Boundaries: Accesses to slots in `bq-\u003ebv` are strictly bounded by `bq-\u003enr_slots` (or `bvecq_acquire_slot()`), preventing reads of uninitialized slots.\n3. Information Leaks \u0026 Userspace Copying: Neither `struct bvecq` nor its internal metadata is copied to userspace. In AFS directory and symlink handling, the patch explicitly adds zeroing of buffer padding (`iov_iter_zero`) before writeback/cache storage.\n4. Error surface: Any potential bugs introduced by this patch (e.g., iterator slot advancement/revert bounds bugs, list traversal issues, or refcounting errors) represent out-of-bounds accesses, use-after-free, or concurrency issues, which are comprehensively detected by KASAN and standard kernel debug facilities.\n\nTherefore, dedicated KMSAN fuzzing is not required.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|