Kernel Hacking¶
A put-together of kernel related topics.
Topics and Dependencies¶
- Modern Character Devices
- File Operations on Character Devices
- Coding: First Functionality
- Character Device Basics
- Coding: Multiple Devices
- Coding: Refactoring
- DMA
- Fedora: Building the Kernel
- Fedora: Building External Kernel Modules
- Module Loading, Hello World
- Coding: Raspi GPIO Interrupts
- Interrupts
- IO Memory
- Dynamic Memory:
kmalloc()
- Doubly Linked Lists
- Coding: Fix Race Condition (Mutex)
- Mutex (and RT Mutex)
- Network Devices
- PCI
- Process vs.Atomic Context
- Raspberry Pi: Building the Kernel
- Coding: Fix Sleep While Atomic
- Spinlock (vs. Mutex)
dup()
,fork()
, and Reference Counting (Stub)- Coding: Timed Event
- Timer Management
- Accessing Userspace Memory
- Waiting for Something
- Workqueue
Group Description¶
Process vs.Atomic Context (kernel.process_vs_atomic)
Interrupts (kernel.interrupt)
Fedora: Building the Kernel (kernel.fedora_kernel_build)
Fedora: Building External Kernel Modules (kernel.fedora_module_build)
Module Loading, Hello World (kernel.modules_hello_world)
IO Memory (kernel.iomemory)
Dynamic Memory: kmalloc() (kernel.kmalloc)
DMA (kernel.dma)
PCI (kernel.pci)
Raspberry Pi: Building the Kernel (kernel.raspi_kernel_build)
Workqueue (kernel.workqueue)
Accessing Userspace Memory (kernel.usermem)
Character Device Basics (kernel.cdev_manual)
Modern Character Devices (kernel.cdev_auto)
dup(), fork(), and Reference Counting (Stub) (kernel.stub_sysprog_dup)
File Operations on Character Devices (kernel.cdev_file_operations)
Waiting for Something (kernel.waitqueue)
Spinlock (vs. Mutex) (kernel.spinlock)
Doubly Linked Lists (kernel.list)
Mutex (and RT Mutex) (kernel.mutex)
Timer Management (kernel.timer)
Network Devices (kernel.netdev)
Sample Code Maintenance¶
Github repo here
Directory
_morph
holdsmy_driver.c
, which is the base for livehacking sessionsmy_driver.c
is morphed as we goBranch tree (not merged back)
Branch
my_driver_hello
Topic
Branch
Contents
The root of everything
Makefile
, buildModule loading,
init()
,exit()
.
Status
DONE
Branch
my_driver_cdev_manual
Topic
Branch
Contents
History: static device numbers
Character device basics
Status
DONE
Branch
my_driver_cdev_dynamic_major
Topic
Branch
Contents
Dynamic device number allocation
devtmpfs
andsysfs
Status
…
Branch
my_driver_cdev_file_operations
Topic
Branch
Contents
History: static device numbers
Character device basics
struct file_operations
open()
ioctl()
and_IO*()
macros
Status
DONE
Branch
my_driver_cdev_first_functionality
Topic
Branch
Contents
Doubly linked list
Basic OO
Simple
ioctl
Userspace
ioctl
usage
Status
DONE
Branch
my_driver_cdev_refactoring
Topic
Branch
Contents
Separate files
My Device encapsulation of matters
My Device as
filp->private_data
Status
DONE
Branch
my_driver_multiple_devices
Topic
Branch
Contents
…
Status
…
Branch
my_driver_mutex
Topic
Branch
Contents
Race on unprotected lists
Mutex
RT mutex
“Interruptible”
Status
DONE
Branch
my_driver_interrupt
Topic
Branch
Contents
Short GPIO introduction ⟶ move to Raspi
Request and free IRQ
Atomic?
Status
DONE
Branch
my_driver_spinlock_atomic
.Topic
Branch
Contents
Spinlock usage
Spinlock caveats (sleep/atomic)
Status
DONE
Branch
my_driver_time_timer
.Topic
Branch
Contents
jiffies
Timer wheel methods
Status
DONE
Branch
my_driver_workqueue
.Topic
Branch
Contents
Workqueue
Getting rid of atomic code
Realtime priorities
Status
DONE
Branch
my_driver_usermem
.Topic
Branch
Contents
copy_{to,from}_user()
Status
DONE
Branch
my_driver_waitqueue
.Topic
Branch
Contents
Wait queues
Blocking vs. nonblocking
read()
EAGAIN
and EOF
Status
DONE
To Do List¶
Networking
https://www.cs.dartmouth.edu/~sergey/netreads/path-of-packet/Lab9_modified.pdf
-
Topic “Kernel Source”
“Kernel Modules”? Probably aggregate into Module Loading, Hello World
“Kernel Internals”?
0520-kernel-communication
0521-kernel-kmalloc (GFP etc, depend interrupts on it)
0525-kernel-io-memory
0532-kernel-threaded-interrupts
0710-kernel-preempt-rt
Aggregate
_morph/
branches top-levelBring source code into slides/screenplays
Userspace/kernel picture from sysprog.
In topics that refer to github code, mention branch where code is maintained. (code-block caption)
SEO
meta
everywheresidebars with backlinks to this document
this document: course description