
Rust vs C Kernel Modules: Safety, Ergonomics and Trade-offs
Compare one Linux 6.18 module in C and Rust for safety, error handling, build cost and API coverage, then pick the language for your next kernel module.
Tag
255 posts

Compare one Linux 6.18 module in C and Rust for safety, error handling, build cost and API coverage, then pick the language for your next kernel module.

Call arm_fir_q15 and arm_biquad_cascade_df1_q31 from CMSIS-DSP to filter fixed-point samples on a Cortex-M, with correct state sizes, scaling and block layout.

Write, build and load a first Rust kernel module in a Linux 6.18 tree: the module! macro, init and Drop, KVec, Kconfig and Makefile entries and dmesg output.

Use the nix crate to call POSIX functions like pipe, fork, waitpid and kill from Rust with typed arguments, Result errors and no raw unsafe libc calls.

Install the Rust toolchain, bindgen and libclang, check them with make rustavailable, enable CONFIG_RUST in a Linux 6.18 tree and build the Rust samples.

Widen before you multiply, shift with rounding, pre-scale before you divide, and saturate the result. Q15 and Q16.16 routines in portable C that never overflow.

Use nrfx drivers directly on an nRF52 in the nRF Connect SDK: enable the nrfx timer, connect its interrupt and run a periodic callback without Zephyr drivers.

Define a custom 128-bit GATT service on nRF52 with Zephyr: characteristic properties, read and write callbacks, notifications through the CCC and MTU limits.
Advertise a non-connectable BLE beacon on an nRF52 with Zephyr: advertising data, bt_le_adv_start parameters, intervals and an iBeacon payload.

How struct sk_buff carries a packet through Linux 6.12: head, data, tail and end pointers, headroom, skb_put, skb_push, skb_pull, cloning and ownership rules.

Follow a received packet through Linux 6.12 from the NIC's DMA ring, the interrupt, NAPI, GRO, IP and TCP to the socket, with the counters for each step.

Use the DMAMUX request multiplexer on STM32G4 and H7 to connect any peripheral request to any DMA channel, plus request generators and synchronization.