From f2b58d56da98058f478f893850020dac5e7449ab Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 15 Nov 2026 11:44:37 -0400 Subject: [PATCH] Census the flags field, because it is the part nobody should hand-grep engine#2542 turned on a fact the tool was ignoring: two devices on this host carry DIFFERENT flag values (0x0007 vs 0x0000), and one of them also carries a rare third value (0x0050) that any decode has to explain. I found that by hand, twice, and a wrong decode survived a review on the strength of a histogram with one bucket. The census now reports the flags histogram per (boot, device, domain), in the text output and in --json, with three arms: both values counted on one device, the rare one not lost in the total, and a fault line with no flags field still parsing. First run on real data already contradicts something I had written: 0x0050 is not a one-off -- the previous boot has 18 of them against 3 in this one, so it recurs in every boot and belongs in any account of the stream. --- tools/diag/iommu_fault_census.py | 40 ++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/tools/diag/iommu_fault_census.py b/tools/diag/iommu_fault_census.py index 2de0fdeba..e1be6c693 100755 --- a/tools/diag/iommu_fault_census.py +++ b/tools/diag/iommu_fault_census.py @@ -43,6 +43,7 @@ FAULT = re.compile( r"(?:(?P[0-9a-fA-F]{4}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-9a-fA-F]):\s+)?" r"AMD-Vi: Event logged \[IO_PAGE_FAULT domain=(?P0x[0-9a-fA-F]+) address=(?P0x[0-9a-fA-F]+)" + r"(?: flags=(?P0x[0-9a-fA-F]+))?" ) @@ -54,24 +55,30 @@ def parse(text, label): if not m: continue key = (label, m.group("dev") or "-", m.group("domain")) - rows.setdefault(key, []).append(int(m.group("addr"), 16)) + rows.setdefault(key, []).append((int(m.group("addr"), 16), (m.group("flags") or "").lower())) return rows def census(rows): out = [] - for (label, dev, domain), addrs in sorted(rows.items()): - counts = {} - for a in addrs: + for (label, dev, domain), pairs in sorted(rows.items()): + counts, flag_counts = {}, {} + for a, fl in pairs: counts[a] = counts.get(a, 0) + 1 + if fl: + flag_counts[fl] = flag_counts.get(fl, 0) + 1 top = sorted(counts.items(), key=lambda kv: (-kv[1], kv[0]))[:5] out.append( { "label": label, "device": dev, "domain": domain, - "faults": len(addrs), + "faults": len(pairs), "distinct": len(counts), + # engine#2542: the flags field is the most informative part of a fault line and the least obvious -- + # two devices on this host carry different values (0x0007 vs 0x0000, plus rare 0x0050), and a decode that + # explains two of three is incomplete. Report the histogram so nobody has to hand-grep for it. + "flags": dict(sorted(flag_counts.items())), "top": [{"address": hex(a), "count": c} for a, c in top], "_set": set(counts), } @@ -136,6 +143,10 @@ def render(entries, inter, as_json): ) for t in e["top"]: lines.append(" %s x%d" % (t["address"], t["count"])) + if e["flags"]: + lines.append( + " flags: %s" % ", ".join("%s x%d" % (f, n) for f, n in sorted(e["flags"].items(), key=lambda kv: -kv[1])) + ) lines.append(" -> %s" % shape(e)) if inter is None: lines.append("shared across boots: (need two or more labeled journals of the same device)") @@ -252,6 +263,25 @@ def ok(name, got, want): ) ok("the top five stop at five and do not list the singletons", len(c["top"]), 5) + # engine#2542: two flag values on one device must both appear -- a histogram with one bucket hides the outlier that + # any decode has to explain, which is exactly how a wrong decode survived review. + two_flags = ( + "Nov 14 20:00 host kernel: nvme 0000:c4:00.0: AMD-Vi: Event logged " + "[IO_PAGE_FAULT domain=0x0015 address=0x1000 flags=0x0000]\n" + "Nov 14 20:01 host kernel: nvme 0000:c4:00.0: AMD-Vi: Event logged " + "[IO_PAGE_FAULT domain=0x0015 address=0x1000 flags=0x0050]\n" + "Nov 14 20:02 host kernel: nvme 0000:c4:00.0: AMD-Vi: Event logged " + "[IO_PAGE_FAULT domain=0x0015 address=0x2000 flags=0x0000]\n" + ) + f = census(parse(two_flags, "b"))[0] + ok("both flags values on one device are counted", f["flags"], {"0x0000": 2, "0x0050": 1}) + ok("...and the rare one is not lost in the total", f["faults"], 3) + + no_flags = ( + "AMD-Vi: Event logged [IO_PAGE_FAULT domain=0x0001 address=0x1000]\n" + ) + ok("a fault line without a flags field still parses", census(parse(no_flags, "b"))[0]["faults"], 1) + print("iommu_fault_census self-test: %d failure(s)" % fails) return 1 if fails else 0