Skip to content

Instantly share code, notes, and snippets.

@joanbm
Last active March 4, 2025 20:24
Show Gist options
  • Save joanbm/a6d3f7f873a60dec0aa4a734c0f1d64e to your computer and use it in GitHub Desktop.
Save joanbm/a6d3f7f873a60dec0aa4a734c0f1d64e to your computer and use it in GitHub Desktop.
Tentative fix for NVIDIA 470.256.02 driver for Linux 6.12-rc1
From 839b964bd5be20275a4d1add020e68e407380adb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joan=20Bruguera=20Mic=C3=B3?= <joanbrugueram@gmail.com>
Date: Sat, 17 Aug 2024 14:26:04 +0000
Subject: [PATCH] Tentative fix for NVIDIA 470.256.02 driver for Linux 6.12-rc1
Note that the fix requires enabling DRM kernel mode setting
(add the `nvidia-drm.modeset=1` parameter to the kernel command line).
(Thanks xtexChooser for the memory management fixes!)
---
nvidia-drm/nvidia-drm-drv.c | 47 +++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/nvidia-drm/nvidia-drm-drv.c b/nvidia-drm/nvidia-drm-drv.c
index f350134..d6233a5 100644
--- a/nvidia-drm/nvidia-drm-drv.c
+++ b/nvidia-drm/nvidia-drm-drv.c
@@ -84,6 +84,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 struct nv_drm_device *dev_list = NULL;
#if defined(NV_DRM_ATOMIC_MODESET_AVAILABLE)
@@ -168,7 +173,12 @@ static const struct drm_mode_config_funcs nv_mode_config_funcs = {
.atomic_check = nv_drm_atomic_check,
.atomic_commit = nv_drm_atomic_commit,
+#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 12, 0)
+ // Rel. commit. "drm: Remove struct drm_mode_config_funcs.output_poll_changed" (Thomas Zimmermann, 12 Aug 2024)
+ // Replace this callback with a DRM client's hotplug callback.
+ // This is required for e.g. /sys/class/drm/card*/modes to work.
.output_poll_changed = nv_drm_output_poll_changed,
+#endif
};
static void nv_drm_event_callback(const struct NvKmsKapiEvent *event)
@@ -739,6 +749,10 @@ static const struct file_operations nv_drm_fops = {
.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[] = {
@@ -906,7 +920,18 @@ static void nv_drm_update_drm_driver_features(void)
#endif /* NV_DRM_ATOMIC_MODESET_AVAILABLE */
}
+#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.
@@ -962,6 +987,20 @@ static void nv_drm_register_drm_device(const nv_gpu_info_t *gpu_info)
goto failed_drm_register;
}
+#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"
+ " (ensure DRM kernel mode setting is enabled via nvidia-drm.modeset=1).\n");
+ goto failed_drm_client_init;
+ }
+
+ drm_client_register(client);
+ pr_info("Registered the nv-hotplug-helper DRM client.\n");
+#endif
+
/* Add NVIDIA-DRM device into list */
nv_dev->next = dev_list;
@@ -969,6 +1008,14 @@ static void nv_drm_register_drm_device(const nv_gpu_info_t *gpu_info)
return; /* Success */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 12, 0)
+failed_drm_client_init:
+
+ kfree(client);
+ drm_dev_unregister(dev);
+
+#endif
+
failed_drm_register:
nv_drm_dev_free(dev);
--
2.47.0
@Augusto7743
Copy link

I have done na test and the driver was patched correctly.
Thanks for your reply helping !
Now the next step ... try find an Linux kernel current version in file format deb for simple install in Ubuntu 24.04.
Ubuntu mainline kernels not are signed. When installing some softwares not make new modules using dkms because the kernel is unsigned.

All good and good luck in your path ... You have all it !

@Augusto7743
Copy link

I have patched and tested in kernel liquorix 6.11 and all works corectly.
Not any issues.
THANKS VERY MUCH !

@hadjiprocopis
Copy link

Note that the fix requires enabling DRM kernel mode setting
(add the `nvidia-drm.modeset=1` parameter to the kernel command line).

Well, your fix did really work for Fedora 39 and also after upgrading to Fedora 41.
But after a kernel update to 6.11.11 (around 12/12/2024) the Xserver did not start on normal boot. But when I reboot on non-graphical mode (init 3) and did startx it did start the X server.

Anyway, to cut the short story long I have now REMOVED the nvidia-drm.modeset=1 from the kernel command line (/etc/default/grub.conf) and also in /etc/modprobe.d/nvidia/conf I now have:

options nvidia NVreg_PreserveVideoMemoryAllocations=0
options nvidia_drm modeset=0

And all that mystically spawns an Xserver on boot. Lovely.

(p.s. thank you very much for your patch!!!)

@Pixelsuft
Copy link

Thanks! Works fine with linux 6.12 on my GT710 (Void Linux).

@joanbm
Copy link
Author

joanbm commented Dec 29, 2024

Thanks all for testing this!

@hadjiprocopis I don't know what could be going on in your case, it should not be related to this specific patch (since it is compiled out for kernels versions <6.12), let's hope it's some minor breakage that has already been fixed. It works for me on Linux 6.12 which is the current LTS.

@Augusto7743
Copy link

@joanbm
What is your Linux distro ?

@joanbm
Copy link
Author

joanbm commented Jan 6, 2025

@Augusto7743 Arch Linux - but most of those issues tend to be pretty distro-agnostic, as for the most part only the kernel and the NVIDIA driver are involved.

@hadjiprocopis
Copy link

Thank you (again and again!!!) for this fix. I can now confirm that it also works in my Fedora41 kernel 6.12.7-200.fc41.x86_64 after latest update (08jan2025) with GPU GeForce GTX 650 nvidia driver 470.256.02 patched by your fix.

But also note my comment above (https://gist.github.com/joanbm/a6d3f7f873a60dec0aa4a734c0f1d64e?permalink_comment_id=5337277#gistcomment-5337277) which still stands: I had to remove the nvidia-drm.modeset=1 .

THANK YOU AGAIN.

@Augusto7743
Copy link

Now for the fix work need remove kernel command "nvidia-drm.modeset=1" ?

@jamaggs
Copy link

jamaggs commented Jan 13, 2025

Hello, just to say this patch works perfectly for me in Mint 22 running the Liquorix 6.12 kernel. Thanks so much for keeping my GT710 working!

@ShprotOFF
Copy link

Hello joanbm.
And I've already completely lost hope. I can't install your patch. The following error appears
pastedbin
My video-device GeForce GT730
My OS Gentoo
Help me please

@hadjiprocopis
Copy link

hadjiprocopis commented Feb 28, 2025

@ShprotOFF It seems that it fails to apply the patch, not compiling the driver.

Perhaps gentoo has modified the NVIDIA drivers (file is called nvidia-drivers-470.256.02-r2) so that the patch is confused? I can't say.

Perhaps if you try to manually download the NVIDIA driver, apply the patches and then compile the drivers yourself? This is what I have been doing from long time ago.
I use the script mentioned here (perhaps you do not need the last patch):

https://gist.github.com/joanbm/d1f89391a4b20f4b56ba931ef6ca62da?permalink_comment_id=5461139#gistcomment-5461139

Once you patch the driver, you need to compile and install:

cd NVIDIA-Linux-x86_64-470.256.02
./nvidia-installer

@ShprotOFF
Copy link

@hadjiprocopis @joanbm Oh, my God...!!! It worked! Thank you so much! If you're in Vladivostok, let me know! I'll treat you to crabs with delicious beer.

@hadjiprocopis
Copy link

hadjiprocopis commented Mar 4, 2025

@ShprotOFF Cool, next time I am in Vladivostok I will give you a call!!! hehe best wishes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment