0%

How to submit a Linux kernel patch

Patch Submitting


Environment Preparation

  • Download send-email and git-core

    1
    sudo apt install git-email git-core
  • Download msmtp

    1
    sudo apt-get install msmtp msmtp-mta
  • Configure the environment for send-emaila

    set the client of local email by using msmtp (originally file ‘~/.msmtprc’ is not existent)

    1
    vim ~/.msmtprc

    In ~/.msmtprc

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    # Default settings

    account gmail
    protocol smtp
    host smtp.gmail.com
    from u202011061@gmail.com
    auth on
    user u202011061@gmail.com
    # password ?????????

    defaults
    port 587
    tls on
    tls_trust_file /etc/ssl/certs/ca-certificates.crt


    # set a default account
    account default : gmail

    • 密码是授权密码而非登录密码

    • 解决办法:

      1. Gmail 授权码
      2. ubuntu configure sendmail
    • 进入Gmail,开启POPIMAP

    • 进入Google Account,如果没有App password需要先两步验证(开通收取国际短信功能),选择应用为邮件,设备名可以自定义,即可得到16个字符组成的密码

    • 注意password(授权密码)是明文,因此你需要修改该文件访问权限

      1
      chmod 600 ~/.msmtprc

      查看权限

      limit_of_authority_of_msmtprc_config

    • 还可创建日志文件

      1
      touch ~/.msmtp.log
  • Configure personal info in file “~/.gitconfig.”(append)

    1
    2
    3
    4
    5
    6
    7
    8
    [sendemail]
    from = Gencen Gan <u202011061@gmail.com>
    smtpserver = smtp.gmail.com
    smtpuser = u202011061@gmail.com
    smtpserverport = 587
    chainreplyto = false
    smtpencryption = tls

step 1

Obtain a current source tree

Get the latest version of linux kernel from the mainline :

1
2
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git (Too slowly)
git clone https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux (Recommended!)

git_clone_mainline

step 2

[增量编译]

Compile the kernel

step 3

Do some changes:

  1. Create a branch in the repo

    1
    git checkout -b fix
  2. Follow the kernel code style

    1
    git pull
  3. Git Add

    If you changed the file auth_null.c, you should add this file instead of add “.”

    1
    git add net/sunrpc/auth_null.c

step 4

Git commit and format your patch

  1. After finishing changes, commit changes by:

    1
    git commit -a -s -v -m"explanation" #-e
    • -a : all
    • -s : add signed-off-by line in *.patch
    • -e : use default editor nano of git to edit the info of commitment
    • -v : display your changes under the information of your commits
  2. For the commit file, commit message you can check the commits on the same file

    1
    git format-patch -1

    This will generate a patch file for only your previous commit

  3. If you do N commits, and would like to format those as a patchset:

    1
    git format-patch -3

    In fact, the parameter is ‘-N’

  4. After you generate the patch file, you should add some information in it.

    • vim *.patch, you will get the contents in *.patch like the following:

      patch_original

    • You should add some description between Subject and Signed-off-by

      patch_modified

    • Now there is no error and no warning.

      No_error_and_no_warning

step 5

Check and send your patch file

  1. Check the style issue of the patch file

    1
    ./scripts/checkpatch.pl 0001-net-sunrpc-auth_null-modified-test.patch
  2. Get the maintainers of your changed file

    1
    ./scripts/get_maintainer.pl net/sunrpc/auth_null.c -f

    And you will get concerning maintainers about this module

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    Chuck Lever <chuck.lever@oracle.com> (supporter:KERNEL NFSD, SUNRPC, AND LOCKD SERVERS)
    Jeff Layton <jlayton@kernel.org> (supporter:KERNEL NFSD, SUNRPC, AND LOCKD SERVERS)
    Trond Myklebust <trond.myklebust@hammerspace.com> (maintainer:NFS, SUNRPC, AND LOCKD CLIENTS)
    Anna Schumaker <anna@kernel.org> (maintainer:NFS, SUNRPC, AND LOCKD CLIENTS)
    "David S. Miller" <davem@davemloft.net> (maintainer:NETWORKING [GENERAL])
    Eric Dumazet <edumazet@google.com> (maintainer:NETWORKING [GENERAL])
    Jakub Kicinski <kuba@kernel.org> (maintainer:NETWORKING [GENERAL])
    Paolo Abeni <pabeni@redhat.com> (maintainer:NETWORKING [GENERAL])
    linux-nfs@vger.kernel.org (open list:KERNEL NFSD, SUNRPC, AND LOCKD SERVERS)
    netdev@vger.kernel.org (open list:NETWORKING [GENERAL])
    linux-kernel@vger.kernel.org (open list)
  3. Send mail and cc to kernel maintainers and mailing list

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    git send-email 
    # --subject-prefix="PATCH v2"
    --smtp-server /usr/bin/msmtp
    --to davem@davemloft.net
    --to kuba@kernel.org
    --to edumazet@google.com
    --to chuck.lever@oracle.com
    --to u202011061@gmail.com # <------ to yourself
    -cc linux-nfs@vger.kernel.org
    -cc netdev@vger.kernel.org
    -cc linux-kernel@vger.kernel.org
    0001-net-sunrpc-auth_null-modified-test.patch

    For test, you can just send it to yourself.

    1
    git send-email --smtp-server /usr/bin/msmtp --to u202011061@gmail.com --cc Gecenliber@outlook.com 0001-net-sunrpc-auth_null-modified-test.patch
  4. If you want to simplify the process of manually adding all maintainers to your email,you can do as follows.

    copy the following lines into ~/.gitconfig

    1
    2
    3
    [sendemail]
    tocmd ="`pwd`/scripts/get_maintainer.pl --nogit --nogit-fallback --norolestats --nol"
    cccmd ="`pwd`/scripts/get_maintainer.pl --nogit --nogit-fallback --norolestats --nom"

    And send email like that : pay attention to parameter --smtp-server /usr/bin/msmtp which is important.

    1
    git send-email --smtp-server /usr/bin/msmtp  0001-atm-he-fix-potential-ioremap-leak-of-membase-in-he_d.patch

Succeed

Happy~

send_patch_success

Reference

[1] configure: Setting up git send-email with gmail to send Linux kernel patch (mudongliang.github.io)

[2] practice: One failed kernel patch (mudongliang.github.io)

[3] demo: git send-mail to commit Linux kernel patch