+ All Categories
Home > Documents > 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Date post: 16-Oct-2021
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
102
Rust in the Linux ecosystem Miguel Ojeda [email protected]
Transcript
Page 1: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Rust in theLinux ecosystem

Miguel [email protected]

Page 2: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Credits & Acknowledgments

Rust...for being a breath of fresh air

Kernel maintainers...for being open-minded

Everyone that has helped Rust for Linux(see credits in the RFC & patch series)

Page 3: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

History

30 years of Linux 30 years of ISO C

Page 4: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Love story*

30 years of Linux

❤*

* Terms and Conditions Apply.

30 years of ISO C

Page 5: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Why is C a good system programming language?

Page 6: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

“Do you see any language except C which is

suitable for development of operating systems?”

Why is C a good system programming language?

Page 7: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

“I like interacting with hardware from a software perspective.

And I have yet to see a language that comes even close to C.”— Linus Torvalds 2012

“Do you see any language except C which is

suitable for development of operating systems?”

Why is C a good system programming language?

Page 8: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Why is C a good system programming language?

“When I read C, I know what the assembly language will look like.”

“If you think like a computer, writing C actually makes sense.”

“The people that designed C ... designed it at a time when compilers had to be simple.”

“You can use C to generate good code for hardware.” Fast

Low-level

Simple

Fits the domain

Page 9: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

But...

Page 10: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

But...

UB

Page 11: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Undefined Behavior

— N2596 C2x Working Draft

Page 12: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Example of UB

int f(int a, int b) { return a / b;}

Page 13: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Example of UB

int f(int a, int b) { return a / b;}

UB ∀x f(x, 0);

Page 14: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Example of UB

Any other inputs that trigger UB?

int f(int a, int b) { return a / b;}

Page 15: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Example of UB

UB f(INT_MIN, -1);

Any other inputs that trigger UB?

int f(int a, int b) { return a / b;}

Page 16: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Instances of UB

Page 17: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Instances of UB

Page 18: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Instances of UB

Page 19: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Instances of UB

Page 20: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Instances of UB

Page 21: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Instances of UB

Page 22: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Instances of UB

Page 23: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Instances of UB

Page 24: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Instances of UB

Page 25: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

So, what does Rust offer?

Page 26: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

So, what does Rust offer?

UB🏖

Page 27: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Safety

Safety in Rust

=No undefined behavior

Page 28: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Safety

Safety in Rust

≠Safety in “safety-critical”

as in functional safety (DO-178B/C, ISO 26262, EN 50128…)

Page 29: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Safety examples

abort()s in C

areRust-safe

Page 30: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Safety examples

abort()s in C

areRust-safe

Even if your company goes bankrupt.

Page 31: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Safety examples

abort()s in C

areRust-safe

Even if your company goes bankrupt.

Even if somebody is injured.

Page 32: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Avoiding UB

int f(int a, int b) { if (b == 0) abort();

if (a == INT_MIN && b == -1) abort();

return a / b;}

Page 33: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Avoiding UB

f is a safe function

int f(int a, int b) { if (b == 0) abort();

if (a == INT_MIN && b == -1) abort();

return a / b;}

Page 34: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Safety examples

Rust panics

areRust-safe

Page 35: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Safety examples

Kernel panics

areRust-safe

Page 36: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Safety examples

Uses after free, null derefs, double frees,

OOB accesses, uninitialized memory reads,

invalid inhabitants, data races...

are notRust-safe

Page 37: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Safety examples

Uses after free, null derefs, double frees,

OOB accesses, uninitialized memory reads,

invalid inhabitants, data races...

are notRust-safe

Even if your system still works.

Page 38: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Safety examples

Race conditions

areRust-safe

Page 39: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Safety examples

Memory leaks

areRust-safe

Page 40: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Safety examples

Deadlocks

areRust-safe

Page 41: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Safety examples

Integer overflows

areRust-safe

Page 42: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Is avoiding UB that important?

Page 43: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Is avoiding UB that important?

~70%of vulnerabilities in C/C++ projects come from UB

Page 44: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Is avoiding UB that important?

— https://msrc-blog.microsoft.com/2019/07/18/we-need-a-safer-systems-programming-language/

Page 45: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Is avoiding UB that important?

— https://langui.sh/2019/07/23/apple-memory-safety/

Page 46: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Is avoiding UB that important?

— https://www.chromium.org/Home/chromium-security/memory-safety

Page 47: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Is avoiding UB that important?

— https://security.googleblog.com/2019/05/queue-hardening-enhancements.html

Page 48: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Is avoiding UB that important?

Page 49: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Sure, UB is an issue and safe Rust does not have it…

Page 50: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Sure, UB is an issue and safe Rust does not have it…

...but does Rust really help, though?

Page 51: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Does Rust help?

Page 52: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

I took a look at this spreadsheet published three weeks ago...

Does Rust help?

Page 53: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

I took a look at this spreadsheet published three weeks ago...

— https://adalogics.com/blog/fuzzing-100-open-source-projects-with-oss-fuzz

Does Rust help?

Page 54: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

I filled the language column and plotted...

Does Rust help?

Page 55: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

I filled the language column and plotted...

Does Rust help?

???

Page 56: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

I filled the language column and plotted...

Does Rust help?

Page 57: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

I filled the language column and plotted...

Does Rust help?

Page 58: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

What else does Rust offer?

Language

Page 59: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

What else does Rust offer?

LanguageStricter type system

Safe/unsafe split Sum types

Pattern matching

Generics

RAII

Lifetimes

Shared & exclusive references

Modules & visibility

Powerful hygienic and procedural macros

Page 60: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

What else does Rust offer?

Standard library

Page 61: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

What else does Rust offer?

Standard library

Vocabulary types like Result and Option

Iterators

FormattingPinning

Checked, saturating & wrapping integer arithmetic primitives

CollectionsNetworking

Processes & Threads

Paths & Filesystem

Page 62: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Tooling

What else does Rust offer?

Page 63: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Tooling

Great compiler error messages

What else does Rust offer?

Documentation generator

Formatter

Linter

Unit & integration tests

UBSAN-like interpreter

Static analyzer

Macro debugging

IDE tooling

C ↔ Rust bindings generatorsBuild system

Page 64: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Tooling

Great compiler error messages

What else does Rust offer?

Documentation generator

Formatter

Linter

Unit & integration tests

plus the usual friends: gdb, lldb, perf, valgrind...UBSAN-like interpreter

Static analyzer

Macro debugging

IDE tooling

C ↔ Rust bindings generatorsBuild system

Page 65: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...
Page 66: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

What is the catch?

Page 67: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

What is the catch?

Cannot model everything ⇒ Unsafe code required

Page 68: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

What is the catch?

Cannot model everything ⇒ Unsafe code required

More information to provide ⇒ More complex language

Page 69: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

What is the catch?

Cannot model everything ⇒ Unsafe code required

More information to provide ⇒ More complex language

Extra runtime checks ⇒ Potentially expensive

Page 70: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

What is the catch?

Cannot model everything ⇒ Unsafe code required

More information to provide ⇒ More complex language

Extra runtime checks ⇒ Potentially expensive

An extra language to learn ⇒ Logistics & maintenance burden

Page 71: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Why is C a good system programming language?

“When I read C, I know what the assembly language will look like.”

“If you think like a computer, writing C actually makes sense.”

“The people that designed C ... designed it at a time when compilers had to be simple.”

“You can use C to generate good code for hardware.” Fast

Low-level

Simple

Fits the domain

Page 72: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Why is C a good system programming language?Rust

Sometimes

Yes

Not really

...

“When I read C, I know what the assembly language will look like.”

“If you think like a computer, writing C actually makes sense.”

“The people that designed C ... designed it at a time when compilers had to be simple.”

“You can use C to generate good code for hardware.” Fast

Low-level

Simple

Fits the domain

Page 73: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Who is using Rust?

Page 74: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...
Page 75: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...
Page 76: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...
Page 77: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...
Page 78: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Projects written in Rust

Page 79: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...
Page 80: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...
Page 81: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...
Page 82: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...
Page 83: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...
Page 84: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...
Page 85: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...
Page 86: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...
Page 87: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...
Page 88: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...
Page 89: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

https://servo.org/

https://github.com/rust-lang/rust

https://www.redox-os.org/

https://github.com/firecracker-microvm/firecracker

https://github.com/BurntSushi/ripgrep

https://github.com/sharkdp/hyperfine

https://github.com/gfx-rs/wgpu

https://veloren.net/

https://rg3d.rs

Links

Page 90: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Projects lookingto take advantage of Rust

Page 91: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Rust for Linux

Page 92: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...
Page 93: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...
Page 94: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Entities supporting Rust

Page 95: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...
Page 96: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

In the kernel...

“Google supports and contributes directly to the Rust for Linux project.

Our Android team is evaluating a new Binder implementation and

considering other drivers where Rust could be adopted.”

— https://lore.kernel.org/lkml/[email protected]/

Page 97: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

In the kernel...

“Arm recognises the Rust value proposition and is actively working

with the Rust community to improve Rust for Arm based systems.

A good example is Arm’s RFC contribution to the Rust language which

made Linux on 64-bit Arm systems a Tier-1 Rust supported platform.

Rustaceans at Arm are excited about the Rust for Linux initiative and

look forward to assisting in this effort.”

— https://lore.kernel.org/lkml/[email protected]/

Page 98: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

In the kernel...

“Microsoft's Linux Systems Group is interested in contributing to

getting Rust into Linux kernel.

Hopefully we will be able to submit select Hyper-V drivers written in

Rust in the coming months.”

— https://lore.kernel.org/lkml/[email protected]/

Page 99: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Rust in theLinux ecosystem

Miguel [email protected]

Page 100: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

Backup slides

Page 101: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...
Page 102: 2021-09-20 - Linux Plumbers Conference - Rust in the Linux ...

C Charter

— N2086 C2x Charter - Original Principles

— N2086 C2x Charter - Additional Principles for C11


Recommended