Files
nvdriver/utils.mk
Eric Hartford c553930fd7 wave 1: kernel/ARM64/Clang/DKMS compat, IOMMU/PCI lifecycle, and RMAPI/UVM isolation
Proactive 100% parity Wave 1 (REA-grounded vs stock 580.178.04):
- Kernel/build compat: Kbuild header probes for timer_delete_sync, vm_flags_set,
  vma_flags_set_word; remove broken UTS_UBUNTU_RELEASE_ABI guard on
  pci_resize_resource; guard x86 set_memory_uc/wb under CONFIG_X86; remove
  illegal ARM64 dma_sync_single_* on coherent DMA; gate nvidia_rs_drm on
  CONFIG_DRM; default LD=ld.lld/OBJCOPY=llvm-objcopy under LLVM=1; fix dkms.conf
  (KDIR support, all 4 modules, 0.2.0) and install.sh (all 4 modules, non-0000
  PCI domains, KREL override).
- IOMMU & PCI lifecycle: switch gsp_route error notifier to per-device DMA
  (nv_rs_rmapi_os_page_dma); add PCI .shutdown (pci_clear_master + udelay(1))
  and AER .err_handler; keep freed rmapi_allocs on list until users==0 for
  hot-unplug DMA teardown; drain nv_rs_uvm_cpu_dma_ht on exit; lock BAR0 fill
  under p->access; raise MAX_BRIDGE_GPUS to 32.
- Security & isolation (REA _nv000655rm / _nv000663rm): enforce cross-process
  share policy on NV_ESC_RM_DUP_OBJECT & NV_ESC_RM_SHARE; refcount shared memory
  backings on release (eliminating dup UAF); scope UVM ManagedFaultMapper by
  faulting GPU & SysmemPageTree.owner; pass real task_tgid_vnr into Caller.pid.
2026-12-01 16:16:09 +00:00

71 lines
4.3 KiB
Makefile

# Paths may be overridden for an explicit kernel/header tree and staging area.
KERNEL_UNAME ?= $(shell uname -r)
KERNEL_SOURCES ?= $(or $(KDIR),$(SYSSRC),/lib/modules/$(KERNEL_UNAME)/build)
KERNEL_OUTPUT ?= $(if $(SYSOUT),$(SYSOUT),$(KERNEL_SOURCES))
# A kernel built with clang (CONFIG_CC_IS_CLANG=y, e.g. CachyOS) hands clang-only flags to
# external module builds, so gcc cannot compile the C shims. Default to LLVM=1 for such kernels;
# an explicit LLVM= on the command line or in the environment is left alone.
ifeq ($(origin LLVM),undefined)
ifneq ($(shell grep -q '^CONFIG_CC_IS_CLANG=y$$' $(KERNEL_OUTPUT)/.config 2>/dev/null && echo y),)
export LLVM := 1
endif
endif
ifeq ($(LLVM),1)
ifeq ($(origin LD),default)
LD := $(or $(shell command -v ld.lld 2>/dev/null),ld)
endif
OBJCOPY ?= $(or $(shell command -v llvm-objcopy 2>/dev/null),objcopy)
else
OBJCOPY ?= objcopy
endif
# Resolve rustc via rustup (including ~/.cargo/bin when non-interactive PATH omits it),
# falling back to ~/.cargo/bin/rustc or PATH rustc. Override with RUSTC=... as before.
RUSTC ?= $(or $(shell PATH="$(HOME)/.cargo/bin:$$PATH" rustup which rustc 2>/dev/null),$(wildcard $(HOME)/.cargo/bin/rustc),$(shell command -v rustc))
NV_RS_ARCH ?= $(if $(ARCH),$(ARCH),$(shell uname -m))
ifneq ($(filter arm64 aarch64,$(NV_RS_ARCH)),)
RUST_KERNEL_TARGET := aarch64-unknown-none
# ARM64 kernel target (RK3588 / Ampere Altra / Apple Silicon Linux): no NEON/FP in kernel mode.
RUST_KERNEL_FLAGS := --edition=2021 --crate-type=lib --target=$(RUST_KERNEL_TARGET) \
--emit=obj -C opt-level=2 -C panic=abort -C relocation-model=static \
-C code-model=small -C target-feature=-neon,-fp-armv8 -C force-frame-pointers=yes \
-C overflow-checks=yes -C debuginfo=1
else
RUST_KERNEL_TARGET := x86_64-unknown-none
# Kernel target supplies a soft-float, no-SSE core; explicit flags document ABI.
RUST_KERNEL_FLAGS := --edition=2021 --crate-type=lib --target=$(RUST_KERNEL_TARGET) \
--emit=obj -C opt-level=2 -C panic=abort -C relocation-model=static \
-C code-model=kernel -C no-redzone=yes -C force-frame-pointers=yes \
-C overflow-checks=yes -C debuginfo=1
# Auto-enable IBT flags when the target kernel has CONFIG_X86_KERNEL_IBT=y (override with NV_RS_KERNEL_IBT=0/1).
# -Z cf-protection=branch emits ENDBR64 on indirect-call targets (matching stock nv-kernel.o_binary);
# -C jump-tables=no avoids .rodata.<fn> switch tables that objtool rejects with CONFIG_OBJTOOL_WERROR=y.
# Export RUSTC_BOOTSTRAP=1 so stable/distro rustc (and rust-toolchain.toml 1.100.0) accepts
# -Z cf-protection=branch without requiring users to install a nightly toolchain.
NV_RS_KERNEL_IBT ?= $(if $(shell grep -q '^CONFIG_X86_KERNEL_IBT=y$$' $(KERNEL_OUTPUT)/.config 2>/dev/null && echo y),1,0)
ifeq ($(NV_RS_KERNEL_IBT),1)
RUST_KERNEL_FLAGS += -Z cf-protection=branch -C jump-tables=no
export RUSTC_BOOTSTRAP := 1
endif
endif
# Matching580 conftest product selectors: ANY nonempty value enables a role.
# Export passes both inherited environment and explicit `make NAME=value` as data. No CPUID/Xen detection.
export VGX_BUILD VGX_KVM_BUILD VGX_DEVICE_VM_BUILD
RUST_BUILD_PRODUCT_RECEIPT := $(ROOT)/target/build-product/config.json
# GNU Make's $(shell) does not receive newly exported command-line variables.
# Single-quote each resolved Make value, including literal quotes/dollars/newlines.
nv_rs_shell_quote = '$(subst ','"'"',$(1))'
RUST_BUILD_PRODUCT_FLAGS := $(shell VGX_BUILD=$(call nv_rs_shell_quote,$(VGX_BUILD)) VGX_KVM_BUILD=$(call nv_rs_shell_quote,$(VGX_KVM_BUILD)) VGX_DEVICE_VM_BUILD=$(call nv_rs_shell_quote,$(VGX_DEVICE_VM_BUILD)) python3 $(ROOT)/tools/timer-timeout-build-product.py --receipt $(RUST_BUILD_PRODUCT_RECEIPT))
ifeq ($(strip $(RUST_BUILD_PRODUCT_FLAGS)),)
$(error Cannot resolve Rust build-product configuration)
endif
RUST_KERNEL_FLAGS += $(RUST_BUILD_PRODUCT_FLAGS)
# Explicit absolute targets work before OUT is assigned by src/nvidia/Makefile.
# EXTRA_PREREQS preserves the original first prerequisite used by rustc $<.
# A changed product receipt invalidates every Rust artifact using these cfgs.
NV_RS_PRIOR_DEFAULT_GOAL := $(.DEFAULT_GOAL)
$(ROOT)/kernel-open/nvidia/libnv_rs_abi.rlib \
$(ROOT)/kernel-open/nvidia/libnv_rs_core.rlib \
$(ROOT)/kernel-open/nvidia/libnv_rs_kernel.a: .EXTRA_PREREQS := $(RUST_BUILD_PRODUCT_RECEIPT)
.DEFAULT_GOAL := $(NV_RS_PRIOR_DEFAULT_GOAL)