SlideShare une entreprise Scribd logo
1  sur  41
Télécharger pour lire hors ligne
Coccinelle: 10 Years of Automated Evolution in the
Linux Kernel
Julia Lawall, Gilles Muller (Inria/LIP6)
September 27, 2018
1
Context
The Linux kernel:
• Open source OS kernel, used in smartphones to supercomputers.
• 16MLOC and rapidly growing.
• Frequent changes to improve correctness and performance.
Issues:
• How to perform evolutions in such a large code base?
• Once a bug is found, how to check whether it occurs elsewhere?
2
How to better maintain large code bases?
Patches: The key to reasoning about change in the Linux kernel.
@@ -1348,8 +1348,7 @@
- fh = kmalloc(sizeof(struct zoran_fh), GFP_KERNEL);
+ fh = kzalloc(sizeof(struct zoran_fh), GFP_KERNEL);
if (!fh) {
dprintk(1,
KERN_ERR "%s: zoran_open(): allocation of zoran_fh failedn",
ZR_DEVNAME(zr));
return -ENOMEM;
}
- memset(fh, 0, sizeof(struct zoran_fh));
3
Coccinelle
A SmPL idea: Raise the level of abstraction to semantic patches.
From:
@@ -1348,8 +1348,7 @@
- fh = kmalloc(sizeof(struct zoran_fh), GFP_KERNEL);
+ fh = kzalloc(sizeof(struct zoran_fh), GFP_KERNEL);
if (!fh) {
dprintk(1,
KERN_ERR "%s: zoran_open(): allocation of zoran_fh failedn",
ZR_DEVNAME(zr));
return -ENOMEM;
}
- memset(fh, 0, sizeof(struct zoran_fh));
4
Coccinelle
A SmPL idea: Raise the level of abstraction to semantic patches.
To:
@@
expression x,E1,E2;
@@
- x = kmalloc(E1,E2);
+ x = kzalloc(E1,E2);
...
- memset(x, 0, E1);
• SmPL = Semantic Patch Language
• Coccinelle applies SmPL semantic patches across a code base.
• Development began in 2006, first released in 2008. 5
Usage in the Linux kernel
2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017
0
200
400
#ofcommits
Coccinelle developers Outreachy interns Dedicated user
0-day Kernel maintainers Others
• Over 5500 commits.
• 44% of the 88 kernel developers who have at least one commit that touches
100 files also have at least one commit that uses Coccinelle.
• 59 semantic patches in the Linux kernel, usable via make coccicheck.
6
How did we get here?
7
Design dimensions
• Expressivity
• Performance
• Correctness guarantees
• Dissemination
Did we make the right decisions?
8
Coccinelle design: expressivity
Original hypothesis: Linux kernel developers will find it easy and convenient to
describe needed code changes in terms of fragments of removed and added code.
@@
expression x,E1,E2;
@@
- x = kmalloc(E1,E2);
+ x = kzalloc(E1,E2);
...
- memset(x, 0, E1);
9
Expressivity evolutions
Confrontation with the real world:
• Many language evolutions: C features, metavariable types, etc.
• Position variables.
– Record and match position of a token.
• Scripting language rules.
– Original goal: bug finding, eg buffer overflows.
– Used in practice for error reporting, counting, etc.
10
Position variables and scripts
@ r @
expression object;
position p
@@
(
drm_connector_reference@p(object)
|
drm_connector_unreference@p(object)
)
@script:python@
object << r.object;
p << r.p;
@@
msg="WARNING: use get/put helpers to reference and dereference %s" % (object)
coccilib.report.print_report(p[0], msg)
11
Status: Use of new features
• 3325 commits contain semantic patches.
• 18% use position variables.
• 5% use scripts.
• 43% of the semantic patches using position variables or scripts are from
outside the Coccinelle team.
• All 59 semantic patches in the Linux kernel use both.
12
Coccinelle design: performance
Goal: Be usable on a typical developer laptop.
Target code base: 5MLOC in Feb 2007, 16.5MLOC in Jan 2018.
Original design choices:
• Intraprocedural, one file at a time.
• Process only .c files, by default.
• Include only local or same-named headers, by default.
• No macro expansion, instead use heuristics to parse macro uses.
• Provide best-effort type inference, but no other program analysis.
13
Performance evolutions
Confrontation with the real world:
• 1, 5, or 15 MLOC is a lot of code.
• Parsing is slow, because of backtracking heuristics.
14
Performance evolutions
Confrontation with the real world:
• 1, 5, or 15 MLOC is a lot of code.
• Parsing is slow, because of backtracking heuristics.
Evolutions:
• Indexing, via glimpse, id-utils.
• Parallelism, via parmap.
14
Status: Performance
0
2,000
4,000
semantic patches
elapsedtime
(sec.)
2 cores (4 threads). i5 CPU 2.30GHz
0
20,000
40,000
semantic patches
numberoffiles
files considered
Based on the 59 semantic patches in the Linux kernel.
15
Coccinelle design: correctness guarantees
Ensure that outermost terms are replaced by like outermost terms
@@
expression x,E1,E2,E3;
@@
- x = kmalloc(E1,E2);
+ x = kzalloc(E1,E2);
...
- memset(x, 0, E1);
No other correctness guarantees:
• Bug fixes and evolutions may not be semantics preserving.
• Improves expressiveness and performance.
• Rely on developer’s knowledge of the code base and ease of creating and
refining semantic patches.
16
Correctness guarantee evolutions
Confrontation with the real world:
Mostly, developer control over readable rules is good enough.
17
Coccinelle design: dissemination strategy
Show by example:
• June 1, 2007: Fix parse errors in kernel code.
• July 6, 2007: Irq function evolution
– Updates in 5 files, in net, atm, and usb
• July 19, 2007: kmalloc + memset −→ kzalloc
– Updates to 166 calls in 146 files.
– A kernel developer responded “Cool!”.
– Violated patch-review policy of Linux.
• July 2008: Use by a non-Coccinelle
developer.
• October 2008: Open-source release.
18
Coccinelle design: dissemination strategy
Show by example:
• June 1, 2007: Fix parse errors in kernel code.
• July 6, 2007: Irq function evolution
– Updates in 5 files, in net, atm, and usb
• July 19, 2007: kmalloc + memset −→ kzalloc
– Updates to 166 calls in 146 files.
– A kernel developer responded “Cool!”.
– Violated patch-review policy of Linux.
• July 2008: Use by a non-Coccinelle
developer.
• October 2008: Open-source release.
@ rule1 @
identifier fn, irq, dev_id;
typedef irqreturn_t;
@@
static irqreturn_t
fn(int irq, void *dev_id)
{ ... }
@@
identifier rule1.fn;
expression E1, E2, E3;
@@
fn(E1, E2
- ,E3
)
19
Dissemination strategy evolutions
Confrontation with the real world:
• Showing by example generated initial interest.
• Organized four workshops: industry participants.
• Presentations at developer conferences: FOSDEM, Linux Plumbers, etc.
• LWN articles by kernel developers.
20
Impact: Changed lines
arch
block
crypto
drivers
fs
include
init
ipc
kernel
lib
mm
net
samples
security
sound
tools
virt
101
103
105
linesofcode(logscale)
Removed lines Added lines
21
Impact: Maintainer use
2008 2009 2010 2011 2012 2013 2014 2015 2016 2017
0
100
200
300
numberofcommits
Cleanups
Bug fixes
22
Impact: Maintainer use examples
TTY. Remove an unused function argument.
• 11 affected files.
DRM. Eliminate a redundant field in a data structure.
• 54 affected files.
Interrupts. Prepare to remove the irq argument from interrupt handlers, and then
remove that argument.
• 188 affected files.
23
Impact: Some recent commits made using Coccinelle
• Wolfram Sang: tree-wide: simplify getting .drvdata: LKML, April 19, 2018
• Kees Cook: treewide: init_timer() -> setup_timer(): b9eaf1872222
• Deepa Dinamani: vfs: change inode times to use struct timespec64:
95582b008388
24
Impact: Intel’s 0-day build-testing service
59 semantic patches in the Linux kernel with a dedicated make target.
2013 2014 2015 2016 2017
0
200
400
#withpatches
api free iterators locks null tests misc
2013 2014 2015 2016 2017
0
100
200
#withmessageonly
25
Coccinelle community
25 contributors
• Most from the Coccinelle team, due to use of OCaml and PL concepts.
• Active mailing list (cocci@systeme.lip6.fr).
Availability
• Packaged for many Linux distros.
Use outside Linux
• RIOT, systemd, qemu, zephyr (in progress), etc.
26
Offshoots: JMake
How do you know if the code you have changed has been checked by the
compiler?
27
Offshoots: JMake
How do you know if the code you have changed has been checked by the
compiler?
• JMake uses heuristics to choose a suitable configuration and mutations to
check that changed lines are compiled.
27
Offshoots: JMake
How do you know if the code you have changed has been checked by the
compiler?
• JMake uses heuristics to choose a suitable configuration and mutations to
check that changed lines are compiled.
• Published in DSN 2017
27
Offshoots: JMake
How do you know if the code you have changed has been checked by the
compiler?
• JMake uses heuristics to choose a suitable configuration and mutations to
check that changed lines are compiled.
• Published in DSN 2017
• http://jmake-release.gforge.inria.fr
27
Offshoots: Prequel
Julia (2011?): Here’s a patch to fix a missing kfree.
28
Offshoots: Prequel
Julia (2011?): Here’s a patch to fix a missing kfree.
Helpful kernel maintainer:
That looks OK, but the code should really be using devm_kzalloc
28
Offshoots: Prequel
Julia (2011?): Here’s a patch to fix a missing kfree.
Helpful kernel maintainer:
That looks OK, but the code should really be using devm_kzalloc
Julia: What’s that???
28
Offshoots: Prequel
Julia (2011?): Here’s a patch to fix a missing kfree.
Helpful kernel maintainer:
That looks OK, but the code should really be using devm_kzalloc
Julia: What’s that???
git grep devm_kzalloc???
git log -S devm_kzalloc???
28
Offshoots: Prequel
Prequel: patch queries for searching commit histories.
Query:
@@
@@
- kzalloc
+ devm_kzalloc
(...)
Returns the most pertinent commits at the top of the result list.
29
Offshoots: Driver backporting
Prequel for driver backporting:
• Compile driver with the target version.
• Use Gcc-reduce to analyze the error messages and construct patch queries.
• Use Prequel to collect examples of the needed changes.
• Scan through the high-ranked results and figure out how to change the code.
30
Offshoots: Driver backporting
Prequel for driver backporting:
• Compile driver with the target version.
• Use Gcc-reduce to analyze the error messages and construct patch queries.
• Use Prequel to collect examples of the needed changes.
• Scan through the high-ranked results and figure out how to change the code.
Published at USENIX ATC 2017. Tested on 33 drivers with 75% success.
http://prequel-pql.gforge.inria.fr
30
Conclusion
• Initial design decisions mostly remain valid, with some extensions.
– Take the expertise of the target users into account.
– Avoid creeping featurism: Do one thing and do it well.
• Tool should be easy to access and install, and easy to use and robust.
• Over 5500 commits in the Linux kernel based on Coccinelle.
• JMake and Prequel inspired by experience with Coccinelle.
31
Conclusion
• Initial design decisions mostly remain valid, with some extensions.
– Take the expertise of the target users into account.
– Avoid creeping featurism: Do one thing and do it well.
• Tool should be easy to access and install, and easy to use and robust.
• Over 5500 commits in the Linux kernel based on Coccinelle.
• JMake and Prequel inspired by experience with Coccinelle.
• Probably, everyone in this room uses some Coccinelle modified code!
31
Conclusion
• Initial design decisions mostly remain valid, with some extensions.
– Take the expertise of the target users into account.
– Avoid creeping featurism: Do one thing and do it well.
• Tool should be easy to access and install, and easy to use and robust.
• Over 5500 commits in the Linux kernel based on Coccinelle.
• JMake and Prequel inspired by experience with Coccinelle.
• Probably, everyone in this room uses some Coccinelle modified code!
http://coccinelle.lip6.fr
Thanks to ANR, Inria, OSADL, Coccinelle users, and many others! 31

Contenu connexe

Tendances

Verilator: Fast, Free, But for Me?
Verilator: Fast, Free, But for Me? Verilator: Fast, Free, But for Me?
Verilator: Fast, Free, But for Me?
DVClub
 
Las16 309 - lua jit arm64 port - status
Las16 309 - lua jit arm64 port - statusLas16 309 - lua jit arm64 port - status
Las16 309 - lua jit arm64 port - status
Linaro
 

Tendances (19)

The Simple Scheduler in Embedded System @ OSDC.TW 2014
The Simple Scheduler in Embedded System @ OSDC.TW 2014The Simple Scheduler in Embedded System @ OSDC.TW 2014
The Simple Scheduler in Embedded System @ OSDC.TW 2014
 
BKK16-207 VLANd in LAVA
BKK16-207 VLANd in LAVABKK16-207 VLANd in LAVA
BKK16-207 VLANd in LAVA
 
BKK16-210 Migrating to the new dispatcher
BKK16-210 Migrating to the new dispatcherBKK16-210 Migrating to the new dispatcher
BKK16-210 Migrating to the new dispatcher
 
LAS16-TR02: Upstreaming 101
LAS16-TR02: Upstreaming 101LAS16-TR02: Upstreaming 101
LAS16-TR02: Upstreaming 101
 
Code review and automated testing for Puppet code
Code review and automated testing for Puppet codeCode review and automated testing for Puppet code
Code review and automated testing for Puppet code
 
LCE13: Test and Validation Summit: Evolution of Testing in Linaro (I)
LCE13: Test and Validation Summit: Evolution of Testing in Linaro (I)LCE13: Test and Validation Summit: Evolution of Testing in Linaro (I)
LCE13: Test and Validation Summit: Evolution of Testing in Linaro (I)
 
HKG15-110: ODP Project Update
HKG15-110: ODP Project UpdateHKG15-110: ODP Project Update
HKG15-110: ODP Project Update
 
BKK16-106 ODP Project Update
BKK16-106 ODP Project UpdateBKK16-106 ODP Project Update
BKK16-106 ODP Project Update
 
LAS16-501: Introduction to LLVM - Projects, Components, Integration, Internals
LAS16-501: Introduction to LLVM - Projects, Components, Integration, InternalsLAS16-501: Introduction to LLVM - Projects, Components, Integration, Internals
LAS16-501: Introduction to LLVM - Projects, Components, Integration, Internals
 
Verilator: Fast, Free, But for Me?
Verilator: Fast, Free, But for Me? Verilator: Fast, Free, But for Me?
Verilator: Fast, Free, But for Me?
 
OVN DBs HA with scale test
OVN DBs HA with scale testOVN DBs HA with scale test
OVN DBs HA with scale test
 
LAS16-207: Bus scaling QoS
LAS16-207: Bus scaling QoSLAS16-207: Bus scaling QoS
LAS16-207: Bus scaling QoS
 
BUD17-300: Journey of a packet
BUD17-300: Journey of a packetBUD17-300: Journey of a packet
BUD17-300: Journey of a packet
 
BUD17-TR02: Upstreaming 101
BUD17-TR02: Upstreaming 101 BUD17-TR02: Upstreaming 101
BUD17-TR02: Upstreaming 101
 
Cinder Project On-Boarding - OpenInfra Summit Denver 2019
Cinder Project On-Boarding - OpenInfra Summit Denver 2019Cinder Project On-Boarding - OpenInfra Summit Denver 2019
Cinder Project On-Boarding - OpenInfra Summit Denver 2019
 
Scaling real world applications using gevent
Scaling real world applications using geventScaling real world applications using gevent
Scaling real world applications using gevent
 
BKK16-203 Irq prediction or how to better estimate idle time
BKK16-203 Irq prediction or how to better estimate idle timeBKK16-203 Irq prediction or how to better estimate idle time
BKK16-203 Irq prediction or how to better estimate idle time
 
Kernel Recipes 2019 - BPF at Facebook
Kernel Recipes 2019 - BPF at FacebookKernel Recipes 2019 - BPF at Facebook
Kernel Recipes 2019 - BPF at Facebook
 
Las16 309 - lua jit arm64 port - status
Las16 309 - lua jit arm64 port - statusLas16 309 - lua jit arm64 port - status
Las16 309 - lua jit arm64 port - status
 

Similaire à Kernel Recipes 2018 - 10 years of automated evolution in the Linux kernel - Julia Lawall

EclipseCon Eu 2015 - Breathe life into your Designer!
EclipseCon Eu 2015 - Breathe life into your Designer!EclipseCon Eu 2015 - Breathe life into your Designer!
EclipseCon Eu 2015 - Breathe life into your Designer!
melbats
 
Abstractions and Directives for Adapting Wavefront Algorithms to Future Archi...
Abstractions and Directives for Adapting Wavefront Algorithms to Future Archi...Abstractions and Directives for Adapting Wavefront Algorithms to Future Archi...
Abstractions and Directives for Adapting Wavefront Algorithms to Future Archi...
inside-BigData.com
 
MattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxMattsonTutorialSC14.pptx
MattsonTutorialSC14.pptx
gopikahari7
 

Similaire à Kernel Recipes 2018 - 10 years of automated evolution in the Linux kernel - Julia Lawall (20)

One bite and all your dreams will come true: Analyzing and Attacking Apple Ke...
One bite and all your dreams will come true: Analyzing and Attacking Apple Ke...One bite and all your dreams will come true: Analyzing and Attacking Apple Ke...
One bite and all your dreams will come true: Analyzing and Attacking Apple Ke...
 
embedded C.pptx
embedded C.pptxembedded C.pptx
embedded C.pptx
 
DevOps Days Boston 2017: Real-world Kubernetes for DevOps
DevOps Days Boston 2017: Real-world Kubernetes for DevOpsDevOps Days Boston 2017: Real-world Kubernetes for DevOps
DevOps Days Boston 2017: Real-world Kubernetes for DevOps
 
Developing Real-Time Systems on Application Processors
Developing Real-Time Systems on Application ProcessorsDeveloping Real-Time Systems on Application Processors
Developing Real-Time Systems on Application Processors
 
Surge2012
Surge2012Surge2012
Surge2012
 
What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)
 
Lecture 4: Deep Learning Frameworks
Lecture 4: Deep Learning FrameworksLecture 4: Deep Learning Frameworks
Lecture 4: Deep Learning Frameworks
 
Efficient and Advanced Omniscient Debugging for xDSMLs (SLE 2015)
Efficient and Advanced Omniscient Debugging for xDSMLs (SLE 2015)Efficient and Advanced Omniscient Debugging for xDSMLs (SLE 2015)
Efficient and Advanced Omniscient Debugging for xDSMLs (SLE 2015)
 
.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3
 
Software Qualitiy with Sonar Tool 2013_4
Software Qualitiy with Sonar Tool 2013_4Software Qualitiy with Sonar Tool 2013_4
Software Qualitiy with Sonar Tool 2013_4
 
OpenSAF Symposium_Python Bindings_9.21.11
OpenSAF Symposium_Python Bindings_9.21.11OpenSAF Symposium_Python Bindings_9.21.11
OpenSAF Symposium_Python Bindings_9.21.11
 
EclipseCon Eu 2015 - Breathe life into your Designer!
EclipseCon Eu 2015 - Breathe life into your Designer!EclipseCon Eu 2015 - Breathe life into your Designer!
EclipseCon Eu 2015 - Breathe life into your Designer!
 
Performance Optimization of Deep Learning Frameworks Caffe* and Tensorflow* f...
Performance Optimization of Deep Learning Frameworks Caffe* and Tensorflow* f...Performance Optimization of Deep Learning Frameworks Caffe* and Tensorflow* f...
Performance Optimization of Deep Learning Frameworks Caffe* and Tensorflow* f...
 
Trends in Systems and How to Get Efficient Performance
Trends in Systems and How to Get Efficient PerformanceTrends in Systems and How to Get Efficient Performance
Trends in Systems and How to Get Efficient Performance
 
What’s eating python performance
What’s eating python performanceWhat’s eating python performance
What’s eating python performance
 
Reverse engineering &amp; immunity debugger
Reverse engineering &amp; immunity debuggerReverse engineering &amp; immunity debugger
Reverse engineering &amp; immunity debugger
 
Abstractions and Directives for Adapting Wavefront Algorithms to Future Archi...
Abstractions and Directives for Adapting Wavefront Algorithms to Future Archi...Abstractions and Directives for Adapting Wavefront Algorithms to Future Archi...
Abstractions and Directives for Adapting Wavefront Algorithms to Future Archi...
 
MattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxMattsonTutorialSC14.pptx
MattsonTutorialSC14.pptx
 
Parsing and Type checking all 2^10000 configurations of the Linux kernel
Parsing and Type checking all 2^10000 configurations of the Linux kernelParsing and Type checking all 2^10000 configurations of the Linux kernel
Parsing and Type checking all 2^10000 configurations of the Linux kernel
 
Learning to Spot and Refactor Inconsistent Method Names
Learning to Spot and Refactor Inconsistent Method NamesLearning to Spot and Refactor Inconsistent Method Names
Learning to Spot and Refactor Inconsistent Method Names
 

Plus de Anne Nicolas

Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataKernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Anne Nicolas
 

Plus de Anne Nicolas (20)

Kernel Recipes 2019 - Driving the industry toward upstream first
Kernel Recipes 2019 - Driving the industry toward upstream firstKernel Recipes 2019 - Driving the industry toward upstream first
Kernel Recipes 2019 - Driving the industry toward upstream first
 
Kernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMI
Kernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMIKernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMI
Kernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMI
 
Kernel Recipes 2019 - Hunting and fixing bugs all over the Linux kernel
Kernel Recipes 2019 - Hunting and fixing bugs all over the Linux kernelKernel Recipes 2019 - Hunting and fixing bugs all over the Linux kernel
Kernel Recipes 2019 - Hunting and fixing bugs all over the Linux kernel
 
Kernel Recipes 2019 - Metrics are money
Kernel Recipes 2019 - Metrics are moneyKernel Recipes 2019 - Metrics are money
Kernel Recipes 2019 - Metrics are money
 
Kernel Recipes 2019 - Kernel documentation: past, present, and future
Kernel Recipes 2019 - Kernel documentation: past, present, and futureKernel Recipes 2019 - Kernel documentation: past, present, and future
Kernel Recipes 2019 - Kernel documentation: past, present, and future
 
Embedded Recipes 2019 - Knowing your ARM from your ARSE: wading through the t...
Embedded Recipes 2019 - Knowing your ARM from your ARSE: wading through the t...Embedded Recipes 2019 - Knowing your ARM from your ARSE: wading through the t...
Embedded Recipes 2019 - Knowing your ARM from your ARSE: wading through the t...
 
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataKernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
 
Kernel Recipes 2019 - Analyzing changes to the binary interface exposed by th...
Kernel Recipes 2019 - Analyzing changes to the binary interface exposed by th...Kernel Recipes 2019 - Analyzing changes to the binary interface exposed by th...
Kernel Recipes 2019 - Analyzing changes to the binary interface exposed by th...
 
Embedded Recipes 2019 - Remote update adventures with RAUC, Yocto and Barebox
Embedded Recipes 2019 - Remote update adventures with RAUC, Yocto and BareboxEmbedded Recipes 2019 - Remote update adventures with RAUC, Yocto and Barebox
Embedded Recipes 2019 - Remote update adventures with RAUC, Yocto and Barebox
 
Embedded Recipes 2019 - Making embedded graphics less special
Embedded Recipes 2019 - Making embedded graphics less specialEmbedded Recipes 2019 - Making embedded graphics less special
Embedded Recipes 2019 - Making embedded graphics less special
 
Embedded Recipes 2019 - Linux on Open Source Hardware and Libre Silicon
Embedded Recipes 2019 - Linux on Open Source Hardware and Libre SiliconEmbedded Recipes 2019 - Linux on Open Source Hardware and Libre Silicon
Embedded Recipes 2019 - Linux on Open Source Hardware and Libre Silicon
 
Embedded Recipes 2019 - From maintaining I2C to the big (embedded) picture
Embedded Recipes 2019 - From maintaining I2C to the big (embedded) pictureEmbedded Recipes 2019 - From maintaining I2C to the big (embedded) picture
Embedded Recipes 2019 - From maintaining I2C to the big (embedded) picture
 
Embedded Recipes 2019 - Testing firmware the devops way
Embedded Recipes 2019 - Testing firmware the devops wayEmbedded Recipes 2019 - Testing firmware the devops way
Embedded Recipes 2019 - Testing firmware the devops way
 
Embedded Recipes 2019 - Herd your socs become a matchmaker
Embedded Recipes 2019 - Herd your socs become a matchmakerEmbedded Recipes 2019 - Herd your socs become a matchmaker
Embedded Recipes 2019 - Herd your socs become a matchmaker
 
Embedded Recipes 2019 - LLVM / Clang integration
Embedded Recipes 2019 - LLVM / Clang integrationEmbedded Recipes 2019 - LLVM / Clang integration
Embedded Recipes 2019 - LLVM / Clang integration
 
Embedded Recipes 2019 - Introduction to JTAG debugging
Embedded Recipes 2019 - Introduction to JTAG debuggingEmbedded Recipes 2019 - Introduction to JTAG debugging
Embedded Recipes 2019 - Introduction to JTAG debugging
 
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimedia
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimediaEmbedded Recipes 2019 - Pipewire a new foundation for embedded multimedia
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimedia
 
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all startedKernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
 
Kernel Recipes 2019 - Suricata and XDP
Kernel Recipes 2019 - Suricata and XDPKernel Recipes 2019 - Suricata and XDP
Kernel Recipes 2019 - Suricata and XDP
 
Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)
Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)
Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)
 

Dernier

CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
anilsa9823
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Dernier (20)

The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 

Kernel Recipes 2018 - 10 years of automated evolution in the Linux kernel - Julia Lawall

  • 1. Coccinelle: 10 Years of Automated Evolution in the Linux Kernel Julia Lawall, Gilles Muller (Inria/LIP6) September 27, 2018 1
  • 2. Context The Linux kernel: • Open source OS kernel, used in smartphones to supercomputers. • 16MLOC and rapidly growing. • Frequent changes to improve correctness and performance. Issues: • How to perform evolutions in such a large code base? • Once a bug is found, how to check whether it occurs elsewhere? 2
  • 3. How to better maintain large code bases? Patches: The key to reasoning about change in the Linux kernel. @@ -1348,8 +1348,7 @@ - fh = kmalloc(sizeof(struct zoran_fh), GFP_KERNEL); + fh = kzalloc(sizeof(struct zoran_fh), GFP_KERNEL); if (!fh) { dprintk(1, KERN_ERR "%s: zoran_open(): allocation of zoran_fh failedn", ZR_DEVNAME(zr)); return -ENOMEM; } - memset(fh, 0, sizeof(struct zoran_fh)); 3
  • 4. Coccinelle A SmPL idea: Raise the level of abstraction to semantic patches. From: @@ -1348,8 +1348,7 @@ - fh = kmalloc(sizeof(struct zoran_fh), GFP_KERNEL); + fh = kzalloc(sizeof(struct zoran_fh), GFP_KERNEL); if (!fh) { dprintk(1, KERN_ERR "%s: zoran_open(): allocation of zoran_fh failedn", ZR_DEVNAME(zr)); return -ENOMEM; } - memset(fh, 0, sizeof(struct zoran_fh)); 4
  • 5. Coccinelle A SmPL idea: Raise the level of abstraction to semantic patches. To: @@ expression x,E1,E2; @@ - x = kmalloc(E1,E2); + x = kzalloc(E1,E2); ... - memset(x, 0, E1); • SmPL = Semantic Patch Language • Coccinelle applies SmPL semantic patches across a code base. • Development began in 2006, first released in 2008. 5
  • 6. Usage in the Linux kernel 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 0 200 400 #ofcommits Coccinelle developers Outreachy interns Dedicated user 0-day Kernel maintainers Others • Over 5500 commits. • 44% of the 88 kernel developers who have at least one commit that touches 100 files also have at least one commit that uses Coccinelle. • 59 semantic patches in the Linux kernel, usable via make coccicheck. 6
  • 7. How did we get here? 7
  • 8. Design dimensions • Expressivity • Performance • Correctness guarantees • Dissemination Did we make the right decisions? 8
  • 9. Coccinelle design: expressivity Original hypothesis: Linux kernel developers will find it easy and convenient to describe needed code changes in terms of fragments of removed and added code. @@ expression x,E1,E2; @@ - x = kmalloc(E1,E2); + x = kzalloc(E1,E2); ... - memset(x, 0, E1); 9
  • 10. Expressivity evolutions Confrontation with the real world: • Many language evolutions: C features, metavariable types, etc. • Position variables. – Record and match position of a token. • Scripting language rules. – Original goal: bug finding, eg buffer overflows. – Used in practice for error reporting, counting, etc. 10
  • 11. Position variables and scripts @ r @ expression object; position p @@ ( drm_connector_reference@p(object) | drm_connector_unreference@p(object) ) @script:python@ object << r.object; p << r.p; @@ msg="WARNING: use get/put helpers to reference and dereference %s" % (object) coccilib.report.print_report(p[0], msg) 11
  • 12. Status: Use of new features • 3325 commits contain semantic patches. • 18% use position variables. • 5% use scripts. • 43% of the semantic patches using position variables or scripts are from outside the Coccinelle team. • All 59 semantic patches in the Linux kernel use both. 12
  • 13. Coccinelle design: performance Goal: Be usable on a typical developer laptop. Target code base: 5MLOC in Feb 2007, 16.5MLOC in Jan 2018. Original design choices: • Intraprocedural, one file at a time. • Process only .c files, by default. • Include only local or same-named headers, by default. • No macro expansion, instead use heuristics to parse macro uses. • Provide best-effort type inference, but no other program analysis. 13
  • 14. Performance evolutions Confrontation with the real world: • 1, 5, or 15 MLOC is a lot of code. • Parsing is slow, because of backtracking heuristics. 14
  • 15. Performance evolutions Confrontation with the real world: • 1, 5, or 15 MLOC is a lot of code. • Parsing is slow, because of backtracking heuristics. Evolutions: • Indexing, via glimpse, id-utils. • Parallelism, via parmap. 14
  • 16. Status: Performance 0 2,000 4,000 semantic patches elapsedtime (sec.) 2 cores (4 threads). i5 CPU 2.30GHz 0 20,000 40,000 semantic patches numberoffiles files considered Based on the 59 semantic patches in the Linux kernel. 15
  • 17. Coccinelle design: correctness guarantees Ensure that outermost terms are replaced by like outermost terms @@ expression x,E1,E2,E3; @@ - x = kmalloc(E1,E2); + x = kzalloc(E1,E2); ... - memset(x, 0, E1); No other correctness guarantees: • Bug fixes and evolutions may not be semantics preserving. • Improves expressiveness and performance. • Rely on developer’s knowledge of the code base and ease of creating and refining semantic patches. 16
  • 18. Correctness guarantee evolutions Confrontation with the real world: Mostly, developer control over readable rules is good enough. 17
  • 19. Coccinelle design: dissemination strategy Show by example: • June 1, 2007: Fix parse errors in kernel code. • July 6, 2007: Irq function evolution – Updates in 5 files, in net, atm, and usb • July 19, 2007: kmalloc + memset −→ kzalloc – Updates to 166 calls in 146 files. – A kernel developer responded “Cool!”. – Violated patch-review policy of Linux. • July 2008: Use by a non-Coccinelle developer. • October 2008: Open-source release. 18
  • 20. Coccinelle design: dissemination strategy Show by example: • June 1, 2007: Fix parse errors in kernel code. • July 6, 2007: Irq function evolution – Updates in 5 files, in net, atm, and usb • July 19, 2007: kmalloc + memset −→ kzalloc – Updates to 166 calls in 146 files. – A kernel developer responded “Cool!”. – Violated patch-review policy of Linux. • July 2008: Use by a non-Coccinelle developer. • October 2008: Open-source release. @ rule1 @ identifier fn, irq, dev_id; typedef irqreturn_t; @@ static irqreturn_t fn(int irq, void *dev_id) { ... } @@ identifier rule1.fn; expression E1, E2, E3; @@ fn(E1, E2 - ,E3 ) 19
  • 21. Dissemination strategy evolutions Confrontation with the real world: • Showing by example generated initial interest. • Organized four workshops: industry participants. • Presentations at developer conferences: FOSDEM, Linux Plumbers, etc. • LWN articles by kernel developers. 20
  • 23. Impact: Maintainer use 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 0 100 200 300 numberofcommits Cleanups Bug fixes 22
  • 24. Impact: Maintainer use examples TTY. Remove an unused function argument. • 11 affected files. DRM. Eliminate a redundant field in a data structure. • 54 affected files. Interrupts. Prepare to remove the irq argument from interrupt handlers, and then remove that argument. • 188 affected files. 23
  • 25. Impact: Some recent commits made using Coccinelle • Wolfram Sang: tree-wide: simplify getting .drvdata: LKML, April 19, 2018 • Kees Cook: treewide: init_timer() -> setup_timer(): b9eaf1872222 • Deepa Dinamani: vfs: change inode times to use struct timespec64: 95582b008388 24
  • 26. Impact: Intel’s 0-day build-testing service 59 semantic patches in the Linux kernel with a dedicated make target. 2013 2014 2015 2016 2017 0 200 400 #withpatches api free iterators locks null tests misc 2013 2014 2015 2016 2017 0 100 200 #withmessageonly 25
  • 27. Coccinelle community 25 contributors • Most from the Coccinelle team, due to use of OCaml and PL concepts. • Active mailing list (cocci@systeme.lip6.fr). Availability • Packaged for many Linux distros. Use outside Linux • RIOT, systemd, qemu, zephyr (in progress), etc. 26
  • 28. Offshoots: JMake How do you know if the code you have changed has been checked by the compiler? 27
  • 29. Offshoots: JMake How do you know if the code you have changed has been checked by the compiler? • JMake uses heuristics to choose a suitable configuration and mutations to check that changed lines are compiled. 27
  • 30. Offshoots: JMake How do you know if the code you have changed has been checked by the compiler? • JMake uses heuristics to choose a suitable configuration and mutations to check that changed lines are compiled. • Published in DSN 2017 27
  • 31. Offshoots: JMake How do you know if the code you have changed has been checked by the compiler? • JMake uses heuristics to choose a suitable configuration and mutations to check that changed lines are compiled. • Published in DSN 2017 • http://jmake-release.gforge.inria.fr 27
  • 32. Offshoots: Prequel Julia (2011?): Here’s a patch to fix a missing kfree. 28
  • 33. Offshoots: Prequel Julia (2011?): Here’s a patch to fix a missing kfree. Helpful kernel maintainer: That looks OK, but the code should really be using devm_kzalloc 28
  • 34. Offshoots: Prequel Julia (2011?): Here’s a patch to fix a missing kfree. Helpful kernel maintainer: That looks OK, but the code should really be using devm_kzalloc Julia: What’s that??? 28
  • 35. Offshoots: Prequel Julia (2011?): Here’s a patch to fix a missing kfree. Helpful kernel maintainer: That looks OK, but the code should really be using devm_kzalloc Julia: What’s that??? git grep devm_kzalloc??? git log -S devm_kzalloc??? 28
  • 36. Offshoots: Prequel Prequel: patch queries for searching commit histories. Query: @@ @@ - kzalloc + devm_kzalloc (...) Returns the most pertinent commits at the top of the result list. 29
  • 37. Offshoots: Driver backporting Prequel for driver backporting: • Compile driver with the target version. • Use Gcc-reduce to analyze the error messages and construct patch queries. • Use Prequel to collect examples of the needed changes. • Scan through the high-ranked results and figure out how to change the code. 30
  • 38. Offshoots: Driver backporting Prequel for driver backporting: • Compile driver with the target version. • Use Gcc-reduce to analyze the error messages and construct patch queries. • Use Prequel to collect examples of the needed changes. • Scan through the high-ranked results and figure out how to change the code. Published at USENIX ATC 2017. Tested on 33 drivers with 75% success. http://prequel-pql.gforge.inria.fr 30
  • 39. Conclusion • Initial design decisions mostly remain valid, with some extensions. – Take the expertise of the target users into account. – Avoid creeping featurism: Do one thing and do it well. • Tool should be easy to access and install, and easy to use and robust. • Over 5500 commits in the Linux kernel based on Coccinelle. • JMake and Prequel inspired by experience with Coccinelle. 31
  • 40. Conclusion • Initial design decisions mostly remain valid, with some extensions. – Take the expertise of the target users into account. – Avoid creeping featurism: Do one thing and do it well. • Tool should be easy to access and install, and easy to use and robust. • Over 5500 commits in the Linux kernel based on Coccinelle. • JMake and Prequel inspired by experience with Coccinelle. • Probably, everyone in this room uses some Coccinelle modified code! 31
  • 41. Conclusion • Initial design decisions mostly remain valid, with some extensions. – Take the expertise of the target users into account. – Avoid creeping featurism: Do one thing and do it well. • Tool should be easy to access and install, and easy to use and robust. • Over 5500 commits in the Linux kernel based on Coccinelle. • JMake and Prequel inspired by experience with Coccinelle. • Probably, everyone in this room uses some Coccinelle modified code! http://coccinelle.lip6.fr Thanks to ANR, Inria, OSADL, Coccinelle users, and many others! 31