[HowTo] Patch kernel 5.9 to support nvidia opencl

Difficulty: ★★★★☆

In one of the threads talking about kernel 5.9 and nvidia support I was was asked if I could provide a tutorial how to patch the kernel to make nvidia opencl work again.

So here we go. The patching process is pretty simple.

First of all you need the latest linux59 build files for Manjaro:

git clone https://gitlab.manjaro.org/packages/core/linux59.git

Second you need the patch file. I have created my own patch file and it is working just fine.

999_inherit.patch
--- linux-5.9/kernel/module.c.old	2020-10-14 06:51:57.598066293 +0200
+++ linux-5.9/kernel/module.c	2020-10-14 07:58:16.504570606 +0200
@@ -1431,6 +1431,7 @@
 	return 0;
 }
 
+#if 0
 static bool inherit_taint(struct module *mod, struct module *owner)
 {
 	if (!owner || !test_bit(TAINT_PROPRIETARY_MODULE, &owner->taints))
@@ -1449,6 +1450,7 @@
 	}
 	return true;
 }
+#endif
 
 /* Resolve a symbol for this module.  I.e. if we find one, record usage. */
 static const struct kernel_symbol *resolve_symbol(struct module *mod,
@@ -1474,6 +1476,7 @@
 	if (!sym)
 		goto unlock;
 
+#if 0
 	if (license == GPL_ONLY)
 		mod->using_gplonly_symbols = true;
 
@@ -1481,6 +1484,7 @@
 		sym = NULL;
 		goto getname;
 	}
+#endif
 
 	if (!check_version(info, name, mod, crc)) {
 		sym = ERR_PTR(-EINVAL);

I called it 999_inherit.patch. But you can call it however you want. Place this file into the linux59 directory next to the PKGBUILD file

Now you need to edit the PKGBUILD file to include your patch.
For that you just need to add the filename into the sources=(…). I put it as last enry to the soruces

sources = (" https://www.kernel.org/pub/linux/kernel/v5.x/linux-${_basekernel}.tar.xz"
        ...    
        '0512-bootsplash.patch'
        '0513-bootsplash.gitpatch'
        '999_inherit.patch')

Next you need to update the checksum.
Make sure that you are in the linux59 directory and excecute

updpkgsums

At this point you are ready to create the packages.
Just excecute

makepkg -sf

This will compile the kernel and create two packages:

linux59-5.9.0-2-x86_64.pkg.tar.xz
linux59-headers-5.9.0-2-x86_64.pkg.tar.xz

I have not changed the names of the packages. That is not best practice for customized packages but this ensures that these new packages are drop-in replacements for the official Manjaro packages. Therefore all other extramodules coming from Manjaro will work fine with this customized kernel (e.g. zfs, virtualbox, etc.)

Now you are ready to install the new kernel packages:

sudo pacman -U linux59-5.9.0-2-x86_64.pkg.tar.xz linux59-headers-5.9.0-2-x86_64.pkg.tar.xz

That is it. I have this running now since several days. No problems. darktable is using opencl with this kernel. All good.

5 Likes

Sorry, but this is breaking the law.

At first I was confused - what I think @philm has in mind is this

On the license page for Nvidia drivers there is no restriction in using the modules - for as long as the package is not split.

2.1.2 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).

2.1.3 Limitations.

No Reverse Engineering. Customer may not reverse engineer, decompile, or disassemble the SOFTWARE, nor attempt in any other manner to obtain the source code.

No Separation of Components. The SOFTWARE is licensed as a single product. Its component parts may not be separated for use on more than one computer, nor otherwise used separately from the other parts.

No Rental. Customer may not rent or lease the SOFTWARE to someone else.

So - the legality in this perspective - is this understood as Linux kernel developers - by means of license spaghetti - it forbidding end users from compiling a binary kernel which makes use of non GPL modules?

Wow. Das ist der Hammer. Instruktionen um den Kernel zu Patchen sind illegal?

Von welchem Gesetz sprichst du? Erklär das bitte mal.

EDIT: English translation:

Wow. This is shocking. Instructions to patch the kernel are illegal?

What law are you talking about? Please explain that one.

GPL. You just bypass limitation of kernel by license requirement hack disabling. These limitations are FOR REASONS.

modules: inherit TAINT_PROPRIETARY_MODULE

If a TAINT_PROPRIETARY_MODULE exports symbol, inherit the taint flag
for all modules importing these symbols, and don't allow loading
symbols from TAINT_PROPRIETARY_MODULE modules if the module previously
imported gplonly symbols.  Add a anti-circumvention devices so people
don't accidentally get themselves into trouble this way.

Comment from Greg:
  "Ah, the proven-to-be-illegal "GPL Condom" defense :)"

[jeyu: pr_info -> pr_err and pr_warn as per discussion]
Link: http://lore.kernel.org/r/20200730162957.GA22469@lst.de
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jessica Yu <jeyu@kernel.org>

Also read thread @ lkml.org LKML: Christoph Hellwig: inherit TAINT_PROPRIETARY_MODULE v2

I can not repeat it often enough. The GPL is a copyleft license and it allows me to change anything - anything (!!) - in the kernel source code. The GPL does not distinguish between good or bad changes.

And more importantly, a tutorial teaching you how to patch the kernel, can never violate the GPL. It is just a tutorial.

And a law is not touch by this.

EDIT:
And for those of you who find too boring to read the GPL I encourage you to watch this 15 minTED talk from Richard Stallmann. talking about the freedom coming with free software. Who controls your computer?