Files
nvdriver/docs/KERNEL_COMPAT.md
Gabriel A. Devenyi 7f7dce5fa1 nvidia-drm: build against kernels that renamed drm_atomic_state to drm_atomic_commit (#541)
Linux 7.3 renamed the atomic state container to struct drm_atomic_commit,
and the plane and CRTC atomic helper callbacks take the renamed type, so
nvidia_rs_drm.c fails to compile there with eight incompatible-pointer
errors (reported in #533).

Probe the definition in <drm/drm_atomic.h> from compat_probes.mk, as the
other DRM guards do, and use a typedef in the five callbacks. No
behaviour change on either side of the rename.


Claude-Session: https://claude.ai/code/session_01W53iUSBQkEg9aqwF4AoBHi

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-12-04 16:15:30 -08:00

15 KiB
Raw Permalink Blame History

Kernel-version compat guards

Conditional compile guards and version-independent stock-parity patterns in the kernel-open C shims for Linux 5.15 through 7.3+.

Stock-parity version-independent patterns

Where stock NVIDIA 580.178.04 avoids #if LINUX_VERSION_CODE guards altogether, we mirror stock directly:

  • .llseek omitted (NULL) across diagnostic.c, gpu_owner.c, uvm_node.c, and rmapi_node.c (×2): matches stock nvidia_fops (nv.c:227) and uvm_fops (uvm.c:1076). Returns -ESPIPE on every kernel version (5.15–7.3+) without referencing the removed no_llseek macro (gone in v6.12).
  • container_of() for struct timer_list in nano_timer_adapter.c: matches stock common/inc/nv-timer.h:39 and works on every kernel version without from_timer / timer_container_of (v6.16) guards.
  • #if defined(MAX_PAGE_ORDER) in rom_fw_adapter.c: matches stock common/inc/nv-linux.h:335 (order > MAX_PAGE_ORDER on ≥6.8, order >= MAX_ORDER on older kernels and distro backports).

Version guards

Symbol Boundary Site
vma->vm_flags const (vm_flags_set/vm_flags_clear) 6.3 (or RHEL_RELEASE_CODE) rmapi_node.c ×4, uvm_node.c ×1, nvidia_rs_drm.c ×2
PCI_IRQ_LEGACY → PCI_IRQ_INTX #ifndef PCI_IRQ_INTX (6.10 & RHEL 9.8) irq_adapter.c ×2 (via NV_RS_PCI_IRQ_INTX)
MODULE_IMPORT_NS (DMA_BUF / "DMA_BUF") 5.16 / RHEL_RELEASE_CODE (ident), 6.13 (string) dmabuf_p2p.c, nvidia_rs_drm.c
hrtimer_init → hrtimer_setup 6.15 nano_timer_adapter.c
class_create(owner, name) → class_create(name); class.devnode const struct device * declarations in device/class.h (6.4 / 6.2; RHEL 9 backports both to 5.14) rmapi_node.c (via NV_RS_CLASS_CREATE_NO_OWNER / NV_RS_CLASS_DEVNODE_CONST_DEV from kernel-open/compat_probes.mk)
fb_is_primary_device() → video_is_primary_device() in <asm/video.h> declaration in asm/video.h (6.9); before it vga_default_device() ga10x_adapter.c (via NV_RS_HAVE_VIDEO_IS_PRIMARY_DEVICE from kernel-open/Kbuild)
pci_resize_resource(..., exclude_bars) declaration in pci.h (6.19, backported to 6.18 stable), else 6.19 / UTS_UBUNTU_RELEASE_ABI pci_adapter.c ×2 (via NV_RS_PCI_RESIZE_EXCLUDE_BARS from kernel-open/Kbuild)
drm_driver.date (field removed) 6.14 nvidia-drm/nvidia_rs_drm.c
<linux/aperture.h> vs <drm/drm_aperture.h> (aperture_remove_conflicting_pci_devices) 6.2 nvidia-drm/nvidia_rs_drm.c (via NV_RS_HAVE_LINUX_APERTURE_H / NV_RS_HAVE_DRM_APERTURE_H)
drm_client_setup (<drm/clients/drm_client_setup.h> / <drm/drm_client_setup.h> vs drm_fbdev_ttm_setup / drm_fbdev_generic_setup) 6.12 / 6.13 nvidia-drm/nvidia_rs_drm.c (via NV_RS_HAVE_DRM_CLIENTS_CLIENT_SETUP_H, etc.)
drm_mode_config_funcs.fb_create & drm_helper_mode_fill_fb_struct info parameter 6.17 nvidia-drm/nvidia_rs_drm.c (via NV_RS_HAVE_DRM_FB_CREATE_FORMAT_INFO)
drm_gem_object_funcs.vmap struct iosys_map / <linux/iosys-map.h> 5.18 nvidia-drm/nvidia_rs_drm.c (via NV_RS_HAVE_DRM_IOSYS_MAP / NV_RS_HAVE_LINUX_IOSYS_MAP_H)
struct drm_atomic_state → struct drm_atomic_commit in the plane / CRTC atomic helper callbacks definition in drm_atomic.h (seen in 7.3) nvidia-drm/nvidia_rs_drm.c ×5 (via NV_RS_HAVE_DRM_ATOMIC_COMMIT from kernel-open/compat_probes.mk)
drm_edid_read_custom / drm_edid_connector_add_modes 6.3 nvidia-drm/nvidia_rs_drm.c (via NV_RS_HAVE_DRM_EDID_READ_CUSTOM)
pin_user_pages(..., vmas) → without vmas declaration in mm.h (6.5), as stock's NV_PIN_USER_PAGES_HAS_ARGS_VMAS rmapi_node.c (via NV_RS_PIN_USER_PAGES_HAS_VMAS from kernel-open/compat_probes.mk)
MAX_ORDER → MAX_PAGE_ORDER #if defined(MAX_PAGE_ORDER) (6.8) rmapi_node.c, rom_fw_adapter.c
dma_resv_reserve_shared / dma_resv_add_{shared,excl}_fence → dma_resv_reserve_fences / dma_resv_add_fence declarations in dma-resv.h (5.19; Ubuntu 5.15 backported dma_resv_reserve_fences independently) nvidia-drm/nvidia_rs_drm.c (via NV_RS_HAVE_DMA_RESV_RESERVE_FENCES / NV_RS_HAVE_DMA_RESV_ADD_FENCE from kernel-open/compat_probes.mk)
dma_fence_ops.use_64bit_seqno → dma_fence_init64 declaration in dma-fence.h (6.17) nvidia-drm/nvidia_rs_drm.c (via NV_RS_HAVE_DMA_FENCE_INIT64 from kernel-open/compat_probes.mk)
  • Host-fixture builds (NV_RS_*_HOST_FIXTURE) do not pull <linux/version.h>. tests/irq-mock/irq_mock.h and tests/rom-fw-mock/rom_fw_mock.h define LINUX_VERSION_CODE 0 and KERNEL_VERSION(a,b,c) so the guards preprocess cleanly on the host-fixture side.

ENDBR / IBT (CONFIG_X86_KERNEL_IBT=y + CONFIG_OBJTOOL_WERROR=y)

  • Stock nv-kernel.o_binary emits endbr64 (f3 0f 1e fa) at indirect-call/vtable entries and omits it on direct-only internal functions.
  • utils.mk auto-detects CONFIG_X86_KERNEL_IBT=y in $(KERNEL_OUTPUT)/.config (overridable via NV_RS_KERNEL_IBT=1 / NV_RS_KERNEL_IBT=0). When enabled on x86_64, RUST_KERNEL_FLAGS adds -Z cf-protection=branch -C jump-tables=no (-C jump-tables=no avoids per-function .rodata.<sym> switch tables that objtool rejects with --werror).
  • Because -Z cf-protection=branch is an unstable rustc flag, utils.mk automatically exports RUSTC_BOOTSTRAP=1 whenever NV_RS_KERNEL_IBT=1. This allows both the pinned stable toolchain in rust-toolchain.toml (1.100.0) and distro-packaged stable rustc (Arch, Gentoo, Fedora, etc.) to emit ENDBR64 prologues without requiring a nightly toolchain.
  • tools/check_kernel_module.py enforces endbr64_at_data_relocation_targets on x86_64 whenever CONFIG_X86_KERNEL_IBT=y, NV_RS_KERNEL_IBT=1, or the built object emits endbr64 entries. NV_RS_KERNEL_IBT=0 suppresses only the config-based trigger, so the object's own endbr64 entry evidence still enforces the rule; the check reports green from the skip only when neither the config nor the object provides evidence. Both symbol and section-symbol relocations are resolved through the ELF tables, not from printed names, and a target passes only when the instruction at the resolved address is endbr64 and the relocation addend is zero; the resolved address is the symbol's value plus the addend, so the same endbr64 is judged twice: measured on one instruction at offset 5, the addend-5 form through the section symbol fails and the addend-0 form through the symbol passes. A target inside a disassembled block fails, but a label inside a function does not: objdump prints each labelled symbol as its own block header, so a label on a mid-function endbr64 is a block entry and passes (measured with addend 0), which is also why duplicate-symbol-prefix.s, whose relocated symbol starts at offset 1, is recorded as an entry pad. The check cannot call that a function entry, and a STT_FUNC boundary rule is not an option (measured locally on the current build, all 205 recorded targets came from symbols that are not STT_FUNC, so such a rule would refuse the current build; report card left untouched (local results should not be committed to the tree)). ARM64 objects are exempt from the x86 endbr64 rule.
  • The pass condition is stricter than objtool's rule, not the same rule. validate_ibt_data_reloc (verified at the v6.12 tag) accepts a data relocation to any instruction it has marked noendbr, accepts an ENDBR instruction without asking whether it is a function entry, and accepts a target it cannot locate as an instruction at all. The checker additionally requires a recorded instruction boundary, endbr64 at the resolved address itself (a block entry as objdump prints it, which for a labelled symbol inside a function is that symbol's own header), addend 0, and endbr64 whatever objtool would have marked it, so a checker failure reads as 'this data pointer is not an endbr64 at offset 0' — objtool can exit 0 on an object the check refuses. The reverse does not hold either, so a green check is not a guarantee that objtool accepts the object: the checker only judges relocations from allocatable, non-executable sections (if not sections[sec][1]&ALLOC or sections[sec][1]&EXEC:continue), while validate_ibt() at the same tag iterates every non-executable section that has a reloc section, skipping only a named list (.discard*, .debug*, .altinstructions, .orc_unwind_ip, __ex_table, …) and nothing in check.c tests SHF_ALLOC at all. Measured on one object with a ret entry relocated from both .rodata and a non-allocatable .note.mine: the checker sees 1 recorded target and refuses that one, and reports nothing about the other; objtool's path warns on both because .note.mine is not in its exclusion list.
  • Module-only checks (GOT relocations, runtime symbols, module name, PCI aliases) belong to default validation, and default validation requires nvidia_rs.ko: --object-only is the only mode that skips them, so fixtures are still assertable without a build while a default run with no module fails instead of reporting green with those checks skipped.
  • The checker honours NV_RS_KERNEL_IBT=0 as an explicit override, the same override utils.mk documents, so both sides of the IBT rule are assertable without a host kernel config. test_gate_cases.py sets NV_RS_KERNEL_IBT=1 for its expectations instead of reading the host's config, and asserts the disabled side separately: a recorded target that is not an entry pad with the ENDBR rule green means the rule was skipped, not that the target passed.
  • Identity is taken from the ELF tables, not from printed names: the section header table, the symbol table and the relocation entries give the target section, the symbol's value and the addend, so a printed string of exactly 256 characters that is also another entity's truncation decides nothing — a relocation to the entity whose name is longer is judged against that entity, not against the shorter one that shares the printed prefix. objdump is still the source of instruction boundaries, so its disassembly has to be attributed to a section, and a header whose printed form belongs to two sections cannot be attributed: the prefix is recorded as ambiguous and every target in it is refused instead of judged against whichever entity was disassembled last. Which names arrive truncated is implementation-dependent (readelf 2.47 here truncates names from the section string table, objdump prints them in full, llvm-readelf 23 truncates neither), so test_gate_cases.py takes the shared-prefix case's expectation from the printing objdump actually showed and records it; no name on the current object shares a prefix, so the resolved branch is the one that runs.
  • The export set is built from the symbol table and counts only defined entries: st_shndx == SHN_UNDEF means the name is referenced, not exported, so an object that references all nine protocol names without defining any fails protocol_exports_present rather than passing (the nm --defined-only check it replaced rejected this case, and --object-only has no module undefined-symbol check to catch it). Undefined symbols stay in the symbol table for relocation analysis, so test_gate_cases.py asserts both sides with undefined-exports.s and defined-exports.s.
  • A section name that appears twice in the section header table is not an identity either: it is recorded as a duplicate, every section sharing it is unattributable, and a relocation into one of them is refused instead of judged against whichever section objdump happened to disassemble first. GNU as merges sections with the same name (it warns "ignoring changed section attributes"), so the shape reaches the checker only through a linker that keeps two output sections under one name; test_gate_cases.py builds it with ld -r and counts duplicates separately from the shared-prefix counter. The current object has no duplicate section names.
  • Entry evidence is recorded whether or not the disassembly can be attributed to a section, so an endbr64 pad inside a duplicate-name section still enables the object-based IBT fallback. Before this, the only entry pad in a fixture whose name could not be attributed was lost, enforcement then came from the host config alone, and a data pointer to an empty section passed both checks.
  • Extended section numbering is read from the escape fields rather than from the header counters: when e_shnum is SHN_UNDEF the real count is in sh_size of header 0, and when e_shstrndx is an escape value the real string table index is in sh_link of header 0 (spec Table 3.5, verified at gabi.xinuos.com/elf/03-sheader.html); a symbol whose st_shndx is SHN_XINDEX gets its index from the associated SHT_SYMTAB_SHNDX (type 18) section. Before this the checker saw no sections on such an object and reported green over an empty set although both data relocations pointed at a ret entry. test_gate_cases.py builds the object itself because as and ld cannot emit it. If the escape value has no associated table objdump refuses the file, so the run exits nonzero instead of passing.
  • A raw st_shndx in the reserved range SHN_LORESERVE..0xfffe is a special value, not a section reference, so it is skipped before the section-bounds check; SHN_XINDEX can still resolve to a real section index that is numerically inside that range. In the built object 65521 is both SHN_ABS's value and a real section, so the two cases are distinguishable only by reading the value as written. Before this the checker stored the symbol's index only after expansion, so the absolute symbol resolved through the section header table at 65521: measured, the run reported green with 2 recorded targets, one of them a symbol that names no section. The export set keys on the raw value, so absolute protocol names are still counted as defined exports. test_gate_cases.py builds the object; the symbol over the code needs a size that spans the section, otherwise objdump prints the whole section as one undecodable blob instead of the endbr64 entry (measured with symbol size 1, 5 and 14).
  • Code symbols that share an address are recorded through the symbol table, because objdump prints only one symbol per address. A data relocation naming an alias of a symbol objdump already displayed had nothing to match against and was dropped without being recorded, so the ENDBR rule passed over an empty set. test_gate_cases.py asserts both alias targets are recorded: the one at the entry is an entry pad, the one inside a multi-byte instruction is recorded as a target that is not one. The entry flag is the symbol's own address (addend 0), not objdump's block header, so an alias is an entry when the symbol it names is one.