Kernel Modules and Device Drivers

In Linux

LDD3: Chapters 1 & 2

Questions to answer

  • What are devices and drivers?
  • What are Linux kernel modules?
  • What are key differences between kernelspace and userspace?

What is a device?

  • A physical component that is attached to the cpu
  • The “organs” of the computer
  • A replaceable component
    • Mostly

What is a device driver?

  • Bridge OS/Hardware gap
  • Allow users to talk to device
  • OS <-> driver <-> CPU <--> devices


slide 9

What is a Kernel Module

  • Snippet of code that can be added to a running kernel

Why Kernel Modules for Device Drivers?

  • Keep kernel text/data minimal
  • Change text/data without reboot
  • More customization
  • Less error surface
  • Easier to develop
  • Can add hardware at runtime
    • (if you know its address)

We are not in Kansas anymore

  • Goodbye main
  • Goodbye C standard library
  • Goodbye IEEE754
  • Hello ring 0 (x86_64)/EL1 (aarch64)
  • Hello asynchronous execution
  • Hello kernel API

Kernelspace vs Userspace

  • Small, fixed-size stack
  • Each mode can have it’s own address space
  • Kernel space handles access to hardware
  • Execution is transferred to kernel space after a system call

Reentrant code