[linux416][nvidia 390.48] nvidia_stack_cache RIP: 0010:usercopy_warn+0x7e/0xa0

Same thing here! Drivers beyond 390 don’t work with GeForce GTX 680. (They are simply broken here)
Kernel 340 would not work after the meltdown/spectre fixes.
So this is a deadlock situation

Hello.
Please add this fix to the 340 branch.
I am using a 8800GT and I have this issue too.

Adding this to v340.108 or next release branch IS VERY WELCOMED! Our 3d apps are breaking often (on average - every second window opening) which is extremally annoying and makes our work much harder and stressful.
NVIDIA 215GTX aka 350M on Xorg with v340.108 suffers this problem on EVERY kernel from 5.0 up.
On 4.15 kernel no problems with garbage, but the overall stability could be better…

PLEASE, update this driver too!

Patches from paxguy [1] fixed an issue like this by changing the NV_KMEM_CACHE_CREATE macro in source, specifying SLAB_USERCOPY on the kmem_cache_create function call. This doesn’t work, obviously, with the official kernel, so instead we’ll check for the presence of the kmem_cache_create_usercopy function – just like the later driver versions did.

Here is an adapted patch for 340.108 that might fix it:

diff --git a/kernel/Makefile b/kernel/Makefile
index 125a690..2b28a4d 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -108,6 +108,7 @@ COMPILE_TESTS = \
 	acquire_console_sem \
 	console_lock \
 	kmem_cache_create \
+	kmem_cache_create_usercopy \
 	outer_flush_all \
 	on_each_cpu \
 	smp_call_function \
diff --git a/kernel/conftest.sh b/kernel/conftest.sh
index b7a85f0..f55db8e 100755
--- a/kernel/conftest.sh
+++ b/kernel/conftest.sh
@@ -914,6 +914,21 @@ compile_test() {
             fi
         ;;
 
+        kmem_cache_create_usercopy)
+            #
+            # Determine if the kmem_cache_create_usercopy function exists.
+            #
+            # This function was added by:
+            #   2017-06-10  8eb8284b412906181357c2b0110d879d5af95e52
+            CODE="
+            #include <linux/slab.h>
+            void kmem_cache_create_usercopy(void) {
+                kmem_cache_create_usercopy();
+            }"
+
+            compile_check_conftest "$CODE" "NV_KMEM_CACHE_CREATE_USERCOPY_PRESENT" "" "functions"
+        ;;
+
         smp_call_function)
             #
             # Determine if the smp_call_function() function is
diff --git a/kernel/nv-linux.h b/kernel/nv-linux.h
index a1d2c68..f15afad 100644
--- a/kernel/nv-linux.h
+++ b/kernel/nv-linux.h
@@ -774,6 +774,17 @@ extern nv_spinlock_t km_lock;
 #error "NV_KMEM_CACHE_CREATE() undefined (kmem_cache_create() unavailable)!"
 #endif
 
+#if defined(NV_KMEM_CACHE_CREATE_USERCOPY_PRESENT)
+#define NV_KMEM_CACHE_CREATE_USERCOPY(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_USERCOPY(kmem_cache, name, type)       \
+        NV_KMEM_CACHE_CREATE(kmem_cache, name, type)
+#endif
+
 #define NV_KMEM_CACHE_ALLOC(ptr, kmem_cache, type)              \
     {                                                           \
         (ptr) = kmem_cache_alloc(kmem_cache, GFP_KERNEL);       \
diff --git a/kernel/nv.c b/kernel/nv.c
index a167be9..a218f83 100644
--- a/kernel/nv.c
+++ b/kernel/nv.c
@@ -752,7 +752,7 @@ int __init nvidia_init_module(void)
     NV_SPIN_LOCK_INIT(&km_lock);
 #endif
 
-    NV_KMEM_CACHE_CREATE(nv_stack_t_cache, NV_STACK_CACHE_STR, nv_stack_t);
+    NV_KMEM_CACHE_CREATE_USERCOPY(nv_stack_t_cache, NV_STACK_CACHE_STR, nv_stack_t);
     if (nv_stack_t_cache == NULL)
     {
         nv_printf(NV_DBG_ERRORS, "NVRM: stack cache allocation failed!\n");

Note: This is untested, so use on your own risk.

  1. https://www.grsecurity.net/~paxguy1/nvidia-drivers-346.16-pax-usercopy.patch

Edit: Edited for clarity.