iterate_and_advance_kernel(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… iterate_and_advance_kernel(9)

okay so this is a page from the Kernel API Manual β€” yes, the kernel has manpages too, we're literally so back πŸŽ€


✨ NAME ✨

iterate_and_advance_kernel β€” bestie, this is the one that iterates over a kernel-internal iterator πŸ¦‹


🌸 SYNOPSIS 🌸

size_t iterate_and_advance_kernel (struct iov_iter *iter , size_t len ,
       void *priv , void *priv2 , iov_step_f step );

πŸ’– ARGUMENTS πŸ’–

  • iter β€” the iterator you're iterating over, the main character of this whole operation πŸ‘‘
  • len β€” how much you're iterating over, i.e. the amount πŸ’«
  • priv β€” data for the step functions πŸ“
  • priv2 β€” more data for the step functions, because one priv was never gonna be enough πŸ™ˆ
  • step β€” the function for other iterators; it gets handed kernel addresses ⭐

πŸ¦‹ DESCRIPTION πŸ¦‹

So what this does: it iterates over the next part of an iterator, up to the length you specified. The buffer shows up in segments, and for kernel iteration those segments are broken up by physical pages and mapped, with the mapped address being the thing presented to you. it's giving "here's the address, you're welcome" ✨

⚠️ note, and this one matters: this will only handle BVEC, KVEC, FOLIOQ, XARRAY and DISCARD-type iterators. It will not handle UBUF or IOVEC-type iterators. no cap, don't try it πŸ’€

A step functions β€” that's step β€” must be provided: one for handling mapped kernel addresses, and the other is given user addresses which have the potential to fault since no pinning is performed 😭 (lowkey a whole vibe check on your fault handling, ngl)

The step functions get passed:

  • the address and length of the segment
  • priv
  • priv2
  • the amount of data so far iterated over β€” which you can, for example, add to priv to point at the right part of a second buffer πŸ‘‘

The step functions should return the amount of the segment they didn't process (i.e. 0 indicates complete processing). slay, returning zero is the good ending πŸ’…

And the return value of this function overall: the amount of data processed. So 0 means nothing was processed, and a value of len means it processed to completion. iconic behavior, honestly 🌈


🧚 SEE ALSO 🧚


and that's the whole page bestie, go forth and iterate responsibly 🫢

source path ./include/linux, dated October 2026 β€” that's the footer, and yes I'm telling you about it in a sign-off instead of copy-pasting it, you're welcome πŸ’œ

πŸ“¦ where this page comes from