Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
bd64646
conftest: Fix drm_connector_helper_funcs_mode_valid_has_const_mode_arg
minipli-oss Nov 20, 2025
9989cd1
nvidia: Fix nvswitch_task_dispatch() prototype
minipli-oss Nov 20, 2025
ac0594d
nvidia: Fix TMR_CALLBACK_FUNCTION type
minipli-oss Mar 4, 2026
639c3ea
nvidia: maxwell - Fix aperture type
minipli-oss Feb 5, 2026
40cfa5e
nvidia: Fix stack info leak in tmrCtrlCmdEventCreate()
minipli-oss Mar 4, 2026
02148e7
nvidia: Fix cleaning of nv_compiler.h
minipli-oss Mar 11, 2026
e530026
nvidia-drm: Fix prototype of nv_drm_connector_mode_valid()
minipli-oss Nov 20, 2025
902bc80
nvidia-uvm: Statically initialize g_exported_uvm_events
minipli-oss Nov 20, 2025
4bed898
nvidia-modeset: Fix prototype of NVEvoSubDevRec.scanLockState()
minipli-oss Feb 5, 2026
533137c
src/: remove system header dependencies
minipli-oss Nov 27, 2025
6ab548b
nvswitch: use designated initializers
minipli-oss Mar 12, 2026
facf074
nvidia-3d: use designated initializers
Feb 5, 2026
d00c39b
nvidia-modeset: use designated initializers
Feb 5, 2026
af7401d
nvidia: gpu/mmu - use designated initializers
minipli-oss Mar 12, 2026
917321a
nvidia: make GPUHWREG use flexible arrays
minipli-oss Mar 18, 2026
dbd5813
x86emu: drop dependency on <stddef.h>
minipli-oss Nov 27, 2025
f0d6583
kernel-open/Kbuild: fix potential duplicated CFLAGS
minipli-oss Feb 26, 2026
f03a900
kernel-open/Kbuild: CFLAGS_REMOVE support
minipli-oss Feb 10, 2026
ea39727
kernel-open/Kbuild: NVIDSTRING support
minipli-oss Feb 10, 2026
5c10301
kernel-open/Kbuild: LDFLAGS and OBJCOPYFLAGS support
minipli-oss Feb 26, 2026
fbd346b
kernel-open/Kbuild: stub module support
minipli-oss Feb 10, 2026
42f5e37
kernel-open: introduce module preparation step
minipli-oss Feb 10, 2026
f4f7458
src/nvidia: move CFLAGS to defs.mk
minipli-oss Dec 9, 2025
574e1b4
src/nvidia: move LINKER_SCRIPT and EXPORTS_LINK_COMMAND to srcs.mk
minipli-oss Feb 26, 2026
12a5c54
src/nvidia: preliminary kbuild support
minipli-oss Feb 10, 2026
fd20ccf
src/nvidia: provide stdatomic.h header for freestanding gcc builds
minipli-oss May 22, 2026
008271f
kernel-open/nvidia: Kbuild support
minipli-oss Feb 10, 2026
27b6849
kernel-open: pass C++ compiler variable to sub-make
minipli-oss Feb 10, 2026
bf17064
Make nv-stddef.h C++-aware and use it in nvdp-host.cpp
minipli-oss Feb 9, 2026
e193642
nvidia-3d: always define XZ_INTERNAL_CRC32
minipli-oss Feb 9, 2026
90b6dfc
src/nvidia-modeset: move CFLAGS to defs.mk, shaders to srcs.mk
minipli-oss Feb 10, 2026
70a0f22
src/nvidia-modeset: preliminary kbuild support
minipli-oss Feb 10, 2026
1ef0199
src/nvidia-modeset: collapse C++ comdat sections
minipli-oss Mar 11, 2026
4680546
kernel-open/nvidia-modeset: Kbuild support
minipli-oss Feb 10, 2026
590b3e6
Experimental support for Linux's kbuild
minipli-oss Dec 16, 2025
4e9a63a
nvidia-modeset: avoid RANDSTRUCT hack for kbuild builds
minipli-oss May 22, 2026
81552f6
conftest: Add test for vm_operations_struct.access() 'len' type
minipli-oss Nov 20, 2025
780824d
conftest: Add test for grsecurity's atomic*_unchecked_t
minipli-oss Dec 11, 2025
f082e47
nvidia-uvm: make *ops union compatible with grsecurity
minipli-oss Nov 20, 2025
b09fc43
kernel-open: mark nv_kthread_q related types nolocal for grsecurity c…
minipli-oss Dec 10, 2025
3160cd3
src/common: make "HAL" types compatible with grsecurity
minipli-oss Feb 12, 2026
aa193e2
src/nvidia-modeset: disable certain gcc plugins for C++ code
minipli-oss Feb 12, 2026
012354f
src/nvidia: disable --gc-sections for kbuild
minipli-oss Feb 27, 2026
98acab3
src/nvidia: make "IFACES" types compatible with grsecurity
minipli-oss Feb 12, 2026
f5cb484
src/nvidia: make nv_work_item_t compatible with grsecurity
minipli-oss Feb 12, 2026
07ce61b
src/nvidia: make MMU_WALK_CALLBACKS compatible with grsecurity
minipli-oss Feb 12, 2026
eabd46a
src/nvidia: make callback wrapping of tmrCtrlCmdEventCreate() grsec c…
minipli-oss Mar 4, 2026
08ea2f9
x86emu: constify function pointer arguments of setup functions
minipli-oss May 27, 2026
a22c63a
src/nvidia: nvalloc - constify pioFuncs and memFuncs
minipli-oss Feb 12, 2026
a93fe18
src/nvidia: mark THREAD_STATE_NODE nolocal for grsecurity compatibility
minipli-oss Mar 18, 2026
d6f9f64
src/nvidia: support mangling sources with coccinelle
minipli-oss Feb 12, 2026
715461e
fix_nvoc_dtor.cocci: fix NVOC_DYNAMIC_DTOR CFI violations
minipli-oss Nov 27, 2025
3782f27
fix_nvoc_pfunc*.cocci: fix bad pFunc fprt casts
minipli-oss Dec 5, 2025
8c4c121
fix_*_init.cocci: fix missing desgnated inits
minipli-oss Mar 12, 2026
b4a808d
src/nvidia: kbuild - hook up cocci scripts
minipli-oss Dec 16, 2025
364f117
XXX: nvidia: comment about memory leak
minipli-oss Mar 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@
# To install the build kernel modules: run (as root) `make modules_install`
###########################################################################

# Experimental use of the Linux kernel's kbuild system
USE_KBUILD ?= 0
export USE_KBUILD

###########################################################################
# rules
###########################################################################

.PHONY: all
all: modules

ifneq ($(USE_KBUILD),1)

###########################################################################
# variables
###########################################################################
Expand All @@ -16,15 +29,8 @@ nv_kernel_o_binary = kernel-open/nvidia/nv-kernel.o_binary
nv_modeset_kernel_o = src/nvidia-modeset/$(OUTPUTDIR)/nv-modeset-kernel.o
nv_modeset_kernel_o_binary = kernel-open/nvidia-modeset/nv-modeset-kernel.o_binary

###########################################################################
# rules
###########################################################################

include utils.mk

.PHONY: all
all: modules

###########################################################################
# nv-kernel.o is the OS agnostic portion of nvidia.ko
###########################################################################
Expand All @@ -48,22 +54,31 @@ $(nv_modeset_kernel_o):
$(nv_modeset_kernel_o_binary): $(nv_modeset_kernel_o)
cd $(dir $@) && ln -sf ../../$^ $(notdir $@)

# Make the OS agnostic binaries a prerequisite of the modules target
modules: $(nv_kernel_o_binary) $(nv_modeset_kernel_o_binary)
endif

###########################################################################
# After the OS agnostic portions are built, descend into kernel-open/ and build
# the kernel modules with kbuild.
###########################################################################

.PHONY: modules
modules: $(nv_kernel_o_binary) $(nv_modeset_kernel_o_binary)
modules:
ifeq ($(USE_KBUILD),1)
# create nv-kernel.o and nv-modeset-kernel.o by building stub modules -- a
# required hack to overcome kbuild limitations regarding the maximum number
# of object files to link into a module.
$(MAKE) -C kernel-open modules NV_PREPARE_ONLY=1
endif
$(MAKE) -C kernel-open modules

###########################################################################
# Install the built kernel modules using kbuild.
###########################################################################

.PHONY: modules_install
modules_install:
modules_install: modules
$(MAKE) -C kernel-open modules_install

###########################################################################
Expand All @@ -75,11 +90,15 @@ clean: nvidia.clean nvidia-modeset.clean kernel-open.clean

.PHONY: nvidia.clean
nvidia.clean:
ifneq ($(USE_KBUILD),1)
$(MAKE) -C src/nvidia clean
endif

.PHONY: nvidia-modeset.clean
nvidia-modeset.clean:
ifneq ($(USE_KBUILD),1)
$(MAKE) -C src/nvidia-modeset clean
endif

.PHONY: kernel-open.clean
kernel-open.clean:
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ DEBUG - Set this to "1" to build the kernel modules as debug. By default, the
build compiles without debugging information. This also enables
various debug log messages in the kernel modules.

USE_KBUILD - Set this to "1" to build all sources using the linux kernel build
system. This is needed to support features like RANDSTRUCT, kCFI or
grsecurity kernels.

These variables can be set on the make command line. E.g.,

make modules -j$(nproc) NV_VERBOSE=1
Expand Down
121 changes: 118 additions & 3 deletions kernel-open/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,95 @@ NV_BUILD_TYPE ?= release
#
ASSIGN_PER_OBJ_CFLAGS = \
$(foreach _cflags_variable, \
$(notdir $(1)) $(1), \
$(sort $(notdir $(1)) $(1)), \
$(eval $(addprefix CFLAGS_,$(_cflags_variable)) += $(2)))

#
# As ASSIGN_PER_OBJ_CFLAGS, just for per-object CFLAGS_REMOVE.
#
ASSIGN_PER_OBJ_CFLAGS_REMOVE = \
$(foreach _cflags_variable, \
$(sort $(notdir $(1)) $(1)), \
$(eval $(addprefix CFLAGS_REMOVE_,$(_cflags_variable)) += $(2)))

#
# As ASSIGN_PER_OBJ_CFLAGS, just for per-object LDFLAGS.
#
ASSIGN_PER_OBJ_LDFLAGS = \
$(foreach _ldflags_variable, \
$(sort $(notdir $(1)) $(1)), \
$(eval $(addprefix LDFLAGS_,$(_ldflags_variable)) += $(2)))

#
# As ASSIGN_PER_OBJ_CFLAGS, just for per-object OBJCOPYFLAGS.
#
ASSIGN_PER_OBJ_OBJCOPYFLAGS = \
$(foreach _objcopyflags_variable, \
$(sort $(notdir $(1)) $(1)i), \
$(eval $(addprefix OBJCOPYFLAGS_,$(_objcopyflags_variable)) += $(2)))


#
# Define rule for generating a source file containing identification information
# for the build.
#
# $(1) string name
# $(2) module name
# $(3) prerequisite object files
##############################################################################

NV_BUILD_USER ?= $(shell whoami)
NV_BUILD_HOST ?= $(shell hostname)

ifndef TARGET_OS
TARGET_OS := $(shell uname)
endif

ifndef TARGET_ARCH
ifneq ($(TARGET_OS),SunOS)
TARGET_ARCH := $(shell uname -m)
else
TARGET_ARCH := $(shell isainfo -n)
endif
TARGET_ARCH := $(subst i386,x86,$(TARGET_ARCH))
TARGET_ARCH := $(subst i486,x86,$(TARGET_ARCH))
TARGET_ARCH := $(subst i586,x86,$(TARGET_ARCH))
TARGET_ARCH := $(subst i686,x86,$(TARGET_ARCH))
TARGET_ARCH := $(subst amd64,x86_64,$(TARGET_ARCH))
endif

DATE ?= date

NVIDSTRING ?= g_nvid_string.c

ifeq ($(NV_BUILD_TYPE),debug)
NVIDSTRING_BUILD_TYPE_STRING = Debug Build
else ifeq ($(NV_BUILD_TYPE),develop)
NVIDSTRING_BUILD_TYPE_STRING = Develop Build
else ifeq ($(NV_BUILD_TYPE),release)
NVIDSTRING_BUILD_TYPE_STRING = Release Build
else
NVIDSTRING_BUILD_TYPE_STRING = Custom '$(NV_BUILD_TYPE)' Build
endif

# NV_VERSION_STRING is set as preprocessor define
NVIDIA_NVID_VERSION := \"NV_VERSION_STRING\"

define GENERATE_NVIDSTRING
$(1)_BUILD_NVID := NVIDIA $$(strip $(2)) for $$(TARGET_ARCH) $$(NVIDIA_NVID_VERSION)
$(1)_BUILD_NVID := $$($$(strip $(1))_BUILD_NVID) $$(NVIDSTRING_BUILD_TYPE_STRING)
ifneq ($$(NVIDIA_NVID_EXTRA),)
$(1)_BUILD_NVID := $$($$(strip $(1))_BUILD_NVID) $$(NVIDIA_NVID_EXTRA)
endif
$(1)_BUILD_NVID := $$($$(strip $(1))_BUILD_NVID) ($$(NV_BUILD_USER)@$$(NV_BUILD_HOST))
# g_nvid_string.c depends on all objects except g_nvid_string.o, and version.mk
# $(NVIDSTRING) evaluated early, to allow reusing it
$$(obj)/$(NVIDSTRING): $$(adprefix $$(obj)/,$$(filter-out $(NVIDSTRING:.c=.o), $(3))) $$(VERSION_MK)
@mkdir -p $$(dir $$@)
@echo "const char $(1)[] = \"nvidia id: $$($$(strip $(1))_BUILD_NVID) `$$(DATE)`\";" > $$@
@echo "const char *const p$$(strip $(1)) = $(1) + 11;" >> $$@;
endef


#
# Include the specifics of the individual NVIDIA kernel modules.
Expand Down Expand Up @@ -70,13 +156,42 @@ endif
quiet_cmd_symlink = SYMLINK $@
cmd_symlink = ln -sf $(abspath $<) $@

#
# Command to neuter .modinfo section for stub modules which are our hacky
# attempt to make kbuild support nested compound objects.
#
# Intended usage:
#
# # stub module
# obj-m += nv-kernel.stub.o
# nv-kernel.stub-y := ...
#
# # real module wanting to make use of nv-kernel.o
# obj-m += ndidia.o
# nvidia-y += nv-kernel.clean.o ...
#

$(foreach _module, $(NV_KERNEL_MODULES), \
$(eval include $(src)/$(_module)/$(_module).Kbuild))
MOD_STUB := common/mod_stub.o

# not really needed, but to have conftest be the very first
NV_OBJECTS_DEPEND_ON_CONFTEST += $(MOD_STUB)

$(obj)/%.clean.o: OBJCOPYFLAGS += --rename-section .modinfo=.discard.modinfo
$(obj)/%.clean.o: $(obj)/%.stub.o FORCE
$(call if_changed,objcopy)

# early flags, which may be filtered for USE_KBUILD=1 builds
ccflags-y += -I$(src)/common/inc
ccflags-y += -I$(src)

ifeq ($(USE_KBUILD),1)
ccflags-y += -DNV_USE_KBUILD
endif

$(foreach _module, $(NV_KERNEL_MODULES), \
$(eval include $(src)/$(_module)/$(_module).Kbuild))


ccflags-y += -Wall $(DEFINES) $(INCLUDES) -Wno-cast-qual -Wno-format-extra-args
ccflags-y += -D__KERNEL__ -DMODULE -DNVRM
ccflags-y += -DNV_VERSION_STRING=\"610.43.02\"
Expand Down
12 changes: 11 additions & 1 deletion kernel-open/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ else
from CONFIG_CC_VERSION_TEXT in the kernel configuration.)
else
CC=$(cc_version_text)
CXX=$(subst cc,++,$(cc_version_text))
endif
endif
endif

CC ?= cc
LD ?= ld
CXX ?= c++
OBJDUMP ?= objdump

ifndef ARCH
Expand Down Expand Up @@ -107,12 +109,20 @@ else
KBUILD_PARAMS += NV_KERNEL_MODULES="$(NV_KERNEL_MODULES)"
KBUILD_PARAMS += INSTALL_MOD_DIR="$(INSTALL_MOD_DIR)"
KBUILD_PARAMS += NV_SPECTRE_V2=$(SPECTRE_V2_RETPOLINE)
ifeq ($(USE_KBUILD),1)
KBUILD_PARAMS += NV_PREPARE_ONLY=$(NV_PREPARE_ONLY)
ifeq ($(NV_PREPARE_ONLY),1)
KBUILD_PARAMS += KBUILD_MODPOST_NOFINAL=1
KBUILD_PARAMS += MODPOST=/bin/true
KBUILD_PARAMS += objtool-enabled=
endif
endif

export ORIG_PAHOLE := $(PAHOLE)

.PHONY: modules module clean clean_conftest modules_install
modules clean modules_install:
@$(MAKE) "LD=$(LD)" "CC=$(CC)" "OBJDUMP=$(OBJDUMP)" \
@$(MAKE) "LD=$(LD)" "CC=$(CC)" "CXX=$(CXX)" "OBJDUMP=$(OBJDUMP)" \
PAHOLE=$(CURDIR)/pahole.sh $(KBUILD_PARAMS) $@
@if [ "$@" = "modules" ]; then \
for module in $(NV_KERNEL_MODULES); do \
Expand Down
5 changes: 3 additions & 2 deletions kernel-open/common/inc/nv-kthread-q-os.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <linux/semaphore.h>

#include "conftest.h"
#include "nvtypes.h"

struct nv_kthread_q
{
Expand All @@ -45,14 +46,14 @@ struct nv_kthread_q
struct task_struct *q_kthread;

bool is_unload_flush_ongoing;
};
} __nolocal;

struct nv_kthread_q_item
{
struct list_head q_list_node;
nv_q_func_t function_to_run;
void *function_args;
};
} __nolocal;


#ifndef NUMA_NO_NODE
Expand Down
6 changes: 6 additions & 0 deletions kernel-open/common/inc/nv-linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
#include "nv-chardev-numbers.h"
#include "nv-platform.h"

#ifndef NV_HAVE_ATOMIC_UNCHECKED_T
#define atomic_unchecked_t atomic_t
#define atomic64_unchecked_t atomic64_t
#define atomic_long_unchecked_t atomic_long_t
#endif

#ifndef AUTOCONF_INCLUDED
#if defined(NV_GENERATED_AUTOCONF_H_PRESENT)
#include <generated/autoconf.h>
Expand Down
7 changes: 5 additions & 2 deletions kernel-open/common/inc/nvkms-kapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -616,13 +616,16 @@ struct NvKmsKapiGpuInfo {
* Linux kernel options CONFIG_RANDSTRUCT_* randomize structs that are composed
* entirely of function pointers, but can only control struct layout for sources
* built by kbuild. NvKmsKapiCallbacks is shared between kbuild-built
* nvidia-drm.ko, and the "OS-agnostic" portions of nvidia-modeset.ko (not built
* by kbuild). Add a _padding member to disable struct randomization.
* nvidia-drm.ko, and the "OS-agnostic" portions of nvidia-modeset.ko (which
* may or may be not built by kbuild). Add a _padding member to disable struct
* randomization if it's not.
*
* Refer to https://github.com/NVIDIA/open-gpu-kernel-modules/issues/1033
*/
struct NvKmsKapiCallbacks {
#ifndef NV_USE_KBUILD
int _padding;
#endif
void (*suspendResume)(NvBool suspend);
void (*remove)(NvU32 gpuId);
void (*probe)(const struct NvKmsKapiGpuInfo *gpu_info);
Expand Down
14 changes: 14 additions & 0 deletions kernel-open/common/inc/nvtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,20 @@ typedef struct
#define NV_ATTRIBUTE_UNUSED
#endif

// grsecurity compatibility
#ifndef __no_const
#define __no_const
#endif
#ifndef __do_const
#define __do_const
#endif
#ifndef __mutable_const
#define __mutable_const
#endif
#ifndef __nolocal
#define __nolocal
#endif

#if defined(_MSC_VER)

#if _MSC_VER >= 1310
Expand Down
4 changes: 4 additions & 0 deletions kernel-open/common/mod_stub.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Stub module fragment for emulated nested compound object kbuild support */
#include <linux/module.h>

MODULE_LICENSE("Dual MIT/GPL");
Loading