How to contribute to Linux kernel

BobAnkh published on
8 min, 1506 words

Categories: Linux Kernel

We will introduce how to contribute to Linux kernel in this post. This post mainly includes two parts: how to set up a development environment and how to create and submit a patch.

Build the development environment for kernel

You can just clone and build the kernel, or if you want to try the compiled kernel, it is recommended to try in a VM.

While there are multiple kinds of VMs (e.g., Vmware, VirtualBox, qemu, firecrackers), I would like to introduce Vagrant and make it work on top of qemu/kvm by libvirt.

The reason we start with Vagrant is that it is easy and convenient to manage and begin with. For most of the requirements, Vagrant is enough. You can achieve similar work or more specific requirements by using command-line qemu-system-x86_64 or virsh provided by libvirt.

Install Vagrant with libvirt

Before we begin to install Vagrant, we should check if the CPU supports virtualization. You can use the command grep -E 'vmx|svm' /proc/cpuinfo to check if the CPU supports virtualization. If the output is 0, it means your processor is not capable of running KVM. In this case, you should enable the virtualization in BIOS.

Then check if your system can use KVM acceleration. You can just type kvm-ok to see the result. If the output is KVM acceleration can be used, it means your system can use KVM acceleration.

As we mentioned, it is convenient as there is a bash script for installation (install.bash) provided by vagrant-libvirt. It will help you install libvirt and Vagrant:

curl -O
chmod +x ./install.bash

Besides, you should grant the privilege for user:

sudo usermod -aG kvm "$USER"
sudo usermod -aG libvirt "$USER"

Please exit and re-login your account to make the privilege take effect.

You can also install some plugins with the command vagrant plugin install <your_plugin>. For example, if you would like to use rsync to sync your files between VM and your host machine, you may want the plugin vagrant-rsync-back.

Then you should write a Vagrantfile to indicate how to build your VM. You can run vagrant up to bring your VM up and vagrant ssh to connect to your VM. If you would like to use vscode for remote development, vagrant ssh-config would help you set up your ssh configuration.

You can use virsh -c qemu:///system list to show all the VMs brought up by qemu/libvirt.

Create and Submit the Patch

Find Where to Begin

First you should find the correct place to develop. It is recommended to use the MAINTAINERS file, which will tell about the maintainers, reviewers and the source tree of subsystems. Most subsystem maintainers run their own trees and want to see patches prepared against those trees.

Here is an example of BPF subsystem:

BPF [GENERAL] (Safe Dynamic Programs and Tools)
M: Alexei Starovoitov <>
M: Daniel Borkmann <>
M: Andrii Nakryiko <>
R: Martin KaFai Lau <>
R: Song Liu <>
R: Yonghong Song <>
R: John Fastabend <>
R: KP Singh <>
R: Stanislav Fomichev <>
R: Hao Luo <>
R: Jiri Olsa <>
S: Supported
T: git git://
T: git git://
F: Documentation/bpf/
F: Documentation/networking/filter.rst
F: Documentation/userspace-api/ebpf/
F: arch/*/net/*
F: include/linux/bpf*
F: include/linux/btf*
F: include/linux/filter.h
F: include/trace/events/xdp.h
F: include/uapi/linux/bpf*
F: include/uapi/linux/btf*
F: include/uapi/linux/filter.h
F: kernel/bpf/
F: kernel/trace/bpf_trace.c
F: lib/test_bpf.c
F: net/bpf/
F: net/core/filter.c
F: net/sched/act_bpf.c
F: net/sched/cls_bpf.c
F: samples/bpf/
F: scripts/
F: scripts/
F: scripts/
F: tools/bpf/
F: tools/lib/bpf/
F: tools/testing/selftests/bpf/

We can develop our patch based on the bpf-next tree.

Configure Email Client

As the patches are all submitted with email in plain text, you should configure a email client to send the patch. It is recommended to use git-email.

Install it on Ubuntu:

sudo apt-get install git-email

Then add the following part to your .gitconfig file to enable email sending:

        helper = store

Create a Patch

For single patch:

git format-patch --subject-prefix='PATCH' -i HEAD~

For patch series:

git format-patch --cover-letter --subject-prefix='PATCH' -N # N is the number of patches

This will generate N+1 patch. There will be a patch beginning with 0000 which indicates itself as the cover-letter patch. It would be like:

Subject: [PATCH 0/2] *** SUBJECT HERE ***

*** BLURB HERE ***


You should use one line to summary what this series is about to replace *** SUBJECT HERE *** and clearly describe what you do in the main body to replace *** BLURB HERE ***.

Often, your patch will be requested to modify and re-submit. Then you have to mark the version of your patch series in the subject and states the difference between every version in your main body of the cover letter. Also there would sometimes have to add a tag pointing to relevant source tree in the subject. This would be like:

Subject: [PATCH v3 bpf-next 0/2] *** SUBJECT HERE ***

*** BLURB HERE ***

 - xxxx
 - yyyy
 - zzzz

Before Submit

You should do some more checks before submitting your patches.

First of all, the patches must be compiled successfully and pass all the tests of subsystem.

Secondly, style-check your changes. Check your patch for basic style violations. Kernel provide a checker scripts/ Simply run ./scripts/ 00*.patch

The checker reports at three levels:

  • ERROR: things that are very likely to be wrong.
  • WARNING: things requiring careful review.
  • CHECK: things requiring thought.

Often, you should fix all the ERRORs and check carefully about all the WARNINGs.

Send the Patch

Last step is to send the patch through emails. You can see who to send by the scripts provided by kernel: ./scripts/ 00*.patch

"David S. Miller" <> (maintainer:NETWORKING [IPv4/IPv6])
David Ahern <> (maintainer:NETWORKING [IPv4/IPv6])
Eric Dumazet <> (maintainer:NETWORKING [GENERAL])
Jakub Kicinski <> (maintainer:NETWORKING [GENERAL])
Paolo Abeni <> (maintainer:NETWORKING [GENERAL])
Andrii Nakryiko <> (maintainer:BPF [SELFTESTS] (Test Runners & Infrastructure))
Mykola Lysenko <> (reviewer:BPF [SELFTESTS] (Test Runners & Infrastructure))
Alexei Starovoitov <> (supporter:BPF [GENERAL] (Safe Dynamic Programs and Tools),commit_signer:1/2=50%)
Daniel Borkmann <> (supporter:BPF [GENERAL] (Safe Dynamic Programs and Tools))
Martin KaFai Lau <> (reviewer:BPF [GENERAL] (Safe Dynamic Programs and Tools))
Song Liu <> (reviewer:BPF [GENERAL] (Safe Dynamic Programs and Tools))
Yonghong Song <> (reviewer:BPF [GENERAL] (Safe Dynamic Programs and Tools))
John Fastabend <> (reviewer:BPF [GENERAL] (Safe Dynamic Programs and Tools))
KP Singh <> (reviewer:BPF [GENERAL] (Safe Dynamic Programs and Tools))
Stanislav Fomichev <> (reviewer:BPF [GENERAL] (Safe Dynamic Programs and Tools))
Hao Luo <> (reviewer:BPF [GENERAL] (Safe Dynamic Programs and Tools))
Jiri Olsa <> (reviewer:BPF [GENERAL] (Safe Dynamic Programs and Tools))
Shuah Khan <> (maintainer:KERNEL SELFTEST FRAMEWORK)
"Jörn-Thorben Hinz" <> (commit_signer:1/2=50%,authored:1/2=50%,added_lines:60/72=83%)
Yixin Shen <> (commit_signer:1/2=50%,authored:1/2=50%,added_lines:12/72=17%,removed_lines:1/1=100%) (open list:NETWORKING [IPv4/IPv6]) (open list) (open list:BPF [SELFTESTS] (Test Runners & Infrastructure)) (open list:KERNEL SELFTEST FRAMEWORK)

You should send to the mailing-list of the subsystem (e.g., in BPF subsystem) and cc some of the maintainers and reviewers. You can send to your own email address before sending the patch to mailing-list for another check.

git send-email --to <> --cc <> 00*.patch

After sending you patch, you can just wait for the response and see if more things should be done.

Here is my patch which is applied to bpf-next.

And there is an awesome patch which can be seen as a template. It covers the background, motivation, detailed design and implementation, evaluations with analysis, future work, discussion and a conclusion. Just as someone commented in reddit:

“Just give me 1 month to write a thesis for this patch…”


Hopefully this post has provided a helpful understanding of how you can participate in the process of contributing to the kernel. Remember that any open source project is no more than the sum of what its contributors put into it.