Skip to content

G83 孤儿完成规则外部审查:ABI/守卫修复、复位关联与审查记录 - #1

Merged
Minorli merged 14 commits into
mainfrom
review/g83-orphan-rules-20261203
Dec 3, 2026
Merged

Minorli merged 14 commits into
mainfrom
review/g83-orphan-rules-20261203

Conversation

@Minorli

@Minorli Minorli commented Dec 3, 2026

Copy link
Copy Markdown
Owner

外部审查 G83 的 eventTimeout/finishEvent 孤儿完成规则(v10–v10.3)和恢复完成戳。完整记录见 docs/G83-Storm-Investigation-20261203.md §12。

验证级别:只有 CPU 测试(arm64,ASan/UBSan)和 RELEASE 交叉编译。x86 CPU 套件、原版回放和实机都没有运行。 本分支未部署。

主要修复(每项一个提交,每个守卫都有先在旧代码上失败的反例):

  • 52887aa 包装器返回 int,原生返回值被截断(finish 包装器在 RELEASE 中、timeout 包装器在 DEBUG 中,已用反汇编确认)
  • 8252a05 拥有者不可读时,原代码当作"无拥有者"放行;现在 getActiveContexts 必须是安装期解析出的同一符号
  • 776df7d 观察表加串行化;写槽前重读 slot 和 submitted,防止完成仍在执行的工作或使戳回退
  • d0d1721 审计原因修正(12-02 12:01 的 0xA6 里 RingBusy 是误报)
  • 2589efe 安装期校验 eventTimeout 体内的 LUT LEA 与调度器偏移
  • 8a2e60a/7e6bdc2/75e6775 要求事件段内有成功复位(或本通道自身的复位)
  • cabed98 拆除豁免的差值收回参考实现的 1..2
  • 2733661 新增 -wex-no-orphan-storm(默认不变)
  • 9382828 采集工具保存 TGLOrphanLive

结论:B 类(风暴)规则在现有证据下不应视为可上线。 原因是守卫无法区分"被复位销毁"和"仍保留在原生队列中"的工作。替代方案见 §12.5。

合并前请在 x86 上执行:python3 tools/test.py、原版回放(--accelerator/--ioaccel)、DEBUG/RELEASE 构建。注意 DEBUG 构建在审查前就已超出栈帧预算。

🤖 Generated with Claude Code

Aric and others added 14 commits December 3, 2026 05:16
…width

Problem: both orphan wrappers were declared to return int. The native
IGAccelEventMachine::eventTimeout returns the channel to restart (NULL for
reasons 1-5, context+0xB8 channel for reason 6; docs/REVIEW.md static table,
and tests/tgl_recovery_native.py declares the routine with a pointer return
that IOAccel hands to restart_channel). finishEvent's result width is not
established in this repository.

Mechanism: with an int return the compiler may keep only eax. Disassembly of
the unchanged source shows it:
- RELEASE wrapTGLOrphanFinish: `call *%rax; movl %eax,%ebx; ... movl %ebx,%eax`
  -- the upper 32 bits of the native result are dropped;
- DEBUG (-O0) wrapTGLOrphanTimeout: `call *%rax; movl %eax,-4(%rbp); ...
  movl -4(%rbp),%eax` -- a reason-6 channel pointer would reach IOAccel as a
  zero-extended 32-bit value. The RELEASE timeout wrapper happened to leave
  rax untouched, which is compiler luck, not a contract.
Now eventTimeout's wrapper returns void * (nullptr when the guarded rule
settles the stamp, unchanged meaning) and finishEvent's returns uint64_t, so
any native result up to register width passes through unchanged.

Verification: CPU/build only. RELEASE rebuilt; the native call is followed by
no 32-bit move of rax in either wrapper. No hardware run.
(The DEBUG configuration currently fails the pre-existing 6144-byte stack
budget in processTGLAccelerator, independent of this change.)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…change

Problem: tests/tgl_orphan.cpp only exercised helpers (observe, reason,
siteIndex, ownerBlocks). The production decision in wrapTGLOrphanTimeout --
hop reads, LUT choice, owner lookup, teardown exemption, slot write and
signal -- had no CPU coverage, so a guard could be bypassed in the caller
without any test failing (tests/README.md: "A direct helper check does not
prove its caller reaches it").

Mechanism: TGLOrphan::evaluate/enter/leave now hold the exact statements the
wrappers ran, parameterised by an Env (reads, clock, thread, native
getActiveContexts call, slot store, signalStampUpdate). The kernel wrappers
supply TGLOrphanKernel with the same canonical-half readers and callees, so
the order of reads, the guard values and the write/signal sequence are
unchanged.

Tests: a model of the 16.0.32 object graph at fake kernel addresses drives
the production template: storm positive (third timeout after >=10 s writes
slot=submitted and signals 1<<idx), young/moving episodes, every guard via
its real producer (kill switch, missing base, gap 0/negative, display range,
simulation, scheduler/LUT/streamer hops, active/pending owner, busy and
unreadable ring), SCI LUT selection, unreadable event-machine hops, index
bounds, and the teardown mark (own dying context excused; other thread or
other context not; queue site captures both contexts; full table and foreign
callers leave no mark). Existing assertions are kept unchanged.

Verification: CPU only (clang++ -std=c++14/17 with ASan/UBSan on arm64);
RELEASE kext rebuilt. No hardware run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…no owner"

Problem: the owner guard ("no active or pending context owns the index") was
satisfied by default. If the scheduler vtable, its +0x198 slot, a context's
+0xB8 channel or the channel's +0x20 index could not be read, active/pending
stayed NULL or owns() returned false, and the rule wrote slot=submitted and
signalled as if the ports were proven empty. The vtable slot was also called
without checking that it is getActiveContexts.

Mechanism: owns() is tri-state (No/Yes/Unknown); an empty port is a known
non-owner, an unreadable or channel-less context is Unknown. The ports are
queried only when vtable+0x198 equals the installer-solved
IGScheduler5::getActiveContexts (0x380EC per the 2026-11-13 anchor audit);
otherwise, or if either port is Unknown, the new OwnerUnknown reason (1<<10)
blocks the write and the native timeout runs. The observer and audit keep
working when the symbol does not match.

Tests: counterexamples written first failed at the behavior assertion on the
previous code (vt+0x198 = 0 -> the rule completed). They cover a zero or
foreign vtable slot, a missing vtable, an unsolved symbol, a null or
non-kernel channel and an unreadable pending context; empty ports still
admit. Verification: CPU (ASan/UBSan) and RELEASE build only; no hardware.
A live storm in which this guard now blocks would show lastReason bit 10.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ting

Problem: (1) the episode table was updated by every thread reaching
eventTimeout without synchronisation. Concurrent observe() calls on one
index can tear an Episode (pair from one call, first/timeouts from another)
and make isLoop() true for an episode that never lasted 10 s. (2) `sent` and
`*slot` were read at the start of the evaluation, the getActiveContexts call
and several hops followed, and only then was slot := sent written. If the
GPU advanced the slot in between (the work is alive) the write completed
stamps still executing; if a newer submission arrived, an older `submitted`
could be written over a newer completion (stamp regression).

Mechanism: evaluateExclusive takes a non-blocking gate; a busy gate returns
Contended (1<<12) without touching the table, and the native timeout runs.
Nothing ever waits on the gate, so it cannot add a lock-order dependency.
Immediately before the store the stamps pointer, slot pointer, submitted
count and slot value are re-read and must equal the values the guards used;
otherwise Changed (1<<11) and the native path. The residual window is the
few instructions between the re-read and the store, not a GPU execution.

Tests: counterexamples injected inside the decision (via the modelled
getActiveContexts) failed on the previous code: partial progress 97->98 was
overwritten with 100. Now partial progress, completion, a new submission and
a moved slot pointer block; an unrelated index does not; a nested
evaluation while the gate is held returns Contended, leaves the table
unchanged, and the outer decision completes and releases the gate.
Verification: CPU (ASan/UBSan) and RELEASE build only; no hardware.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem: TGLOrphanLive.lastReason is the only field that explains a refused
decision during a live storm, and two of its values were misleading.
(1) An unreadable event-machine hop (accel, stamps, submitted, slot) was
reported as NoStreamer although the LUT/streamer were never reached;
UnusableIdx existed but was never set. (2) When the streamer did not
resolve, the ring was never read, yet reason() reported RingBusy because
ringIdle and ringUnreadable both stayed false. The 2026-12-02 12:01 audit
value 0xA6 (Young|Gap|NoStreamer|RingBusy, commit 94038b3) therefore does
not show that the ring was busy in that storm.

Mechanism: hop failure now reports UnusableIdx (1<<9); the ring is marked
unreadable until it is actually read, so an unresolved streamer reports
NoStreamer|RingUnreadable. No admission changes: every affected case was
already refused. The header comment's stale "gap of 1..2" (v10) is updated
to the v10.1 positive-gap rule and the v10.3 teardown exemption.

Tests: both cases failed on the previous code at the reason assertions.
Verification: CPU (ASan/UBSan) and RELEASE build only. Decoders of
TGLOrphanLive in the maintainer's private tools must read bit 9 for hop
failures from this build on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r code matches

Problem: the installer checked eventTimeout's 27-byte prologue, the
finishEvent prologue and three symbol offsets, but the decision then reads
kextBase+0xA0280/0xA0290 (stamp->engine LUTs) and accel+0x1250 (scheduler)
from constants. A build with the same prologue and symbol offsets but a
moved LUT or scheduler field would make the rule read the wrong engine byte
or object, instead of refusing to install.

Mechanism: before routing, the installer compares the three eventTimeout
instructions that consume those values, as recorded in the 2026-11-13 anchor
audit: lea 0xA0280(%rip) at 0x15F5D, lea 0xA0290(%rip) at 0x15F67 and
mov 0x1250(%rax),%rdi at 0x15F7B. The LEA displacements are RIP-relative
inside the kext and are not relocated by the loader, so a literal comparison
is valid (unlike the imported call displacements the reset-poll installer
skips). A mismatch leaves TGLOrphanObserveReady false and the native path.

Tests: the audited bytes decode to the Off:: constants the decision uses;
every single-byte drift and an unreadable image refuse. Verification: CPU and
RELEASE build only; the bytes themselves were not re-read from a binary in
this review (no Apple driver on this host). The three teardown return-address
sites are still not byte-verified (see the review record).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a stamp

Problem: the investigation (§6 "安全原则") and the v10 commit state that the
rule acts only where "the reset destroyed the work", but no guard linked the
decision to any reset. All remaining guards (>=3 timeouts over >=10 s, idle
ring, no owner on the two execlist ports) are also met by work that is alive
but not on the hardware: e.g. a submission retained in the native wait queue
(the v8 detail-4 semaphore-wait path moves it there), blocked on a
cross-engine dependency such as the BCS 0x0e009002 semaphore wait seen in the
storms, or parked while the display is off. Settling such a stamp lets the
client consume or free buffers before the GPU executes the work.

Mechanism: wrapTGLRecovery records the uptime of every resetOK; the decision
requires that time to lie inside the episode (first timeout .. now),
otherwise NoReset (1<<13) and the native timeout. Every recorded storm
qualifies (each reason-6 timeout restarts the channel through
resetHardwareAndReplay). The v10.3 teardown exemption, which by design runs
without any recovery (2026-12-02 16:47: no GPU report, no recovery call),
does not need the reset when it is what admitted the owner; a teardown
thread whose stamp has no dying owner is case B and does. If the single-pass
recovery route is not installed, case B never settles.

This tightens admission only. It does not prove destruction either: any
successful reset counts (engine correlation is not established), and a
retained-queue submission during a storm can still pass; see the review
record. Tests: the previous code settled with no reset (counterexample
failed); now no reset, a reset before the episode and a future reset block,
a reset at the first timeout admits, and the teardown cases above hold.
Verification: CPU (ASan/UBSan) and RELEASE build only; no hardware.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem: docs/G83-Storm-Investigation-20261203.md §9 lists TGLOrphanLive as
collected by tools/tgl-capture, but the failure-path key list never included
TGLOrphanLive or TGLOrphanObserveReady. After a storm or a watchdog panic the
only on-disk evidence of the completion rule's decisions (calls, loops,
completions, lastReason, hop audit) was whatever the maintainer read by hand.

Mechanism: both keys join the per-snapshot list next to TGLRecoveryLive.
Values are raw registry data; no decoding is added and no other key changes.

Verification: host build of tools/tgl-capture and tests/capture-reports on
arm64 only. Not run against a live registry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem: v10.3's teardown exemption is a port of community Fix 2 (upstream
#44), which completes a dying context's stamp only for
1 <= submitted - completed <= 2; its single recorded actuation had a gap of 1.
v10.1 widened the gap guard to any positive value from case-B storm data
(2026-12-02 12:01: gaps 3..189) and v10.3 inherited that width without any
teardown data. With the exemption the owner IS on the execlist port; a larger
gap means more submissions outstanding for a context that the hardware still
holds, so the evidence for "nothing is executing" is weaker, not stronger.

Mechanism: when the teardown exemption is what admits the owner, a gap above
MaxTeardownGap (2) clears gapOK (reason Gap). Case B (no owner) keeps the
v10.1 positive-gap rule.

Tests: a dying owner with gap 3 was settled by the previous code (counter-
example failed at the reason assertion); now Gap, while the same gap without
an owner still completes. Teardown fixtures use the reference's one-behind
shape (gap 1, and gap 2 for the no-reset case). Verification: CPU (ASan/UBSan)
and RELEASE build only. If a real G83 teardown livelock shows a gap > 2, this
bound needs evidence before it is widened again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pisode

Problem: the reset linkage added in 8a2e60a requires the reset inside the
episode (first timeout .. now). When the stuck index IS the reset's affected
channel, WEX recovery increments that index's submitted count and submits a
stamp command; if that stamp never arrives (observed once on G83, §8.6:
target 0xcc54, observed 0xcc4a; upstream #249 shows the same shape followed
by 78 reason-4 NULL timeouts and no further reset), the stuck
(submitted, completed) pair is new and starts after the reset. The linkage
then never held for exactly the channel the reset destroyed.

Mechanism: wrapTGLRecovery also records the resetOK time per affected stamp
index; the decision accepts that index's own reset if it precedes the
episode's first timeout by at most MinStuckNs (10 s). Resets of other
channels still count only inside the episode.

Tests: an own-channel reset 3 s before the episode did not admit on the
previous code (counterexample failed); now it admits, while an own reset more
than 10 s earlier, another index's reset and a missing table do not.
Verification: CPU (ASan/UBSan) and RELEASE build only; no hardware.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem: -wex-no-orphan-complete disables both rules. The review finds that
case B (storm, no owner) cannot tell work destroyed by a reset from work
retained in a native queue (wait queue after a semaphore wait, a
cross-engine dependency, display-parked work), while case C acts only inside
a client teardown on the context being destroyed. A maintainer who accepts
that analysis had no way to keep C without B short of a rebuild.

Mechanism: with -wex-no-orphan-storm the decision refuses every completion
that the teardown exemption did not admit (StormOff, 1<<14). Defaults are
unchanged: without the argument both rules behave as before this commit.
The name is registered in tests/fixtures/boot_argument_names.json.

Tests: storm-off refuses case B and still lets the teardown exemption settle
its dying context; boot_arguments.py passes. Verification: CPU and RELEASE
build only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The orphan decision had no entry in tests/README.md although the contract
maintenance rules require the contract, tested path, counterexamples and
limits to be recorded. Describes the production entry it exercises, the
admission conditions after this review, the counterexample classes and the
conclusion it cannot support (that settled work was destroyed by a reset).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mple

Problem: 8a2e60a/7e6bdc2 stored the reset time with mach_absolute_time()
immediately after resetAndResume, inside the body that tests/tgl_recovery.py
extracts and compiles against its ABI fixture. The CPU test therefore no
longer compiled (undeclared clock and linkage globals), i.e. the production
wrapper was untested at its consumer.

Mechanism: the linkage now converts the wrapper's existing post-reset
clock_get_uptime sample (`after`), so the wrapper still samples the clock
exactly twice. The fixture declares the two linkage globals, includes the
real kern_tgl_orphan.hpp for Indices, models absolutetime_to_nanoseconds and
asserts that only resetOK records the global time and the affected index
(17) and that a failed reset or an absent affected channel records nothing.

Tests: tgl_recovery production/equivalent pass and all nine existing
semantic mutants are still caught; a manual mutant recording on every reset
fails at the new assertion. Verification: CPU and RELEASE build only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Appends §12 to the investigation: verification levels (CPU/build only, x86
suite and hardware not run), findings O1-O12 with severity, location,
evidence and the commit that addresses each, the recovery and anchor review,
documentation inconsistencies (D1-D8), the conclusion that the case-B storm
rule should not be treated as ready under current evidence with concrete
alternatives, the hardware metrics to watch, a triage of related upstream
issues and unresolved repository items, and answers to the three
self-check questions. Corrects §6 (v10 gap 1..2, missing 557756b, v9 data
claim), annotates §8.6's date and §9's capture claim, and adds §8 item 7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Minorli
Minorli merged commit 20073af into main Dec 3, 2026
2 checks passed
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