Re: [PATCH v1] rust: console: add abstraction for kernel console drivers
From: Greg Kroah-Hartman
Date: Fri Feb 27 2026 - 18:15:11 EST
On Fri, Feb 27, 2026 at 01:53:56PM -0800, Matthew Wood wrote:
> Add a safe Rust abstraction for the kernel's `struct console`,
> enabling console drivers to be implemented in Rust that provides:
>
> - `ConsoleOps` trait with a required `write` callback and an
> optional `setup` callback, mirroring the C console_operations
> interface. The trait requires `Send + Sync` to reflect that
> console write may be called from any context including IRQ.
>
> - `Console<T>` struct that wraps `struct console` using pin-init
> and `Opaque<T>`, with automatic unregistration via `PinnedDrop`.
> Registration is performed through a pin-initializer returned by
> `Console::register()`, which uses `pin_chain` to set the data
> pointer and call `register_console()` after the struct is pinned.
>
> - `ConsoleOpsAdapter<T>` that provides the extern "C" callbacks
> bridging from the kernel's function pointers to the Rust trait
> methods. The `#[vtable]` attribute on `ConsoleOps` enables
> compile-time detection of whether `setup` is implemented via
> `T::HAS_SETUP`.
>
> - Console flag constants re-exported from the C `enum cons_flags`.
>
> C helper functions are added for `register_console()`,
> `unregister_console()`, and `console_is_registered()` as these are
> either inlines or macros that cannot be called directly from Rust
> through bindgen.
>
> This abstraction is a dependency for a Rust netconsole implementation
> I am working on.
I'd prefer to see it then, with the user, before even reviewing this
one, sorry. That way we "know" it at least works for you.
thanks,
greg k-h