Skip to content

Character device abstractions for Rust

Josef Zoller lkml llvm oe-kbuild-all rust-for-linux 1 version In review

Get series with b4
b4 am [email protected] change-id 20241011-rust-char-dev-f82eb3e29899

Versions newest first

  1. v1 Latest3 patches 6 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3rust: char_dev: add character device abstractionrust/bindings/bindings_helper.h rust/helpers/fs.c rust/kernel/char_dev.rs +3 more+1046 -42 replies
2/3rust: macros: add IoctlCommand derive macrorust/kernel/ioctl.rs rust/kernel/prelude.rs rust/macros/ioctl_cmd.rs +1 more+414 -10 replies
3/3samples: rust: add character device samplesamples/rust/Kconfig samples/rust/Makefile samples/rust/rust_char_dev.rs+517 -02 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/3] Character device abstractions for Rust

Writing character devices is a common way to start writing kernel code, especially because of the book "Linux Device Drivers", which is still one of the best resources to learn about Linux kernel programming. To allow an easier entry into Rust kernel programming specifically, this series adds abstractions for these kinds of devices to the Rust API.

I also included a sample that demonstrates how to use these abstractions to create the simplest example from LDD3, the "scull" device.

I'm also aware of the patch series about misc devices that was sent recently. I think these are both valuable additions to the Rust API, and could even be combined in some way, in which case the file operations abstractions in both series should probably be separated and generalized. But I'm still sending this series as it is, because it is my first ever patch and I could use some feedback on my approach.

This series depends on the File abstraction patch [1] and the Opaque::try_ffi_init patch [2], however, the latter is such a small change that it could easily be included in this series if necessary.

---
Josef Zoller (3):
rust: char_dev: add character device abstraction
rust: macros: add IoctlCommand derive macro
samples: rust: add character device sample

 rust/bindings/bindings_helper.h |   1 +
 rust/helpers/fs.c               |  16 +
 rust/kernel/char_dev.rs         | 976 ++++++++++++++++++++++++++++++++++++++++
 rust/kernel/init/macros.rs      |  10 +-
 rust/kernel/ioctl.rs            | 236 +++++++++-
 rust/kernel/lib.rs              |   1 +
 rust/kernel/prelude.rs          |   2 +-
 rust/macros/ioctl_cmd.rs        | 202 +++++++++
 rust/macros/lib.rs              |  21 +
 samples/rust/Kconfig            |  10 +
 samples/rust/Makefile           |   1 +
 samples/rust/rust_char_dev.rs   | 506 +++++++++++++++++++++
 12 files changed, 1977 insertions(+), 5 deletions(-)

---
base-commit: ce1c54fdff7c4556b08f5b875a331d8952e8b6b7
change-id: 20241011-rust-char-dev-f82eb3e29899
prerequisite-patch-id: be636dd988fbd1f993df5fe7cd10eabfadd319b2
prerequisite-patch-id: 478b4285f3752e64043d2e3b5ccd786ef039f659

Best regards,

Signature · 1 line
Josef Zoller <[email protected]>