NVIDIA Driver build failed

I failed to build nvidia driver on debian linux.
How to fix this issue ?

Environment is,

  • nvidia driver : 440.82
  • linux kernel : 5.4.49
  • debian version : 10.4

Error message is,

In file included from /usr/src/nvidia-440.82/common/inc/nv-linux.h:138,
from /usr/src/nvidia-440.82/nvidia/nv-frontend.c:13:
/usr/src/nvidia-440.82/common/inc/nv-list-helpers.h:69:23: error: redefinition of ‘list_is_first’
static inline int list_is_first(const struct list_head *list,
^~~~~~~~~~~~~
In file included from ./include/linux/preempt.h:11,
from ./include/linux/spinlock.h:51,
from /usr/src/nvidia-440.82/common/inc/nv-lock.h:16,
from /usr/src/nvidia-440.82/common/inc/nv-linux.h:19,
from /usr/src/nvidia-440.82/nvidia/nv-frontend.c:13:
./include/linux/list.h:245:19: note: previous definition of ‘list_is_first’ was here
static inline int list_is_first(const struct list_head *list,
^~~~~~~~~~~~~
In file included from /usr/src/nvidia-440.82/nvidia/nv-frontend.c:13:
/usr/src/nvidia-440.82/common/inc/nv-linux.h: In function ‘nv_insert_pfn’:
/usr/src/nvidia-440.82/common/inc/nv-linux.h:984:11: error: implicit declaration of function ‘vm_insert_pfn_prot’; did you mean ‘vmf_insert_pfn_prot’? [-Werror=implicit-function-declaration]
ret = vm_insert_pfn_prot(vma, virt_addr, pfn,
^~~~~~~~~~~~~~~~~~
vmf_insert_pfn_prot
/usr/src/nvidia-440.82/common/inc/nv-linux.h: In function ‘nv_dma_maps_swiotlb’:
/usr/src/nvidia-440.82/common/inc/nv-linux.h:1254:31: error: ‘swiotlb_dma_ops’ undeclared (first use in this function); did you mean ‘swiotlb_map’?
swiotlb_in_use = (ops == &swiotlb_dma_ops);
^~~~~~~~~~~~~~~
swiotlb_map
/usr/src/nvidia-440.82/common/inc/nv-linux.h:1254:31: note: each undeclared identifier is reported only once for each function it appears in
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:266: /usr/src/nvidia-440.82/nvidia/nv-frontend.o] エラー 1
make[1]: *** [Makefile:1706: /usr/src/nvidia-440.82] エラー 2
make[1]: ディレクトリ ‘/home/legato/src/linux-stable-5.4.y/linux-stable’ から出ます
make: *** [Makefile:81: modules] エラー 2

Best Regards.

If you need to build the NVIDIA kernel module:

Software Element         Min Requirement          Check With...
---------------------    ---------------------    ---------------------
binutils                 2.9.5                    `size --version`
GNU make                 3.77                     `make --version`
gcc                      2.91.66                  `gcc --version`

Are these requirements fulfilled?

Yes, fullfilled.

binutils                 2.31.1
GNU make                 4.2.1
gcc                      8.3.0

None of the errors in the log should be an issue. The NVIDIA conftest.sh script is failing to properly run.

The only thing that I can think of right now, without seeing some verbose output of that script, is that you’ve got something strange going on with your Linux headers.

Is your kernel headers actually installed in that directory? That’s a non-standard path for a default Debian install, right? Might be something to do with that.

Yes, it exists, I build linux kernel on this directory.

vm_insert_pfn_prot and swiotlb_dma_ops don’t exist in linux kernel version 5.4.y.
They have same feature as vmf_insert_pfn_prot and swiotlb_map ?

For list_is_first function, which should I use NVIDIA Driver Code or Linux Kernel Code ?

What I meant is that the driver source already tests for those cases: (See nv-linux.h and nv-list-helpers.h respectively.)

#if !defined(NV_LIST_IS_FIRST_PRESENT)
    static inline int list_is_first(const struct list_head *list,
                                    const struct list_head *head)
    {
        return list->prev == head;
    }
#endif
#if defined(NV_VMF_INSERT_PFN_PROT_PRESENT)
    return vmf_insert_pfn_prot(vma, virt_addr, pfn,
             __pgprot(pgprot_val(vma->vm_page_prot) | extra_prot));
#else
#if defined(CONFIG_SWIOTLB)
  #if defined(NV_DMA_OPS_PRESENT) || defined(NV_GET_DMA_OPS_PRESENT) || \
      defined(NV_SWIOTLB_DMA_OPS_PRESENT)
    /*
     * We only use the 'dma_ops' symbol on older x86_64 kernels; later kernels,
     * including those for other architectures, have converged on the
     * get_dma_ops() interface.
     */
    #if defined(NV_GET_DMA_OPS_PRESENT)

There’s something else that failing with the driver build. Specifically when the kernel/conftest.sh script runs, located within the driver source.

As I do not use Debian myself, someone else with more experience on that front will have to step in here.

In conftest.sh, list_is_first is defined as,

    list_is_first)
        #
        # Determine if the list_is_first() function is present.
        #
        # Added by commit 70b44595eafe ("mm, compaction: use free lists
        # to quickly locate a migration source") in 5.1 (2019-03-05)
        #
        CODE="
        #include <linux/list.h> 
        void conftest_list_is_first(void) {
            list_is_first();
        }"

        compile_check_conftest "$CODE" "NV_LIST_IS_FIRST_PRESENT" "" "functions"
    ;;

In this case, which linux/list.h has to be placed on ? /usr/include or /home/legato/src/linux-stable-5.4.y/linux-stable/include (it’s build directory) ?
list.h header file exists only in build directory.
I think this issue caused by header installation incorrectly, you said.
How to add header directory for conftest.sh ?

run the installer with --kernel-source-path=KERNEL-SOURCE-PATH