[PATCH v3 00/10] Binary Large Objects for Rust DebugFS

Danilo Krummrich posted 10 patches 3 months, 2 weeks ago
rust/kernel/debugfs.rs              | 110 ++++++++++++-
rust/kernel/debugfs/file_ops.rs     | 146 ++++++++++++++++-
rust/kernel/debugfs/traits.rs       | 238 +++++++++++++++++++++++++++-
rust/kernel/fs/file.rs              | 142 ++++++++++++++++-
rust/kernel/uaccess.rs              |  81 ++++++++++
samples/rust/rust_debugfs.rs        |  13 ++
samples/rust/rust_debugfs_scoped.rs |  14 +-
7 files changed, 732 insertions(+), 12 deletions(-)
[PATCH v3 00/10] Binary Large Objects for Rust DebugFS
Posted by Danilo Krummrich 3 months, 2 weeks ago
This series adds support for exposing binary large objects via Rust debugfs.

The first two patches extend UserSliceReader and UserSliceWriter with partial
read/write helpers.

The series further introduces read_binary_file(), write_binary_file() and
read_write_binary_file() methods for the Dir and ScopedDir types.

It also introduces the BinaryWriter and BinaryReader traits, which are used to
read/write the implementing type's binary representation with the help of the
backing file operations from/to debugfs.

Additional to some more generic blanked implementations for the BinaryWriter and
BinaryReader traits it also provides implementations for common smart pointer
types.

Both samples (file-based and scoped) are updated with corresponding examples.

A branch containing the patches can be found in [1].

[1] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/log/?h=debugfs_blobs

Changes in v3:
  - Add UserSliceReader::read_slice_file() and
    UserSliceWriter::write_slice_file() taking an &mut file::Offset to
    adjust it internally and make use of them.
  - Add a new type file::Offset, rather than a type alias.
  - Move affected delegate comments to previous patch.
  - Add a brief comment for BinaryReadFile, BinaryWriteFile and
    BinaryReadWriteFile.

Changes in v2:
  - Add file::Offset type alias.
  - uaccess:
    - Saturate at buffer length on offset overflow.
    - Use file::Offset instead of usize.
  - debugfs:
    - Use file::Offset instead of usize.
    - Handle potential overflow when updating ppos.
    - Use &T::FILE_OPS directly if possible.
    - Fix safety comment in BinaryReaderMut::read_from_slice_mut().

Danilo Krummrich (10):
  rust: fs: add new type file::Offset
  rust: uaccess: add UserSliceReader::read_slice_partial()
  rust: uaccess: add UserSliceReader::read_slice_file()
  rust: uaccess: add UserSliceWriter::write_slice_partial()
  rust: uaccess: add UserSliceWriter::write_slice_file()
  rust: debugfs: support for binary large objects
  rust: debugfs: support blobs from smart pointers
  samples: rust: debugfs: add example for blobs
  rust: debugfs: support binary large objects for ScopedDir
  samples: rust: debugfs_scoped: add example for blobs

 rust/kernel/debugfs.rs              | 110 ++++++++++++-
 rust/kernel/debugfs/file_ops.rs     | 146 ++++++++++++++++-
 rust/kernel/debugfs/traits.rs       | 238 +++++++++++++++++++++++++++-
 rust/kernel/fs/file.rs              | 142 ++++++++++++++++-
 rust/kernel/uaccess.rs              |  81 ++++++++++
 samples/rust/rust_debugfs.rs        |  13 ++
 samples/rust/rust_debugfs_scoped.rs |  14 +-
 7 files changed, 732 insertions(+), 12 deletions(-)


base-commit: e6901808a3b28d8bdabfa98a618b2eab6f8798e8
-- 
2.51.0
Re: [PATCH v3 00/10] Binary Large Objects for Rust DebugFS
Posted by Miguel Ojeda 3 months, 1 week ago
On Wed, Oct 22, 2025 at 4:32 PM Danilo Krummrich <dakr@kernel.org> wrote:
>
>   rust: uaccess: add UserSliceReader::read_slice_partial()
>   rust: uaccess: add UserSliceReader::read_slice_file()
>   rust: uaccess: add UserSliceWriter::write_slice_partial()
>   rust: uaccess: add UserSliceWriter::write_slice_file()

Acked-by: Miguel Ojeda <ojeda@kernel.org>

Cheers,
Miguel
Re: [PATCH v3 00/10] Binary Large Objects for Rust DebugFS
Posted by Danilo Krummrich 3 months ago
On Wed Oct 22, 2025 at 4:30 PM CEST, Danilo Krummrich wrote:

Applied to driver-core-testing, thanks!

> Danilo Krummrich (10):
>   rust: fs: add new type file::Offset

    I picked up the version from v2 [1] for now and send a follow-up series for
    the new type approach [2].

>   rust: uaccess: add UserSliceReader::read_slice_partial()

    [ Replace map_or() with let-else; use saturating_add(). - Danilo ]

>   rust: uaccess: add UserSliceReader::read_slice_file()

    [ Replace saturating_add() with the raw operator and a corresponding
      OVERFLOW comment. - Danilo ]

>   rust: uaccess: add UserSliceWriter::write_slice_partial()

    [ Replace map_or() with let-else; use saturating_add(). - Danilo ]

>   rust: uaccess: add UserSliceWriter::write_slice_file()

    [ Replace saturating_add() with the raw operator and a corresponding
      OVERFLOW comment. - Danilo ]

>   rust: debugfs: support for binary large objects
>   rust: debugfs: support blobs from smart pointers
>   samples: rust: debugfs: add example for blobs
>   rust: debugfs: support binary large objects for ScopedDir
>   samples: rust: debugfs_scoped: add example for blobs

[1] https://lore.kernel.org/all/20251020222722.240473-2-dakr@kernel.org/
[2] https://lore.kernel.org/lkml/20251105002346.53119-1-dakr@kernel.org/