dkms icon indicating copy to clipboard operation
dkms copied to clipboard

Keep the Module.symvers file along with the *.ko

Open DidierTrosset-Acqiris opened this issue 1 year ago • 4 comments

When the build is complete, only the *.ko files are copied to the final module directory.

However, some modules export functions, and to be able to use these exported functions when compiling other modules (either using dkms or not) one need the Module.symvers file. This Module.symvers file is generated when compiling the module, but it is left in the build directory. Unfortunately, this directory is deleted when the build is finished.

I'd like to have an option such that the Module.symvers file is copied along the *.ko files to the final module directory.

DidierTrosset-Acqiris avatar Jun 20 '24 09:06 DidierTrosset-Acqiris

Let me see if I get this right:

Your use-case is to build a dkms module that is then effectively used as input for another dkms module? Can you provide links to the modules in question?

Copying the Module.symvers alongside would be trivial, although I'm not sure it will work as expected. Namely, based on a quick look kmod/depmod takes only one symvers file and in 99% of the cases there will be pre-existing one alongside the kernel itself.

If you can outline how you see things working, ideally by adding a test, that would be appreciated.

evelikov avatar Jul 05 '24 11:07 evelikov

I am compiling my own module: a PCIe driver to a company made card. This card acquires data to internal memory and then transfers it to the host PC. The driver has been doing this successfully for more that 20 years. I recently added the ability to transfer the data from our card directly to an nVidia GPU card using RDMA.

My precise use case is that my driver has to call functions that are exported by the nvidia driver to handle the direct data transfer from our company-card to the GPU-card.

My problem is that the compilation of the nvidia proprietary driver (that uses dkms) erases the build directory when done. It of course copies the build result (kernel module file) before deletion to a target directory. But the Module.symvers file resulting from the compilation of the nvidia driver is lost. That's the file the compilation of my own driver requires, and that I'd like to keep.

DidierTrosset-Acqiris avatar Jul 23 '24 14:07 DidierTrosset-Acqiris

Thanks for the extensive reply - I think you covered everything but the part that was of interest ;-)

Assuming the nvidia Module.symvers is placed in /usr/foo, can you share pseudo code of how you envision the whole thing working? Are you concatenating the two symvers, if so how do you remove/replace the "nvidia" fragment, from the main file, as you update the nvidia driver?

evelikov avatar Sep 11 '24 17:09 evelikov

I've not concatenated any symvers files. What I did to make it work is compiling the nvidia driver manually (I mean not in the dkms automatic way, but in a shell) and checking a symvers was there. It's the standard nvidia driver in /usr/src/nvidia-current-525-147-05 installed by the nvidia-kernel-dkms Debian package. Then I added "KBUILD_EXTRA_SYMBOLS=/usr/src/nvidia-current-525-147-05/Module.symvers" to the MAKE[0] make command of my module dkms.conf file. Is that the part of interest?

What I can envision first is that dkms default behavior would be to copy the Module.symvers file alongside the final *.ko file. This need to be the default behavior of dkms. I mean it would not be practicable for me to change the nvidia dkms.conf file, adding a flag to conserve the symvers. I'd like the nvidia files installed by the apt package nvidia-kernel-dkms to be kept pristine.

Likewise, I'd want the final /var/lib/dkms/nvidia-current/525.147.05/6.1.0-21-amd64/x86_64/module directory to contain Module.symvers alongside the *.ko files.

That's the main thing I'd need, because as of now, I'm not using the Module.symvers that correspondsprecisely to the nvidia kernel module I'm using.

What I could envision next, is a way to indicate in the dkms.conf of my module, that it requires another dkms module, and that the KBUILD_EXTRA_SYMBOLS would be added automatically for me. Especially since the location of the final Module.symvers file can change. But I guess dkms has all the data it needs to create this string.

DidierTrosset-Acqiris avatar Sep 12 '24 08:09 DidierTrosset-Acqiris

I read again your answer, and maybe I guess there's a miscomprehension: I do not replace any nvidia fragment. I do not update the nvidia driver. I simply use the nvidia driver.

I mean from my kernel module, I call functions that are declared and defined by the nvidia kernel module: nvidia_p2p_get_pages, nvidia_p2p_dma_map_pages,…

That's why I need the Module.symvers file resulting from the compilation of the nvidia kernel module to compile my kernel module.

I'm gonna create a project with the pseudo code.

DidierTrosset-Acqiris avatar Nov 26 '24 10:11 DidierTrosset-Acqiris

Can you provide a pull request with the changes you're interested in?

scaronni avatar Nov 26 '24 10:11 scaronni

Hi Simone. I created the pull request. Only three lines of code. https://github.com/dell/dkms/pull/459

DidierTrosset-Acqiris avatar Nov 28 '24 09:11 DidierTrosset-Acqiris

Merged, thanks!

scaronni avatar Nov 30 '24 09:11 scaronni