rust: build_assert: document and fix use with function arguments
Status from this message: Applied to driver-core-linus, thanks!
Get series with b4
b4 am [email protected] change-id 20251127-io-build-assert-3579a5bfb81cVersions newest first
Changes in v3 from the cover letter
- Add "Fixes:" tags.
- CC stable on fixup patches.
- Link to v2: https://patch.msgid.link/[email protected]
Patches in v3 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/7 | rust: build_assert: add instructions for use with function argumentsrust/ | +6 | 0 replies | |
| 2/7 | rust: io: always inline functions using build_assert with argumentsrust/ rust/ | +8 | 1 reply | |
| 3/7 | rust: cpufreq: always inline functions using build_assert with argumentsrust/ | +2 | 7 replies | |
| 4/7 | rust: bits: always inline functions using build_assert with argumentsrust/ | +4 | 0 replies | |
| 5/7 | rust: sync: refcount: always inline functions using build_assert with argumentsrust/ | +2 | 2 replies | |
| 6/7 | rust: irq: always inline functions using build_assert with argumentsrust/ | +2 | 0 replies | |
| 7/7 | rust: num: bounded: add missing comment for always inlined functionrust/ | +1 | 0 replies |
Reviews trailers per patch
All 7 patches have a Reviewed-by or Acked-by.
| Patch | Daniel Almeida | Viresh Kumar | Timur Tabi | Boqun Feng |
|---|---|---|---|---|
| 1/7 | R-b | |||
| 2/7 | R-b | T-b | ||
| 3/7 | R-b | A-b | ||
| 4/7 | R-b | |||
| 5/7 | R-b | A-b | ||
| 6/7 | R-b | |||
| 7/7 | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.
Cover letter [PATCH v3 0/7] rust: build_assert: document and fix use with function arguments
build_assert relies on the compiler to optimize out its error path, lest build fails with the dreaded error:
ERROR: modpost: "rust_build_error" [path/to/module.ko] undefined!
It has been observed that very trivial code performing I/O accesses (sometimes even using an immediate value) would seemingly randomly fail with this error whenever CLIPPY=1 was set. The same behavior was also observed until different, very similar conditions [1][2].
The cause, as pointed out by Gary Guo [3], appears to be that the failing function is eventually using build_assert with its argument, but is only annotated with #[inline]. This gives the compiler freedom to not inline the function, which it notably did when Clippy was active, triggering the error.
The fix is to annotate functions passing their argument to build_assert with #[inline(always)], telling the compiler to be as aggressive as possible with their inlining. This is also the correct behavior as inlining is mandatory for correct behavior in these cases.
This series fixes all possible points of failure in the kernel crate, and adds documentation to build_assert explaining how to properly inline functions for which this behavior may arise.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
---
Changes in v3:
- Add "Fixes:" tags.
- CC stable on fixup patches.
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- Turn into a series and address other similar cases in the kernel crate.
- Link to v1: https://patch.msgid.link/[email protected]
---
Alexandre Courbot (7):
rust: build_assert: add instructions for use with function arguments
rust: io: always inline functions using build_assert with arguments
rust: cpufreq: always inline functions using build_assert with arguments
rust: bits: always inline functions using build_assert with arguments
rust: sync: refcount: always inline functions using build_assert with arguments
rust: irq: always inline functions using build_assert with arguments
rust: num: bounded: add missing comment for always inlined function
rust/kernel/bits.rs | 6 ++++-- rust/kernel/build_assert.rs | 7 ++++++- rust/kernel/cpufreq.rs | 2 ++ rust/kernel/io.rs | 9 ++++++--- rust/kernel/io/resource.rs | 2 ++ rust/kernel/irq/flags.rs | 2 ++ rust/kernel/num/bounded.rs | 1 + rust/kernel/sync/refcount.rs | 3 ++- 8 files changed, 25 insertions(+), 7 deletions(-)
---
base-commit: ba65a4e7120a616d9c592750d9147f6dcafedffa
change-id: 20251127-io-build-assert-3579a5bfb81c
Best regards,
Signature · 1 line
Alexandre Courbot <[email protected]>