Skip to content

AlexMelanFromRingo/linux-7.1-experiments

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Linux 7.1 kernel experiments — minimal, modern & Rust

Three Linux 7.1 kernels built from source on Ubuntu 24.04 / WSL2, each with a different goal, every one boot-tested under QEMU/KVM:

  1. Minimal — the smallest bootable kernel (tinyconfig + the few options needed to reach userspace).
  2. Modern — newest/best features, hardened, legacy & 32-bit dropped, built with Clang for kCFI, targeting current hardware.
  3. Rust-enhanced — a git-cloned tree with CONFIG_RUST, the in-tree Rust sample drivers, and an original memory-safe Rust device I wrote and wired into the build.

Why 7.1? It was the newest kernel on kernel.org at build time (latest_stable: 7.1; 7.0.12 stable, 6.18 LTS). Newest features, best Rust support, newest hardware enablement.

Results at a glance

Minimal Modern Rust-enhanced
Base config tinyconfig (+boot) defconfig + modern.config defconfig + RUST
Toolchain gcc 13.3 clang/lld 18 (LLVM=1) clang 18 + rustc 1.91.1
bzImage size 945 KB 20 MB (zstd) 15 MB
Enabled =y symbols 522 1852 1626
Headline size kCFI, MGLRU, BBR, BTF, CXL/Xe/SEV safe Rust driver in ring 0
Boots in QEMU ✅ 0.29 s to init ✅ kCFI+Landlock live ✅ driver test PASS

Documentation

Doc Contents
docs/01-environment.md machine, installed packages, source acquisition & verification
docs/02-minimal-kernel.md minimal build, initramfs, boot test, every step
docs/03-modern-kernel.md modern feature set + rationale, what was dropped, results
docs/04-rust-in-kernel.md Rust rationale, our module, the realistic path to replacing C
docs/05-cheatsheet.md condensed command reference + gotchas
docs/06-results.md consolidated numbers & captured boot logs
docs/07-real-rootfs.md modern kernel on a real Debian 13 rootfs (virtio-blk)
docs/08-advanced-rust.md a real Rust PCI driver + a C→Rust rewrite verified vs. the C original
docs/09-thinlto.md the modern kernel rebuilt with Clang ThinLTO (+ kCFI)

Extension work (rounds 2 & 3)

Beyond the three kernels, all boot-verified under QEMU/KVM:

  • ThinLTO build — the modern kernel rebuilt with LTO_CLANG_THIN (+kCFI); 18 MB image, peak 6 GiB RAM. → docs/09
  • Real Debian rootfs + networking — the modern kernel boots Debian 13 (trixie) on an ext4 virtio disk, and reaches the real internet over virtio-net (HTTP 301 from 1.1.1.1). → docs/07
  • rust_pci_probe — a Rust PCI driver binding to pci-testdev, MMIO + config space. → docs/08
  • rust_crc16lib/crc/crc16.c rewritten in safe Rust, proven bit-identical to the C original at boot. → docs/08
  • rust_mathportint_sqrt() + gcd() from lib/math/ rewritten in safe Rust, verified vs. the C originals. → docs/08

Four original Rust modules (rust_safe_counter, rust_pci_probe, rust_crc16, rust_mathport) were written and wired into the kernel's Kconfig/Kbuild.

Repository layout

README.md                     this file
modern.config                 the documented "modern features" Kconfig fragment
docs/                         01–09: every step, rationale, cheatsheet, results
artifacts/
├── minimal/    config · boot.log · init.c · run-qemu.sh
├── modern/     config · boot.log · rootfs-boot.log · run-qemu.sh
├── modern-lto/ config · boot.log · run-qemu.sh
├── rust/       ← the four original Rust kernel modules:
│               rust_safe_counter.rs   misc-device counter (Mutex, RAII)
│               rust_pci_probe.rs       PCI driver (pci-testdev, MMIO)
│               rust_crc16.rs           C→Rust rewrite of lib/crc/crc16.c
│               rust_mathport.rs        C→Rust rewrite of int_sqrt()/gcd()
│               + boot logs, config, the userspace ioctl tester
└── rootfs/     demo-init scripts + netdemo.c + boot logs (Debian + networking)

Build outputs (bzImage, vmlinux, initramfs/disk images) and the multi-GB kernel source/build trees are not committed — they are regenerable from the configs and the documented steps. Everything needed to reproduce is here.

TL;DR — build all three

# minimal
make -C src O=build-minimal tinyconfig
src/scripts/config --file build-minimal/.config -e 64BIT -e PRINTK -e TTY \
    -e SERIAL_8250 -e SERIAL_8250_CONSOLE -e BINFMT_ELF -e BLK_DEV_INITRD
make -C src O=build-minimal olddefconfig && make -C src O=build-minimal -j$(nproc) bzImage

# modern (clang + kCFI)
make -C src LLVM=1 O=build-modern defconfig
src/scripts/kconfig/merge_config.sh -m -O build-modern build-modern/.config modern.config
make -C src LLVM=1 O=build-modern olddefconfig && make -C src LLVM=1 O=build-modern -j$(nproc) all

# rust-enhanced
cd rust-kernel && rustup override set 1.91.1
make LLVM=1 BINDGEN=bindgen-0.71 defconfig
scripts/config -e RUST -e SAMPLES -e SAMPLES_RUST -e SAMPLE_RUST_MINIMAL -e SAMPLE_RUST_SAFE_COUNTER
make LLVM=1 BINDGEN=bindgen-0.71 olddefconfig && make LLVM=1 BINDGEN=bindgen-0.71 -j$(nproc)

See docs/05-cheatsheet.md for QEMU boot commands and host setup.

About

Building Linux 7.1 three ways — minimal, modern (kCFI/LLVM/ThinLTO) and Rust-enhanced — with four original Rust kernel modules, all boot-tested in QEMU. Fully documented.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors