An Empirical Study of Rust-for-Linux: The Success, Dissatisfaction, and Compromise

Hongyu Li, Liwei Guo, Yexuan Yang, Shangguang Wang, Mengwei XuUSENIX ATC 2024 · OpenReview

TL;DR

This paper presents the first comprehensive empirical study of Rust for Linux (RFL), investigating its adoption, benefits, and challenges. While RFL shows promise in enhancing kernel safety, it introduces complexities and trade-offs, highlighting that Rust is not a silver bullet for kernel development.

What Problem Does This Paper Address?

The Linux kernel, a cornerstone of modern computing, has long been plagued by memory and concurrency bugs, largely due to the C language's permissive memory access. Rust, with its strong static typing and ownership model, offers a potential solution by promising memory safety without sacrificing performance. The Rust-for-Linux (RFL) project aims to integrate Rust into the kernel, but its actual impact on safety, performance, and developer experience remains unclear. This paper addresses this gap by empirically studying RFL's current status, its effectiveness in improving safety, its performance implications, and its influence on kernel development.

Methods

The authors conducted a multi-faceted empirical study of RFL. Their methodology involved:

  • Data Collection: Gathering a substantial dataset including RFL commits, issues, pull requests (PRs), mailing list discussions, and Zulip conversations.
  • Code Analysis: Analyzing RFL code to understand its development progress, patch distribution, and the construction of safe abstraction layers.
  • Bug Analysis: Auditing bug reports and "unsafe" code blocks within RFL to assess its impact on kernel security.
  • Performance Benchmarking: Comparing the performance of Rust drivers against their C counterparts using real hardware and various workloads.
  • Developer Experience Analysis: Examining documentation coverage, CI error rates, and developer experience metrics to understand RFL's impact on the kernel community.
  • Qualitative Analysis: Reviewing community discussions and developer opinions to gauge sentiment and identify key concerns.

Datasets

The study utilized the following datasets:

  • RFL GitHub Repository: 1540 commits, 269 issues, 763 PRs.
  • Linux Mailing List: 3611 mails related to RFL.
  • RFL Zulip Forum: 12501 discussions.
  • Upstream Linux Kernel Repository: Existing RFL drivers and Rust kernel crates.

The paper also implicitly uses existing kernel drivers (e.g., NVME, NULL block, e1000, binder) as benchmarks for comparison.

Key Insights and Ideas

  • Rust is not a magic bullet for kernel safety: While Rust significantly improves "securability" by catching many bugs at compile time, it cannot fully eliminate vulnerabilities. "Unsafe" blocks are still necessary for certain kernel operations, and semantic bugs can still slip through.
  • The "unsafe" escape hatch is a double-edged sword: The unsafe keyword is crucial for bridging Rust with the C-based kernel, but it also introduces potential sources of vulnerabilities that are harder to detect.
  • Performance trade-offs exist: Rust drivers can be larger than their C counterparts due to Rust's features like generic programming. While performance is often comparable, some Rust drivers can be significantly slower, especially when lacking advanced C-specific optimizations.
  • Developer experience is mixed: Rust attracts new developers to the kernel community, but its steep learning curve and the need to reconcile Rust's paradigms with kernel conventions create development overhead.
  • Code review is a bottleneck: The RFL project's progress is significantly hampered by a shortage of qualified reviewers who understand both Rust and kernel programming, leading to slow PR merging.
  • Prioritization is key for RFL expansion: The study suggests prioritizing RFL development on subsystems with a high density of memory/thread bugs that Rust can fix, such as linux-block.

Key Results

  • Safety: RFL mitigates kernel vulnerabilities, but "unsafe" usage is inevitable. The study found 25 bugs in merged and staged RFL code, with some impacting memory and thread safety.
  • Performance: Rust drivers are generally comparable to C drivers, with some exceptions. The e1000 driver was found to be 11x slower due to missing advanced features. Binary sizes for fully implemented Rust drivers were 1.2x to 2.4x larger than C.
  • Development: RFL achieves 100% documentation coverage and fewer CI errors per KLoC compared to other kernel subsystems like ebpf and io_uring. Rust attracts a higher percentage of novice developers (58%) to the kernel community.
  • Code Review: PR reviewing time has significantly increased, with RFL commits taking much longer to be reviewed than in the past.

Limitations and Future Work

Limitations:

  • The study acknowledges that "unsafe" code does not necessarily imply vulnerabilities, but it does represent a source of them.
  • The performance analysis of Rust drivers is limited by the fact that some Rust drivers have not implemented full features compared to their C counterparts.
  • The study notes that the "young blood" attracted by Rust are primarily contributing to Rust-relevant toolchains and crates, not necessarily core kernel development, suggesting a disconnect.

Future Work:

  • The authors plan to continuously monitor RFL's evolution and update their repository of tools and datasets.
  • The study suggests prioritizing RFL development on specific subsystems with high bug densities.
  • Further investigation into the performance implications of Rust in complex real-world programs like operating systems is warranted.
  • Addressing the steep learning curve of Rust for kernel development and improving the code review process are crucial for RFL's broader adoption.

Summary updated

BibTeX
@inproceedings{li2024empirical,
  author = {Hongyu Li and Liwei Guo and Yexuan Yang and Shangguang Wang and Mengwei Xu},
  title = {{An Empirical Study of Rust-for-Linux: The Success, Dissatisfaction, and Compromise}},
  booktitle = {USENIX ATC},
  year = {2024},
  url = {https://openreview.net/forum?id=Cbq9FH4rS7},
}
Figure