LKML Archive mirror
 help / color / mirror / Atom feed
From: Alice Ryhl <aliceryhl@google.com>
To: Boqun Feng <boqun.feng@gmail.com>
Cc: "Benno Lossin" <benno.lossin@proton.me>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Matthew Wilcox" <willy@infradead.org>,
	"Al Viro" <viro@zeniv.linux.org.uk>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Kees Cook" <keescook@chromium.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Wedson Almeida Filho" <wedsonaf@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Andreas Hindborg" <a.hindborg@samsung.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Arve Hjønnevåg" <arve@android.com>,
	"Todd Kjos" <tkjos@android.com>,
	"Martijn Coenen" <maco@android.com>,
	"Joel Fernandes" <joel@joelfernandes.org>,
	"Carlos Llamas" <cmllamas@google.com>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Trevor Gross" <tmgross@umich.edu>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	rust-for-linux@vger.kernel.org,
	"Christian Brauner" <brauner@kernel.org>
Subject: Re: [PATCH v6 3/4] rust: uaccess: add typed accessors for userspace pointers
Date: Thu, 18 Apr 2024 21:35:53 +0200	[thread overview]
Message-ID: <CAH5fLghTqbK-b4z_GJYJF9PFj8JkkKE+dNNpELFZspC2o9Oa1A@mail.gmail.com> (raw)
In-Reply-To: <ZiFWIFMSBbU0i8JF@boqun-archlinux>

On Thu, Apr 18, 2024 at 7:27 PM Boqun Feng <boqun.feng@gmail.com> wrote:
>
> On Thu, Apr 18, 2024 at 04:23:06PM +0000, Benno Lossin wrote:
> > On 18.04.24 15:17, Alice Ryhl wrote:
> > > On Thu, Apr 18, 2024 at 3:02 PM Benno Lossin <benno.lossin@proton.me> wrote:
> > >>
> > >> On 18.04.24 10:59, Alice Ryhl wrote:
> > >>> diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs
> > >>> index 8fad61268465..9c57c6c75553 100644
> > >>> --- a/rust/kernel/types.rs
> > >>> +++ b/rust/kernel/types.rs
> > >>> @@ -409,3 +409,67 @@ pub enum Either<L, R> {
> > >>>       /// Constructs an instance of [`Either`] containing a value of type `R`.
> > >>>       Right(R),
> > >>>   }
> > >>> +
> > >>> +/// Types for which any bit pattern is valid.
> > >>> +///
> > >>> +/// Not all types are valid for all values. For example, a `bool` must be either zero or one, so
> > >>> +/// reading arbitrary bytes into something that contains a `bool` is not okay.
> > >>> +///
> > >>> +/// It's okay for the type to have padding, as initializing those bytes has no effect.
> > >>> +///
> > >>> +/// # Safety
> > >>> +///
> > >>> +/// All bit-patterns must be valid for this type. This type must not have interior mutability.
> > >>
> > >> What is the reason for disallowing interior mutability here? I agree
> > >> that it is necessary for `AsBytes`, but I don't think we need it here.
>
> Hmm.. technically, if the interior mutability behaves in a way that each
> byte is still initialized during the modification, then it should be
> fine for `AsBytes`, for example and `AtomicI32` (implemented by asm
> blocks)? Not making any change suggestion, just checking my understand.

No, that's UB. When the type is not interior mutable, then any two
loads from the same immutable reference may be assumed to return the
same value. Changing it with an atomic would violate that since the
value changes.

Alice

  reply	other threads:[~2024-04-18 19:36 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-18  8:59 [PATCH v6 0/4] Memory management patches needed by Rust Binder Alice Ryhl
2024-04-18  8:59 ` [PATCH v6 1/4] rust: uaccess: add userspace pointers Alice Ryhl
2024-04-19 17:11   ` Boqun Feng
2024-04-19 18:12     ` Alice Ryhl
2024-04-18  8:59 ` [PATCH v6 2/4] uaccess: always export _copy_[from|to]_user with CONFIG_RUST Alice Ryhl
2024-05-14 17:27   ` Andrew Morton
2024-05-15  7:34     ` Arnd Bergmann
2024-04-18  8:59 ` [PATCH v6 3/4] rust: uaccess: add typed accessors for userspace pointers Alice Ryhl
2024-04-18 13:01   ` Benno Lossin
2024-04-18 13:17     ` Alice Ryhl
2024-04-18 16:23       ` Benno Lossin
2024-04-18 17:19         ` Boqun Feng
2024-04-18 19:35           ` Alice Ryhl [this message]
2024-04-18 20:01             ` Boqun Feng
2024-04-18 17:52     ` Trevor Gross
2024-04-25 16:13   ` Gary Guo
2024-04-26  7:13     ` Alice Ryhl
2024-04-18  8:59 ` [PATCH v6 4/4] rust: add abstraction for `struct page` Alice Ryhl
2024-04-18 18:52   ` Boqun Feng
2024-04-18 22:08     ` Benno Lossin
2024-04-18 22:56       ` Boqun Feng
2024-04-18 23:04         ` Boqun Feng
2024-04-19  8:36           ` Benno Lossin
2024-04-19 17:23             ` Boqun Feng
2024-04-19 19:24               ` Benno Lossin
2024-04-19 19:35                 ` Boqun Feng
2024-04-25 16:20         ` Gary Guo

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=CAH5fLghTqbK-b4z_GJYJF9PFj8JkkKE+dNNpELFZspC2o9Oa1A@mail.gmail.com \
    --to=aliceryhl@google.com \
    --cc=a.hindborg@samsung.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex.gaynor@gmail.com \
    --cc=arnd@arndb.de \
    --cc=arve@android.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=brauner@kernel.org \
    --cc=cmllamas@google.com \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=joel@joelfernandes.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=maco@android.com \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=tkjos@android.com \
    --cc=tmgross@umich.edu \
    --cc=viro@zeniv.linux.org.uk \
    --cc=wedsonaf@gmail.com \
    --cc=willy@infradead.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).