From: Lyude Paul <lyude@redhat.com>
To: Danilo Krummrich <dakr@redhat.com>, Greg KH <gregkh@linuxfoundation.org>
Cc: Boqun Feng <boqun.feng@gmail.com>,
	rafael@kernel.org, mcgrof@kernel.org, russell.h.weight@intel.com,
	ojeda@kernel.org, alex.gaynor@gmail.com,  wedsonaf@gmail.com,
	gary@garyguo.net, bjorn3_gh@protonmail.com,
	 benno.lossin@proton.me, a.hindborg@samsung.com,
	aliceryhl@google.com,  airlied@gmail.com,
	fujita.tomonori@gmail.com, pstanner@redhat.com,
	 ajanulgu@redhat.com, rust-for-linux@vger.kernel.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] rust: add abstraction for struct device
Date: Thu, 13 Jun 2024 16:18:55 -0400	[thread overview]
Message-ID: <3fae55cb4012c137072b54f4ec96027190958048.camel@redhat.com> (raw)
In-Reply-To: <Zmrkg7oOceWWV4nz@pollux>
On Thu, 2024-06-13 at 14:22 +0200, Danilo Krummrich wrote:
> On Thu, Jun 13, 2024 at 07:47:13AM +0200, Greg KH wrote:
> > On Wed, Jun 12, 2024 at 10:56:43PM +0200, Danilo Krummrich wrote:
> > 
> > As someone who has written comments in code for functions that are
> > always ignored, I am happy to see you think that this is actually
> > going
> > to do anything :)
> 
> One advantage we have in Rust is, that if something has a specific
> requirement
> we mark it as `unsafe` and the user of the API has to put it in an
> `unsafe`
> block, which we require a sfety comment for, where the user of the
> API has to
> explain why this is the correct thing to do in this case.
> 
> In other words we can technically enforce that people read the
> comment and
> explain how they ensure to fulfill what the comment asks for.
Been going through this thread to catch up on the status of the patches
here: I've been working with danilo for a while, but have been busy
with kernel modesetting bindings for rust. Anyway, as someone who's
spent quite a lot of time writing up really detailed documentation for
some of the DisplayPort MST kernel APIs only to keep running into
situations where said documentation was ignored (not to criticize
anyone! I'm certainly guilty of having misread documentation or not
reading something myself :) I like to think about unsafe blocks in the
sense of being one thing I'm less likely to have to keep repeating
myself about over a mailing list. Because I know at the very least that
a contributor has to actively ignore a compiler warning or be aware in
some sense that there is some kind of safety constraint they're being
held responsible for that will come up during code review. If it's just
a comment in C code, I don't even have a guarantee that a contributor's
IDE isn't hiding large kdoc comments by default.
Also, in regards to rust code relying on C code not being guaranteed
safe even if it is 'safe' code: frankly, sometimes I wish "unsafe" was
just named "danger". "un-safe" implies code outside the block is
perfectly "safe" - but it is still possible to introduce UB in entirely
safe code bases (source: cve-rs) and most rust contributors I've talked
to don't see safe code as being perfectly-safe either.
> 
> > 
> > Heck, I have put huge messages in kernel code for when people
> > implement
> > the api wrong[1], and they still ignore that at runtime.  Only way
> > to get
> > it noticed is if you break someone's build.
> 
> You only see the ones who still do it wrong. You probably don't have
> visibility
> of the ones who did it right due to your effort to write it down. :-)
> 
> > 
> > So you all need to really define what `Send` means, as it sounds
> > like a
> > userspace thing that isn't going to fit in well within the kernel
> > model.
> 
> Please see the explanation above.
> 
> > 
> > thanks,
> > 
> > greg k-h
> > 
> > [1] See the pr_debug() calls in kobject_cleanup() as proof, people
> > just
> >     create an "empty" release function to shut them up, thinking
> > that is
> >     the correct solution when obviously it is not...
> > 
> 
-- 
Cheers,
 Lyude Paul (she/her)
 Software Engineer at Red Hat
next prev parent reply	other threads:[~2024-06-13 20:19 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-10 18:02 [PATCH v2 0/2] Rust abstractions for Device & Firmware Danilo Krummrich
2024-06-10 18:02 ` [PATCH v2 1/2] rust: add abstraction for struct device Danilo Krummrich
2024-06-10 18:38   ` Boqun Feng
2024-06-11 13:21     ` Danilo Krummrich
2024-06-11 13:29       ` Greg KH
2024-06-11 16:13         ` Boqun Feng
2024-06-12 13:59           ` Danilo Krummrich
2024-06-12 14:51           ` Danilo Krummrich
2024-06-12 15:02             ` Greg KH
2024-06-12 15:35               ` Danilo Krummrich
2024-06-12 15:50                 ` Greg KH
2024-06-12 16:18                   ` Danilo Krummrich
2024-06-12 17:13                     ` Greg KH
2024-06-12 17:43                       ` Greg KH
2024-06-12 20:56                       ` Danilo Krummrich
2024-06-13  5:47                         ` Greg KH
2024-06-13 12:22                           ` Danilo Krummrich
2024-06-13 20:18                             ` Lyude Paul [this message]
2024-06-10 18:02 ` [PATCH v2 2/2] rust: add firmware abstractions Danilo Krummrich
2024-06-11  6:31   ` Greg KH
2024-06-11 13:34     ` Danilo Krummrich
2024-06-11 13:44       ` 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=3fae55cb4012c137072b54f4ec96027190958048.camel@redhat.com \
    --to=lyude@redhat.com \
    --cc=a.hindborg@samsung.com \
    --cc=airlied@gmail.com \
    --cc=ajanulgu@redhat.com \
    --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=dakr@redhat.com \
    --cc=fujita.tomonori@gmail.com \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=pstanner@redhat.com \
    --cc=rafael@kernel.org \
    --cc=russell.h.weight@intel.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=wedsonaf@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).