P1 notes: Sorting (Is this relevant this time?) Questions? Please ask. Somebody else probably wonders I depend on questions to fill in stuff I gloss over Kernel Modules! About today: I didn't re-test any of this, to amake it more real LKM: Around since Linux 1.2 (1995) Why? - Debugging - Recompile less often - Reboot less often (reset and update both) - Not slower - Kernel is smaller - Reload a particular driver without rebooting Why not? - More complicated - Management system required for hotplug - I used to dislike them Used for: - Device Drivers (most of the time) - Filesystems - Can add system calls - Network drivers (operate protocol) - Executable interpreter (ELF is normal, can add more) Utilities: insmod rmmod depmod lsmod modinfo modprobe Inserting Modules: insmod or modprobe Unresolved symbols: - Symbols are exported from the kernel OR MODULES - Dependencies among modules - /proc/kallsyms - Use count remove with rmmod or modprobe -r Could not find kernel version - Descriptive error messages are sometimes lacking How do you tell if it worked? - Depends on the module - lsmod will tell you if it's there Automatic Loading - Do you really want this? Maybe...probably not - unload after 1min with autoclean Where are LKMs found? - Usually /lib/modules Versions: Kernel version must match module version - Memory layout, kernel subroutines, etc - Did anything important really change? insmod -f - Symbol versioning - gcc versions - What about multiple kernels? + People do that sometimes... - Symbol licensing errors and viral GPL Boot without device drivers? - This is complicated and probably not a good idea - Loader can load stuff into RAM before kernel starts - Still need to understand FS and run programs How insmod works: init_module system call init_module subroutine in module - Linking is done at insertion time Debugging is possible with kdb Memory: Linux kernel is not pageable - virtual addresses = real addresses Modules can't be paged either, but virtual addresses != real addresses - kmalloc Demo: blink.c /proc filesystem: Demo adding something crypto.c