rcu_read_lock_held(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… rcu_read_lock_held(9) β€” a Kernel API Manual moment

okay so we're deep in the kernel manual bestie, welcome to rcu_read_lock_held(9) πŸŽ€ this is the Kernel API Manual and honestly? this little function is doing the most for your debug checks and it deserves its flowers 🌸


✨ NAME ✨

rcu_read_lock_held β€” literally "might we be in RCU read-side critical section?" like that's the whole vibe check πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

int notrace rcu_read_lock_held (void );

🌸 ARGUMENTS 🌸

  • void β€” no arguments, babe. zero. none. she takes nothing and she gives everything ✨

πŸ’– DESCRIPTION πŸ’–

okay so here's the tea πŸ“: if CONFIG_DEBUG_LOCK_ALLOC is selected, this returns nonzero iff you're in an RCU read-side critical section. iykyk 😌

in the absence of CONFIG_DEBUG_LOCK_ALLOC, this one just assumes we are in an RCU read-side critical section unless it can prove otherwise. she's trusting like that 🫢 this is useful for debug checks in functions that require that they be called within an RCU read-side critical section β€” basically "hey are you where you're supposed to be" energy πŸ”₯

she also checks debug_lockdep_rcu_enabled to prevent false positives during boot and while lockdep is disabled. thoughtful queen πŸ‘‘

⚠️ note bestie: rcu_read_lock and the matching rcu_read_unlock must occur in the same context. for example, it is illegal to invoke rcu_read_unlock in process context if the matching rcu_read_lock was invoked from within an irq handler. like... do not do that. that's a no from me πŸ™ˆ
⚠️ also note: rcu_read_lock is disallowed if the CPU is either idle or offline from an RCU perspective, so check for those as well. main character energy requires a CPU that's actually online, fr fr πŸ’€

πŸ’œ SEE ALSO πŸ’œ

Kernel file ./kernel/rcu/update.c

the whole friend group, iconic lineup honestly πŸ‘‘πŸŒˆ


and that's the page!! πŸ’« brought to you by ./kernel/rcu, dated October 2026, and signed off with so much love β€” go forth and check your RCU contexts responsibly bestie πŸ§šπŸ’œ

πŸ“¦ where this page comes from