From: "Arnd Bergmann" <arnd@arndb.de>
To: "Alice Ryhl" <aliceryhl@google.com>
Cc: "Lee Jones" <lee@kernel.org>,
linux-kernel@vger.kernel.org,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"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
Subject: Re: [PATCH v4 2/4] samples: rust: Provide example using the new Rust MiscDevice abstraction
Date: Fri, 06 Dec 2024 11:29:00 +0100 [thread overview]
Message-ID: <2073da49-37c6-4add-9450-47842d05cd79@app.fastmail.com> (raw)
In-Reply-To: <CAH5fLgjauL-1QbnkVVK34COD_Ch_rcdpUEMKBsC9HB-TKWNscA@mail.gmail.com>
On Fri, Dec 6, 2024, at 11:09, Alice Ryhl wrote:
> On Fri, Dec 6, 2024 at 11:05 AM Arnd Bergmann <arnd@arndb.de> wrote:
>>
>> On Fri, Dec 6, 2024, at 10:05, Lee Jones wrote:
>> > This sample driver demonstrates the following basic operations:
>> >
>> > * Register a Misc Device
>> > * Create /dev/rust-misc-device
>> > * Provide open call-back for the aforementioned character device
>> > * Operate on the character device via a simple ioctl()
>> > * Provide close call-back for the character device
>> >
>> > Signed-off-by: Lee Jones <lee@kernel.org>
>>
>> Could you include a compat_ioctl() callback in the example?
>> I think it would be good to include it as a reminder for
>> authors of actual drivers that every driver implementing
>> ioctl should also implement compat_ioctl. In C drivers, this
>> can usually be done by pointing .compat_ioctl() to the
>> generic compat_ptr_ioctl() function, which assumes that 'arg'
>> is a pointer disguised as an 'unsigned long'.
>
> The current Rust logic for building the fops table will use
> compat_ptr_ioctl() automatically if you specify ioctl() but don't
> specify compat_ioctl(), so this already uses compat_ptr_ioctl(). But
> maybe that's not what we want?
Ok, got it. It's usually the right thing to do, but it's easy
to get wrong if there is at least one ioctl command that actually
needs an integer argument instead of a pointer.
Almost all command definitions are for either no argument or
a pointer argument, and compat_ptr_ioctl() works fine there, by
doing a conversion from a 32-bit pointer to a 64-bit pointer
by zero-extending the upper 33 (on s390) or 32 bits (everywhere
else). Integer values need to either a 32-bit sign-extension
or a 32-bit zero-extension depending on how the argument is
interpreted on 32-bit architectures.
I wonder if we should change the prototype of the ioctl
callback to always pass a __user pointer and just not allow
the few commands that pass an integer in rust drivers, and
worry about it only when it's absolutely needed.
Arnd
next prev parent reply other threads:[~2024-12-06 10:31 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-06 9:05 [PATCH v4 0/4] rust: miscdevice: Provide sample driver using the new MiscDevice bindings Lee Jones
2024-12-06 9:05 ` [PATCH v4 1/4] Documentation: ioctl-number: Carve out some identifiers for use by sample drivers Lee Jones
2024-12-06 9:05 ` [PATCH v3 1/5] rust: miscdevice: Provide accessor to pull out miscdevice::this_device Lee Jones
2024-12-06 10:25 ` Miguel Ojeda
2024-12-06 12:05 ` Lee Jones
2024-12-06 9:05 ` [PATCH v3 2/5] Documentation: ioctl-number: Carve out some identifiers for use by sample drivers Lee Jones
2024-12-06 9:05 ` [PATCH v4 2/4] samples: rust: Provide example using the new Rust MiscDevice abstraction Lee Jones
2024-12-06 9:29 ` Danilo Krummrich
2024-12-06 9:40 ` Alice Ryhl
2024-12-06 9:58 ` Danilo Krummrich
2024-12-06 10:04 ` Arnd Bergmann
2024-12-06 10:09 ` Alice Ryhl
2024-12-06 10:29 ` Arnd Bergmann [this message]
2024-12-06 10:40 ` Alice Ryhl
2024-12-06 11:15 ` Arnd Bergmann
2024-12-06 9:05 ` [PATCH v4 3/4] sample: rust_misc_device: Demonstrate additional get/set value functionality Lee Jones
2024-12-06 9:05 ` [PATCH v3 3/5] samples: rust: Provide example using the new Rust MiscDevice abstraction Lee Jones
2024-12-06 9:05 ` [PATCH v4 4/4] MAINTAINERS: Add Rust Misc Sample to MISC entry Lee Jones
2024-12-06 9:05 ` [PATCH v3 4/5] sample: rust_misc_device: Demonstrate additional get/set value functionality Lee Jones
2024-12-06 9:05 ` [PATCH v3 5/5] MAINTAINERS: Add Rust Misc Sample to MISC entry Lee Jones
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=2073da49-37c6-4add-9450-47842d05cd79@app.fastmail.com \
--to=arnd@arndb.de \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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
all inboxes | Powered by JetHome®