From 854a06b7310a3ba35d817e133d5e31e0873fb0b7 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Thu, 20 Nov 2025 16:40:41 +0000 Subject: [PATCH 01/37] conftest: Fix drm_connector_helper_funcs_mode_valid_has_const_mode_arg The return type is expected to be 'enum drm_mode_status', fix that. Signed-off-by: Mathias Krause --- kernel-open/conftest.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel-open/conftest.sh b/kernel-open/conftest.sh index 59f3624d1..6ec4973fc 100755 --- a/kernel-open/conftest.sh +++ b/kernel-open/conftest.sh @@ -4932,8 +4932,9 @@ compile_test() { CODE=" #include - 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; } From e251a50c4dc932df2ab7db1e4176bafdf6ead3fb Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Thu, 20 Nov 2025 16:49:51 +0000 Subject: [PATCH 02/37] nvidia: Fix nvswitch_task_dispatch() prototype nvswitch_task_dispatch() is supposed to be of type nv_q_func_t which expects a void pointer argument. Fix that to make it compatible with strongly type-based CFI implementations like RAP, as found in grsecurity. Signed-off-by: Mathias Krause --- kernel-open/nvidia/linux_nvswitch.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel-open/nvidia/linux_nvswitch.c b/kernel-open/nvidia/linux_nvswitch.c index 015de1ca6..be2e0be70 100644 --- a/kernel-open/nvidia/linux_nvswitch.c +++ b/kernel-open/nvidia/linux_nvswitch.c @@ -259,7 +259,7 @@ struct file_operations ctl_fops = static int nvswitch_initialize_device_interrupt(NVSWITCH_DEV *nvswitch_dev); static void nvswitch_shutdown_device_interrupt(NVSWITCH_DEV *nvswitch_dev); static void nvswitch_load_bar_info(NVSWITCH_DEV *nvswitch_dev); -static void nvswitch_task_dispatch(NVSWITCH_DEV *nvswitch_dev); +static void nvswitch_task_dispatch(void *nvswitch_dev); static NvBool nvswitch_is_device_blacklisted @@ -313,7 +313,7 @@ nvswitch_init_background_tasks NV_ATOMIC_SET(nvswitch_dev->task_q_ready, 1); nv_kthread_q_item_init(&nvswitch_dev->task_item, - (nv_q_func_t) &nvswitch_task_dispatch, + &nvswitch_task_dispatch, nvswitch_dev); if (!nv_kthread_q_schedule_q_item(&nvswitch_dev->task_q, @@ -1208,9 +1208,10 @@ nvswitch_isr_thread static void nvswitch_task_dispatch ( - NVSWITCH_DEV *nvswitch_dev + void *_nvswitch_dev ) { + NVSWITCH_DEV *nvswitch_dev = _nvswitch_dev; NvU64 nsec; NvU64 timeout; NvS64 rc; From 3d51bad5ab5dbaf3311025e236f1140304bfc1fe Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Wed, 4 Mar 2026 10:05:59 +0000 Subject: [PATCH 03/37] nvidia: Fix TMR_CALLBACK_FUNCTION type The retun type should be 'void' as all users of tmrCtrlCmdEventCreate() pass a 'void (*)(void *)' function pointer. Signed-off-by: Mathias Krause --- src/nvidia/src/kernel/gpu/timer/timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvidia/src/kernel/gpu/timer/timer.c b/src/nvidia/src/kernel/gpu/timer/timer.c index 5a28338c0..dba085a76 100644 --- a/src/nvidia/src/kernel/gpu/timer/timer.c +++ b/src/nvidia/src/kernel/gpu/timer/timer.c @@ -1769,7 +1769,7 @@ tmrapiDeregisterEvents_IMPL(TimerApi *pTimerApi) // inner callback and calls it correctly from itself. Hacky but it should work around the // limitations in the SDK (all RM derived types undefined, so TIMEPROC type is impossible). // -typedef NvU32 (*TMR_CALLBACK_FUNCTION)(void *pCallbackData); +typedef void (*TMR_CALLBACK_FUNCTION)(void *pCallbackData); typedef struct { From 319ddfc10af1708d2f4b6a3a10c3849c2feb34f6 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Thu, 5 Feb 2026 10:18:03 +0000 Subject: [PATCH 04/37] nvidia: maxwell - Fix aperture type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc warns about the use of the wrong enum type, fix that! .../src/nvidia/src/kernel/gpu/mem_mgr/arch/maxwell/virt_mem_allocator_gm107.c:1720:76: warning: implicit conversion from ‘GMMU_APERTURE’ to ‘FB_CACHE_MEMTYPE’ [-Wenum-conversion] 1720 | kmemsysCacheOp_HAL(pGpu, GPU_GET_KERNEL_MEMORY_SYSTEM(pGpu), NULL, aperture, FB_CACHE_INVALIDATE); | ^~~~~~~~ .../src/nvidia/generated/g_kern_mem_sys_nvoc.h:632:135: note: in definition of macro ‘kmemsysCacheOp_HAL’ 632 | #define kmemsysCacheOp_HAL(pGpu, pKernelMemorySystem, arg3, arg4, operation) kmemsysCacheOp_DISPATCH(pGpu, pKernelMemorySystem, arg3, arg4, operation) | ^~~~ Signed-off-by: Mathias Krause --- .../kernel/gpu/mem_mgr/arch/maxwell/virt_mem_allocator_gm107.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvidia/src/kernel/gpu/mem_mgr/arch/maxwell/virt_mem_allocator_gm107.c b/src/nvidia/src/kernel/gpu/mem_mgr/arch/maxwell/virt_mem_allocator_gm107.c index cc2098b02..476b174e3 100644 --- a/src/nvidia/src/kernel/gpu/mem_mgr/arch/maxwell/virt_mem_allocator_gm107.c +++ b/src/nvidia/src/kernel/gpu/mem_mgr/arch/maxwell/virt_mem_allocator_gm107.c @@ -1692,7 +1692,7 @@ dmaFreeMapping_GM107 if (pCliMapInfo != NULL && pCliMapInfo->pDmaMappingInfo->bNeedL2InvalidateAtUnmap) { - GMMU_APERTURE aperture = (pCliMapInfo->pDmaMappingInfo->aperture == GMMU_APERTURE_PEER) ? + FB_CACHE_MEMTYPE aperture = (pCliMapInfo->pDmaMappingInfo->aperture == GMMU_APERTURE_PEER) ? FB_CACHE_PEER_MEMORY : FB_CACHE_SYSTEM_MEMORY; kmemsysCacheOp_HAL(pGpu, GPU_GET_KERNEL_MEMORY_SYSTEM(pGpu), NULL, aperture, FB_CACHE_INVALIDATE); From 76c78b096b7ad46c370d25be87cc9a7fffefeada Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Wed, 4 Mar 2026 10:09:34 +0000 Subject: [PATCH 05/37] nvidia: Fix stack info leak in tmrCtrlCmdEventCreate() In case tmrEventCreate() fails, we will copy the uninitialized value of the stack local variable 'pEvent' and expose it to the caller. Prevent that by initializing it to NULL, as all other users do. Signed-off-by: Mathias Krause --- src/nvidia/src/kernel/gpu/timer/timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvidia/src/kernel/gpu/timer/timer.c b/src/nvidia/src/kernel/gpu/timer/timer.c index dba085a76..b5f41cd84 100644 --- a/src/nvidia/src/kernel/gpu/timer/timer.c +++ b/src/nvidia/src/kernel/gpu/timer/timer.c @@ -1822,7 +1822,7 @@ tmrCtrlCmdEventCreate ) { NV_STATUS rc; - TMR_EVENT *pEvent; + TMR_EVENT *pEvent = NULL; wrapperStorage_t *pWrapper; OBJTMR *pTmr = GPU_GET_TIMER(pGpu); From a32a49cd6f04450cd65a778c814ff899bfe971ee Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Wed, 11 Mar 2026 21:19:58 +0100 Subject: [PATCH 06/37] nvidia: Fix cleaning of nv_compiler.h Targets added to 'clean-files' shouldn't have the '$(obj)/' prefix or won't be found for the 'make clean' target. Fix that to ensure 'nv_compiler.h' will be removed on 'make clean'. Signed-off-by: Mathias Krause --- kernel-open/nvidia/nvidia.Kbuild | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel-open/nvidia/nvidia.Kbuild b/kernel-open/nvidia/nvidia.Kbuild index a04d6198b..8b05205d4 100644 --- a/kernel-open/nvidia/nvidia.Kbuild +++ b/kernel-open/nvidia/nvidia.Kbuild @@ -74,12 +74,12 @@ $(call ASSIGN_PER_OBJ_CFLAGS, $(NVIDIA_OBJECTS), $(NVIDIA_CFLAGS)) # nv-procfs.c requires nv-compiler.h # -NV_COMPILER_VERSION_HEADER = $(obj)/nv_compiler.h +NV_COMPILER_VERSION_HEADER = nv_compiler.h -$(NV_COMPILER_VERSION_HEADER): +$(obj)/$(NV_COMPILER_VERSION_HEADER): @echo \#define NV_COMPILER \"`$(CC) -v 2>&1 | tail -n 1`\" > $@ -$(obj)/nvidia/nv-procfs.o: $(NV_COMPILER_VERSION_HEADER) +$(obj)/nvidia/nv-procfs.o: $(obj)/$(NV_COMPILER_VERSION_HEADER) clean-files += $(NV_COMPILER_VERSION_HEADER) From ac4912325a8e9f7f135622ccd4acdcd15ba51831 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Thu, 20 Nov 2025 16:16:20 +0000 Subject: [PATCH 07/37] nvidia-drm: Fix prototype of nv_drm_connector_mode_valid() The drm_connector_helper_funcs.mode_valid() hook is expected to return a 'enum drm_mode_status' since Linux commit 0993f1d0d8a1 ("drm: Make the connector mode_valid() func return a drm_mode_status enum") merged in v3.14. Add a conftest test for it to fix that without breaking older kernels. The test is slightly evolved as C considers mismatched enum vs. int return types as compatible but they still violate CFI checks for advanced implementations like RAP as found in grsecurity. Signed-off-by: Mathias Krause --- kernel-open/conftest.sh | 32 +++++++++++++++++++ kernel-open/nvidia-drm/nvidia-drm-connector.c | 11 +++++-- kernel-open/nvidia-drm/nvidia-drm-sources.mk | 1 + 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/kernel-open/conftest.sh b/kernel-open/conftest.sh index 6ec4973fc..a515909db 100755 --- a/kernel-open/conftest.sh +++ b/kernel-open/conftest.sh @@ -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 + + #ifndef __same_type + #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) + #endif + + /* BUILD_BUG_ON() from 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 diff --git a/kernel-open/nvidia-drm/nvidia-drm-connector.c b/kernel-open/nvidia-drm/nvidia-drm-connector.c index fee5b9109..bb718c67b 100644 --- a/kernel-open/nvidia-drm/nvidia-drm-connector.c +++ b/kernel-open/nvidia-drm/nvidia-drm-connector.c @@ -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; diff --git a/kernel-open/nvidia-drm/nvidia-drm-sources.mk b/kernel-open/nvidia-drm/nvidia-drm-sources.mk index a2c3a3862..6bdc535cb 100644 --- a/kernel-open/nvidia-drm/nvidia-drm-sources.mk +++ b/kernel-open/nvidia-drm/nvidia-drm-sources.mk @@ -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 From a421e854fa03a03a65caf5f6a4744056575fcce8 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Thu, 20 Nov 2025 16:52:36 +0000 Subject: [PATCH 08/37] nvidia-uvm: Statically initialize g_exported_uvm_events There is no need to initialize 'g_exported_uvm_events' at runtime, initialize at compile time. Signed-off-by: Mathias Krause --- kernel-open/nvidia-uvm/uvm_global.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kernel-open/nvidia-uvm/uvm_global.c b/kernel-open/nvidia-uvm/uvm_global.c index 913765809..e346d7738 100644 --- a/kernel-open/nvidia-uvm/uvm_global.c +++ b/kernel-open/nvidia-uvm/uvm_global.c @@ -42,19 +42,19 @@ #include "nv_uvm_interface.h" uvm_global_t g_uvm_global; -static struct UvmEventsLinux g_exported_uvm_events; +static struct UvmEventsLinux g_exported_uvm_events = { + .isrTopHalf = uvm_isr_top_half_entry, + .suspend = uvm_suspend_entry, + .resume = uvm_resume_entry, + .drainP2P = uvm_suspend_and_drainP2P_entry, + .resumeP2P = uvm_resumeP2P_entry, +}; static bool g_ops_registered = false; static NV_STATUS uvm_register_callbacks(void) { NV_STATUS status = NV_OK; - g_exported_uvm_events.isrTopHalf = uvm_isr_top_half_entry; - g_exported_uvm_events.suspend = uvm_suspend_entry; - g_exported_uvm_events.resume = uvm_resume_entry; - g_exported_uvm_events.drainP2P = uvm_suspend_and_drainP2P_entry; - g_exported_uvm_events.resumeP2P = uvm_resumeP2P_entry; - // Register the UVM callbacks with the main GPU driver: status = uvm_rm_locked_call(nvUvmInterfaceRegisterUvmEvents(&g_exported_uvm_events)); if (status != NV_OK) From ecf4da37c67b128d3ff487fc5579307ffc340ec7 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Thu, 5 Feb 2026 09:54:13 +0000 Subject: [PATCH 09/37] nvidia-modeset: Fix prototype of NVEvoSubDevRec.scanLockState() Actual implementations of the NVEvoSubDevRec.scanLockState hook want an 'NVEvoLockAction'-typed 'action' argument. Fix that. Signed-off-by: Mathias Krause --- src/nvidia-modeset/include/nvkms-evo-states.h | 19 ----------------- src/nvidia-modeset/include/nvkms-types.h | 21 ++++++++++++++++++- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/nvidia-modeset/include/nvkms-evo-states.h b/src/nvidia-modeset/include/nvkms-evo-states.h index ab34f2a67..cd9a82632 100644 --- a/src/nvidia-modeset/include/nvkms-evo-states.h +++ b/src/nvidia-modeset/include/nvkms-evo-states.h @@ -39,25 +39,6 @@ typedef enum NVEvoLockSignal { NV_EVO_LOCK_SIGNAL_STEREO, } NVEvoLockSignal; -typedef enum NVEvoLockAction { - NV_EVO_PROHIBIT_LOCK, - NV_EVO_PROHIBIT_LOCK_DISABLE, - NV_EVO_LOCK_HEADS, - NV_EVO_UNLOCK_HEADS, - NV_EVO_ADD_FRAME_LOCK_SERVER, - NV_EVO_REM_FRAME_LOCK_SERVER, - NV_EVO_ADD_FRAME_LOCK_HOUSE_SYNC, - NV_EVO_REM_FRAME_LOCK_HOUSE_SYNC, - NV_EVO_ADD_FRAME_LOCK_CLIENT, - NV_EVO_REM_FRAME_LOCK_CLIENT, - NV_EVO_ADD_FRAME_LOCK_REF, - NV_EVO_REM_FRAME_LOCK_REF, - NV_EVO_ADD_SLI_SECONDARY, - NV_EVO_ADD_SLI_LAST_SECONDARY, - NV_EVO_ADD_SLI_PRIMARY, - NV_EVO_REM_SLI, -} NVEvoLockAction; - /* nv_evo.c */ NVEvoLockPin nvEvoGetPinForSignal(const NVDispEvoRec *, diff --git a/src/nvidia-modeset/include/nvkms-types.h b/src/nvidia-modeset/include/nvkms-types.h index 1bc0d328f..de3427a8c 100644 --- a/src/nvidia-modeset/include/nvkms-types.h +++ b/src/nvidia-modeset/include/nvkms-types.h @@ -796,6 +796,25 @@ typedef struct { NvU32 surfaceCount; } NVHsStateOneHeadAllDisps; +typedef enum NVEvoLockAction { + NV_EVO_PROHIBIT_LOCK, + NV_EVO_PROHIBIT_LOCK_DISABLE, + NV_EVO_LOCK_HEADS, + NV_EVO_UNLOCK_HEADS, + NV_EVO_ADD_FRAME_LOCK_SERVER, + NV_EVO_REM_FRAME_LOCK_SERVER, + NV_EVO_ADD_FRAME_LOCK_HOUSE_SYNC, + NV_EVO_REM_FRAME_LOCK_HOUSE_SYNC, + NV_EVO_ADD_FRAME_LOCK_CLIENT, + NV_EVO_REM_FRAME_LOCK_CLIENT, + NV_EVO_ADD_FRAME_LOCK_REF, + NV_EVO_REM_FRAME_LOCK_REF, + NV_EVO_ADD_SLI_SECONDARY, + NV_EVO_ADD_SLI_LAST_SECONDARY, + NV_EVO_ADD_SLI_PRIMARY, + NV_EVO_REM_SLI, +} NVEvoLockAction; + /* Subdevice-specific, channel-independent state */ typedef struct _NVEvoSubDevRec { NvU32 subDeviceInstance; @@ -812,7 +831,7 @@ typedef struct _NVEvoSubDevRec { void *cursorPio[NVKMS_MAX_HEADS_PER_DISP]; NvBool (*scanLockState)(NVDispEvoPtr pDispEvo, NVEvoSubDevPtr pEvoSubDev, - NvU32 action, + NVEvoLockAction action, /* NV_INVALID_HEAD-terminated * array of head indices */ const NvU32 *pHeads); From ef9d43f0d05982c6bc96c0aaf458eb185bb75046 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Wed, 18 Mar 2026 09:29:21 -0400 Subject: [PATCH 10/37] kernel-open: RANDSTRUCT kernel config test Test the kernel for having RANDSTRUCT enabled and break the build, if it is as this would otherwise lead to ABI-incompatibilities with the OS-agnostic part that doesn't get compiled with RANDSTRCUT enabled. A visible outcome of this would be calling the wrong callback function via structures that purely consist of function pointers (which RANDSTRUCT randomizes). Signed-off-by: Mathias Krause --- kernel-open/Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel-open/Makefile b/kernel-open/Makefile index f7a8db69f..50565d934 100644 --- a/kernel-open/Makefile +++ b/kernel-open/Makefile @@ -68,6 +68,15 @@ else endif endif + # 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 + CC ?= cc LD ?= ld OBJDUMP ?= objdump From 5ab85101b5bbfc3ce1f163ee94da76599c944303 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Thu, 27 Nov 2025 10:28:08 +0000 Subject: [PATCH 11/37] src/: remove system header dependencies Get rid of system header includes in preparation for upcoming kbuild support which prevents their usage via -nostdinc. The change is mostly mechanic, by making use of appropriate substitutes: - stddef.h gets replaced by a new nv-stddef.h header that uses kernel headers when appropriate defines are set or the regular system header otherwise, - stdarg.h gets replaced by nv_stdarg.h, which already uses kernel headers, if needed For softfloat the additional headers get wrapped: - stdbool.h, which makes use of Linux's for kernel builds and the system's otherwise. - stdint.h, which also makes use of Linux's for kernel builds but also provide the missing [u]int_fast*_t typedefs Signed-off-by: Mathias Krause --- src/common/displayport/inc/dp_internal.h | 2 +- src/common/displayport/inc/dp_object.h | 2 +- src/common/modeset/hdmipacket/nvhdmipkt.c | 2 +- .../modeset/hdmipacket/nvhdmipkt_C671.c | 2 +- src/common/modeset/timing/nvt_dsc_pps.c | 2 +- src/common/modeset/timing/nvtiming_pvt.h | 2 +- .../nvswitch/kernel/ls10/discovery_ls10.c | 2 +- src/common/nvswitch/kernel/ls10/tnvl_ls10.c | 2 +- src/common/sdk/nvidia/inc/nv-stddef.h | 38 +++++++++++++++++++ src/common/shared/msgq/msgq.c | 2 +- src/common/softfloat/nvidia/stdbool.h | 10 +++++ src/common/softfloat/nvidia/stdint.h | 38 +++++++++++++++++++ .../utils/interface/nv_mode_timings_utils.h | 2 +- .../common/utils/interface/nv_vasprintf.h | 4 +- src/common/unix/common/utils/unix_rm_handle.c | 2 +- .../nvidia-3d/interface/nvidia-3d-imports.h | 2 +- .../nvidia-push/interface/nvidia-push-types.h | 2 +- .../uproc/os/common/include/libos_log.h | 2 +- .../uproc/os/libos-v3.1.0/lib/libdwarf.c | 2 +- .../uproc/os/libos-v3.1.0/lib/liblogdecode.c | 5 +-- src/nvidia-modeset/include/nvkms-types.h | 2 +- src/nvidia-modeset/lib/nvkms-format.c | 2 +- .../include/nvidia-modeset-os-interface.h | 6 +-- .../os-interface/include/nvkms.h | 6 +-- src/nvidia-modeset/src/nvkms-dma.c | 2 +- src/nvidia/inc/kernel/core/prelude.h | 4 +- .../inc/libraries/nvport/inline/util_valist.h | 2 +- src/nvidia/inc/libraries/nvport/util.h | 2 +- .../deprecated/rmapi_deprecated_allocmemory.c | 2 +- .../deprecated/rmapi_deprecated_control.c | 2 +- .../deprecated/rmapi_deprecated_utils.c | 2 +- .../interface/rmapi/src/g_finn_rm_api.c | 6 ++- src/nvidia/src/kernel/gpu/conf_compute/ccsl.c | 2 +- 33 files changed, 121 insertions(+), 44 deletions(-) create mode 100644 src/common/sdk/nvidia/inc/nv-stddef.h create mode 100644 src/common/softfloat/nvidia/stdbool.h create mode 100644 src/common/softfloat/nvidia/stdint.h diff --git a/src/common/displayport/inc/dp_internal.h b/src/common/displayport/inc/dp_internal.h index 571e90076..f06390a4f 100644 --- a/src/common/displayport/inc/dp_internal.h +++ b/src/common/displayport/inc/dp_internal.h @@ -37,7 +37,7 @@ // #include -#include // size_t +#include // size_t #include "dp_object.h" #include "dp_ringbuffer.h" diff --git a/src/common/displayport/inc/dp_object.h b/src/common/displayport/inc/dp_object.h index 9bb02e805..8da7d6f8d 100644 --- a/src/common/displayport/inc/dp_object.h +++ b/src/common/displayport/inc/dp_object.h @@ -33,7 +33,7 @@ #define INCLUDED_DP_OBJECT_H #include "nvtypes.h" -#include "stddef.h" +#include "nv-stddef.h" #include "dp_hostimp.h" static inline void dpMemCopy(void * target, const void * source, size_t len) diff --git a/src/common/modeset/hdmipacket/nvhdmipkt.c b/src/common/modeset/hdmipacket/nvhdmipkt.c index 88317d0db..58ecc58e5 100644 --- a/src/common/modeset/hdmipacket/nvhdmipkt.c +++ b/src/common/modeset/hdmipacket/nvhdmipkt.c @@ -25,7 +25,7 @@ * Purpose: Provide initialization functions for HDMI library */ -#include +#include #include "nvlimits.h" #include "nvhdmipkt_common.h" #include "nvhdmipkt_class.h" diff --git a/src/common/modeset/hdmipacket/nvhdmipkt_C671.c b/src/common/modeset/hdmipacket/nvhdmipkt_C671.c index abdb91f46..88605af4f 100644 --- a/src/common/modeset/hdmipacket/nvhdmipkt_C671.c +++ b/src/common/modeset/hdmipacket/nvhdmipkt_C671.c @@ -25,7 +25,7 @@ * Purpose: Provides packet write functions for HDMI library for Ampere+ chips */ -#include +#include #include "nvhdmipkt_common.h" #include "nvhdmipkt_class.h" diff --git a/src/common/modeset/timing/nvt_dsc_pps.c b/src/common/modeset/timing/nvt_dsc_pps.c index 3f539ecbe..883cc8116 100644 --- a/src/common/modeset/timing/nvt_dsc_pps.c +++ b/src/common/modeset/timing/nvt_dsc_pps.c @@ -35,7 +35,7 @@ #include "displayport/displayport.h" #include "displayport/displayport2x.h" #include "nvctassert.h" -#include +#include /* ------------------------ Macros ----------------------------------------- */ diff --git a/src/common/modeset/timing/nvtiming_pvt.h b/src/common/modeset/timing/nvtiming_pvt.h index 1a54d0211..8f9002f83 100644 --- a/src/common/modeset/timing/nvtiming_pvt.h +++ b/src/common/modeset/timing/nvtiming_pvt.h @@ -49,7 +49,7 @@ #define nvt_assert(p) ((void)0) #endif // DD_UNITTEST -#include // NULL +#include // NULL #ifdef __cplusplus extern "C" { diff --git a/src/common/nvswitch/kernel/ls10/discovery_ls10.c b/src/common/nvswitch/kernel/ls10/discovery_ls10.c index 01af0303d..3db0c7bc1 100644 --- a/src/common/nvswitch/kernel/ls10/discovery_ls10.c +++ b/src/common/nvswitch/kernel/ls10/discovery_ls10.c @@ -30,7 +30,7 @@ #include "nvswitch/ls10/nxbar_discovery.h" #include "nvswitch/ls10/dev_npg_ip.h" -#include +#include #define VERBOSE_MMIO_DISCOVERY 0 diff --git a/src/common/nvswitch/kernel/ls10/tnvl_ls10.c b/src/common/nvswitch/kernel/ls10/tnvl_ls10.c index 92e3f1eff..ad948105b 100644 --- a/src/common/nvswitch/kernel/ls10/tnvl_ls10.c +++ b/src/common/nvswitch/kernel/ls10/tnvl_ls10.c @@ -39,7 +39,7 @@ #include "nvswitch/ls10/ptop_discovery_ip.h" #include "nvswitch/ls10/dev_minion_ip.h" -#include +#include /* ------------------------ Macros ----------------------------------------- */ #define TNVL_MAX_CERT_CHAIN_SIZE (0x1000) diff --git a/src/common/sdk/nvidia/inc/nv-stddef.h b/src/common/sdk/nvidia/inc/nv-stddef.h new file mode 100644 index 000000000..5ef838b56 --- /dev/null +++ b/src/common/sdk/nvidia/inc/nv-stddef.h @@ -0,0 +1,38 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + + +#ifndef _NV_STDDEF_H_ +#define _NV_STDDEF_H_ + +#if defined(NV_KERNEL_INTERFACE_LAYER) && defined(__FreeBSD__) + #include // NULL +#elif defined(NV_KERNEL_INTERFACE_LAYER) && defined(NV_LINUX) + #include // NULL + #include // size_t + #include // SIZE_MAX,... +#else + #include // NULL +#endif + +#endif // _NV_STDDEF_H_ diff --git a/src/common/shared/msgq/msgq.c b/src/common/shared/msgq/msgq.c index 76d9dd361..86d750bfa 100644 --- a/src/common/shared/msgq/msgq.c +++ b/src/common/shared/msgq/msgq.c @@ -21,7 +21,7 @@ * DEALINGS IN THE SOFTWARE. */ -#include +#include #include #include diff --git a/src/common/softfloat/nvidia/stdbool.h b/src/common/softfloat/nvidia/stdbool.h new file mode 100644 index 000000000..c50698c32 --- /dev/null +++ b/src/common/softfloat/nvidia/stdbool.h @@ -0,0 +1,10 @@ +#ifndef _NV_STDBOOL_H_ +#define _NV_STDBOOL_H_ + +#if defined(NV_KERNEL_INTERFACE_LAYER) && defined(NV_LINUX) + #include +#else + #include_next +#endif + +#endif // _NV_STDBOOL_H_ diff --git a/src/common/softfloat/nvidia/stdint.h b/src/common/softfloat/nvidia/stdint.h new file mode 100644 index 000000000..5dadb5d31 --- /dev/null +++ b/src/common/softfloat/nvidia/stdint.h @@ -0,0 +1,38 @@ +#ifndef _NV_STDINT_H_ +#define _NV_STDINT_H_ + +#if defined(NV_KERNEL_INTERFACE_LAYER) && defined(NV_LINUX) + #include + + /* Linux lacks the '*fast/least*_t' variants. */ + typedef int8_t int_fast8_t; + typedef uint8_t uint_fast8_t; + + typedef int16_t int_fast16_t; + typedef uint16_t uint_fast16_t; + + typedef int32_t int_fast32_t; + typedef uint32_t uint_fast32_t; + + typedef int64_t int_fast64_t; + typedef uint64_t uint_fast64_t; + + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; + + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; + + #define INT64_C(x) S64_C(x) + #define UINT64_C(x) U64_C(x) +#else + #include_next +#endif + +#endif // _NV_STDINT_H_ diff --git a/src/common/unix/common/utils/interface/nv_mode_timings_utils.h b/src/common/unix/common/utils/interface/nv_mode_timings_utils.h index 62ef305c0..6fafaf667 100644 --- a/src/common/unix/common/utils/interface/nv_mode_timings_utils.h +++ b/src/common/unix/common/utils/interface/nv_mode_timings_utils.h @@ -33,7 +33,7 @@ #include "nv_mode_timings.h" #include "timing/nvtiming.h" -#include /* size_t */ +#include /* size_t */ /* * Macros used for printing values divided by 1000 without floating diff --git a/src/common/unix/common/utils/interface/nv_vasprintf.h b/src/common/unix/common/utils/interface/nv_vasprintf.h index ec94beb51..a8023f899 100644 --- a/src/common/unix/common/utils/interface/nv_vasprintf.h +++ b/src/common/unix/common/utils/interface/nv_vasprintf.h @@ -28,8 +28,8 @@ extern "C" { #endif -#include -#include +#include +#include /* * nv_vasprintf() depends on nv_vasprintf_{alloc,free,vsnprintf}(). diff --git a/src/common/unix/common/utils/unix_rm_handle.c b/src/common/unix/common/utils/unix_rm_handle.c index b24d0e05e..bd3b39b58 100644 --- a/src/common/unix/common/utils/unix_rm_handle.c +++ b/src/common/unix/common/utils/unix_rm_handle.c @@ -37,7 +37,7 @@ * [15:00] Handle constant */ -#include +#include #include "unix_rm_handle.h" diff --git a/src/common/unix/nvidia-3d/interface/nvidia-3d-imports.h b/src/common/unix/nvidia-3d/interface/nvidia-3d-imports.h index 839a2da59..a64f93369 100644 --- a/src/common/unix/nvidia-3d/interface/nvidia-3d-imports.h +++ b/src/common/unix/nvidia-3d/interface/nvidia-3d-imports.h @@ -29,7 +29,7 @@ #ifndef __NVIDIA_3D_IMPORTS_H__ #define __NVIDIA_3D_IMPORTS_H__ -#include /* size_t */ +#include /* size_t */ void *nv3dImportAlloc(size_t size); void nv3dImportFree(void *ptr); diff --git a/src/common/unix/nvidia-push/interface/nvidia-push-types.h b/src/common/unix/nvidia-push/interface/nvidia-push-types.h index ef0ce1548..7b3b4ad9d 100644 --- a/src/common/unix/nvidia-push/interface/nvidia-push-types.h +++ b/src/common/unix/nvidia-push/interface/nvidia-push-types.h @@ -29,7 +29,7 @@ #ifndef __NVIDIA_PUSH_TYPES_H__ #define __NVIDIA_PUSH_TYPES_H__ -#include /* size_t */ +#include /* size_t */ diff --git a/src/common/uproc/os/common/include/libos_log.h b/src/common/uproc/os/common/include/libos_log.h index 7e59dd739..25b4aeb20 100644 --- a/src/common/uproc/os/common/include/libos_log.h +++ b/src/common/uproc/os/common/include/libos_log.h @@ -25,7 +25,7 @@ #define LIBOS_LOGGER_H_ #include "nvtypes.h" -#include +#include "nv_stdarg.h" #include "libos_printf_arg.h" #if defined(NVRM) diff --git a/src/common/uproc/os/libos-v3.1.0/lib/libdwarf.c b/src/common/uproc/os/libos-v3.1.0/lib/libdwarf.c index 1ba1acda1..fd0dc32d7 100644 --- a/src/common/uproc/os/libos-v3.1.0/lib/libdwarf.c +++ b/src/common/uproc/os/libos-v3.1.0/lib/libdwarf.c @@ -23,7 +23,7 @@ #ifdef NVRM -# include +# include # include # define printf(fmt, ...) nv_printf(LEVEL_ERROR, fmt, ##__VA_ARGS__) diff --git a/src/common/uproc/os/libos-v3.1.0/lib/liblogdecode.c b/src/common/uproc/os/libos-v3.1.0/lib/liblogdecode.c index e5e79cfc4..406f223df 100644 --- a/src/common/uproc/os/libos-v3.1.0/lib/liblogdecode.c +++ b/src/common/uproc/os/libos-v3.1.0/lib/liblogdecode.c @@ -27,7 +27,7 @@ #ifdef NVRM # include -# include // size_t +# include // size_t #define LIBOS_LOG_DECODE_PRINTF(level, fmt, ...) portDbgExPrintfLevel(level, fmt, ##__VA_ARGS__) @@ -39,6 +39,7 @@ #include "time.h" #endif +# include # include # include # include @@ -75,8 +76,6 @@ #define LIBOS_LOG_DECODE_PRINTF(level, fmt, ...) printf(fmt, ...) #endif -#include - #include "nvtypes.h" #include "nvstatus.h" #include "liblogdecode.h" diff --git a/src/nvidia-modeset/include/nvkms-types.h b/src/nvidia-modeset/include/nvkms-types.h index de3427a8c..3b7f7fbe4 100644 --- a/src/nvidia-modeset/include/nvkms-types.h +++ b/src/nvidia-modeset/include/nvkms-types.h @@ -61,7 +61,7 @@ extern "C" { #include "timing/dpsdp.h" #include "hdmipacket/nvhdmi_frlInterface.h" // HDMI_{SRC,SINK}_CAPS -#include +#include #include "nv_smg.h" diff --git a/src/nvidia-modeset/lib/nvkms-format.c b/src/nvidia-modeset/lib/nvkms-format.c index cb8c8fd1a..fb50558ff 100644 --- a/src/nvidia-modeset/lib/nvkms-format.c +++ b/src/nvidia-modeset/lib/nvkms-format.c @@ -25,7 +25,7 @@ #include "nv_common_utils.h" #include "nvctassert.h" -#include +#include #define RGB_ENTRY(_format, _depth, _bytesPerPixel) \ [NvKmsSurfaceMemoryFormat##_format] = { \ diff --git a/src/nvidia-modeset/os-interface/include/nvidia-modeset-os-interface.h b/src/nvidia-modeset/os-interface/include/nvidia-modeset-os-interface.h index d4d656e76..e97754a8e 100644 --- a/src/nvidia-modeset/os-interface/include/nvidia-modeset-os-interface.h +++ b/src/nvidia-modeset/os-interface/include/nvidia-modeset-os-interface.h @@ -29,11 +29,7 @@ #if !defined(_NVIDIA_MODESET_OS_INTERFACE_H_) #define _NVIDIA_MODESET_OS_INTERFACE_H_ -#if defined(NV_KERNEL_INTERFACE_LAYER) && defined(NV_LINUX) -#include /* size_t */ -#else -#include /* size_t */ -#endif +#include /* size_t */ #include "nvtypes.h" /* NvU8 */ #include "nvkms.h" diff --git a/src/nvidia-modeset/os-interface/include/nvkms.h b/src/nvidia-modeset/os-interface/include/nvkms.h index d350ef756..55c8abd64 100644 --- a/src/nvidia-modeset/os-interface/include/nvkms.h +++ b/src/nvidia-modeset/os-interface/include/nvkms.h @@ -25,11 +25,7 @@ #define __NV_KMS_H__ #include "nvtypes.h" -#if defined(NV_KERNEL_INTERFACE_LAYER) && defined(NV_LINUX) -#include /* size_t */ -#else -#include /* size_t */ -#endif +#include /* size_t, NULL */ #include "nvkms-kapi.h" diff --git a/src/nvidia-modeset/src/nvkms-dma.c b/src/nvidia-modeset/src/nvkms-dma.c index a6c0b57b6..b8b3743e7 100644 --- a/src/nvidia-modeset/src/nvkms-dma.c +++ b/src/nvidia-modeset/src/nvkms-dma.c @@ -21,7 +21,7 @@ * DEALINGS IN THE SOFTWARE. */ -#include +#include #include "nvkms-dma.h" #include "nvkms-utils.h" diff --git a/src/nvidia/inc/kernel/core/prelude.h b/src/nvidia/inc/kernel/core/prelude.h index 3273c2f58..5c72252d6 100644 --- a/src/nvidia/inc/kernel/core/prelude.h +++ b/src/nvidia/inc/kernel/core/prelude.h @@ -23,12 +23,10 @@ #ifndef __PRELUDE_H__ #define __PRELUDE_H__ -/* ------------------------ C library --------------------------------------- */ -#include // NULL - /* ------------------------ SDK includes ------------------------------------ */ #include "nvtypes.h" +#include "nv-stddef.h" #include "nvrangetypes.h" #include "nvstatus.h" #include "nvmisc.h" diff --git a/src/nvidia/inc/libraries/nvport/inline/util_valist.h b/src/nvidia/inc/libraries/nvport/inline/util_valist.h index 4d293c3fd..fb67c05ac 100644 --- a/src/nvidia/inc/libraries/nvport/inline/util_valist.h +++ b/src/nvidia/inc/libraries/nvport/inline/util_valist.h @@ -27,4 +27,4 @@ */ // We used to have custom implementations in here, but now we just take the standard ones -#include // define va_* +#include // define va_* diff --git a/src/nvidia/inc/libraries/nvport/util.h b/src/nvidia/inc/libraries/nvport/util.h index 6234d618a..194b7a43e 100644 --- a/src/nvidia/inc/libraries/nvport/util.h +++ b/src/nvidia/inc/libraries/nvport/util.h @@ -183,7 +183,7 @@ PORT_UTIL_INLINE NvU32 portUtilCountTrailingZeros32(NvU32 n); /// @} End core functions -#include /* NULL */ +#include /* NULL */ /** * @name Extended Functions diff --git a/src/nvidia/interface/deprecated/rmapi_deprecated_allocmemory.c b/src/nvidia/interface/deprecated/rmapi_deprecated_allocmemory.c index 6a88b6f92..c2502ae30 100644 --- a/src/nvidia/interface/deprecated/rmapi_deprecated_allocmemory.c +++ b/src/nvidia/interface/deprecated/rmapi_deprecated_allocmemory.c @@ -37,7 +37,7 @@ #include "ctrl/ctrl2080/ctrl2080fb.h" // NV2080_CTRL_FB_INFO -#include +#include typedef NV_STATUS RmAllocMemoryFunc( DEPRECATED_CONTEXT *pContext, diff --git a/src/nvidia/interface/deprecated/rmapi_deprecated_control.c b/src/nvidia/interface/deprecated/rmapi_deprecated_control.c index 0a647ed35..0ffdba52a 100644 --- a/src/nvidia/interface/deprecated/rmapi_deprecated_control.c +++ b/src/nvidia/interface/deprecated/rmapi_deprecated_control.c @@ -45,7 +45,7 @@ #include "rmapi/rs_utils.h" #include "rmapi/rmapi.h" -#include // NULL +#include // NULL /** * Kernel-space deprecated control conversion. diff --git a/src/nvidia/interface/deprecated/rmapi_deprecated_utils.c b/src/nvidia/interface/deprecated/rmapi_deprecated_utils.c index 0b2f8bb9b..257bc2358 100644 --- a/src/nvidia/interface/deprecated/rmapi_deprecated_utils.c +++ b/src/nvidia/interface/deprecated/rmapi_deprecated_utils.c @@ -28,7 +28,7 @@ #include "ctrl/ctrl0080/ctrl0080gpu.h" // NV0080_CTRL_CMD_GPU_FIND_SUBDEVICE_HANDLE #include "nvos.h" -#include +#include NV_STATUS RmDeprecatedGetHandleParent diff --git a/src/nvidia/interface/rmapi/src/g_finn_rm_api.c b/src/nvidia/interface/rmapi/src/g_finn_rm_api.c index dfb6812ed..b6368ec09 100644 --- a/src/nvidia/interface/rmapi/src/g_finn_rm_api.c +++ b/src/nvidia/interface/rmapi/src/g_finn_rm_api.c @@ -21,8 +21,10 @@ #include "ctrl/ctrlb06f.h" #if defined(NVRM) /* Kernel Mode */ -#include -#include +#include +#ifndef NV_KERNEL_INTERFACE_LAYER +# include +#endif #include "nvport/nvport.h" #elif defined(NV_LIBOS) /* LIBOS */ #include diff --git a/src/nvidia/src/kernel/gpu/conf_compute/ccsl.c b/src/nvidia/src/kernel/gpu/conf_compute/ccsl.c index f5ab03e26..bf2a26d88 100644 --- a/src/nvidia/src/kernel/gpu/conf_compute/ccsl.c +++ b/src/nvidia/src/kernel/gpu/conf_compute/ccsl.c @@ -31,7 +31,7 @@ #include "nvport/nvport.h" #include "rmapi/rmapi.h" #include "ctrl/ctrlc56f.h" -#include +#include // This guard is here until we fix CONF_COMPUTE and SPDM guards across whole RM #include "kernel/gpu/spdm/libspdm_includes.h" #include From 3f06caf3ee7b686ed5de58c0b1be1ffdcd4fb806 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Thu, 12 Mar 2026 11:33:53 +0100 Subject: [PATCH 12/37] nvswitch: use designated initializers Use designated initializers for initializing static nvswitch discovery handler objects to resolve incompatibilities with Linux's RANDSTRUCT gcc plugin. Signed-off-by: Mathias Krause --- .../nvswitch/kernel/lr10/discovery_lr10.c | 32 +++++++++---------- .../nvswitch/kernel/ls10/discovery_ls10.c | 32 +++++++++---------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/common/nvswitch/kernel/lr10/discovery_lr10.c b/src/common/nvswitch/kernel/lr10/discovery_lr10.c index f282ba590..63f3d2616 100644 --- a/src/common/nvswitch/kernel/lr10/discovery_lr10.c +++ b/src/common/nvswitch/kernel/lr10/discovery_lr10.c @@ -921,37 +921,37 @@ nvswitch_nxbar_handle_data2_lr10 static NVSWITCH_DISCOVERY_HANDLERS_LR10 discovery_handlers_ptop_lr10 = { - &_nvswitch_ptop_parse_entry_lr10, - &_nvswitch_ptop_parse_enum_lr10, - &_nvswitch_ptop_handle_data1_lr10, - &_nvswitch_ptop_handle_data2_lr10 + .parse_entry = _nvswitch_ptop_parse_entry_lr10, + .parse_enum = _nvswitch_ptop_parse_enum_lr10, + .handle_data1 = _nvswitch_ptop_handle_data1_lr10, + .handle_data2 = _nvswitch_ptop_handle_data2_lr10 }; static NVSWITCH_DISCOVERY_HANDLERS_LR10 discovery_handlers_npg_lr10 = { - &_nvswitch_npg_parse_entry_lr10, - &_nvswitch_npg_parse_enum_lr10, - &_nvswitch_npg_handle_data1_lr10, - &_nvswitch_npg_handle_data2_lr10 + .parse_entry = _nvswitch_npg_parse_entry_lr10, + .parse_enum = _nvswitch_npg_parse_enum_lr10, + .handle_data1 = _nvswitch_npg_handle_data1_lr10, + .handle_data2 = _nvswitch_npg_handle_data2_lr10 }; static NVSWITCH_DISCOVERY_HANDLERS_LR10 discovery_handlers_nvlw_lr10 = { - &nvswitch_nvlw_parse_entry_lr10, - &nvswitch_nvlw_parse_enum_lr10, - &nvswitch_nvlw_handle_data1_lr10, - &nvswitch_nvlw_handle_data2_lr10 + .parse_entry = nvswitch_nvlw_parse_entry_lr10, + .parse_enum = nvswitch_nvlw_parse_enum_lr10, + .handle_data1 = nvswitch_nvlw_handle_data1_lr10, + .handle_data2 = nvswitch_nvlw_handle_data2_lr10 }; static NVSWITCH_DISCOVERY_HANDLERS_LR10 discovery_handlers_nxbar_lr10 = { - &nvswitch_nxbar_parse_entry_lr10, - &nvswitch_nxbar_parse_enum_lr10, - &nvswitch_nxbar_handle_data1_lr10, - &nvswitch_nxbar_handle_data2_lr10 + .parse_entry = nvswitch_nxbar_parse_entry_lr10, + .parse_enum = nvswitch_nxbar_parse_enum_lr10, + .handle_data1 = nvswitch_nxbar_handle_data1_lr10, + .handle_data2 = nvswitch_nxbar_handle_data2_lr10 }; // diff --git a/src/common/nvswitch/kernel/ls10/discovery_ls10.c b/src/common/nvswitch/kernel/ls10/discovery_ls10.c index 3db0c7bc1..33a7d109b 100644 --- a/src/common/nvswitch/kernel/ls10/discovery_ls10.c +++ b/src/common/nvswitch/kernel/ls10/discovery_ls10.c @@ -952,37 +952,37 @@ nvswitch_nxbar_handle_data2_ls10 static NVSWITCH_DISCOVERY_HANDLERS_LS10 discovery_handlers_ptop_ls10 = { - &_nvswitch_ptop_parse_entry_ls10, - &_nvswitch_ptop_parse_enum_ls10, - &_nvswitch_ptop_handle_data1_ls10, - &_nvswitch_ptop_handle_data2_ls10 + .parse_entry = _nvswitch_ptop_parse_entry_ls10, + .parse_enum = _nvswitch_ptop_parse_enum_ls10, + .handle_data1 = _nvswitch_ptop_handle_data1_ls10, + .handle_data2 = _nvswitch_ptop_handle_data2_ls10 }; static NVSWITCH_DISCOVERY_HANDLERS_LS10 discovery_handlers_npg_ls10 = { - &_nvswitch_npg_parse_entry_ls10, - &_nvswitch_npg_parse_enum_ls10, - &_nvswitch_npg_handle_data1_ls10, - &_nvswitch_npg_handle_data2_ls10 + .parse_entry = _nvswitch_npg_parse_entry_ls10, + .parse_enum = _nvswitch_npg_parse_enum_ls10, + .handle_data1 = _nvswitch_npg_handle_data1_ls10, + .handle_data2 = _nvswitch_npg_handle_data2_ls10 }; static NVSWITCH_DISCOVERY_HANDLERS_LS10 discovery_handlers_nvlw_ls10 = { - &nvswitch_nvlw_parse_entry_ls10, - &nvswitch_nvlw_parse_enum_ls10, - &nvswitch_nvlw_handle_data1_ls10, - &nvswitch_nvlw_handle_data2_ls10 + .parse_entry = nvswitch_nvlw_parse_entry_ls10, + .parse_enum = nvswitch_nvlw_parse_enum_ls10, + .handle_data1 = nvswitch_nvlw_handle_data1_ls10, + .handle_data2 = nvswitch_nvlw_handle_data2_ls10 }; static NVSWITCH_DISCOVERY_HANDLERS_LS10 discovery_handlers_nxbar_ls10 = { - &nvswitch_nxbar_parse_entry_ls10, - &nvswitch_nxbar_parse_enum_ls10, - &nvswitch_nxbar_handle_data1_ls10, - &nvswitch_nxbar_handle_data2_ls10 + .parse_entry = nvswitch_nxbar_parse_entry_ls10, + .parse_enum = nvswitch_nxbar_parse_enum_ls10, + .handle_data1 = nvswitch_nxbar_handle_data1_ls10, + .handle_data2 = nvswitch_nxbar_handle_data2_ls10 }; // From 165106dd3782b00cb40b764d86c42036b92a9088 Mon Sep 17 00:00:00 2001 From: PaX Team Date: Thu, 5 Feb 2026 09:24:35 +0000 Subject: [PATCH 13/37] nvidia-3d: use designated initializers Use designated initializers for initializing static Nv3dHal objects to resolve incompatibilities with Linux's RANDSTRUCT gcc plugin. Signed-off-by: PaX Team Signed-off-by: Mathias Krause --- .../unix/nvidia-3d/src/nvidia-3d-init.c | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/common/unix/nvidia-3d/src/nvidia-3d-init.c b/src/common/unix/nvidia-3d/src/nvidia-3d-init.c index a59e54ffa..dca2f2f80 100644 --- a/src/common/unix/nvidia-3d/src/nvidia-3d-init.c +++ b/src/common/unix/nvidia-3d/src/nvidia-3d-init.c @@ -309,30 +309,30 @@ static NvBool GetSpaVersion( } static const Nv3dHal _nv3dHalTuring = { - _nv3dSetSpaVersionKepler, /* setSpaVersion */ - _nv3dInitChannelTuring, /* initChannel */ - _nv3dUploadDataInlineKepler, /* uploadDataInline */ - _nv3dSetProgramOffsetVolta, /* setProgramOffset */ - _nv3dAssignNv3dTexturePascal, /* assignNv3dTexture */ - _nv3dSetVertexStreamEndTuring, /* setVertexStreamEnd */ + .setSpaVersion = _nv3dSetSpaVersionKepler, + .initChannel = _nv3dInitChannelTuring, + .uploadDataInline = _nv3dUploadDataInlineKepler, + .setProgramOffset = _nv3dSetProgramOffsetVolta, + .assignNv3dTexture = _nv3dAssignNv3dTexturePascal, + .setVertexStreamEnd = _nv3dSetVertexStreamEndTuring }; static const Nv3dHal _nv3dHalAmpere = { - _nv3dSetSpaVersionKepler, /* setSpaVersion */ - _nv3dInitChannelTuring, /* initChannel */ - _nv3dUploadDataInlineKepler, /* uploadDataInline */ - _nv3dSetProgramOffsetVolta, /* setProgramOffset */ - _nv3dAssignNv3dTexturePascal, /* assignNv3dTexture */ - _nv3dSetVertexStreamEndTuring, /* setVertexStreamEnd */ + .setSpaVersion = _nv3dSetSpaVersionKepler, + .initChannel = _nv3dInitChannelTuring, + .uploadDataInline = _nv3dUploadDataInlineKepler, + .setProgramOffset = _nv3dSetProgramOffsetVolta, + .assignNv3dTexture = _nv3dAssignNv3dTexturePascal, + .setVertexStreamEnd = _nv3dSetVertexStreamEndTuring }; static const Nv3dHal _nv3dHalHopper = { - _nv3dSetSpaVersionKepler, /* setSpaVersion */ - _nv3dInitChannelHopper, /* initChannel */ - _nv3dUploadDataInlineKepler, /* uploadDataInline */ - _nv3dSetProgramOffsetVolta, /* setProgramOffset */ - _nv3dAssignNv3dTextureHopper, /* assignNv3dTexture */ - _nv3dSetVertexStreamEndTuring, /* setVertexStreamEnd */ + .setSpaVersion = _nv3dSetSpaVersionKepler, + .initChannel = _nv3dInitChannelHopper, + .uploadDataInline = _nv3dUploadDataInlineKepler, + .setProgramOffset = _nv3dSetProgramOffsetVolta, + .assignNv3dTexture = _nv3dAssignNv3dTextureHopper, + .setVertexStreamEnd = _nv3dSetVertexStreamEndTuring }; NvBool nv3dAllocDevice( From fc6cf5307f914b066f1e4f07030ae7a42d2a67ac Mon Sep 17 00:00:00 2001 From: PaX Team Date: Thu, 5 Feb 2026 09:24:35 +0000 Subject: [PATCH 14/37] nvidia-modeset: use designated initializers Use designated initializers for initializing NvKmsNvPushImports to resolve incompatibilities with Linux's RANDSTRUCT gcc plugin. Signed-off-by: PaX Team Signed-off-by: Mathias Krause --- src/nvidia-modeset/src/nvkms-push.c | 34 ++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/nvidia-modeset/src/nvkms-push.c b/src/nvidia-modeset/src/nvkms-push.c index 4b6094ac3..81bd96d18 100644 --- a/src/nvidia-modeset/src/nvkms-push.c +++ b/src/nvidia-modeset/src/nvkms-push.c @@ -233,24 +233,24 @@ static void NvPushImportLogNvDiss( #endif /* DEBUG */ static const NvPushImports NvKmsNvPushImports = { - NvPushImportRmApiControl, /* rmApiControl */ - NvPushImportRmApiAlloc, /* rmApiAlloc */ - NvPushImportRmApiFree, /* rmApiFree */ - NvPushImportRmApiMapMemoryDma, /* rmApiMapMemoryDma */ - NvPushImportRmApiUnmapMemoryDma, /* rmApiUnmapMemoryDma */ - NvPushImportRmApiAllocMemory64, /* rmApiAllocMemory64 */ - NvPushImportRmApiVidHeapControl, /* rmApiVidHeapControl */ - NvPushImportRmApiMapMemory, /* rmApiMapMemory */ - NvPushImportRmApiUnmapMemory, /* rmApiUnmapMemory */ - NvPushImportGetMilliSeconds, /* getMilliSeconds */ - NvPushImportYield, /* yield */ - NvPushImportWaitForEvent, /* waitForEvent */ - NvPushImportEmptyEventFifo, /* emptyEventFifo */ - NvPushImportChannelErrorOccurred, /* channelErrorOccurred */ - NvPushImportPushbufferWrapped, /* pushbufferWrapped */ - NvPushImportLogError, /* logError */ + .rmApiControl = NvPushImportRmApiControl, + .rmApiAlloc = NvPushImportRmApiAlloc, + .rmApiFree = NvPushImportRmApiFree, + .rmApiMapMemoryDma = NvPushImportRmApiMapMemoryDma, + .rmApiUnmapMemoryDma = NvPushImportRmApiUnmapMemoryDma, + .rmApiAllocMemory64 = NvPushImportRmApiAllocMemory64, + .rmApiVidHeapControl = NvPushImportRmApiVidHeapControl, + .rmApiMapMemory = NvPushImportRmApiMapMemory, + .rmApiUnmapMemory = NvPushImportRmApiUnmapMemory, + .getMilliSeconds = NvPushImportGetMilliSeconds, + .yield = NvPushImportYield, + .waitForEvent = NvPushImportWaitForEvent, + .emptyEventFifo = NvPushImportEmptyEventFifo, + .channelErrorOccurred = NvPushImportChannelErrorOccurred, + .pushbufferWrapped = NvPushImportPushbufferWrapped, + .logError = NvPushImportLogError, #if defined(DEBUG) - NvPushImportLogNvDiss, /* logNvDiss */ + .logNvDiss = NvPushImportLogNvDiss, #endif }; From 1fe68c930b1d1c502aa26fc5376fdb0ca7ceae40 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Thu, 12 Mar 2026 11:35:44 +0100 Subject: [PATCH 15/37] nvidia: gpu/mmu - use designated initializers Use designated initializers for initializing static MMU walk callback objects to resolve incompatibilities with Linux's RANDSTRUCT gcc plugin. Signed-off-by: Mathias Krause --- src/nvidia/src/kernel/gpu/mmu/bar2_walk.c | 14 ++++++------ src/nvidia/src/kernel/gpu/mmu/gmmu_trace.c | 26 +++++++++++----------- src/nvidia/src/kernel/gpu/mmu/gmmu_walk.c | 14 ++++++------ 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/nvidia/src/kernel/gpu/mmu/bar2_walk.c b/src/nvidia/src/kernel/gpu/mmu/bar2_walk.c index bae762f39..ebb3b8c43 100644 --- a/src/nvidia/src/kernel/gpu/mmu/bar2_walk.c +++ b/src/nvidia/src/kernel/gpu/mmu/bar2_walk.c @@ -935,11 +935,11 @@ _bar2WalkCBWriteBuffer const MMU_WALK_CALLBACKS g_bar2WalkCallbacks = { - _bar2WalkCBLevelAlloc, - _bar2WalkCBLevelFree, - _bar2WalkCBUpdatePdb, - _bar2WalkCBUpdatePde, - _bar2WalkCBFillEntries, - NULL, - _bar2WalkCBWriteBuffer, + .LevelAlloc = _bar2WalkCBLevelAlloc, + .LevelFree = _bar2WalkCBLevelFree, + .UpdatePdb = _bar2WalkCBUpdatePdb, + .UpdatePde = _bar2WalkCBUpdatePde, + .FillEntries = _bar2WalkCBFillEntries, + .CopyEntries = NULL, + .WriteBuffer = _bar2WalkCBWriteBuffer, }; diff --git a/src/nvidia/src/kernel/gpu/mmu/gmmu_trace.c b/src/nvidia/src/kernel/gpu/mmu/gmmu_trace.c index 17dda40f4..6092316ea 100644 --- a/src/nvidia/src/kernel/gpu/mmu/gmmu_trace.c +++ b/src/nvidia/src/kernel/gpu/mmu/gmmu_trace.c @@ -546,17 +546,17 @@ _gmmuSwToHwLevel const MMU_TRACE_CALLBACKS g_gmmuTraceCallbacks = { - _gmmuIsPte, // isPte - _gmmuGetFmtPde, // getFmtPde - _gmmuGetFmtPte, // getFmtPte - _gmmuGetPdePa, // getPdePa - _gmmuGetPtePa, // getPtePa - _gmmuPrintPdb, // printPdb - _gmmuPrintPde, // printPde - _gmmuPrintPt, // printPt - _gmmuPrintPte, // printPte - _gmmuIsInvalidPdeOk, // isInvalidPdeOk - _gmmuPdeAddrSpace, // pdeAddrSpace - _gmmuPteAddrSpace, // pteAddrSpace - _gmmuSwToHwLevel, // swToHwLevel + .isPte = _gmmuIsPte, + .getFmtPde = _gmmuGetFmtPde, + .getFmtPte = _gmmuGetFmtPte, + .getPdePa = _gmmuGetPdePa, + .getPtePa = _gmmuGetPtePa, + .printPdb = _gmmuPrintPdb, + .printPde = _gmmuPrintPde, + .printPt = _gmmuPrintPt, + .printPte = _gmmuPrintPte, + .isInvalidPdeOk = _gmmuIsInvalidPdeOk, + .pdeAddrSpace = _gmmuPdeAddrSpace, + .pteAddrSpace = _gmmuPteAddrSpace, + .swToHwLevel = _gmmuSwToHwLevel, }; diff --git a/src/nvidia/src/kernel/gpu/mmu/gmmu_walk.c b/src/nvidia/src/kernel/gpu/mmu/gmmu_walk.c index f72063c78..9b735c53b 100644 --- a/src/nvidia/src/kernel/gpu/mmu/gmmu_walk.c +++ b/src/nvidia/src/kernel/gpu/mmu/gmmu_walk.c @@ -1002,11 +1002,11 @@ _gmmuWalkCBCopyEntries const MMU_WALK_CALLBACKS g_gmmuWalkCallbacks = { - _gmmuWalkCBLevelAlloc, - _gmmuWalkCBLevelFree, - _gmmuWalkCBUpdatePdb, - _gmmuWalkCBUpdatePde, - _gmmuWalkCBFillEntries, - _gmmuWalkCBCopyEntries, - NULL, + .LevelAlloc = _gmmuWalkCBLevelAlloc, + .LevelFree = _gmmuWalkCBLevelFree, + .UpdatePdb = _gmmuWalkCBUpdatePdb, + .UpdatePde = _gmmuWalkCBUpdatePde, + .FillEntries = _gmmuWalkCBFillEntries, + .CopyEntries = _gmmuWalkCBCopyEntries, + .WriteBuffer = NULL, }; From 6e5d31985b91ff3d171426bb9020aa2c2027fbb0 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Wed, 18 Mar 2026 16:37:52 -0400 Subject: [PATCH 16/37] nvidia: make GPUHWREG use flexible arrays Make the union of GPUHWREG use proper flexible arrays to avoid UBSAN out-of-bounds warnings when accessing hardware registers. Signed-off-by: Mathias Krause --- src/common/sdk/nvidia/inc/nv-stddef.h | 8 ++++++++ src/nvidia/generated/g_gpu_access_nvoc.h | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/common/sdk/nvidia/inc/nv-stddef.h b/src/common/sdk/nvidia/inc/nv-stddef.h index 5ef838b56..cc9cb5b46 100644 --- a/src/common/sdk/nvidia/inc/nv-stddef.h +++ b/src/common/sdk/nvidia/inc/nv-stddef.h @@ -35,4 +35,12 @@ #include // NULL #endif +#ifndef __DECLARE_FLEX_ARRAY + #ifdef __cplusplus + #define __DECLARE_FLEX_ARRAY(T, field) T field[0] + #else + #define __DECLARE_FLEX_ARRAY(T, field) T field[] + #endif +#endif + #endif // _NV_STDDEF_H_ diff --git a/src/nvidia/generated/g_gpu_access_nvoc.h b/src/nvidia/generated/g_gpu_access_nvoc.h index e644e0121..b00aa7d47 100644 --- a/src/nvidia/generated/g_gpu_access_nvoc.h +++ b/src/nvidia/generated/g_gpu_access_nvoc.h @@ -69,9 +69,9 @@ typedef NvU32 (*GpuReadRegCallback)(OBJGPU *, void *, NvU32 addr, NvU32 accessSi union GPUHWREG { - volatile NvV8 Reg008[1]; - volatile NvV16 Reg016[1]; - volatile NvV32 Reg032[1]; + volatile __DECLARE_FLEX_ARRAY(NvV8, Reg008); + volatile __DECLARE_FLEX_ARRAY(NvV16, Reg016); + volatile __DECLARE_FLEX_ARRAY(NvV32, Reg032); }; typedef union GPUHWREG GPUHWREG; From 23f1e7c67fbda7ff64b8d12022caff9d321c2237 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Thu, 27 Nov 2025 10:26:21 +0000 Subject: [PATCH 17/37] x86emu: drop dependency on Define 'NULL' directly instead of depending on system headers to do so. Signed-off-by: Mathias Krause --- src/nvidia/arch/nvalloc/unix/include/x86emu/x86emui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvidia/arch/nvalloc/unix/include/x86emu/x86emui.h b/src/nvidia/arch/nvalloc/unix/include/x86emu/x86emui.h index 5788558d8..0ce30835d 100644 --- a/src/nvidia/arch/nvalloc/unix/include/x86emu/x86emui.h +++ b/src/nvidia/arch/nvalloc/unix/include/x86emu/x86emui.h @@ -51,7 +51,7 @@ #ifndef NO_SYS_HEADERS #define NO_SYS_HEADERS #endif -#include /* NULL */ +#define NULL ((void *)0) #if defined(__cplusplus) && !defined(_NO_INLINE) #define _INLINE inline #else From 7c70a05a42d16b0194f88d21c8777cf1024aa121 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Thu, 26 Feb 2026 20:49:37 +0000 Subject: [PATCH 18/37] kernel-open/Kbuild: fix potential duplicated CFLAGS The ASSIGN_PER_OBJ_CFLAGS helper tries to support older kbuild versions that used the full path as the target-stem by not only assigning the basenamed "CFLAGS_" variable but also one with the full path. However, if the object file's directory part is empty, ASSIGN_PER_OBJ_CFLAGS would add the flags twice, as "$(notdir $(1))" and "$(1)" evaluate to the same. Avoid that by filtering duplicates via $(sort ...). Signed-off-by: Mathias Krause --- kernel-open/Kbuild | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel-open/Kbuild b/kernel-open/Kbuild index 60181c7f0..9f2d0435a 100644 --- a/kernel-open/Kbuild +++ b/kernel-open/Kbuild @@ -39,7 +39,7 @@ NV_BUILD_TYPE ?= release # ASSIGN_PER_OBJ_CFLAGS = \ $(foreach _cflags_variable, \ - $(notdir $(1)) $(1), \ + $(sort $(notdir $(1)) $(1)), \ $(eval $(addprefix CFLAGS_,$(_cflags_variable)) += $(2))) From 9947da36a262b5d93569c91531a21c7021921aca Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Tue, 10 Feb 2026 09:54:38 +0000 Subject: [PATCH 19/37] kernel-open/Kbuild: CFLAGS_REMOVE support Provide an ASSIGN_PER_OBJ_CFLAGS_REMOVE macro to be able to set per-object-file CFLAGS_REMOVE variables. For it to be effective, move the *.Kbuild include to after setting early cflags, allowing to override these via ASSIGN_PER_OBJ_CFLAGS_REMOVE. Signed-off-by: Mathias Krause --- kernel-open/Kbuild | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/kernel-open/Kbuild b/kernel-open/Kbuild index 9f2d0435a..1c0e3851e 100644 --- a/kernel-open/Kbuild +++ b/kernel-open/Kbuild @@ -42,6 +42,14 @@ ASSIGN_PER_OBJ_CFLAGS = \ $(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))) + # # Include the specifics of the individual NVIDIA kernel modules. @@ -70,13 +78,15 @@ endif quiet_cmd_symlink = SYMLINK $@ cmd_symlink = ln -sf $(abspath $<) $@ +# 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 += -I$(src)/common/inc -ccflags-y += -I$(src) 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\" From 2c1dee51fca52f9e5a90e40c472fa4746fdb5d32 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Tue, 10 Feb 2026 10:37:55 +0000 Subject: [PATCH 20/37] kernel-open/Kbuild: NVIDSTRING support Add support for the GENERATE_NVIDSTRING macro for pure kbuild-based builds. Signed-off-by: Mathias Krause --- kernel-open/Kbuild | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/kernel-open/Kbuild b/kernel-open/Kbuild index 1c0e3851e..20478b072 100644 --- a/kernel-open/Kbuild +++ b/kernel-open/Kbuild @@ -51,6 +51,68 @@ ASSIGN_PER_OBJ_CFLAGS_REMOVE = \ $(eval $(addprefix CFLAGS_REMOVE_,$(_cflags_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. # From 405804c912951e4cf9c2ca5c4d9edba108d138d9 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Thu, 26 Feb 2026 20:59:12 +0000 Subject: [PATCH 21/37] kernel-open/Kbuild: LDFLAGS and OBJCOPYFLAGS support Provide ASSIGN_PER_OBJ_LDFLAGS and ASSIGN_PER_OBJ_OBJCOPYFLAGS macros that can be used to to set per-object-file LDFLAGS and OBJCOPYFLAGS variables. Signed-off-by: Mathias Krause --- kernel-open/Kbuild | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/kernel-open/Kbuild b/kernel-open/Kbuild index 20478b072..2baa133b2 100644 --- a/kernel-open/Kbuild +++ b/kernel-open/Kbuild @@ -50,6 +50,22 @@ ASSIGN_PER_OBJ_CFLAGS_REMOVE = \ $(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 From 6b0c069f94c3b5ee02eaa3e04c3420d0ef77b534 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Tue, 10 Feb 2026 10:43:56 +0000 Subject: [PATCH 22/37] kernel-open/Kbuild: stub module support Add rules to work around kbuild's lack of compound object file support for modules. It's implemented by building stub modules composed of the object files intended to group plus kernel-open/common/mod_stub.o for the .modinfo bits which get stripped by an intermediate objcopy call. The stub module should be named $foo.stub.o, the created (and depended on) object file will be called $foo.clean.o. Signed-off-by: Mathias Krause --- kernel-open/Kbuild | 24 ++++++++++++++++++++++++ kernel-open/common/mod_stub.c | 4 ++++ 2 files changed, 28 insertions(+) create mode 100644 kernel-open/common/mod_stub.c diff --git a/kernel-open/Kbuild b/kernel-open/Kbuild index 2baa133b2..7905c9f13 100644 --- a/kernel-open/Kbuild +++ b/kernel-open/Kbuild @@ -156,6 +156,30 @@ 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 ... +# + +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) diff --git a/kernel-open/common/mod_stub.c b/kernel-open/common/mod_stub.c new file mode 100644 index 000000000..f3584c952 --- /dev/null +++ b/kernel-open/common/mod_stub.c @@ -0,0 +1,4 @@ +/* Stub module fragment for emulated nested compound object kbuild support */ +#include + +MODULE_LICENSE("Dual MIT/GPL"); From f8481c080aa89c02676e230ed20e5f7318242c7d Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Tue, 10 Feb 2026 10:48:06 +0000 Subject: [PATCH 23/37] kernel-open: introduce module preparation step Don't build the regular modules during preparation, which is an intermediate step for full kbuild support. Signed-off-by: Mathias Krause --- kernel-open/Makefile | 8 ++++++++ kernel-open/nvidia-drm/nvidia-drm.Kbuild | 2 ++ kernel-open/nvidia-modeset/nvidia-modeset.Kbuild | 2 ++ kernel-open/nvidia-peermem/nvidia-peermem.Kbuild | 2 ++ kernel-open/nvidia-uvm/nvidia-uvm.Kbuild | 2 ++ kernel-open/nvidia/nvidia.Kbuild | 4 ++++ 6 files changed, 20 insertions(+) diff --git a/kernel-open/Makefile b/kernel-open/Makefile index 50565d934..01c3fd936 100644 --- a/kernel-open/Makefile +++ b/kernel-open/Makefile @@ -141,6 +141,14 @@ 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: diff --git a/kernel-open/nvidia-drm/nvidia-drm.Kbuild b/kernel-open/nvidia-drm/nvidia-drm.Kbuild index 892fa4dab..9998773fd 100644 --- a/kernel-open/nvidia-drm/nvidia-drm.Kbuild +++ b/kernel-open/nvidia-drm/nvidia-drm.Kbuild @@ -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 diff --git a/kernel-open/nvidia-modeset/nvidia-modeset.Kbuild b/kernel-open/nvidia-modeset/nvidia-modeset.Kbuild index 15694fe5d..bb7ca8edc 100644 --- a/kernel-open/nvidia-modeset/nvidia-modeset.Kbuild +++ b/kernel-open/nvidia-modeset/nvidia-modeset.Kbuild @@ -11,8 +11,10 @@ NVIDIA_MODESET_SOURCES += nvidia-modeset/nv-kthread-q.c NVIDIA_MODESET_OBJECTS = $(patsubst %.c,%.o,$(NVIDIA_MODESET_SOURCES)) +ifneq ($(NV_PREPARE_ONLY),1) obj-m += nvidia-modeset.o nvidia-modeset-y := $(NVIDIA_MODESET_OBJECTS) +endif NVIDIA_MODESET_KO = nvidia-modeset/nvidia-modeset.ko diff --git a/kernel-open/nvidia-peermem/nvidia-peermem.Kbuild b/kernel-open/nvidia-peermem/nvidia-peermem.Kbuild index d2bcaf8d0..c52a74ed1 100644 --- a/kernel-open/nvidia-peermem/nvidia-peermem.Kbuild +++ b/kernel-open/nvidia-peermem/nvidia-peermem.Kbuild @@ -11,8 +11,10 @@ NVIDIA_PEERMEM_SOURCES += nvidia-peermem/nvidia-peermem.c NVIDIA_PEERMEM_OBJECTS = $(patsubst %.c,%.o,$(NVIDIA_PEERMEM_SOURCES)) +ifneq ($(NV_PREPARE_ONLY),1) obj-m += nvidia-peermem.o nvidia-peermem-y := $(NVIDIA_PEERMEM_OBJECTS) +endif NVIDIA_PEERMEM_KO = nvidia-peermem/nvidia-peermem.ko diff --git a/kernel-open/nvidia-uvm/nvidia-uvm.Kbuild b/kernel-open/nvidia-uvm/nvidia-uvm.Kbuild index c33f5c2f4..6df0d381c 100644 --- a/kernel-open/nvidia-uvm/nvidia-uvm.Kbuild +++ b/kernel-open/nvidia-uvm/nvidia-uvm.Kbuild @@ -13,8 +13,10 @@ NVIDIA_UVM_OBJECTS = include $(src)/nvidia-uvm/nvidia-uvm-sources.Kbuild NVIDIA_UVM_OBJECTS += $(patsubst %.c,%.o,$(NVIDIA_UVM_SOURCES)) +ifneq ($(NV_PREPARE_ONLY),1) obj-m += nvidia-uvm.o nvidia-uvm-y := $(NVIDIA_UVM_OBJECTS) +endif NVIDIA_UVM_KO = nvidia-uvm/nvidia-uvm.ko diff --git a/kernel-open/nvidia/nvidia.Kbuild b/kernel-open/nvidia/nvidia.Kbuild index 8b05205d4..bd9c0f4ba 100644 --- a/kernel-open/nvidia/nvidia.Kbuild +++ b/kernel-open/nvidia/nvidia.Kbuild @@ -9,8 +9,10 @@ include $(src)/nvidia/nvidia-sources.Kbuild NVIDIA_OBJECTS = $(patsubst %.c,%.o,$(NVIDIA_SOURCES)) +ifneq ($(NV_PREPARE_ONLY),1) obj-m += nvidia.o nvidia-y := $(NVIDIA_OBJECTS) +endif NVIDIA_KO = nvidia/nvidia.ko @@ -96,8 +98,10 @@ NVIDIA_INTERFACE := nvidia/nv-interface.o # before v5.6 looks at "always"; kernel versions between v5.12 and v5.6 # look at both. +ifneq ($(NV_PREPARE_ONLY),1) always += $(NVIDIA_INTERFACE) always-y += $(NVIDIA_INTERFACE) +endif $(obj)/$(NVIDIA_INTERFACE): $(addprefix $(obj)/,$(NVIDIA_OBJECTS)) $(LD) -r -o $@ $^ From 8eec7471fd67723068a5c960a250a93100cf4410 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Tue, 9 Dec 2025 19:41:45 +0000 Subject: [PATCH 24/37] src/nvidia: move CFLAGS to defs.mk Extract compiler flags into defs.mk for reuse by upcomming kbuild support. Signed-off-by: Mathias Krause --- src/nvidia/Makefile | 78 +++---------------------------------------- src/nvidia/defs.mk | 81 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 74 deletions(-) create mode 100644 src/nvidia/defs.mk diff --git a/src/nvidia/Makefile b/src/nvidia/Makefile index d1d6d8663..686d36c3b 100644 --- a/src/nvidia/Makefile +++ b/src/nvidia/Makefile @@ -9,6 +9,7 @@ VERSION_MK_DIR = ../../ include ../../utils.mk include srcs.mk +include defs.mk ############################################################################## # Helper functions to determine the compiler type @@ -22,54 +23,17 @@ GET_COMPILER_TYPE = \ ALL_SRCS = $(SRCS) $(SRCS_CXX) ALL_SRCS += $(NVIDSTRING) -SRC_COMMON = ../common CONDITIONAL_CFLAGS := -CFLAGS += -include $(SRC_COMMON)/sdk/nvidia/inc/cpuopsys.h - -CFLAGS += -I kernel/inc -CFLAGS += -I interface -CFLAGS += -I $(SRC_COMMON)/sdk/nvidia/inc -CFLAGS += -I $(SRC_COMMON)/sdk/nvidia/inc/hw -CFLAGS += -I arch/nvalloc/common/inc -CFLAGS += -I arch/nvalloc/common/inc/gsp -CFLAGS += -I arch/nvalloc/common/inc/deprecated -CFLAGS += -I arch/nvalloc/unix/include -CFLAGS += -I inc -CFLAGS += -I inc/os -CFLAGS += -I $(SRC_COMMON)/shared/inc -CFLAGS += -I $(SRC_COMMON)/shared/msgq/inc -CFLAGS += -I $(SRC_COMMON)/inc - -CFLAGS += -I $(SRC_COMMON)/uproc/os/libos-v2.0.0/include -CFLAGS += -I $(SRC_COMMON)/uproc/os/common/include -CFLAGS += -I $(SRC_COMMON)/inc/swref -CFLAGS += -I $(SRC_COMMON)/inc/swref/published - -CFLAGS += -I generated -CFLAGS += -I $(SRC_COMMON)/nvswitch/kernel/inc -CFLAGS += -I $(SRC_COMMON)/nvswitch/interface -CFLAGS += -I $(SRC_COMMON)/nvswitch/common/inc/ -CFLAGS += -I $(SRC_COMMON)/inc/displayport -CFLAGS += -I $(SRC_COMMON)/nvlink/interface/ -CFLAGS += -I $(SRC_COMMON)/nvlink/inband/interface -CFLAGS += -I src/mm/uvm/interface -CFLAGS += -I inc/libraries -CFLAGS += -I src/libraries -CFLAGS += -I inc/kernel +CFLAGS += $(addprefix -include ,$(NV_INCLUDE)) +CFLAGS += $(addprefix -I ,$(NV_INCDIRS)) +CFLAGS += $(NV_DEFINES) # Libspdm source requires additional include paths and build flags. include src/libraries/libspdm/nvidia/openspdm.mk $(call BUILD_OBJECT_LIST,$(LIBSPDM_SOURCES)): CFLAGS += $(addprefix -I ,$(LIBSPDM_INCLUDES)) $(call BUILD_OBJECT_LIST,$(LIBSPDM_SOURCES)): CFLAGS += $(addprefix -D,$(LIBSPDM_DEFINES)) -#if NV_USE_MBEDTLS -MBEDTLS_VERSION ?= 3.6.2 -CFLAGS += -I $(SRC_COMMON)/mbedtls/$(MBEDTLS_VERSION)/include -CFLAGS += -I $(SRC_COMMON)/mbedtls/$(MBEDTLS_VERSION)/nvidia -CFLAGS += -D"MBEDTLS_USER_CONFIG_FILE=" -#endif - CFLAGS += -Werror-implicit-function-declaration CFLAGS += -Wwrite-strings CFLAGS += -Wundef @@ -104,40 +68,6 @@ endif CFLAGS += -fno-pic -CFLAGS += -D_LANGUAGE_C -CFLAGS += -D__NO_CTYPE -CFLAGS += -DNVRM -CFLAGS += -DLOCK_VAL_ENABLED=0 -CFLAGS += -DPORT_ATOMIC_64_BIT_SUPPORTED=1 -CFLAGS += -DPORT_IS_KERNEL_BUILD=1 -CFLAGS += -DPORT_IS_CHECKED_BUILD=0 -CFLAGS += -DPORT_MODULE_atomic=1 -CFLAGS += -DPORT_MODULE_core=1 -CFLAGS += -DPORT_MODULE_cpu=1 -CFLAGS += -DPORT_MODULE_crypto=1 -CFLAGS += -DPORT_MODULE_debug=1 -CFLAGS += -DPORT_MODULE_memory=1 -CFLAGS += -DPORT_MODULE_safe=1 -CFLAGS += -DPORT_MODULE_string=1 -CFLAGS += -DPORT_MODULE_sync=1 -CFLAGS += -DPORT_MODULE_thread=1 -CFLAGS += -DPORT_MODULE_util=1 -CFLAGS += -DPORT_MODULE_example=0 -CFLAGS += -DPORT_MODULE_mmio=0 -CFLAGS += -DPORT_MODULE_time=0 -CFLAGS += -DRS_STANDALONE=0 -CFLAGS += -DRS_STANDALONE_TEST=0 -CFLAGS += -DRS_COMPATABILITY_MODE=1 -CFLAGS += -DRS_PROVIDES_API_STATE=0 -CFLAGS += -DNV_CONTAINERS_NO_TEMPLATES - -CFLAGS += -DINCLUDE_NVLINK_LIB -CFLAGS += -DINCLUDE_NVSWITCH_LIB - -CFLAGS += -DNV_PRINTF_STRINGS_ALLOWED=1 -CFLAGS += -DNV_ASSERT_FAILED_USES_STRINGS=1 -CFLAGS += -DPORT_ASSERT_FAILED_USES_STRINGS=1 - ifeq ($(DEBUG),1) CFLAGS += -gsplit-dwarf endif diff --git a/src/nvidia/defs.mk b/src/nvidia/defs.mk new file mode 100644 index 000000000..96af68db9 --- /dev/null +++ b/src/nvidia/defs.mk @@ -0,0 +1,81 @@ +# shared make defines for Makefile and Kbuild + +SRC_COMMON := ../common + +NV_INCLUDE := +NV_INCDIRS := +NV_DEFINES := + +NV_INCLUDE += $(SRC_COMMON)/sdk/nvidia/inc/cpuopsys.h + +NV_INCDIRS += kernel/inc +NV_INCDIRS += interface +NV_INCDIRS += $(SRC_COMMON)/sdk/nvidia/inc +NV_INCDIRS += $(SRC_COMMON)/sdk/nvidia/inc/hw +NV_INCDIRS += arch/nvalloc/common/inc +NV_INCDIRS += arch/nvalloc/common/inc/gsp +NV_INCDIRS += arch/nvalloc/common/inc/deprecated +NV_INCDIRS += arch/nvalloc/unix/include +NV_INCDIRS += inc +NV_INCDIRS += inc/os +NV_INCDIRS += $(SRC_COMMON)/shared/inc +NV_INCDIRS += $(SRC_COMMON)/shared/msgq/inc +NV_INCDIRS += $(SRC_COMMON)/inc + +NV_INCDIRS += $(SRC_COMMON)/uproc/os/libos-v2.0.0/include +NV_INCDIRS += $(SRC_COMMON)/uproc/os/common/include +NV_INCDIRS += $(SRC_COMMON)/inc/swref +NV_INCDIRS += $(SRC_COMMON)/inc/swref/published + +NV_INCDIRS += generated +NV_INCDIRS += $(SRC_COMMON)/nvswitch/kernel/inc +NV_INCDIRS += $(SRC_COMMON)/nvswitch/interface +NV_INCDIRS += $(SRC_COMMON)/nvswitch/common/inc/ +NV_INCDIRS += $(SRC_COMMON)/inc/displayport +NV_INCDIRS += $(SRC_COMMON)/nvlink/interface/ +NV_INCDIRS += $(SRC_COMMON)/nvlink/inband/interface +NV_INCDIRS += src/mm/uvm/interface +NV_INCDIRS += inc/libraries +NV_INCDIRS += src/libraries +NV_INCDIRS += inc/kernel + +#if NV_USE_MBEDTLS +MBEDTLS_VERSION ?= 3.6.2 +NV_INCDIRS += $(SRC_COMMON)/mbedtls/$(MBEDTLS_VERSION)/include +NV_INCDIRS += $(SRC_COMMON)/mbedtls/$(MBEDTLS_VERSION)/nvidia +NV_DEFINES += -D"MBEDTLS_USER_CONFIG_FILE=" +#endif + +NV_DEFINES += -D_LANGUAGE_C +NV_DEFINES += -D__NO_CTYPE +NV_DEFINES += -DNVRM +NV_DEFINES += -DLOCK_VAL_ENABLED=0 +NV_DEFINES += -DPORT_ATOMIC_64_BIT_SUPPORTED=1 +NV_DEFINES += -DPORT_IS_KERNEL_BUILD=1 +NV_DEFINES += -DPORT_IS_CHECKED_BUILD=0 +NV_DEFINES += -DPORT_MODULE_atomic=1 +NV_DEFINES += -DPORT_MODULE_core=1 +NV_DEFINES += -DPORT_MODULE_cpu=1 +NV_DEFINES += -DPORT_MODULE_crypto=1 +NV_DEFINES += -DPORT_MODULE_debug=1 +NV_DEFINES += -DPORT_MODULE_memory=1 +NV_DEFINES += -DPORT_MODULE_safe=1 +NV_DEFINES += -DPORT_MODULE_string=1 +NV_DEFINES += -DPORT_MODULE_sync=1 +NV_DEFINES += -DPORT_MODULE_thread=1 +NV_DEFINES += -DPORT_MODULE_util=1 +NV_DEFINES += -DPORT_MODULE_example=0 +NV_DEFINES += -DPORT_MODULE_mmio=0 +NV_DEFINES += -DPORT_MODULE_time=0 +NV_DEFINES += -DRS_STANDALONE=0 +NV_DEFINES += -DRS_STANDALONE_TEST=0 +NV_DEFINES += -DRS_COMPATABILITY_MODE=1 +NV_DEFINES += -DRS_PROVIDES_API_STATE=0 +NV_DEFINES += -DNV_CONTAINERS_NO_TEMPLATES + +NV_DEFINES += -DINCLUDE_NVLINK_LIB +NV_DEFINES += -DINCLUDE_NVSWITCH_LIB + +NV_DEFINES += -DNV_PRINTF_STRINGS_ALLOWED=1 +NV_DEFINES += -DNV_ASSERT_FAILED_USES_STRINGS=1 +NV_DEFINES += -DPORT_ASSERT_FAILED_USES_STRINGS=1 From fb77ed328a60fc4e1ad470bdbeaef1a59327eeff Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Thu, 26 Feb 2026 21:03:02 +0000 Subject: [PATCH 25/37] src/nvidia: move LINKER_SCRIPT and EXPORTS_LINK_COMMAND to srcs.mk Move the definitions of LINKER_SCRIPT and EXPORTS_LINK_COMMAND to srcs.mk. Signed-off-by: Mathias Krause --- src/nvidia/Makefile | 3 --- src/nvidia/srcs.mk | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nvidia/Makefile b/src/nvidia/Makefile index 686d36c3b..9a8aef1e9 100644 --- a/src/nvidia/Makefile +++ b/src/nvidia/Makefile @@ -80,7 +80,6 @@ endif CFLAGS += -ffunction-sections CFLAGS += -fdata-sections NV_KERNEL_O_LDFLAGS += --gc-sections -EXPORTS_LINK_COMMAND = exports_link_command.txt ifeq ($(TARGET_ARCH),x86_64) COMPILER_TYPE := $(call GET_COMPILER_TYPE, $(CC)) @@ -137,8 +136,6 @@ NV_KERNEL_O = $(OUTPUTDIR)/nv-kernel.o .PHONY: all all: $(NV_KERNEL_O) -LINKER_SCRIPT = nv-kernel.ld - NV_KERNEL_O_LDFLAGS += $(LDFLAGS) $(NV_KERNEL_O): $(OBJS) $(EXPORTS_LINK_COMMAND) $(LINKER_SCRIPT) diff --git a/src/nvidia/srcs.mk b/src/nvidia/srcs.mk index 675167f37..3e42a15e4 100644 --- a/src/nvidia/srcs.mk +++ b/src/nvidia/srcs.mk @@ -1017,3 +1017,6 @@ SRCS += src/libraries/utils/nvassert.c SRCS += ../common/uproc/os/libos-v3.1.0/lib/libdwarf.c SRCS += ../common/uproc/os/libos-v3.1.0/lib/libelf.c SRCS += ../common/uproc/os/libos-v3.1.0/lib/liblogdecode.c + +LINKER_SCRIPT := nv-kernel.ld +EXPORTS_LINK_COMMAND := exports_link_command.txt From 3b6a3b31f8feebd06b0e559280f5a2f51c3156fe Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Tue, 10 Feb 2026 09:08:07 +0000 Subject: [PATCH 26/37] src/nvidia: preliminary kbuild support Provide a Kbuild file to be able to build src/nvidia/ using Linux's kbuild. It's meant to be included by kernel-open/nvidia/. Signed-off-by: Mathias Krause --- src/nvidia/nvidia.Kbuild | 92 ++++++++++++++++++++++++++++++++++++++++ src/nvidia/srcs.mk | 4 +- 2 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 src/nvidia/nvidia.Kbuild diff --git a/src/nvidia/nvidia.Kbuild b/src/nvidia/nvidia.Kbuild new file mode 100644 index 000000000..90787377a --- /dev/null +++ b/src/nvidia/nvidia.Kbuild @@ -0,0 +1,92 @@ +########################################################################### +# nvidia.Kbuild, included by kernel-open/nvidia/nvidia.Kbuild +########################################################################### + +nvidia_src ?= . + +NV_KERNEL_O = nv-kernel.clean.o +NV_KERNEL_O_OBJS = $(nv-kernel-objs) + +include $(src)/$(nvidia_src)/srcs.mk +include $(src)/$(nvidia_src)/defs.mk + +# The source files for nv-kernel.o are all SRCS and SRCS_CXX defined in +# srcs.mk, and the NVIDIA ID string +SRCS := $(addprefix $(nvidia_src)/,$(SRCS)) +SRCS_CXX := $(addprefix $(nvidia_src)/,$(SRCS_CXX)) +NVIDSTRING := $(addprefix $(nvidia_src)/,g_nvid_string.c) + +nv-kernel-objs := $(SRCS:.c=.o) +nv-kernel-objs += $(SRCS_CXX:.cpp=.o) +nv-kernel-objs += $(NVIDSTRING:.c=.o) + +# Hack to create a relocatable intermediate object file to avoid '/bin/sh: +# Argument list too long' errors for the real module. +ifeq ($(NV_PREPARE_ONLY),1) +obj-m += nv-kernel.stub.o +nv-kernel.stub-y := $(nv-kernel-objs) $(MOD_STUB) +endif + +# for the 'clean' target +targets += $(nv-kernel-objs) +# ensure to use "our" NVIDSTRING +$(eval targets += $(NVIDSTRING)) + +# Define how to generate the NVIDIA ID string -- intentionally deviates from +# the OS-agnostic build +$(eval $(call GENERATE_NVIDSTRING, \ + NVRM_ID, \ + Linux Open Kernel Module, $(nv-kernel-objs))) + +# now compile the final ccflags +nv-kernel-cflags := $(addprefix -include $(src)/$(nvidia_src)/,$(NV_INCLUDE)) +nv-kernel-cflags += $(addprefix -I $(src)/$(nvidia_src)/,$(NV_INCDIRS)) +nv-kernel-cflags += $(NV_DEFINES) + +# quite some implicit fall-through cases +nv-kernel-cflags += -Wno-implicit-fallthrough +# lots of missing prototypes, all accross the board +nv-kernel-cflags-remove := -Wmissing-declarations -Wmissing-prototypes + +# Define how to perform dead code elimination: place each symbol in its own +# section at compile time, and garbage collect unreachable sections at link +# time. exports_link_command.txt tells the linker which symbols need to be +# exported from $(NV_KERNEL_O) so the linker can determine which symbols are +# unreachable. +nv-kernel-cflags += -ffunction-sections +nv-kernel-cflags += -fdata-sections + +nv-kernel-ldflags := --gc-sections +nv-kernel-ldflags += @$(src)/$(nvidia_src)/$(EXPORTS_LINK_COMMAND) +nv-kernel-ldflags += -T $(src)/$(nvidia_src)/$(LINKER_SCRIPT) + +nv-kernel-objcopyflags := --localize-symbol=memset +nv-kernel-objcopyflags += --localize-symbol=memcpy +#nv-kernel-objcopyflags += --remove-section=.note.gnu.property + +# move early -I... flags to after ours -- what a hack! +ccflags-includes := $(filter -I$(src)%,$(ccflags-y)) +nv-kernel-cflags += $(patsubst -I%,-I %,$(ccflags-includes)) +nv-kernel-cflags-remove += $(ccflags-includes) + +$(call ASSIGN_PER_OBJ_CFLAGS_REMOVE, $(nv-kernel-objs), $(nv-kernel-cflags-remove)) +$(call ASSIGN_PER_OBJ_CFLAGS, $(nv-kernel-objs), $(nv-kernel-cflags)) +$(call ASSIGN_PER_OBJ_LDFLAGS, nv-kernel.stub.o, $(nv-kernel-ldflags)) +$(call ASSIGN_PER_OBJ_OBJCOPYFLAGS, nv-kernel.clean.o, $(nv-kernel-objcopyflags)) + +$(obj)/nv-kernel.stub.o: $(addprefix $(obj)/$(nvidia_src)/,\ + $(EXPORTS_LINK_COMMAND) $(LINKER_SCRIPT)) + +## Libspdm source requires additional include paths and build flags. +include $(src)/$(nvidia_src)/src/libraries/libspdm/nvidia/openspdm.mk +# is sufficient to get all required defines and types +LIBSPDM_DEFINES += "LIBSPDM_STDINT_ALT=" +LIBSPDM_DEFINES += "LIBSPDM_STDBOOL_ALT=" +LIBSPDM_DEFINES += "LIBSPDM_STDDEF_ALT=" + +libspdm-objs := $(addprefix $(nvidia_src)/,$(LIBSPDM_SOURCES:.c=.o)) + +libspdm-cflags := $(addprefix -I $(src)/$(nvidia_src)/,$(LIBSPDM_INCLUDES)) +libspdm-cflags += $(addprefix -D,$(LIBSPDM_DEFINES)) + +$(call ASSIGN_PER_OBJ_CFLAGS, $(libspdm-objs), $(libspdm-cflags)) diff --git a/src/nvidia/srcs.mk b/src/nvidia/srcs.mk index 3e42a15e4..17acb032c 100644 --- a/src/nvidia/srcs.mk +++ b/src/nvidia/srcs.mk @@ -1,5 +1,5 @@ -SRCS ?= -SRCS_CXX ?= +SRCS := +SRCS_CXX := SRCS += generated/g_access_cntr_buffer_nvoc.c SRCS += generated/g_all_dcl_pb.c From e3cdae8395b48f77c070ddc6d202e5f215c5ef90 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Tue, 10 Feb 2026 09:56:46 +0000 Subject: [PATCH 27/37] kernel-open/nvidia: Kbuild support Support building the dependent src/nv-kernel.o using Linux's kbuild. Signed-off-by: Mathias Krause --- kernel-open/nvidia/nvidia.Kbuild | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kernel-open/nvidia/nvidia.Kbuild b/kernel-open/nvidia/nvidia.Kbuild index bd9c0f4ba..498d23eba 100644 --- a/kernel-open/nvidia/nvidia.Kbuild +++ b/kernel-open/nvidia/nvidia.Kbuild @@ -14,6 +14,17 @@ obj-m += nvidia.o nvidia-y := $(NVIDIA_OBJECTS) endif +ifeq ($(USE_KBUILD),1) +# build nv-kernel.o using Linux's kbuild system +nvidia_src := ../src/nvidia +include $(src)/$(nvidia_src)/nvidia.Kbuild + +nvidia-y += $(NV_KERNEL_O) + +NV_OBJECTS_DEPEND_ON_CONFTEST += $(NV_KERNEL_O_OBJS) + +else # !USE_KBUILD + NVIDIA_KO = nvidia/nvidia.ko @@ -48,6 +59,7 @@ $(obj)/$(NVIDIA_BINARY_OBJECT_O): $(NVIDIA_BINARY_OBJECT) FORCE $(call if_changed,symlink) nvidia-y += $(NVIDIA_BINARY_OBJECT_O) +endif # From 17ce643814ae99be99ba6731a18f7476121a8c84 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Tue, 10 Feb 2026 09:38:49 +0000 Subject: [PATCH 28/37] kernel-open: pass C++ compiler variable to sub-make Try to deduce a fitting C++ compiler from the kernel's config and pass it as CXX to the kernel's make file. This is required for the upcomming kbuild support. Signed-off-by: Mathias Krause --- kernel-open/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel-open/Makefile b/kernel-open/Makefile index 01c3fd936..0ddea676f 100644 --- a/kernel-open/Makefile +++ b/kernel-open/Makefile @@ -64,6 +64,7 @@ else from CONFIG_CC_VERSION_TEXT in the kernel configuration.) else CC=$(cc_version_text) + CXX=$(subst cc,++,$(cc_version_text)) endif endif endif @@ -79,6 +80,7 @@ else 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++ @@ -152,7 +154,7 @@ else .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 \ From b60c08e4f1d25d0bdebba59c90b09c5ff6cdae9e Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Mon, 9 Feb 2026 21:33:27 +0000 Subject: [PATCH 29/37] Make nv-stddef.h C++-aware and use it in nvdp-host.cpp Wrap C++-defined types and keywords prior to including Linux kernel headers to avoid clashing with the ones defined there. This is required for the upcoming kbuild support which cannot make use of standard system headers but has to rely on kernel headers. Signed-off-by: Mathias Krause --- src/common/sdk/nvidia/inc/nv-stddef.h | 18 ++++++++++++++++++ src/nvidia-modeset/src/dp/nvdp-host.cpp | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/common/sdk/nvidia/inc/nv-stddef.h b/src/common/sdk/nvidia/inc/nv-stddef.h index cc9cb5b46..009f40ac7 100644 --- a/src/common/sdk/nvidia/inc/nv-stddef.h +++ b/src/common/sdk/nvidia/inc/nv-stddef.h @@ -28,9 +28,27 @@ #if defined(NV_KERNEL_INTERFACE_LAYER) && defined(__FreeBSD__) #include // NULL #elif defined(NV_KERNEL_INTERFACE_LAYER) && defined(NV_LINUX) + #ifdef __cplusplus + // Hack to prevent from redefining 'bool' + #define _Bool int + #define bool LINUX_bool + #define true LINUX_true + #define false LINUX_false + #endif #include // NULL #include // size_t #include // SIZE_MAX,... + #ifdef __cplusplus + #undef _Bool + #undef bool + #undef true + #undef false + // XXX: no fallback for pre-C++11 but we enforce it via -std=gnu++11 + #if __cplusplus >= 201103L + #undef NULL + #define NULL nullptr + #endif + #endif #else #include // NULL #endif diff --git a/src/nvidia-modeset/src/dp/nvdp-host.cpp b/src/nvidia-modeset/src/dp/nvdp-host.cpp index eb1128b06..18c7019fd 100644 --- a/src/nvidia-modeset/src/dp/nvdp-host.cpp +++ b/src/nvidia-modeset/src/dp/nvdp-host.cpp @@ -23,7 +23,7 @@ /* DisplayPort management routines */ -#include +#include #include "nvkms-utils.h" From 58f5ca350506813d90d12be26dfd8e06efc9b474 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Mon, 9 Feb 2026 21:34:10 +0000 Subject: [PATCH 30/37] nvidia-3d: always define XZ_INTERNAL_CRC32 Make sure to always declare xz_crc32_init() in xz.h as nvidia-3d-fermi.c unconditionally makes use of it. Signed-off-by: Mathias Krause --- src/common/unix/nvidia-3d/src/nvidia-3d-fermi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/unix/nvidia-3d/src/nvidia-3d-fermi.c b/src/common/unix/nvidia-3d/src/nvidia-3d-fermi.c index 6e28df205..d561a7e92 100644 --- a/src/common/unix/nvidia-3d/src/nvidia-3d-fermi.c +++ b/src/common/unix/nvidia-3d/src/nvidia-3d-fermi.c @@ -33,6 +33,7 @@ #include #include +#define XZ_INTERNAL_CRC32 1 #include #if NV_PUSH_ALLOW_FLOAT From cf4a56d19b6769b24905a1a26b30c3f3bb69ee8b Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Wed, 18 Mar 2026 11:00:53 -0400 Subject: [PATCH 31/37] dp/connectorimpl: always define DP_OPTION_AUTO_ENABLE_MST_STREAM_ENCR The preprocessor symbol DP_OPTION_AUTO_ENABLE_MST_STREAM_ENCR doesn't get defined by the build system, causing build errors under '-Werror=undef'. Fix that by providing a default definition of 0 for it. Signed-off-by: Mathias Krause --- src/common/displayport/inc/dp_connectorimpl.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/common/displayport/inc/dp_connectorimpl.h b/src/common/displayport/inc/dp_connectorimpl.h index c46bf265c..bdc955d9b 100644 --- a/src/common/displayport/inc/dp_connectorimpl.h +++ b/src/common/displayport/inc/dp_connectorimpl.h @@ -44,6 +44,10 @@ #include "dp_deviceimpl.h" #include "./dptestutil/dp_testmessage.h" +#ifndef DP_OPTION_AUTO_ENABLE_MST_STREAM_ENCR + #define DP_OPTION_AUTO_ENABLE_MST_STREAM_ENCR 0 +#endif + // HDCP abort codes #define HDCP_FLAGS_ABORT_DEVICE_REVOKED 0x00000800 // Abort due to a revoked device in DP1.2 topology #define HDCP_FLAGS_ABORT_DEVICE_INVALID 0x00080000 // Abort due to an invalid device in DP1.2 topology From daf2363f910080c37f16677938137d3e939fa25f Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Tue, 10 Feb 2026 09:32:46 +0000 Subject: [PATCH 32/37] src/nvidia-modeset: move CFLAGS to defs.mk, shaders to srcs.mk Extract compiler flags into defs.mk as well as shaders to srcs.mk for reuse by upcomming kbuild support. Signed-off-by: Mathias Krause --- src/nvidia-modeset/Makefile | 66 +++---------------------------------- src/nvidia-modeset/defs.mk | 62 ++++++++++++++++++++++++++++++++++ src/nvidia-modeset/srcs.mk | 7 ++++ 3 files changed, 74 insertions(+), 61 deletions(-) create mode 100644 src/nvidia-modeset/defs.mk diff --git a/src/nvidia-modeset/Makefile b/src/nvidia-modeset/Makefile index b54138cc4..a46354212 100644 --- a/src/nvidia-modeset/Makefile +++ b/src/nvidia-modeset/Makefile @@ -8,6 +8,7 @@ VERSION_MK_DIR = ../../ include ../../utils.mk include srcs.mk +include defs.mk ############################################################################## # Helper functions to determine the compiler type @@ -21,51 +22,11 @@ GET_COMPILER_TYPE = \ ALL_SRCS = $(SRCS) $(SRCS_CXX) ALL_SRCS += $(NVIDSTRING) -SRC_COMMON = ../common - CONDITIONAL_CFLAGS := -CFLAGS += -include $(SRC_COMMON)/sdk/nvidia/inc/cpuopsys.h - -CFLAGS += -I $(SRC_COMMON)/sdk/nvidia/inc -CFLAGS += -I $(SRC_COMMON)/sdk/nvidia/inc/hw -CFLAGS += -I $(SRC_COMMON)/shared/inc -CFLAGS += -I $(SRC_COMMON)/inc -CFLAGS += -I $(SRC_COMMON)/softfloat/nvidia -CFLAGS += -I $(SRC_COMMON)/softfloat/source/include -CFLAGS += -I $(SRC_COMMON)/softfloat/source/8086-SSE -CFLAGS += -I $(SRC_COMMON)/unix/common/utils/interface -CFLAGS += -I $(SRC_COMMON)/unix/common/inc -CFLAGS += -I $(SRC_COMMON)/modeset -CFLAGS += -I os-interface/include -CFLAGS += -I kapi/interface -CFLAGS += -I ../nvidia/arch/nvalloc/unix/include -CFLAGS += -I interface -CFLAGS += -I include -CFLAGS += -I kapi/include -CFLAGS += -I generated -CFLAGS += -I $(SRC_COMMON)/displayport/inc -CFLAGS += -I $(SRC_COMMON)/displayport/inc/dptestutil -CFLAGS += -I $(SRC_COMMON)/inc/displayport - -CFLAGS += -DNDEBUG -CFLAGS += -D_LANGUAGE_C -CFLAGS += -D__NO_CTYPE - -CFLAGS += -DNV_CPU_INTRINSICS_KERNEL -CFLAGS += -DNVHDMIPKT_RM_CALLS_INTERNAL=0 -CFLAGS += -DNVHDMIPKT_NVKMS - -# XXX it would be nice to only define these for appropriate files... -CFLAGS += -DSOFTFLOAT_ROUND_ODD -CFLAGS += -DSOFTFLOAT_FAST_DIV32TO16 -CFLAGS += -DSOFTFLOAT_FAST_DIV64TO32 - -# Tell nvtiming to use nvkms import functions -CFLAGS += -DNVT_USE_NVKMS - -# Tell SMG we're being compiled into kernel -CFLAGS += -DNV_SMG_IN_NVKMS +CFLAGS += $(addprefix -include ,$(NV_INCLUDE)) +CFLAGS += $(addprefix -I ,$(NV_INCDIRS)) +CFLAGS += $(NV_DEFINES) CFLAGS += -Wformat CFLAGS += -Wreturn-type @@ -172,19 +133,6 @@ CXX_ONLY_CFLAGS += -fcheck-new SHADER_OBJS = -CFLAGS += -I $(SRC_COMMON)/unix/nvidia-3d/interface -CFLAGS += -I $(SRC_COMMON)/unix/nvidia-push/interface -CFLAGS += -I $(SRC_COMMON)/unix/nvidia-3d/include -CFLAGS += -I $(SRC_COMMON)/unix/nvidia-push/include -CFLAGS += -I $(SRC_COMMON)/unix/xzminidec/interface -CFLAGS += -I $(SRC_COMMON)/unix/nvidia-headsurface -CFLAGS += -I src/shaders - -CFLAGS += -DNV_PUSH_IN_KERNEL -CFLAGS += -DNV_XZ_CUSTOM_MEM_HOOKS -CFLAGS += -DNV_XZ_USE_NVTYPES -CFLAGS += -DXZ_DEC_SINGLE - # Compress the shaders and embed in ELF object files. define COMPRESS_SHADERS $$(OUTPUTDIR)/$(1)_shaders.xz: src/shaders/g_$(1)_shaders @@ -196,11 +144,7 @@ $$(eval $$(call READ_ONLY_OBJECT_FROM_FILE_RULE,$$(OUTPUTDIR)/$(1)_shaders.xz)) SHADER_OBJS += $$(OUTPUTDIR)/$(1)_shaders.xz.o endef -$(eval $(call COMPRESS_SHADERS,turing)) -$(eval $(call COMPRESS_SHADERS,ampere)) -$(eval $(call COMPRESS_SHADERS,hopper)) -$(eval $(call COMPRESS_SHADERS,blackwell)) -$(eval $(call COMPRESS_SHADERS,gb20x)) +$(foreach shader, $(SHADERS), $(eval $(call COMPRESS_SHADERS,$(shader)))) OBJS = $(call BUILD_OBJECT_LIST,$(ALL_SRCS)) OBJS += $(SHADER_OBJS) diff --git a/src/nvidia-modeset/defs.mk b/src/nvidia-modeset/defs.mk new file mode 100644 index 000000000..a3471756d --- /dev/null +++ b/src/nvidia-modeset/defs.mk @@ -0,0 +1,62 @@ +# shared make defines for Makefile and Kbuild + +SRC_COMMON := ../common + +NV_INCLUDE := +NV_INCDIRS := +NV_DEFINES := + +NV_INCLUDE += $(SRC_COMMON)/sdk/nvidia/inc/cpuopsys.h + +NV_INCDIRS += $(SRC_COMMON)/sdk/nvidia/inc +NV_INCDIRS += $(SRC_COMMON)/sdk/nvidia/inc/hw +NV_INCDIRS += $(SRC_COMMON)/shared/inc +NV_INCDIRS += $(SRC_COMMON)/inc +NV_INCDIRS += $(SRC_COMMON)/softfloat/nvidia +NV_INCDIRS += $(SRC_COMMON)/softfloat/source/include +NV_INCDIRS += $(SRC_COMMON)/softfloat/source/8086-SSE +NV_INCDIRS += $(SRC_COMMON)/unix/common/utils/interface +NV_INCDIRS += $(SRC_COMMON)/unix/common/inc +NV_INCDIRS += $(SRC_COMMON)/modeset +NV_INCDIRS += os-interface/include +NV_INCDIRS += kapi/interface +NV_INCDIRS += ../nvidia/arch/nvalloc/unix/include +NV_INCDIRS += interface +NV_INCDIRS += include +NV_INCDIRS += kapi/include +NV_INCDIRS += generated +NV_INCDIRS += $(SRC_COMMON)/displayport/inc +NV_INCDIRS += $(SRC_COMMON)/displayport/inc/dptestutil +NV_INCDIRS += $(SRC_COMMON)/inc/displayport + +NV_DEFINES += -DNDEBUG +NV_DEFINES += -D_LANGUAGE_C +NV_DEFINES += -D__NO_CTYPE + +NV_DEFINES += -DNV_CPU_INTRINSICS_KERNEL +NV_DEFINES += -DNVHDMIPKT_RM_CALLS_INTERNAL=0 +NV_DEFINES += -DNVHDMIPKT_NVKMS + +# XXX it would be nice to only define these for appropriate files... +NV_DEFINES += -DSOFTFLOAT_ROUND_ODD +NV_DEFINES += -DSOFTFLOAT_FAST_DIV32TO16 +NV_DEFINES += -DSOFTFLOAT_FAST_DIV64TO32 + +# Tell nvtiming to use nvkms import functions +NV_DEFINES += -DNVT_USE_NVKMS + +# Tell SMG we're being compiled into kernel +NV_DEFINES += -DNV_SMG_IN_NVKMS + +NV_INCDIRS += $(SRC_COMMON)/unix/nvidia-3d/interface +NV_INCDIRS += $(SRC_COMMON)/unix/nvidia-push/interface +NV_INCDIRS += $(SRC_COMMON)/unix/nvidia-3d/include +NV_INCDIRS += $(SRC_COMMON)/unix/nvidia-push/include +NV_INCDIRS += $(SRC_COMMON)/unix/xzminidec/interface +NV_INCDIRS += $(SRC_COMMON)/unix/nvidia-headsurface +NV_INCDIRS += src/shaders + +NV_DEFINES += -DNV_PUSH_IN_KERNEL +NV_DEFINES += -DNV_XZ_CUSTOM_MEM_HOOKS +NV_DEFINES += -DNV_XZ_USE_NVTYPES +NV_DEFINES += -DXZ_DEC_SINGLE diff --git a/src/nvidia-modeset/srcs.mk b/src/nvidia-modeset/srcs.mk index bda977fbc..170edeee9 100644 --- a/src/nvidia-modeset/srcs.mk +++ b/src/nvidia-modeset/srcs.mk @@ -227,3 +227,10 @@ SRCS += ../common/unix/xzminidec/src/xz_crc32.c SRCS += ../common/unix/xzminidec/src/xz_dec_bcj.c SRCS += ../common/unix/xzminidec/src/xz_dec_lzma2.c SRCS += ../common/unix/xzminidec/src/xz_dec_stream.c + +# shaders +SHADERS += turing +SHADERS += ampere +SHADERS += hopper +SHADERS += blackwell +SHADERS += gb20x From 0d5f849612767854ddab4f64d38e6c7f9601c7a5 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Tue, 10 Feb 2026 09:37:55 +0000 Subject: [PATCH 33/37] src/nvidia-modeset: preliminary kbuild support Provide a Kbuild file to be able to build src/nvidia-modeset/ using Linux's kbuild. It's meant to be included by kernel-open/nvidia-modeset/. Signed-off-by: Mathias Krause --- src/nvidia-modeset/nvidia-modeset.Kbuild | 151 +++++++++++++++++++++++ src/nvidia-modeset/srcs.mk | 4 +- 2 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 src/nvidia-modeset/nvidia-modeset.Kbuild diff --git a/src/nvidia-modeset/nvidia-modeset.Kbuild b/src/nvidia-modeset/nvidia-modeset.Kbuild new file mode 100644 index 000000000..aa5898a6d --- /dev/null +++ b/src/nvidia-modeset/nvidia-modeset.Kbuild @@ -0,0 +1,151 @@ +########################################################################### +# nvidia-modeset.Kbuild, included by kernel-open/nvidia-modeset/nvidia-modeset.Kbuild +########################################################################### + +nvidia_modeset_src ?= . + +NV_MODESET_KERNEL_O = nv-modeset-kernel.clean.o +NV_MODESET_KERNEL_O_OBJS = $(nv-modeset-kernel-objs) + +include $(src)/$(nvidia_modeset_src)/srcs.mk +include $(src)/$(nvidia_modeset_src)/defs.mk + +# The source files for nv-modeset-kernel.o are all SRCS and SRCS_CXX defined in +# srcs.mk, the NVIDIA ID string and the shaders +SRCS := $(addprefix $(nvidia_modeset_src)/,$(SRCS)) +SRCS_CXX := $(addprefix $(nvidia_modeset_src)/,$(SRCS_CXX)) +NVIDSTRING := $(addprefix $(nvidia_modeset_src)/,g_nvid_string.c) +ALL_SRCS := $(SRCS) $(SRCS_CXX) $(NVIDSTRING) + +# g_${shader}_shaders -> $[shaders}_shaders.xz.o +SHADER_OBJS := \ + $(addprefix $(nvidia_modeset_src)/src/shaders/,\ + $(addsuffix .xz.o,$(addsuffix _shaders,$(SHADERS)))) + +nv-modeset-kernel-objs := $(SRCS:.c=.o) +nv-modeset-kernel-objs += $(SRCS_CXX:.cpp=.o) +nv-modeset-kernel-objs += $(NVIDSTRING:.c=.o) +nv-modeset-kernel-objs += $(SHADER_OBJS) + +# Hack to create a relocatable intermediate object file to avoid '/bin/sh: +# Argument list too long' errors for the real module. +ifeq ($(NV_PREPARE_ONLY),1) +obj-m += nv-modeset-kernel.stub.o +nv-modeset-kernel.stub-y := $(nv-modeset-kernel-objs) $(MOD_STUB) +endif + +# for the 'clean' target +targets += $(nv-modeset-kernel-objs) +# ensure to use "our" NVIDSTRING +$(eval targets += $(NVIDSTRING)) + +# Define how to generate the NVIDIA ID string -- intentionally deviates from +# the OS-agnostic build +$(eval $(call GENERATE_NVIDSTRING, \ + NV_KMS_ID, \ + Linux Open Kernel Mode Setting Driver, $(nv-modeset-kernel-objs))) + +# now compile the final ccflags +nv-modeset-kernel-cflags := $(addprefix -include $(src)/$(nvidia_modeset_src)/,$(NV_INCLUDE)) +nv-modeset-kernel-cflags += $(addprefix -I $(src)/$(nvidia_modeset_src)/,$(NV_INCDIRS)) +nv-modeset-kernel-cflags += $(NV_DEFINES) + +# suppress some warnings +nv-modeset-kernel-cflags += -Wno-format-zero-length +nv-modeset-kernel-cflags += -Wno-implicit-fallthrough + +# XXX: Using -ffunction-sections / -fdata-sections makes no sense without +# XXX: --gc-sections. However, we cannot make use of --gc-sections as that +# XXX: would also drop crucial sections like .alt_instructions or +# XXX: .return_sites. So just disable these. +#nv-modeset-kernel-cflags += -ffunction-sections +#nv-modeset-kernel-cflags += -fdata-sections + +# move early -I... flags to after ours -- what a hack! +ccflags-includes := $(filter -I$(src)%,$(ccflags-y)) +nv-modeset-kernel-cflags += $(patsubst -I%,-I %,$(ccflags-includes)) +nv-modeset-kernel-cflags-remove += $(ccflags-includes) + +$(call ASSIGN_PER_OBJ_CFLAGS_REMOVE, $(nv-modeset-kernel-objs), $(nv-modeset-kernel-cflags-remove)) +$(call ASSIGN_PER_OBJ_CFLAGS, $(nv-modeset-kernel-objs), $(nv-modeset-kernel-cflags)) + +nv-modeset-kernel-cxxflags := -std=gnu++11 +nv-modeset-kernel-cxxflags += -fno-operator-names +nv-modeset-kernel-cxxflags += -fno-rtti +nv-modeset-kernel-cxxflags += -fno-exceptions +nv-modeset-kernel-cxxflags += -fcheck-new + +# ... referenced in section `__mcount_loc' of ...: defined in discarded section ... :/ +nv-modeset-kernel-cxxflags += -mno-record-mcount + +# --- 8< --- taken from scripts/Makefile.lib, adapted for C++ +# + +# strip C-only options from c_flags +cxx_cflags_filter := -W%implicit +cxx_cflags_filter += -W%implicit-int +cxx_cflags_filter += -W%implicit-function-declaration +cxx_cflags_filter += -W%strict-prototypes +cxx_cflags_filter += -W%missing-prototypes +cxx_cflags_filter += -W%pointer-sign +cxx_cflags_filter += -W%incompatible-pointer-types +cxx_cflags_filter += -W%designated-init +cxx_cflags_filter += -W%override-init +cxx_cflags_filter += -std=gnu11 + +CXX_FLAGS := $(nv-modeset-kernel-cxxflags) + +cxx_flags = $(filter-out $(cxx_cflags_filter),$(c_flags)) $(CXX_FLAGS) +quiet_cmd_cc_o_cxx = CXX $(quiet_modtag) $@ + cmd_cc_o_cxx = $(CXX) $(cxx_flags) -c -o $@ $< \ + $(cmd_ld_single) #\ + $(cmd_objtool) # disabled for now, as .return_sites / .call_sites reference to-be-discarded symbols + +define rule_cc_o_cxx + $(call cmd_and_fixdep,cc_o_cxx) + $(call cmd,checksrc) + $(call cmd,checkdoc) + $(call cmd,gen_objtooldep) + $(call cmd,gen_symversions_c)$(eval # genksyms can only parse C code!) + $(call cmd,record_mcount) + $(call cmd,warn_shared_object) +endef + +$(obj)/%.o: $(obj)/%.cpp $(recordmcount_source) FORCE + $(call if_changed_rule,cc_o_cxx) + $(call cmd,force_checksrc) +# +# --- >8 --- + +# shader rules +# +ld_o_xz-ldflags = -r -z noexecstack --format=binary +ld_o_xz-objcopy = --rename-section .data=.rodata,contents,alloc,load,data,readonly + +# changing into the directory of the .xz is needed to get sane names for the +# _binary_..._start/_end/_size symbols +quiet_cmd_ld_o_xz = LD XZO $@ + cmd_ld_o_xz = (cd $(dir $<) && $(LD) $(ld_o_xz-ldflags) $(notdir $<) -o $@.tmp) && $(OBJCOPY) $(ld_o_xz-objcopy) $@.tmp $@ && rm -f $@.tmp + +$(obj)/%.xz.o: $(obj)/%.xz FORCE + $(call if_changed,ld_o_xz) + +quiet_cmd_shader_xz = XZRAW $@ + cmd_shader_xz = cat $< | $(XZ) -ce -C none > $@ + +# This one is needed because we want to change the basename of the file and '%' +# would match the full path, including directories,prefixing the 'g_' at the +# wrong spot. +define mk_shader_rules +$$(obj)/$(1).xz: $$(obj)/$(dir $(1))/g_$(notdir $(1)) FORCE + $$(call if_changed,shader_xz) + +# for 'make clean' +targets += $(1).xz + +# not really needed, but to have conftest be the very first +NV_OBJECTS_DEPEND_ON_CONFTEST += $(1).xz +endef + +$(foreach shader, $(SHADER_OBJS:.xz.o=), $(eval $(call mk_shader_rules,$(shader)))) + diff --git a/src/nvidia-modeset/srcs.mk b/src/nvidia-modeset/srcs.mk index 170edeee9..ad89faca8 100644 --- a/src/nvidia-modeset/srcs.mk +++ b/src/nvidia-modeset/srcs.mk @@ -1,5 +1,5 @@ -SRCS ?= -SRCS_CXX ?= +SRCS := +SRCS_CXX := SRCS += ../common/shared/nvstatus/nvstatus.c SRCS += ../common/softfloat/source/8086-SSE/s_commonNaNToF16UI.c From 61b6eb0b455a96c4f00ed9c430a3ad06c2238a8c Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Wed, 11 Mar 2026 21:05:25 +0100 Subject: [PATCH 34/37] src/nvidia-modeset: collapse C++ comdat sections The C++ code of nv-modeset-kernel.o causes a lot of comdat sections to be generated which interferes badly with objtool trying to instrument / reference these, especially when some of the comdat sections do get dropped during linking of the final module. Resolve this issue by collapsing the comdat sections early and squashing the scattered sections with the help of a linker script. Signed-off-by: Mathias Krause --- src/nvidia-modeset/nv-modeset-kernel.ld | 28 ++++++++++++++++++++++++ src/nvidia-modeset/nvidia-modeset.Kbuild | 10 +++++++++ src/nvidia-modeset/srcs.mk | 2 ++ 3 files changed, 40 insertions(+) create mode 100644 src/nvidia-modeset/nv-modeset-kernel.ld diff --git a/src/nvidia-modeset/nv-modeset-kernel.ld b/src/nvidia-modeset/nv-modeset-kernel.ld new file mode 100644 index 000000000..8305d6d87 --- /dev/null +++ b/src/nvidia-modeset/nv-modeset-kernel.ld @@ -0,0 +1,28 @@ +/* + * nv-modeset-kernel.o linker script + * + * g++ puts inline functions, vtables, template functions, etc, in separate + * ".gnu.linkonce.*" / ".text.*" /... sections even without '-ffunction-sections + * -fdata-sections'. Duplicates will be collapsed at link time via + * '--force-group-allocation'. However, the weird section names will still be + * preserved which just increases module load time. + + * Merge these sections with this little linker script. + * + * C++ symbols/sections get filtered by their common '_Z' prefix, demanded by + * the Itanium ABI. + */ + +SECTIONS { + + .text : { *(.text) *(.text._Z*) *(.gnu.linkonce.t._Z*) } + + .rodata : { *(.rodata) *(.rodata._Z*) *(.gnu.linkonce.r._Z*) } + + .data : { *(.data) *(.data._Z*) } + + .bss : { *(.bss) *(.bss._Z*) } + + /* The rest of the sections ("orphaned sections") will just be copied from + the input to the output */ +} diff --git a/src/nvidia-modeset/nvidia-modeset.Kbuild b/src/nvidia-modeset/nvidia-modeset.Kbuild index aa5898a6d..3e61d1227 100644 --- a/src/nvidia-modeset/nvidia-modeset.Kbuild +++ b/src/nvidia-modeset/nvidia-modeset.Kbuild @@ -54,6 +54,13 @@ nv-modeset-kernel-cflags += $(NV_DEFINES) nv-modeset-kernel-cflags += -Wno-format-zero-length nv-modeset-kernel-cflags += -Wno-implicit-fallthrough +# Get rid of COMDAT groups when linking nv-modeset-kernel.stub.o to not cause +# objtool-generated cross-section linker errors on sections the linker is about +# to drop. Also merge all related C++-specific sections with the help of a +# linker script to reduce them to a sensible number of to-be-loaded sections. +nv-modeset-kernel-ldflags := --force-group-allocation +nv-modeset-kernel-ldflags += -T $(src)/$(nvidia_modeset_src)/$(LINKER_SCRIPT) + # XXX: Using -ffunction-sections / -fdata-sections makes no sense without # XXX: --gc-sections. However, we cannot make use of --gc-sections as that # XXX: would also drop crucial sections like .alt_instructions or @@ -68,6 +75,9 @@ nv-modeset-kernel-cflags-remove += $(ccflags-includes) $(call ASSIGN_PER_OBJ_CFLAGS_REMOVE, $(nv-modeset-kernel-objs), $(nv-modeset-kernel-cflags-remove)) $(call ASSIGN_PER_OBJ_CFLAGS, $(nv-modeset-kernel-objs), $(nv-modeset-kernel-cflags)) +$(call ASSIGN_PER_OBJ_LDFLAGS, nv-modeset-kernel.stub.o, $(nv-modeset-kernel-ldflags)) + +$(obj)/nv-modeset-kernel.stub.o: $(obj)/$(nvidia_modeset_src)/$(LINKER_SCRIPT) nv-modeset-kernel-cxxflags := -std=gnu++11 nv-modeset-kernel-cxxflags += -fno-operator-names diff --git a/src/nvidia-modeset/srcs.mk b/src/nvidia-modeset/srcs.mk index ad89faca8..f44f8edb0 100644 --- a/src/nvidia-modeset/srcs.mk +++ b/src/nvidia-modeset/srcs.mk @@ -234,3 +234,5 @@ SHADERS += ampere SHADERS += hopper SHADERS += blackwell SHADERS += gb20x + +LINKER_SCRIPT := nv-modeset-kernel.ld From 4f7a0d95012dbf95d05f15b5ee1b5373967730c3 Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Tue, 10 Feb 2026 09:43:16 +0000 Subject: [PATCH 35/37] kernel-open/nvidia-modeset: Kbuild support Support building the dependent src/nvidia-modeset-kernel.o using Linux's kbuild. Signed-off-by: Mathias Krause --- kernel-open/nvidia-modeset/nvidia-modeset.Kbuild | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/kernel-open/nvidia-modeset/nvidia-modeset.Kbuild b/kernel-open/nvidia-modeset/nvidia-modeset.Kbuild index bb7ca8edc..43b88fd67 100644 --- a/kernel-open/nvidia-modeset/nvidia-modeset.Kbuild +++ b/kernel-open/nvidia-modeset/nvidia-modeset.Kbuild @@ -16,6 +16,17 @@ obj-m += nvidia-modeset.o nvidia-modeset-y := $(NVIDIA_MODESET_OBJECTS) endif +ifeq ($(USE_KBUILD),1) +# build nv-modeset-kernel.o using Linux's kbuild system +nvidia_modeset_src := ../src/nvidia-modeset +include $(src)/$(nvidia_modeset_src)/nvidia-modeset.Kbuild + +nvidia-modeset-y += $(NV_MODESET_KERNEL_O) + +NV_OBJECTS_DEPEND_ON_CONFTEST += $(NV_MODESET_KERNEL_O_OBJS) + +else # !USE_KBUILD + NVIDIA_MODESET_KO = nvidia-modeset/nvidia-modeset.ko NV_KERNEL_MODULE_TARGETS += $(NVIDIA_MODESET_KO) @@ -48,6 +59,7 @@ $(obj)/$(NVIDIA_MODESET_BINARY_OBJECT_O): $(NVIDIA_MODESET_BINARY_OBJECT) FORCE $(call if_changed,symlink) nvidia-modeset-y += $(NVIDIA_MODESET_BINARY_OBJECT_O) +endif # @@ -84,8 +96,10 @@ NVIDIA_MODESET_INTERFACE := nvidia-modeset/nv-modeset-interface.o # before v5.6 looks at "always"; kernel versions between v5.12 and v5.6 # look at both. +ifneq ($(NV_PREPARE_ONLY),1) always += $(NVIDIA_MODESET_INTERFACE) always-y += $(NVIDIA_MODESET_INTERFACE) +endif $(obj)/$(NVIDIA_MODESET_INTERFACE): $(addprefix $(obj)/,$(NVIDIA_MODESET_OBJECTS)) $(LD) -r -o $@ $^ From 69de8b8231184d8141a95fd56b5e2d762f4f08fb Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Tue, 16 Dec 2025 22:19:36 +0000 Subject: [PATCH 36/37] Experimental support for Linux's kbuild Add experimental support for using the Linux kernel's kbuild system to not only compile code below kernel-open/ but src/ as well. The build is still done in two phases, as in first building src/, then kernel-open/ as otherwise the build would run into errors, trying to link too many objects, hitting shell command argument limits. Compiling the code below src/ via kbuild is needed to, e.g., support more recent kernel features like IBT or to add required marker locations via objtool for features like RETHUNK. Using kbuild is disabled by default and needs to be explicitly opt-in via `make USE_KBUILD=1`. Signed-off-by: Mathias Krause --- Makefile | 37 ++++++++++++++++++++++++++++--------- README.md | 4 ++++ src/nvidia-modeset/Makefile | 4 ++++ src/nvidia/Makefile | 4 ++++ 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 449c7f585..38e228c9a 100644 --- a/Makefile +++ b/Makefile @@ -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 ########################################################################### @@ -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 ########################################################################### @@ -48,6 +54,9 @@ $(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 @@ -55,7 +64,13 @@ $(nv_modeset_kernel_o_binary): $(nv_modeset_kernel_o) ########################################################################### .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 ########################################################################### @@ -63,7 +78,7 @@ modules: $(nv_kernel_o_binary) $(nv_modeset_kernel_o_binary) ########################################################################### .PHONY: modules_install -modules_install: +modules_install: modules $(MAKE) -C kernel-open modules_install ########################################################################### @@ -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: diff --git a/README.md b/README.md index a89739266..7ddc4653c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/nvidia-modeset/Makefile b/src/nvidia-modeset/Makefile index a46354212..2ad070a1c 100644 --- a/src/nvidia-modeset/Makefile +++ b/src/nvidia-modeset/Makefile @@ -2,6 +2,10 @@ # Makefile for nv-modeset-kernel.o ########################################################################### +ifeq ($(USE_KBUILD),1) +$(error nv-modeset-kernel.o gets build as part of kernel-open/) +endif + NV_MODULE_LOGGING_NAME ?= nvidia-modeset VERSION_MK_DIR = ../../ diff --git a/src/nvidia/Makefile b/src/nvidia/Makefile index 9a8aef1e9..1a005d1b1 100644 --- a/src/nvidia/Makefile +++ b/src/nvidia/Makefile @@ -2,6 +2,10 @@ # Makefile for nv-kernel.o ########################################################################### +ifeq ($(USE_KBUILD),1) +$(error nv-kernel.o gets build as part of kernel-open/) +endif + NV_MODULE_LOGGING_NAME ?= nvidia VERSION_MK_DIR = ../../ From a1f715b9864c6433cda6140b570659590e25ed5d Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Wed, 18 Mar 2026 09:29:21 -0400 Subject: [PATCH 37/37] kernel-open: Lift RANDSTRUCT restriction for USE_KBUILD=1 The RANDSTRUCT limitation isn't needed when all sources get compiled with kbuild. Guard it like that. Signed-off-by: Mathias Krause --- kernel-open/Makefile | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/kernel-open/Makefile b/kernel-open/Makefile index 0ddea676f..c189f5613 100644 --- a/kernel-open/Makefile +++ b/kernel-open/Makefile @@ -69,13 +69,15 @@ else endif endif - # 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!)) + 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