skills/kernel-dev/kernel-concurrency/SKILL.md
Kernel concurrency skill for Linux locking and synchronization. Use when choosing spinlocks vs mutexes, using RCU, seqlocks, completions, or applying memory barriers in kernel code. Activates on queries about kernel spinlock, mutex, RCU, seqlock, memory barrier, or PREEMPT_RT locking.
npx skillsauth add mohitmishra786/low-level-dev-skills kernel-concurrencyInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Guide agents through synchronization in the Linux kernel: spinlocks, mutexes, semaphores, RCU, seqlocks, completions, and memory ordering rules — critical for correct drivers and subsystem patches.
probe vs ioctl pathsscheduling while atomicContext can sleep?
├── No (IRQ, spinlock held, preempt disabled)
│ └── spin_lock_irqsave() / atomic_t
└── Yes
├── Exclusive long-held → mutex
├── Reader/writer → rw_semaphore or RCU (read-mostly)
└── One-shot signal → completion
Never sleep while holding a spinlock (kmalloc(GFP_KERNEL), mutex_lock).
spinlock_t lock;
unsigned long flags;
spin_lock_irqsave(&lock, flags);
/* critical section — no blocking */
spin_unlock_irqrestore(&lock, flags);
Use spin_lock_bh when softirq/tasklet sharing is the concern.
struct mutex m;
mutex_lock(&m);
/* may allocate, may sleep */
mutex_unlock(&m);
/* Readers — no lock */
rcu_read_lock();
p = rcu_dereference(ptr);
/* use p */
rcu_read_unlock();
/* Writer */
new = kmalloc(...);
rcu_assign_pointer(ptr, new);
synchronize_rcu();
kfree(old);
RCU readers must not block indefinitely. Grace period completes after all CPUs quiescent.
unsigned seq;
do {
seq = read_seqbegin(&seqlock);
/* read shared data */
} while (read_seqretry(&seqlock, seq));
Writer uses write_seqlock / write_sequnlock.
DECLARE_COMPLETION(done);
/* waiter */
wait_for_completion(&done);
/* signaller */
complete(&done);
Kernel provides smp_mb(), smp_wmb(), smp_rmb(). Device MMIO uses readl/writel (ordered on most arches). See skills/low-level-programming/memory-model for userspace analogies.
/kernel-concurrency Protect shared ring buffer between IRQ and read() syscall
| Symptom | Cause | Fix |
|---------|-------|-----|
| scheduling while atomic | Sleep under spinlock | Use GFP_ATOMIC or defer work |
| Deadlock | AB-BA mutex order | Global lock ordering |
| RCU stall | Reader blocked too long | rcu_read_lock section minimal |
| Lost wake | complete before wait | Use INIT_COMPLETION each cycle |
| Corrupt counter | Non-atomic RMW in IRQ | atomic_t or lock |
skills/kernel/device-drivers — threaded IRQ patternskills/low-level-programming/memory-model — C11 atomics vs kernelskills/debuggers/concurrency-debugging — userspace TSanskills/kernel/kernel-internals — scheduler preemptionskills/profilers/linux-perf — lock contention profilingdevelopment
QEMU/KVM skill for virtualization and kernel development. Use when running qemu-system-x86_64 with KVM, configuring virtio devices, VFIO passthrough, QMP monitor, libvirt, or booting custom kernels. Activates on queries about QEMU, KVM, virtio, VFIO, virsh, virt-install, or -kernel -append.
development
Hardware virtualization internals skill for Intel VT-x and AMD-V. Use when studying VMCS/VMCB, EPT/NPT page tables, VMEXIT handling, APIC virtualization, or building minimal hypervisors. Activates on queries about VMX, SVM, VMCS, EPT, NPT, VMEXIT, or type-1 hypervisor.
testing
Linux containers internals skill for namespaces, cgroups, and OCI. Use when understanding clone/unshare namespaces, cgroups v2 limits, overlayfs, runc, seccomp profiles, capabilities, or escape mitigations. Activates on queries about namespaces, cgroups, overlayfs, runc, seccomp-bpf, OCI spec, or container escape.
tools
Reverse engineering skill for binary analysis. Use when decompiling with Ghidra, analyzing with radare2, scripting RE tools, triaging with strings/file/xxd, or diffing binaries. Activates on queries about Ghidra, radare2, r2, decompiler, Binary Ninja, Diaphora, or stripped binary analysis.