Re: [RFC PATCH v2 0/4] rust: miscdevice: abstraction for uring-cmd

From: Daniel Almeida
Date: Sun Jul 27 2025 - 13:18:00 EST


Hi Sidong,

> On 27 Jul 2025, at 12:03, Sidong Yang <sidong.yang@xxxxxxxxxx> wrote:
>
> This patch series implemens an abstraction for io-uring sqe and cmd and
> adds uring_cmd callback for miscdevice. Also there is an example that use
> uring_cmd in rust-miscdevice sample.
>
> I received a email from kernel bot that `io_tw_state` is not FFI-safe.
> It seems that the struct has no field how can I fix this?

It’s not something that you introduced. Empty structs are problematic when
used in FFI, because ZSTs are not defined in the C standard AFAIK, although
they are supported in some compilers. For example, this is not illegal nor UB
in GCC [0]. The docs say:

> The structure has size zero.

This aligns with Rust's treatment of ZSTs, which are also zero-sized, so I
don't think this will be a problem, but lets wait for others to chime in.

I'll review this tomorrow.

>
> Changelog:
> v2:
> * use pinned &mut for IoUringCmd
> * add missing safety comments
> * use write_volatile for read uring_cmd in sample
>
> Sidong Yang (4):
> rust: bindings: add io_uring headers in bindings_helper.h
> rust: io_uring: introduce rust abstraction for io-uring cmd
> rust: miscdevice: add uring_cmd() for MiscDevice trait
> samples: rust: rust_misc_device: add uring_cmd example
>
> rust/bindings/bindings_helper.h | 2 +
> rust/kernel/io_uring.rs | 183 +++++++++++++++++++++++++++++++
> rust/kernel/lib.rs | 1 +
> rust/kernel/miscdevice.rs | 41 +++++++
> samples/rust/rust_misc_device.rs | 34 ++++++
> 5 files changed, 261 insertions(+)
> create mode 100644 rust/kernel/io_uring.rs
>
> --
> 2.43.0
>
>


— Daniel

[0]: https://gcc.gnu.org/onlinedocs/gcc/Empty-Structures.html