[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2024120909-yield-celery-4257@gregkh>
Date: Mon, 9 Dec 2024 12:17:49 +0100
From: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To: Danilo Krummrich <dakr@...nel.org>
Cc: Alice Ryhl <aliceryhl@...gle.com>, Arnd Bergmann <arnd@...db.de>,
Alexander Viro <viro@...iv.linux.org.uk>,
Christian Brauner <brauner@...nel.org>, Jan Kara <jack@...e.cz>,
Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>,
Trevor Gross <tmgross@...ch.edu>, Lee Jones <lee@...nel.org>,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-fsdevel@...r.kernel.org
Subject: Re: [PATCH v2 2/2] rust: miscdevice: access the `struct miscdevice`
from fops->open()
On Mon, Dec 09, 2024 at 12:07:13PM +0100, Danilo Krummrich wrote:
> On Mon, Dec 09, 2024 at 07:27:47AM +0000, Alice Ryhl wrote:
> > Providing access to the underlying `struct miscdevice` is useful for
> > various reasons. For example, this allows you access the miscdevice's
> > internal `struct device` for use with the `dev_*` printing macros.
> >
> > Note that since the underlying `struct miscdevice` could get freed at
> > any point after the fops->open() call, only the open call is given
> > access to it. To print from other calls, they should take a refcount on
> > the device to keep it alive.
> >
> > Signed-off-by: Alice Ryhl <aliceryhl@...gle.com>
> > ---
> > rust/kernel/miscdevice.rs | 19 ++++++++++++++++---
> > 1 file changed, 16 insertions(+), 3 deletions(-)
> >
> > diff --git a/rust/kernel/miscdevice.rs b/rust/kernel/miscdevice.rs
> > index 0cb79676c139..c5af1d5ec4be 100644
> > --- a/rust/kernel/miscdevice.rs
> > +++ b/rust/kernel/miscdevice.rs
> > @@ -104,7 +104,7 @@ pub trait MiscDevice {
> > /// Called when the misc device is opened.
> > ///
> > /// The returned pointer will be stored as the private data for the file.
> > - fn open(_file: &File) -> Result<Self::Ptr>;
> > + fn open(_file: &File, _misc: &MiscDeviceRegistration<Self>) -> Result<Self::Ptr>;
>
> How is the user of this abstraction supposed to access the underlying struct
> miscdevice e.g. from other fops? AFAICS, there is no way for the user to store a
> device pointer / reference in their driver private data.
That should be "hung" off of the miscdevice structure. In C that's done
through embedding the miscdevice structure within something else, don't
know how you all are going to do that in rust :)
Or, better yet, in your open callback, the rust code can set the file
private data pointer, that's what is done a lot as well, either could
work.
> I also think it's a bit weird to pass the registration structure in open() to
> access the device.
That's what the miscdevice api does today in C. Well, it's embedded in
the file private pointer, so I guess just a function to call to get it
instead would work.
> I think we need an actual representation of a struct miscdevice, i.e.
> `misc::Device`.
I thought we have that already?
thanks,
greg k-h
Powered by blists - more mailing lists