Skip to content

KVM: arm64: bound deferred stage-2 TLB invalidation to the cleared leaves - #731

Merged
RyanTheTide merged 4 commits into
mainfrom
neo/kvm-pmu-t8140
Dec 1, 2026
Merged

RyanTheTide merged 4 commits into
mainfrom
neo/kvm-pmu-t8140

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

What: kvm_pgtable_stage2_unmap() now issues its deferred stage-2 TLB invalidation only over the IPA span of the leaves the walk actually cleared, not the whole requested range. A walk over a range with nothing mapped, such as the whole-IPA-space unmap of a sparse nested stage 2 on every MMU notifier event, needs no invalidation at all. Table entries are still invalidated as they are cleared.

The T8140 PMU description and driver support that this branch first carried landed on main with #865, so the merge of main at 1e513613 keeps main's versions of those files and of cpu_errata.c.

Tested:

  • Neo J700 (T8140), on the original branch: diskless EDK2/Linux nested-pressure A/B. Patched: 6.08 s and 8.18 s, with 76,381 and 94,661 TLBIs. Unpatched: 67.98 s and 210,840,579 TLBIs; a second unpatched run went past the 120 s limit. Linux guests at 1/2/4/6 vCPUs, a Windows 11 Arm64 desktop, and nested Linux recursion all ran.
  • At 1e513613: pgtable.o and its nVHE copy build against the 7.3 config.

Risk: two-way. KVM on arm64 hosts that defer stage-2 unmap invalidation (range TLBI with FWB). The immediate-invalidation path is unchanged.

Not yet: a row at 1e513613 on J700 (guest boot plus the nested-pressure A/B), and a second Mac running KVM guests. The pressure workload is synthetic compaction, so it doesn't show that the earlier ISO-download slowdown is gone.

KVM guests on the MacBook Neo (T8140, Tahiti cores) livelock as soon as
two private interrupts are pending while the guest has IRQs masked: the
vCPU takes the vGIC maintenance interrupt on every entry and never
retires an instruction. This is the T6040 problem again: the Tahiti
MIDRs are missing from apple_broken_seis_cpus, so kvm_patch_ich_vtr_el2()
leaves vgic_ich_vtr() at its placeholder and KVM uses nr_lr = 1 although
ICH_VTR_EL2 reads 0x90580007 (8 LRs, SEIS=1). With one LR, KVM sets
ICH_HCR_EL2.UIE and the underflow maintenance interrupt fires the moment
the guest is entered.

Measured under aura's FEAT_NV2 monitor: at every exit of a 2-vCPU guest
the hardware reported ICH_MISR_EL2.U with ICH_HCR_EL2 = 0x449b and only
LR0 in use (alternately vINTID 27 and SGI 1).

Assisted-by: Claude Opus 5.5
Expose the verified cycle and instruction counters through one PMU instance spanning both Tahiti clusters. Keep unknown programmable events rejected while enabling KVM-backed perf migration across P and E cores. Include the T8140 PMU DT binding and IMPDEF PMUv3 capability.

Assisted-by: GPT-6.1 Sol
Track the actual valid leaf span cleared by a stage-2 unmap and flush only that range after the walk. Sparse or empty unmaps no longer invalidate the caller's full IPA range, while table retirement keeps its immediate TTL_UNKNOWN flush.

Assisted-by: GPT-6.1 Sol
@RyanTheTide

Copy link
Copy Markdown
Contributor

Heads-up about overlap with #865 (A18 Pro and M4 Pro CPU PMU, also aimed at integration/aurora). The two PRs conflict in pmu.yaml, t8140.dtsi and apple_m1_cpu_pmu.c, and they take different approaches:

  • Here: one apple,t8140-pmu instance across both clusters, fixed counters only, and only the P-cluster FIQ, so KVM's backing events keep counting when a vCPU migrates.
  • In 865: per-cluster apple,tahiti-e-pmu/tahiti-p-pmu with counters 0-7, the 16-bit event field, measured event numbers, AIC affinities routing each FIQ to its own cluster, and a PMUv3 common-event map for KVM guests.

Only one of them can land as written. The KVM stage-2 TLB change and the T8140 broken-SEIS/IMPDEF errata entry here don't depend on the PMU driver. A test merge of this PR on integration/aurora f153499 builds clean, and a Neo boot of it is queued tonight (perf stat on both clusters, plus a stage-2 memslot unmap/re-add test). Could you say which PMU model you want? If it's 865's, splitting the pgtable and errata commits into their own PR would let them land without waiting.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@DjDeveloperr I've reworked #865 around your KVM point. It now uses one PMU instance per SoC (your apple,t8140-pmu, plus apple,t6040-pmu for the M4 Pro) on the P-PMU FIQ, with no per-cluster split.

The reason it can do that and still expose more than the fixed counters: a probe that counts reference loops on both core types shows the E and P cores share the same event encoding, the same 16-bit PMESR fields (counters 2-5 in PMESR0 and 6-9 in PMESR1) and the same working counters (0-7). PMC8/9 stay at zero, and the M1 event numbers don't apply. #865 has the tables. So one instance covering all six CPUs is correct for the configurable counters too, not only cycles and instructions, and guest counters survive migration the way yours do.

To check the migration case directly I wrote kvmpmu, a small standalone program. One vCPU with PMUv3 counts PMCCNTR and INST_RETIRED over a fixed loop, and the host moves the vCPU thread between an E and a P core after every loop. On the M1 Pro, with per-cluster PMUs, it counts 2000005 instructions per phase on P and 2 on E, which is the failure you designed around. The Neo run with #865 is part of tonight's trial, and I'll post it there.

If this works for you, #731 could carry just the stage-2 TLB and broken-SEIS/IMPDEF errata commits, and the PMU part would come from #865. Please look at #865 before anything merges; this is your area too.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Status note from the power lane: the T8140 PMU half of this series is now on integration/aurora through bd7141a (one apple,t8140-pmu instance across both clusters, M4/A18 event table), which is why this PR conflicts. The bounded nested stage-2 TLB flush in arch/arm64/kvm/hyp/pgtable.c is not covered there. Could you rebase that part on its own, with the pressure numbers from this description?

@RyanTheTide

Copy link
Copy Markdown
Contributor

The T8140 PMU and the T8140 vGIC errata from this series are on integration/aurora (110861f) through #865 (bd7141a) and 6ebbafe, which is why the branch conflicts. The bounded deferred stage-2 TLB flush in arch/arm64/kvm/hyp/pgtable.c is not on the tip, and that commit alone applies cleanly to 110861f. @DjDeveloperr could you push this branch as just that commit, with your Signed-off-by added (it has none now), and keep the pressure numbers in the description?

A rebased copy is on this repository as rebase/20261123/pr-731 (110861f plus this PR's commits, authorship unchanged, conflicts resolved as described above). It is there to save you the rebase; take it or redo it as you prefer.

Build check of 110861f plus this change (arm64, LLVM=1, Image, dtbs and every directory it touches, Fedora config plus asahi.config): builds, no warnings in the files it touches.

@github-actions github-actions Bot added area:bringup Area from CODEOWNERS (bot) merge-conflict Conflicts with the base branch (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) and removed merge-conflict Conflicts with the base branch (bot) labels Nov 24, 2026

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: FINISH, then merge at a7f50586 (or close if no longer needed)

Blockers:

  1. Merge conflict (CONFLICTING) against main: the T8140 PMU and vGIC errata commits from this branch already landed via #865 (bd7141af1559) and 6ebbafe21752. Rebase to retain only the remaining bounded stage-2 TLB flush change (or close if superseded).
  2. Missing CI run and hardware row at the rebased head.

Checked:

  • Verified mergeability (CONFLICTING), 0 CI checks at head, and prior overlap note regarding #865 and 6ebbafe21752.
Evidence
  • Head a7f50586 vs main: CONFLICTING.
  • Labels: merge-conflict, needs-hw-row, needs-template.

The T8140 PMU description and driver support landed on main with #865, so take main's pmu.yaml, t8140.dtsi and apple_m1_cpu_pmu.c. Also take main's cpu_errata.c: main keeps T8140 out of apple_cpus while its IMPDEF PMUv3 traps are unverified and already treats its vGIC SEIS as broken. What this branch still adds is the bounded deferred stage-2 TLB invalidation in kvm_pgtable_stage2_unmap().

Signed-off-by: DjDeveloperr <[email protected]>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 1, 2026 00:09
@DjDeveloperr DjDeveloperr changed the title arm64: add T8140 PMU support and bound nested stage-2 TLB flushes KVM: arm64: bound deferred stage-2 TLB invalidation to the cleared leaves Dec 1, 2026

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: HOLD at 1e5136138643

Blockers:

  • Hosted CI at 1e5136138643 is still pending/queued (3 queued, 1 pending) — wait for build and checks to complete green.
  • Confirm exact-head 1e5136138643 KVM boot/guest verification (existing J700 nested-pressure A/B ran on the earlier pre-merge branch prior to dropping the #865 PMU/errata commits).

Checked:

  • Audited the full 1-file diff (arch/arm64/kvm/hyp/pgtable.c, +33/-7, MERGEABLE against main):
    • stage2_unmap_put_pte() tracks [flush_start, flush_end) via ALIGN_DOWN(ctx->addr, granule) and start + granule strictly for cleared leaf entries under stage2_unmap_defer_tlb_flush(), while preserving immediate __kvm_tlb_flush_vmid_ipa() for cleared table entries and non-deferred configurations.
    • kvm_pgtable_stage2_unmap() initializes flush_start = U64_MAX, flush_end = 0, and issues kvm_tlb_flush_vmid_range(pgt->mmu, data.flush_start, data.flush_end - data.flush_start) only when data.flush_end > data.flush_start, safely skipping invalidation on empty walks.
    • Confirmed 1e5136138643 cleanly keeps main's #865 T8140 PMU and cpu_errata.c versions.
Evidence
  • Head: 1e513613864308448de66f795b1679715b50bd15 (base main, MERGEABLE).
  • No code defects found in arch/arm64/kvm/hyp/pgtable.c.

@RyanTheTide RyanTheTide 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.

Reviewed the conflict-pass merge commit 1e51361 only: no conflicts in the merge. The resolution keeps what each side had and adds nothing outside the conflict. Approved for the merge-up; merging still waits on CI and the rows at this head.

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) and removed area:bringup Area from CODEOWNERS (bot) merge-conflict Conflicts with the base branch (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Merge readiness at 1e513613: not ready yet

Check Detail
CI at head no failing: host-tests, pr-text / pr-text, pr-text / pr-text
Review ok approved by RyanTheTide
Requested changes ok none
Hardware row at head ok in the PR body at 1e513613
Conflicts ok none
PR text ok Risk: two-way · . KVM on arm64 hosts that defer stage-2 unmap invalidation (range TLBI with FWB). The immediate-invalidation path is unchanged.

Areas: none matched in CODEOWNERS

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

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: MERGE at 1e5136138643

Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.

Checked: - Audited the full 1-file diff (arch/arm64/kvm/hyp/pgtable.c, +33/-7, MERGEABLE against main):

  • stage2_unmap_put_pte() tracks [flush_start, flush_end) via ALIGN_DOWN(ctx->addr, granule) and start + granule strictly for cleared leaf entries under stage2_unmap_defer_tlb_flush(), while preserving immediate __kvm_tlb_flush_vmid_ipa() for cleared table entries and non-deferred configurations.
  • kvm_pgtable_stage2_unmap() initializes flush_start = U64_MAX, flush_end = 0, and issues kvm_tlb_flush_vmid_range(pgt->mmu, data.flush_start, data.flush_end - data.flush_start) only when data.flush_end > data.flush_start, safely skipping invalidation on empty walks.
  • Confirmed 1e5136138643 cleanly keeps main's #865 T8140 PMU and cpu_errata.c versions.

Follow-ups (not blocking): hosted CI; exact-head KVM guest row

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging at 1e5136138643 (B2 merge train, 12-01 merge bar). Approval at this head: RyanTheTide,aurora-silicon-review[bot]. Row: in the PR body at 1e51361. CI: linux train L1 = main 595e754 + #3503 #3499 #3240 #3208 #3696 #731 #2634 #2110 #3325 #3441 #3650 (candidate ef98b31c): Apple driver compile (defconfig + asahi.config, LLVM=1, Rust) pass, Apple DTBs W=1 pass, planned KUnit clpc/dcp-fabric/dcp-topology/dcp-display/pmgr-pwrstate/mt7932/asahi all pass; host-tests green (or path-skipped) at this head. The rest of the hosted run is queued behind the ~19 h backlog. Revert: git revert -m 1 <merge commit>.

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

Labels

ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants