[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAH5fLgjRd5S4owRrZS7ONeb=-Tzq+xQDtWtqii1tCgEoqzr+bw@mail.gmail.com>
Date: Wed, 11 Jun 2025 13:08:11 +0200
From: Alice Ryhl <aliceryhl@...gle.com>
To: Andreas Hindborg <a.hindborg@...nel.org>
Cc: Danilo Krummrich <dakr@...nel.org>, 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 <lossin@...nel.org>, Trevor Gross <tmgross@...ch.edu>,
Bjorn Helgaas <bhelgaas@...gle.com>, Krzysztof Wilczyński <kwilczynski@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>, "Rafael J. Wysocki" <rafael@...nel.org>,
Tamir Duberstein <tamird@...il.com>, Viresh Kumar <viresh.kumar@...aro.org>,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-pci@...r.kernel.org, Maíra Canal <mcanal@...lia.com>
Subject: Re: [PATCH] rust: types: add FOREIGN_ALIGN to ForeignOwnable
On Wed, Jun 11, 2025 at 12:46 PM Andreas Hindborg <a.hindborg@...nel.org> wrote:
>
> "Alice Ryhl" <aliceryhl@...gle.com> writes:
>
> > On Thu, Jun 5, 2025 at 10:00 PM Andreas Hindborg <a.hindborg@...nel.org> wrote:
> >>
> >> The current implementation of `ForeignOwnable` is leaking the type of the
> >> opaque pointer to consumers of the API. This allows consumers of the opaque
> >> pointer to rely on the information that can be extracted from the pointer
> >> type.
> >>
> >> To prevent this, change the API to the version suggested by Maira
> >> Canal (link below): Remove `ForeignOwnable::PointedTo` in favor of a
> >> constant, which specifies the alignment of the pointers returned by
> >> `into_foreign`.
> >>
> >> Suggested-by: Alice Ryhl <aliceryhl@...gle.com>
> >> Suggested-by: Maíra Canal <mcanal@...lia.com>
> >> Link: https://lore.kernel.org/r/20240309235927.168915-3-mcanal@igalia.com
> >> Signed-off-by: Andreas Hindborg <a.hindborg@...nel.org>
> >
> > One nit below. With that and things other folks mentioned fixed, you may add:
> >
> > Reviewed-by: Alice Ryhl <aliceryhl@...gle.com>
> >
> >> diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs
> >> index 22985b6f6982..025c619a2195 100644
> >> --- a/rust/kernel/types.rs
> >> +++ b/rust/kernel/types.rs
> >> @@ -21,15 +21,11 @@
> >> ///
> >> /// # Safety
> >> ///
> >> -/// Implementers must ensure that [`into_foreign`] returns a pointer which meets the alignment
> >> -/// requirements of [`PointedTo`].
> >> -///
> >> -/// [`into_foreign`]: Self::into_foreign
> >> -/// [`PointedTo`]: Self::PointedTo
> >> +/// Implementers must ensure that [`Self::into_foreign`] return pointers with alignment that is an
> >> +/// integer multiple of [`Self::FOREIGN_ALIGN`].
> >
> > We should require non-null:
>
> What is your rationale for this?
The rationale is that the implementation of XArray assumes that the
pointers are non-null. If we allow null pointers, we will need to fix
the XArray.
Alice
Powered by blists - more mailing lists