[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJ-ks9=3LC7MM+uubZfjRTrWYa+sOakeq-0hwZpXK9hxXtuG5g@mail.gmail.com>
Date: Wed, 12 Feb 2025 16:24:06 -0500
From: Tamir Duberstein <tamird@...il.com>
To: Danilo Krummrich <dakr@...nel.org>
Cc: Gary Guo <gary@...yguo.net>, Miguel Ojeda <ojeda@...nel.org>, DJ Delorie <dj@...hat.com>,
Eric Blake <eblake@...hat.com>, Paul Eggert <eggert@...ucla.edu>,
Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>, Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>, rust-for-linux@...r.kernel.org,
linux-man@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v5] rust: alloc: satisfy POSIX alignment requirement
On Wed, Feb 12, 2025 at 3:58 PM Danilo Krummrich <dakr@...nel.org> wrote:
>
> On Wed, Feb 12, 2025 at 03:47:11PM -0500, Tamir Duberstein wrote:
> > Looks like I wasn't the only one to fall into the trap (rust/kernel/io.rs):
> >
> > #[inline]
> > const fn io_addr_assert<U>(&self, offset: usize) -> usize {
> > build_assert!(Self::offset_valid::<U>(offset, SIZE));
> >
> > self.addr() + offset
> > }
> >
> > since offset isn't known at compile time, this can easily be misused?
>
> Well, that's intentional.
>
> iomem.readb(0x0) // succeeds if SIZE >=1
> iomem.readb(foo) // fails if foo is not known at compile time
By "fails" here you mean fail to link, right?
> iomem.try_readb(foo) // succeeds if self.maxsize() >= 1
Apologies for being dense throughout this discussion. Could you check
my understanding?
The trick is that `build_error` is marked `#[export_name =
"rust_build_error"]` which isn't exported unless
CONFIG_RUST_BUILD_ASSERT_ALLOW is defined, causing linking to it to
fail. This even works for doctests, but not for #[test] in the kernel
crate because they are built as part of the crate. The only to way
make that work correctly is to put `build_error` in a crate all by
itself.
Powered by blists - more mailing lists