Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INFO/PATCH] Nvidia driver 510 on kernel 6.2 #160

Open
shelterx opened this issue Apr 18, 2023 · 4 comments
Open

[INFO/PATCH] Nvidia driver 510 on kernel 6.2 #160

shelterx opened this issue Apr 18, 2023 · 4 comments

Comments

@shelterx
Copy link

shelterx commented Apr 18, 2023

I spent quite some time trying to find a working patch for the Nvidia 510 driver and kernel 6.2.
It turns out there's a patch but it's for driver version 510.108.03 and that driver isn't available in the nvidia-all package.
However I managed to get it to install it by modifying the PKGBUILD file slightly.

Maybe this can be integrated in the script, it would help other people wanting 510 on kernel 6.2, the way I did it was a bit of a "hack".
I did have some issue tho', I think it breaks nvidia-drm modeset=1 :(
Anyway, the patch for kernel 6.2 is "originally" from here.

--- a/nvidia-drm/nvidia-drm-connector.c	2023-03-04 08:32:31.663651988 +0000
+++ b/nvidia-drm/nvidia-drm-connector.c	2023-03-04 08:33:16.124316171 +0000
@@ -30,6 +30,9 @@
 #include "nvidia-drm-utils.h"
 #include "nvidia-drm-encoder.h"
 
+#include <linux/version.h>
+#include <linux/utsname.h>
+
 /*
  * Commit fcd70cd36b9b ("drm: Split out drm_probe_helper.h")
  * moves a number of helper function definitions from
@@ -58,6 +61,24 @@ static void nv_drm_connector_destroy(str
     nv_drm_free(nv_connector);
 }
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0)
+static bool check_edid_override(struct drm_connector *connector)
+{
+	return connector->override_edid != NULL;
+}
+#else
+static bool check_edid_override(struct drm_connector *connector)
+{
+	int ret;
+
+	mutex_lock(&connector->edid_override_mutex);
+	ret = connector->edid_override != NULL;
+	mutex_lock(&connector->edid_override_mutex);
+
+	return ret;
+}
+#endif
+
 static bool
 __nv_drm_detect_encoder(struct NvKmsKapiDynamicDisplayParams *pDetectParams,
                         struct drm_connector *connector,
@@ -98,7 +119,7 @@ __nv_drm_detect_encoder(struct NvKmsKapi
             break;
     }
 
-    if (connector->override_edid) {
+    if (check_edid_override(connector)) {
         const struct drm_property_blob *edid = connector->edid_blob_ptr;
 
         if (edid->length <= sizeof(pDetectParams->edid.buffer)) {
--- a/nvidia-drm/nvidia-drm-drv.c	2023-03-04 08:32:31.663651988 +0000
+++ b/nvidia-drm/nvidia-drm-drv.c	2023-03-04 08:33:16.124316171 +0000
@@ -62,6 +62,9 @@
 
 #include <linux/pci.h>
 
+#include <linux/version.h>
+#include <linux/utsname.h>
+
 /*
  * Commit fcd70cd36b9b ("drm: Split out drm_probe_helper.h")
  * moves a number of helper function definitions from
@@ -240,9 +243,10 @@ nv_drm_init_mode_config(struct nv_drm_de
     dev->mode_config.preferred_depth = 24;
     dev->mode_config.prefer_shadow = 1;
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0)
     /* Currently unused. Update when needed. */
-
     dev->mode_config.fb_base = 0;
+#endif
 
 #if defined(NV_DRM_CRTC_STATE_HAS_ASYNC_FLIP) || \
     defined(NV_DRM_CRTC_STATE_HAS_PAGEFLIP_FLAGS)

@shelterx shelterx changed the title [INFO [INFO/PATCH] Nvidia driver 510 on kernel 6.2 Apr 18, 2023
@shelterx
Copy link
Author

A note tho', the Makefile in the installed kernels modules directory (/lib/modules) needs to be modified if you compile this with clang. Else the -Werror flags in the Makefile would cause the driver build to fail.
I have not tried with gcc.

@shelterx
Copy link
Author

And here's the patch for kernel 6.3: https://gist.github.com/joanbm/d10e9cbbbb8e245b6e7e27b2db338faf

From a77f2da778f4a62695a6c7d26bba674d59ad9170 Mon Sep 17 00:00:00 2001
From: Joan Bruguera <[email protected]>
Date: Sat, 25 Feb 2023 10:57:09 +0000
Subject: [PATCH] Tentative fix for NVIDIA 470.161.03 driver for Linux 6.3-rc1

---
 common/inc/nv-linux.h                   | 13 +++++++++++++
 nvidia-drm/nvidia-drm-gem-user-memory.c |  7 ++++---
 nvidia-uvm/uvm.c                        |  2 +-
 nvidia/nv-mmap.c                        | 12 ++++++------
 4 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/common/inc/nv-linux.h b/common/inc/nv-linux.h
index f8df9e3..5b22cf1 100644
--- a/common/inc/nv-linux.h
+++ b/common/inc/nv-linux.h
@@ -1988,4 +1988,17 @@ static inline void nv_mutex_destroy(struct mutex *lock)
 
 }
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 3, 0)
+// Rel. commit "mm: introduce vma->vm_flags wrapper functions" (Suren Baghdasaryan, 26 Jan 2023)
+static inline void vm_flags_set(struct vm_area_struct *vma, vm_flags_t flags)
+{
+    vma->vm_flags |= flags;
+}
+
+static inline void vm_flags_clear(struct vm_area_struct *vma, vm_flags_t flags)
+{
+    vma->vm_flags &= ~flags;
+}
+#endif
+
 #endif  /* _NV_LINUX_H_ */
diff --git a/nvidia-drm/nvidia-drm-gem-user-memory.c b/nvidia-drm/nvidia-drm-gem-user-memory.c
index 8824daa..3ea9099 100644
--- a/nvidia-drm/nvidia-drm-gem-user-memory.c
+++ b/nvidia-drm/nvidia-drm-gem-user-memory.c
@@ -35,6 +35,7 @@
 #include "linux/dma-buf.h"
 #include "linux/mm.h"
 #include "nv-mm.h"
+#include "nv-linux.h"
 
 static inline
 void __nv_drm_gem_user_memory_free(struct nv_drm_gem_object *nv_gem)
@@ -92,9 +93,9 @@ static int __nv_drm_gem_user_memory_mmap(struct nv_drm_gem_object *nv_gem,
         return -EINVAL;
     }
 
-    vma->vm_flags &= ~VM_PFNMAP;
-    vma->vm_flags &= ~VM_IO;
-    vma->vm_flags |= VM_MIXEDMAP;
+    vm_flags_clear(vma, VM_PFNMAP);
+    vm_flags_clear(vma, VM_IO);
+    vm_flags_set(vma, VM_MIXEDMAP);
 
     return 0;
 }
diff --git a/nvidia-uvm/uvm.c b/nvidia-uvm/uvm.c
index 3e7318d..7eddff7 100644
--- a/nvidia-uvm/uvm.c
+++ b/nvidia-uvm/uvm.c
@@ -812,7 +812,7 @@ static int uvm_mmap(struct file *filp, struct vm_area_struct *vma)
     // Using VM_DONTCOPY would be nice, but madvise(MADV_DOFORK) can reset that
     // so we have to handle vm_open on fork anyway. We could disable MADV_DOFORK
     // with VM_IO, but that causes other mapping issues.
-    vma->vm_flags |= VM_MIXEDMAP | VM_DONTEXPAND;
+    vm_flags_set(vma, VM_MIXEDMAP | VM_DONTEXPAND);
 
     vma->vm_ops = &uvm_vm_ops_managed;
 
diff --git a/nvidia/nv-mmap.c b/nvidia/nv-mmap.c
index df514c9..8f85ff6 100644
--- a/nvidia/nv-mmap.c
+++ b/nvidia/nv-mmap.c
@@ -447,7 +447,7 @@ static int nvidia_mmap_numa(
     }
 
     // Needed for the linux kernel for mapping compound pages
-    vma->vm_flags |= VM_MIXEDMAP;
+    vm_flags_set(vma, VM_MIXEDMAP);
 
     for (i = 0, addr = mmap_context->page_array[0]; i < pages;
          addr = mmap_context->page_array[++i], start += PAGE_SIZE)
@@ -596,7 +596,7 @@ int nvidia_mmap_helper(
         }
         up(&nvl->mmap_lock);
 
-        vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND;
+        vm_flags_set(vma, VM_IO | VM_PFNMAP | VM_DONTEXPAND);
     }
     else
     {
@@ -663,15 +663,15 @@ int nvidia_mmap_helper(
 
         NV_PRINT_AT(NV_DBG_MEMINFO, at);
 
-        vma->vm_flags |= (VM_IO | VM_LOCKED | VM_RESERVED);
-        vma->vm_flags |= (VM_DONTEXPAND | VM_DONTDUMP);
+        vm_flags_set(vma, VM_IO | VM_LOCKED | VM_RESERVED);
+        vm_flags_set(vma, VM_DONTEXPAND | VM_DONTDUMP);
     }
 
     if ((prot & NV_PROTECT_WRITEABLE) == 0)
     {
         vma->vm_page_prot = NV_PGPROT_READ_ONLY(vma->vm_page_prot);
-        vma->vm_flags &= ~VM_WRITE;
-        vma->vm_flags &= ~VM_MAYWRITE;
+        vm_flags_clear(vma, VM_WRITE);
+        vm_flags_clear(vma, VM_MAYWRITE);
     }
 
     vma->vm_ops = &nv_vm_ops;
-- 
2.39.2

@ryanmusante
Copy link

Is 510 for compatibility with certain configurations?

@shelterx
Copy link
Author

515-530 got a bug where Assassin's Creed Valhalla won't run for example. It might affect other stuff too so I stick with 510 for now since it works best for me right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants