The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Arnd Bergmann" <arnd@arndb.de>
To: "Alice Ryhl" <aliceryhl@google.com>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alexander Viro" <viro@zeniv.linux.org.uk>,
	"Christian Brauner" <brauner@kernel.org>,
	"Jan Kara" <jack@suse.cz>, "Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] rust: miscdevice: add base miscdevice abstraction
Date: Wed, 02 Oct 2024 13:24:57 +0000	[thread overview]
Message-ID: <50b1c868-3cab-4310-ba4f-2a0a24debaa9@app.fastmail.com> (raw)
In-Reply-To: <CAH5fLghmkkYWF8zNFci-B-BvG8LbFCDEZkZWgr54HvLos5nrqw@mail.gmail.com>

On Wed, Oct 2, 2024, at 12:58, Alice Ryhl wrote:
> On Wed, Oct 2, 2024 at 2:48 PM Arnd Bergmann <arnd@arndb.de> wrote:
> A quick sketch.
>
> One option is to do something along these lines:

This does seem promising, at least if I read your sketch
correctly. I'd probably need a more concrete example to
understand better how this would be used in a driver.

> struct IoctlParams {
>     pub cmd: u32,
>     pub arg: usize,
> }
>
> impl IoctlParams {
>     fn user_slice(&self) -> IoctlUser {
>         let userslice = UserSlice::new(self.arg, _IOC_SIZE(self.cmd));
>         match _IOC_DIR(self.cmd) {
>             _IOC_READ => IoctlParams::Read(userslice.reader()),
>             _IOC_WRITE => IoctlParams::Write(userslice.writer()),
>             _IOC_READ|_IOC_WRITE => IoctlParams::WriteRead(userslice),
>             _ => unreachable!(),

Does the unreachable() here mean that something bad happens
if userspace passes something other than one of the three,
or are the 'cmd' values here in-kernel constants that are
always valid?

> enum IoctlUser {
>     Read(UserSliceReader),
>     Write(UserSliceWriter),
>     WriteRead(UserSlice),
> }
>
> Then ioctl implementations can use a match statement like this:
>
> match ioc_params.user_slice() {
>     IoctlUser::Read(slice) => {},
>     IoctlUser::Write(slice) => {},
>     IoctlUser::WriteRead(slice) => {},
> }
>
> Where each branch of the match handles that case.

This is where I fail to see how that would fit in. If there
is a match statement in a driver, I would assume that it would
always match on the entire cmd code, but never have a command
that could with more than one _IOC_DIR type.

      Arnd

  reply	other threads:[~2024-10-02 13:25 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-01  8:22 [PATCH v2 0/2] Miscdevices in Rust Alice Ryhl
2024-10-01  8:22 ` [PATCH v2 1/2] rust: types: add Opaque::try_ffi_init Alice Ryhl
2024-10-01  8:46   ` Benno Lossin
2024-10-25  4:10   ` Trevor Gross
2024-10-25  7:57     ` Alice Ryhl
2024-10-01  8:22 ` [PATCH v2 2/2] rust: miscdevice: add base miscdevice abstraction Alice Ryhl
2024-10-01  8:53   ` Dirk Behme
2024-10-01  9:13     ` Alice Ryhl
2024-10-01 11:28   ` Alice Ryhl
2024-10-02 12:48   ` Arnd Bergmann
2024-10-02 12:58     ` Alice Ryhl
2024-10-02 13:24       ` Arnd Bergmann [this message]
2024-10-02 13:31         ` Alice Ryhl
2024-10-02 13:57           ` Arnd Bergmann
2024-10-02 14:23             ` Alice Ryhl
2024-10-02 15:31               ` Arnd Bergmann
2024-10-02 13:24     ` Christian Brauner
2024-10-02 13:36       ` Alice Ryhl
2024-10-02 14:23         ` Christian Brauner
2024-10-02 15:45           ` Arnd Bergmann
2024-10-02 16:04             ` Greg Kroah-Hartman
2024-10-02 20:08               ` Arnd Bergmann
2024-10-03  8:19               ` Christian Brauner
2024-10-03  8:09             ` Christian Brauner
2024-10-02 13:31   ` Christian Brauner
2024-10-02 14:06   ` Christian Brauner
2024-10-02 14:24     ` Alice Ryhl
2024-10-03  8:33       ` Christian Brauner
2024-10-21 10:34   ` Miguel Ojeda
2024-10-22 13:15     ` Alice Ryhl

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=50b1c868-3cab-4310-ba4f-2a0a24debaa9@app.fastmail.com \
    --to=arnd@arndb.de \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=brauner@kernel.org \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    --cc=viro@zeniv.linux.org.uk \
    /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