Skip to content

Instantly share code, notes, and snippets.

@joanbm
Last active September 20, 2025 10:28
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?= <[email protected]>
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

@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!

@Thoughtyness
Copy link

Thank you! I can confirm this works on the 6.12.33 kernel

@alinuxf
Copy link

alinuxf commented Aug 15, 2025

I can compile and install on kernel 6.12.42 but the Xserver did not start on normal boot. Though I can use startx to get a basic xserver.
On a previous thread [hadjiprocopis] reported the same trouble but his turnaround doesn't work for me.
I am using a GT730 card. Why a graphical boot doesn't work ? systemd issue ?

Edit 16/08/25
@joanbm It now works with linux-6.12.42 There was an error in the kernel command line in grub.cfg. Thanks!

@joanbm
Copy link
Author

joanbm commented Aug 16, 2025

@alinuxf Unfortunately it's very hard to diagnose without having more details, like distro & desktop environment, how you are starting X11 on boot, and any related logs you can find (e.g. from dmesg, journalctl, or the Xorg logs).

If you can open an issue in https://github.com/joanbm/nvidia-470xx-linux-mainline/issues providing those maybe it's possible to figure it out.

@alinuxf
Copy link

alinuxf commented Aug 18, 2025

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

If it's difficult to find the kernel command line in the boot system, you can pass an option to the nvidia-drm module.
To do this, create the file /etc/modprobe.d/nvidia.conf containing the line:
options nvidia-drm modeset
That is working for me.

@Augusto7743
Copy link

Augusto7743 commented Aug 26, 2025

Here all below works in Ubuntu 24.04.
First extract the nvidia driver and then patch it.

edit grub and add kernel command line

nvidia-drm.modeset=1

then in sequence

bash -c "echo blacklist nouveau > /etc/modprobe.d/blacklist-nvidia-nouveau.conf"
bash -c "echo options nouveau modeset=0 >> /etc/modprobe.d/blacklist-nvidia-nouveau.conf"
update-initramfs -u -v
update-grub

Restart the OS in recovery mode and go to the nvidia driver patched path.
Install the patched driver.
Now restart the OS.

@MedHatchi
Copy link

MedHatchi commented Aug 30, 2025

@Augusto7743 You need to patch the driver yourself before installing. The "quick and dirty" way to manually install the driver on Linux 6.12-rc's is as follows:

# Download and extract driver
curl "https://us.download.nvidia.com/XFree86/Linux-x86_64/470.256.02/NVIDIA-Linux-x86_64-470.256.02.run" > NVIDIA-Linux-x86_64-470.256.02.run
sh NVIDIA-Linux-x86_64-470.256.02.run --extract-only
cd NVIDIA-Linux-x86_64-470.256.02
# Download and apply patches
curl "https://aur.archlinux.org/cgit/aur.git/plain/0001-Fix-conftest-to-ignore-implicit-function-declaration.patch?h=nvidia-470xx-utils&id=df0426ab325cb0ad8909a3058d66336ce1f872ce" | patch -Np1 -d kernel
curl "https://aur.archlinux.org/cgit/aur.git/plain/0002-Fix-conftest-to-use-a-short-wchar_t.patch?h=nvidia-470xx-utils&id=df0426ab325cb0ad8909a3058d66336ce1f872ce" | patch -Np1 -d kernel
curl "https://aur.archlinux.org/cgit/aur.git/plain/0003-Fix-conftest-to-use-nv_drm_gem_vmap-which-has-the-se.patch?h=nvidia-470xx-utils&id=df0426ab325cb0ad8909a3058d66336ce1f872ce" | patch -Np1 -d kernel
curl "https://aur.archlinux.org/cgit/aur.git/plain/kernel-6.10.patch?h=nvidia-470xx-utils&id=df0426ab325cb0ad8909a3058d66336ce1f872ce" | patch -Np1 -d kernel
curl "https://gist.githubusercontent.com/joanbm/a6d3f7f873a60dec0aa4a734c0f1d64e/raw/6bae5606c033b6c6c08233523091992370e357b7/nvidia-470xx-fix-linux-6.12.patch" | patch -Np1 -d kernel
# Run the installer
sudo ./nvidia-installer 

However, note that this installs the driver outside of the distribution's package manager so it has some potential for causing conflicts. What I personally do in Arch Linux is take the PKGBUILD for the AUR package, modify it to apply the patch and rebuild the package. Generally speaking if you don't want to spend some time tinkering, it's better to wait for the update to be shipped by your distro's package manager.

I'm on kali linux 2025.2 (6.12.38) Those five patches applied normaly and i think the one in top post is combined patches but still it give me error when try to install driver its the same as trying to install using .run file

failed to run /usr/sbin/dkms .....'
Building module(s)...(bad exit status: 2)

DKMS (dkms-3.2.0) make.log for nvidia/470.256.02 for kernel 6.12.38+kali-amd64 (x86_64)
Sat Aug 30 20:59:32 CET 2025

Building module(s)

command: 'make' -j2 NV_EXCLUDE_BUILD_MODULES='' KERNEL_UNAME=6.12.38+kali-amd64 IGNORE_CC_MISMATCH='' modules

make[1]: Entering directory '/usr/src/linux-headers-6.12.38+kali-common'
make[2]: Entering directory '/usr/src/linux-headers-6.12.38+kali-amd64'

Compiler version check failed:

The major and minor number of the compiler used to
compile the kernel:

x86_64-linux-gnu-gcc-14 (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44

does not match the compiler used here:

x86_64-linux-gnu-gcc-14 (Debian 14.3.0-5) 14.3.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

It is recommended to set the CC environment variable
to the compiler that was used to compile the kernel.

The compiler version check can be disabled by setting
the IGNORE_CC_MISMATCH environment variable to "1".
However, mixing compiler versions between the kernel
and kernel modules can result in subtle bugs that are
difficult to diagnose.

*** Failed CC version check. Bailing out! ***

make[4]: *** [/var/lib/dkms/nvidia/470.256.02/build/Kbuild:281: cc_version_check] Error 1
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [/usr/src/linux-headers-6.12.38+kali-common/Makefile:1970: /var/lib/dkms/nvidia/470.256.02/build] Error 2
make[2]: *** [/usr/src/linux-headers-6.12.38+kali-common/Makefile:236: __sub-make] Error 2
make[2]: Leaving directory '/usr/src/linux-headers-6.12.38+kali-amd64'
make[1]: *** [Makefile:236: __sub-make] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-6.12.38+kali-common'
make: *** [Makefile:80: modules] Error 2

exit code: 2

elapsed time: 00:00:02


@joanbm
Copy link
Author

joanbm commented Aug 30, 2025

@MedHatchi As the error states, the problem is that the GCC version you have installed doesn't match the one that was used to build the kernel, this is something that depends exclusively on the software your distro provides rather than the patches for newer kernels.

The error also suggests a workaround via an environment variable, perhaps that will let you avoid hunting down how to match the GCC versions (14.2 and 14.3 may be 'close enough').

@MedHatchi
Copy link

i had kali linux 2025.2 that is built with 14.3 and now i installed 2025.1a that is built with gcc 14.2 held them with apt-mark i've done full upgrade gcc version remain the same = 14.2.0 driver install dkms problem and display the box of x-config then boot to cli till i add nvidiadrm modeset so it boot to GUI ,i will reinstall kali 2025.2 and downgrade gcc on that version and try again (btw i guess the top post contains all 5 patches in one i think)

@joanbm
Copy link
Author

joanbm commented Aug 31, 2025

The top post only contains the patch for Linux 6.12, to apply all the patches up to 6.12 you can use the snippet from Augusto7743 you previously quoted, or I recently created a nvidia-470xx-linux-mainline repository with all the patches along with some helper scripts.

@hadjiprocopis
Copy link

@ MedHatchi re: compiler version mismatch

the dirty workaround here is to run:

   cd NVIDIA-Linux-x86_64-470.256.02
   nvidia-installer --no-cc-version-check

which may succeed in compiling but may lead to incompatibility problems after installation. But worth a try.

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