Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 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
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
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");
37 changes: 35 additions & 2 deletions kernel-open/conftest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4919,6 +4919,38 @@ compile_test() {
compile_check_conftest "$CODE" "NV_DRM_DRIVER_HAS_DATE" "" "types"
;;

drm_connector_helper_funcs_mode_valid_has_int_ret_type)
#
# Determine if the return type is 'int' for
# drm_connector_helper_funcs::mode_valid.
#
# It was changed to 'enum drm_mode_status' by commit 0993f1d0d8a1
# ("drm: Make the connector mode_valid() vfunc return a
# drm_mode_status enum") in v3.14.
#
CODE="
#include <drm/drm_atomic_helper.h>

#ifndef __same_type
#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
#endif

/* BUILD_BUG_ON() from <linux/kernel.h> isn't working */
#define CONF_BUILD_BUG_ON(cond) \
char conf_bug_on_trigger[0 - !!(cond)]

/* We exploit the fact, that 'int' and 'enum' are compatible but
* 'enum e1' and 'enum e2' are not to cause a build error if the
* return type of drm_connector_helper_funcs::mode_valid is an enum.
*/
enum conftest_enum { CONFTEST = -1 } conftest_enum;
const struct drm_connector_helper_funcs conftest_func;
CONF_BUILD_BUG_ON(!__same_type(conftest_func.mode_valid(NULL, NULL), conftest_enum));
"

compile_check_conftest "$CODE" "NV_DRM_CONNECTOR_HELPER_FUNCS_MODE_VALID_HAS_INT_RET_TYPE" "" "types"
;;

drm_connector_helper_funcs_mode_valid_has_const_mode_arg)
#
# Determine if the 'mode' pointer argument is const in
Expand All @@ -4932,8 +4964,9 @@ compile_test() {
CODE="
#include <drm/drm_atomic_helper.h>

static int conftest_drm_connector_mode_valid(struct drm_connector *connector,
const struct drm_display_mode *mode) {
static enum drm_mode_status
conftest_drm_connector_mode_valid(struct drm_connector *connector,
const struct drm_display_mode *mode) {
return 0;
}

Expand Down
11 changes: 8 additions & 3 deletions kernel-open/nvidia-drm/nvidia-drm-connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,16 @@ static int nv_drm_connector_get_modes(struct drm_connector *connector)
return count;
}

static int nv_drm_connector_mode_valid(struct drm_connector *connector,
#ifdef NV_DRM_CONNECTOR_HELPER_FUNCS_MODE_VALID_HAS_INT_RET_TYPE
static int
#else
static enum drm_mode_status
#endif
nv_drm_connector_mode_valid(struct drm_connector *connector,
#if defined(NV_DRM_CONNECTOR_HELPER_FUNCS_MODE_VALID_HAS_CONST_MODE_ARG)
const struct drm_display_mode *mode)
const struct drm_display_mode *mode)
#else
struct drm_display_mode *mode)
struct drm_display_mode *mode)
#endif
{
struct drm_device *dev = connector->dev;
Expand Down
1 change: 1 addition & 0 deletions kernel-open/nvidia-drm/nvidia-drm-sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@ NV_CONFTEST_TYPE_COMPILE_TESTS += drm_format_info_has_is_yuv
NV_CONFTEST_TYPE_COMPILE_TESTS += drm_driver_has_gem_prime_mmap
NV_CONFTEST_TYPE_COMPILE_TESTS += drm_output_poll_changed
NV_CONFTEST_TYPE_COMPILE_TESTS += drm_driver_has_date
NV_CONFTEST_TYPE_COMPILE_TESTS += drm_connector_helper_funcs_mode_valid_has_int_ret_type
NV_CONFTEST_TYPE_COMPILE_TESTS += drm_connector_helper_funcs_mode_valid_has_const_mode_arg
NV_CONFTEST_TYPE_COMPILE_TESTS += drm_fb_create_takes_format_info
2 changes: 2 additions & 0 deletions kernel-open/nvidia-drm/nvidia-drm.Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ NVIDIA_DRM_SOURCES += nvidia-drm/nvidia-drm-linux.c

NVIDIA_DRM_OBJECTS = $(patsubst %.c,%.o,$(NVIDIA_DRM_SOURCES))

ifneq ($(NV_PREPARE_ONLY),1)
obj-m += nvidia-drm.o
nvidia-drm-y := $(NVIDIA_DRM_OBJECTS)
endif

NVIDIA_DRM_KO = nvidia-drm/nvidia-drm.ko

Expand Down
Loading