# sysprog21/lkmpg

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/sysprog21-lkmpg).**

8,511 stars · 618 forks · TeX · OSL-3.0

## Links

- GitHub: https://github.com/sysprog21/lkmpg
- Homepage: https://sysprog21.github.io/lkmpg/
- awesome-repositories: https://awesome-repositories.com/repository/sysprog21-lkmpg.md

## Topics

`books` `c` `device-driver` `documentation` `kernel` `linux` `linux-kernel` `linux-kernel-driver` `linux-kernel-module` `lkm` `lkmpg`

## Description

The Linux Kernel Module Programming Guide is an educational resource that teaches how to write, compile, and manage loadable kernel modules for modern Linux kernels. It covers the complete lifecycle of kernel modules, from building and loading to unloading and debugging, with a focus on extending kernel functionality without recompiling the entire kernel.

The guide provides comprehensive coverage of core kernel programming concepts including dynamic module loading, file-operation registration, interrupt handling, kernel-user data copying, concurrency control, and deferred task scheduling. It also addresses device driver development patterns for PCI, USB, and character devices, along with memory management, synchronization mechanisms such as mutexes, spinlocks, and read-write locks, and timing operations using timers and workqueues.

The material includes practical techniques for kernel debugging and testing, virtual filesystem exports through procfs, sysfs, and debugfs, and safe memory allocation and data transfer between user and kernel address spaces. The guide is designed for Linux 5.0+ kernels and includes instructions for testing modules in a virtual machine environment.

## Tags

### Operating Systems & Systems Programming

- [Linux Kernel Module Management](https://awesome-repositories.com/f/operating-systems-systems-programming/linux-kernel-module-management.md) — The primary subject of the guide: writing and testing loadable kernel modules for Linux 5.0+ kernels.
- [Device Driver IOCTL Communication](https://awesome-repositories.com/f/operating-systems-systems-programming/device-driver-ioctl-communication.md) — Teaches how to pass device-specific control operations from user space to kernel drivers using ioctl. ([source](https://sysprog21.github.io/lkmpg/))
- [Bottom-Half Deferred Work Handlers](https://awesome-repositories.com/f/operating-systems-systems-programming/interrupt-driven-signal-handlers/bottom-half-deferred-work-handlers.md) — Teaches how to defer heavy interrupt work to bottom halves using workqueues and threaded handlers.
- [Kernel Module Debuggers](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-component-debugging/kernel-module-debuggers.md) — Teaches debugging kernel modules using /proc, sysfs, and debugfs interfaces in a virtual machine.
- [Interrupt Handling](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-core-internals/interrupt-handling.md) — Teaches registering callback functions that run immediately when hardware interrupts are triggered. ([source](https://sysprog21.github.io/lkmpg/))
- [Dynamic Module Loaders](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-core-internals/kernel-development/dynamic-module-loaders.md) — Teaches how to insert and remove kernel code segments at runtime using insmod and rmmod.
- [Device Drivers](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-core-internals/kernel-development/kernel-driver-implementation/device-drivers.md) — Teaches creating device drivers for PCI, USB, and character devices that interact with kernel subsystem interfaces.
- [Character Device Registrations](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-core-internals/kernel-development/kernel-driver-implementation/device-drivers/character-device-registrations.md) — Teaches how to register character devices with major numbers and file operations for user-space interaction. ([source](https://sysprog21.github.io/lkmpg/))
- [Dynamic Memory Allocation](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-core-internals/process-and-memory-management/memory-management/allocation-strategies/dynamic-memory-allocation.md) — Teaches dynamic kernel memory allocation using kmalloc and related functions with GFP flags. ([source](https://sysprog21.github.io/lkmpg/))
- [Kernel Memory Allocators and Synchronizers](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-core-internals/process-and-memory-management/memory-management/allocation-strategies/dynamic-memory-allocation/memory-allocation-tracers/kernel-memory-event-tracers/kernel-memory-allocators-and-synchronizers.md) — Covers kernel memory allocation and concurrency control using mutexes, spinlocks, and read-write locks.
- [Deferred Work Schedulers](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-execution-context-layering/interrupt-handlers/deferred-work-schedulers.md) — Covers scheduling deferred work from interrupt handlers using workqueues and threaded handlers. ([source](https://sysprog21.github.io/lkmpg/))
- [Kernel Module Compilation](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-module-compilation.md) — Teaches compiling kernel module source code against the running kernel's build tree to produce a .ko file. ([source](https://sysprog21.github.io/lkmpg/))
- [Kernel-User Data Copying Mechanisms](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-to-user-bridges/kernel-user-data-copying-mechanisms.md) — Teaches safe data transfer between kernel and user spaces using copy_to_user and copy_from_user.
- [User-Kernel Data Copying](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-to-user-bridges/user-kernel-data-copying.md) — Teaches safe data transfer between user and kernel address spaces using dedicated copy functions. ([source](https://sysprog21.github.io/lkmpg/))
- [Memory-Mapped I/O](https://awesome-repositories.com/f/operating-systems-systems-programming/memory-mapped-i-o.md) — Teaches reading and writing hardware registers via memory-mapped I/O using architecture-specific accessor functions. ([source](https://sysprog21.github.io/lkmpg/))
- [Mutex-Based Resource Synchronizations](https://awesome-repositories.com/f/operating-systems-systems-programming/mutex-based-resource-synchronizations.md) — Teaches mutex-based synchronization for protecting shared resources in kernel modules. ([source](https://sysprog21.github.io/lkmpg/))
- [Procfs, Sysfs, and Debugfs Exports](https://awesome-repositories.com/f/operating-systems-systems-programming/virtual-filesystem-schemes/procfs-sysfs-and-debugfs-exports.md) — Teaches how to export kernel data to user space via procfs, sysfs, and debugfs virtual files.
- [DMA Setup for Devices](https://awesome-repositories.com/f/operating-systems-systems-programming/direct-memory-access/dma-controllers/dma-setup-for-devices.md) — Teaches how to configure DMA masks and allocate buffers for direct memory access in device drivers. ([source](https://sysprog21.github.io/lkmpg/))
- [Asynchronous Device Notifications](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-core-internals/kernel-development/kernel-driver-implementation/device-drivers/asynchronous-device-notifications.md) — Teaches how to deliver SIGIO signals to user space when a device becomes ready for I/O. ([source](https://sysprog21.github.io/lkmpg/))
- [Character Device Unregistrations](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-core-internals/kernel-development/kernel-driver-implementation/device-drivers/character-device-unregistrations.md) — Teaches how to release major numbers and clean up device nodes during module removal. ([source](https://sysprog21.github.io/lkmpg/))
- [Device Readiness Polling Interfaces](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-core-internals/kernel-development/kernel-driver-implementation/device-drivers/device-readiness-polling-interfaces.md) — Teaches how to implement poll, select, and epoll support for device readiness reporting. ([source](https://sysprog21.github.io/lkmpg/))
- [PCI Device Driver Implementations](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-core-internals/kernel-development/kernel-driver-implementation/device-drivers/pci-device-driver-implementations.md) — Teaches how to write PCI device drivers that bind to hardware and manage resources. ([source](https://sysprog21.github.io/lkmpg/))
- [USB Device Driver Implementations](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-core-internals/kernel-development/kernel-driver-implementation/device-drivers/usb-device-driver-implementations.md) — Teaches how to write USB device drivers that communicate via USB Request Blocks. ([source](https://sysprog21.github.io/lkmpg/))
- [Integer Atomic Operations](https://awesome-repositories.com/f/operating-systems-systems-programming/lock-free-atomic-containers/integer-atomic-operations.md) — Covers atomic integer and bit operations for lock-free concurrency in kernel modules. ([source](https://sysprog21.github.io/lkmpg/))
- [Sysfs Attribute Creations](https://awesome-repositories.com/f/operating-systems-systems-programming/procfs-extractions/container-specific-procfs-and-sysfs-views/sysfs-attribute-creations.md) — Teaches how to expose kernel variables as sysfs files for user-space read and write access. ([source](https://sysprog21.github.io/lkmpg/))

### Data & Databases

- [Kernel File-Operation Registrations](https://awesome-repositories.com/f/data-databases/file-storage-and-metadata-management/local-file-operations/kernel-file-operation-registrations.md) — Teaches how to bind user-space file operations to kernel functions via file_operations structures.
- [Read-Write Lock Shared Data Protection](https://awesome-repositories.com/f/data-databases/acid-transactional-cores/concurrent-read-write-transactions/exclusive-write-access/read-write-lock-shared-data-protection.md) — Teaches read-write locks for optimizing concurrent read access in kernel modules. ([source](https://sysprog21.github.io/lkmpg/))

### Development Tools & Productivity

- [Kernel Module Loaders](https://awesome-repositories.com/f/development-tools-productivity/system-feature-managers/kernel-feature-managers/kernel-module-loaders.md) — Teaches dynamically inserting code segments into the running kernel using insmod. ([source](https://sysprog21.github.io/lkmpg/))
- [Kernel Module Unloaders](https://awesome-repositories.com/f/development-tools-productivity/system-feature-managers/kernel-feature-managers/kernel-module-loaders/kernel-module-unloaders.md) — Teaches removing loaded kernel modules using rmmod and cleaning up resources. ([source](https://sysprog21.github.io/lkmpg/))
- [Module Entry and Exit Point Designators](https://awesome-repositories.com/f/development-tools-productivity/system-feature-managers/kernel-feature-managers/kernel-module-loaders/module-entry-and-exit-point-designators.md) — Teaches designating module_init and module_exit functions for kernel module lifecycle. ([source](https://sysprog21.github.io/lkmpg/))
- [Short](https://awesome-repositories.com/f/development-tools-productivity/execution-delays/short.md) — Teaches short execution delays using udelay, mdelay, and msleep in kernel modules. ([source](https://sysprog21.github.io/lkmpg/))
- [Debugfs Interface Creations](https://awesome-repositories.com/f/development-tools-productivity/system-feature-managers/kernel-feature-managers/kernel-module-loaders/fuse-kernel-module-interfaces/debugfs-interface-creations.md) — Teaches how to create debugfs entries for exporting debugging information from kernel modules. ([source](https://sysprog21.github.io/lkmpg/))

### Programming Languages & Runtimes

- [Workqueue Deferred Work](https://awesome-repositories.com/f/programming-languages-runtimes/deferred-execution/workqueue-deferred-work.md) — Teaches workqueue-based deferred work scheduling for sleeping operations in kernel modules. ([source](https://sysprog21.github.io/lkmpg/))
- [Interrupt and Deferred Work Handlers](https://awesome-repositories.com/f/programming-languages-runtimes/deferred-execution/workqueue-deferred-work/interrupt-and-deferred-work-handlers.md) — Covers registering interrupt handlers and scheduling deferred work via timers, workqueues, and threaded handlers.
- [Spinlocks](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/concurrency-models/concurrency/synchronization-primitives/mutual-exclusion-locks/spinlocks.md) — Teaches spinlock-based synchronization for short critical sections in atomic kernel context. ([source](https://sysprog21.github.io/lkmpg/))
- [Completion-Based Thread Synchronization](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/concurrency-models/concurrency/execution-models/multi-threaded-execution/thread-synchronized-execution/completion-based-thread-synchronization.md) — Teaches kernel completion primitives for blocking threads until a task finishes. ([source](https://sysprog21.github.io/lkmpg/))

### Security & Cryptography

- [Kernel Mutexes and Spinlocks](https://awesome-repositories.com/f/security-cryptography/row-level-security/concurrency-locking/kernel-mutexes-and-spinlocks.md) — Teaches kernel concurrency control using mutexes, spinlocks, and read-write locks.

### Software Engineering & Architecture

- [Kernel Module Lifecycle Hooks](https://awesome-repositories.com/f/software-engineering-architecture/integration-extensibility/extensibility/plugin-architectures/hook-event-orchestration/hook-resolution-lifecycles/lifecycle-hooks/process-exit-hooks/kernel-module-lifecycle-hooks.md) — Teaches how to designate module_init and module_exit functions for kernel module lifecycle management.
- [Condition-Based](https://awesome-repositories.com/f/software-engineering-architecture/execution-pausing/process-sleeping/condition-based.md) — Teaches condition-based process sleeping using wait_event and wake_up primitives. ([source](https://sysprog21.github.io/lkmpg/))
- [Monotonic Time Measurement](https://awesome-repositories.com/f/software-engineering-architecture/monotonic-time-measurement.md) — Teaches monotonic clock time measurement for interval timing in kernel modules. ([source](https://sysprog21.github.io/lkmpg/))

### System Administration & Monitoring

- [Proc File Entry Creations](https://awesome-repositories.com/f/system-administration-monitoring/file-system-monitors/file-creation-watchers/proc-file-entry-creations.md) — Teaches how to create /proc file entries with custom read and write handlers for kernel data export. ([source](https://sysprog21.github.io/lkmpg/))

### DevOps & Infrastructure

- [Timer-Based Deferred Work Scheduling](https://awesome-repositories.com/f/devops-infrastructure/automation-orchestration/task-execution-frameworks/task-job-management/task-schedulers/delayed-task-scheduling/timer-based-deferred-work-scheduling.md) — Teaches kernel timer-based deferred work scheduling for periodic and delayed tasks. ([source](https://sysprog21.github.io/lkmpg/))

### Hardware & IoT

- [GPIO Pin Controllers](https://awesome-repositories.com/f/hardware-iot/gpio-pin-controllers.md) — Teaches how to configure GPIO pins as inputs or outputs and read or set their voltage levels. ([source](https://sysprog21.github.io/lkmpg/))
