Skip to content

perf, arm64: T6030 (M3 Pro) CPU PMU and KVM guest PMUv3 - #4277

Merged
DjDeveloperr merged 5 commits into
mainfrom
feat/t6030-cpu-pmu
Dec 4, 2026
Merged

DjDeveloperr merged 5 commits into
mainfrom
feat/t6030-cpu-pmu

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

What: Give the M3 Pro (T6030: J514s, J516s) a CPU PMU and turn on the IMPDEF PMUv3 traps on its cores, so KVM can offer guests a PMUv3. A guest's mrs pmcr_el0 then stops taking an undefined-instruction exception. That exception was reported for the Windows 11 Arm64 boot loader under EDK2 with QEMU/KVM on an M3 Pro.
Tested: J516s row at 539d1c95, the kernel and device trees of this head (the commit after it changes only a host test): VERDICT PASS, 19/19 checks (receipt in the comments). On P and E cores: exact instruction counts, overflow IRQs for every sample, KVM_CAP_ARM_PMU_V3 = 1, the guest's PMCR_EL0 read, exact guest INST_RETIRED on P, on E and across P/E migrations, guest overflow, KUnit 24/24 at boot. Stock 7.3.0-f3822 shows the reported fault: the cap is 0 and the guest's PMCR_EL0 read takes EC 0. Host: checkpatch --strict clean on all five commits; dt_binding_check (arm/pmu.yaml) and CHECK_DTBS (both T6030 boards) clean; apple-m4-pmu-tests 5/5 with all mutations.
Risk: two-way · T6030 (M3 Pro). It sets HACR_EL2 bit 56 on T6030 cores, the trap M1/M2 already use. There is no public basis for that bit on M3, so the J516s row's guest PMCR_EL0 read is what proves it.
Not yet: Nothing for the T6030 itself. Follow-ups: T6031 and T8122, and generic branch events. The J516s survey: INST_BRANCH, INST_INT_LD and INST_LDST count only on counters 5-7; L1D_CACHE_MISS_LD 0x5a3 and its NONSPEC 0x0bf counted on no counter, so L1D misses stay unmapped.

Details

Problem (checked on main)

  • t6030.dtsi has no CPU PMU node, and apple_m1_cpu_pmu.c has no M3 entry, so the M3 Pro has no perf hardware counters.
  • has_impdef_pmuv3() in cpu_errata.c matches only the M1 and M2 cores (apple_cpus).
  • Without that capability, kvm_arm_pmu_get_pmuver_limit() treats the IMPDEF PMU as absent, so kvm_host_pmu_init() registers no host PMU. KVM_CAP_ARM_PMU_V3 is then 0, QEMU refuses pmu=on, and a guest's PMUv3 system register access is undefined.

Change

  1. dt-bindings: arm: pmu: apple,t6030-pmu.
  2. drivers/perf: apple_m1: T6030 tables. The M3 cores select events with 16-bit fields laid out as on M4 (PMESR0 for counters 2-5, PMESR1 for 6-9) and have 64-bit counters. Counters 0 and 1 are cycles and instructions. Only those two back generic and PMUv3 events; raw events can use counters 2-9. There is one PMU for both clusters, as from M4 on, so a KVM guest's counters keep counting when its vCPU moves between clusters. QEMU doesn't pin vCPUs. KUnit: an M3 variant and an M3 test case.
  3. arm64: errata: the T6030 part numbers 0x044 (Sawtooth) and 0x045 (Everest) go in a list of their own for the IMPDEF PMUv3 traps. Adding them to apple_cpus would also turn on the GICv3 SEIS workaround, which the T6030 isn't known to need.
  4. arm64: dts: apple: t6030: the pmu node. The AIC raises both core types' PMU FIQs as AIC_CPU_PMU_P.

Public basis

  • XNU pexpert/pexpert/arm64/H15.h (used for the T6030, T6031 and T8122): CPMU_PMC_COUNT 10, CPMU_64BIT_PMCS 1, CPMU_16BIT_EVENTS 1. XNU's osfmk/arm64/kpc.c programs PMESR0/PMESR1 with 16-bit fields at (counter - 2|6) * 16.
  • XNU osfmk/arm64/cpc_arm64_events.c: one T6030 list, identical to the T6031 and T8122 lists. CORE_ACTIVE_CYCLE is 0x002 and INST_ALL 0x08c, as on M1. Many events have a prefix above the low byte now, for example L1D_CACHE_MISS_LD 0x5a3 (M1: 0xa3) and L1I_TLB_MISS_DEMAND 0x1d4. The list doesn't say which of counters 2-9 count which event, so this PR maps nothing beyond the fixed counters.
  • Part numbers: m1n1 src/midr.h (T6030 Sawtooth 0x44, Everest 0x45). Read on the J516s on 12-04: MIDR_EL1 0x611f0441 on the six 2.748 GHz apple,sawtooth cores and 0x611f0451 on the six 4.056 GHz apple,everest cores.
  • HACR_EL2 bit 56: the M1/M2 trap from upstream; on M3 the J516s row is the proof.

Not in this PR

  • T6031 (M3 Max) and T8122 (M3) have the same XNU event list. Their part numbers per m1n1 are 0x48/0x49 and 0x42/0x43. Each needs its own DT node and its own row.
  • Generic branch, branch-miss and L1D-miss events for M3: the J516s kit surveys those events on every counter, and a follow-up can map them from that table.
Evidence
  • Kit: work/j516s-c1608-pmu-20261204 on Mini (one trial boot with the stock Stage 2 and this PR's DTB). It runs perf_event_open counts and sampling on P and E cores, plus a minimal KVM guest with no QEMU. Its control is a vCPU without PMUv3, which reproduces the reported fault (EC 0 at the PMCR_EL0 read).
  • Host check logs: build/dt-binding-check.log, build/dtbs-check.log, build/w1.log and build/dt-diff-vs-main.txt in the kit.

The T6030 (M3 Pro) gets one CPU PMU node for both of its clusters, as
the T6040 and T6050 do.

Signed-off-by: DjDeveloperr <hey@djdev.me>
The M3 generation cores select events with 16-bit fields laid out as on
M4: PMESR0 holds counters 2-5 and PMESR1 counters 6-9. XNU's H15
configuration (pexpert/pexpert/arm64/H15.h, used for the T6030, T6031
and T8122) sets CPMU_16BIT_EVENTS, CPMU_PMC_COUNT 10 and
CPMU_64BIT_PMCS, and its kpc.c programs PMESR0/1 that way. XNU's CPC
event list (osfmk/arm64/cpc_arm64_events.c) gives the event numbers, the
same list for all three SoCs: CORE_ACTIVE_CYCLE is 0x002 and INST_ALL
0x08c, as on M1, while L1D_CACHE_MISS_LD, for example, moved from 0xa3
to 0x5a3.

Counters 0 and 1 count cycles and instructions. The list doesn't say
which of counters 2-9 count which event, so only those two back the
generic and PMUv3 events. Raw events can use counters 2-9.

Use one PMU for both clusters, as from M4 on. XNU programs the same
event list on both core types, and a KVM guest's counters then keep
counting when its vCPU moves between clusters.

Signed-off-by: DjDeveloperr <hey@djdev.me>
KVM offers guests a PMUv3 only when the IMPDEF PMUv3 traps are on
(ARM64_WORKAROUND_PMUV3_IMPDEF_TRAPS), and those match only the M1 and
M2 cores. On an M3 Pro a guest's PMCR_EL0 read therefore takes an
undefined instruction exception. That was reported for the Windows 11
Arm64 boot loader under EDK2 and QEMU with KVM.

Add the T6030 cores' part numbers, 0x044 and 0x045 (m1n1's midr.h), in a
list of their own. apple_cpus also turns on the GICv3 SEIS workaround,
which the T6030 isn't known to need.

Signed-off-by: DjDeveloperr <hey@djdev.me>
One node for both clusters: the AIC raises both core types' PMU FIQs as
AIC_CPU_PMU_P.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 4, 2026 06:55
@github-actions github-actions Bot added area:platform Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m2 Macs affected, from Merge risk (bot) blast:m3 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Merge readiness at 5e652749: not ready yet

Check Detail
CI at head running running: dt-checks, host-tests
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head no no line with the head SHA 5e652749, a Mac and a result in the PR body or a comment
Conflicts ok none
PR text ok Risk: two-way · T6030 (M3 Pro). It sets HACREL2 bit 56 on T6030 cores, the trap M1/M2 already use. There is no public basis for that bit on M3, so the J516s row's guest PMCREL0 read is what proves it.

Areas: area:gpu, area:platform

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed 539d1c95fcee and found no code blockers. The binding and driver match the single PMU node on J514s and J516s. I checked the T6030 event IDs against Apple’s published event table. Only cycles (0x002) and instructions (0x08c) are mapped to generic perf and guest PMUv3 events. Counters 2–9 remain available for raw events. The E and P core IDs are confined to the PMUv3 trap list, leaving the interrupt-controller workaround unchanged. The W=1 initializer warnings follow the existing table pattern. Merge still needs green CI and the J516s counts, overflow interrupts, guest PMCR read, and cross-cluster migration result.

@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Dec 4, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Hardware check on MacBook Pro 16-inch M3 Pro (J516s, T6030: P-cores Everest 0x045, E-cores Sawtooth 0x044) at head 539d1c95fceef0831322751775f1b92236c9d89a (tree 2d324e631bb4748c550f222c3356f19adf148303): PASS (VERDICT PASS, 19/19 checks).

Stock baseline (7.3.0-f3822)

  • pmu_sysfs= (none), impdef_traps=0, KVM_CAP_ARM_PMU_V3=0.
  • KVM_ARM_VCPU_INIT with KVM_ARM_VCPU_PMU_V3 returns EINVAL (22).
  • No-PMU EL1 guest takes the reported ESR_EL1.EC=0x0 undefined-instruction exception at PMCR_EL0 read (+0x18).

Trial results (7.3.0-j516s-c1608pmu)

  • Probe & traps: enabled with apple_t6030_pmu PMU driver, 10 (0,000003ff) counters available over CPUs 0-11; Apple IMPDEF PMUv3 Traps detected (lines=1); KVM_CAP_ARM_PMU_V3=1.
  • KUnit: apple-m1-cpu-pmu pass:24, fail:0, skip:0, total:24.
  • Host counts (20M iterations x 8 insns):
    • P-core (cpu11, 0x045): generic inst +0 ppm, ipc 6.70, 1.67 GHz; named inst +0 ppm, ipc 6.70, 2.04 GHz
    • E-core (cpu6, 0x044): generic inst +0 ppm, ipc 5.33, 2.13 GHz; named inst +0 ppm, ipc 5.33, 2.60 GHz
  • Host overflow sampling & AIC FIQ IRQs:
    • P-core: cycles 119/119 samples, 119 IRQs; inst 800/800 samples, 800 IRQs
    • E-core: cycles 150/150 samples, 150 IRQs; inst 800/800 samples, 800 IRQs
  • KVM guest PMUv3 (EL1 guest, no in-kernel GIC):
    • PMCR_EL0 read: P (cpu11) PMCR_EL0=0x840 N=1 (done); E (cpu6) PMCR_EL0=0x840 N=1 (done)
    • Guest counts (4 insns/iter): P INST_RETIRED 4.0000/iter (1.00 cyc/iter); E INST_RETIRED 4.0000/iter (1.00 cyc/iter)
    • P<->E migration (every 5 ms): INST_RETIRED 4.0000/iter (1.00 cyc/iter), P 6 / E 5 visits (11 flips)
    • Guest cycle-counter overflow: P & E both PMOVSSET=0x80000000, PMU line to userspace=1
    • Control (no-PMU vCPU): ESR_EL1.EC=0x0 at +0x18 (reproduces reported fault)
  • Kernel log: 0 new WARN/BUG/Oops lines (0 PMU/KVM-related boot warnings).

Raw event counter survey (informational, counters 2–9)

(+ = counts as expected, 0 = zero)

Cluster Raw ID Event Counters 2–9 mask Counts (c2..c9)
P (0x045) 0x08d INST_BRANCH 000+++00 0 0 0 20000006 20000006 20000006 0 0
P (0x045) 0x095 INST_INT_LD 000+++00 0 0 0 20000002 20000002 20000002 0 0
P (0x045) 0x09b INST_LDST 000+++00 0 0 0 20000002 20000002 20000002 0 0
P (0x045) 0x0cb BRANCH_MISPRED_NONSPEC ++++++++ 0 0 0 1 1 1 0 0
P (0x045) 0x5a3 L1D_CACHE_MISS_LD 00000000 0 0 0 0 0 0 0 0
P (0x045) 0x0bf L1D_CACHE_MISS_LD_NONSPEC 00000000 0 0 0 0 0 0 0 0
E (0x044) 0x08d INST_BRANCH 000+++00 0 0 0 20000006 20000006 20000006 0 0
E (0x044) 0x095 INST_INT_LD 000+++00 0 0 0 20000002 20000002 20000002 0 0
E (0x044) 0x09b INST_LDST 000+++00 0 0 0 20000002 20000002 20000002 0 0
E (0x044) 0x0cb BRANCH_MISPRED_NONSPEC ++++++++ 0 0 0 4 4 4 0 0
E (0x044) 0x5a3 L1D_CACHE_MISS_LD 00000000 0 0 0 0 0 0 0 0
E (0x044) 0x0bf L1D_CACHE_MISS_LD_NONSPEC 00000000 0 0 0 0 0 0 0 0

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Dec 4, 2026
The cycles-anywhere mutation rewrites the first "return BIT(0);" in the
driver and needs it to be unique. The T6030 affinity function adds a
second one, so anchor the mutation to M4's CORE_ACTIVE_CYCLE case.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) and removed ci-failing A check failed at the PR head (bot) labels Dec 4, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The host run at 539d1c95fcee passed 1,172 of 1,173 jobs. The cycles-anywhere control found two copies of its match string after the T6030 table was added and stopped before testing the mutation. At 5e65274965a8 the control targets the M4 case explicitly. I ran the normal test and all four negative controls on pc at that head, and all behaved as expected. The commit changes only the host test, so the J516s 19/19 result still covers the kernel change. The fresh hosted checks are pending.

@DjDeveloperr
DjDeveloperr merged commit a9f1fab into main Dec 4, 2026
9 checks passed
@DjDeveloperr
DjDeveloperr deleted the feat/t6030-cpu-pmu branch December 4, 2026 07:50
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Merged as a9f1fabc2493 with match-head 5e65274965a8. Evidence: J516s hardware row 19/19 at 539d1c95fcee (the only change since is tools/asahi/apple-m4-pmu-tests.py, +2/-1), exact-head host review with all four negative controls (07:19Z), hosted checks green at this head.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

This might be the wrong solution

@sithglan

sithglan commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Post-merge code review of 5e65274965a8 (following up on the comment above):

Concrete issues / gaps

  1. HACR_EL2 bit 56 is lost on boot CPU0 across deep sleep (suspend-to-RAM)

    • cpu_enable_impdef_pmuv3_traps() (arch/arm64/kernel/cpu_errata.c:336) sets SYS_HACR_EL2 |= BIT(56) via the ARM64_CPUCAP_LOCAL_CPU_ERRATUM .cpu_enable hook at boot / CPU hotplug.
    • Secondary CPUs re-run .cpu_enable when re-onlined after deep sleep, but CPU0 does not — it returns through cpu_resume() -> __cpu_suspend_exit() (arch/arm64/kernel/suspend.c:95) -> arm64_impdef_cpu_reset_restore() (arch/arm64/kernel/cpufeature_impdef.c:372), which only restores ACTLR_EL1 and AMX. cpu_do_suspend() (arch/arm64/mm/proc.S:89) does not save HACR_EL2 either.
    • On J516s (which has deep sleep via soc: apple: enable T6030 suspend-to-RAM on J516s #4067), after a deep sleep any KVM vCPU scheduled on CPU0 reading PMCR_EL0 will take an unhandled guest UNDEF (EC 0) while CPUs 1–11 continue trapping normally.
  2. T6030 is still missing the vGIC SEIS workaround, and KVM was only tested without an in-kernel GIC

    • arch/arm64/kernel/cpu_errata.c now has three asymmetric Apple MIDR lists:
      • apple_cpus[] (M1/M2): both ARM64_WORKAROUND_PMUV3_IMPDEF_TRAPS and ARM64_WORKAROUND_GICv3_BROKEN_SEIS
      • apple_impdef_pmuv3_cpus[] (T6030): only ARM64_WORKAROUND_PMUV3_IMPDEF_TRAPS
      • apple_broken_seis_cpus[] (M4/A18/M5/M6): only ARM64_WORKAROUND_GICv3_BROKEN_SEIS
    • Every other Apple SoC in the tree (M1, M2, M4, M5, M6) has broken ICH_VTR_EL2.SEIS, and the motivating workload (Windows 11 Arm64 under EDK2 + QEMU/KVM) requires an in-kernel vGICv3 — which the J516s KVM test (no in-kernel GIC) did not exercise.
  3. Raw events on T6030 silently count 0 because m3_pmu_event_affinity() assigns counter 2 first

    • m3_pmu_event_affinity() returns M3_PMU_CNTR_EVT (GENMASK(9, 2)) for every non-fixed event, and __m1_pmu_get_event_idx() allocates the lowest free bit (counter 2) first.
    • Yet the J516s survey in the comments shows that every non-fixed event that counted (0x08d INST_BRANCH, 0x095 INST_INT_LD, 0x09b INST_LDST, and 0x0cb BRANCH_MISPRED_NONSPEC) only counted on counters 5–7 (0 0 0 <N> <N> <N> 0 0, same ONLY_5_6_7 mask as M1/M2) and read 0 on counters 2–4 and 8–9. (Note also the survey table labels 0x0cb's mask ++++++++ even though the observed counts 0 0 0 1 1 1 0 0 / 0 0 0 4 4 4 0 0 are 000+++00.)
    • Exposing counters 8–9 (GENMASK(9, 0)) is also unproven on M3 — nothing in the survey counted on 8 or 9 (on M4, counters 8–9 were deliberately hidden with GENMASK(7, 0) for that reason).
  4. Minor: m3_pmu_t6030_init() calls m4_pmu_init() -> m1_pmu_init(), running m1_pmu_init_pmceid() and rewriting cntr_mask / attr_groups three times (same pattern as t6050_pmu_init()).

Architectural / scope notes

  • Enabling HACR_EL2[56] per-SoC in apple_impdef_pmuv3_cpus[] only addresses mrs pmcr_el0 on T6030 when pmu=on is requested (exposing a barebones N=1 PMUv3 with 2 events in PMCEID0_EL0), leaving T6031/T8122/M4/M5/M6 without PMUv3 traps and T6030 without the SEIS fix. Unifying the Apple SEIS + HACR_EL2[56] handling across verified Apple cores (plus restoring HACR_EL2[56] in arm64_impdef_cpu_reset_restore()) would avoid this split.
  • The single-PMU DT binding (apple,t6030-pmu) matches Aurora's M4/M5 choice for unpinned KVM vCPU migration, though it diverges from upstream Linux's per-uarch bindings (apple,icestorm-pmu / apple,firestorm-pmu).

The M3 hardware findings themselves (16-bit PMESR0/PMESR1, 64-bit counters, AIC_CPU_PMU_P, and proving HACR_EL2[56] traps guest PMUv3 on M3 cores) are solid.

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

Labels

area:gpu Area from CODEOWNERS (bot) area:platform Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m2 Macs affected, from Merge risk (bot) blast:m3 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants