120 likes | 294 Views
Jeff Foster. Linux Device Drivers overview. Introduction. Goals of Linux Device Drivers Teach people how to write drivers Teach people some programming tricks Serve as reference Target audience: Linux user with no kernel knowledge ...but with a deep understanding of their device.
E N D
Jeff Foster Linux Device Driversoverview
Introduction • Goals of Linux Device Drivers • Teach people how to write drivers • Teach people some programming tricks • Serve as reference • Target audience: • Linux user with no kernel knowledge • ...but with a deep understanding of their device Linux Device Drivers overview, September 12, 2000
(Some of) Our Goals • Find bugs in existing drivers • Show existing drivers don’t have bugs • Help people write new drivers • Mismatch with book Linux Device Drivers overview, September 12, 2000
What to Look For • Discussion of common mistakes • API requirements (KPI?) • driver functions return positive ints on success, negative ints on failure (pp50-51) • kernel won’t call non-blocking I/O functions if previous request still pending (p264) • Invariants • “every kernel function that calls kmalloc (GFP_KERNEL) should be reentrant” (p153) Linux Device Drivers overview, September 12, 2000
What to Ignore • Warning: Out of date! • Written for 2.0.x, little bit on 2.1.x (Chap. 17) • 2.4.x will be released soon • Locking got a lot finer • Symbol table interface changed • Many fast/slow call distinctions gone • /dev changing in the future (currently awful) Linux Device Drivers overview, September 12, 2000
Other Places to Look • The source code! • linux/include/blk.h: “All functions called within end_request() must be atomic.” • Patches to the source (2.2.14) linux/drivers/char/acquirewdt.c -unregister_reboot_notifier(&acq_notifier); +register_reboot_notifier(&acq_notifier); • Linux kernel mailing list (high volume) • The web Linux Device Drivers overview, September 12, 2000
Partial Directory Layout • /usr/src/linux /arch architecture-specific stuff /i386 sometimes you have to look here /drivers device drivers /char character devices -- most modular /block block devices -- more integrated ... /init boot up code /kernel the core OS (e.g., scheduler) /mem black magic • Also /fs, /net, /lib, ... Linux Device Drivers overview, September 12, 2000
Kernel Architecture • It looks like only /drivers interesting • ...but the kernel is more monolithic than it looks • ...especially block devices (buffer management) • char devices better behaved • Start here Linux Device Drivers overview, September 12, 2000
Topic 1: Locking • Four kinds of locks in kernel • Spin locks and read-write locks • Interrupt enable/disable • Sometimes combined, e.g., spin_lock_irq • Whole kernel lock • Locks are used all over the place • Are they used correctly? consistently? Linux Device Drivers overview, September 12, 2000
Topic 2: Interrupt Time • When in_interrupt is true, code cannot • Access current • Call the scheduler (may sleep) • Call kmalloc(GFP_KERNEL) (may sleep) • Copy to/from user-space (may sleep) • more? • Also see Dawson Engler’s work Linux Device Drivers overview, September 12, 2000
Topic 3: Resource Allocation • Drivers get and release system resources • Memory • IRQs • module numbers (maybe) • space for their code (mod usage count) • Are the resources handled correctly? • Leaks lead to instability -- reboot to reclaim Linux Device Drivers overview, September 12, 2000
What We’re Missing • Many errors in drivers are with device interface, not kernel interface • see patch files • No device-specific info in book • How do we find these bugs? Linux Device Drivers overview, September 12, 2000