From bfe725e19080e2b1db567b6b1eacb935250ee3c1 Mon Sep 17 00:00:00 2001 From: pi-release Date: Sun, 15 Nov 2026 23:15:15 -0400 Subject: [PATCH] diag: unmap_fault_order reads the kernel's PADDED boot stamp, so a real capture can correlate BOOT_RE was r'^\s*\[(\d+\.\d+)\]' -- digits immediately after the bracket. The kernel pads the stamp to a fixed width: journalctl -k -o short-monotonic writes '[ 321.308031]' (two spaces), and dmesg writes '[ 0.000000]'. Measured on this box's own fault lines, every one of them parsed with t=None, so parse_faults returned untimed faults and correlate() had nothing to compare: the tool reported no fault shares an iova with an unmap inside the window: ordering not shown by this capture for a capture whose iova and timestamps matched, 31 us apart. The doc example in this file writes the UNPADDED '[1234.567890]', which is what the fixtures used and why every arm stayed green. r'^\s*\[\s*(\d+\.\d+)\]' fixes it and an arm now pins the padded shape: it must timestamp, and the same padded fault must correlate against a tracefs unmap 31 us earlier. Dropping the inner \s* fails the arm by name. Measured before/after with the real shape: before: faults parsed: 1; with an unmap of the same iova within +-5000 us: 0 after : faults parsed: 1; with an unmap of the same iova within +-5000 us: 1 iova 0x4128000 size 0x1000: unmap -31 us, unmap BEFORE fault (translation gone) --- tools/diag/unmap_fault_order.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/diag/unmap_fault_order.py b/tools/diag/unmap_fault_order.py index b5fab9741..056f3317d 100755 --- a/tools/diag/unmap_fault_order.py +++ b/tools/diag/unmap_fault_order.py @@ -53,7 +53,11 @@ # and a `dmesg`/trace-style capture writes `[1234.567890]` seconds-since-boot. A fault line is only correlatable # when its clock is the trace's, so the seconds form is preferred when both appear. ISO_RE = re.compile(r"(\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?)") -BOOT_RE = re.compile(r"^\s*\[(\d+\.\d+)\]") +# The kernel pads the stamp to a fixed width: `[ 321.308031]`, two spaces here and one for values >= 1000 s. +# Written without the inner `\s*` the regex only matched the unpadded shape a doc example uses, so EVERY real +# boot-stamped line parsed as untimed and the tool could not correlate on a capture it produced itself -- +# measured 2026-11-16 on `journalctl -k -o short-monotonic`: `[ 321.308031] … IO_PAGE_FAULT …` -> t=None. +BOOT_RE = re.compile(r"^\s*\[\s*(\d+\.\d+)\]") def read_lines(path): @@ -172,9 +176,21 @@ def chk(cond, msg): "iova=0xffff8e83841c3a00 size=0x45ec0"]) chk(pointer_shaped(ptr), "a pointer-shaped iova column is detected, not read as uncorrelated") chk(not pointer_shaped(got), "a real IOVA column is not mistaken for one") + # 7. the REAL kernel stamp is PADDED (`[ 321.308031]`, two spaces; `[ 0.000000]` early in a dmesg). The doc + # example above writes the unpadded `[1234.567890]`, and an arm built only from it passed while every real + # capture parsed as untimed -- the tool then reported "nothing correlated" on data it had just been given. + padded = "[ 321.308031] strixhalo kernel: nvme 0000:c4:00.0: AMD-Vi: Event logged " \ + "[IO_PAGE_FAULT domain=0x0015 address=0x4128000]" + pf = parse_faults([padded], lambda _s: None) + chk(pf and pf[0][0] == 321.308031, "a padded boot stamp parses (measure with journalctl -k -o short-monotonic)") + ptr_tr = parse_trace([" bash-1 [002] .... 321.308000: unm: (iommu_unmap_fast) iova=0x4128000 size=0x1000"]) + hits = correlate(ptr_tr, pf, 5000) + chk(hits and hits[0][3] and hits[0][3][1] < 0, + "a padded fault correlates with an unmap 31 us earlier (BEFORE, not an uncorrelated negative)") return 0 if ok else 1 + def main(): ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) ap.add_argument("--trace", help="a tracefs capture with a kprobe on the unmap path")