SlideShare a Scribd company logo
1 of 28
Download to read offline
Introduction to
Linux Kernel
Development
Your first patch
Levente Kurusa
Linux kernel hacker & enthusiast
Fedora Project Hungary
<levex@linux.com>
Developer Conference 2014, Brno, CZ.
Topics
# 1 General introduction
# 2 Building
# 3 Kernel API
# 4 Patching
# 5 Sending it of
General Introduction
What is a kernel?
The operating system's core
Responsibilities:
# 1 Initialise the system for the user
# 2 Protect the data
# 3 Introduce abstractions to help the
development of new software
Kernel types
# 1 Microkernel
# 2 Monolithic kernel
# 3 Hybrid kernel
Some exotics:
# 1 Exokernel
# 2 Cache kernel
Linux specifics
# 1 Monolithic kernel
# 2 Modular
# 3 Error-happens-so-panic type
The source of panic()
“ I remarked to Dennis that easily half the code I
was writing in Multics was error recovery code. He
said, "We left all that stuf out. If there's an error,
we have this routine called panic, and when it is
called, the machine crashes, and you holler down
the hall, 'Hey, reboot it.'” “
-- Tom van Vleck to Dennis Ritchie
Building
Kconfig
Allows for specific code to be excluded via optional
preprocessor macros.
Why do we need this?
# 1 To allow diferent configurations!
# 2 Headers are lengthy!
(and incomprehensible anyways)
Kconfig symbols
Specific symbols that will be converted to
CONFIG_* preprocessor defines.
Types:
# 1 bool (true or false) [y, n]
# 2 tristate (built-in, module, false) [y, m ,n]
They have default values
Kconfig example
config ATA_ACPI
bool "ATA ACPI Support"
depends on ACPI && PCI
default y
help
This option adds support for ATA-related ACPI objects.
These ACPI objects add the ability to retrieve taskfiles
from the ACPI BIOS and write them to the disk
controller.
These objects may be related to performance, security,
power management, or other areas.
Makefiles are still in use!
We still use makefiles to define the relations between the
source files.
GNU Make gives us a pretty cool interface!
We don't reinvent the wheel!
How to configure?
Configuration is easy thanks to GNU make!
# 1 'make defconfig' -> Create a default configuration for
$ARCH
# 2 'make menuconfig' -> Shows a cool ncurses menu, which
allows pretty configuration
# 3 'make randconfig' -> Randomly configure the kernel
# 4 'make xconfig' -> For all the GUI fans out there!
Building
Configuration completed, let's build.
'make -j`nproc`'
(Looks way cooler than 'make -j4')
Post-build
To actually boot, you will need an initrd or initramfs.
The kernel file that needs to be booted will be at:
./$ARCH/boot/bzImage
Or if you need the vmlinux file it will be in the root.
Introduction to Kernel API
No C library, no developer
Most developers flee when they see they can't use printf()
But wait, there is a replacement for that! printk()
Actually, the relevant parts from the C library are there!
This means: sscanf(), [vscn]printf(), kstrtoX() etc...
Thread-safety concerns
Since the kernel supports Symmetric MultiProcessing, we need
ways to achieve mutual exclusion.
This is what we have in store:
# 1 mutex (with global/local IRQ disable, full flags save)
# 2 semaphores!
# 3 spinlock_t
A cool module system
Your device will most likely not used by all users, so modules
are a great way.
Modules are built-up like this:
# 1 module_init(init function ptr);
Shows which function will be called when the module is
passed to insmod
# 2 module_exit(exit function ptr);
This function will be called when your module is
rmmod'd.
PCI drivers
PCI drivers are built up in the exact same way, but they also
have a table consisting of pci_device_id's.
To register your PCI driver, you would call:
pci_register_driver(ptr-to-pci_operations-struct);
This together with a probe() function will suffice.
kobjects
Kobjects are primitives that are parts of a garbage collection
system.
Kobjects are usually 'inlined' in a container struct which handles
them.
They have a few helper functions i.e.
kobj_{put,get}(struct kobject *kobj);
They have types! (struct kobj_type)
Patching
Contibuting to the Kernel
# 1 Reviewing patches for common errors
# 2 Building randconfigs
# 3 Adding support for new device
# 4 Fixing a bug
# 5 Doing staging work
This is what we will do!
checkpatch.pl
Excellent utility to find code-style errors!
Sometimes it also finds bugs!
All patches have to be checkpatch-safe before being applied!
Code style?
# 1 Code style contributes to the consistency of the kernel
# 2 Helps to spot bugs
# 3 Don't be afraid, this isn't that terribly bad code style!
Developer Certificate
of Origin
# 1 I created this change and I have the right to post it; or
# 2 The change is based on a previous change under the
same license.
# 3 The change was sent to me by someone who has
certified any of these options.
Sending it of
Thanks for your attention!
Levente Kurusa
<levex@linux.com>
Developer Conference 2014, Brno, CZ. http://devconf.cz/f/105

More Related Content

What's hot

Kernel Recipes 2013 - Crosstool-NG, a cross-toolchain generator
Kernel Recipes 2013 - Crosstool-NG, a cross-toolchain generatorKernel Recipes 2013 - Crosstool-NG, a cross-toolchain generator
Kernel Recipes 2013 - Crosstool-NG, a cross-toolchain generatorAnne Nicolas
 
Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011pundiramit
 
Claudio Scordino - Handling mixed criticality on embedded multi-core systems
Claudio Scordino - Handling mixed criticality on embedded multi-core systemsClaudio Scordino - Handling mixed criticality on embedded multi-core systems
Claudio Scordino - Handling mixed criticality on embedded multi-core systemslinuxlab_conf
 
Kernel Recipes 2013 - ARM support in the Linux kernel
Kernel Recipes 2013 - ARM support in the Linux kernelKernel Recipes 2013 - ARM support in the Linux kernel
Kernel Recipes 2013 - ARM support in the Linux kernelAnne Nicolas
 
Defeating x64: Modern Trends of Kernel-Mode Rootkits
Defeating x64: Modern Trends of Kernel-Mode RootkitsDefeating x64: Modern Trends of Kernel-Mode Rootkits
Defeating x64: Modern Trends of Kernel-Mode RootkitsAlex Matrosov
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux DevelopersOpersys inc.
 
Workshop su Android Kernel Hacking
Workshop su Android Kernel HackingWorkshop su Android Kernel Hacking
Workshop su Android Kernel HackingDeveler S.r.l.
 
Automotive Grade Linux and systemd
Automotive Grade Linux and systemdAutomotive Grade Linux and systemd
Automotive Grade Linux and systemdAlison Chaiken
 
WIndows Kernel-Land exploitation
WIndows Kernel-Land exploitationWIndows Kernel-Land exploitation
WIndows Kernel-Land exploitationkyaw thiha
 
Qi -- Lightweight Boot Loader Applied in Mobile and Embedded Devices
Qi -- Lightweight Boot Loader Applied in Mobile and Embedded DevicesQi -- Lightweight Boot Loader Applied in Mobile and Embedded Devices
Qi -- Lightweight Boot Loader Applied in Mobile and Embedded DevicesNational Cheng Kung University
 
Reconstructing Gapz: Position-Independent Code Analysis Problem
Reconstructing Gapz: Position-Independent Code Analysis ProblemReconstructing Gapz: Position-Independent Code Analysis Problem
Reconstructing Gapz: Position-Independent Code Analysis ProblemAlex Matrosov
 
Build your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectBuild your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectYen-Chin Lee
 
Android is NOT just 'Java on Linux'
Android is NOT just 'Java on Linux'Android is NOT just 'Java on Linux'
Android is NOT just 'Java on Linux'Tetsuyuki Kobayashi
 

What's hot (20)

Kernel Recipes 2013 - Crosstool-NG, a cross-toolchain generator
Kernel Recipes 2013 - Crosstool-NG, a cross-toolchain generatorKernel Recipes 2013 - Crosstool-NG, a cross-toolchain generator
Kernel Recipes 2013 - Crosstool-NG, a cross-toolchain generator
 
Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011
 
Claudio Scordino - Handling mixed criticality on embedded multi-core systems
Claudio Scordino - Handling mixed criticality on embedded multi-core systemsClaudio Scordino - Handling mixed criticality on embedded multi-core systems
Claudio Scordino - Handling mixed criticality on embedded multi-core systems
 
Kernel Recipes 2013 - ARM support in the Linux kernel
Kernel Recipes 2013 - ARM support in the Linux kernelKernel Recipes 2013 - ARM support in the Linux kernel
Kernel Recipes 2013 - ARM support in the Linux kernel
 
Defeating x64: Modern Trends of Kernel-Mode Rootkits
Defeating x64: Modern Trends of Kernel-Mode RootkitsDefeating x64: Modern Trends of Kernel-Mode Rootkits
Defeating x64: Modern Trends of Kernel-Mode Rootkits
 
Linux kernel system call
Linux kernel system callLinux kernel system call
Linux kernel system call
 
Driver_linux
Driver_linuxDriver_linux
Driver_linux
 
Init of Android
Init of AndroidInit of Android
Init of Android
 
Linux kernel booting
Linux kernel bootingLinux kernel booting
Linux kernel booting
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux Developers
 
Workshop su Android Kernel Hacking
Workshop su Android Kernel HackingWorkshop su Android Kernel Hacking
Workshop su Android Kernel Hacking
 
Automotive Grade Linux and systemd
Automotive Grade Linux and systemdAutomotive Grade Linux and systemd
Automotive Grade Linux and systemd
 
Embedded Android : System Development - Part III
Embedded Android : System Development - Part IIIEmbedded Android : System Development - Part III
Embedded Android : System Development - Part III
 
Building Embedded Linux UDOONEO
Building Embedded Linux UDOONEOBuilding Embedded Linux UDOONEO
Building Embedded Linux UDOONEO
 
WIndows Kernel-Land exploitation
WIndows Kernel-Land exploitationWIndows Kernel-Land exploitation
WIndows Kernel-Land exploitation
 
Qi -- Lightweight Boot Loader Applied in Mobile and Embedded Devices
Qi -- Lightweight Boot Loader Applied in Mobile and Embedded DevicesQi -- Lightweight Boot Loader Applied in Mobile and Embedded Devices
Qi -- Lightweight Boot Loader Applied in Mobile and Embedded Devices
 
Reconstructing Gapz: Position-Independent Code Analysis Problem
Reconstructing Gapz: Position-Independent Code Analysis ProblemReconstructing Gapz: Position-Independent Code Analysis Problem
Reconstructing Gapz: Position-Independent Code Analysis Problem
 
Build your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectBuild your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto project
 
Android is NOT just 'Java on Linux'
Android is NOT just 'Java on Linux'Android is NOT just 'Java on Linux'
Android is NOT just 'Java on Linux'
 
Make own you kernel os
Make own you kernel osMake own you kernel os
Make own you kernel os
 

Similar to Introduction to Linux Kernel Development - Your First Patch

Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modulesdibyajyotig
 
Linux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesungLinux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesungdns -
 
BKK16-211 Internet of Tiny Linux (io tl)- Status and Progress
BKK16-211 Internet of Tiny Linux (io tl)- Status and ProgressBKK16-211 Internet of Tiny Linux (io tl)- Status and Progress
BKK16-211 Internet of Tiny Linux (io tl)- Status and ProgressLinaro
 
Mobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversAnil Kumar Pugalia
 
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B KuteUnit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B KuteTushar B Kute
 
Linux Kernel - Let's Contribute!
Linux Kernel - Let's Contribute!Linux Kernel - Let's Contribute!
Linux Kernel - Let's Contribute!Levente Kurusa
 
Linux Kernel Development
Linux Kernel DevelopmentLinux Kernel Development
Linux Kernel DevelopmentPriyank Kapadia
 
Auditing the Opensource Kernels
Auditing the Opensource KernelsAuditing the Opensource Kernels
Auditing the Opensource KernelsSilvio Cesare
 
Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606
Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606
Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606Eunice Lin
 
Kernel init
Kernel initKernel init
Kernel initgowell
 
Embedded Linux from Scratch to Yocto
Embedded Linux from Scratch to YoctoEmbedded Linux from Scratch to Yocto
Embedded Linux from Scratch to YoctoSherif Mousa
 
Exploiting Llinux Environment
Exploiting Llinux EnvironmentExploiting Llinux Environment
Exploiting Llinux EnvironmentEnrico Scapin
 

Similar to Introduction to Linux Kernel Development - Your First Patch (20)

Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
 
Linux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesungLinux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesung
 
Studienarb linux kernel-dev
Studienarb linux kernel-devStudienarb linux kernel-dev
Studienarb linux kernel-dev
 
Building
BuildingBuilding
Building
 
BKK16-211 Internet of Tiny Linux (io tl)- Status and Progress
BKK16-211 Internet of Tiny Linux (io tl)- Status and ProgressBKK16-211 Internet of Tiny Linux (io tl)- Status and Progress
BKK16-211 Internet of Tiny Linux (io tl)- Status and Progress
 
Mobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux Drivers
 
Walking around linux kernel
Walking around linux kernelWalking around linux kernel
Walking around linux kernel
 
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B KuteUnit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
 
淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道 淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道
 
Linux Kernel - Let's Contribute!
Linux Kernel - Let's Contribute!Linux Kernel - Let's Contribute!
Linux Kernel - Let's Contribute!
 
Linux Device Driver’s
Linux Device Driver’sLinux Device Driver’s
Linux Device Driver’s
 
Linux Kernel Development
Linux Kernel DevelopmentLinux Kernel Development
Linux Kernel Development
 
Kernel compilation
Kernel compilationKernel compilation
Kernel compilation
 
Auditing the Opensource Kernels
Auditing the Opensource KernelsAuditing the Opensource Kernels
Auditing the Opensource Kernels
 
Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606
Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606
Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606
 
Kernel init
Kernel initKernel init
Kernel init
 
Embedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernelEmbedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernel
 
Embedded Linux from Scratch to Yocto
Embedded Linux from Scratch to YoctoEmbedded Linux from Scratch to Yocto
Embedded Linux from Scratch to Yocto
 
Rhce ppt
Rhce pptRhce ppt
Rhce ppt
 
Exploiting Llinux Environment
Exploiting Llinux EnvironmentExploiting Llinux Environment
Exploiting Llinux Environment
 

Recently uploaded

Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 

Recently uploaded (20)

🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 

Introduction to Linux Kernel Development - Your First Patch

  • 1. Introduction to Linux Kernel Development Your first patch Levente Kurusa Linux kernel hacker & enthusiast Fedora Project Hungary <levex@linux.com> Developer Conference 2014, Brno, CZ.
  • 2. Topics # 1 General introduction # 2 Building # 3 Kernel API # 4 Patching # 5 Sending it of
  • 4. What is a kernel? The operating system's core Responsibilities: # 1 Initialise the system for the user # 2 Protect the data # 3 Introduce abstractions to help the development of new software
  • 5. Kernel types # 1 Microkernel # 2 Monolithic kernel # 3 Hybrid kernel Some exotics: # 1 Exokernel # 2 Cache kernel
  • 6. Linux specifics # 1 Monolithic kernel # 2 Modular # 3 Error-happens-so-panic type
  • 7. The source of panic() “ I remarked to Dennis that easily half the code I was writing in Multics was error recovery code. He said, "We left all that stuf out. If there's an error, we have this routine called panic, and when it is called, the machine crashes, and you holler down the hall, 'Hey, reboot it.'” “ -- Tom van Vleck to Dennis Ritchie
  • 9. Kconfig Allows for specific code to be excluded via optional preprocessor macros. Why do we need this? # 1 To allow diferent configurations! # 2 Headers are lengthy! (and incomprehensible anyways)
  • 10. Kconfig symbols Specific symbols that will be converted to CONFIG_* preprocessor defines. Types: # 1 bool (true or false) [y, n] # 2 tristate (built-in, module, false) [y, m ,n] They have default values
  • 11. Kconfig example config ATA_ACPI bool "ATA ACPI Support" depends on ACPI && PCI default y help This option adds support for ATA-related ACPI objects. These ACPI objects add the ability to retrieve taskfiles from the ACPI BIOS and write them to the disk controller. These objects may be related to performance, security, power management, or other areas.
  • 12. Makefiles are still in use! We still use makefiles to define the relations between the source files. GNU Make gives us a pretty cool interface! We don't reinvent the wheel!
  • 13. How to configure? Configuration is easy thanks to GNU make! # 1 'make defconfig' -> Create a default configuration for $ARCH # 2 'make menuconfig' -> Shows a cool ncurses menu, which allows pretty configuration # 3 'make randconfig' -> Randomly configure the kernel # 4 'make xconfig' -> For all the GUI fans out there!
  • 14. Building Configuration completed, let's build. 'make -j`nproc`' (Looks way cooler than 'make -j4')
  • 15. Post-build To actually boot, you will need an initrd or initramfs. The kernel file that needs to be booted will be at: ./$ARCH/boot/bzImage Or if you need the vmlinux file it will be in the root.
  • 17. No C library, no developer Most developers flee when they see they can't use printf() But wait, there is a replacement for that! printk() Actually, the relevant parts from the C library are there! This means: sscanf(), [vscn]printf(), kstrtoX() etc...
  • 18. Thread-safety concerns Since the kernel supports Symmetric MultiProcessing, we need ways to achieve mutual exclusion. This is what we have in store: # 1 mutex (with global/local IRQ disable, full flags save) # 2 semaphores! # 3 spinlock_t
  • 19. A cool module system Your device will most likely not used by all users, so modules are a great way. Modules are built-up like this: # 1 module_init(init function ptr); Shows which function will be called when the module is passed to insmod # 2 module_exit(exit function ptr); This function will be called when your module is rmmod'd.
  • 20. PCI drivers PCI drivers are built up in the exact same way, but they also have a table consisting of pci_device_id's. To register your PCI driver, you would call: pci_register_driver(ptr-to-pci_operations-struct); This together with a probe() function will suffice.
  • 21. kobjects Kobjects are primitives that are parts of a garbage collection system. Kobjects are usually 'inlined' in a container struct which handles them. They have a few helper functions i.e. kobj_{put,get}(struct kobject *kobj); They have types! (struct kobj_type)
  • 23. Contibuting to the Kernel # 1 Reviewing patches for common errors # 2 Building randconfigs # 3 Adding support for new device # 4 Fixing a bug # 5 Doing staging work This is what we will do!
  • 24. checkpatch.pl Excellent utility to find code-style errors! Sometimes it also finds bugs! All patches have to be checkpatch-safe before being applied!
  • 25. Code style? # 1 Code style contributes to the consistency of the kernel # 2 Helps to spot bugs # 3 Don't be afraid, this isn't that terribly bad code style!
  • 26. Developer Certificate of Origin # 1 I created this change and I have the right to post it; or # 2 The change is based on a previous change under the same license. # 3 The change was sent to me by someone who has certified any of these options.
  • 28. Thanks for your attention! Levente Kurusa <levex@linux.com> Developer Conference 2014, Brno, CZ. http://devconf.cz/f/105