lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAH5fLgim-L2nDwrV689-0uizgpLy2pZL1BT3vyBbW7syejn1NA@mail.gmail.com>
Date: Wed, 16 Jul 2025 11:46:08 +0200
From: Alice Ryhl <aliceryhl@...gle.com>
To: Danilo Krummrich <dakr@...nel.org>
Cc: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>, "Liam R. Howlett" <Liam.Howlett@...cle.com>, 
	Andrew Morton <akpm@...ux-foundation.org>, Matthew Wilcox <willy@...radead.org>, 
	Tamir Duberstein <tamird@...il.com>, Andreas Hindborg <a.hindborg@...nel.org>, 
	Miguel Ojeda <ojeda@...nel.org>, 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>, linux-mm@...ck.org, 
	rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/2] rust: alloc: take the allocator into account for FOREIGN_ALIGN

On Tue, Jul 15, 2025 at 4:19 PM Danilo Krummrich <dakr@...nel.org> wrote:
>
> On Tue Jul 15, 2025 at 3:46 PM CEST, Alice Ryhl wrote:
> > diff --git a/rust/kernel/alloc/kbox.rs b/rust/kernel/alloc/kbox.rs
> > index bffe72f44cb33a265018e67d92d9f0abe82f8e22..fd3f1e0b9c3b3437fb50d8f1b28c92bc7cefd565 100644
> > --- a/rust/kernel/alloc/kbox.rs
> > +++ b/rust/kernel/alloc/kbox.rs
> > @@ -400,12 +400,19 @@ fn try_init<E>(init: impl Init<T, E>, flags: Flags) -> Result<Self, E>
> >  }
> >
> >  // SAFETY: The pointer returned by `into_foreign` comes from a well aligned
> > -// pointer to `T`.
> > +// pointer to `T` allocated by `A`.
> >  unsafe impl<T: 'static, A> ForeignOwnable for Box<T, A>
> >  where
> >      A: Allocator,
> >  {
> > -    const FOREIGN_ALIGN: usize = core::mem::align_of::<T>();
> > +    const FOREIGN_ALIGN: usize = {
> > +        let mut align = core::mem::align_of::<T>();
> > +        if align < A::MIN_ALIGN {
> > +            align = A::MIN_ALIGN;
> > +        }
> > +        align
> > +    };
>
> Pretty unfortunate that core::cmp::max() can't be used from const context. :(
>
> What do you think about
>
>         const FOREIGN_ALIGN: usize =
>             if core::mem::align_of::<T>() < A::MIN_ALIGN {
>                 A::MIN_ALIGN
>             } else {
>                 core::mem::align_of::<T>()
>             };
>
> instead? I think that reads a bit better.

I don't mind doing that instead.

Alice

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ