Skip to content

hwmon: macsmc: Select sensor keys by key metadata, not by SoC - #2353

Closed
RyanTheTide wants to merge 1 commit into
integration/aurorafrom
powerctl/hwmon-gates
Closed

RyanTheTide wants to merge 1 commit into
integration/aurorafrom
powerctl/hwmon-gates

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

drivers/hwmon/macsmc-hwmon.c had a chip list, macsmc_hwmon_is_m3() (t6030, t6031, t6032, t6034, t8122), that switched two things which do not depend on the SoC:

  • macsmc_hwmon_create_sensor() (line 866): a sensor node was admitted only if the SMC reports its key as readable and as a 4-byte flt or 8-byte ioft value. This check ran on those five SoCs only. It was gated in c91c5f4 ("hwmon: macsmc: preserve the legacy sensor export policy") to keep the earlier behaviour on other machines. No firmware difference was given.
  • macsmc_hwmon_debugfs_init() (line 1683): the read-only debugfs keys inventory was created on those SoCs, and on T6050 after 2604bb0 ("hwmon: macsmc: expose read-only SMC key inventory on T6050").

Change

  • The key check now runs on every SoC. It uses the key's own metadata from apple_smc_get_key_info(), which every SMC reports. macsmc_hwmon_read_key() decodes only these two formats on every SoC, so a key that fails the check could only fail every read. The die sensor, thermal pressure and temperature discovery paths already run the same check with no chip gate.
  • The debugfs inventory is created on every machine. It walks the SMC key index and reads readable float T*/P* keys only when root reads the file. It reads nothing at probe and writes nothing.
  • macsmc_hwmon_is_m3() is removed. The driver has no of_machine_is_compatible() call left.

Why every SoC is safe:

  • T6030/1/2/4 and T8122: no change.
  • T6050: the inventory was already on. The key check is new there but only drops keys that can never be read.
  • T8103, T600x, T8112, T602x, T604x, T8132, T8140, T8142, T8152: no SMC write and no new probe-time SMC call. The check uses key info the driver already fetched. A rejected node is dropped, as it already was when the key is missing. On a node with #thermal-sensor-cells, a rejected temperature node keeps a hidden channel, so thermal zone indices do not move. Today those nodes are the T600x MacBook Pro, T604x, T8112, T8122 and T8140 trees.

The key check and the inventory were written by Chris Kearney for T6030.

Testing

  • drivers/hwmon/macsmc-hwmon.o with W=1 (clang, LLVM=1, release config) on base 0abc2f3 and on this branch: 0 warnings on both. The same build with the KUnit code compiled in also has 0 warnings.
  • No DT change. All 137 Apple DTBs build with no warnings.
  • KUnit on arm64 (kunit.py, qemu virt, LLVM): macsmc-hwmon 4/4 and macsmc-hwmon-fan 14/14 passed on the head of this stack (with the fan_control removal on top); 52 tests run in total, 51 passed, 1 skipped (a GPU test that needs CONFIG_UCLAMP_TASK). The kunitconfig enables MFD_MACSMC, MACSMC_POWER and SENSORS_MACSMC_HWMON with their KUnit options under COMPILE_TEST.

Still to run

The test kernel goes on J316s (T6000), J413 (T8112), J616s (T6040) and J700 (T8140). On each machine, compare against the current kernel:

  1. The macsmc_hwmon channel list (index, label, value). Expected: every channel that gave a value before is still there, with the same index and label. A channel can only disappear, or show up as hidden in a dmesg "unavailable ... hidden" line, if every read of it failed before.
  2. sudo head -2 /sys/kernel/debug/<smc hwmon device>/keys. Expected: a # N keys header, with N equal to the number of lines that follow it, and no new SMC errors in dmesg.
  3. cat /sys/class/thermal/thermal_zone*/type and the temperatures. Expected: the same set as before.
Exact commands
H=$(grep -l '^macsmc_hwmon$' /sys/class/hwmon/hwmon*/name | xargs dirname)
cd $H; for f in *_input; do printf '%s\t%s\t%s\n' "$f" "$(cat ${f%_input}_label 2>/dev/null)" "$(cat $f 2>&1)"; done > /tmp/ch-$(uname -r).txt
diff /tmp/ch-<old>.txt /tmp/ch-<new>.txt      # expect no change for channels that read a value before
dmesg | grep -i macsmc                         # expect no new errors
D=$(sudo ls /sys/kernel/debug | grep -i -e smc -e hwmon); sudo head -2 /sys/kernel/debug/$D/keys; sudo wc -l /sys/kernel/debug/$D/keys

Assisted-by: LLM (Claude:Opus 5.5)

macsmc_hwmon_is_m3() matched apple,t6030/t6031/t6032/t6034/t8122 and
gated two things that do not depend on the SoC:

1. The key check in macsmc_hwmon_create_sensor(). A sensor node was
   admitted only if the SMC reports its key readable and as a 4-byte
   "flt " or 8-byte "ioft" value, but only on those five SoCs. The gate
   was added to keep the earlier admission policy on other machines,
   not because of a firmware difference. Every SMC reports a key's
   type, size and flags (apple_smc_get_key_info()), and
   macsmc_hwmon_read_key() decodes only those two formats on every SoC,
   so a key that fails the check can only fail every read. The die
   sensor, thermal pressure and temperature discovery paths already
   apply the same check without a SoC gate. Apply it to every sensor
   node. On a node that is a thermal sensor provider
   (#thermal-sensor-cells, used today by the T600x MacBook Pro, T604x,
   T8112, T8122 and T8140 trees) a rejected temperature node keeps its
   hidden channel, so zone indices do not move; elsewhere the unusable
   channel is no longer registered.

2. The debugfs "keys" inventory, enabled on the same SoCs and T6050.
   It only walks the SMC key index and key info and reads readable
   4-byte float T* and P* keys on demand, which every SMC supports.
   It is debugfs, root only, and reads nothing at probe. Create it on
   every machine.

No SMC write and no probe-time key read is added on any SoC. The key
check and the inventory were written by Chris Kearney for T6030.

Fixes: c91c5f4 ("hwmon: macsmc: preserve the legacy sensor export policy")
Fixes: 2604bb0 ("hwmon: macsmc: expose read-only SMC key inventory on T6050")
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Superseded by #2304, which makes the same change (key metadata checks and the key inventory on every SoC) and came first.

@RyanTheTide
RyanTheTide deleted the powerctl/hwmon-gates branch November 27, 2026 13:22
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.

1 participant