public inbox for kernelnewbies@kernelnewbies.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Fabio <development@redaril.me>
Cc: kernelnewbies@kernelnewbies.org
Subject: Re: Rust: how to implement file_operations for a misc device?
Date: Wed, 24 Sep 2025 12:27:30 +0200	[thread overview]
Message-ID: <2025092445-editor-wobbling-1f26@gregkh> (raw)
In-Reply-To: <240f21b8-6d0c-4ce0-8dbb-2eea3c6d6b1d@redaril.me>

On Tue, Sep 23, 2025 at 06:47:25PM +0200, Fabio wrote:
> Hello,
> 
> brand-new kernel newbie here. I'm interested in the Rust side of the kernel.
> To get acquainted, I'm following the Linux Driver Development book, 3rd
> edition, also integrating it with modern documentation and best practices
> (or at least I hope so).
> 
> I'm developing the scull module on top of the
> `kernel::miscdevice::MiscDevice` trait. Where I'm stuck at is the lack of
> the `kernel::file::Operations` trait [1], that most online resources refer
> to. I need such trait to implement read and write operations for the misc
> device. AFAIU, this trait used to exist but it's no longer in the mainline
> codebase [2]. Also, `kernel::miscdevice::MiscdeviceVTable` is private inside
> the miscdevice module, so there's no way I can somehow extend it.
> 
> Is there any workaround for what I want to achieve, or is ioctl the only
> allowed interface to misc devices in Rust?

Please see the rust sample misc driver that is right now in linux-next,
it shows how to use the read and write iter functions, which should be
all that you need.

Specifically look at commit e5b0d7da941a ("samples: rust_misc_device:
Expand the sample to support read()ing from userspace"), which shows how
this can be done.

Yes, this is a bit different than the traditional "read/write"
callbacks, as documented in the device driver's book, but things have
moved on in the decades since we wrote that :)

The changes for this will be showing up in the next kernel release (i.e.
6.18).

hope this helps,

greg k-h

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

  reply	other threads:[~2025-09-24 10:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-23 16:47 Rust: how to implement file_operations for a misc device? Fabio
2025-09-24 10:27 ` Greg KH [this message]
2025-11-14 10:42   ` Simple mutex_destroy question Lucas Tanure
2025-11-19 10:08     ` Lucas Tanure
2025-11-19 13:08       ` Raka Gunarto
2025-11-19 16:27     ` Billie Alsup (balsup)
2025-11-20 10:27       ` Lucas Tanure
2025-11-20 13:43         ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2025092445-editor-wobbling-1f26@gregkh \
    --to=greg@kroah.com \
    --cc=development@redaril.me \
    --cc=kernelnewbies@kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox