PT_MAKE_LEVELS(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… PT_MAKE_LEVELS(9) β€” a kernel API manual page, but make it cute

okay so bestie, this one's from the Kernel API Manual and it's genuinely kind of iconic once you get it. Let's go ✨


🌸 NAME 🌸

PT_MAKE_LEVELS β€” build an unwound walker. yes that's the whole name, she's efficient πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

PT_MAKE_LEVELS (fn , do_fn );

(no cap, that spacing is exactly how she ships, we do not touch it πŸ™ˆ)


πŸ¦‹ ARGUMENTS πŸ¦‹

  • fn β€” the name of the walker function. that's her name, that's her whole identity 🫢
  • do_fn β€” the function that gets called at each level. she's the one doing the actual work at every stop on the tour πŸ’–

✨ DESCRIPTION ✨

so what this does is build a function call tree that can be fully inlined. fully! like, completely absorbed into the caller, no call overhead, no vibes lost 🌈

the caller has to provide a function body in an __always_inline function, and that body looks like this, exactly:

static __always_inline int do_fn(struct pt_range *range, void *arg,
       unsigned int level, struct pt_table_p *table,
       pt_level_fn_t descend_fn)

then the macro creates an inline function for each table level, and each one calls do_fn with a compile time constant for level plus a pointer to the next lower function. so it's a chain, each level handing off to the one below, all inlined, all gorgeous πŸ‘‘

the result is an optimally inlined walk where every single one of those functions sees a constant level β€” which means the compiler can codegen the exact constants/etc for that level. like, she knows exactly which level she's on at compile time and she can optimize accordingly. main character energy, honestly ⭐

⚠️ heads up though: note this can produce a lot of code! like, a LOT. codegen says slay but your binary size said 😭

🌺 SEE ALSO 🌺

kernel file ./drivers/iommu/generic_pt/pt_iter.h β€” and also her whole friend group, go say hi:


and that's the page, bestie πŸ’œ she lives in ./drivers/iommu/generic_pt, dated October 2026. go inline something. periodt. πŸŽ€βœ¨

πŸ“¦ where this page comes from