iterate_and_advance_kernel(9)
π 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 handleBVEC,KVEC,FOLIOQ,XARRAYandDISCARD-type iterators. It will not handleUBUForIOVEC-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
privpriv2- the amount of data so far iterated over β which you can, for example, add to
privto 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 π§
- Kernel file
./include/linux/iov_iter.h iterate_and_advance2(9)iterate_and_advance(9)
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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms