xhci: report a refused platform DMA release as CK_XHCI_E_RELEASE
merged9565418bd493c602 #482 · opened 2026-10-30 12:37 UTC · closed 2026-10-30 13:15 UTC · merged 2026-10-30 13:15 UTC
Imported from GitHub aien-dev/aienux#482, by drakestapleton
Base a1fc1f34cd7c896a4c946b55b7634f4b2f5df5c7 · Head 099fb9103a342a7fc8d3e051ee240bf1b3aa443a
Merged on GitHub as ce2ce2ab21dad32ec9c1103a94a148179cf58892; reachable from main d01b2f19cccf3e173a6bdb3541813d467f537a76 (observed 2026-11-18T16:35:36Z)
drakestapleton wrote on 2026-10-30 12:37 UTC
A refused DMA abort on the ACPI platform xHCI fallback was reported as success. plat_fence_all() returned CK_XHCI_E_RELEASE and set state to release-failed. ck_xhci_fence() then overwrote that with fenced and returned CK_XHCI_OK when the PCI halt had succeeded (hrc == 0, which the no-keyboard path requires). The stream stayed confined. The caller was told the release worked.
The PCI path just above already returns CK_XHCI_E_RELEASE and leaves release-failed. The platform path now returns that code immediately after plat_fence_all(), and leaves the state plat_fence_all() already set.
Only CK_XHCI_E_RELEASE is propagated. plat_fence_all() turns a still-live stream into CK_XHCI_E_RELEASE before it returns, so that code is the one that means a stream is still confined. The other non-OK results happen before a grant, and the PCI controller is already released:
CK_XHCI_E_ARG (ambiguous name, bad or unmappable BAR)
CK_XHCI_E_HALT (halt before grant)
CK_XHCI_E_DMA (allocation before grant)
CK_XHCI_E_DENIED (SMMU deny)
CK_XHCI_ABSENT is not reached from this fallback. The fallback only runs when g_nplat > 0. Those other codes stay the PCI fence's result (CK_XHCI_OK / fenced on the no-keyboard path). A host case locks the deny path: a named confine of CK_SMMU_ABSENT still returns CK_XHCI_OK, state fenced, log denied (NoSmmu).
CK_XHCI_E_HALT before a grant does not install a stream. Firmware DMA if that halt failed is the existing halt path, not this reporting bug. Real ACPI platform xHCI behaviour is hardware-unverified.
virtio-net's init-failure, window-map-failure, and final-release paths could return CK_NET_E_INIT, CK_NET_E_ARG, or the original rc while n->confined stayed 1. They now return CK_NET_E_SMMU when the stream is still confined. A passing selftest whose bus master is still on still returns CK_NET_E_SMMU. A second bind while live still returns CK_NET_E_ARG. QEMU scripts match log lines (virtio_net: init FAIL, virtio_net=selftest-failed), not the C return code. devices.c treats only netrc == 0 as selftest-ok.
The optional ck_dma_unconfine distinct-error-code change is not included. The real function is static state in smmu_svc.c and is not linked into the stage host binary (ck_host.c is the mock; linking both would duplicate symbols). Distinguishing "not confined" from "confined on two SMMUs" needs an IORT, a model SMMU, page tables, and two instances. That is more than a few lines. Multi-SMMU behaviour is hardware-unverified.
Tests
Host only. Nothing here ran on real hardware. QEMU gates (scripts/qemu_ck_net_test.sh and the keyboard and SMMU QEMU gates) were NOT_RUN. stage-free was NOT_RUN on this x86_64 host: the freestanding flags (-mgeneral-regs-only, -mno-outline-atomics, -fno-tree-loop-distribute-patterns) are not supported by the x86_64 compiler. That is the ARM image build, not this patch.
Unpatched production lines (the early return and the three n->confined checks removed, tests left in), stage_test:
ASan/UBSan stage-sanitize: same stage host result, PASS checks=900 failures=0
crumb verify with the compiler pinned in crumb.lock (d0f0b95d344b4c6628c3d868346932fd247ce168):
crumb verify: OK: 96 crumbs current
Default cc on this VM is clang 18. It rejects an existing -Wstring-plus-int in dev/tests/pi5_agent_test.c, which this change does not touch. gcc 13 (STAGE_CC=gcc) builds the suite clean.
drakestapleton reviewed (COMMENTED) on 2026-10-30 12:57 UTC
DMA-fence security review at f234fd4874fd1c9fe7939cccc007dea9ce8e4c1d (COMMENT, not an approval). Host-shim evidence only: a real ACPI platform xHCI and multi-SMMU behaviour are hardware-unverified, and the QEMU net/keyboard/SMMU gates were NOT_RUN.
Verdict: the fix for #478 is correct and complete for the paths it claims. I found no remaining path that reports success after a refused release, and nothing to fix before merge. The two pre-existing reporting gaps in devices.c listed below are outside this diff and non-blocking.
1. No success after a failed release: PASS
ck_xhci_fence, PCI path: after ck_xhci_release() (xhci_fence.c:448), a live stream sets release-failed and returns CK_XHCI_E_RELEASE (:449-452), before any platform attempt.
Platform fallback:
plat_fence_all turns any CK_XHCI_E_RELEASE or still-live stream into release-failed / CK_XHCI_E_RELEASE (:344-347).
The new early return (:462) passes that code out before the x->state = "fenced" overwrite (:464) and the hrc-based return (:466). This was the #478 bug, and it is closed.
The other prc values (ARG at :271-285, HALT at :294-297, DMA at :300-303, DENIED at :314-317) all return before x->confined = 1 (:320), so no stream exists, and the PCI controller was already shown released at :449. Keeping the PCI result (CK_XHCI_OK/fenced) is correct.
No-PCI path:return plat_fence_all() was already correct and is unchanged.
Transient state:plat_fence_one sets fenced (:327) before its own release (:328). That is transient only, because plat_fence_all overwrites it at :345 whenever the stream stays live.
Live re-entry: re-entering while live returns CK_XHCI_E_ARG (:359-363, and :255-259 per controller). That is not a success, but the code collides with genuine argument errors; this is #480's territory and deliberately left out.
virtio-net (net_bind.c):
The window-map failure (:398), init failure (:413) and final release (:435) now all return CK_NET_E_SMMU while n->confined is set.
The DMA (:372-377) and DENIED (:381-386) returns happen before n->confined = 1 (:388).
A stuck bus master on a failed selftest keeps its original non-OK rc, so it is still not a success.
NVMe (devices.c:80-110): unchanged by this PR. ck_dev_nvme_release clears claimed only when !bm_on && !confined && !stuck (:109), and the failed-bind path calls it (:140).
2. No free or reuse of a still-confined device, stream or buffer: PASS
xHCI: the shared g_dma_mem (xhci_fence.c:299, :401) is reused only after the live checks at :359-363 / :255-259. A failed abort keeps x->confined and stream_id (:177-181).
Platform → PCI handover: the fallback runs only after the PCI stream is shown released (:449).
virtio-net: the memset(n, 0, ...) and the reuse of g_dma_mem (net_bind.c:368-372) are behind the ck_net_live() guard (:363-366). ck_net_release keeps confined/stream_id when the abort fails (:122-128).
NVMe: keeps ownership while confined (devices.c:98-109).
Allocations:ck_dma_alloc buffers are never freed, so none of these paths can free them.
Test-only reset: the new ck_xhci_host_forget (xhci_fence.c:192-207) refuses while live and is compiled only under CK_HOST_TEST.
3. Callers handle the new codes: PASS, with two non-blocking reporting notes
Callers:ck_xhci_fence has only two: devices.c:158 (and ck_xhci_session → devices.c:241). ck_net_bind_selftest has only devices.c:148.
No caller checks only for rc == OK in a way that treats the new codes as benign:
The net summary counts only netrc == 0 as selftest-ok (:150).
The xHCI result is printed with ck_xhci_state() (release-failed) and its rc (:159).
The recovery halt re-checks every *_live() and panics if any DMA is live (:173-177).
There is no syscall or console code-to-name mapping for these codes, only numeric printing, so nothing else needs updating.
Pre-existing, outside this diff (non-blocking): ck_stage_quiesce reports success without re-checking.
devices.c:221 prints quiesce before reset virtio_net=released-now unconditionally after ck_net_release().
devices.c:219-220 prints nvme=released-now from was_live without re-checking.
Both can report a release that was refused. The rtl8127 and xHCI lines (:223-224) already re-check.
Exact fix: use ck_net_live() ? "LIVE" : "released-now" on the virtio_net line, and on the NVMe line use was_live ? ((g_nvme.bm_on || g_nvme.confined) ? "LIVE" : "released-now").
Optional:devices.c:150 could print selftest-failed (LIVE) when ck_net_live() is true.
4. Tests: PASS (host mock), one coverage gap
What they use: the tests drive the existing ck_host_unconfine_fail mock. They add ck_host_unconfine_allow, so the PCI abort succeeds and the platform abort is the one refused, plus an injected ACPI device (ck_host_plat_set) and a ck_dma_confine_named result.
asserts CK_XHCI_E_RELEASE, release-failed, live == 1, 2 grants (PCI then ACPI name), and abort FAILED, stays confined
checks that re-entry is refused with no new grant
checks that the deny control still gives CK_XHCI_OK/fenced/denied (NoSmmu)
On the old code this returns CK_XHCI_OK/fenced, so it fails, which matches the 3 unpatched failures in the PR body.
virtio-net (test_net_release_refused): covers the init-failure path, with CK_NET_E_SMMU, live, bus master revoked, no re-bind while live, and a clean re-bind after release. The old code returned CK_NET_E_INIT, so it fails.
Gap (non-blocking):
The window-map failure (net_bind.c:398) and the final-release path with a non-OK rc (:435) have no test of their own.
A caps region outside its BAR would cover :398.
Flake risk: the xHCI test relies on a 20 µs polling pthread register model, which could be flaky under load. Consider generous halt timeouts there.
5. Scope, CI and mergeability: PASS
Files:net_bind.c (+5/-1) and .h (comment only), xhci_fence.c (+21: the one-line fix plus a CK_HOST_TEST-only helper), xhci_fence.h (+4, CK_HOST_TEST only), the host mock (ck_host.c/.h), stage_test.c, and crumbs.
No Makefile, workflow or SMMU-service change. #480's distinct EARG codes are not included, as claimed.
Mergeability:mergeable: true, mergeable_state: clean, base 4f7f13d8.
CI: these succeeded: AIEN Checks, sbom, CodeQL, Analyze (actions, c-cpp, python, rust). AIEN Alpha was skipped.
Evidence: host stage suite 900/900 with the fix and 3 failures unpatched (author-reported; I did not re-run it). No QEMU or hardware runs. A real ACPI platform xHCI and multi-SMMU behaviour are hardware-unverified.
— Grokbot
drakestapleton reviewed (COMMENTED) on 2026-10-30 13:15 UTC
Head re-check at 099fb9103a342a7fc8d3e051ee240bf1b3aa443a (COMMENT, not an approval).
Since f234fd48, this head adds only two main merges and regenerated crumbs:
595140e5 merges main 77514f7e (#475) into f234fd48.
099fb910 merges main a1fc1f34 (#391, current main) into 595140e5.
Files from main match main exactly. Every non-crumb file changed since f234fd48 has the same blob as at a1fc1f34:
the workflows aien-verification.yml, copilot-setup-steps.yml and sbom.yml, plus the new osc-code-flip-guard.yml
the two osc evidence logs
GATES.md, native/kernel/Makefile, osc_admit.c and qemu_ck_osc_receipt_test.sh
None of them differ from main, so nothing was hand-edited. The PR adds no code, test or workflow changes of its own.
5 regenerated crumbs:.crumb, native/.crumb, native/kernel/.crumb, native/kernel/core/.crumb and scripts/.crumb.
Fix and test files are unchanged. Excluding crumbs, the net diff against main is the same 7 files with the same blobs as at f234fd48:
CI at this SHA is green. These all succeeded: AIEN Checks, osc-code-flip-guard, sbom, CodeQL, and Analyze (actions, c-cpp, python, rust). AIEN Alpha was skipped. The PR is mergeable and clean.
Caveats. Real platform xHCI and multi-SMMU are hardware-unverified. Follow-ups #489 and #490 are tracked.
— Grokbot
Fetch it
A git bundle of the pull request's head, 12916 bytes.