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

Fix nvidia driver for 6.12 #353636

Closed
500InternalError opened this issue Nov 4, 2024 · 8 comments
Closed

Fix nvidia driver for 6.12 #353636

500InternalError opened this issue Nov 4, 2024 · 8 comments
Labels
0.kind: bug Something is broken

Comments

@500InternalError
Copy link
Contributor

Describe the bug

Currently the output of nvidia card is unavaliable on machines running 6.12 kernel(at least it doesn't work for me)

Steps To Reproduce

Steps to reproduce the behavior:

  1. Patching nvidia driver with the following lines(required for 6.12 to enable display according to WARNING: CPU: X PID: XXXX at include/linux/rwsem.h:80 follow_pte+0xf8/0x120 on resume NVIDIA/open-gpu-kernel-modules#719 (comment)):
    nvidia = {
      open = true;
      package = config.boot.kernelPackages.nvidiaPackages.mkDriver {
        version = "565.57.01";
        sha256_64bit = "sha256-buvpTlheOF6IBPWnQVLfQUiHv4GcwhvZW3Ks0PsYLHo=";
        sha256_aarch64 = "sha256-aDVc3sNTG4O3y+vKW87mw+i9AqXCY29GVqEIUlsvYfE=";
        openSha256 = "sha256-/tM3n9huz1MTE6KKtTCBglBMBGGL/GOHi5ZSUag4zXA=";
        settingsSha256 = "sha256-H7uEe34LdmUFcMcS6bz7sbpYhg9zPCb/5AmZZFTx1QA=";
        persistencedSha256 = "sha256-hdszsACWNqkCh8G4VBNitDT85gk9gJe1BlQ8LdrYIkg=";
        patchesOpen = [
          ./nvidia.patch
        ];
      };
      };
    };
  };

contents of nvidia.patch:

diff --git a/kernel-open/nvidia-drm/nvidia-drm-drv.c b/kernel-open/nvidia-drm/nvidia-drm-drv.c
index 8cb94219..27b3cbd9 100644
--- a/kernel-open/nvidia-drm/nvidia-drm-drv.c
+++ b/kernel-open/nvidia-drm/nvidia-drm-drv.c
@@ -100,6 +100,8 @@
 #include <drm/drm_atomic_helper.h>
 #endif
 
+#include <drm/drm_client.h>
+
 static int nv_drm_revoke_modeset_permission(struct drm_device *dev,
                                             struct drm_file *filep,
                                             NvU32 dpyId);
@@ -1711,6 +1713,8 @@
     .read           = drm_read,
 
     .llseek         = noop_llseek,
+    // Rel. commit. "fs: move FMODE_UNSIGNED_OFFSET to fop_flags" (Christian Brauner, 9 Aug 2024)
+    .fop_flags      = FOP_UNSIGNED_OFFSET,
 };
 
 static const struct drm_ioctl_desc nv_drm_ioctls[] = {
@@ -1939,6 +1943,18 @@
 }
 
 
+static int hotplug_helper_client_hotplug(struct drm_client_dev *client)
+{
+    nv_drm_output_poll_changed(client->dev);
+    return 0;
+}
+ 
+static const struct drm_client_funcs nv_hotplug_helper_client_funcs = {
+    .owner      = THIS_MODULE,
+    .hotplug    = hotplug_helper_client_hotplug,
+};
+
+
 
 /*
  * Helper function for allocate/register DRM device for given NVIDIA GPU ID.
@@ -2029,8 +2045,23 @@
     nv_dev->next = dev_list;
     dev_list = nv_dev;
 
+    /* Register a DRM client for receiving hotplug events */
+    struct drm_client_dev *client = kzalloc(sizeof(*client), GFP_KERNEL);
+    if (client == NULL || drm_client_init(dev, client,
+        "nv-hotplug-helper", &nv_hotplug_helper_client_funcs)) {
+        printk(KERN_WARNING "Failed to initialize the nv-hotplug-helper DRM client.");
+        goto failed_drm_client_init;
+    }
+
+    drm_client_register(client);
+    pr_info("Registered the nv-hotplug-helper DRM client.");
+
     return; /* Success */
 
+failed_drm_client_init:
+
+    kfree(client);
+
 failed_drm_register:
 
     nv_drm_dev_free(dev);
  1. nvidia-open doesn't compile, log showing:
/build/source/kernel-open/nvidia-drm/nvidia-drm-drv.c: In function 'hotplug_helper_client_hotplug':
/build/source/kernel-open/nvidia-drm/nvidia-drm-drv.c:1948:5: error: implicit declaration of function 'nv_drm_output_poll_changed' [-Werror=implicit-function-declaration]
 1948 |     nv_drm_output_poll_changed(client->dev);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~
  CC [M]  /build/source/kernel-open/nvidia-drm/nv-pci-table.o
  CC [M]  /build/source/kernel-open/nvidia-drm/nvidia-drm-gem-nvkms-memory.o
  CC [M]  /build/source/kernel-open/nvidia-drm/nvidia-drm-gem-user-memory.o

Expected behavior

The kernel module should compile

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

Notify maintainers

@NickCao

Metadata

> $ nix-shell -p nix-info --run "nix-info -m"                                                                                                                                    
 - system: `"x86_64-linux"`
 - host os: `Linux 6.12.0-rc5, NixOS, 24.11 (Vicuna), 24.11.20241102.7ffd9ae`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.24.9`
 - channels(root): `"nixos"`
 - nixpkgs: `/nix/store/zq2axpgzd5kykk1v446rkffj3bxa2m2h-source`

Add a 👍 reaction to issues you find important.

@500InternalError 500InternalError added the 0.kind: bug Something is broken label Nov 4, 2024
@vssukharev
Copy link

vssukharev commented Nov 21, 2024

Is it like working now? I'm stuck with same issue with stable nvidia drivers and latest kernel. Beta drivers solve the problem.

@500InternalError
Copy link
Contributor Author

It seems like a problem of my patch.Try this patch:

diff --git a/kernel-open/nvidia-drm/nvidia-drm-drv.c b/kernel-open/nvidia-drm/nvidia-drm-drv.c
index 8cb94219..27b3cbd9 100644
--- a/kernel-open/nvidia-drm/nvidia-drm-drv.c
+++ b/kernel-open/nvidia-drm/nvidia-drm-drv.c
@@ -100,6 +100,11 @@
 #include <drm/drm_atomic_helper.h>
 #endif
 
+#include <linux/version.h>
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 12, 0)
+#include <drm/drm_client.h>
+#endif
+
 static int nv_drm_revoke_modeset_permission(struct drm_device *dev,
                                             struct drm_file *filep,
                                             NvU32 dpyId);
@@ -147,7 +152,7 @@
 
 #if defined(NV_DRM_ATOMIC_MODESET_AVAILABLE)
 
-#if defined(NV_DRM_OUTPUT_POLL_CHANGED_PRESENT)
+
 static void nv_drm_output_poll_changed(struct drm_device *dev)
 {
     struct drm_connector *connector = NULL;
@@ -191,7 +196,7 @@
     nv_drm_connector_list_iter_end(&conn_iter);
 #endif
 }
-#endif /* NV_DRM_OUTPUT_POLL_CHANGED_PRESENT */
+
 
 static struct drm_framebuffer *nv_drm_framebuffer_create(
     struct drm_device *dev,
@@ -229,9 +234,7 @@
     .atomic_check  = nv_drm_atomic_check,
     .atomic_commit = nv_drm_atomic_commit,
 
-    #if defined(NV_DRM_OUTPUT_POLL_CHANGED_PRESENT)
-    .output_poll_changed = nv_drm_output_poll_changed,
-    #endif
+
 };
 
 static void nv_drm_event_callback(const struct NvKmsKapiEvent *event)
@@ -1711,6 +1714,10 @@
     .read           = drm_read,
 
     .llseek         = noop_llseek,
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 12, 0)
+    // Rel. commit. "fs: move FMODE_UNSIGNED_OFFSET to fop_flags" (Christian Brauner, 9 Aug 2024)
+    .fop_flags      = FOP_UNSIGNED_OFFSET,
+#endif
 };
 
 static const struct drm_ioctl_desc nv_drm_ioctls[] = {
@@ -1939,6 +1946,20 @@
 }
 
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 12, 0)
+static int hotplug_helper_client_hotplug(struct drm_client_dev *client)
+{
+    nv_drm_output_poll_changed(client->dev);
+    return 0;
+}
+ 
+static const struct drm_client_funcs nv_hotplug_helper_client_funcs = {
+    .owner      = THIS_MODULE,
+    .hotplug    = hotplug_helper_client_hotplug,
+};
+#endif
+
+
 
 /*
  * Helper function for allocate/register DRM device for given NVIDIA GPU ID.
@@ -2029,8 +2050,27 @@
     nv_dev->next = dev_list;
     dev_list = nv_dev;
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 12, 0)
+    /* Register a DRM client for receiving hotplug events */
+    struct drm_client_dev *client = kzalloc(sizeof(*client), GFP_KERNEL);
+    if (client == NULL || drm_client_init(dev, client,
+        "nv-hotplug-helper", &nv_hotplug_helper_client_funcs)) {
+        printk(KERN_WARNING "Failed to initialize the nv-hotplug-helper DRM client.");
+        goto failed_drm_client_init;
+    }
+
+    drm_client_register(client);
+    pr_info("Registered the nv-hotplug-helper DRM client.");
+#endif
+
     return; /* Success */
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 12, 0)
+failed_drm_client_init:
+
+    kfree(client);
+#endif
+
 failed_drm_register:
 
     nv_drm_dev_free(dev);

@vssukharev
Copy link

Thanks. How can I override standard package?

@500InternalError
Copy link
Contributor Author

set

hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.mkDriver {
        version = "565.57.01";
        sha256_64bit = "sha256-buvpTlheOF6IBPWnQVLfQUiHv4GcwhvZW3Ks0PsYLHo=";
        sha256_aarch64 = "sha256-aDVc3sNTG4O3y+vKW87mw+i9AqXCY29GVqEIUlsvYfE=";
        openSha256 = "sha256-/tM3n9huz1MTE6KKtTCBglBMBGGL/GOHi5ZSUag4zXA=";
        settingsSha256 = "sha256-H7uEe34LdmUFcMcS6bz7sbpYhg9zPCb/5AmZZFTx1QA=";
        persistencedSha256 = "sha256-hdszsACWNqkCh8G4VBNitDT85gk9gJe1BlQ8LdrYIkg=";
        patchesOpen = [
          ./path_of_this_patch
        ];
      };

@vssukharev
Copy link

Thanks!

Mindavi added a commit to Mindavi/nixos-configuration that referenced this issue Nov 24, 2024
frandmb added a commit to frandmb/dotfiles that referenced this issue Nov 26, 2024
driver 560 (latest) requires a patch to compile on 6.12, switching to beta for now. NixOS/nixpkgs#353636
@philiptaron
Copy link
Contributor

As of a few days ago, the latest production driver now supports kernel 6.12.

@Saiv46
Copy link

Saiv46 commented Feb 12, 2025

I still get compilation error of latest driver on kernel 6.12.10

@hoh
Copy link
Contributor

hoh commented Feb 14, 2025

Upgrading to Nvidia drivers 570 solves the issue.

hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.mkDriver {                                            
    version = "570.86.16"; # use new 570 drivers                                                            
    sha256_64bit = "sha256-RWPqS7ZUJH9JEAWlfHLGdqrNlavhaR1xMyzs8lJhy9U=";                                   
    openSha256 = "sha256-DuVNA63+pJ8IB7Tw2gM4HbwlOh1bcDg2AN2mbEU9VPE=";                                     
    settingsSha256 = "sha256-9rtqh64TyhDF5fFAYiWl3oDHzKJqyOW3abpcf2iNRT8=";                                 
    usePersistenced = false;                                                                                
};                 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken
Projects
None yet
Development

No branches or pull requests

5 participants