trace_user_fault_read(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… trace_user_fault_read(9) β€” Kernel API Manual, bestie edition πŸŽ€

okay so this is a page straight out of the Kernel API Manual, and honestly? it's giving "copy stuff from user space into a per-CPU buffer" and I'm obsessed. let's get into it. ✨


🌸 NAME 🌸

trace_user_fault_read β€” literally just reading user space into a per CPU buffer, no cap πŸ’–


πŸ¦‹ SYNOPSIS πŸ¦‹

char * trace_user_fault_read (struct trace_user_buf_info *tinfo , const
char __user *ptr , size_t size , trace_user_buf_copy copy_func , void
*data );

✨ ARGUMENTS ✨

  • tinfo β€” the tinfo that was allocated by trace_user_fault_get. it's the whole vibe check for where this buffer lives 🫢
  • ptr β€” the user space pointer you wanna read, bestie πŸ‘€
  • size β€” how much user space you're reading. the size. yes, that size πŸ’…
  • copy_func β€” an optional function to use for copying from user space. optional like your third coffee of the day β˜•
  • data β€” data passed along to copy_func, but only if you actually supplied one πŸ™ˆ

πŸ’œ DESCRIPTION πŸ’œ

okay so preemption must be disabled when this is called, and it must not be enabled while you're using the returned buffer. not me being dramatic β€” this is the actual rule. πŸ”₯ what this does is copy from user space into a per CPU buffer, and it does it per CPU, which is the whole point.

the size must not be greater than the size you passed in to trace_user_fault_init. that's the ceiling, queen. 🌈

if copy_func is NULL, then trace_user_fault_read will just use copy_from_user, no big deal. otherwise it calls copy_func. and when it calls copy_func, it hands it these:

  • buffer: the per CPU buffer of the tinfo
  • ptr: the pointer ptr to user space to read
  • size: the size of the ptr to read
  • data: the data parameter

it's expected that copy_func will return 0 on success and non zero if there was a fault. so like, 0 = slay, non zero = something went wrong πŸ’€

returns a pointer to the buffer with the content read from ptr. preemption must remain disabled while the caller accesses the buffer this function returns β€” fr fr, don't turn it back on mid-buffer, that's not the move. πŸ™…β€β™€οΈ

returns NULL if there was a fault, or if the size you passed in is greater than the size passed to trace_user_fault_init. so NULL is the "nope" return, both ways. 😭

⚠️ quick recap bestie: preemption stays off for the whole ride, and your size never exceeds the trace_user_fault_init size. those are the two non-negotiables. πŸ’…

πŸ‘‘ SEE ALSO πŸ‘‘

kernel file ./kernel/trace/trace.c, plus the whole friend group:


and that's the page, bestie!! 🧚 it lives in ./kernel/trace, it's dated October 2026, and it's filed under trace_user_fault_read(9) β€” iykyk πŸ’– mwah, go read some user space πŸ“

πŸ“¦ where this page comes from