Miguel Ojeda, the author of the Rust-for-Linux project, has proposed an updated version of the components for developing device drivers in the Rust language for consideration by Linux kernel developers. Rust support is considered experimental but has already been approved for inclusion in the linux-next branch. The new version addresses the issues raised during the discussion of the first version of the patches. Linus Torvalds has already joined the discussion and suggested changing the logic of processing some bitwise operations.
Ricordiamo che le modifiche proposte consentono di utilizzare Rust come secondo linguaggio per lo sviluppo di driver e moduli del kernel. Il supporto per Rust è presentato come un'opzione, non attiva per impostazione predefinita e non porta all'inclusione di Rust tra le dipendenze di compilazione obbligatorie per il kernel. L'uso di Rust per lo sviluppo di driver permetterà di creare driver sicuri e di qualità superiore con il minimo sforzo, eliminando problemi come l'accesso alla memoria dopo che è stata liberata, la dereferenza di puntatori nulli e il superamento dei limiti del buffer.
La gestione sicura della memoria in Rust è garantita durante la compilazione attraverso il controllo dei riferimenti, il tracciamento della proprietà degli oggetti e la gestione del tempo di vita degli oggetti (ambito di visibilità), nonché attraverso la valutazione della correttezza dell'accesso alla memoria durante l'esecuzione del codice. Rust fornisce anche strumenti per proteggersi dai sovraccarichi interi, richiede l'inizializzazione obbligatoria dei valori delle variabili prima dell'uso, gestisce meglio gli errori nella libreria standard, applica il concetto di immutabilità (immutable) per riferimenti e variabili per impostazione predefinita e offre una forte tipizzazione statica per minimizzare gli errori logici.
The most notable changes in the new version of the patches:
- The memory allocation code has been modified to eliminate possible generation of 'panic' states due to errors such as memory shortage. Included is a version of the Rust library alloc, which has reworked code for error handling, but the ultimate goal is to transfer into the main edition of alloc all functionalities necessary for the kernel (changes have been prepared and submitted to the Rust standard library).
- Instead of nightly builds for compiling the kernel with Rust support, beta releases and stable releases of the rustc compiler can now be used. Currently, rustc 1.54-beta1 is used as the reference compiler, but after the release of 1.54 at the end of the month, it will be maintained as the reference compiler.
- Support has been added for writing tests using the standard Rust attribute '#[test]' and the ability to use doctests for documenting tests.
- Support for ARM32 and RISCV architectures has been added in addition to the previously supported x86_64 and ARM64.
- Improvements have been made to the GCC Rust implementations (GCC frontend for Rust) and rustc_codegen_gcc (rustc backend for GCC), which now passes all basic tests.
- A new level of abstraction has been proposed for using kernel mechanisms written in C in Rust programs, such as red-black trees, reference-counted objects, file descriptor creation, tasks, files, and input/output vectors.
- In the components for driver development, support for the 'file_operations' module, the 'module!' macro, macro registration, and rudimentary drivers (probe and remove) has been improved.
- In Binder, support for passing file descriptors and LSM hooks has been implemented.
- È stato proposto un esempio più funzionale di driver in Rust — bcm2835-rng per il generatore hardware di numeri random delle schede Raspberry Pi.
Inoltre, vengono menzionati progetti di alcune aziende relativi all'uso di Rust nel kernel:
- Microsoft ha espresso interesse a partecipare al lavoro di integrazione del supporto per Rust nel kernel Linux e prevederà nei prossimi mesi l'approvazione di implementazioni di driver per Hyper-V in Rust.
- ARM sta lavorando per migliorare il supporto di Rust per i sistemi basati su processori ARM. Il progetto Rust ha già ricevuto modifiche che hanno portato i sistemi ARM a 64 bit nel novero delle piattaforme di primo livello supportate (Tier-1).
- Google fornisce direttamente supporto al progetto Rust for Linux, sviluppando una nuova implementazione del meccanismo di interazione tra processi Binder in Rust e considerando la possibilità di riscrivere vari driver in Rust. Attraverso ISRG (Internet Security Research Group), Google ha finanziato il lavoro per integrare il supporto per Rust nel kernel Linux.
- IBM ha implementato il supporto per Rust nel kernel per sistemi PowerPC.
- Il laboratorio LSE (Systems Research Laboratory) ha sviluppato un driver SPI in Rust.
Fonte: opennet.ru
