Repository navigation
third_party: carry the two amdxdna patches every build of ours runs (bo_invalid_list UAF, TDR array recovery) - #1038
Conversation
…loses #971, #1005) The xdna-driver pin (526c6081) is pre-fix and neither fix is upstream, so a module built from the pin alone panics on one close path (bo_invalid_list use-after-free) and cannot bring the array back after a TDR (hwctx_restart -22, every later request hangs until a reboot). Until now both patches existed only as uncommitted working-tree changes in scratch trees on one box, which is how the c22 image ended up shipping the panicking driver. Add third_party/patches/amdxdna/: the two patches as a series against the pin, and a README with the build (ARCH + the driver's own modules target, which generates config_kernel.h), sign, install and initramfs recipe, the srcversion each build must produce, and what a pin bump invalidates. Verified: applying both patches to a clean 526c6081 checkout reproduces the amdxdna sources of the module this box runs byte for byte (cmp over every .c/.h), and rebuilding that tree with MODULE_VER_STR='2.21.0_20261104,<pin>' produces srcversion 56AB94758C18FEEC838D18C = /sys/module/amdxdna/srcversion on the box. docs/npu.md points at it from the pin paragraph.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 964af2235
This is the panic fix and the stick's dependency, so I checked the carrier itself rather than the prose.
The series applies to the pin, verified from a fresh upstream clone (not from any tree of ours):
git clone https://github.com/amd/xdna-driver && git checkout 526c6081
git apply --check 0001-*.patch -> clean
git apply 0001-*.patch
git apply --check 0002-*.patch -> clean
git apply 0002-*.patch
git diff --stat -> 9 files changed, 139 insertions(+), 23 deletions(-)
9 files / +139/−23 is exactly the README's 4 files, +48/−4 plus 5 files, +91/−19, and "order matters" is real — 0002's hunks sit on 0001's post-state. The patches are ours (From: pi-hrx-fabric <[email protected]>), git-format, and nothing in the engine tree re-heads an AMD file in place, which is the pattern this repo wants.
The box is running the documented build. /sys/module/amdxdna/srcversion = 56AB94758C18FEEC838D18C, which is the README's "pin + 0001 + 0002 (what the box and the c22/c23 images run)" row, and modinfo -F srcversion /lib/modules/7.4.0-rc1-1bit/updates/amdxdna.ko reports the same value here, so the file and the loaded module agree on this boot. That is the strongest claim in the PR and it re-derives.
tools/copyright.py --check → rc=0, so the two .patch files pass while keeping their From <sha> first line (no header is prepended to a patch — that would corrupt it).
One thing to be explicit about, because it is the difference between a fix and a plan: nothing in this tree applies the series. The only reference outside third_party/patches/amdxdna/ is docs/npu.md:1208, which points at the README — no os/mini/mkimage/container-build.sh hook. So merging this changes what the next driver build can consume, not what the c24 stick ships; the image-side half is #971, as the README itself says ("#971 carries the image-side half of shipping it"). Worth stating in the merge commit or the owner's note, so nobody reads "carried" as "shipped".
Two nits:
- The fingerprint table has no pin-only row, so a build that comes out at an unexpected
srcversioncannot be told apart from one built without the patches at a glance. If the pre-fix value is recorded anywhere (the 01:48 panic's boot would have had it), add it — the README already explains that the version string is part of the hash, which is exactly why a "this means the patches are missing" row is worth having. ## When the pin movessaysgit apply --3wayis "the sane way to see whether upstream moved under a hunk" — right, but it is worth one line on what to do when it succeeds with conflicts resolved: the fingerprint table then has no row at all, and the srcversion check silently becomes unverifiable until the 0002 provocation is re-run. Say that the table must be regenerated before the pin bump merges (which the paragraph implies but does not require).
Not re-run: the 0002 provocation (a TDR must power-cycle the NPU and the array must answer afterwards). That needs an npu-hold ticket, a wedge, and the driver loaded from this build — the author's 2026-11-04 10:48-10:50 run is the record, and it is the one measurement here that cannot be reproduced on demand without taking the device down deliberately.
PR Reviewer Guide 🔍(Review updated until commit 97ad764)Here are some key observations to aid the review process:
|
|
Persistent review updated to latest commit 97ad764 |
…0008, not 0007' is answered by the artifact Owner: amdxdna 0008 is being built and c25 must carry it. Nothing in the gate could tell the two apart: vermagic and the MOK signature are identical for every module we have ever built, and the depmod path only says which FILE wins. The srcversion is the only field that names the source (that is what #1038 established the other way round). Measured both arms on the c25 ISO: --srcversion 56AB94758C18FEEC838D18C (what it carries) -> ok, rc=0 --srcversion DEADBEEF0000000000000000 (a stale cut) -> FAIL 'this cut must carry ... (a stale module)', rc=1 so the failure mode is a red gate, not a note.
…, lemond debug, a 32M ring, thermals) for c25 (#1057) * os/v3 puppy: the live USB logs it all as proof - boot proof, lemond debug, a sized ring, thermals and a proof bundle Cycle 25 (owner: "make sure the live usb log verbose it all for proof that it works"). Five pieces, each with the measurement that decided it: 1. 1bit-proof: boot-proof.txt once per boot (cmdline, uname, Secure Boot via mokutil AND the efivar byte, modules with srcversions, amdxdna's tdr_timeout_ms, firmware hashes, PCI/accel devices, RAM/GTT/VRAM, the boot timeline, RELEASE-TAG and the sha256sums result), and a bundle of the boot's log directory + SHA256SUMS as proof-<tag>-<date>.tar.zst with its sha256 printed. A value that cannot be read is written 'n/a <reason>' and never omitted - a missing line and a zero look identical to a reviewer. 2. 10lemonade seeds log_level=debug (+ 8 MB x 3 rotation) into lemond's config.json when the key is absent and never overwrites a level somebody set. Measured on the pinned build: lemond has no level flag and no env var (only -v/--version); the accepted strings are trace|debug|info|warning|error|fatal|none, and debug is what prints 'Debug logging enabled - subprocess output will be visible' - the engine's own lines then land in lemond.log. trace is refused on purpose: per-token chatter would spend the whole evidence budget on itself. 3. 1bit-logs samples Tctl / fan rpm / package W every 10 s BUT ONLY while an engine child exists, in one loop with the 15 s log copy (two cadences, one sleeper, so they cannot drift). Unreadable sensors are 'n/a', not 0. 4. mkimage adds log_buf_len=32M to the shared cmdline and refuses to write an image without it: c23's ring wrapped and 1bit-logs could only mark the loss. 5. vm-check gains four rows: the ring size, the boot proof's labels (a file that exists but says nothing is what a stub produces), the thermal gate in both directions (engaged when serving, absent when idle), and the bundle being READABLE through zstd|tar - not merely present. Checks: bash -n, shellcheck -S warning and tools/copyright.py --check clean; 1bit-proof is exercised on this host as root (real ring, tdr_timeout_ms=15000, per-file firmware hashes, SB byte=1); the lemond seed is exercised in all three states (absent / no key / owner-set) and log_level=debug was confirmed by a live lemond run; the thermal sampler is exercised with a stubbed 'loaded' model (tctl=61 fan=n/a pkg_w=104.2) and with the real gate (no line written). * os/v3 puppy: the thermal-gate row counts children portably (pgrep -c is not in every build) * os/v3 puppy: 1bit-proof counts SHA256SUMS entries, not lines (the WARNING summary made 1 bad file read as 2) * os/v3 puppy: the boot-proof row asserts instead of reporting (want=None made it INFO, so it could never fire) Measured on the c25 image: the run came back 62 PASS / 0 FAIL / 3 SKIP with this row as INFO - the very 'a sentence is not a check' shape this row exists to remove. It now requires every label to be present AND at least 20 lines, so a stub that writes only the labels cannot pass either. * os/v3 puppy: g3-probe takes --srcversion, so 'this cut carries patch 0008, not 0007' is answered by the artifact Owner: amdxdna 0008 is being built and c25 must carry it. Nothing in the gate could tell the two apart: vermagic and the MOK signature are identical for every module we have ever built, and the depmod path only says which FILE wins. The srcversion is the only field that names the source (that is what #1038 established the other way round). Measured both arms on the c25 ISO: --srcversion 56AB94758C18FEEC838D18C (what it carries) -> ok, rc=0 --srcversion DEADBEEF0000000000000000 (a stale cut) -> FAIL 'this cut must carry ... (a stale module)', rc=1 so the failure mode is a red gate, not a note. --------- Co-authored-by: pi-os3 <pi-os3@local>
Root cause
third_party/xdna-driverpinsamd/xdna-driverat526c6081, and two defects that both take the NPU down on thishardware are not in that pin and not upstream:
bo_invalid_listuse-after-free at close — a client that closes while a BO sits onclient->bo_invalid_listfrees the client and leaves the BO linked into it (
amdxdna_hmm_invalidatecopiedabo->clientand tookclient->hwctx_srcufirst) →kernel BUG at lib/list_debug.c:32. This is the 2026-11-04 01:48 panic, and thereason os/v3/puppy: the image builds amdxdna from pin 526c6081, which predates the bo_invalid_list fix, so the next stick ships the panicking module #971 exists: the image builds the module from the pin, so the next stick ships the panicking driver.
aie2_hwctx_restart()fails-22and every later request hangs until a reboot (amdxdna: one TDR leaves the NPU array unrecoverable on the appliance (hwctx_restart -22, 'restore data not reclaimed'), so a single wedged request needs a reboot #1005).Both fixes have been running on the box since 2026-11-04, but only as uncommitted working-tree changes in scratch
trees on that one box — which is exactly how the fix went missing from an image build before. Nothing in git records
which source the shipping
amdxdna.kocame from, andg3-probe.shcannot tell (it asserts presence/vermagic/signer).What this PR does
third_party/patches/amdxdna/0001-…-fix-the-bo_invalid_list-use-after-free.patch(4 files, +48/−4)third_party/patches/amdxdna/0002-…-recover-the-array-after-a-TDR.patch(5 files, +91/−19)third_party/patches/amdxdna/README.md— why they are a series, the build/sign/install/initramfs recipe (thedriver's own
modulestarget withARCH, which generatesconfig_kernel.h), thesrcversioneach build mustproduce, the loaded-vs-file check, and what a pin bump invalidates.
docs/npu.md— the pin paragraph now points at the directory instead of leaving the patches invisible.No pin change, no kernel change, nothing applied automatically: this makes the driver build reproducible and the
missing-fix failure mode detectable (
cat /sys/module/amdxdna/srcversion), and gives #971's option A a home.Measured, before/after
526c6081checkout → everydrivers/accel/amdxdna/{*.c,*.h}is byte-identical (cmp) to the tree the loaded module was built fromMODULE_VER_STR='2.21.0_20261104,526c6081974e…'→ srcversion56AB94758C18FEEC838D18C=cat /sys/module/amdxdna/srcversionon the box (measured 2026-11-04 20:17)tdr_timeout_ms=1:aie2_tdr_recover_all: Array stopped dispatching, power-cycling NPU→aie2_hw_reset→ the array answers again, no reboot (2026-11-04 10:48–10:50, 3 prior attempts never entered the branch)56AB9475…in their zdrv), and the c23 board run passed its ladder 400/600/1000 with 0 TDRsNotes for review:
srcversionhashes the built module's contents, so it moves with the version string: the same sources built withthe default string came out at
1184D9F6…. The README says so, so a mismatch is not mistaken for a missing patch.this PR only makes the current pin's patches durable.
closes #971
closes #1005