drm_panic_trylock(9)
π drm_panic_trylock(9) β from the Kernel API Manual, bestie π
okay so picture this: it's a kernel panic, everything is on fire π₯, and you need to print something to the screen right now. This little function, drm_panic_trylock(9), is your girl. She's the one who tries to get you into the panic printing critical section. No cap.
β¨ SYNOPSIS β¨
drm_panic_trylock (dev , flags );
π ARGUMENTS π
devβ astruct drm_device. that's your device, bestie π«Άflagsβunsigned longirq flags. you literally have to pass these to the unlock counterpart, so don't lose them, iykyk π
πΈ DESCRIPTION πΈ
So any panic printing code must call this function. like, mandatory, periodt. And if the trylock fails? You abort the whole panic printing attempt. no arguments, no second chances π
While you're holding the panic lock, the panic printing code is allowed to assume the following, and honestly? it's giving main character energy:
- anything protected by
drm_panic_lockanddrm_panic_unlockpairs is safe to access. go off π - furthermore, the panic printing code only registers in
drm_dev_unregisterand gets removed indrm_dev_unregister. this lets the panic code safely access any state that's invariant in between those two function calls β like the list of planesdrm_mode_config.plane_list, or most of thestruct drm_planestructure. iconic.
And specifically, thanks to the protection around plane updates in drm_atomic_helper_swap_state, you get these extra guarantees too:
- it is safe to dereference the
drm_plane.statepointer β¨ - anything in
struct drm_plane_stateβ or your driver's subclass of it β that stays invariant after the atomic check code has finished is safe to access. specifically, this includes the reference counted pointers to framebuffer and buffer objects π¦ - anything set up by
drm_plane_helper_funcs.fb_prepareand cleaned up bydrm_plane_helper_funcs.fb_cleanupis safe to access, as long as it stays invariant between those two calls. this also means that for drivers using dynamic buffer management the framebuffer is pinned, and therefore all relevant datastructures can be accessed without taking any further locks (which would be impossible in panic context anyway). slay π - importantly β software and hardware state set up by
drm_plane_helper_funcs.begin_fb_accessanddrm_plane_helper_funcs.end_fb_accessis not safe to access. nope. do not. π«
β οΈ drivers must not make any assumptions about the actual state of the hardware, unless they explicitly protected that hardware access withdrm_panic_lockanddrm_panic_unlock. read it again. internalize it. fr fr.
β RETURN β
0when failing to acquire the raw spinlock- nonzero on success
(yes, that's inverted from what your brain wants it to be β 0 means it failed. lowkey cursed but that's the deal π)
π SEE ALSO π
Kernel file ./include/drm/drm_panic.h β plus struct drm_scanout_buffer(9), drm_panic_lock(9), and drm_panic_unlock(9). go read the whole squad π«Ά
okay that's the whole page, bestie π this one lives in ./include/drm, dated October 2026, and it's filed under drm_panic_trylock(9) β now go forth and panic-print responsibly, mwah π§π
π¦ 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