Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
854a06b
conftest: Fix drm_connector_helper_funcs_mode_valid_has_const_mode_arg
minipli-oss Nov 20, 2025
e251a50
nvidia: Fix nvswitch_task_dispatch() prototype
minipli-oss Nov 20, 2025
3d51bad
nvidia: Fix TMR_CALLBACK_FUNCTION type
minipli-oss Mar 4, 2026
319ddfc
nvidia: maxwell - Fix aperture type
minipli-oss Feb 5, 2026
76c78b0
nvidia: Fix stack info leak in tmrCtrlCmdEventCreate()
minipli-oss Mar 4, 2026
a32a49c
nvidia: Fix cleaning of nv_compiler.h
minipli-oss Mar 11, 2026
ac49123
nvidia-drm: Fix prototype of nv_drm_connector_mode_valid()
minipli-oss Nov 20, 2025
a421e85
nvidia-uvm: Statically initialize g_exported_uvm_events
minipli-oss Nov 20, 2025
ecf4da3
nvidia-modeset: Fix prototype of NVEvoSubDevRec.scanLockState()
minipli-oss Feb 5, 2026
ef9d43f
kernel-open: RANDSTRUCT kernel config test
minipli-oss Mar 18, 2026
5ab8510
src/: remove system header dependencies
minipli-oss Nov 27, 2025
3f06caf
nvswitch: use designated initializers
minipli-oss Mar 12, 2026
165106d
nvidia-3d: use designated initializers
Feb 5, 2026
fc6cf53
nvidia-modeset: use designated initializers
Feb 5, 2026
1fe68c9
nvidia: gpu/mmu - use designated initializers
minipli-oss Mar 12, 2026
6e5d319
nvidia: make GPUHWREG use flexible arrays
minipli-oss Mar 18, 2026
23f1e7c
x86emu: drop dependency on <stddef.h>
minipli-oss Nov 27, 2025
7c70a05
kernel-open/Kbuild: fix potential duplicated CFLAGS
minipli-oss Feb 26, 2026
9947da3
kernel-open/Kbuild: CFLAGS_REMOVE support
minipli-oss Feb 10, 2026
2c1dee5
kernel-open/Kbuild: NVIDSTRING support
minipli-oss Feb 10, 2026
405804c
kernel-open/Kbuild: LDFLAGS and OBJCOPYFLAGS support
minipli-oss Feb 26, 2026
6b0c069
kernel-open/Kbuild: stub module support
minipli-oss Feb 10, 2026
f8481c0
kernel-open: introduce module preparation step
minipli-oss Feb 10, 2026
8eec747
src/nvidia: move CFLAGS to defs.mk
minipli-oss Dec 9, 2025
fb77ed3
src/nvidia: move LINKER_SCRIPT and EXPORTS_LINK_COMMAND to srcs.mk
minipli-oss Feb 26, 2026
3b6a3b3
src/nvidia: preliminary kbuild support
minipli-oss Feb 10, 2026
e3cdae8
kernel-open/nvidia: Kbuild support
minipli-oss Feb 10, 2026
17ce643
kernel-open: pass C++ compiler variable to sub-make
minipli-oss Feb 10, 2026
b60c08e
Make nv-stddef.h C++-aware and use it in nvdp-host.cpp
minipli-oss Feb 9, 2026
58f5ca3
nvidia-3d: always define XZ_INTERNAL_CRC32
minipli-oss Feb 9, 2026
cf4a56d
dp/connectorimpl: always define DP_OPTION_AUTO_ENABLE_MST_STREAM_ENCR
minipli-oss Mar 18, 2026
daf2363
src/nvidia-modeset: move CFLAGS to defs.mk, shaders to srcs.mk
minipli-oss Feb 10, 2026
0d5f849
src/nvidia-modeset: preliminary kbuild support
minipli-oss Feb 10, 2026
61b6eb0
src/nvidia-modeset: collapse C++ comdat sections
minipli-oss Mar 11, 2026
4f7a0d9
kernel-open/nvidia-modeset: Kbuild support
minipli-oss Feb 10, 2026
69de8b8
Experimental support for Linux's kbuild
minipli-oss Dec 16, 2025
a1f715b
kernel-open: Lift RANDSTRUCT restriction for USE_KBUILD=1
minipli-oss Mar 18, 2026
a1e0c29
conftest: Add test for vm_operations_struct.access() 'len' type
minipli-oss Nov 20, 2025
dfd59fc
conftest: Add test for grsecurity's atomic*_unchecked_t
minipli-oss Dec 11, 2025
084f8a0
nvidia-uvm: make *ops union compatible with grsecurity
minipli-oss Nov 20, 2025
aceb4c2
kernel-open: mark nv_kthread_q related types nolocal for grsecurity c…
minipli-oss Dec 10, 2025
1d1d3eb
src/common: make "HAL" types compatible with grsecurity
minipli-oss Feb 12, 2026
684be25
src/nvidia-modeset: disable certain gcc plugins for C++ code
minipli-oss Feb 12, 2026
302a353
src/nvidia: disable --gc-sections for kbuild
minipli-oss Feb 27, 2026
2c34485
src/nvidia: make "IFACES" types compatible with grsecurity
minipli-oss Feb 12, 2026
3be6831
src/nvidia: make nv_work_item_t compatible with grsecurity
minipli-oss Feb 12, 2026
3337080
src/nvidia: make MMU_WALK_CALLBACKS compatible with grsecurity
minipli-oss Feb 12, 2026
5ccc8f0
src/nvidia: make callback wrapping of tmrCtrlCmdEventCreate() grsec c…
minipli-oss Mar 4, 2026
1a5c5f1
src/nvidia: nvalloc - constify pioFuncs and memFuncs
minipli-oss Feb 12, 2026
ebd68ab
src/nvidia: mark THREAD_STATE_NODE nolocal for grsecurity compatibility
minipli-oss Mar 18, 2026
fadae3b
src/nvidia: support mangling sources with coccinelle
minipli-oss Feb 12, 2026
9011d9a
fix_nvoc_dtor.cocci: fix NVOC_DYNAMIC_DTOR CFI violations
minipli-oss Nov 27, 2025
3900714
fix_nvoc_ctor.cocci: fix NVOC_DYNAMIC_OBJ_CREATE CFI violations
minipli-oss Nov 27, 2025
f049e83
fix_nvoc_pfunc*.cocci: fix bad pFunc fprt casts
minipli-oss Dec 5, 2025
ba610b7
fix_*_init.cocci: fix missing desgnated inits
minipli-oss Mar 12, 2026
23a3af9
src/nvidia: kbuild - hook up cocci scripts
minipli-oss Dec 16, 2025
03505ed
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
118 changes: 115 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,39 @@ 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)


$(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=\"590.48.01\"
Expand Down
23 changes: 22 additions & 1 deletion kernel-open/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,25 @@ else
from CONFIG_CC_VERSION_TEXT in the kernel configuration.)
else
CC=$(cc_version_text)
CXX=$(subst cc,++,$(cc_version_text))
endif
endif
endif

ifneq ($(USE_KBUILD),1)
# RANDSTRUCT is incompatible with how we build the OS-agnostic part, leading
# to calling the wrong callback functions from pure *ops structures at
# runtime.
ranstruct_enabled=$(firstword $(shell . $(KERNEL_OUTPUT)/.config; \
echo "$$CONFIG_RANDSTRUCT$$CONFIG_GCC_PLUGIN_RANDSTRUCT"))
ifneq ($(ranstruct_enabled),)
$(error RANDSTRUCT enabled kernel is incompatible with binary objects!))
endif
endif

CC ?= cc
LD ?= ld
CXX ?= c++
OBJDUMP ?= objdump
AWK ?= awk
# Bake the following awk program in a string. The program is needed to add C++
Expand Down Expand Up @@ -132,10 +145,18 @@ 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

.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_VARIABLES) $(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
14 changes: 14 additions & 0 deletions kernel-open/common/inc/nvtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,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