linux device drivers overview
DESCRIPTION
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. - PowerPoint PPT PresentationTRANSCRIPT
Linux Device Driversoverview
Jeff Foster
Linux Device Drivers overview, September 12, 2000 2
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 3
(Some of) Our Goals
Find bugs in existing driversShow existing drivers don’t have
bugsHelp people write new drivers
Mismatch with book
Linux Device Drivers overview, September 12, 2000 4
What to Look For
Discussion of common mistakesAPI 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 5
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 finerSymbol table interface changedMany fast/slow call distinctions gone/dev changing in the future (currently awful)
Linux Device Drivers overview, September 12, 2000 6
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 7
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 8
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 9
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 placeAre they used correctly? consistently?
Linux Device Drivers overview, September 12, 2000 10
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 11
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 12
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?