amd-debug-tools 0.2.19__tar.gz → 0.2.21__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. {amd_debug_tools-0.2.19/src/amd_debug_tools.egg-info → amd_debug_tools-0.2.21}/PKG-INFO +1 -1
  2. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/common.py +1 -1
  3. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/database.py +1 -5
  4. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/failures.py +12 -0
  5. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/kernel.py +31 -0
  6. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/prerequisites.py +39 -6
  7. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/ttm.py +79 -50
  8. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/wake.py +27 -20
  9. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21/src/amd_debug_tools.egg-info}/PKG-INFO +1 -1
  10. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug_tools.egg-info/SOURCES.txt +2 -0
  11. amd_debug_tools-0.2.21/src/amd_debug_tools.egg-info/scm_file_list.json +67 -0
  12. amd_debug_tools-0.2.21/src/amd_debug_tools.egg-info/scm_version.json +8 -0
  13. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/test_common.py +16 -0
  14. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/test_database.py +18 -0
  15. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/test_kernel.py +41 -0
  16. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/test_prerequisites.py +171 -0
  17. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/test_wake.py +36 -0
  18. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/.github/workflows/ci.yml +0 -0
  19. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/.github/workflows/mirror.yml +0 -0
  20. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/.gitignore +0 -0
  21. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/.pre-commit-config.yaml +0 -0
  22. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/.vscode/settings.json +0 -0
  23. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/LICENSE +0 -0
  24. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/Makefile +0 -0
  25. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/README.md +0 -0
  26. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/amd_bios.py +0 -0
  27. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/amd_pstate.py +0 -0
  28. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/amd_s2idle.py +0 -0
  29. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/amd_ttm.py +0 -0
  30. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/docs/amd-bios.md +0 -0
  31. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/docs/amd-pstate.md +0 -0
  32. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/docs/amd-s2idle.md +0 -0
  33. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/docs/amd-ttm.md +0 -0
  34. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/docs/in-tree.md +0 -0
  35. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/install_deps.py +0 -0
  36. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/psr.py +0 -0
  37. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/pyproject.toml +0 -0
  38. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/setup.cfg +0 -0
  39. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/__init__.py +0 -0
  40. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/acpi.py +0 -0
  41. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/bash/amd-s2idle +0 -0
  42. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/battery.py +0 -0
  43. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/bios.py +0 -0
  44. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/display.py +0 -0
  45. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/installer.py +0 -0
  46. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/power_rails.py +0 -0
  47. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/pstate.py +0 -0
  48. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/s2idle-hook +0 -0
  49. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/s2idle.py +0 -0
  50. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/sleep_report.py +0 -0
  51. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/templates/html +0 -0
  52. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/templates/md +0 -0
  53. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/templates/stdout +0 -0
  54. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/templates/txt +0 -0
  55. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug/validator.py +0 -0
  56. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug_tools.egg-info/dependency_links.txt +0 -0
  57. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug_tools.egg-info/entry_points.txt +0 -0
  58. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug_tools.egg-info/requires.txt +0 -0
  59. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/amd_debug_tools.egg-info/top_level.txt +0 -0
  60. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/launcher.py +0 -0
  61. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/test_acpi.py +0 -0
  62. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/test_batteries.py +0 -0
  63. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/test_bios.py +0 -0
  64. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/test_display.py +0 -0
  65. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/test_failures.py +0 -0
  66. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/test_installer.py +0 -0
  67. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/test_launcher.py +0 -0
  68. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/test_power_rails.py +0 -0
  69. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/test_pstate.py +0 -0
  70. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/test_s2idle.py +0 -0
  71. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/test_sleep_report.py +0 -0
  72. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/test_ttm.py +0 -0
  73. {amd_debug_tools-0.2.19 → amd_debug_tools-0.2.21}/src/test_validator.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: amd-debug-tools
3
- Version: 0.2.19
3
+ Version: 0.2.21
4
4
  Summary: debug tools for AMD systems
5
5
  Author-email: Mario Limonciello <superm1@kernel.org>
6
6
  License-Expression: MIT
@@ -394,7 +394,7 @@ def read_msr(msr, cpu):
394
394
  """Read a Model-Specific Register (MSR) value from the CPU."""
395
395
  p = f"/dev/cpu/{cpu}/msr"
396
396
  if not os.path.exists(p) and is_root():
397
- os.system("modprobe msr")
397
+ subprocess.run(["/sbin/modprobe", "msr"], check=False)
398
398
  try:
399
399
  f = os.open(p, os.O_RDONLY)
400
400
  except OSError as exc:
@@ -44,12 +44,8 @@ class SleepDatabase:
44
44
  self.debug_cnt = 0
45
45
 
46
46
  if not dbf:
47
- # if we were packaged we would have a directory in /var/lib
48
47
  path = os.path.join("/", "var", "lib", "amd-s2idle")
49
- if not os.path.exists(path):
50
- path = os.path.join("/", "var", "local", "lib", "amd-s2idle")
51
- os.makedirs(path, exist_ok=True)
52
-
48
+ os.makedirs(path, mode=0o700, exist_ok=True)
53
49
  dbf = os.path.join(path, "data.db")
54
50
  new = not os.path.exists(dbf)
55
51
  self.db = sqlite3.connect(dbf)
@@ -653,3 +653,15 @@ class MissingAmdCaptureModule(S0i3Failure):
653
653
  "If the module is not available, disable the camera in the BIOS to prevent issues."
654
654
  )
655
655
  self.url = "https://gitlab.freedesktop.org/drm/amd/-/issues/4869"
656
+
657
+
658
+ class NpuIommu(S0i3Failure):
659
+ """IOMMU configuration incompatible with NPU"""
660
+
661
+ def __init__(self):
662
+ super().__init__()
663
+ self.description = "IOMMU configuration incompatible with NPU"
664
+ self.explanation = (
665
+ "The NPU requires a properly configured IOMMU to function correctly. "
666
+ "Ensure that the IOMMU is enabled and configured in the BIOS."
667
+ )
@@ -94,6 +94,30 @@ def get_kernel_command_line() -> str:
94
94
  return " ".join([x for x in cmdline.split() if not x.startswith(tuple(filtered))])
95
95
 
96
96
 
97
+ def redact_sensitive(text: str) -> str:
98
+ """Redact high-confidence sensitive tokens from captured log text.
99
+
100
+ Only obviously-sensitive patterns are scrubbed so that the remaining
101
+ content keeps its diagnostic value:
102
+ - MAC addresses
103
+ - UUIDs (e.g. LUKS/filesystem identifiers)
104
+ - key/secret/password/token assignments
105
+ """
106
+ text = re.sub(r"([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}", "<redacted-mac>", text)
107
+ text = re.sub(
108
+ r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-"
109
+ r"[0-9a-fA-F]{4}-[0-9a-fA-F]{12}",
110
+ "<redacted-uuid>",
111
+ text,
112
+ )
113
+ text = re.sub(
114
+ r"(?i)\b(key|secret|password|passwd|token)=\S+",
115
+ r"\1=<redacted>",
116
+ text,
117
+ )
118
+ return text
119
+
120
+
97
121
  def sscanf_bios_args(line):
98
122
  """Extracts the format string and arguments from a BIOS trace line"""
99
123
  if re.search(r"ex_trace_point", line):
@@ -128,6 +152,13 @@ def sscanf_bios_args(line):
128
152
  else:
129
153
  break
130
154
 
155
+ # Reject unexpected conversions or oversized field widths from
156
+ # untrusted firmware-supplied format strings.
157
+ if re.search(r"%(?![xXdD%])", format_string) or re.search(
158
+ r"%\d{4,}", format_string
159
+ ):
160
+ return None
161
+
131
162
  try:
132
163
  return format_string % tuple(converted_args)
133
164
  except TypeError:
@@ -20,7 +20,13 @@ import pyudev
20
20
 
21
21
  from amd_debug.wake import WakeIRQ
22
22
  from amd_debug.display import Display
23
- from amd_debug.kernel import get_kernel_log, SystemdLogger, CySystemdLogger, DmesgLogger
23
+ from amd_debug.kernel import (
24
+ get_kernel_log,
25
+ redact_sensitive,
26
+ SystemdLogger,
27
+ CySystemdLogger,
28
+ DmesgLogger,
29
+ )
24
30
  from amd_debug.common import (
25
31
  apply_prefix_wrapper,
26
32
  BIT,
@@ -67,6 +73,7 @@ from amd_debug.failures import (
67
73
  MissingThunderbolt,
68
74
  MissingXhciHcd,
69
75
  MSRFailure,
76
+ NpuIommu,
70
77
  RogAllyMcuPowerSave,
71
78
  RogAllyOldMcu,
72
79
  SleepModeWrong,
@@ -343,21 +350,39 @@ class PrerequisiteValidator(AmdTool):
343
350
 
344
351
  def check_amd_xdna(self):
345
352
  """Check for AMD XDNA driver"""
353
+ amdxdna_path = os.path.join("/", "sys", "module", "amdxdna")
354
+ driver_loaded = os.path.exists(amdxdna_path)
355
+ # No driver loaded means HW should be power gated, should be OK.
356
+ if not driver_loaded:
357
+ return True
358
+
359
+ # IOMMU disabled can cause problems with the NPU
360
+ found_iommu = False
361
+ for _dev in self.pyudev.list_devices(subsystem="iommu"):
362
+ found_iommu = True
363
+ break
346
364
  for device in self.pyudev.list_devices(subsystem="pci", PCI_CLASS="118000"):
347
365
  slot = device.properties["PCI_SLOT_NAME"]
348
366
  driver = device.properties.get("DRIVER")
349
367
  pci_id = device.properties.get("PCI_ID")
350
368
  if not pci_id.startswith("1022"):
351
369
  continue
352
- if not driver:
353
- self.db.record_prereq(f"NPU device in {slot} missing driver", "🚦")
354
- self.failures += [MissingDriver(slot)]
355
370
  p = os.path.join(device.sys_path, "fw_version")
356
371
  if os.path.exists(p):
357
372
  xdna_fw_version = read_file(p)
358
373
  self.db.record_prereq(
359
374
  f"NPU loaded with firmware {xdna_fw_version}", "✅"
360
375
  )
376
+ if not found_iommu and driver:
377
+ self.db.record_prereq("NPU is not supported with IOMMU disabled", "❌")
378
+ self.failures += [NpuIommu()]
379
+ return False
380
+ if not driver:
381
+ self.db.record_prereq(
382
+ f"NPU device in {slot} didn't bind a driver", "🚦"
383
+ )
384
+ self.failures += [MissingDriver(slot)]
385
+
361
386
  return True
362
387
 
363
388
  def check_amd_hsmp(self):
@@ -917,6 +942,14 @@ class PrerequisiteValidator(AmdTool):
917
942
 
918
943
  def check_aspm(self):
919
944
  """Check if ASPM has been overridden"""
945
+ # pcie_aspm=off disables ASPM entirely but leaves the reported
946
+ # policy at [default], so the sysfs check below can't catch it
947
+ if "pcie_aspm=off" in self.cmdline.split():
948
+ self.db.record_prereq(
949
+ "ASPM disabled on kernel command line (pcie_aspm=off)", "❌"
950
+ )
951
+ self.failures += [ASpmWrong()]
952
+ return False
920
953
  p = os.path.join("/", "sys", "module", "pcie_aspm", "parameters", "policy")
921
954
  contents = read_file(p)
922
955
  policy = ""
@@ -1158,7 +1191,7 @@ class PrerequisiteValidator(AmdTool):
1158
1191
  """Read CPUID using kernel userspace interface"""
1159
1192
  p = os.path.join("/", "dev", "cpu", f"{cpu}", "cpuid")
1160
1193
  if not os.path.exists(p):
1161
- os.system("modprobe cpuid")
1194
+ subprocess.run(["/sbin/modprobe", "cpuid"], check=False)
1162
1195
  with open(p, "rb") as f:
1163
1196
  position = (subleaf << 32) | leaf
1164
1197
  f.seek(position)
@@ -1432,7 +1465,7 @@ class PrerequisiteValidator(AmdTool):
1432
1465
  result = False
1433
1466
  if not result:
1434
1467
  self.db.record_prereq(Headers.BrokenPrerequisites, "🚫")
1435
- self.db.record_debug(self.kernel_log.get_full_log())
1468
+ self.db.record_debug(redact_sensitive(self.kernel_log.get_full_log()))
1436
1469
  self.db.sync()
1437
1470
  clear_temporary_message(len(msg))
1438
1471
  return result
@@ -1,19 +1,19 @@
1
1
  # SPDX-License-Identifier: MIT
2
2
  """TTM configuration tool"""
3
3
 
4
- import asyncio
5
- import os
6
4
  import argparse
7
5
  import glob
6
+ import os
8
7
  import subprocess
8
+
9
9
  from amd_debug.common import (
10
10
  AmdTool,
11
11
  bytes_to_gb,
12
12
  gb_to_pages,
13
13
  get_system_mem,
14
- relaunch_sudo,
15
14
  print_color,
16
15
  reboot,
16
+ relaunch_sudo,
17
17
  version,
18
18
  )
19
19
 
@@ -30,6 +30,7 @@ def maybe_reboot() -> bool:
30
30
  return reboot()
31
31
  return True
32
32
 
33
+
33
34
  def is_ttm_in_initramfs(initramfs_path: str) -> bool:
34
35
  """
35
36
  Check if the ttm module is included in the initramfs.
@@ -40,79 +41,107 @@ def is_ttm_in_initramfs(initramfs_path: str) -> bool:
40
41
  Returns:
41
42
  bool: True if "gpu/drm/ttm/ttm.ko" is found, False otherwise
42
43
  """
43
- try:
44
- # Run lsinitramfs and search for "ttm" in the output
45
- result = subprocess.run(
46
- ["lsinitramfs", initramfs_path],
47
- capture_output=True,
48
- text=True,
49
- check=True
50
- )
44
+ # Supported initramfs inspection tools
45
+ inspector_tools = [
46
+ (["lsinitramfs", initramfs_path], "initramfs-tools"),
47
+ (["lsinitcpio", initramfs_path], "mkinitcpio"),
48
+ (["lsinitrd", initramfs_path], "dracut"),
49
+ ]
51
50
 
52
- # Check if "gpu/drm/ttm/ttm.ko" appears in the output
53
- return "gpu/drm/ttm/ttm.ko" in result.stdout.lower()
51
+ # Check if "gpu/drm/ttm/ttm.ko" appears in the output
52
+ for cmd, _package in inspector_tools:
53
+ tool = cmd[0]
54
+ try:
55
+ result = subprocess.run(
56
+ cmd,
57
+ capture_output=True,
58
+ text=True,
59
+ check=True,
60
+ )
61
+ return "gpu/drm/ttm/ttm.ko" in result.stdout.lower()
62
+ except FileNotFoundError:
63
+ continue
64
+ except subprocess.CalledProcessError as e:
65
+ print_color(f"Error running {tool}: {e}", "❌")
66
+ return False
67
+
68
+ print_color(
69
+ "Error: no supported initramfs inspection tool found "
70
+ "(tried: lsinitramfs, lsinitcpio, lsinitrd). "
71
+ "Install initramfs-tools, mkinitcpio, or dracut.",
72
+ "❌",
73
+ )
74
+ return False
54
75
 
55
- except subprocess.CalledProcessError as e:
56
- print_color(f"Error running lsinitramfs: {e}", "❌")
57
- return False
58
- except FileNotFoundError:
59
- print_color("Error: 'lsinitramfs' command not found. Is initramfs-tools installed?", "❌")
60
- return False
61
76
 
62
77
  def check_initramfs_images() -> bool:
63
- """Check if initramfs images exist in /boot/"""
78
+ """Check if any initramfs image contains the TTM module.
79
+
80
+ Returns:
81
+ True if TTM is included in at least one initramfs image (regeneration needed).
82
+ False if no initramfs images are found or TTM is not in any of them.
83
+ """
64
84
  print_color("Checking if the initramfs image needs to be regenerated", "🐧")
65
85
  if not os.path.exists("/boot"):
66
86
  print_color("Warning: /boot not found. Is it mounted?", "🚦")
67
87
  return False
68
88
 
69
- # Check for common initramfs patterns
89
+ # Collect initramfs images across all patterns, deduplicated by realpath
70
90
  patterns = [
71
- '/boot/initrd.img-*', # Debian/Ubuntu
72
- '/boot/initramfs-*.img', # Fedora/RHEL
73
- '/boot/initramfs-*' # Arch
91
+ "/boot/initrd.img-*", # Debian/Ubuntu
92
+ "/boot/initramfs-*.img", # Fedora/RHEL
93
+ "/boot/initramfs-*", # Arch (broadest, catches remaining)
74
94
  ]
75
-
95
+ seen = set()
96
+ all_images = []
76
97
  for pattern in patterns:
77
- initramfs_files = glob.glob(pattern)
78
- if initramfs_files:
79
- print_color(f"Found initramfs images: {initramfs_files}", "🐧")
80
-
81
- latest_initramfs = max(initramfs_files)
82
- if is_ttm_in_initramfs(latest_initramfs):
83
- print_color(f"TTM module is included in initramfs: {latest_initramfs}", "✅")
84
- print_color("The initramfs image needs to be regenerated", "🐧")
85
- return True
86
- else:
87
- print_color(f"TTM module is not included in initramfs", "○")
88
- print_color(f"The initramfs image does not need to be regenerated", "○")
98
+ for img in sorted(glob.glob(pattern)):
99
+ real = os.path.realpath(img)
100
+ if real not in seen:
101
+ seen.add(real)
102
+ all_images.append(img)
103
+
104
+ if not all_images:
105
+ print_color("No initramfs images found in /boot", "○")
106
+ return False
107
+
108
+ print_color(f"Found initramfs images: {all_images}", "🐧")
109
+
110
+ for img in all_images:
111
+ if is_ttm_in_initramfs(img):
112
+ print_color(f"TTM module is included in initramfs: {img}", "✅")
113
+ print_color("The initramfs image needs to be regenerated", "🐧")
114
+ return True
115
+
116
+ print_color("TTM module is not included in any initramfs image", "○")
117
+ print_color("TTM loads from rootfs; initramfs regeneration not required", "○")
89
118
  return False
90
119
 
120
+
91
121
  def regenerate_initramfs():
92
122
  """Regenerate initramfs image"""
93
123
  if not check_initramfs_images():
94
- print_color("No initramfs images found, skipping regeneration", "○")
124
+ print_color("Skipping initramfs regeneration", "○")
95
125
  return
96
126
 
97
- # Supported initramfs tools
127
+ # Supported initramfs tools: (command, display_name)
98
128
  initramfs_tools = [
99
- ["update-initramfs", "-u"],
100
- ["dracut", "--force"],
101
- ["mkinitcpio", "-P"]
129
+ (["update-initramfs", "-u"], "update-initramfs"),
130
+ (["dracut", "--force"], "dracut"),
131
+ (["mkinitcpio", "-P"], "mkinitcpio"),
102
132
  ]
103
133
 
104
- for cmd in initramfs_tools:
105
- tool = cmd[0]
106
- if os.path.exists(f"/usr/sbin/{cmd[0]}") or os.path.exists(f"/usr/bin/{cmd[0]}"):
107
- print_color(f"Updating initramfs using {tool}", "🐧")
134
+ for cmd, name in initramfs_tools:
135
+ if os.path.exists(f"/usr/sbin/{cmd[0]}") or os.path.exists(
136
+ f"/usr/bin/{cmd[0]}"
137
+ ):
138
+ print_color(f"Updating initramfs using {name}", "🐧")
108
139
  try:
109
140
  subprocess.run(cmd, check=True)
110
141
  print_color("Initramfs updated successfully", "✅")
111
142
  return
112
- except subprocess.CalledProcessError as e:
113
- print_color(f"Failed to update initramfs: {e}", "❌")
114
- continue
115
- except FileNotFoundError:
143
+ except (subprocess.CalledProcessError, FileNotFoundError) as e:
144
+ print_color(f"Failed to update initramfs using {name}: {e}", "❌")
116
145
  continue
117
146
 
118
147
  print_color("No supported initramfs tool found", "❌")
@@ -75,29 +75,36 @@ class WakeIRQ:
75
75
 
76
76
  # "might" look like an ACPI device, try to follow it
77
77
  if not self.name and self.actions:
78
- p = os.path.join("/", "sys", "bus", "acpi", "devices", self.actions)
79
- if os.path.exists(p):
80
- for directory in os.listdir(p):
81
- if "physical_node" not in directory:
82
- continue
83
-
84
- for root, _dirs, files in os.walk(
85
- os.path.join(p, directory), followlinks=True
86
- ):
87
- if "name" in files:
88
- try:
89
- self.name = read_file(os.path.join(root, "name"))
90
- except (PermissionError, FileNotFoundError):
91
- pass
92
- t = os.path.join(root, "driver")
93
- if os.path.exists(t):
78
+ # self.actions is a free-form string supplied to request_irq() by
79
+ # the kernel, so restrict it to a single path component to avoid
80
+ # escaping the ACPI device directory via "/" or "..".
81
+ comp = os.path.basename(self.actions)
82
+ if comp and comp not in (".", ".."):
83
+ p = os.path.join("/", "sys", "bus", "acpi", "devices", comp)
84
+ if os.path.exists(p):
85
+ for directory in os.listdir(p):
86
+ if "physical_node" not in directory:
87
+ continue
88
+
89
+ for root, _dirs, files in os.walk(
90
+ os.path.join(p, directory), followlinks=False
91
+ ):
92
+ if "name" in files:
94
93
  try:
95
- self.driver = os.path.basename(os.readlink(t))
96
- except (PermissionError, FileNotFoundError, OSError):
94
+ self.name = read_file(os.path.join(root, "name"))
95
+ except (PermissionError, FileNotFoundError):
97
96
  pass
97
+ t = os.path.join(root, "driver")
98
+ if os.path.exists(t):
99
+ try:
100
+ self.driver = os.path.basename(
101
+ os.readlink(t)
102
+ )
103
+ except (PermissionError, FileNotFoundError, OSError):
104
+ pass
105
+ break
106
+ if self.name:
98
107
  break
99
- if self.name:
100
- break
101
108
 
102
109
  # If the name isn't descriptive try to guess further
103
110
  if self.driver and self.actions == self.name:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: amd-debug-tools
3
- Version: 0.2.19
3
+ Version: 0.2.21
4
4
  Summary: debug tools for AMD systems
5
5
  Author-email: Mario Limonciello <superm1@kernel.org>
6
6
  License-Expression: MIT
@@ -66,4 +66,6 @@ src/amd_debug_tools.egg-info/SOURCES.txt
66
66
  src/amd_debug_tools.egg-info/dependency_links.txt
67
67
  src/amd_debug_tools.egg-info/entry_points.txt
68
68
  src/amd_debug_tools.egg-info/requires.txt
69
+ src/amd_debug_tools.egg-info/scm_file_list.json
70
+ src/amd_debug_tools.egg-info/scm_version.json
69
71
  src/amd_debug_tools.egg-info/top_level.txt
@@ -0,0 +1,67 @@
1
+ {
2
+ "files": [
3
+ ".github/workflows/ci.yml",
4
+ ".github/workflows/mirror.yml",
5
+ ".gitignore",
6
+ ".pre-commit-config.yaml",
7
+ ".vscode/settings.json",
8
+ "LICENSE",
9
+ "Makefile",
10
+ "README.md",
11
+ "amd_bios.py",
12
+ "amd_pstate.py",
13
+ "amd_s2idle.py",
14
+ "amd_ttm.py",
15
+ "docs/amd-bios.md",
16
+ "docs/amd-pstate.md",
17
+ "docs/amd-s2idle.md",
18
+ "docs/amd-ttm.md",
19
+ "docs/in-tree.md",
20
+ "install_deps.py",
21
+ "psr.py",
22
+ "pyproject.toml",
23
+ "src/amd_debug/__init__.py",
24
+ "src/amd_debug/acpi.py",
25
+ "src/amd_debug/bash/amd-s2idle",
26
+ "src/amd_debug/battery.py",
27
+ "src/amd_debug/bios.py",
28
+ "src/amd_debug/common.py",
29
+ "src/amd_debug/database.py",
30
+ "src/amd_debug/display.py",
31
+ "src/amd_debug/failures.py",
32
+ "src/amd_debug/installer.py",
33
+ "src/amd_debug/kernel.py",
34
+ "src/amd_debug/power_rails.py",
35
+ "src/amd_debug/prerequisites.py",
36
+ "src/amd_debug/pstate.py",
37
+ "src/amd_debug/s2idle-hook",
38
+ "src/amd_debug/s2idle.py",
39
+ "src/amd_debug/sleep_report.py",
40
+ "src/amd_debug/templates/html",
41
+ "src/amd_debug/templates/md",
42
+ "src/amd_debug/templates/stdout",
43
+ "src/amd_debug/templates/txt",
44
+ "src/amd_debug/ttm.py",
45
+ "src/amd_debug/validator.py",
46
+ "src/amd_debug/wake.py",
47
+ "src/launcher.py",
48
+ "src/test_acpi.py",
49
+ "src/test_batteries.py",
50
+ "src/test_bios.py",
51
+ "src/test_common.py",
52
+ "src/test_database.py",
53
+ "src/test_display.py",
54
+ "src/test_failures.py",
55
+ "src/test_installer.py",
56
+ "src/test_kernel.py",
57
+ "src/test_launcher.py",
58
+ "src/test_power_rails.py",
59
+ "src/test_prerequisites.py",
60
+ "src/test_pstate.py",
61
+ "src/test_s2idle.py",
62
+ "src/test_sleep_report.py",
63
+ "src/test_ttm.py",
64
+ "src/test_validator.py",
65
+ "src/test_wake.py"
66
+ ]
67
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "tag": "0.2.21",
3
+ "distance": 0,
4
+ "node": "gacc87499f28855bfe36071873d565300e692d160",
5
+ "dirty": false,
6
+ "branch": "HEAD",
7
+ "node_date": "2026-08-16"
8
+ }
@@ -34,6 +34,7 @@ from amd_debug.common import (
34
34
  is_root,
35
35
  minimum_kernel,
36
36
  print_color,
37
+ read_msr,
37
38
  reboot,
38
39
  run_countdown,
39
40
  systemd_in_use,
@@ -233,6 +234,21 @@ class TestCommon(unittest.TestCase):
233
234
  mock_geteuid.assert_called_once()
234
235
  self.assertEqual(mock_geteuid.call_count, 1)
235
236
 
237
+ @patch("amd_debug.common.os.open", side_effect=OSError)
238
+ @patch("amd_debug.common.subprocess.run")
239
+ @patch("amd_debug.common.is_root", return_value=True)
240
+ @patch("amd_debug.common.os.path.exists", return_value=False)
241
+ def test_read_msr_loads_module(
242
+ self, mock_exists, mock_is_root, mock_run, mock_open_fd
243
+ ):
244
+ """Test read_msr loads the msr module via an absolute path and no shell"""
245
+ with self.assertRaises(PermissionError):
246
+ read_msr(0xC0010292, 0)
247
+ mock_run.assert_called_once_with(["/sbin/modprobe", "msr"], check=False)
248
+ # ensure the module load never went through a shell
249
+ _, kwargs = mock_run.call_args
250
+ self.assertNotIn("shell", kwargs)
251
+
236
252
  def test_get_log_priority(self):
237
253
  """Test get_log_priority works for expected values"""
238
254
  ret = get_log_priority(None)
@@ -7,6 +7,7 @@ This module contains unit tests for the datbase functions in the amd-debug-tools
7
7
  import unittest
8
8
 
9
9
  from datetime import datetime
10
+ from unittest.mock import patch, MagicMock
10
11
 
11
12
  from amd_debug.database import SleepDatabase
12
13
 
@@ -364,6 +365,23 @@ class TestSleepDatabase(unittest.TestCase):
364
365
  result = self.db.report_power_rails(timestamp)
365
366
  self.assertEqual(result, [])
366
367
 
368
+ def test_default_db_path_uses_var_lib_restrictive(self):
369
+ """Test the default database path is created securely in /var/lib"""
370
+ with patch("amd_debug.database.os.makedirs") as makedirs, patch(
371
+ "amd_debug.database.os.path.exists", return_value=False
372
+ ), patch("amd_debug.database.sqlite3.connect", return_value=MagicMock()):
373
+ SleepDatabase()
374
+
375
+ # Directory is created in /var/lib with a restrictive mode
376
+ makedirs.assert_called_once_with(
377
+ "/var/lib/amd-s2idle", mode=0o700, exist_ok=True
378
+ )
379
+
380
+ # The insecure /var/local fallback is never referenced
381
+ for call in makedirs.call_args_list:
382
+ for arg in call.args:
383
+ self.assertNotIn("/var/local", str(arg))
384
+
367
385
  def test_schema_migration_v1_to_v2(self):
368
386
  """Test database migration from schema v1 to v2"""
369
387
  # Create a new database (will be at v2)
@@ -14,6 +14,7 @@ import logging
14
14
  from amd_debug.kernel import (
15
15
  sscanf_bios_args,
16
16
  get_kernel_command_line,
17
+ redact_sensitive,
17
18
  DmesgLogger,
18
19
  InputFile,
19
20
  KernelLogger,
@@ -67,6 +68,31 @@ class TestKernelLog(unittest.TestCase):
67
68
  result = get_kernel_command_line()
68
69
  self.assertEqual(result, expected_output)
69
70
 
71
+ def test_redact_sensitive(self):
72
+ """Test redact_sensitive function"""
73
+
74
+ # MAC addresses are redacted
75
+ result = redact_sensitive("wlan0: link up 00:11:22:33:44:55 detected")
76
+ self.assertEqual(result, "wlan0: link up <redacted-mac> detected")
77
+
78
+ # UUIDs are redacted
79
+ result = redact_sensitive(
80
+ "cryptsetup: 12345678-90ab-cdef-1234-567890abcdef mounted"
81
+ )
82
+ self.assertEqual(result, "cryptsetup: <redacted-uuid> mounted")
83
+
84
+ # key/secret/password/token assignments are redacted
85
+ self.assertEqual(
86
+ redact_sensitive("luks key=abcd1234"), "luks key=<redacted>"
87
+ )
88
+ self.assertEqual(
89
+ redact_sensitive("token=deadbeef"), "token=<redacted>"
90
+ )
91
+
92
+ # Ordinary log text is preserved
93
+ line = "amd_pmc AMDI0009:00: SMU idlemask s0i3: 0x1234abcd"
94
+ self.assertEqual(redact_sensitive(line), line)
95
+
70
96
  def test_sscanf_bios_args(self):
71
97
  """Test sscanf_bios_args function"""
72
98
 
@@ -338,6 +364,21 @@ class TestSscanfBiosArgsEdge(unittest.TestCase):
338
364
  """ev_queue_notify_reques without ': ' returns None"""
339
365
  self.assertIsNone(sscanf_bios_args("ev_queue_notify_reques nothing"))
340
366
 
367
+ def test_ex_trace_args_oversized_width(self):
368
+ """An oversized field width is rejected instead of allocating memory"""
369
+ line = 'ex_trace_args: "%2147483646d", 1, 0, 0, 0, 0, 0'
370
+ self.assertIsNone(sscanf_bios_args(line))
371
+
372
+ def test_ex_trace_args_unexpected_conversion(self):
373
+ """A conversion outside the whitelist is rejected"""
374
+ line = 'ex_trace_args: "value: %s", 1, 0, 0, 0, 0, 0'
375
+ self.assertIsNone(sscanf_bios_args(line))
376
+
377
+ def test_ex_trace_args_valid_conversion(self):
378
+ """A whitelisted conversion is still applied normally"""
379
+ line = 'ex_trace_args: "%x", 1234'
380
+ self.assertEqual(sscanf_bios_args(line), "1234")
381
+
341
382
 
342
383
  class TestGetKernelLog(unittest.TestCase):
343
384
  """Test get_kernel_log provider selection"""
@@ -98,6 +98,131 @@ class TestPrerequisiteValidator(unittest.TestCase):
98
98
  self.assertFalse(result)
99
99
  self.assertTrue(any(isinstance(f, AmdHsmpBug) for f in self.validator.failures))
100
100
 
101
+ @patch("amd_debug.prerequisites.os.path.exists")
102
+ def test_check_amd_xdna_no_driver(self, mock_exists):
103
+ """Test check_amd_xdna when driver is not loaded"""
104
+ mock_exists.return_value = False
105
+ result = self.validator.check_amd_xdna()
106
+ self.assertTrue(result)
107
+ self.mock_db.record_prereq.assert_not_called()
108
+
109
+ @patch("amd_debug.prerequisites.os.path.exists")
110
+ def test_check_amd_xdna_no_iommu(self, mock_exists):
111
+ """Test check_amd_xdna when IOMMU is disabled"""
112
+ mock_exists.side_effect = lambda p: True if "amdxdna" in p else False
113
+
114
+ def mock_list_devices(**kwargs):
115
+ if kwargs.get("subsystem") == "iommu":
116
+ return []
117
+ if kwargs.get("subsystem") == "pci":
118
+ return [
119
+ MagicMock(
120
+ properties={
121
+ "PCI_SLOT_NAME": "0000:01:00.0",
122
+ "PCI_ID": "1022:1234",
123
+ "DRIVER": "amdxdna",
124
+ }
125
+ )
126
+ ]
127
+ return []
128
+
129
+ self.mock_pyudev.list_devices.side_effect = mock_list_devices
130
+
131
+ result = self.validator.check_amd_xdna()
132
+ self.assertFalse(result)
133
+ self.assertTrue(any(isinstance(f, NpuIommu) for f in self.validator.failures))
134
+ self.mock_db.record_prereq.assert_called_with(
135
+ "NPU is not supported with IOMMU disabled", "❌"
136
+ )
137
+
138
+ @patch("amd_debug.prerequisites.os.path.exists")
139
+ def test_check_amd_xdna_missing_driver(self, mock_exists):
140
+ """Test check_amd_xdna when NPU is found but no driver is bound"""
141
+ mock_exists.side_effect = lambda p: True if "amdxdna" in p else False
142
+
143
+ def mock_list_devices(**kwargs):
144
+ if kwargs.get("subsystem") == "iommu":
145
+ return [MagicMock()]
146
+ if kwargs.get("subsystem") == "pci":
147
+ return [
148
+ MagicMock(
149
+ properties={
150
+ "PCI_SLOT_NAME": "0000:01:00.0",
151
+ "PCI_ID": "1022:1234",
152
+ "DRIVER": None,
153
+ }
154
+ )
155
+ ]
156
+ return []
157
+
158
+ self.mock_pyudev.list_devices.side_effect = mock_list_devices
159
+
160
+ result = self.validator.check_amd_xdna()
161
+ self.assertTrue(result)
162
+ self.assertTrue(
163
+ any(isinstance(f, MissingDriver) for f in self.validator.failures)
164
+ )
165
+ self.mock_db.record_prereq.assert_called_with(
166
+ "NPU device in 0000:01:00.0 didn't bind a driver", "🚦"
167
+ )
168
+
169
+ @patch("amd_debug.prerequisites.read_file")
170
+ @patch("amd_debug.prerequisites.os.path.exists")
171
+ def test_check_amd_xdna_success(self, mock_exists, mock_read_file):
172
+ """Test check_amd_xdna when driver is loaded, NPU is bound, and IOMMU is enabled"""
173
+ mock_exists.side_effect = lambda p: True
174
+ mock_read_file.return_value = "1.0.0"
175
+
176
+ def mock_list_devices(**kwargs):
177
+ if kwargs.get("subsystem") == "iommu":
178
+ return [MagicMock()]
179
+ if kwargs.get("subsystem") == "pci":
180
+ return [
181
+ MagicMock(
182
+ sys_path="/sys/devices/pci",
183
+ properties={
184
+ "PCI_SLOT_NAME": "0000:01:00.0",
185
+ "PCI_ID": "1022:1234",
186
+ "DRIVER": "amdxdna",
187
+ },
188
+ )
189
+ ]
190
+ return []
191
+
192
+ self.mock_pyudev.list_devices.side_effect = mock_list_devices
193
+
194
+ result = self.validator.check_amd_xdna()
195
+ self.assertTrue(result)
196
+ self.mock_db.record_prereq.assert_called_with(
197
+ "NPU loaded with firmware 1.0.0", "✅"
198
+ )
199
+
200
+ @patch("amd_debug.prerequisites.os.path.exists")
201
+ def test_check_amd_xdna_non_amd(self, mock_exists):
202
+ """Test check_amd_xdna when the NPU is not an AMD device"""
203
+ mock_exists.side_effect = lambda p: True if "amdxdna" in p else False
204
+
205
+ def mock_list_devices(**kwargs):
206
+ if kwargs.get("subsystem") == "iommu":
207
+ return [MagicMock()]
208
+ if kwargs.get("subsystem") == "pci":
209
+ return [
210
+ MagicMock(
211
+ properties={
212
+ "PCI_SLOT_NAME": "0000:01:00.0",
213
+ "PCI_ID": "8086:abcd",
214
+ "DRIVER": "amdxdna",
215
+ }
216
+ )
217
+ ]
218
+ return []
219
+
220
+ self.mock_pyudev.list_devices.side_effect = mock_list_devices
221
+
222
+ result = self.validator.check_amd_xdna()
223
+ self.assertTrue(result)
224
+ self.mock_db.record_prereq.assert_not_called()
225
+
101
226
  def test_check_amd_pmc_no_driver(self):
102
227
  """Test check_amd_pmc with no driver"""
103
228
  self.mock_pyudev.list_devices.return_value = []
@@ -592,6 +717,31 @@ class TestPrerequisiteValidator(unittest.TestCase):
592
717
  "Unable to check CPU topology: cpuid kernel module not loaded", "❌"
593
718
  )
594
719
 
720
+ @patch("amd_debug.prerequisites.subprocess.run")
721
+ @patch("builtins.open", new_callable=mock_open)
722
+ @patch("amd_debug.prerequisites.read_file")
723
+ @patch("amd_debug.prerequisites.os.path.exists")
724
+ def test_check_cpu_loads_cpuid_module(
725
+ self, mock_path_exists, mock_read_file, mock_file_open, mock_run
726
+ ):
727
+ """Test read_cpuid loads the cpuid module via an absolute path and no shell"""
728
+ self.validator.cpu_family = 0x19
729
+ self.validator.cpu_model = 0x74
730
+ mock_read_file.return_value = "31" # kernel_max = 31 (32 cores)
731
+ # cpuid device node missing so the module load path is exercised
732
+ mock_path_exists.return_value = False
733
+ mock_file_open.return_value.read.side_effect = [
734
+ struct.pack("4I", 0, 0, 0x100, 0), # subleaf 0: level_type = 1
735
+ struct.pack("4I", 0, 0, 0x400, 0), # subleaf 1: level_type = 4 (socket)
736
+ struct.pack("4I", 0, 16, 0, 0), # subleaf 1: cpu_count = 16
737
+ ]
738
+ result = self.validator.check_cpu()
739
+ self.assertTrue(result)
740
+ mock_run.assert_any_call(["/sbin/modprobe", "cpuid"], check=False)
741
+ # ensure the module load never went through a shell
742
+ for _, kwargs in mock_run.call_args_list:
743
+ self.assertNotIn("shell", kwargs)
744
+
595
745
  @patch("builtins.open", side_effect=PermissionError)
596
746
  @patch("amd_debug.prerequisites.read_file")
597
747
  @patch("amd_debug.prerequisites.os.path.exists")
@@ -878,6 +1028,27 @@ class TestPrerequisiteValidator(unittest.TestCase):
878
1028
  with self.assertRaises(FileNotFoundError):
879
1029
  self.validator.check_aspm()
880
1030
 
1031
+ def test_check_aspm_disabled_on_cmdline(self):
1032
+ """Test check_aspm when pcie_aspm=off is on the kernel command line"""
1033
+ self.validator.cmdline = "quiet pcie_aspm=off rw"
1034
+ result = self.validator.check_aspm()
1035
+ self.assertFalse(result)
1036
+ self.mock_db.record_prereq.assert_called_with(
1037
+ "ASPM disabled on kernel command line (pcie_aspm=off)", "❌"
1038
+ )
1039
+ self.assertTrue(any(isinstance(f, ASpmWrong) for f in self.validator.failures))
1040
+
1041
+ @patch("amd_debug.prerequisites.read_file")
1042
+ def test_check_aspm_cmdline_without_aspm_off(self, mock_read_file):
1043
+ """Test check_aspm still reads the policy when cmdline is clean"""
1044
+ self.validator.cmdline = "quiet splash rw"
1045
+ mock_read_file.return_value = "[default]"
1046
+ result = self.validator.check_aspm()
1047
+ self.assertTrue(result)
1048
+ self.mock_db.record_prereq.assert_called_with(
1049
+ "ASPM policy set to 'default'", "✅"
1050
+ )
1051
+
881
1052
  @patch("amd_debug.prerequisites.os.path.exists")
882
1053
  @patch("amd_debug.prerequisites.read_file")
883
1054
  def test_check_i2c_hid_no_devices(self, mock_read_file, mock_path_exists):
@@ -492,6 +492,42 @@ class TestWakeIRQ(unittest.TestCase):
492
492
  irq = WakeIRQ(80)
493
493
  self.assertEqual(irq.name, "")
494
494
 
495
+ @patch("amd_debug.wake.read_file")
496
+ @patch("os.path.exists")
497
+ @patch("os.listdir")
498
+ @patch("os.walk")
499
+ def test_wake_irq_acpi_path_traversal(
500
+ self, mock_os_walk, mock_os_listdir, mock_os_path_exists, mock_read_file
501
+ ):
502
+ """A traversal sequence in actions must not escape the ACPI device dir"""
503
+ mock_read_file.side_effect = lambda path: {
504
+ "/sys/kernel/irq/82/chip_name": "",
505
+ "/sys/kernel/irq/82/actions": "../../foo",
506
+ "/sys/kernel/irq/82/wakeup": "enabled",
507
+ }.get(path, "")
508
+
509
+ checked = []
510
+
511
+ def exists_side_effect(path):
512
+ checked.append(path)
513
+ return False
514
+
515
+ mock_os_path_exists.side_effect = exists_side_effect
516
+
517
+ irq = WakeIRQ(82)
518
+
519
+ # The action name must be reduced to its basename before being joined
520
+ # under the ACPI devices directory, so no ".." component is ever used.
521
+ acpi_checks = [
522
+ p for p in checked if p.startswith("/sys/bus/acpi/devices")
523
+ ]
524
+ self.assertIn("/sys/bus/acpi/devices/foo", acpi_checks)
525
+ for p in acpi_checks:
526
+ self.assertNotIn("..", p)
527
+ # os.walk must never run since the sanitised path does not exist.
528
+ mock_os_walk.assert_not_called()
529
+ self.assertEqual(irq.name, "")
530
+
495
531
  def test_wake_irq_str(self):
496
532
  """Test __str__ of WakeIRQ"""
497
533
  with patch("amd_debug.wake.read_file", side_effect=FileNotFoundError()), \