Verify stock requirements in UVM and modeset bridge checks (#462)

* Verify stock requirements in UVM and modeset bridge checks

* fix(tools): require stock pair check for explicit --stock-symvers and check access-bits from stock_uvm_und

---------

Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Eric Hartford <eric@quixi.ai>
This commit is contained in:
harmless_teddy
2026-12-05 00:08:46 -05:00
committed by GitHub
parent 45104b98b8
commit e8ba298d38
4 changed files with 297 additions and 18 deletions

View File

@ -12,10 +12,10 @@ modules:
python3 tools/check_kernel_module.py
uvm-bridge: modules
$(MAKE) -C $(KERNEL_OUTPUT) M=$(ROOT)/kernel-open/uvm_bridge KBUILD_EXTRA_SYMBOLS=$(ROOT)/kernel-open/Module.symvers modules
cd $(ROOT) && python3 tools/check_uvm_symbol_conformance.py
cd $(ROOT) && python3 tools/check_uvm_symbol_conformance.py $(UVM_CONFORMANCE_ARGS)
modeset-bridge: modules
$(MAKE) -C $(KERNEL_OUTPUT) M=$(ROOT)/kernel-open/modeset_bridge KBUILD_EXTRA_SYMBOLS=$(ROOT)/kernel-open/Module.symvers modules
cd $(ROOT) && python3 tools/check_modeset_symbol_conformance.py
cd $(ROOT) && python3 tools/check_modeset_symbol_conformance.py $(MODESET_CONFORMANCE_ARGS)
# Staging is mandatory: this project must never replace the working driver.
modules_install: modules
@stage=$(call nv_rs_shell_quote,$(INSTALL_MOD_PATH)); \

View File

@ -72,6 +72,30 @@ class TestSymbolConformance(unittest.TestCase):
self.assertEqual(report["exact_crc_match_count"], 0)
self.assertEqual(report["bridge_exported_count"], 76)
def test_explicit_r620_detects_missing_access_bits_backing(self) -> None:
data = self._uvm_base_inputs()
data["expected_symbol_count"] = 79
result = uvm_check.evaluate_conformance(**data)
self.assertFalse(result["passed"])
self.assertFalse(result["checks"]["r620_access_bits_handlers_wired"])
self.assertEqual(set(result["missing_access_bits_handlers"]), set(uvm_check.R620_ACCESS_BITS_HANDLERS))
def test_stock_imports_require_access_bits_even_when_exact_checks_are_skipped(self) -> None:
inputs = self._uvm_base_inputs(modversions=False)
inputs["stock_uvm_und"].update(uvm_check.R620_ACCESS_BITS_SYMBOLS)
inputs["stock_nv_def"].update(uvm_check.R620_ACCESS_BITS_SYMBOLS)
inputs["skipped_exact_gate"] = True
report = uvm_check.evaluate_conformance(**inputs)
self.assertFalse(report["passed"])
self.assertFalse(report["checks"]["r620_access_bits_handlers_wired"])
handlers = set(uvm_check.R620_ACCESS_BITS_HANDLERS)
inputs["bridge_und"].update(handlers)
inputs["rust_def"].update(handlers)
inputs["nv_rs_symvers"].update(dict.fromkeys(handlers, "0x00000000"))
report = uvm_check.evaluate_conformance(**inputs)
self.assertTrue(report["passed"])
self.assertTrue(report["checks"]["r620_access_bits_handlers_wired"])
def test_uvm_fails_without_modversions_when_export_missing(self) -> None:
inputs = self._uvm_base_inputs(modversions=False)
inputs["bridge_def"].remove("nvUvmInterfaceSym00")
@ -126,6 +150,34 @@ class TestSymbolConformance(unittest.TestCase):
# stock modeset and bridge CRCs for nvidia_get_rm_ops are equal, so crc_mismatches stays empty.
self.assertEqual(report["crc_mismatches"], [])
def test_explicit_crc_exception_requires_both_values(self) -> None:
cases = [
(uvm_check, self._uvm_base_inputs(), "stock_uvm_crcs", "nvUvmInterfaceSym00"),
(ms_check, self._modeset_base_inputs(), "stock_ms_crcs", "nvidia_get_rm_ops"),
]
for checker, inputs, stock_crcs, symbol in cases:
with self.subTest(checker=checker.__name__):
inputs["allowed_crc_differences"] = frozenset({symbol})
inputs[stock_crcs][symbol] = "0x11111111"
result = checker.evaluate_conformance(**inputs)
self.assertTrue(result["passed"])
self.assertEqual(result["allowed_crc_mismatches"][0]["symbol"], symbol)
del inputs[stock_crcs][symbol]
result = checker.evaluate_conformance(**inputs)
self.assertFalse(result["passed"])
self.assertEqual(result["allowed_crc_mismatches"], [])
self.assertEqual(result["unexpected_crc_mismatches"][0]["symbol"], symbol)
def test_modeset_rejects_missing_crcs_in_explicit_stock_cross_check(self) -> None:
inputs = self._modeset_base_inputs()
inputs["stock_drm_crcs"] = {}
inputs["stock_modeset_symvers"] = {}
result = ms_check.evaluate_conformance(**inputs)
self.assertTrue(result["stock_drm_modeset_nvkmskapi_checked"])
self.assertFalse(result["passed"])
self.assertEqual(result["stock_drm_modeset_nvkmskapi_crc_mismatches"][0]["symbol"],
"nvKmsKapiGetFunctionsTable")
def test_parse_modversions_returns_none_when_versions_section_absent(self) -> None:
with tempfile.TemporaryDirectory(prefix="nvrs-modver-test-") as tmpdir:
src = Path(tmpdir) / "empty.s"

View File

@ -15,10 +15,18 @@ Checks:
matching CRC.
5. `nvidia_rs.ko` itself does NOT export `nvidia_get_rm_ops` directly (preserving
side-by-side Dual-GPU Parity compatibility with stock `nvidia.ko` on the host).
By default the stock modules are the ones installed on the host
(`modinfo -n nvidia-modeset` / `nvidia-drm` / `nvidia`). `--stock-modeset-ko`,
`--stock-drm-ko` and `--stock-nvidia-ko` (or the `NV_RS_STOCK_MODESET_KO`,
`NV_RS_STOCK_DRM_KO` / `NV_RS_STOCK_NVIDIA_KO` environment variables) point the
comparison at a stock build tree instead, so the same check can run against a
locally built stock module set.
"""
from __future__ import annotations
from contextlib import contextmanager
import argparse
import json
import os
import re
@ -227,6 +235,9 @@ def evaluate_conformance(
reference_driver_version: str = "",
stock_nvidia_version: str = "",
skipped_exact_gate: bool = False,
allowed_crc_differences: frozenset[str] = frozenset(),
stock_modeset_symvers: dict[str, str] | None = None,
require_stock_pair_check: bool = False,
) -> dict:
required_from_nvidia = sorted((stock_ms_und | stock_drm_und) & stock_nv_def)
drm_from_modeset = sorted(stock_drm_und & stock_ms_def)
@ -296,12 +307,41 @@ def evaluate_conformance(
nv_rs_direct_collisions = sorted(s for s in nv_rs_symvers if s in required_from_nvidia)
allowed_crc_mismatches = []
unexpected_crc_mismatches = []
for mismatch in crc_mismatches:
if (mismatch["symbol"] in allowed_crc_differences
and mismatch["stock_crc"] is not None and mismatch["bridge_crc"] is not None):
allowed_crc_mismatches.append(mismatch)
else:
unexpected_crc_mismatches.append(mismatch)
stock_pair_checked = stock_modeset_symvers is not None and stock_drm_crcs is not None
stock_pair_crc_mismatches = []
if stock_modeset_symvers is not None and stock_drm_crcs is not None:
stock_pair_crc_mismatches = [
{
"symbol": symbol,
"drm_import_crc": stock_drm_crcs.get(symbol),
"modeset_export_crc": stock_modeset_symvers.get(symbol),
}
for symbol in drm_from_modeset
if symbol.startswith("nvKmsKapi")
and (
symbol not in stock_drm_crcs
or symbol not in stock_modeset_symvers
or stock_drm_crcs[symbol] != stock_modeset_symvers[symbol]
)
]
exact_checks = {
"stock_required_nvidia_symbol_count_nonzero": len(required_from_nvidia) > 0,
"all_stock_modeset_drm_nvidia_symbols_exported_by_bridge": len(missing_bridge_exports) == 0,
"all_stock_modeset_drm_modversions_crcs_match": (not modversions_mismatch) and len(crc_mismatches) == 0,
"all_stock_modeset_drm_modversions_crcs_match": (not modversions_mismatch) and not unexpected_crc_mismatches,
}
internal_checks = {
"stock_drm_modeset_nvkmskapi_crcs_match": (
(not stock_pair_crc_mismatches)
and (stock_pair_checked or not require_stock_pair_check)
),
"all_bridge_rust_ffi_handlers_linked_and_exported": (
len(bridge_nv_rs_imports) == 8
and len(missing_rust_defs) == 0
@ -324,6 +364,11 @@ def evaluate_conformance(
"stock_nvidia_ko": stock_nv_ko,
"required_from_nvidia": required_from_nvidia,
"drm_from_modeset": drm_from_modeset,
"allowed_crc_differences": sorted(allowed_crc_differences),
"allowed_crc_mismatches": allowed_crc_mismatches,
"unexpected_crc_mismatches": unexpected_crc_mismatches,
"stock_drm_modeset_nvkmskapi_checked": stock_pair_checked,
"stock_drm_modeset_nvkmskapi_crc_mismatches": stock_pair_crc_mismatches,
"required_symbol_count": len(required_from_nvidia),
"bridge_exported_count": len(required_from_nvidia) - len(missing_bridge_exports),
"exact_crc_match_count": (len(required_from_nvidia) - len(crc_mismatches)) if modversions_enabled else 0,
@ -346,19 +391,81 @@ def evaluate_conformance(
}
def stock_module(explicit: str | None, env: str, module: str) -> Path:
"""Locate a stock module: explicit path, environment override, or modinfo."""
if explicit:
return Path(explicit)
from_env = os.environ.get(env)
if from_env:
return Path(from_env)
return Path(run(find_tool("modinfo"), "-n", module).strip())
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument(
"--stock-modeset-ko",
help="stock nvidia-modeset.ko to compare against (default: modinfo -n nvidia-modeset)",
)
parser.add_argument(
"--stock-drm-ko",
help="stock nvidia-drm.ko to compare against (default: modinfo -n nvidia-drm)",
)
parser.add_argument(
"--stock-nvidia-ko",
help="stock nvidia.ko that provides the RM ops (default: modinfo -n nvidia)",
)
parser.add_argument(
"--report",
help="report path (default: reports/modeset-symbol-conformance.json)",
)
parser.add_argument(
"--stock-symvers",
help=(
"stock Module.symvers used to cross-check the stock nvidia-drm.ko <- "
"nvidia-modeset.ko nvKmsKapi* CRCs (default: Module.symvers next to the "
"stock modules, when present)"
),
)
parser.add_argument(
"--allow-crc-difference",
action="append",
default=[],
metavar="SYMBOL",
help=(
"stock symbol whose CONFIG_MODVERSIONS CRC is known to differ because the "
"stock tree is a different driver version (repeatable)"
),
)
args = parser.parse_args()
report_out = Path(args.report) if args.report else REPORT_OUT
for p in (RUST_OBJ, NVIDIA_RS_KO, NVIDIA_RS_SYMVERS, BRIDGE_KO, BRIDGE_SYMVERS):
if not p.exists():
print(f"ERROR: missing build artifact: {p}", file=sys.stderr)
return 2
modinfo_bin = find_tool("modinfo")
stock_modeset_ko = Path(run(modinfo_bin, "-n", "nvidia-modeset").strip())
stock_drm_ko = Path(run(modinfo_bin, "-n", "nvidia-drm").strip())
stock_nv_ko = Path(run(modinfo_bin, "-n", "nvidia").strip())
stock_modeset_ko = stock_module(
args.stock_modeset_ko, "NV_RS_STOCK_MODESET_KO", "nvidia-modeset"
)
stock_drm_ko = stock_module(args.stock_drm_ko, "NV_RS_STOCK_DRM_KO", "nvidia-drm")
stock_nv_ko = stock_module(args.stock_nvidia_ko, "NV_RS_STOCK_NVIDIA_KO", "nvidia")
for p in (stock_modeset_ko, stock_drm_ko, stock_nv_ko):
if not p.exists():
print(f"ERROR: missing stock module: {p}", file=sys.stderr)
return 2
reference_version = read_reference_driver_version()
stock_nvidia_version = run(modinfo_bin, "-F", "version", str(stock_nv_ko)).strip()
strict_conformance = os.environ.get("NV_RS_STRICT_CONFORMANCE") == "1"
strict_conformance = (
os.environ.get("NV_RS_STRICT_CONFORMANCE") == "1"
or bool(args.stock_modeset_ko or args.stock_drm_ko or args.stock_nvidia_ko or args.stock_symvers)
or any(os.environ.get(key) for key in (
"NV_RS_STOCK_MODESET_KO", "NV_RS_STOCK_DRM_KO", "NV_RS_STOCK_NVIDIA_KO",
))
or bool(args.allow_crc_difference)
)
skipped_exact_gate = bool(
not strict_conformance
and reference_version
@ -395,6 +502,15 @@ def main() -> int:
nv_rs_symvers = parse_symvers(NVIDIA_RS_SYMVERS)
rust_def, _ = parse_elf_symbols(RUST_OBJ)
stock_symvers_path = (
Path(args.stock_symvers) if args.stock_symvers
else stock_modeset_ko.parent / "Module.symvers"
)
if args.stock_symvers and not stock_symvers_path.is_file():
print(f"ERROR: missing stock symbol versions: {stock_symvers_path}", file=sys.stderr)
return 2
stock_modeset_symvers = parse_symvers(stock_symvers_path) if stock_symvers_path.is_file() else None
report = evaluate_conformance(
stock_modeset_ko=str(stock_modeset_ko),
stock_drm_ko=str(stock_drm_ko),
@ -414,7 +530,11 @@ def main() -> int:
reference_driver_version=reference_version,
stock_nvidia_version=stock_nvidia_version,
skipped_exact_gate=skipped_exact_gate,
allowed_crc_differences=frozenset(args.allow_crc_difference),
stock_modeset_symvers=stock_modeset_symvers,
require_stock_pair_check=bool(args.stock_symvers),
)
report["stock_symvers"] = str(stock_symvers_path) if stock_modeset_symvers is not None else None
passed = report["passed"]
if skipped_exact_gate:
print(
@ -423,8 +543,8 @@ def main() -> int:
"internal bridge <-> nvidia_rs.ko wiring checks still enforced.",
file=sys.stderr,
)
REPORT_OUT.parent.mkdir(parents=True, exist_ok=True)
REPORT_OUT.write_text(json.dumps(report, indent=2) + "\n")
report_out.parent.mkdir(parents=True, exist_ok=True)
report_out.write_text(json.dumps(report, indent=2) + "\n")
print(json.dumps({
"passed": passed,
"modversions_enabled": report["modversions_enabled"],

View File

@ -11,10 +11,17 @@ Checks:
matching CRC (76/76).
4. nvidia_rs.ko itself does NOT export nvUvmInterface* directly (preserving side-by-side
Dual-GPU Parity compatibility with stock nvidia.ko on the host).
By default the stock modules are the ones installed on the host
(`modinfo -n nvidia-uvm` / `modinfo -n nvidia`). `--stock-uvm-ko` and
`--stock-nvidia-ko` (or the `NV_RS_STOCK_UVM_KO` / `NV_RS_STOCK_NVIDIA_KO`
environment variables) point the comparison at a stock build tree instead, so the
same check can run against a locally built stock module set.
"""
from __future__ import annotations
from contextlib import contextmanager
import argparse
import json
import os
import re
@ -36,6 +43,22 @@ BRIDGE_SYMVERS = ROOT / "kernel-open/uvm_bridge/Module.symvers"
REPORT_OUT = ROOT / "reports/uvm-symbol-conformance.json"
# Rust handlers behind the 620.73.04 access-bits entry points. They are not
# part of the stock 580 symbol set, but the bridge has to reach them: stock
# UVM allocates one access-bits buffer per parent GPU and aborts the whole GPU
# registration when the allocation fails (uvm_gpu.c:3034-3038).
R620_ACCESS_BITS_SYMBOLS = frozenset({
"nvUvmInterfaceAccessBitsBufAlloc",
"nvUvmInterfaceAccessBitsBufFree",
"nvUvmInterfaceAccessBitsDump",
})
R620_ACCESS_BITS_HANDLERS = (
"nv_rs_uvm_iface_access_bits_buf_alloc",
"nv_rs_uvm_iface_access_bits_buf_free",
"nv_rs_uvm_iface_access_bits_buf_dump",
)
def find_tool(name: str) -> str:
return shutil.which(name) or f"/sbin/{name}"
@ -217,6 +240,8 @@ def evaluate_conformance(
reference_driver_version: str = "",
stock_nvidia_version: str = "",
skipped_exact_gate: bool = False,
expected_symbol_count: int = 76,
allowed_crc_differences: frozenset[str] = frozenset(),
) -> dict:
required_uvm_syms = sorted(stock_uvm_und & stock_nv_def)
missing_bridge_exports = [s for s in required_uvm_syms if s not in bridge_symvers or s not in bridge_def]
@ -263,20 +288,40 @@ def evaluate_conformance(
nv_rs_direct_uvm_collisions = sorted(s for s in nv_rs_symvers if s.startswith("nvUvmInterface"))
required_uvm_iface_syms = [s for s in required_uvm_syms if s.startswith("nvUvmInterface")]
missing_access_bits_handlers = [
s for s in R620_ACCESS_BITS_HANDLERS if s not in bridge_nv_rs_imports
]
# The host's stock UVM may need these even when exact stock CRC checks are skipped.
check_access_bits = (
bool(R620_ACCESS_BITS_SYMBOLS.intersection(stock_uvm_und))
or expected_symbol_count >= 79
or len(missing_access_bits_handlers) < len(R620_ACCESS_BITS_HANDLERS)
)
expected_backing_count = 76 + (len(R620_ACCESS_BITS_HANDLERS) if check_access_bits else 0)
allowed_crc_mismatches = []
unexpected_crc_mismatches = []
for mismatch in crc_mismatches:
if (mismatch["symbol"] in allowed_crc_differences
and mismatch["stock_crc"] is not None and mismatch["bridge_crc"] is not None):
allowed_crc_mismatches.append(mismatch)
else:
unexpected_crc_mismatches.append(mismatch)
exact_checks = {
"stock_uvm_required_symbol_count_76": len(required_uvm_iface_syms) == 76,
"stock_uvm_required_symbol_count_matches_expectation": len(required_uvm_iface_syms) == expected_symbol_count,
"all_stock_uvm_symbols_exported_by_bridge": len(missing_bridge_exports) == 0,
"all_stock_uvm_modversions_crcs_match": (not modversions_mismatch) and len(crc_mismatches) == 0,
"all_stock_uvm_modversions_crcs_match": (not modversions_mismatch) and not unexpected_crc_mismatches,
}
internal_checks = {
"all_76_rust_ffi_handlers_linked_and_exported": (
len(bridge_nv_rs_imports) == 76
"all_expected_rust_ffi_handlers_linked_and_exported": (
len(bridge_nv_rs_imports) == expected_backing_count
and len(missing_rust_defs) == 0
and len(missing_nv_rs_exports) == 0
),
"bridge_to_nvidia_rs_modversions_crcs_match": (not modversions_mismatch) and len(bridge_to_nv_rs_crc_mismatches) == 0,
"no_direct_nvUvmInterface_collision_in_nvidia_rs": len(nv_rs_direct_uvm_collisions) == 0,
}
if check_access_bits:
internal_checks["r620_access_bits_handlers_wired"] = not missing_access_bits_handlers
checks = {**exact_checks, **internal_checks}
passed = all(internal_checks.values()) if skipped_exact_gate else all(checks.values())
@ -288,6 +333,11 @@ def evaluate_conformance(
"skipped_exact_gate": skipped_exact_gate,
"stock_uvm_ko": str(stock_uvm_ko),
"stock_nvidia_ko": str(stock_nv_ko),
"expected_symbol_count": expected_symbol_count,
"allowed_crc_differences": sorted(allowed_crc_differences),
"allowed_crc_mismatches": allowed_crc_mismatches,
"missing_access_bits_handlers": missing_access_bits_handlers,
"unexpected_crc_mismatches": unexpected_crc_mismatches,
"required_symbol_count": len(required_uvm_syms),
"bridge_exported_count": len(required_uvm_syms) - len(missing_bridge_exports),
"exact_crc_match_count": (len(required_uvm_syms) - len(crc_mismatches)) if modversions_enabled else 0,
@ -302,18 +352,73 @@ def evaluate_conformance(
}
def stock_module(explicit: str | None, env: str, module: str) -> Path:
"""Locate a stock module: explicit path, environment override, or modinfo."""
if explicit:
return Path(explicit)
from_env = os.environ.get(env)
if from_env:
return Path(from_env)
return Path(run(find_tool("modinfo"), "-n", module).strip())
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument(
"--stock-uvm-ko",
help="stock nvidia-uvm.ko to compare against (default: modinfo -n nvidia-uvm)",
)
parser.add_argument(
"--stock-nvidia-ko",
help="stock nvidia.ko that provides the interface (default: modinfo -n nvidia)",
)
parser.add_argument(
"--report",
help="report path (default: reports/uvm-symbol-conformance.json)",
)
parser.add_argument(
"--expected-symbol-count",
type=int,
default=76,
help="number of required nvUvmInterface* symbols the stock tree must import",
)
parser.add_argument(
"--allow-crc-difference",
action="append",
default=[],
metavar="SYMBOL",
help=(
"stock symbol whose CONFIG_MODVERSIONS CRC is known to differ because the "
"stock tree is a different driver version (repeatable)"
),
)
args = parser.parse_args()
report_out = Path(args.report) if args.report else REPORT_OUT
for p in (RUST_OBJ, NVIDIA_RS_KO, NVIDIA_RS_SYMVERS, BRIDGE_KO, BRIDGE_SYMVERS):
if not p.exists():
print(f"ERROR: missing build artifact: {p}", file=sys.stderr)
return 2
modinfo_bin = find_tool("modinfo")
stock_uvm_ko = Path(run(modinfo_bin, "-n", "nvidia-uvm").strip())
stock_nv_ko = Path(run(modinfo_bin, "-n", "nvidia").strip())
stock_uvm_ko = stock_module(args.stock_uvm_ko, "NV_RS_STOCK_UVM_KO", "nvidia-uvm")
stock_nv_ko = stock_module(
args.stock_nvidia_ko, "NV_RS_STOCK_NVIDIA_KO", "nvidia"
)
for p in (stock_uvm_ko, stock_nv_ko):
if not p.exists():
print(f"ERROR: missing stock module: {p}", file=sys.stderr)
return 2
reference_version = read_reference_driver_version()
stock_nvidia_version = run(modinfo_bin, "-F", "version", str(stock_nv_ko)).strip()
strict_conformance = os.environ.get("NV_RS_STRICT_CONFORMANCE") == "1"
strict_conformance = (
os.environ.get("NV_RS_STRICT_CONFORMANCE") == "1"
or bool(args.stock_uvm_ko or args.stock_nvidia_ko)
or bool(os.environ.get("NV_RS_STOCK_UVM_KO") or os.environ.get("NV_RS_STOCK_NVIDIA_KO"))
or bool(args.allow_crc_difference)
or args.expected_symbol_count != 76
)
skipped_exact_gate = bool(
not strict_conformance
and reference_version
@ -347,6 +452,8 @@ def main() -> int:
reference_driver_version=reference_version,
stock_nvidia_version=stock_nvidia_version,
skipped_exact_gate=skipped_exact_gate,
expected_symbol_count=args.expected_symbol_count,
allowed_crc_differences=frozenset(args.allow_crc_difference),
)
passed = report["passed"]
if skipped_exact_gate:
@ -356,8 +463,8 @@ def main() -> int:
"internal bridge <-> nvidia_rs.ko wiring checks still enforced.",
file=sys.stderr,
)
REPORT_OUT.parent.mkdir(parents=True, exist_ok=True)
REPORT_OUT.write_text(json.dumps(report, indent=2) + "\n")
report_out.parent.mkdir(parents=True, exist_ok=True)
report_out.write_text(json.dumps(report, indent=2) + "\n")
print(json.dumps({
"passed": passed,
"modversions_enabled": report["modversions_enabled"],