Linux's V4L2 VP9 Codec Kernel Code Rewritten In Rust For Better Memory Safety

Written by Michael Larabel in Multimedia on 27 February 2024 at 08:12 PM EST. 61 Comments
MULTIMEDIA
Daniel Almeida with Collabora has posted a rewritten of the VP9 codec library code within the Linux kernel's Video 4 Linux 2 (V4L2) subsystem. In using Rust rather than the existing C code, this should yield better memory safety and better fend off potential issues within the existing code.

The "request for comments" code ports the VP9 library code into Rust plus converts the RKVDEC and Hantro driver code to using the Rust'ed version. Fluendo's Fluster testing shows the same results when using either the Rust or C versions of the code.

VP9 logo


Almeida commented with the RFC patches:
"Much has been spoken at various occasions about drivers and I feel that the consensus is to wait for now. This is why I am proposing a different approach: porting our codec libraries to Rust.

IMHO, these components can benefit greatly from Rust, as they implement complicated algorithms that also happen to process data received from userspace through V4L2 controls. These algorithms use the data received from userspace in order to index into a lot of arrays and thus benefit from Rust's memory safety.

The first thing about the code is that it does not include any layer of bindings. This was pointed out as a blocker several times due to the need of keeping them in sync with the C code.

The Rust code here also offers a C API for C drivers.This C API is automatically generated by cbindgen and I have provided instructions on how to do so. We can even use functions from both the C and Rust libraries at the same time since the ABI is the same.

The above can come in handy because it means that we can convert a given codebase piece by piece if need be. C drivers will work as usual through the C API and any new Rust driver will get to benefit from a native Rust interface."

He went on to add in the patch cover letter:
"I hope to convince the community that this is a feasible way to slowly experiment with Rust code without tying us up too much to it.

Lastly, please note that this code is just a proof of concept, we can settle on a proper patch - with all that entails - if it is well received."

Those interested can find these RFC patches on the kernel mailing list while awaiting feedback from other upstream Linux kernel stakeholders.
Related News
About The Author
Michael Larabel

Michael Larabel is the principal author of Phoronix.com and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and OpenBenchmarking.org automated benchmarking software. He can be followed via Twitter, LinkedIn, or contacted via MichaelLarabel.com.

Popular News This Week