nvidia modules are ready

This commit is contained in:
idriskalp
2019-12-28 21:58:26 +03:00
parent 1a5e36a3e5
commit 8d33ceddbd
45 changed files with 2392 additions and 90 deletions
+207
View File
@@ -0,0 +1,207 @@
#
# This Makefile was automatically generated; do not edit.
# Generated on 'swio-display-x64-rhel04-13' on Thu May 24 21:16:20 PDT 2018.
#
#
# KBUILD Makefile for the NVIDIA Linux kernel module.
#
# The motivation for replacing the original Makefile is the hope that this
# version will simplify the build and installation process. In the past,
# many architectural and cosmetic changes to the Linux kernel have made it
# difficult to maintain compatibility or required duplication of logic.
#
# Linux 2.6 introduces numerous such changes, many of which impact modules.
# Relying on KBUILD, some aspects of the build system otherwise difficult
# to support (for example, module versioning) are abstracted away and dealt
# with elsewhere, making life significantly easier here.
#
# The new approach currently has its own share of problems, some of which
# are architectural difficulties with KBUILD, others minor annoyances. For
# this reason, an improved version of the NVIDIA Makefile is available to
# those experiencing difficulties.
#
# kbuild Makefile originally developed by:
#
# Alistair J Strachan (alistair@devzero.co.uk) (first pass, enhancements)
# Christian Zander (zander@mail.minion.de) (enhancements)
#
#
# The NVIDIA kernel module base name.
#
MODULE_BASENAME := nvidia
#
# This suffix is used to construct the name of the NVIDIA kernel module
# in case of multiple kernel module builds. This suffix can either take the
# numeric value 0-7 or the string "frontend". For normal NVIDIA kernel module
# builds, this variable is empty and hence the module name is identical to
# the base names.
#
NV_MODULE_SUFFIX ?=
#
# The NVIDIA kernel module name and static file names. In case of multiple
# NVIDIA kernel module builds, $(NV_MODULE_SUFFIX) is appended to the
# module basename to construct the module name of the concerned module.
# KBUILD will go ahead and append ".o" or ".ko" to form the module file name.
#
ifeq ($(NV_MODULE_SUFFIX),frontend)
MODULE_NAME := $(MODULE_BASENAME)-$(NV_MODULE_SUFFIX)
else
MODULE_NAME := $(MODULE_BASENAME)$(NV_MODULE_SUFFIX)
endif
VERSION_HEADER := nv_compiler.h
#
# List of object files to link into NVIDIA kernel module; this list
# is assigned depending on the value of $(NV_MODULE_SUFFIX) being passed.
# Make sure KBUILD understands that we want a module.
#
CORE_OBJS := nv-kernel.o
ifdef NV_BUILD_MODULE_INSTANCES
ifeq ($(NV_MODULE_SUFFIX),frontend)
MODULE_GLUE_OBJS := $(patsubst %.c,%.o,nv-frontend.c)
$(MODULE_NAME)-objs := $(MODULE_GLUE_OBJS)
else
MODULE_GLUE_OBJS := $(patsubst %.c,%.o, nv.c nv-acpi.c nv-chrdev.c nv-cray.c nv-dma.c nv-drm.c nv-gvi.c nv-i2c.c nv-mempool.c nv-mmap.c nv-p2p.c nv-pat.c nv-procfs.c nv-usermap.c nv-vm.c nv-vtophys.c os-interface.c os-mlock.c os-pci.c os-registry.c os-smp.c os-usermap.c nv_uvm_interface.c)
$(MODULE_NAME)-objs := $(CORE_OBJS) $(MODULE_GLUE_OBJS)
endif
else
MODULE_GLUE_OBJS := $(patsubst %.c,%.o, nv.c nv-acpi.c nv-chrdev.c nv-cray.c nv-dma.c nv-drm.c nv-gvi.c nv-i2c.c nv-mempool.c nv-mmap.c nv-p2p.c nv-pat.c nv-procfs.c nv-usermap.c nv-vm.c nv-vtophys.c os-interface.c os-mlock.c os-pci.c os-registry.c os-smp.c os-usermap.c nv_uvm_interface.c) $(patsubst %.c,%.o,nv-frontend.c)
$(MODULE_NAME)-objs := $(CORE_OBJS) $(MODULE_GLUE_OBJS)
endif
#
# List of targets to build in case of multiple NVIDIA kernel module builds.
# The actual target is constructed by prefixing nvidia/nvidia- to every
# item in the list $(BUILD_MODULES_LIST)/$(BUILD_MODULE_FRONTEND).
#
ifdef NV_BUILD_MODULE_INSTANCES
BUILD_MODULES_LIST := $(shell seq 0 `expr $(NV_BUILD_MODULE_INSTANCES) - 1`)
BUILD_MODULE_FRONTEND := frontend
endif
COMPILE_TESTS = \
remap_pfn_range \
vmap \
set_pages_uc \
set_memory_uc \
set_memory_array_uc \
change_page_attr \
i2c_adapter \
pci_get_class \
pm_message_t \
irq_handler_t \
pci_choose_state \
vm_insert_page \
acpi_device_ops \
acpi_op_remove \
acpi_device_id \
acquire_console_sem \
console_lock \
kmem_cache_create \
outer_flush_all \
on_each_cpu \
smp_call_function \
nvmap_support \
acpi_evaluate_integer \
ioremap_cache \
ioremap_wc \
proc_dir_entry \
INIT_WORK \
acpi_walk_namespace \
scatterlist \
pci_domain_nr \
pci_dma_mapping_error \
file_operations \
sg_alloc_table \
sg_init_table \
pci_get_domain_bus_and_slot \
get_num_physpages \
efi_enabled \
dom0_kernel_present \
drm_available \
proc_create_data \
pde_data \
proc_remove \
sg_table \
pm_vt_switch_required \
pci_save_state \
file_inode \
drm_pci_set_busid \
write_cr4 \
for_each_online_node \
node_end_pfn \
get_user_pages \
get_user_pages_remote \
register_cpu_notifier \
cpuhp_setup_state \
vm_fault_present \
vm_fault_has_address \
drm_driver_unload_has_int_return_type \
drm_gem_object_get \
do_gettimeofday \
drm_legacy_pci_init \
timer_setup
#
# CFLAGS dependent on the type of builds (e.g. single/muliple module, debug)
#
ifdef NV_BUILD_MODULE_INSTANCES
EXTRA_CFLAGS += -DNV_BUILD_MODULE_INSTANCES=1
ifneq ($(NV_MODULE_SUFFIX),frontend)
EXTRA_CFLAGS += -DNV_MODULE_INSTANCE=$(NV_MODULE_SUFFIX)
endif
else
EXTRA_CFLAGS += -DNV_MODULE_INSTANCE=0
EXTRA_CFLAGS += -DNV_BUILD_MODULE_INSTANCES=0
endif
EXTRA_CFLAGS += -UDEBUG -U_DEBUG -DNDEBUG
#
# Include common definitions; we rely on the definition of the source path to
# find the file; set to a reasonable default if unset (e.g. for top-level
# passes). The source path is also used in the common file.
#
src ?= .
include $(src)/nvidia-modules-common.mk
#
# Generate multiple targets at runtime depending on the items present in
# the lists $(BUILD_MODULES_LIST) and $(BUILD_MODULE_FRONTEND) for multiple
# NVIDIA kernel module builds.
#
# For normal builds, generate the target $(MODULE_BASENAME).ko.
#
# Multiple-RM builds require GNU Make v3.81 or later, due to a bug in earlier
# versions of GNU Make that prevents the use of $(eval) within a $(foreach):
#
# http://savannah.gnu.org/bugs/?func=detailitem&item_id=1517
#
$(foreach obj_file, $(BUILD_MODULES_LIST), $(eval $(call BUILD_MODULE_RULE,$(MODULE_BASENAME)$(obj_file).ko,$(obj_file),$(MODULE_BASENAME)-$(BUILD_MODULE_FRONTEND).ko)))
$(eval $(call BUILD_MODULE_RULE,$(MODULE_BASENAME)-$(BUILD_MODULE_FRONTEND).ko,$(BUILD_MODULE_FRONTEND),))
$(eval $(call BUILD_MODULE_RULE,$(MODULE_BASENAME).ko,,))
#
# Add dependencies for the generated targets, depending on whether we are
# building multiple RM instances or a single RM.
#
ifdef NV_BUILD_MODULE_INSTANCES
NV_MODULE_TARGET_DEPS := $(addsuffix .ko,$(addprefix $(MODULE_BASENAME),$(BUILD_MODULES_LIST) -$(BUILD_MODULE_FRONTEND)))
else
NV_MODULE_TARGET_DEPS := $(MODULE_OBJECT)
endif
module: $(NV_MODULE_TARGET_DEPS)
+234
View File
@@ -0,0 +1,234 @@
################################################################################
# Copyright (c) 2013 NVidia Corporation
#
# 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.
#
################################################################################
#
# UVM kernel module makefile
#
# The following UVM_BUILD_TYPEs are supported: debug, release, and develop.
# The first two are nearly self-explanatory, but "develop" deserves a little
# more explanation (below).
#
# Description of the UVM build types (UVM_BUILD_TYPE):
#
# debug builds: these get debug symbols, no optimization (in order to allow
# easier stepping through of functions), and debug printing.
#
# develop builds: these are "printing" builds, normally without debug symbols.
# These builds must run at close to normal speeds, so they are optimized, and
# do not have any debug symbols. However, they do have debug printing output.
# This allows a convenient way for QA (or anyone) to get a slightly deeper look
# at what the driver is doing, without the hassle of setting up kernel
# debugging.
#
# release builds: these are just the usual speed-optimized, no-debug,
# no-printing builds that you would expect most users to run.
#
UVM_BUILD_TYPE ?= release
ifeq ($(UVM_BUILD_TYPE),debug)
EXTRA_CFLAGS += -DDEBUG -O0 -g
else
ifeq ($(UVM_BUILD_TYPE),develop)
# -DDEBUG is required, in order to allow pr_devel() print statements to
# work:
EXTRA_CFLAGS += -DDEBUG -O2
else
EXTRA_CFLAGS += -O2
endif
endif
NV_HOST_OS := $(shell uname)
NV_HOST_ARCH := $(shell uname -m)
NV_TARGET_DEFINES ?=
NV_DEFINES=
# In addition to the UVM_BUILD_TYPE (release, debug) choice, there is also a
# UVM_PROJECT choice. Choices include UVM_NEXT and UVM_LITE, and ALL. The
# default is UVM_LITE.
#
# Unless you are working (inside NVIDIA) on the "next" version of UVM, you want
# to use the default choice here.
UVM_PROJECT ?= UVM_LITE
UVM_LITE ?= 0
UVM_NEXT ?= 0
RM_ENABLED ?= 1
ifeq ($(UVM_PROJECT),ALL)
UVM_LITE = 1
UVM_NEXT = 1
else
ifeq ($(UVM_PROJECT),UVM_LITE)
UVM_LITE = 1
else
ifeq ($(UVM_PROJECT),UVM_NEXT)
UVM_NEXT = 1
else
$(error "Invalid UVM_PROJECT: $(UVM_PROJECT)")
endif
endif
endif
ifeq ($(UVM_LITE),0)
ifeq ($(UVM_NEXT),0)
$(error "Cannot build with both UVM_LITE and UVM_NEXT disabled")
endif
endif
ifneq ($(UVM_LITE),0)
NV_DEFINES += -DNVIDIA_UVM_LITE_ENABLED
endif
ifneq ($(UVM_NEXT),0)
NV_DEFINES += -DNVIDIA_UVM_NEXT_ENABLED
endif
NV_DEFINES += -D$(NV_HOST_OS)
ifneq ($(findstring $(NV_HOST_OS),"Linux"),)
NV_HOST_OS_FAMILY = Unix
NV_HOST_OS_FAMILY_LOWER_CASE = unix
NV_DEFINES+= -D__linux__
endif
ifneq ($(findstring $(NV_HOST_OS),"macosx"),)
NV_HOST_OS_FAMILY = MacOSX
NV_HOST_OS_FAMILY_LOWER_CASE = macosx
endif
ifeq ($(NV_HOST_OS_FAMILY),)
$(error "Unrecognized NV_HOST_OS: $(NV_HOST_OS)")
endif
ifneq ($(findstring $(NV_HOST_OS_FAMILY),"Unix MacOSX"),)
# For Unix and MacOS, use the host platform as the default target platform.
NV_TARGET_OS ?= $(NV_HOST_OS)
NV_TARGET_ARCH ?= $(NV_HOST_ARCH)
endif
#
# Determine NV_TARGET_OS_FAMILY
#
NV_TARGET_OS_FAMILY =
ifneq ($(findstring $(NV_TARGET_OS),"Linux"),)
NV_TARGET_OS_FAMILY = Unix
NV_TARGET_OS_FAMILY_LOWER_CASE = unix
endif
ifneq ($(findstring $(NV_TARGET_OS),"macosx"),)
NV_TARGET_OS_FAMILY = MacOSX
NV_TARGET_OS_FAMILY_LOWER_CASE = macosx
endif
ifeq ($(NV_TARGET_OS_FAMILY),)
$(error "NV_TARGET_OS_FAMILY has not been set.")
endif
src ?= .
obj ?= $(src)
# In both internal builds, and installation (public) builds, the UVM open-source
# files (that's all of them, for UVM) are in a subdirectory below the RM
# open-source files.
RM_OUT_DIR ?= $(src)/..
VERSION_HEADER := $(RM_OUT_DIR)/nv_compiler.h
COMPILE_TESTS = \
remap_page_range \
remap_pfn_range \
irq_handler_t \
vm_insert_page \
kmem_cache_create \
outer_flush_all \
vm_operations_struct \
file_operations \
task_struct \
address_space \
address_space_init_once \
kbasename \
fatal_signal_pending \
kuid_t \
do_gettimeofday \
vm_fault_has_address
MODULE_NAME:= nvidia-uvm
MODULE_GLUE_OBJS := nvidia_uvm_linux.o \
nvidia_uvm_common.o \
nvidia_uvm_utils.o
ifneq ($(UVM_LITE),0)
MODULE_GLUE_OBJS += nvidia_uvm_lite.o \
nvidia_uvm_page_cache.o \
nvidia_uvm_lite_api.o \
nvidia_uvm_lite_counters.o \
nvidia_page_migration.o \
nvidia_page_migration_kepler.o \
nvidia_uvm_lite_events.o \
uvm_gpu_ops_tests.o
endif
NV_INCLUDES:= -I$(PWD) -I$(RM_OUT_DIR)
ifneq ($(UVM_NEXT),0)
include $(src)/uvmnext.mk
endif
ifneq ($(RM_ENABLED),0)
NV_DEFINES += -DNVIDIA_UVM_RM_ENABLED
endif
EXTRA_CFLAGS += $(NV_DEFINES) $(NV_TARGET_DEFINES) $(NV_INCLUDES)
ccflags-y += $(EXTRA_CFLAGS)
RM_MODULE_SYMVERS:= $(RM_OUT_DIR)/Module.symvers
UVM_MODULE_SYMVERS:= $(obj)/Module.symvers
module $(MODULE_NAME).ko: $(UVM_MODULE_SYMVERS) debug_diagnostics_printing
$(MODULE_NAME)-y := $(MODULE_GLUE_OBJS)
include $(RM_OUT_DIR)/nvidia-modules-common.mk
$(eval $(call BUILD_MODULE_RULE, $(MODULE_OBJECT),"uvm",))
module: $(MODULE_OBJECT)
$(RM_MODULE_SYMVERS):
cd $(RM_OUT_DIR); make module SYSSRC=$(KERNEL_SOURCES) SYSOUT=$(KERNEL_OUTPUT) KBUILD_EXTMOD=$(RM_OUT_DIR)
$(UVM_MODULE_SYMVERS): $(RM_MODULE_SYMVERS)
cp $< $@
debug_diagnostics_printing:
ifeq ($(NV_VERBOSE),1)
@echo "NVIDIA UVM: CC=$(CC), HOST_CC=$(HOST_CC) NV_TARGET_ARCH=$(NV_TARGET_ARCH)"
@echo "NVIDIA UVM: CONFTEST=$(CONFTEST)"
@echo "KERNEL_SOURCES: $(KERNEL_SOURCES)"
@echo "EXTRA_CFLAGS: $(EXTRA_CFLAGS)"
endif
.PHONY: debug_diagnostics_printing
View File
View File
+43
View File
@@ -0,0 +1,43 @@
diff --git kernel/uvm/nvidia_uvm_lite.c kernel/uvm/nvidia_uvm_lite.c
index 65b9a4d..f5ea5d7 100644
--- a/kernel/uvm/nvidia_uvm_lite.c
+++ b/kernel/uvm/nvidia_uvm_lite.c
@@ -830,8 +830,10 @@ done:
#if defined(NV_VM_OPERATIONS_STRUCT_HAS_FAULT)
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
int _fault(struct vm_area_struct *vma, struct vm_fault *vmf)
-#else
-int _fault(struct vm_fault *vmf)
+#elif LINUX_VERSION_CODE < KERNEL_VERSION(5, 1, 0)
+int _fault(struct vm_fault *vmf)
+#else
+vm_fault_t _fault(struct vm_fault *vmf)
#endif
{
#if defined(NV_VM_FAULT_HAS_ADDRESS)
@@ -886,8 +888,10 @@ static struct vm_operations_struct uvmlite_vma_ops =
#if defined(NV_VM_OPERATIONS_STRUCT_HAS_FAULT)
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
int _sigbus_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
-#else
+#elif LINUX_VERSION_CODE < KERNEL_VERSION(5, 1, 0)
int _sigbus_fault(struct vm_fault *vmf)
+#else
+vm_fault_t _sigbus_fault(struct vm_fault *vmf)
#endif
{
vmf->page = NULL;
diff --git kernel/nv-drm.c kernel/nv-drm.c
index 122ba7d..1be5733 100644
--- a/kernel/nv-drm.c
+++ b/kernel/nv-drm.c
@@ -146,7 +146,7 @@ static const struct file_operations nv_drm_fops = {
};
static struct drm_driver nv_drm_driver = {
-#if defined(DRIVER_LEGACY)
+#if defined(DRIVER_LEGACY) || LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0)
.driver_features = DRIVER_GEM | DRIVER_PRIME | DRIVER_LEGACY,
#else
.driver_features = DRIVER_GEM | DRIVER_PRIME,
+49
View File
@@ -0,0 +1,49 @@
diff --git kernel/nv-linux.h kernel/nv-linux.h
index 4043bf1..62f0874 100644
--- kernel/nv-linux.h
+++ kernel/nv-linux.h
@@ -877,12 +877,21 @@ extern void *nv_stack_t_cache;
__ret; \
})
#elif (NV_SMP_CALL_FUNCTION_ARGUMENT_COUNT == 3)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 3, 0)
#define NV_SMP_CALL_FUNCTION(func, info, wait) \
({ \
int __ret = smp_call_function(func, info, wait); \
__ret; \
})
#else
+#define NV_SMP_CALL_FUNCTION(func, info, wait) \
+ ({ \
+ int __ret = 0; \
+ smp_call_function(func, info, wait); \
+ __ret; \
+ })
+#endif
+#else
#error "NV_SMP_CALL_FUNCTION_ARGUMENT_COUNT value unrecognized!"
#endif
#elif defined(CONFIG_SMP)
@@ -897,12 +906,21 @@ extern void *nv_stack_t_cache;
__ret; \
})
#elif (NV_ON_EACH_CPU_ARGUMENT_COUNT == 3)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 3, 0)
#define NV_ON_EACH_CPU(func, info, wait) \
({ \
int __ret = on_each_cpu(func, info, wait); \
__ret; \
})
#else
+#define NV_ON_EACH_CPU(func, info, wait) \
+ ({ \
+ int __ret = 0; \
+ on_each_cpu(func, info, wait); \
+ __ret; \
+ })
+#endif
+#else
#error "NV_ON_EACH_CPU_ARGUMENT_COUNT value unrecognized!"
#endif
#elif defined(CONFIG_SMP)
@@ -0,0 +1,113 @@
From f90c388c755a6bd9b72cb51c712a0ae686e0b377 Mon Sep 17 00:00:00 2001
From: Alberto Milone <alberto.milone@canonical.com>
Date: Wed, 27 Nov 2019 13:01:18 +0100
Subject: [PATCH 1/1] Add support for Linux 5.4
---
conftest.sh | 46 ++++++++++++++++++++++++++++++++++++++++
nv-drm.c | 9 +++++---
nvidia-modules-common.mk | 2 +-
3 files changed, 53 insertions(+), 4 deletions(-)
diff --git a/conftest.sh b/conftest.sh
index fb0bf60..babbb50 100755
--- a/kernel/conftest.sh
+++ b/kernel/conftest.sh
@@ -265,6 +265,23 @@ build_cflags() {
if [ -n "$BUILD_PARAMS" ]; then
CFLAGS="$CFLAGS -D$BUILD_PARAMS"
fi
+
+ # Check if gcc supports asm goto and set CC_HAVE_ASM_GOTO if it does.
+ # Older kernels perform this check and set this flag in Kbuild, and since
+ # conftest.sh runs outside of Kbuild it ends up building without this flag.
+ # Starting with commit e9666d10a5677a494260d60d1fa0b73cc7646eb3 this test
+ # is done within Kconfig, and the preprocessor flag is no longer needed.
+
+ GCC_GOTO_SH="$SOURCES/build/gcc-goto.sh"
+
+ if [ -f "$GCC_GOTO_SH" ]; then
+ # Newer versions of gcc-goto.sh don't print anything on success, but
+ # this is okay, since it's no longer necessary to set CC_HAVE_ASM_GOTO
+ # based on the output of those versions of gcc-goto.sh.
+ if [ `/bin/sh "$GCC_GOTO_SH" "$CC"` = "y" ]; then
+ CFLAGS="$CFLAGS -DCC_HAVE_ASM_GOTO"
+ fi
+ fi
}
CONFTEST_PREAMBLE="#include \"conftest.h\"
@@ -1521,6 +1538,35 @@ compile_test() {
compile_check_conftest "$CODE" "NV_DRM_AVAILABLE" "" "generic"
;;
+ drm_driver_prime_flag_present)
+ #
+ # Determine whether driver feature flag DRIVER_PRIME is present.
+ #
+ # The DRIVER_PRIME flag was added by commit 3248877ea179 (drm:
+ # base prime/dma-buf support (v5)) in v3.4 (2011-11-25) and is
+ # removed by commit 0424fdaf883a (drm/prime: Actually remove
+ # DRIVER_PRIME everywhere) on 2019-06-17.
+ #
+ # DRIVER_PRIME definition moved from drmP.h to drm_drv.h by
+ # commit 85e634bce01a (drm: Extract drm_drv.h) in v4.10
+ # (2016-11-14).
+ #
+ # DRIVER_PRIME define is changed to enum value by commit
+ # 0e2a933b02c9 (drm: Switch DRIVER_ flags to an enum) in v5.1
+ # (2019-01-29).
+ #
+ CODE="
+ #include <drm/drmP.h>
+ #if defined(NV_DRM_DRM_DRV_H_PRESENT)
+ #include <drm/drm_drv.h>
+ #endif
+ unsigned int drm_driver_prime_flag_present_conftest(void) {
+ return DRIVER_PRIME;
+ }"
+
+ compile_check_conftest "$CODE" "NV_DRM_DRIVER_PRIME_FLAG_PRESENT" "" "types"
+ ;;
+
proc_create_data)
#
# Determine if the proc_create_data() function is present.
diff --git a/nv-drm.c b/nv-drm.c
index 76719bb..12f7029 100644
--- a/kernel/nv-drm.c
+++ b/kernel/nv-drm.c
@@ -156,11 +156,14 @@ static const struct file_operations nv_drm_fops = {
};
static struct drm_driver nv_drm_driver = {
+ .driver_features =
+#if defined(NV_DRM_DRIVER_PRIME_FLAG_PRESENT)
+ DRIVER_PRIME |
+#endif
#if defined(DRIVER_LEGACY) || LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0)
- .driver_features = DRIVER_GEM | DRIVER_PRIME | DRIVER_LEGACY,
-#else
- .driver_features = DRIVER_GEM | DRIVER_PRIME,
+ DRIVER_LEGACY |
#endif
+ DRIVER_GEM,
.load = nv_drm_load,
.unload = nv_drm_unload,
.fops = &nv_drm_fops,
diff --git a/nvidia-modules-common.mk b/nvidia-modules-common.mk
index 8ac7058..7418005 100644
--- a/kernel/nvidia-modules-common.mk
+++ b/kernel/nvidia-modules-common.mk
@@ -180,7 +180,7 @@ ifndef NV_VERBOSE
endif
KBUILD_PARAMS += KBUILD_VERBOSE=$(NV_VERBOSE)
-KBUILD_PARAMS += -C $(KERNEL_SOURCES) SUBDIRS=$(PWD)
+KBUILD_PARAMS += -C $(KERNEL_SOURCES) M=$(PWD)
KBUILD_PARAMS += ARCH=$(ARCH)
#
--
2.20.1
@@ -0,0 +1,29 @@
Author: Andreas Beckmann <anbe@debian.org>
Description: use kmem_cache_create_usercopy on 4.16+
fixes "Bad or missing usercopy whitelist? Kernel memory exposure attempt
detected from SLUB object 'nvidia_stack_cache'" on linux-image-4.16.0-2-*
or newer that have disabled CONFIG_HARDENED_USERCOPY_FALLBACK
Bug-Debian: #901919, #899998
Bug: https://devtalk.nvidia.com/default/topic/1031067
--- a/kernel/nv-linux.h
+++ b/kernel/nv-linux.h
@@ -757,11 +757,18 @@ extern nv_spinlock_t km_lock;
0, 0, NULL, NULL); \
}
#elif (NV_KMEM_CACHE_CREATE_ARGUMENT_COUNT == 5)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)
+#define NV_KMEM_CACHE_CREATE(kmem_cache, name, type) \
+ { \
+ kmem_cache = kmem_cache_create_usercopy(name, sizeof(type), 0, 0, 0, sizeof(type), NULL); \
+ }
+#else
#define NV_KMEM_CACHE_CREATE(kmem_cache, name, type) \
{ \
kmem_cache = kmem_cache_create(name, sizeof(type), \
0, 0, NULL); \
}
+#endif
#else
#error "NV_KMEM_CACHE_CREATE_ARGUMENT_COUNT value unrecognized!"
#endif
View File
View File
View File
@@ -0,0 +1,199 @@
--- kernel/conftest.sh
+++ kernel/conftest.sh
@@ -168,6 +168,7 @@ test_headers() {
FILES="$FILES linux/sched/task.h"
FILES="$FILES xen/ioemu.h"
FILES="$FILES linux/fence.h"
+ FILES="$FILES linux/ktime.h"
FILES_ARCH="$FILES_ARCH asm/set_memory.h"
@@ -1971,6 +1972,38 @@ compile_test() {
compile_check_conftest "$CODE" "NV_DRM_DRIVER_UNLOAD_HAS_INT_RETURN_TYPE" "" "types"
;;
+ drm_gem_object_get)
+ #
+ # Determine if the function drm_gem_object_get() is present.
+ #
+ CODE="
+ #include <drm/drmP.h>
+ #if defined(NV_DRM_DRM_GEM_H_PRESENT)
+ #include <drm/drm_gem.h>
+ #endif
+ void conftest_drm_gem_object_get(void) {
+ drm_gem_object_get();
+ }"
+
+ compile_check_conftest "$CODE" "NV_DRM_GEM_OBJECT_GET_PRESENT" "" "functions"
+ ;;
+
+ do_gettimeofday)
+ #
+ # Determine if the function do_gettimeofday() is present.
+ #
+ CODE="
+ #include <linux/time.h>
+ #if defined(NV_LINUX_KTIME_H_PRESENT)
+ #include <linux/ktime.h>
+ #endif
+ void conftest_do_gettimeofday(void) {
+ do_gettimeofday();
+ }"
+
+ compile_check_conftest "$CODE" "NV_DO_GETTIMEOFDAY_PRESENT" "" "functions"
+ ;;
+
drm_legacy_pci_init)
#
# Determine if drm_legacy_pci_init() is present. drm_pci_init() was
--- kernel/nv-drm.c
+++ kernel/nv-drm.c
@@ -37,6 +37,16 @@ struct nv_gem_object {
struct page **pages;
};
+static inline void
+nv_drm_gem_object_unreference_unlocked(struct nv_gem_object *nv_gem)
+{
+#if defined(NV_DRM_GEM_OBJECT_GET_PRESENT)
+ drm_gem_object_put_unlocked(&nv_gem->base);
+#else
+ drm_gem_object_unreference_unlocked(&nv_gem->base);
+#endif
+}
+
static int nv_drm_load(
struct drm_device *dev,
unsigned long flags
@@ -252,7 +262,7 @@ RM_STATUS NV_API_CALL nv_alloc_os_descriptor_handle(
goto done;
}
- drm_gem_object_unreference_unlocked(&nv_obj->base);
+ nv_drm_gem_object_unreference_unlocked(nv_obj);
status = RM_OK;
--- /dev/null
+++ kernel/nv-time.h
@@ -0,0 +1,24 @@
+#ifndef __NV_TIME_H__
+#define __NV_TIME_H__
+
+#include "conftest.h"
+#include <linux/time.h>
+
+#if defined(NV_LINUX_KTIME_H_PRESENT)
+#include <linux/ktime.h>
+#endif
+
+static inline void nv_gettimeofday(struct timeval *tv)
+{
+#ifdef NV_DO_GETTIMEOFDAY_PRESENT
+ do_gettimeofday(tv);
+#else
+ struct timespec64 now;
+
+ ktime_get_real_ts64(&now);
+ tv->tv_sec = now.tv_sec;
+ tv->tv_usec = now.tv_nsec/1000;
+#endif
+}
+
+#endif
--- kernel/os-interface.c
+++ kernel/os-interface.c
@@ -13,6 +13,7 @@
#include "os-interface.h"
#include "nv-linux.h"
+#include "nv-time.h"
RM_STATUS NV_API_CALL os_disable_console_access(void)
{
@@ -440,7 +441,7 @@ RM_STATUS NV_API_CALL os_get_current_time(
{
struct timeval tm;
- do_gettimeofday(&tm);
+ nv_gettimeofday(&tm);
*seconds = tm.tv_sec;
*useconds = tm.tv_usec;
@@ -475,7 +476,7 @@ RM_STATUS NV_API_CALL os_delay_us(NvU32 MicroSeconds)
#ifdef NV_CHECK_DELAY_ACCURACY
struct timeval tm1, tm2;
- do_gettimeofday(&tm1);
+ nv_gettimeofday(&tm1);
#endif
if (in_irq() && (MicroSeconds > NV_MAX_ISR_DELAY_US))
@@ -490,7 +491,7 @@ RM_STATUS NV_API_CALL os_delay_us(NvU32 MicroSeconds)
udelay(usec);
#ifdef NV_CHECK_DELAY_ACCURACY
- do_gettimeofday(&tm2);
+ nv_gettimeofday(&tm2);
nv_printf(NV_DBG_ERRORS, "NVRM: osDelayUs %d: 0x%x 0x%x\n",
MicroSeconds, tm2.tv_sec - tm1.tv_sec, tm2.tv_usec - tm1.tv_usec);
#endif
@@ -518,7 +519,7 @@ RM_STATUS NV_API_CALL os_delay(NvU32 MilliSeconds)
struct timeval tm_start;
#endif
- do_gettimeofday(&tm_aux);
+ nv_gettimeofday(&tm_aux);
#ifdef NV_CHECK_DELAY_ACCURACY
tm_start = tm_aux;
#endif
@@ -552,7 +553,7 @@ RM_STATUS NV_API_CALL os_delay(NvU32 MilliSeconds)
do
{
schedule_timeout(jiffies);
- do_gettimeofday(&tm_aux);
+ nv_gettimeofday(&tm_aux);
if (NV_TIMERCMP(&tm_aux, &tm_end, <))
{
NV_TIMERSUB(&tm_end, &tm_aux, &tm_aux);
@@ -574,7 +575,7 @@ RM_STATUS NV_API_CALL os_delay(NvU32 MilliSeconds)
udelay(MicroSeconds);
}
#ifdef NV_CHECK_DELAY_ACCURACY
- do_gettimeofday(&tm_aux);
+ nv_gettimeofday(&tm_aux);
timersub(&tm_aux, &tm_start, &tm_aux);
nv_printf(NV_DBG_ERRORS, "NVRM: osDelay %dmsec: %d.%06dsec\n",
MilliSeconds, tm_aux.tv_sec, tm_aux.tv_usec);
--- kernel/uvm/nvidia_uvm_linux.h
+++ kernel/uvm/nvidia_uvm_linux.h
@@ -146,6 +146,7 @@
#include <linux/interrupt.h> /* tasklets, interrupt helpers */
#include <linux/timer.h>
#include <linux/time.h> /* do_gettimeofday()*/
+#include "nv-time.h"
#include <asm/div64.h> /* do_div() */
#if defined(NV_ASM_SYSTEM_H_PRESENT)
--- kernel/uvm/nvidia_uvm_lite.c
+++ kernel/uvm/nvidia_uvm_lite.c
@@ -2019,7 +2019,7 @@ static RM_STATUS _check_ecc_errors(UvmGpuMigrationTracking *pMigTracker,
{
if (!!(rmInterruptSet) && !bEccIncomingError)
{
- do_gettimeofday(&eccErrorStartTime);
+ nv_gettimeofday(&eccErrorStartTime);
_set_timeout_in_usec(&eccErrorStartTime, &eccTimeout,
UVM_ECC_ERR_TIMEOUT_USEC);
@@ -2051,7 +2051,7 @@ static RM_STATUS _check_ecc_errors(UvmGpuMigrationTracking *pMigTracker,
//
if (!!(rmInterruptSet) && (eccErrorStartTime.tv_usec != 0))
{
- do_gettimeofday(&eccErrorCurrentTime);
+ nv_gettimeofday(&eccErrorCurrentTime);
if ((eccErrorCurrentTime.tv_sec > eccTimeout.tv_sec) ||
((eccErrorCurrentTime.tv_sec == eccTimeout.tv_sec) &&
(eccErrorCurrentTime.tv_usec >= eccTimeout.tv_usec)))
@@ -0,0 +1,28 @@
Author: Andreas Beckmann <anbe@debian.org>
Description: unregister procfs upon module load failure
the nvidia module may leave stale proc entries if it refuses to be
loaded becase nouveau is already loaded and has claimed the device
.
the error unwinding in nvidia_init_module() is insane
(375.26 looks much better)
.
this patch is probably not correct in all cases, but the unwinding is
not reverse linear in creation and the gotos are all across everything
.
leaving stale proc entries prevents the nvidia module from loading again
.
accessing the stale proc entries results in
BUG: unable to handle kernel paging request at ...
Bug-Debian: #764639
--- a/kernel/nv.c
+++ b/kernel/nv.c
@@ -1038,6 +1038,8 @@ failed3:
pci_unregister_driver(&nv_pci_driver);
+ nv_unregister_procfs();
+
failed5:
rm_shutdown_rm(sp);