Coding: Fix Sleep While Atomic (Slideshow)¶
Simple Spinlock Usage: spin_lock()
¶
Replace
struct mutex
withspinlock_t
Use plain
spin_lock()
Test
Two tight loops injecting events via
ioctl()
Generate interrupts in parallel
⟶ hang sooner or later
Discuss Call Chain, IRQ State¶
Event: spin lock taken from ISR directly, top-level
What if caller already holds a spinlock?
⟶
spin_unlock()
unconditionally reenables interrupts⟶ conversely,
spin_lock()
unconditionally disables interrupts
Enter spin_lock_irqsave()
, spin_unlock_irqrestore()
¶
Fix
Test
Gone
Ah, kmalloc()
¶
event.c
: still usingGFP_KERNEL
Called from interrupt service routine!
CONFIG_DEBUG_ATOMIC_SLEEP
would have complained loudly
Fix
Pass
gfp_t
parameter tomy_event_list_add()