SlideShare a Scribd company logo
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
Ad

More Related Content

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
Anne Nicolas
 
Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011
pundiramit
 
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
linuxlab_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 kernel
Anne 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 Rootkits
Alex Matrosov
 
Linux kernel system call
Linux kernel system callLinux kernel system call
Linux kernel system call
Ramin Farajpour Cami
 
Driver_linux
Driver_linuxDriver_linux
Driver_linux
Sayanton Vhaduri
 
Init of Android
Init of AndroidInit of Android
Init of Android
Tetsuyuki Kobayashi
 
Linux kernel booting
Linux kernel bootingLinux kernel booting
Linux kernel booting
Ramin Farajpour Cami
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux Developers
Opersys inc.
 
Workshop su Android Kernel Hacking
Workshop su Android Kernel HackingWorkshop su Android Kernel Hacking
Workshop su Android Kernel Hacking
Develer S.r.l.
 
Automotive Grade Linux and systemd
Automotive Grade Linux and systemdAutomotive Grade Linux and systemd
Automotive Grade Linux and systemd
Alison Chaiken
 
Embedded Android : System Development - Part III
Embedded Android : System Development - Part IIIEmbedded Android : System Development - Part III
Embedded Android : System Development - Part III
Emertxe Information Technologies Pvt Ltd
 
Building Embedded Linux UDOONEO
Building Embedded Linux UDOONEOBuilding Embedded Linux UDOONEO
Building Embedded Linux UDOONEO
NEEVEE Technologies
 
WIndows Kernel-Land exploitation
WIndows Kernel-Land exploitationWIndows Kernel-Land exploitation
WIndows Kernel-Land exploitation
kyaw 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 Devices
National 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 Problem
Alex 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 project
Yen-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
 
Make own you kernel os
Make own you kernel osMake own you kernel os
Make own you kernel os
Ramin Farajpour Cami
 
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
Anne Nicolas
 
Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011
pundiramit
 
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
linuxlab_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 kernel
Anne 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 Rootkits
Alex Matrosov
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux Developers
Opersys inc.
 
Workshop su Android Kernel Hacking
Workshop su Android Kernel HackingWorkshop su Android Kernel Hacking
Workshop su Android Kernel Hacking
Develer S.r.l.
 
Automotive Grade Linux and systemd
Automotive Grade Linux and systemdAutomotive Grade Linux and systemd
Automotive Grade Linux and systemd
Alison Chaiken
 
WIndows Kernel-Land exploitation
WIndows Kernel-Land exploitationWIndows Kernel-Land exploitation
WIndows Kernel-Land exploitation
kyaw 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 Devices
National 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 Problem
Alex 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 project
Yen-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
 

Similar to Introduction to Linux Kernel Development (20)

Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
dibyajyotig
 
Linux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesungLinux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesung
dns -
 
Studienarb linux kernel-dev
Studienarb linux kernel-devStudienarb linux kernel-dev
Studienarb linux kernel-dev
murali_purushothaman
 
Building
BuildingBuilding
Building
Satpal Parmar
 
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
Linaro
 
Mobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux Drivers
Anil Kumar Pugalia
 
Walking around linux kernel
Walking around linux kernelWalking around linux kernel
Walking around linux kernel
Dharshana Kasun Warusavitharana
 
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
Tushar B Kute
 
淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道 淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道
National Cheng Kung University
 
Linux Kernel - Let's Contribute!
Linux Kernel - Let's Contribute!Linux Kernel - Let's Contribute!
Linux Kernel - Let's Contribute!
Levente Kurusa
 
Linux Device Driver’s
Linux Device Driver’sLinux Device Driver’s
Linux Device Driver’s
Rashmi Warghade
 
Linux Kernel Development
Linux Kernel DevelopmentLinux Kernel Development
Linux Kernel Development
Priyank Kapadia
 
Kernel compilation
Kernel compilationKernel compilation
Kernel compilation
Ganesh Chavan
 
Auditing the Opensource Kernels
Auditing the Opensource KernelsAuditing the Opensource Kernels
Auditing the Opensource Kernels
Silvio Cesare
 
Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606
Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606
Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606
Eunice Lin
 
Kernel init
Kernel initKernel init
Kernel init
gowell
 
Linux Device Driver for Writing a real world driver for embedded Linux
Linux Device Driver for Writing a real world driver for embedded LinuxLinux Device Driver for Writing a real world driver for embedded Linux
Linux Device Driver for Writing a real world driver for embedded Linux
AchyuthShettigar2
 
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
Emertxe Information Technologies Pvt Ltd
 
Compiling kernel.pdf Compiling kernel Compiling kernel
Compiling kernel.pdf Compiling kernel Compiling kernelCompiling kernel.pdf Compiling kernel Compiling kernel
Compiling kernel.pdf Compiling kernel Compiling kernel
RaghuBR9
 
Embedded Linux from Scratch to Yocto
Embedded Linux from Scratch to YoctoEmbedded Linux from Scratch to Yocto
Embedded Linux from Scratch to Yocto
Sherif Mousa
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
dibyajyotig
 
Linux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesungLinux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesung
dns -
 
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
Linaro
 
Mobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux Drivers
Anil 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 Kute
Tushar 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 Development
Priyank Kapadia
 
Auditing the Opensource Kernels
Auditing the Opensource KernelsAuditing the Opensource Kernels
Auditing the Opensource Kernels
Silvio Cesare
 
Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606
Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606
Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606
Eunice Lin
 
Kernel init
Kernel initKernel init
Kernel init
gowell
 
Linux Device Driver for Writing a real world driver for embedded Linux
Linux Device Driver for Writing a real world driver for embedded LinuxLinux Device Driver for Writing a real world driver for embedded Linux
Linux Device Driver for Writing a real world driver for embedded Linux
AchyuthShettigar2
 
Compiling kernel.pdf Compiling kernel Compiling kernel
Compiling kernel.pdf Compiling kernel Compiling kernelCompiling kernel.pdf Compiling kernel Compiling kernel
Compiling kernel.pdf Compiling kernel Compiling kernel
RaghuBR9
 
Embedded Linux from Scratch to Yocto
Embedded Linux from Scratch to YoctoEmbedded Linux from Scratch to Yocto
Embedded Linux from Scratch to Yocto
Sherif Mousa
 
Ad

Recently uploaded (20)

The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
How to use nRF24L01 module with Arduino
How to use nRF24L01 module with ArduinoHow to use nRF24L01 module with Arduino
How to use nRF24L01 module with Arduino
CircuitDigest
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Journal of Soft Computing in Civil Engineering
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
New Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdfNew Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdf
mohamedezzat18803
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
How to use nRF24L01 module with Arduino
How to use nRF24L01 module with ArduinoHow to use nRF24L01 module with Arduino
How to use nRF24L01 module with Arduino
CircuitDigest
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
New Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdfNew Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdf
mohamedezzat18803
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
Ad

Introduction to Linux Kernel Development

  • 1. Introduction to Linux Kernel Development Your first patch Levente Kurusa Linux kernel hacker & enthusiast Fedora Project Hungary <[email protected]> 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 <[email protected]> Developer Conference 2014, Brno, CZ. http://devconf.cz/f/105