SlideShare a Scribd company logo
1 of 60
Download to read offline
Not breaking userspace: the evolving Linux ABI
Alison Chaiken
Southern California Linux Expo 2022
alison@she-devel.com
Slides: http://she-devel.com/Chaiken_LinuxABI.pdf
Blue text indicates hyperlinks.
2
Why do kernel upgrades
make users nervous?
3
Contents
●
What is an ABI and what is Linux’s?
●
Why does it matter?
– 64-bit time (Y2038)
– Priority inversions and robotics
– Writing and maintaining log monitors
– Mounting old filesystems
– Mixing BPF programs and udev rules
●
How to avoid ABI breaks
●
Summary
4
What is an Application Binary Interface?
●
Library headers and documentation are the API.
●
For C programs in general:
– return types of functions;
– parameter lists of functions;
– layout of structs
– meaning, range or ordering of enums.
●
Lack of “name mangling” in C is a problem.
5
ABI Guarantees are a Contract
compiler
libc
(syscalls)
userspace
(ELF)
Linux
kernel
6
The Linux Kernel Warranty
7
8
Y2038 and 64-bit time
tinyurl.com/mw94ktpw
9
32-bit IoT devices have a long service life
Disclaimer: these devices may not run Linux, or be 64-bit, or already updated.
10
Good News: Kernel and Glibc are ready!
11
Two bad choices for distros with 32-bit arches
A. complete set of 32- and
64-bit-time packages;
OR
B. distinct 32- and 64-bit-time
images: i386 and i386t
https://tinyurl.com/mryr56ee
12
Servers 1, Robots 0
13
Priority inversion occurs when L-prio thread holds
a lock that H-prio thread needs
Priority
Time
Lo-prio
takes
lock
Hi-prio
needs
lock
14
Priority Inheritance in Realtime Kernel Boosts the
L-prio thread temporarily
Vital for userspace tasks as well as kernel!
Time
Priority
Hi-prio
needs
lock
Lo-prio
takes
lock
15
Problem: glibc threads do not support PI
Bug report posted in 2010; still “NEW” in 2022.
16
Fix Requires an ABI Break
Either:
●
a syscall must take an additional argument;
-or-
●
a function arg (the “futex word”) must change from
32- to 64-bit.
17
Robotics projects need a different pthread library
tinyurl.com/2p99dtan,
https://tinyurl.com/2rmmmban
glibc
librtpi
Or an entirely different
libc!
musl
18
What is in the Linux Kernel Stable ABI?
Advertised: ELF, /proc, /sys and device-tree.
What about :
●
Devices in /dev?
●
printk output (dmesg)?
●
Bootargs (cmdline)?
●
Module params?
●
Netlink sockets?
●
Tracepoints?
●
Valid BPF programs?
●
Filesystem metadata?
●
Meaning of constants
in headers?
?
?
?
?
?
?
?
?
19
YOU
lose!
You broke
my ABI!
sysfs
or
procfs?
YOU
win!
Y
e
s
!
N
o
You are a Developer:
“I want to debug and optimize”.
You are a User:
“I want it to just work!”
Developers are not covered by the Warranty
20
dmesg, GDB and log monitors
21
Threading Kernel Log Messages
22
And then fix GDB
23
Y
e
s
!
YOU
lose!
You broke
my ABI!
in-tree
userspace
tool?
sysfs
or
procfs?
YOU
win!
Y
e
s
!
N
o
No
24
Kernel ABI Stability Checklist
●
ELF format: yes, /proc: yes, /sys: yes†
●
Device files in dev? (not /dev/kmsg)
●
printk output (dmesg)?
●
Filesystem metadata?
●
Valid BPF programs?
●
Tracepoints?
●
Bootargs (cmdline)?
●
Module parameters?
†
except /sys/kernel/debug, /sys/kernel/btf . . .
25
Mounting Old Filesystems
26
Will old filesystems mount with new kernels?
Manipulating FS metadata with custom tool relies on
Undefined Behavior.
“I was under the impression
that mounting existing FSs
fell under the scope of the
kernel⇔userspace
boundary”
it's not just about
"whatever the kernel
happens to accept". It
should also be, "was it
generated using an
official version of the
userspace tools",
27
ABI Contract holds if official userspace tools are used
libc: mount
Linux
kernel
What about FS from Windows, iOS, BSD?
userspace:
e2fsprogs,
zfsutils, etc.
28
Kernel ABI Stability Checklist
●
ELF format: yes, /proc: yes, /sys: yes†
●
Device files in dev? (not /dev/kmsg)
●
printk output (dmesg)?
●
Filesystem metadata? only with official tools
●
Valid BPF programs?
●
Bootargs (cmdline)?
●
Module parameters?
●
Tracepoints?
†
except /sys/kernel/debug, /sys/kernel/btf . . .
29
Are BPF Programs
Part of Stable ABI?
30
BPF’s ABI Guarantee
Controversy: can an ordinary user tool like a udev
rule depend on a developer tool like bpftrace?
31
What about Kernel Features on which BPF Programs Rely?
Stable ABI is any ‘"user
workflow", whether it uses
BPF or any other kernel
feature’
OSS 2022,
6/21/22
“out-of-tree modules
will have the technical
debt of changing every
time a new kernel
release is out, and so
should out-of-tree bpf
programs.”
Kernel Summit mailing list
6/16/22
Photo:
https://lwn.net/Articles/899182/
32
Avoiding ABI Breaks
33
Method 0: generic syscalls
ioctl()
prctl()
https://tinyurl.com/bdd5yeys
int prctl(int option, unsigned long arg2, unsigned long arg3,
unsigned long arg4, unsigned long arg5);
int ioctl(int fd, unsigned long request, ...);
34
Method 1: Unused Function Parameters
●
Retain deprecated params: man shmctl
●
“Reserved for future use” params: man pid_getfd
●
Bitmasks with unused bits: man statx
●
Multiple versions of the same syscall: apropos clone
●
Some unwrapped syscalls have no glibc implementation.
35
Method 2: avoid procfs and sysfs changes
“I'd just prefer to have
$NEW_FEATURE
under /proc or /sys.”
“This is ABI, you
can't walk back on
it.”
https://pixabay.com/en/speech-bubble-ellipse-shape-arrow-25917/
36
Summary
●
The Linux ABI definition is both fuzzy and controversial.
●
Some ABI breaks are unavoidable.
●
Y2038 fix will be painful for distros.
●
glibc’s thread library NPTL is not suitable for robotics.
●
Trouble arises when users rely on developer tools.
●
Think carefully when writing userspace applications!
37
Acknowledgements
Thanks to Akkana Peck and Sarah Newman for their
feedback.
Today, Saturday July 30, at 6 PM in this same room!
38
Many full-time-remote Linux jobs with Aurora
Innovation (aurora.tech)
39
Resources
●
Please support LWN!
●
“To Save C, We Must Save ABI,” and “
Binary Banshees and Digital Daemons,” JeanHeyd Meneide.
●
“It’s About Time,” Mike Crowe, Overload, 28(156):28-30, April
2020. (about pthreads and condition variables)
●
Gratian Crisan,
librtpi: Conditional Variables for Real-Time Applications,
Embedded Linux Conference 2020 presentation
●
“BPF CO-RE (Compile Once, Run Everywhere),” Andrii
Nakryiko’s blog
40
Changing Meanings
of Names
41
Behavior of Clocks during Suspension
Should CLOCK_MONOTONIC advance when the system is
suspended?
42
Changing the meaning of bootargs
●
See bootargs with sudo dmesg | grep -i “command line”
●
Should bootarg A means something different alone than in
conjunction with bootarg B?
$ git log -n 1 --grep=consistent – kernel/rcu/tree_nocb.h
●
Someone preferred the old behavior:
$ git log --oneline -n 1 --grep="option to opt" – kernel/rcu
43
“official
version
userspace
tools”?
Y
e
s
!
YOU
lose!
You broke
my ABI!
in-tree
userspace
tool?
sysfs
or
procfs?
YOU
win!
Y
e
s
!
N
o
No
44
Trace Events are “stable API”
●
The list of tracepoints is (mostly) stable.
●
The format of trace events (the ABI!) changes.
The difference between a tracepoint and trace event is that a
tracepoint is the "trace_foo()" in the kernel, whereas the trace
event is the data extracted from the tracepoint via the
TRACE_EVENT() macro and listed in the format files in the
tracefs events directory.
45
Why kernel tracepoints disappear:
optimizing compilers
#linux-rt IRC chat:
<rostedt> I already get people asking me why a function is
traced in one kernel, but not the other
<rostedt> and I have to tell them it was because gcc decided to
inline it in the other kernel
<rostedt> now we are going to lose tracing, because a function
was modified slightly where gcc can do a tail call?
<rostedt> and tail calls are quite common
46
The libc⇔kernel ABI boundary
/usr/include
/usr/include/linux/
/usr/include/x86_64/asm
/usr/include/x86_64/bits
/usr/include/x86_64/sys
Linux kernel headers from
linux-libc-deb
glibc headers from
libc6-dev
47
BPF Programs and
"Compile Once, Run Everywhere"
●
Problem: BPF programs rely on internal kernel ABI.
●
Solution: BPF Type Format, with debug info exported to
/sys/kernel/btf:
– $ bpftool btf dump file /sys/kernel/btf/battery format c
●
CO-RE further has LINUX_KERNEL_VERSION and
CONFIG_FOO_FEATURE macros to help with more complex
changes.
48
Printk indexing will ease log-monitor maintenance
Solution: export kernel format strings to
/sys/kernel/debug for use by log monitors.
49
Method 3: Export info to sysfs (BTF and
printk indexing)
How to access the ABI of the currently running
kernel:
$ ls /sys/kernel/btf
$ bpftool btf dump file /sys/kernel/btf/vfat
$ bpftool btf dump file /sys/kernel/btf/battery format c
Not part of stable ABI!
50
Method 4: JIT Compilation
Works great, but expensive:
– requires kernel headers to be updated along with kernel;
– requires compilation with libclang or libgcc;
– slows startup of applications while JIT runs.
51
Who ever heard of futexes?
52
musl has had PI mutexes since 2019
53
C language lacks features that make ABI stability
easier
●
There are no function overloads or overrides.
– No “name mangling.”
– To safely change a function’s ABI, one must rename it.
●
“Encapsulation” methods are limited to static keyword.
– No notion of granular privacy.
– Implementation details tend to “leak” from C programs.
●
Maybe “assembly labels” like __attribute__((alias()) are a path
forward?
54
Undefined Behavior with FS Metadata
55
Backward compatibility is hard
http://stackoverflow.com/questions/28986125/double-curved-shape
i386
strcpy() &
strdup()
32-bit time
56
Why not just recompile?
●
Source code is unavailable.
●
Need to recompile propagates to other libraries/applications.
●
Proprietary toolchain is too old to support needed features.
●
Code would need new FDA, ISO262 … certification.
●
Suppose recompiling is not enough?
57
ABI-Break Demo
$ git clone https://github.com/chaiken/SCALE2022-demo-code
$ cd SCALE2022-demo-code/C-ABI
$ make right-abi-lib
$ $ make wrong-abi-lib
Makefile main.c
is_negative_64.c
is_negative_128.c
58
What about the asterix?
59
How should libc’s respond to kernel ABI Break?
Security, Performance, Stability, POSIX:
pick 23
(forgetting readability, logical consistency . . . )
(c)
Chris
Potter
(2012)
Title:
Scales
of
Justice
-
www.flickr.com/photos/86530412@N02/7953227784
60
Debian and Out-of-Tree Kernel Modules
The kernel ABI
An ABI (Application Binary Interface) is an interface
between two software components, considered at the
level of register allocation and memory layout. The ABI
between the kernel and user-space is generally
maintained carefully, and is not a concern here. However,
the ABI between the kernel and its modules is not. In order
to support out-of-tree modules, the kernel version should
be changed when the ABI between the kernel and
modules changes.

More Related Content

Similar to Not breaking userspace: the evolving Linux ABI

Using VPP and SRIO-V with Clear Containers
Using VPP and SRIO-V with Clear ContainersUsing VPP and SRIO-V with Clear Containers
Using VPP and SRIO-V with Clear ContainersMichelle Holley
 
UM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareUM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareBrendan Gregg
 
Kernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver frameworkKernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver frameworkAnne Nicolas
 
Share the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development BoardShare the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development BoardJian-Hong Pan
 
Dataplane programming with eBPF: architecture and tools
Dataplane programming with eBPF: architecture and toolsDataplane programming with eBPF: architecture and tools
Dataplane programming with eBPF: architecture and toolsStefano Salsano
 
DEF CON 27 - JEFF DILEO - evil e bpf in depth
DEF CON 27 - JEFF DILEO - evil e bpf in depthDEF CON 27 - JEFF DILEO - evil e bpf in depth
DEF CON 27 - JEFF DILEO - evil e bpf in depthFelipe Prado
 
eBPF Debugging Infrastructure - Current Techniques
eBPF Debugging Infrastructure - Current TechniqueseBPF Debugging Infrastructure - Current Techniques
eBPF Debugging Infrastructure - Current TechniquesNetronome
 
Os Grossupdated
Os GrossupdatedOs Grossupdated
Os Grossupdatedoscon2007
 
Using open source software to build an industrial grade embedded linux platfo...
Using open source software to build an industrial grade embedded linux platfo...Using open source software to build an industrial grade embedded linux platfo...
Using open source software to build an industrial grade embedded linux platfo...SZ Lin
 
BPF & Cilium - Turning Linux into a Microservices-aware Operating System
BPF  & Cilium - Turning Linux into a Microservices-aware Operating SystemBPF  & Cilium - Turning Linux into a Microservices-aware Operating System
BPF & Cilium - Turning Linux into a Microservices-aware Operating SystemThomas Graf
 
Development of Signal Processing Algorithms using OpenCL for FPGA based Archi...
Development of Signal Processing Algorithms using OpenCL for FPGA based Archi...Development of Signal Processing Algorithms using OpenCL for FPGA based Archi...
Development of Signal Processing Algorithms using OpenCL for FPGA based Archi...Pradeep Singh
 
Linux Kernel Platform Development: Challenges and Insights
 Linux Kernel Platform Development: Challenges and Insights Linux Kernel Platform Development: Challenges and Insights
Linux Kernel Platform Development: Challenges and InsightsGlobalLogic Ukraine
 
Implementation of Soft-core processor on FPGA (Final Presentation)
Implementation of Soft-core processor on FPGA (Final Presentation)Implementation of Soft-core processor on FPGA (Final Presentation)
Implementation of Soft-core processor on FPGA (Final Presentation)Deepak Kumar
 
ELC-E Linux Awareness
ELC-E Linux AwarenessELC-E Linux Awareness
ELC-E Linux AwarenessPeter Griffin
 
Kernel Recipes 2019 - BPF at Facebook
Kernel Recipes 2019 - BPF at FacebookKernel Recipes 2019 - BPF at Facebook
Kernel Recipes 2019 - BPF at FacebookAnne Nicolas
 
Build and deploy scientific Python Applications
Build and deploy scientific Python Applications  Build and deploy scientific Python Applications
Build and deploy scientific Python Applications Ramakrishna Reddy
 
eBPF - Rethinking the Linux Kernel
eBPF - Rethinking the Linux KerneleBPF - Rethinking the Linux Kernel
eBPF - Rethinking the Linux KernelThomas Graf
 
Utilizing AMD GPUs: Tuning, programming models, and roadmap
Utilizing AMD GPUs: Tuning, programming models, and roadmapUtilizing AMD GPUs: Tuning, programming models, and roadmap
Utilizing AMD GPUs: Tuning, programming models, and roadmapGeorge Markomanolis
 

Similar to Not breaking userspace: the evolving Linux ABI (20)

Using VPP and SRIO-V with Clear Containers
Using VPP and SRIO-V with Clear ContainersUsing VPP and SRIO-V with Clear Containers
Using VPP and SRIO-V with Clear Containers
 
UM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareUM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of Software
 
Kernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver frameworkKernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver framework
 
Share the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development BoardShare the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development Board
 
Dataplane programming with eBPF: architecture and tools
Dataplane programming with eBPF: architecture and toolsDataplane programming with eBPF: architecture and tools
Dataplane programming with eBPF: architecture and tools
 
DEF CON 27 - JEFF DILEO - evil e bpf in depth
DEF CON 27 - JEFF DILEO - evil e bpf in depthDEF CON 27 - JEFF DILEO - evil e bpf in depth
DEF CON 27 - JEFF DILEO - evil e bpf in depth
 
eBPF Debugging Infrastructure - Current Techniques
eBPF Debugging Infrastructure - Current TechniqueseBPF Debugging Infrastructure - Current Techniques
eBPF Debugging Infrastructure - Current Techniques
 
Os Grossupdated
Os GrossupdatedOs Grossupdated
Os Grossupdated
 
Next Stop, Android
Next Stop, AndroidNext Stop, Android
Next Stop, Android
 
Using open source software to build an industrial grade embedded linux platfo...
Using open source software to build an industrial grade embedded linux platfo...Using open source software to build an industrial grade embedded linux platfo...
Using open source software to build an industrial grade embedded linux platfo...
 
BPF & Cilium - Turning Linux into a Microservices-aware Operating System
BPF  & Cilium - Turning Linux into a Microservices-aware Operating SystemBPF  & Cilium - Turning Linux into a Microservices-aware Operating System
BPF & Cilium - Turning Linux into a Microservices-aware Operating System
 
Development of Signal Processing Algorithms using OpenCL for FPGA based Archi...
Development of Signal Processing Algorithms using OpenCL for FPGA based Archi...Development of Signal Processing Algorithms using OpenCL for FPGA based Archi...
Development of Signal Processing Algorithms using OpenCL for FPGA based Archi...
 
Linux Kernel Platform Development: Challenges and Insights
 Linux Kernel Platform Development: Challenges and Insights Linux Kernel Platform Development: Challenges and Insights
Linux Kernel Platform Development: Challenges and Insights
 
Implementation of Soft-core processor on FPGA (Final Presentation)
Implementation of Soft-core processor on FPGA (Final Presentation)Implementation of Soft-core processor on FPGA (Final Presentation)
Implementation of Soft-core processor on FPGA (Final Presentation)
 
ELC-E Linux Awareness
ELC-E Linux AwarenessELC-E Linux Awareness
ELC-E Linux Awareness
 
Kernel Recipes 2019 - BPF at Facebook
Kernel Recipes 2019 - BPF at FacebookKernel Recipes 2019 - BPF at Facebook
Kernel Recipes 2019 - BPF at Facebook
 
Build and deploy scientific Python Applications
Build and deploy scientific Python Applications  Build and deploy scientific Python Applications
Build and deploy scientific Python Applications
 
Smart logic
Smart logicSmart logic
Smart logic
 
eBPF - Rethinking the Linux Kernel
eBPF - Rethinking the Linux KerneleBPF - Rethinking the Linux Kernel
eBPF - Rethinking the Linux Kernel
 
Utilizing AMD GPUs: Tuning, programming models, and roadmap
Utilizing AMD GPUs: Tuning, programming models, and roadmapUtilizing AMD GPUs: Tuning, programming models, and roadmap
Utilizing AMD GPUs: Tuning, programming models, and roadmap
 

More from Alison Chaiken

Supporting SW Update via u-boot and GPT/EFI
Supporting SW Update via u-boot and GPT/EFISupporting SW Update via u-boot and GPT/EFI
Supporting SW Update via u-boot and GPT/EFIAlison Chaiken
 
Two C++ Tools: Compiler Explorer and Cpp Insights
Two C++ Tools: Compiler Explorer and Cpp InsightsTwo C++ Tools: Compiler Explorer and Cpp Insights
Two C++ Tools: Compiler Explorer and Cpp InsightsAlison Chaiken
 
V2X Communications: Getting our Cars Talking
V2X Communications: Getting our Cars TalkingV2X Communications: Getting our Cars Talking
V2X Communications: Getting our Cars TalkingAlison Chaiken
 
Practical Challenges to Deploying Highly Automated Vehicles
Practical Challenges to Deploying Highly Automated VehiclesPractical Challenges to Deploying Highly Automated Vehicles
Practical Challenges to Deploying Highly Automated VehiclesAlison Chaiken
 
Linux: the first second
Linux: the first secondLinux: the first second
Linux: the first secondAlison Chaiken
 
Functional AI and Pervasive Networking in Automotive
 Functional AI and Pervasive Networking in Automotive Functional AI and Pervasive Networking in Automotive
Functional AI and Pervasive Networking in AutomotiveAlison Chaiken
 
Flash in Vehicles: an End-User's Perspective
Flash in Vehicles: an End-User's PerspectiveFlash in Vehicles: an End-User's Perspective
Flash in Vehicles: an End-User's PerspectiveAlison Chaiken
 
Linux: the first second
Linux: the first secondLinux: the first second
Linux: the first secondAlison Chaiken
 
IRQs: the Hard, the Soft, the Threaded and the Preemptible
IRQs: the Hard, the Soft, the Threaded and the PreemptibleIRQs: the Hard, the Soft, the Threaded and the Preemptible
IRQs: the Hard, the Soft, the Threaded and the PreemptibleAlison Chaiken
 
Automotive Linux, Cybersecurity and Transparency
Automotive Linux, Cybersecurity and TransparencyAutomotive Linux, Cybersecurity and Transparency
Automotive Linux, Cybersecurity and TransparencyAlison Chaiken
 
LISA15: systemd, the Next-Generation Linux System Manager
LISA15: systemd, the Next-Generation Linux System Manager LISA15: systemd, the Next-Generation Linux System Manager
LISA15: systemd, the Next-Generation Linux System Manager Alison Chaiken
 
Automotive Grade Linux and systemd
Automotive Grade Linux and systemdAutomotive Grade Linux and systemd
Automotive Grade Linux and systemdAlison Chaiken
 
Tuning systemd for embedded
Tuning systemd for embeddedTuning systemd for embedded
Tuning systemd for embeddedAlison Chaiken
 
Systemd for developers
Systemd for developersSystemd for developers
Systemd for developersAlison Chaiken
 
Developing Automotive Linux
Developing Automotive LinuxDeveloping Automotive Linux
Developing Automotive LinuxAlison Chaiken
 
Systemd: the modern Linux init system you will learn to love
Systemd: the modern Linux init system you will learn to loveSystemd: the modern Linux init system you will learn to love
Systemd: the modern Linux init system you will learn to loveAlison Chaiken
 
Technology, Business and Regulation of the Connected Car
Technology, Business and Regulation of the Connected CarTechnology, Business and Regulation of the Connected Car
Technology, Business and Regulation of the Connected CarAlison Chaiken
 
Best practices for long-term support and security of the device-tree
Best practices for long-term support and security of the device-treeBest practices for long-term support and security of the device-tree
Best practices for long-term support and security of the device-treeAlison Chaiken
 
The “Telematics Horizon” V2V and V2I Networking
The “Telematics Horizon” V2V and V2I NetworkingThe “Telematics Horizon” V2V and V2I Networking
The “Telematics Horizon” V2V and V2I NetworkingAlison Chaiken
 
Developing automotive Linux
Developing automotive LinuxDeveloping automotive Linux
Developing automotive LinuxAlison Chaiken
 

More from Alison Chaiken (20)

Supporting SW Update via u-boot and GPT/EFI
Supporting SW Update via u-boot and GPT/EFISupporting SW Update via u-boot and GPT/EFI
Supporting SW Update via u-boot and GPT/EFI
 
Two C++ Tools: Compiler Explorer and Cpp Insights
Two C++ Tools: Compiler Explorer and Cpp InsightsTwo C++ Tools: Compiler Explorer and Cpp Insights
Two C++ Tools: Compiler Explorer and Cpp Insights
 
V2X Communications: Getting our Cars Talking
V2X Communications: Getting our Cars TalkingV2X Communications: Getting our Cars Talking
V2X Communications: Getting our Cars Talking
 
Practical Challenges to Deploying Highly Automated Vehicles
Practical Challenges to Deploying Highly Automated VehiclesPractical Challenges to Deploying Highly Automated Vehicles
Practical Challenges to Deploying Highly Automated Vehicles
 
Linux: the first second
Linux: the first secondLinux: the first second
Linux: the first second
 
Functional AI and Pervasive Networking in Automotive
 Functional AI and Pervasive Networking in Automotive Functional AI and Pervasive Networking in Automotive
Functional AI and Pervasive Networking in Automotive
 
Flash in Vehicles: an End-User's Perspective
Flash in Vehicles: an End-User's PerspectiveFlash in Vehicles: an End-User's Perspective
Flash in Vehicles: an End-User's Perspective
 
Linux: the first second
Linux: the first secondLinux: the first second
Linux: the first second
 
IRQs: the Hard, the Soft, the Threaded and the Preemptible
IRQs: the Hard, the Soft, the Threaded and the PreemptibleIRQs: the Hard, the Soft, the Threaded and the Preemptible
IRQs: the Hard, the Soft, the Threaded and the Preemptible
 
Automotive Linux, Cybersecurity and Transparency
Automotive Linux, Cybersecurity and TransparencyAutomotive Linux, Cybersecurity and Transparency
Automotive Linux, Cybersecurity and Transparency
 
LISA15: systemd, the Next-Generation Linux System Manager
LISA15: systemd, the Next-Generation Linux System Manager LISA15: systemd, the Next-Generation Linux System Manager
LISA15: systemd, the Next-Generation Linux System Manager
 
Automotive Grade Linux and systemd
Automotive Grade Linux and systemdAutomotive Grade Linux and systemd
Automotive Grade Linux and systemd
 
Tuning systemd for embedded
Tuning systemd for embeddedTuning systemd for embedded
Tuning systemd for embedded
 
Systemd for developers
Systemd for developersSystemd for developers
Systemd for developers
 
Developing Automotive Linux
Developing Automotive LinuxDeveloping Automotive Linux
Developing Automotive Linux
 
Systemd: the modern Linux init system you will learn to love
Systemd: the modern Linux init system you will learn to loveSystemd: the modern Linux init system you will learn to love
Systemd: the modern Linux init system you will learn to love
 
Technology, Business and Regulation of the Connected Car
Technology, Business and Regulation of the Connected CarTechnology, Business and Regulation of the Connected Car
Technology, Business and Regulation of the Connected Car
 
Best practices for long-term support and security of the device-tree
Best practices for long-term support and security of the device-treeBest practices for long-term support and security of the device-tree
Best practices for long-term support and security of the device-tree
 
The “Telematics Horizon” V2V and V2I Networking
The “Telematics Horizon” V2V and V2I NetworkingThe “Telematics Horizon” V2V and V2I Networking
The “Telematics Horizon” V2V and V2I Networking
 
Developing automotive Linux
Developing automotive LinuxDeveloping automotive Linux
Developing automotive Linux
 

Recently uploaded

Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitterShivangiSharma879191
 
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
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
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
 
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
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
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
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 

Recently uploaded (20)

Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
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
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
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
 
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...
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
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
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 

Not breaking userspace: the evolving Linux ABI

  • 1. Not breaking userspace: the evolving Linux ABI Alison Chaiken Southern California Linux Expo 2022 alison@she-devel.com Slides: http://she-devel.com/Chaiken_LinuxABI.pdf Blue text indicates hyperlinks.
  • 2. 2 Why do kernel upgrades make users nervous?
  • 3. 3 Contents ● What is an ABI and what is Linux’s? ● Why does it matter? – 64-bit time (Y2038) – Priority inversions and robotics – Writing and maintaining log monitors – Mounting old filesystems – Mixing BPF programs and udev rules ● How to avoid ABI breaks ● Summary
  • 4. 4 What is an Application Binary Interface? ● Library headers and documentation are the API. ● For C programs in general: – return types of functions; – parameter lists of functions; – layout of structs – meaning, range or ordering of enums. ● Lack of “name mangling” in C is a problem.
  • 5. 5 ABI Guarantees are a Contract compiler libc (syscalls) userspace (ELF) Linux kernel
  • 7. 7
  • 8. 8 Y2038 and 64-bit time tinyurl.com/mw94ktpw
  • 9. 9 32-bit IoT devices have a long service life Disclaimer: these devices may not run Linux, or be 64-bit, or already updated.
  • 10. 10 Good News: Kernel and Glibc are ready!
  • 11. 11 Two bad choices for distros with 32-bit arches A. complete set of 32- and 64-bit-time packages; OR B. distinct 32- and 64-bit-time images: i386 and i386t https://tinyurl.com/mryr56ee
  • 13. 13 Priority inversion occurs when L-prio thread holds a lock that H-prio thread needs Priority Time Lo-prio takes lock Hi-prio needs lock
  • 14. 14 Priority Inheritance in Realtime Kernel Boosts the L-prio thread temporarily Vital for userspace tasks as well as kernel! Time Priority Hi-prio needs lock Lo-prio takes lock
  • 15. 15 Problem: glibc threads do not support PI Bug report posted in 2010; still “NEW” in 2022.
  • 16. 16 Fix Requires an ABI Break Either: ● a syscall must take an additional argument; -or- ● a function arg (the “futex word”) must change from 32- to 64-bit.
  • 17. 17 Robotics projects need a different pthread library tinyurl.com/2p99dtan, https://tinyurl.com/2rmmmban glibc librtpi Or an entirely different libc! musl
  • 18. 18 What is in the Linux Kernel Stable ABI? Advertised: ELF, /proc, /sys and device-tree. What about : ● Devices in /dev? ● printk output (dmesg)? ● Bootargs (cmdline)? ● Module params? ● Netlink sockets? ● Tracepoints? ● Valid BPF programs? ● Filesystem metadata? ● Meaning of constants in headers? ? ? ? ? ? ? ? ?
  • 19. 19 YOU lose! You broke my ABI! sysfs or procfs? YOU win! Y e s ! N o You are a Developer: “I want to debug and optimize”. You are a User: “I want it to just work!” Developers are not covered by the Warranty
  • 20. 20 dmesg, GDB and log monitors
  • 24. 24 Kernel ABI Stability Checklist ● ELF format: yes, /proc: yes, /sys: yes† ● Device files in dev? (not /dev/kmsg) ● printk output (dmesg)? ● Filesystem metadata? ● Valid BPF programs? ● Tracepoints? ● Bootargs (cmdline)? ● Module parameters? † except /sys/kernel/debug, /sys/kernel/btf . . .
  • 26. 26 Will old filesystems mount with new kernels? Manipulating FS metadata with custom tool relies on Undefined Behavior. “I was under the impression that mounting existing FSs fell under the scope of the kernel⇔userspace boundary” it's not just about "whatever the kernel happens to accept". It should also be, "was it generated using an official version of the userspace tools",
  • 27. 27 ABI Contract holds if official userspace tools are used libc: mount Linux kernel What about FS from Windows, iOS, BSD? userspace: e2fsprogs, zfsutils, etc.
  • 28. 28 Kernel ABI Stability Checklist ● ELF format: yes, /proc: yes, /sys: yes† ● Device files in dev? (not /dev/kmsg) ● printk output (dmesg)? ● Filesystem metadata? only with official tools ● Valid BPF programs? ● Bootargs (cmdline)? ● Module parameters? ● Tracepoints? † except /sys/kernel/debug, /sys/kernel/btf . . .
  • 29. 29 Are BPF Programs Part of Stable ABI?
  • 30. 30 BPF’s ABI Guarantee Controversy: can an ordinary user tool like a udev rule depend on a developer tool like bpftrace?
  • 31. 31 What about Kernel Features on which BPF Programs Rely? Stable ABI is any ‘"user workflow", whether it uses BPF or any other kernel feature’ OSS 2022, 6/21/22 “out-of-tree modules will have the technical debt of changing every time a new kernel release is out, and so should out-of-tree bpf programs.” Kernel Summit mailing list 6/16/22 Photo: https://lwn.net/Articles/899182/
  • 33. 33 Method 0: generic syscalls ioctl() prctl() https://tinyurl.com/bdd5yeys int prctl(int option, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5); int ioctl(int fd, unsigned long request, ...);
  • 34. 34 Method 1: Unused Function Parameters ● Retain deprecated params: man shmctl ● “Reserved for future use” params: man pid_getfd ● Bitmasks with unused bits: man statx ● Multiple versions of the same syscall: apropos clone ● Some unwrapped syscalls have no glibc implementation.
  • 35. 35 Method 2: avoid procfs and sysfs changes “I'd just prefer to have $NEW_FEATURE under /proc or /sys.” “This is ABI, you can't walk back on it.” https://pixabay.com/en/speech-bubble-ellipse-shape-arrow-25917/
  • 36. 36 Summary ● The Linux ABI definition is both fuzzy and controversial. ● Some ABI breaks are unavoidable. ● Y2038 fix will be painful for distros. ● glibc’s thread library NPTL is not suitable for robotics. ● Trouble arises when users rely on developer tools. ● Think carefully when writing userspace applications!
  • 37. 37 Acknowledgements Thanks to Akkana Peck and Sarah Newman for their feedback. Today, Saturday July 30, at 6 PM in this same room!
  • 38. 38 Many full-time-remote Linux jobs with Aurora Innovation (aurora.tech)
  • 39. 39 Resources ● Please support LWN! ● “To Save C, We Must Save ABI,” and “ Binary Banshees and Digital Daemons,” JeanHeyd Meneide. ● “It’s About Time,” Mike Crowe, Overload, 28(156):28-30, April 2020. (about pthreads and condition variables) ● Gratian Crisan, librtpi: Conditional Variables for Real-Time Applications, Embedded Linux Conference 2020 presentation ● “BPF CO-RE (Compile Once, Run Everywhere),” Andrii Nakryiko’s blog
  • 41. 41 Behavior of Clocks during Suspension Should CLOCK_MONOTONIC advance when the system is suspended?
  • 42. 42 Changing the meaning of bootargs ● See bootargs with sudo dmesg | grep -i “command line” ● Should bootarg A means something different alone than in conjunction with bootarg B? $ git log -n 1 --grep=consistent – kernel/rcu/tree_nocb.h ● Someone preferred the old behavior: $ git log --oneline -n 1 --grep="option to opt" – kernel/rcu
  • 44. 44 Trace Events are “stable API” ● The list of tracepoints is (mostly) stable. ● The format of trace events (the ABI!) changes. The difference between a tracepoint and trace event is that a tracepoint is the "trace_foo()" in the kernel, whereas the trace event is the data extracted from the tracepoint via the TRACE_EVENT() macro and listed in the format files in the tracefs events directory.
  • 45. 45 Why kernel tracepoints disappear: optimizing compilers #linux-rt IRC chat: <rostedt> I already get people asking me why a function is traced in one kernel, but not the other <rostedt> and I have to tell them it was because gcc decided to inline it in the other kernel <rostedt> now we are going to lose tracing, because a function was modified slightly where gcc can do a tail call? <rostedt> and tail calls are quite common
  • 46. 46 The libc⇔kernel ABI boundary /usr/include /usr/include/linux/ /usr/include/x86_64/asm /usr/include/x86_64/bits /usr/include/x86_64/sys Linux kernel headers from linux-libc-deb glibc headers from libc6-dev
  • 47. 47 BPF Programs and "Compile Once, Run Everywhere" ● Problem: BPF programs rely on internal kernel ABI. ● Solution: BPF Type Format, with debug info exported to /sys/kernel/btf: – $ bpftool btf dump file /sys/kernel/btf/battery format c ● CO-RE further has LINUX_KERNEL_VERSION and CONFIG_FOO_FEATURE macros to help with more complex changes.
  • 48. 48 Printk indexing will ease log-monitor maintenance Solution: export kernel format strings to /sys/kernel/debug for use by log monitors.
  • 49. 49 Method 3: Export info to sysfs (BTF and printk indexing) How to access the ABI of the currently running kernel: $ ls /sys/kernel/btf $ bpftool btf dump file /sys/kernel/btf/vfat $ bpftool btf dump file /sys/kernel/btf/battery format c Not part of stable ABI!
  • 50. 50 Method 4: JIT Compilation Works great, but expensive: – requires kernel headers to be updated along with kernel; – requires compilation with libclang or libgcc; – slows startup of applications while JIT runs.
  • 51. 51 Who ever heard of futexes?
  • 52. 52 musl has had PI mutexes since 2019
  • 53. 53 C language lacks features that make ABI stability easier ● There are no function overloads or overrides. – No “name mangling.” – To safely change a function’s ABI, one must rename it. ● “Encapsulation” methods are limited to static keyword. – No notion of granular privacy. – Implementation details tend to “leak” from C programs. ● Maybe “assembly labels” like __attribute__((alias()) are a path forward?
  • 55. 55 Backward compatibility is hard http://stackoverflow.com/questions/28986125/double-curved-shape i386 strcpy() & strdup() 32-bit time
  • 56. 56 Why not just recompile? ● Source code is unavailable. ● Need to recompile propagates to other libraries/applications. ● Proprietary toolchain is too old to support needed features. ● Code would need new FDA, ISO262 … certification. ● Suppose recompiling is not enough?
  • 57. 57 ABI-Break Demo $ git clone https://github.com/chaiken/SCALE2022-demo-code $ cd SCALE2022-demo-code/C-ABI $ make right-abi-lib $ $ make wrong-abi-lib Makefile main.c is_negative_64.c is_negative_128.c
  • 58. 58 What about the asterix?
  • 59. 59 How should libc’s respond to kernel ABI Break? Security, Performance, Stability, POSIX: pick 23 (forgetting readability, logical consistency . . . ) (c) Chris Potter (2012) Title: Scales of Justice - www.flickr.com/photos/86530412@N02/7953227784
  • 60. 60 Debian and Out-of-Tree Kernel Modules The kernel ABI An ABI (Application Binary Interface) is an interface between two software components, considered at the level of register allocation and memory layout. The ABI between the kernel and user-space is generally maintained carefully, and is not a concern here. However, the ABI between the kernel and its modules is not. In order to support out-of-tree modules, the kernel version should be changed when the ABI between the kernel and modules changes.