Running NVidia driver on Linux Kernel 2.6.21 or 2.6.20 with paravirtualization turned on

This page describes how to get the NVidia driver (both latest and legacy versions) running on a Debian Kernel version 2.6.20 or 2.6.21 compiled with paravirtualization turned on.

Before I describe the easy way to accomplish this let me spill some words about why this problem occurs.

Description of Kernel 2.6.20 and 2.6.21 issue with paravirt_ops and GPL

It is a long ongoing discussion about ways for the kernel developers to distinguish between drivers written under GPL and proprietary drivers (Like Nvidia's and ATI's). The reason why they do this is because they can't and don't want to give support to people with problems running such drivers because they can not legally debug (and moreover fix) problems occurring in or around the closed-source drivers. That is why when the kernel encounters such driver it sets a so called tainted flag in the kernel. Which means this kernel has been marked once and forever (well until next reboot) as not-supported one. This is the first thing the kernel support team will look for when you post bug-report and will just delete it from their lists. So now back to the problem. Some functions are marked in the 2.6.20 (2.6.21) kernel as GPL usage only because maybe they are somewhat related to tainting the kernel and the developers want to prevent bad driver use them at all (this last sentence is however my personal opinion it is not based on facts). What happens is that when paravirtualization support is turned on many functions in the kernel call implicitly paravirt_ops - function marked as GPL only. One of these functions is udelay - function that makes a program stay idle for some period of time. And the nvidia driver uses udelay (I can't imagine a driver that won't use udelay somehow) and therefore you can not compile the driver normally. What one can do however is first fix the tool from the kernel driver building utilities that checks for drivers not marked as GPL and still using the GPL only functions and secondly because of the kbuild package still not linking such function automatically to bad drivers give the appropriate options to the linker to circumvent this and make the driver know of paravirt_ops function. Luckily all kernel functions are listed in the System map found under /boot/System.map-[kernel_version]. That is what enables us to get the driver back running when we perform the described steps.

Quick solution - Download the patched drivers (for more information read the explanation bellow)

Now for those who have read the full explanation bellow and think of Linux being f***ing difficult and only for nuclear scientists I collected these steps in an easy script that checks if your system resembles well enough mine to be relatively sure that you can apply these steps and have the same result. Afterwards it just copies a fixed precompiled version of modpost (the program you actually mess with in steps 1 through 5 from Hugo's manual (replaced partially by steps 1g - 2 maybe :-) ). It then uses the already modified Makefile to start the nvidia installer and conclude the install. Of course as I stat ein the script too you can not hold me responsible for any damage or psychological problems you might receive by using this script. It is without any guarantee and with no obligations whatsoever from my side to help you (although I will gladly try to help you if i can and have time for).

PS. Well a lot of people have already tested and reported these packages to work so I guess they should be pretty safe but this doesn't invalidate my previous statement :)

The packages can be downloaded from here

http://grizach.servebeer.com/nvpatch/NVIDIA-Linux-x86-100.14.19-pkg1-patched.run - prepared for 2.6.21
http://grizach.servebeer.com/nvpatch/NVIDIA-Linux-x86-100.14.11-pkg1-patched.run - prepared for 2.6.21
http://grizach.servebeer.com/nvpatch/NVIDIA-Linux-x86-96.43.01-pkg1-patched-2.6.21.run - prepared for 2.6.21
http://grizach.servebeer.com/nvpatch/NVIDIA-Linux-x86-1.0-9639-pkg1-patched.run - prepared for 2.6.21

http://grizach.servebeer.com/nvpatch/NVIDIA-Linux-x86-100.14.03-pkg1-patched.run - prepared for 2.6.20
http://grizach.servebeer.com/nvpatch/NVIDIA-Linux-x86-96.43.01-pkg1-patched-2.6.20.run - prepared for 2.6.20
http://grizach.servebeer.com/nvpatch/NVIDIA-Linux-x86-1.0-9631-pkg1-patched.run - prepared for 2.6.20

One more mirror again thanks to Peter

http://grizach.sc18.info/nvpatch/NVIDIA-Linux-x86-100.14.19-pkg1-patched.run - prepared for 2.6.21
http://grizach.sc18.info/nvpatch/NVIDIA-Linux-x86-100.14.11-pkg1-patched.run - prepared for 2.6.21
http://grizach.sc18.info/nvpatch/NVIDIA-Linux-x86-96.43.01-pkg1-patched-2.6.21.run - prepared for 2.6.21
http://grizach.sc18.info/nvpatch/NVIDIA-Linux-x86-1.0-9639-pkg1-patched.run - prepared for 2.6.21

http://grizach.sc18.info/nvpatch/NVIDIA-Linux-x86-100.14.03-pkg1-patched.run - prepared for 2.6.20
http://grizach.sc18.info/nvpatch/NVIDIA-Linux-x86-96.43.01-pkg1-patched-2.6.20.run - prepared for 2.6.20
http://grizach.sc18.info/nvpatch/NVIDIA-Linux-x86-1.0-9631-pkg1-patched.run - prepared for 2.6.20

The NVPatch project needs a new DNS server with short TTL to continue to operate on it's new home www.grizachi-inc.com. If someone is willing to provide us with DDNS service please contact us. Thanks!

These packages have been made with the makeself. This is the same tool used by the NVidia people to package their driver. It is free GPL program which does really great thing. I will certainly use it from now on when I need to create some self extracting and self running archives.

Long solution with explanations - based on the post from Hugo in the Debian Users mailing list.

HOWTO:2.6.20-1-k7 + nvidia
If you get this message with a nvidia closed driver install:
FATAL: modpost: GPL-incompatible module nvidia.ko uses GPL-only symbol
'paravirt_ops'

and you are running Sid's latest Debian stock kernel, then there is a
workaround that was published in the nvidia linux forum:
http://www.nvnews.net/vbulletin/showthread.php?t=87541

I have reworked the solution for Debian based upon another forum thread:
http://www.nvnews.net/vbulletin/showthread.php?t=89844

1. Rebuild the linux-kbuild-2.6.20 .deb:
    a. apt-get update
    b. apt-get build-dep linux-kbuild-2.6.20
       As user:
    c. mkdir linux-kbuild-2.6.20-build
    d. cd linux-kbuild-2.6.20-build
    e. apt-get source linux-kbuild-2.6.20
       The linux-kbuild-2.6.20 sources will be downloaded and unpacked
into a folder.
       cd to that folder, then:
    f. change
linux-kbuild-2.6.20-build/linux-kbuild-2.6-2.6.20/scripts/mod/mod.c and
delete lines 1197+1198. Please take care this is ONLY for 2.6.20. 
In 2.6.21 there is a case statement starting at approx the same location
with two cases that have fatal() function calls in them. You can just
delete the two-lined each fatal function call and that will do the same 
trick.
    g. dpkg-buildpackage -uc -us -rfakeroot (the .deb is created)
2. Install the rebuilt linux-kbuild-2.6.20_2.6.20-1_i386.deb
3. apt-get install linux-image-2.6.20-1-<version>
4. apt-get install linux-headers-2.6.20-1-<version>
5. reboot into that kernel.
6. unpack nvidia-driver (using '-x')
7. run ./nvidia-installer -K (This will end with an unknown symbol error!)
8. In the /NVIDIA-Linux-x86-1.0-<version>-pkg1/usr/src/nv dir. run:
PARAVIRT_OPS=`grep "D paravirt_ops" /boot/System.map-2.6.20-1-k7 | colrm 9`
9. ld -m elf_i386 -defsym paravirt_ops=0x$PARAVIRT_OPS -r -o nvidia.ko
nvidia.o nvidia.mod.o
10. Install nvidia.ko (by copying the module over into
/lib/modules/2.6.20-1-<version>/kernel/dricers/video)
11. depmod -a

It looks like this issue will be around for awhile ;-)

Hugo

I will try to give some hints about how to install the driver a bit easier manually and will present one patched version of this driver that can be installed automatically on most Debian systems and hopefully other distros based on Debian (like Ubuntu, Kubunto, Knoppix etc)

First of all the steps needed to patch the kbuild system can not be avoided and IMHO are pretty well documented in the article. What a friend of mine noticed is that if you do this like the description suggests you are prompted again to update the package the next time you do apt-get upgrade/dist-upgrade. This can be avoid if you make a little trick. Instead of repackaging your fixed version do the following: [This practically means, do steps 1a - 1f and afterwards continue with the steps below]

1g. cd linux-kbuild-2.6.20-build/linux-kbuild-2.6-2.6.20/scripts/mod
	make
1h. apt-get install linux-kbuild-2.6.20
1i. cp -r linux-kbuild-2.6.20-build/linux-kbuild-2.6-2.6.20/scripts/mod \
		/usr/src/linux-kbuild-2.6.20/scripts/

2. Just skip this step and continue ahead.

I know this is a bit more unsafe but works well and will keep your fixed version as long as kbuild package stays the save version. I have seen the version is still ending with -1 this means they haven't changed it for the time the 2.6.20 kernel is out.

Next tip is a bit more tricky but actually helps you run nvidia-installer as it should be run without any further options or errors whatsoever.

1. Go to the directory where you have your unpacked driver (the one with nvidia-installer file)
2. cd usr/src/nv/
3. open with your favourite editor Makefile.kbuild and just after line 77 that should read 
   something like this :

	EXTRA_CFLAGS += -Wall -Wimplicit -Wreturn-type....bla bla bla....

	add the following two lines:

 PARAVIRT_OPS := $(shell grep "D paravirt_ops" /boot/System.map-$(shell uname -r) | colrm 9)
 EXTRA_LDFLAGS := --defsym paravirt_ops=0x$(PARAVIRT_OPS)

4. change back to the directory of nvidia-installer ( cd ../../../ )
and run it ( ./nvidia-installer )

After your fix the installer should run without problems and the driver should be up and running as it always was. I think this steps should work for the 2.6.21 kernel as well because as you see we do use uname -r to get the kernel version up there.

Notes about the legacy driver versions

Beren Walters pointed out that on some machines the X server will not report its lib and module paths to the standard output but to the error output. This required that both outputs be tied together upon command execution so that on all versions it will work as axpected. Thanks for that note!

Other distributions

From the referrals of my page I found this blog. Unfortunately I can not give particular credits to someone because the best I can say is that he has the nickname Debian User. Nevertheless, thanks Debian User!. It contains the text of this very same article but has collected information from some other sources with description how to apply this patch for these distributions. At least for FC6 there is step by step tutorial there.

Credits

Last but not least some credits:

First of all thanks to Hugo for describing this easy way to fix the NVidia drivers problem. To close transitively the thanks here I'd like to thank to the people from the mentioned nvnews threads. Also huge thanks to Baren Walterf for pointing out a problem with the legacy driver not finding the correct lib/module paths of the X server. Last but not least I'd like to thank Peter Velichkov for finding this tutorial, actually testing it before I'd risk changing my kernel and designing this page. Hell yes! This problem was the only reason I was sticking with a 2.6.18 kernel all the time till now (well the 2.6.19 was miserable mistake IMO [what can you expect from kernel with first message in the changelog - "please post BEFORE you go to parties and not AFTER" from Linus Torvalds :-P ]). Moreover it was his computer that first suffered the wrath of the script after I wrote it.

And just at the bottom the copy once again of the DISCLAIMER to be sure no one got me wrong and thinks I am violation something with this work. (Well in some sense we do overcome some kernel mechanisms to distinguish good from bad drivers, but come on, udelay not usable by any commercial drivers that is redicilous!)

DISCLAIMER: First of all this is our very own solution and we can not guarantee that it will work on your computer. Although I don't think so it might even blow your computer, more possibly just wipe something important ;-) NVidia has also nothing to do with this modified version of the driver so I guess no official support can be expected from them either last but not least this binary driver taints the kernel so no support is to be expected from Linus too :). The only ones that can help you are either we or other users that are capable of understanding what is going on in here.

According to the NVidia license this version of the driver should be legally ok: "...Linux/FreeBSD Exception. Notwithstanding the foregoing terms of Section 2.1.1, SOFTWARE designed exclusively for use on the Linux or FreeBSD operating systems, or other operating systems derived from the source code to these operating systems, may be copied and redistributed, provided that the binary files thereof are not modified in any way (except for unzipping of compressed files)." No binary files have been modified only Makefile.kbuild have been changed

The fixed version of modpost is under GPL and that is why source code is included in the archive too.

Because of the German Law I have to make it explicitly clear that I don't have any influence and connection with any information on external sites linked from the pages hosted at http://grizach.servebeer.com/ . At the moment of posting them I made my best to make sure no offensive content of any kind was there and I will be grateful for any information that invalidates this statement, as to take care to remove such links in future. Moreover I'd like to state that this server name is a dynamic redirection on DDNS server and the IP changes every 24 hours, because of the limitations of my DSL connection. Therefore it exists the minimal chance that you are being redirected to a completely different server that has nothing in common with this one and I have no way to prevent it from happen. The dynamic redirection on the DNS server takes approx 5 to 10 minutes and my local daemon checks the changes every 30minutes. This makes a period of up to 40minutes a day (approx at 1AM CET) when the redirection is wrong! Please, in case of doubt whether you are on the correct server check again in 1 hour or contact me on the addresses given on my contacts page in the Homepage area on this server. Thank you!

Thanks for using my script! - Julian

If you have any comments about the design mail me - Peter