import_iovec(9)
π import_iovec β the kernel API manual, bestie edition π
okay so this one lives in the Kernel API Manual (section 9, kernel developer land π§), and it's genuinely one of those functions that looks scary and is actually just doing a very specific lil job. let me walk you through it π«Ά
β¨ NAME β¨
import_iovec β copies an array of &struct iovec from userspace into the kernel, checks that it's valid, and initializes a brand-new &struct iov_iter iterator so you can actually access it. that's the whole vibe. importing iovecs. slay. π
πΈ SYNOPSIS πΈ
ssize_t import_iovec (int type , const struct iovec __user *uvec ,
unsigned nr_segs , unsigned fast_segs , struct iovec **iovp , struct
iov_iter *i );
six parameters, one return value, zero chill. let's meet the cast π
π ARGUMENTS π
typeβ one ofREADorWRITE. that's it. pick a lane bestie, there's only twoπ¦uvecβ pointer to the userspace array. the OG, still living in userspace until we bring it in π«nr_segsβ number of elements in the userspace array. like, how many segs are we talking about hereπfast_segsβ number of elements iniov. the fast path capacity, iykyk βiovpβ (input and output parameter!) pointer to a pointer to a kernel array β usually a small one chilling on the stack on-stack. it goes in, it comes out, it's giving main character energy πiβ pointer to the iterator that will get initialized on success. no success, no init, that's the deal π
π¦ DESCRIPTION π¦
okay so here's the tea β:
if the array pointed to by *iov is big enough to hold all nr_segs, then this function places NULL in *iov on return. yep, NULL. that's not a bug, that's the signal β¨
otherwise, a new array gets allocated and the result is placed in *iov. so either way, you're covered.
and the iconic part: this means the caller may call kfree on *iov regardless of whether the small on-stack array was used or not β and regardless of whether this function returns an error or not. literally every path, kfree is safe. no cap, that's a genuinely thoughtful API design and i'm obsessed π«Άπ
lowkey important: thekfreeguarantee holds in all cases β small stack array or freshly allocated array, success or error. don't overthink it, justkfreeit π₯
β RETURN β
- negative error code on error π
- bytes imported on success π
π SEE ALSO π
- Kernel file
./lib/iov_iter.c _copy_mc_to_iter(9)_copy_from_iter_flushcache(9)iov_iter_folio_queue(9)iov_iter_xarray(9)iov_iter_discard(9)iov_iter_restore(9)iov_iter_extract_pages(9)iov_iter_extract_bvecs(9)
go read the whole iov_iter cinematic universe if you have a sec, it's a whole franchise πΈ
that's the page bestie!! π it ships out of ./lib and it's dated October 2026 β so like, from the future, which is very on brand for a kernel girlie π« mwah, go import some iovecs, you're gonna ate π
π
π¦ 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