A dedicated unikernel for microservices

Sunday, November 10, 2019

My first patch to Linux kernel

Hello everyone! during September I submitted my first patch to the Linux kernel. This was an amazing experience in which I learnt a lot! the main problem was that information is spread in many documents so there is no a single place where are the steps are covered. I wrote down some of these steps here. Bear in mind that the patch was on a kernel module.

Where to code the patch?
My patch was on "vhost/virtio" subsystem so I cloned net-next and I applied the changes there (see https://www.kernel.org/doc/man-pages/linux-next.html)

How to try the patch?
To try it, I backported the changes to my current Ubuntu installation. First, I get the headers of the current Ubuntu by doing:

sudo apt-get install linux-headers-`uname -r`

Then, I got the source code that corresponds with the headers. To know which repository to clone I checked from here https://wiki.ubuntu.com/Kernel/SourceCode.

git checkout -b vsockttest Ubuntu-2.6.27-7.13

I applied the changes and then I compiled only the modules by doing:

make -C /lib/modules/4.15.0-45-generic/build M=$(pwd) modules

Finally, you have to remove old modules and install new ones.

How to write the commit message and correct patch code style automatically?

I titled the commit as “vhost/virtio:”. At the end, I added "Signed-off-by: Matias Ezequiel Vara Larsen ". I added a hook to check code style during commit (see https://kernelnewbies.org/FirstKernelPatch). I had to configure vim to use the right identation and to limit the number of characters of a line. 

How to generate the patch?
To generate a patch from last commit, do:

git format-patch -v2 --subject-prefix='PATCH net-next' -o ../ HEAD^

The patch has the tag "net-next" that indicates that the patch is ready for "net-next". Net-next gets patches in a 2 week windows which go to the next release. Do not send net-next packets if window is not open! (see https://www.kernel.org/doc/Documentation/networking/netdev-FAQ.txt)
The “-v2” indicates that it is the second version of the patch. If you patch is a POC you can tagged with "RFC PATCH".

How to send it?

You can get a list of maintainers by doing:

./scripts/get_maintainer.pl 0001-x86-build-don-t-add-maccumulate-outgoing-args-w-o-co.patc

Use git-send-email to send the patch:

git send-email --to stefanha@redhat.com -cc davem@davemloft.net -cc kvm@vger.kernel.org -cc virtualization@lists.linux-foundation.org -cc netdev@vger.kernel.org -cc linux-kernel@vger.kernel.org -cc matiasevara@gmail.com -cc sgarzare@redhat.com -cc eric.dumazet@gmail.com ../v2-0001-vsock-virtio-add-support-for-MSG_PEEK.patch

How to answer feedback?

To answer feedback configure mutt and answer from there. Don’t use gmail!
It is possible that gmail wont work with mutt. You have to configure your gmail account to allow you to use an unknown device.