mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
GSP_SET_SYSTEM_INFO went to GSP-RM with acpiMethodData and bIsPrimary left zero. On an Optimus laptop nouveau (r535/r570_gsp_acpi_info) and OpenRM fill them from the GPU's ACPI node: the _DOD display list, the JT _DSM capabilities and the NVOP Optimus capabilities. Do the same, at the 580.178.04 GspSystemInfo offsets (acpiMethodData 0xa0..0x344, bIsPrimary 0x380), and log what was found: ga10x: ACPI sysinfo: primary=0 dod=0(n=1) jt=0(caps=20016003) opt=0(caps=19000059) This did not by itself fix the GA107 boot (the sysmem flush page did, programmed since #145), and it has not been tested in isolation; it brings the system info in line with what the other drivers send on Optimus systems. Only x86 with CONFIG_ACPI evaluates the methods. bIsPrimary comes from video_is_primary_device() where <asm/video.h> has it (6.9+, probed in Kbuild) and from the VGA arbiter's default device before that. Also report an I/O BAR to GSP-RM only when PCI_COMMAND_IO is enabled: the GA107 exposes an I/O BAR that the platform leaves disabled.
12 KiB
12 KiB
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:
.llseekomitted (NULL) acrossdiagnostic.c,gpu_owner.c,uvm_node.c, andrmapi_node.c(×2): matches stocknvidia_fops(nv.c:227) anduvm_fops(uvm.c:1076). Returns-ESPIPEon every kernel version (5.15–7.3+) without referencing the removedno_llseekmacro (gone in v6.12).container_of()forstruct timer_listinnano_timer_adapter.c: matches stockcommon/inc/nv-timer.h:39and works on every kernel version withoutfrom_timer/timer_container_of(v6.16) guards.#if defined(MAX_PAGE_ORDER)inrom_fw_adapter.c: matches stockcommon/inc/nv-linux.h:335(order > MAX_PAGE_ORDERon ≥6.8,order >= MAX_ORDERon 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 |
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 |
hrtimer_init → hrtimer_setup |
6.15 | nano_timer_adapter.c |
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 |
- Host-fixture builds (
NV_RS_*_HOST_FIXTURE) do not pull<linux/version.h>.tests/irq-mock/irq_mock.handtests/rom-fw-mock/rom_fw_mock.hdefineLINUX_VERSION_CODE 0andKERNEL_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_binaryemitsendbr64(f3 0f 1e fa) at indirect-call/vtable entries and omits it on direct-only internal functions. utils.mkauto-detectsCONFIG_X86_KERNEL_IBT=yin$(KERNEL_OUTPUT)/.config(overridable viaNV_RS_KERNEL_IBT=1/NV_RS_KERNEL_IBT=0). When enabled onx86_64,RUST_KERNEL_FLAGSadds-Z cf-protection=branch -C jump-tables=no(-C jump-tables=noavoids per-function.rodata.<sym>switch tables that objtool rejects with--werror).- Because
-Z cf-protection=branchis an unstablerustcflag,utils.mkautomatically exportsRUSTC_BOOTSTRAP=1wheneverNV_RS_KERNEL_IBT=1. This allows both the pinned stable toolchain inrust-toolchain.toml(1.100.0) and distro-packaged stablerustc(Arch, Gentoo, Fedora, etc.) to emitENDBR64prologues without requiring a nightly toolchain. tools/check_kernel_module.pyenforcesendbr64_at_data_relocation_targetsonx86_64wheneverCONFIG_X86_KERNEL_IBT=y,NV_RS_KERNEL_IBT=1, or the built object emitsendbr64entries.NV_RS_KERNEL_IBT=0suppresses only the config-based trigger, so the object's ownendbr64entry 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 isendbr64and the relocation addend is zero; the resolved address is the symbol's value plus the addend, so the sameendbr64is 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-functionendbr64is a block entry and passes (measured with addend 0), which is also whyduplicate-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 aSTT_FUNCboundary rule is not an option (measured locally on the current build, all 205 recorded targets came from symbols that are notSTT_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 x86endbr64rule.- 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 markednoendbr, accepts anENDBRinstruction 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,endbr64at 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, andendbr64whatever objtool would have marked it, so a checker failure reads as 'this data pointer is not anendbr64at 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), whilevalidate_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 incheck.ctestsSHF_ALLOCat all. Measured on one object with aretentry relocated from both.rodataand 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.mineis 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-onlyis 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=0as an explicit override, the same overrideutils.mkdocuments, so both sides of the IBT rule are assertable without a host kernel config.test_gate_cases.pysets 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.pytakes 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_UNDEFmeans the name is referenced, not exported, so an object that references all nine protocol names without defining any failsprotocol_exports_presentrather than passing (thenm --defined-onlycheck it replaced rejected this case, and--object-onlyhas no module undefined-symbol check to catch it). Undefined symbols stay in the symbol table for relocation analysis, sotest_gate_cases.pyasserts both sides withundefined-exports.sanddefined-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.pybuilds it withld -rand 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
endbr64pad 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_shnumisSHN_UNDEFthe real count is insh_sizeof header 0, and whene_shstrndxis an escape value the real string table index is insh_linkof header 0 (spec Table 3.5, verified at gabi.xinuos.com/elf/03-sheader.html); a symbol whosest_shndxisSHN_XINDEXgets its index from the associatedSHT_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 aretentry.test_gate_cases.pybuilds the object itself becauseasandldcannot 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_shndxin the reserved rangeSHN_LORESERVE..0xfffeis a special value, not a section reference, so it is skipped before the section-bounds check;SHN_XINDEXcan still resolve to a real section index that is numerically inside that range. In the built object 65521 is bothSHN_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.pybuilds 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 theendbr64entry (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.pyasserts 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.