[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAH5fLggXGMHM1bhmaUb94gDu_LiUbMGugARpOZoUNSTU3phm=g@mail.gmail.com>
Date: Sun, 21 Sep 2025 12:46:26 +0200
From: Alice Ryhl <aliceryhl@...gle.com>
To: Joel Fernandes <joelagnelf@...dia.com>
Cc: linux-kernel@...r.kernel.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>, Andreas Hindborg <a.hindborg@...nel.org>,
Trevor Gross <tmgross@...ch.edu>, Danilo Krummrich <dakr@...nel.org>, acourbot@...dia.com,
Alistair Popple <apopple@...dia.com>, Timur Tabi <ttabi@...dia.com>, rust-for-linux@...r.kernel.org
Subject: Re: [PATCH] rust: print: Fix issue with rust_build_error
On Sat, Sep 20, 2025 at 6:20 PM Joel Fernandes <joelagnelf@...dia.com> wrote:
>
> When printing just before calling io.write32(), modpost fails due to
> build_assert's missing rust_build_error symbol. The issue is that, the
> printk arguments are passed as reference in bindings code, thus Rust
> cannot trust its value and fails to optimize away the build_assert.
>
> The issue can be reproduced with the following simple snippet:
> let offset = 0;
> pr_err!("{}", offset);
> io.write32(base, offset);
>
> Fix it by just using a closure to call printk. Rust captures the
> arguments into the closure's arguments thus breaking the dependency.
> This can be fixed by simply creating a variable alias for each variable
> however the closure is a simple and concise fix.
>
> Another approach with using const-generics for the io.write32 API was
> investigated, but it cannot work with code that dynamically calculates
> the write offset.
>
> Disassembly of users of pr_err!() with/without patch shows identical
> code generation, thus the fix has no difference in the final binary.
>
> Signed-off-by: Joel Fernandes <joelagnelf@...dia.com>
The actual bug is that write32 uses build_error!. Trying to change the
printing macros is just a band-aid. Someone already mentioned that it
breaks the ? operator. I think this change is a bad idea. We should
fix the actual problem, rather than making random changes to other
parts of the kernel to work around build_error!'s inherent fragility.
Alice
Powered by blists - more mailing lists