Skip to content

soc: apple: clpc: link without the SMC driver - #2693

Closed
RyanTheTide wants to merge 2 commits into
integration/aurorafrom
fix/clpc-link-without-smc-20261121
Closed

RyanTheTide wants to merge 2 commits into
integration/aurorafrom
fix/clpc-link-without-smc-20261121

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem. APPLE_CLPC treats the SMC as optional (depends on MFD_MACSMC || !MFD_MACSMC), but the PHPC package-power read and the zETM High Power mode record call apple_smc_read()/apple_smc_write(), which have no stubs. Any kernel with APPLE_CLPC=y and MFD_MACSMC unset fails to link. That includes the driver's own drivers/soc/apple/clpc.kunitconfig, so the CLPC KUnit suite does not build on integration/aurora today.

Change. Test IS_ENABLED(CONFIG_MFD_MACSMC) before the SMC lookup in both callers, so they return -ENODEV and the calls drop out at compile time. Without the SMC driver, the low-power profile has only its frequency ceiling, which is what already happens when the node has no apple,smc phandle. Kernels with the SMC driver (all our distro and fleet configs) are unchanged.

Testing (KUnit, arm64 qemu, kunit.py run --kunitconfig drivers/soc/apple/clpc.kunitconfig --arch=arm64):

  • integration/aurora cc14570, stock kunitconfig: link fails (undefined apple_smc_write, apple_smc_read)
  • with this change, stock kunitconfig (no SMC): 11/11 pass
  • with this change, plus APPLE_MAILBOX/APPLE_RTKIT/MFD_MACSMC=y: 13 pass, 1 skipped
  • checkpatch --strict clean

Still to run. Nothing on hardware: with the SMC driver built in, the object code paths are the same.

Reviewer detail
  • First breaking commit: bdd3bc3 (PHPC read, T6050 platform profiles); f04da7c added the zETM write.
  • Second commit: tools/asahi/clpc-high-power-cleanup-tests.py compiles the extracted function against its own prelude, which lacked IS_ENABLED/CONFIG_MFD_MACSMC. It now defines both, with the SMC driver built in, so the test keeps covering the SMC path. That test passes with gcc 16.1 and clang 22, its --old-ref 677be395 variant still fails the pre-fix source as intended, and clpc-gpu-demand-tests passes.
  • No gate: the guard is on the Kconfig symbol of the optional dependency, not on a chip or board.
  • Logs and patches: lab store traces/kernel/20261121-cts-viewmask-clpc/ (kunit-integ-cc145705-nosmc.log, kunit-fix-nosmc.log, kunit-fix-smc.log).
  • Found while rebasing soc: apple: clpc: Take the Low Power mode ceiling from the DT #1906 for the J616s Low Power row.

Assisted-by: LLM (Claude:Opus 5.5)

APPLE_CLPC treats the SMC as optional ("depends on MFD_MACSMC ||
!MFD_MACSMC"), but the PHPC package-power read and the zETM High Power
mode record call apple_smc_read()/apple_smc_write(), which have no
stubs. A kernel with APPLE_CLPC=y and MFD_MACSMC unset fails to link:

  clpc.c: undefined reference to `apple_smc_write'
  clpc.c: undefined reference to `apple_smc_read'

That includes the driver's own clpc.kunitconfig, which does not enable
the SMC.

Test IS_ENABLED(CONFIG_MFD_MACSMC) before looking the SMC up, so both
paths return -ENODEV and the calls drop out at compile time. The low-power
profile then has only its frequency ceiling, as it already does when the
node has no apple,smc phandle. Kernels with the SMC driver are unchanged.

Fixes: bdd3bc3 ("soc: apple: clpc: T6050 platform profiles after macOS's power modes")
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
apple_clpc_send_high_power() now tests IS_ENABLED(CONFIG_MFD_MACSMC)
before it talks to the SMC. The host test compiles the extracted
function against its own prelude, which had neither macro, so it
stopped building. Define both, with the SMC driver built in, so the
test keeps exercising the SMC path it checks.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

No blockers.

Checked at da9e3bb: Kconfig depends on MFD_MACSMC || !MFD_MACSMC (drivers/soc/apple/Kconfig:320) rules out APPLE_CLPC=y with MFD_MACSMC=m, so IS_ENABLED() is enough here and IS_REACHABLE() isn't needed. The two apple_smc_*() calls in clpc.c (clpc.c:824, clpc.c:1305) are now the only ones, and both sit behind the new guard (clpc.c:822, clpc.c:1301), so they drop out at compile time. apple_clpc_smc() uses only driver-core and OF calls, so it links either way. With the SMC driver built in, the code is unchanged. Without it, the low-power profile keeps its frequency ceiling and skips the power step-down, the same as a node with no apple,smc.

  1. clpc.c:1509: without the SMC driver, clpc->high_power is still set when the node has the phandle and the machine matches. apple_clpc_profile_set() then calls apple_clpc_send_high_power(), which returns -ENODEV (clpc.c:1337-1342). So selecting "performance", which apple_clpc_profile_probe() still advertises, fails on every write. That is safe, since nothing changes, but it isn't the "same as no phandle" case the description claims, where performance applies normally. Add IS_ENABLED(CONFIG_MFD_MACSMC) && to the clpc->high_power assignment so both cases behave alike. Keep the guards in the two callers for the link.
  2. Nit: the High Power write came in with f04da7c, not bdd3bc3. Add a second Fixes: f04da7cf87ff ("soc: apple: clpc: J714s: tell the SMC about High Power mode") to the first commit.

HW row: not needed for the MFD_MACSMC=y configs, whose code paths don't change. A make drivers/soc/apple/clpc.o with the fleet config before and after, with identical objdump -d, would show that directly.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adversarial pre-PR checklist review at da9e3bbcab83ebb807e2be4ba797c4c98f57113e (REQUEST_CHANGES).

Checklist Summary

  • §1 (No model gating): Pass — guards on IS_ENABLED(CONFIG_MFD_MACSMC) for the optional Kconfig dependency.
  • §2 (No hacks / default cmdline): Pass.
  • §3 (Kconfig link safety & correctness): Kconfig link safety passes (depends on MFD_MACSMC || !MFD_MACSMC in drivers/soc/apple/Kconfig:320 disallows APPLE_CLPC=y with MFD_MACSMC=m, so IS_ENABLED(CONFIG_MFD_MACSMC) covers every valid build combination, and both apple_smc_read_u32()/:824 and apple_smc_write()/:1305 are behind it). However, there is a real behavioral bug in the !CONFIG_MFD_MACSMC path (see Blocker below).
  • §4 (Clean-room & attribution): Pass — both commits (6fb5d1ca, da9e3bbc) have human author/committer (Ryan Murray <ryan@aurorasilicon.org>) and Signed-off-by: only; PR body includes Assisted-by:.
  • §5 (Evidence): KUnit (arm64 qemu with and without SMC) and host tests (tools/asahi/clpc-high-power-cleanup-tests.py, clpc-gpu-demand-tests) pass.
  • §6 (Naming): Pass.
  • CI: 7/7 checks PASS (host-tests, source, rust-build, kunit, DWC3/ATC builtin-no-atc, DWC3/ATC modular-no-atc, DWC3/ATC builtin-modular-atc).

Blocker

  1. performance profile permanently fails with -ENODEV when CONFIG_MFD_MACSMC=n on a high_power_machine with apple,smc in DT (drivers/soc/apple/clpc.c:1508-1510, :1337-1344):
    • In apple_clpc_probe() (clpc.c:1508-1510), clpc->smc_np is still parsed and clpc->high_power is still set to true even when !IS_ENABLED(CONFIG_MFD_MACSMC).
    • apple_clpc_profile_probe() (clpc.c:1318) advertises PLATFORM_PROFILE_PERFORMANCE, so writing performance enters apple_clpc_profile_set() (clpc.c:1337-1344), calls apple_clpc_send_high_power(clpc, true), receives -ENODEV, and returns early without updating clpc->profile or clearing clpc->low_power (leaving low-power ceilings active when switching low-power -> performance, and debugfs status at :1071 reporting smc high power: off (0 records sent) despite SMC support being compiled out).
    • This breaks the advertised performance profile in the exact !CONFIG_MFD_MACSMC build this PR enables, and contradicts the commit message / PR description ("as it already does when the node has no apple,smc phandle", where clpc->high_power is false and performance succeeds).
    • Fix: Gate clpc->smc_np parsing and/or clpc->high_power at clpc.c:1508-1510 with IS_ENABLED(CONFIG_MFD_MACSMC) (while keeping the IS_ENABLED(CONFIG_MFD_MACSMC) guards in apple_clpc_read_power() and apple_clpc_send_high_power() so the apple_smc_*() calls still drop out at compile time).

Non-blocking Nits

  • Commit 6fb5d1ca826c carries Fixes: bdd3bc3f17b4, but apple_smc_write() was introduced by f04da7cf87ff ("soc: apple: clpc: J714s: tell the SMC about High Power mode"); please add a second Fixes: tag for f04da7cf87ff.
  • For §5 completeness on fleet configs (MFD_MACSMC=y), an objdump -d drivers/soc/apple/clpc.o before/after comparison on the fleet config would directly prove unchanged code generation without needing a hardware boot.

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Superseded by #2846: the same two commits rebased on integration/aurora f5fae3c, plus the review fix (probe takes the apple,smc phandle only when the SMC driver is built, so performance no longer fails with -ENODEV), the second Fixes: tag, and the objdump comparison on the fleet config (identical with MFD_MACSMC=y). Closing this one to avoid a force push.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants