From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Alexandre Courbot <acourbot@nvidia.com>,
Daniel Almeida <daniel.almeida@collabora.com>,
Viresh Kumar <viresh.kumar@linaro.org>,
Sasha Levin <sashal@kernel.org>,
rafael@kernel.org, ojeda@kernel.org, lossin@kernel.org,
gary@garyguo.net, linux-pm@vger.kernel.org,
rust-for-linux@vger.kernel.org
Subject: [PATCH AUTOSEL 6.19-6.18] rust: cpufreq: always inline functions using build_assert with arguments
Date: Wed, 11 Feb 2026 07:30:26 -0500 [thread overview]
Message-ID: <20260211123112.1330287-16-sashal@kernel.org> (raw)
In-Reply-To: <20260211123112.1330287-1-sashal@kernel.org>
From: Alexandre Courbot <acourbot@nvidia.com>
[ Upstream commit 8c8b12a55614ea05953e8d695e700e6e1322a05d ]
`build_assert` relies on the compiler to optimize out its error path.
Functions using it with its arguments must thus always be inlined,
otherwise the error path of `build_assert` might not be optimized out,
triggering a build error.
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
LLM Generated explanations, may be completely bogus:
Now I have all the information needed for a thorough analysis. Here is
my assessment:
---
## Analysis: `rust: cpufreq: always inline functions using build_assert
with arguments`
### 1. What the Commit Does
This commit adds `#[inline(always)]` (plus explanatory comment) to the
`const fn copy_name()` function in `rust/kernel/cpufreq.rs`. This
function uses `build_assert!` to validate that a driver name string fits
within `CPUFREQ_NAME_LEN`.
### 2. The Bug Mechanism (Build Fix)
The `build_assert!` macro works by calling `build_error()` on the error
path. `build_error()` (defined in `rust/build_error.rs`) is exported
with the symbol name `rust_build_error`. Crucially, in the Makefile:
```25:26:rust/Makefile
always-$(CONFIG_RUST) += build_error.o
endif
```
When `CONFIG_RUST_BUILD_ASSERT_ALLOW` is NOT set (the default),
`build_error.o` is compiled but **not linked** into the kernel. This
means any reference to `rust_build_error` in the final binary causes a
**linker error** -- this is the deliberate mechanism that turns
`build_assert!` into a build-time check.
The problem: if `copy_name()` is not inlined, the compiler generates a
standalone function body where the `name` parameter is opaque. It cannot
prove that `src.len() <= CPUFREQ_NAME_LEN` will always hold, so it
preserves the `build_error()` call. This creates a reference to the
deliberately-missing `rust_build_error` symbol, causing a **build
failure**.
With `#[inline(always)]`, the function body is always expanded at the
call site where the actual argument (`T::NAME`) is a known const value.
The compiler can then evaluate the condition, prove it's true, and
eliminate the error path -- allowing successful linking.
### 3. Established Pattern -- Sibling Patches Were All Tagged for Stable
This commit is part of a broader effort by Alexandre Courbot to fix all
`build_assert!`-using functions that lack `#[inline(always)]`. The
**four sibling patches** (all with identical commit messages) that fix
this in other files **all have** `Cc: stable@vger.kernel.org` and
`Fixes:` tags:
- `d6ff6e870077a` - `rust: sync: refcount` -- **Cc: stable, Fixes:
bb38f35b35f9**
- `09c3c9112d71c` - `rust: bits` -- **Cc: stable, Fixes: cc84ef3b88f4**
- `5d9c4c272ba06` - `rust: irq` -- **Cc: stable, Fixes: 746680ec6696**
- `33d19f621641d` - `rust: io` -- **Cc: stable, Fixes: ce30d94e6855**
The cpufreq variant likely lacks the stable tag because it was sent
through a different maintainer tree (Viresh Kumar's cpufreq tree, not
the Rust or DRM trees), not because it's less important.
### 4. Consistency with Existing Code
Identical patterns in the codebase **already have** `#[inline(always)]`:
- `i2c.rs:45` - `pub const fn new()` with `build_assert!` on string
length
- `acpi.rs:38` - `pub const fn new()` with `build_assert!` on string
length
- `ioctl.rs:12` - `const fn _IOC()` with multiple `build_assert!` calls
- `bits.rs:31-32` - `bit_*` and `genmask_*` functions
- `irq/flags.rs:100-101` - `const fn new()`
- `io/resource.rs:230-231` - `const fn new()`
- `num/bounded.rs:369-370` - `from_expr()`
The `cpufreq.rs` `copy_name` function is the exact same pattern (const
fn taking an argument, using `build_assert!` on it) but was missing the
annotation -- clearly an oversight.
### 5. Affected Stable Trees
The file `rust/kernel/cpufreq.rs` was introduced in v6.16. I confirmed
the vulnerable `copy_name` function (without `#[inline(always)]`) exists
in:
- **v6.18.9** (latest 6.18 stable)
- **v6.17.13** (latest 6.17 stable)
- **v6.16** (and its stable updates)
### 6. Risk Assessment
- **Change size**: 2 lines (1 comment + 1 attribute annotation)
- **Behavioral change**: Zero runtime change. `#[inline(always)]` only
affects compilation.
- **Regression risk**: Effectively zero. The function was likely already
being inlined by the optimizer; this just guarantees it, matching the
established pattern.
- **Benefit**: Prevents potential build failures that could occur with
different Rust compiler versions, optimization levels, or future code
changes that affect inlining decisions.
### 7. Classification
This is a **build fix** -- one of the categories explicitly approved for
stable backporting. It prevents a linker error that could occur when the
compiler decides not to inline `copy_name`. The sibling fixes were all
explicitly tagged for stable by the author and maintainers.
### 8. Dependencies
None. This is a self-contained 2-line change with no dependencies on
other patches.
### Conclusion
This is a minimal, zero-risk build fix that follows an established
pattern across the Rust kernel codebase. Every sibling patch from the
same author fixing the exact same class of issue was tagged `Cc:
stable@vger.kernel.org`. The affected code exists in 6.16.y, 6.17.y, and
6.18.y stable trees. The only reason this specific patch lacks the
stable tag is likely that it went through a different maintainer tree.
The fix is obviously correct, small, and prevents potential build
failures.
**YES**
rust/kernel/cpufreq.rs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/rust/kernel/cpufreq.rs b/rust/kernel/cpufreq.rs
index f968fbd228905..0879a79485f8e 100644
--- a/rust/kernel/cpufreq.rs
+++ b/rust/kernel/cpufreq.rs
@@ -1015,6 +1015,8 @@ impl<T: Driver> Registration<T> {
..pin_init::zeroed()
};
+ // Always inline to optimize out error path of `build_assert`.
+ #[inline(always)]
const fn copy_name(name: &'static CStr) -> [c_char; CPUFREQ_NAME_LEN] {
let src = name.to_bytes_with_nul();
let mut dst = [0; CPUFREQ_NAME_LEN];
--
2.51.0
next prev parent reply other threads:[~2026-02-11 12:31 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-11 12:30 [PATCH AUTOSEL 6.19-5.10] s390/perf: Disable register readout on sampling events Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] arm64: Add support for TSV110 Spectre-BHB mitigation Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] xenbus: Use .freeze/.thaw to handle xenbus devices Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] s390/purgatory: Add -Wno-default-const-init-unsafe to KBUILD_CFLAGS Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.18] s390/boot: " Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.1] perf/arm-cmn: Support CMN-600AE Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.18] ntfs: ->d_compare() must not block Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.12] ACPI: x86: s2idle: Invoke Microsoft _DSM Function 9 (Turn On Display) Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.12] block: decouple secure erase size limit from discard size limit Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] sparc: don't reference obsolete termio struct for TC* constants Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] EFI/CPER: don't go past the ARM processor CPER record buffer Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19] ACPI: scan: Use async schedule function in acpi_scan_clear_dep_fn() Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.6] cpufreq: dt-platdev: Block the driver from probing on more QC platforms Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] EFI/CPER: don't dump the entire memory region Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.12] ACPI: battery: fix incorrect charging status when current is zero Sasha Levin
2026-02-11 12:30 ` Sasha Levin [this message]
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.18] blk-mq-sched: unify elevators checking for async requests Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] x86/xen/pvh: Enable PAE mode for 32-bit guest only when CONFIG_X86_PAE is set Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.12] APEI/GHES: ARM processor Error: don't go past allocated memory Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.18] md raid: fix hang when stopping arrays with metadata through dm-raid Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] tools/power cpupower: Reset errno before strtoull() Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] sparc: Synchronize user stack on fork and clone Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] blk-mq-debugfs: add missing debugfs_mutex in blk_mq_debugfs_register_hctxs() Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] rnbd-srv: Zero the rsp buffer before using it Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.12] alpha: fix user-space corruption during memory compaction Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] ACPICA: Abort AML bytecode execution when executing AML_FATAL_OP Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19] arm64: mte: Set TCMA1 whenever MTE is present in the kernel Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.18] tools/cpupower: Fix inverted APERF capability check Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.15] ACPI: processor: Fix NULL-pointer dereference in acpi_processor_errata_piix4() Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.12] ACPI: resource: Add JWIPC JVC9100 to irq1_level_low_skip_override[] Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.6] perf/cxlpmu: Replace IRQF_ONESHOT with IRQF_NO_THREAD Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.6] md-cluster: fix NULL pointer dereference in process_metadata_update Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] APEI/GHES: ensure that won't go past CPER allocated record Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.12] powercap: intel_rapl: Add PL4 support for Ice Lake Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.18] io_uring/timeout: annotate data race in io_flush_timeouts() Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260211123112.1330287-16-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=acourbot@nvidia.com \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=linux-pm@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=patches@lists.linux.dev \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox