Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tentative fix for NVIDIA 455.28 driver for Linux 5.10-rc1
From 0c3e4c40305e78fd6d9899e43af6f0544a02fa6e Mon Sep 17 00:00:00 2001
From: Joan Bruguera <joanbrugueram@gmail.com>
Date: Mon, 26 Oct 2020 04:44:33 +0100
Subject: [PATCH] Tentative fix for NVIDIA 455.28 driver for Linux 5.10-rc1
NOTE: This does not fix the licensing problem with nvidia-uvm which also affects Linux 5.9
---
common/inc/nv-linux.h | 6 ++++++
nvidia-drm/nvidia-drm-gem-user-memory.c | 7 +++++++
2 files changed, 13 insertions(+)
diff --git a/common/inc/nv-linux.h b/common/inc/nv-linux.h
index 09d1e50..630f80b 100644
--- a/common/inc/nv-linux.h
+++ b/common/inc/nv-linux.h
@@ -11,6 +11,7 @@
#ifndef _NV_LINUX_H_
#define _NV_LINUX_H_
+#include <linux/version.h>
#include "nvstatus.h"
#include "nv-misc.h"
#include "nv.h"
@@ -169,6 +170,11 @@ static inline uid_t __kuid_val(uid_t uid)
#include <linux/pagemap.h>
#include <linux/dma-mapping.h>
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0))
+// dma-mapping.h has been split on commit 0a0f0d8be76dcd4390ff538e7060fda34db79717,,
+// so this needs to be incldued now for the build to work
+#include <linux/dma-map-ops.h>
+#endif
#if defined(CONFIG_SWIOTLB) && defined(NVCPU_AARCH64)
#include <linux/swiotlb.h>
diff --git a/nvidia-drm/nvidia-drm-gem-user-memory.c b/nvidia-drm/nvidia-drm-gem-user-memory.c
index 737d84c..082fc11 100644
--- a/nvidia-drm/nvidia-drm-gem-user-memory.c
+++ b/nvidia-drm/nvidia-drm-gem-user-memory.c
@@ -20,6 +20,7 @@
* DEALINGS IN THE SOFTWARE.
*/
+#include <linux/version.h>
#include "nvidia-drm-conftest.h"
#if defined(NV_DRM_AVAILABLE)
@@ -60,8 +61,14 @@ static struct sg_table *__nv_drm_gem_user_memory_prime_get_sg_table(
{
struct nv_drm_gem_user_memory *nv_user_memory = to_nv_user_memory(nv_gem);
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0))
+ // New parameter to drm_prime_pages_to_sg (commit 707d561f77b5e2a6f90c9786bee44ee7a8dedc7e)
+ return drm_prime_pages_to_sg(nv_gem->nv_dev->dev, nv_user_memory->pages,
+ nv_user_memory->pages_count);
+#else
return drm_prime_pages_to_sg(nv_user_memory->pages,
nv_user_memory->pages_count);
+#endif
}
static void *__nv_drm_gem_user_memory_prime_vmap(
--
2.29.1
@oscarbg

This comment has been minimized.

Copy link

@oscarbg oscarbg commented Nov 3, 2020

Hi,
I'm on 5.10rc2 and 455.34.01..
patch seems good but still unable to build kernel modules as it fails with:

No hay ninguna regla para construir el objetivo 'scripts/module.lds', necesario para '/var/lib/dkms/nvidia/455.34.01/build/nvidia-drm.ko'. Alto.

seems 5.10 has started requiring "scripts/module.lds" for external kernel modules..

cat /var/lib/dkms/nvidia/455.34.01/build/make.log:


 CC [M]  /var/lib/dkms/nvidia/455.34.01/build/nvidia-drm/nvidia-drm-helper.o
  CC [M]  /var/lib/dkms/nvidia/455.34.01/build/nvidia-drm/nv-pci-table.o
  CC [M]  /var/lib/dkms/nvidia/455.34.01/build/nvidia-drm/nvidia-drm-gem-nvkms-memory.o
  CC [M]  /var/lib/dkms/nvidia/455.34.01/build/nvidia-drm/nvidia-drm-gem-user-memory.o
  CC [M]  /var/lib/dkms/nvidia/455.34.01/build/nvidia-drm/nvidia-drm-format.o
  LD [M]  /var/lib/dkms/nvidia/455.34.01/build/nvidia.o
  LD [M]  /var/lib/dkms/nvidia/455.34.01/build/nvidia-uvm.o
  LD [M]  /var/lib/dkms/nvidia/455.34.01/build/nvidia-modeset.o
ld -r -o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-interface.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-frontend.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-pci.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-acpi.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-cray.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-dma.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-i2c.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-mmap.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-p2p.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-pat.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-procfs.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-usermap.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-vm.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-vtophys.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/os-interface.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/os-mlock.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/os-pci.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/os-registry.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/os-usermap.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-modeset-interface.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-pci-table.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-kthread-q.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-memdbg.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-ibmnpu.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-report-err.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-rsync.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-msi.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv-caps.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nv_uvm_interface.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nvlink_linux.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/nvlink_caps.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/linux_nvswitch.o /var/lib/dkms/nvidia/455.34.01/build/nvidia/procfs_nvswitch.o
ld -r -o /var/lib/dkms/nvidia/455.34.01/build/nvidia-modeset/nv-modeset-interface.o /var/lib/dkms/nvidia/455.34.01/build/nvidia-modeset/nvidia-modeset-linux.o /var/lib/dkms/nvidia/455.34.01/build/nvidia-modeset/nv-kthread-q.o
  LD [M]  /var/lib/dkms/nvidia/455.34.01/build/nvidia-drm.o
  MODPOST /var/lib/dkms/nvidia/455.34.01/build/Module.symvers
make[3]: *** No hay ninguna regla para construir el objetivo 'scripts/module.lds', necesario para '/var/lib/dkms/nvidia/455.34.01/build/nvidia-drm.ko'.  Alto.
@joanbm

This comment has been minimized.

Copy link
Owner Author

@joanbm joanbm commented Nov 3, 2020

Hmm, I'm currently on 5.10-rc2 and 455.38 on Arch Linux and it still builds for me. Not sure what this error is about... Which distribution are you using?

@oscarbg

This comment has been minimized.

Copy link

@oscarbg oscarbg commented Nov 3, 2020

@oscarbg

This comment has been minimized.

Copy link

@oscarbg oscarbg commented Nov 3, 2020

I'm using Ubuntu 20.10, kernel is from Kernel ppa (https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.10-rc2/)..
note I tested also 455.38 with same issue.. also same driver builds ok for 5.9 from kernel ppa..

@joanbm

This comment has been minimized.

Copy link
Owner Author

@joanbm joanbm commented Nov 4, 2020

Interesting, I just set up a Ubuntu 20.04 VM and tried to build the driver and I get the same problem.

I found a workaround which is to copy /usr/src/linux-headers-5.10.0-051000rc2-generic/scripts/module.lds.S to /usr/src/linux-headers-5.10.0-051000rc2-generic/scripts/module.lds and then remove the last line (an #include). With this the module builds. I couldn't load it since this was a just a simple VM, so it'd be nice if you could try it and report back.

In my Arch Linux install, it works since the linux-mainline-headers I have includes the module.lds file. So I'm not sure if this is a packaging problem in Ubuntu. It's definitely looks related to 5.10 changes, commit: torvalds/linux@596b047

@oscarbg

This comment has been minimized.

Copy link

@oscarbg oscarbg commented Nov 4, 2020

many thanks for your effort in giving a look!!
I will try tomorrow your fix and report.. although I expect driver to work, as you expose seems a build only issue..

@belfastraven

This comment has been minimized.

Copy link

@belfastraven belfastraven commented Nov 4, 2020

Thanks for your efforts. I am confirming that your fix worked on Ubuntu I had the same problem as @oscarbg (ubuntu groovy x86_64). the -generic /script modlule.lds.s is just a symlink to the plain /usr/src/linux-headers-5.10.0-051000rc2/script/module.lds.S. Copying that to -generic/script directory and editing per your instruction allowed build to finish and the drivers to load.

@oscarbg

This comment has been minimized.

Copy link

@oscarbg oscarbg commented Nov 5, 2020

yep confirmed working.. thanks..

@joanbm

This comment has been minimized.

Copy link
Owner Author

@joanbm joanbm commented Nov 5, 2020

Great, glad it worked!

By the way, I took a look to see if this was actually a problem with the NVIDIA driver and I'm fairly sure this is a problem with the kernel or the Ubuntu package. Building other different out-of-tree kernel modules also fails with this error.

Looking at torvalds/linux@596b047 the problem seems to be that module.lds is neither shipped with the kernel headers .deb package (they removed it from scripts/package/builddeb) but it's also not generated on-demand by the other modules: target in the Makefile which is used when building out-of-tree modules. I guess it's supposed to be generated on-the-fly when building out-of-tree modules but it doesn't look like a simple one line fix. In Arch Linux I think they ignore scripts/package/builddeb so that's why I still have a generated modules.lds file around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.