お腹.ヘッタ。

関数型とかセキュリティとか勉強したい。進捗つらぽよ

Linuxカーネルへのパッチの出し方メモ

これは三ヶ月放っておいたら出し方忘れてしまって、えらく叱られてしまったのでそのためにメモしなおしたものです。とてもつらかった。。。。困ったらChatGPTを使いましょう。破茶滅茶な英文が幾分マシになります。なんか僕が失敗するたびにこのページは勝手に増えます。

最初に読むべきモノたち

チートシート

カーネルの修正

基本的には頑張ってコードを読む以外はなさそう。あたりを付けて書き換えるとかビルドするとか。 とりあえずbuildの仕方とかは載せておこうじゃないか。 基本的にはfullbuildは初回とか、rebaseしたりした時にいる感じ。

git clone git@github.com:takehaya/linux.git
cd linux
git checkout support_rss_gtp
# ubuntu case
sudo apt install linux-image-6.1.0-1008-oem linux-headers-6.1.0-1008-oem linux-modules-6.1.0-1008-oem
sudo sed -i 's/# deb-src/deb-src/' /etc/apt/sources.list
sudo apt update
sudo apt build-dep -y linux
sudo apt install libncurses-dev
mkdir ../build
make olddefconfig O=../build
cd ../build
make localmodconfig
make menuconfig

# build
# CONFIG_SYSTEM_REVOCATION_KEYS のキー情報を消し飛ばしておく
# ICEのコンフィグを有効にして行おう
# cf. https://qiita.com/MNT_QU/items/4b86e56731320f033c3e#config%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6
make -j64 LOCALVERSION=-rss-custom-01
make modules -j64 LOCALVERSION=-rss-custom-01

# package
make bindeb-pkg -j64 LOCALVERSION=-rss-custom-01

# local install
# sudo make modules_install
# sudo make install
sudo apt install ../*.deb

debugのためにビルドして再度適用するときはこちら

make modules -j64 LOCALVERSION=-rss-custom-01
sudo cp drivers/net/ethernet/intel/ice/ice.ko /lib/modules/6.3.0-rc6-rss-custom-01/kernel/drivers/net/ethernet/intel/ice/ice.ko 

sudo modprobe -r irdma
sudo modprobe -r ice
sudo depmod -a
sudo modprobe ice

強いて言うならばこれが参考になるかもしれないですね(古いけど!) https://knqyf263.hatenablog.com/entry/2019/07/01/152643

パッチの送信方法

送るための前準備

# patchのコードスタイルが合っているかどうかを見る
# これが何も出なくなるまで頑張る。
git diff HEAD^ | scripts/checkpatch.pl

# singoff by と言うのをすることでコードに対して署名をする
git config format.signOff yes

# sendemailをするときの対象者を設定する
# (これは特定のgit管理されてるリポジトリで行う)
# に実態が置かれてる
git config sendemail.to "$(git diff HEAD^ | ./scripts/get_maintainer.pl --separator , --nokeywords --nogit --nogit-fallback --norolestats --nol)"
git config sendemail.cc "$(git diff HEAD^ | ./scripts/get_maintainer.pl --separator , --nokeywords --nogit --nogit-fallback --norolestats --nom)"
# ちなみにさらにメールを明示的に追加するならこんな感じである
# git config sendemail.cc "$(git diff HEAD^ | ./scripts/get_maintainer.pl --separator , --nokeywords --nogit --nogit-fallback --norolestats --nom) mailhol.vincent@wanadoo.fr vladimir.oltean@nxp.com"

# smtpの設定などを.gitconfigに入れておく
# 80文字で折り返すようにしておくといいが、実際には手動でぽちぽちやることになるのでなくてもいい。
~/private/linux$ vim ~/.gitconfig 
[sendemail]
       smtpserver = smtp.gmail.com
       smtpuser = hayatake396@gmail.com
       smtpencryption = tls
       smtpserverport = 587
       smtpPass = aaaaaa
       annotate = yes
[format]
        wrap = 80

実際に送りつける

# 単一のちょっとしたパッチはこれで送りつけて大丈夫
# パッチのバージョンに合わせてv6とかv7,v8...に上げていく必要がある
git send-email --annotate -v6 --subject-prefix='PATCH net-next' HEAD

# 意味が変わるようなパッチであれば二つに分割したりする必要がある。例えばuapiとそれに基づいて作られるdriveの機能とか(ethtool.hとiceドライバに関する機能)とかね
# 以下のコマンドで二つのパッチを同時に出せる
git send-email --annotate -v6 --subject-prefix='PATCH net-next' -2 HEAD

# パッチを同時に二つコマンドを実行すると以下のように出てくる。同時に二つ出すのは明示的にパッチシリーズであると言うことにするためだ。
# ここには見えてないがcommit messageとパッチの画面が出てくるのでそこでeditをしよう。
# ちなみに本当にパッチが二つになってるか知りたい場合は、以下に見える /tmp/hoge/v[0-9]-000~が2個あるかどうかで確認しよう。
~/private/linux$ git send-email --annotate -v7 --subject-prefix='PATCH net-next' -2 HEAD
/tmp/B_FPb86TTd/v7-0001-ethtool-Add-GTP-RSS-hash-options-to-ethtool.h.patch
/tmp/B_FPb86TTd/v7-0002-ice-Implement-RSS-settings-for-GTP-using-ethtool.patch
2 files to edit
(mbox) Adding cc: Takeru Hayasaka <hayatake396@gmail.com> from line 'From: Takeru Hayasaka <hayatake396@gmail.com>'
(body) Adding cc: Takeru Hayasaka <hayatake396@gmail.com> from line 'Signed-off-by: Takeru Hayasaka <hayatake396@gmail.com>'

From: Takeru Hayasaka <hayatake396@gmail.com>
To: Jesse Brandeburg <jesse.brandeburg@intel.com>,
        Tony Nguyen <anthony.l.nguyen@intel.com>,
        "David S. Miller" <davem@davemloft.net>,
        Eric Dumazet <edumazet@google.com>,
        Jakub Kicinski <kuba@kernel.org>,
        Paolo Abeni <pabeni@redhat.com>,
        Jonathan Corbet <corbet@lwn.net>
Cc: intel-wired-lan@lists.osuosl.org,
        netdev@vger.kernel.org,
        linux-doc@vger.kernel.org,
        linux-kernel@vger.kernel.org,
        mailhol.vincent@wanadoo.fr,
        vladimir.oltean@nxp.com,
        laforge@gnumonks.org,
        Takeru Hayasaka <hayatake396@gmail.com>
Subject: [PATCH net-next v7 1/2] ethtool: Add GTP RSS hash options to ethtool.h
Date: Thu,  1 Feb 2024 03:33:09 +0000
Message-Id: <20240201033310.1028154-1-hayatake396@gmail.com>
X-Mailer: git-send-email 2.34.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

    The Cc list above has been expanded by additional
    addresses found in the patch commit message. By default
    send-email prompts before sending whenever this occurs.
    This behavior is controlled by the sendemail.confirm
    configuration setting.

    For additional information, run 'git send-email --help'.
    To retain the current behavior, but squelch this message,
    run 'git config --global sendemail.confirm auto'.

Send this email? ([y]es|[n]o|[e]dit|[q]uit|[a]ll): y

# この時、yを押すと一つずつパッチが送られる。aを押すと全部送ってくれる感じである

気をつけた方がいいこと

コミットメッセージは80文字で切る

注意点としては文章の区切りで改行を入れるのではなく、コンテキストが続くものは連続で書くべきである。 例えば以下が正しい例である

commit 739a0aac9d26ce2b51bb5ec2da46c8db91129b58 (HEAD)
Author: Takeru Hayasaka <hayatake396@gmail.com>
Date:   Thu Feb 1 03:11:04 2024 +0000

    ice: Implement RSS settings for GTP using ethtool
    
    Following the addition of new GTP RSS hash options to ethtool.h, this patch
    implements the corresponding RSS settings for GTP packets in the Intel ice
    driver. It enables users to configure RSS for GTP-U and GTP-C traffic over IPv4
    and IPv6, utilizing the newly defined hash options.
    
    The implementation covers the handling of gtpu(4|6), gtpc(4|6), gtpc(4|6)t,
    gtpu(4|6)e, gtpu(4|6)u, and gtpu(4|6)d traffic, providing enhanced load
    distribution for GTP traffic across multiple processing units.
    
    Signed-off-by: Takeru Hayasaka <hayatake396@gmail.com>

これを悪くしてみよう。例えば怒られた例だとなるべく句読点で改行したり、適当なはちゃめチヤなところで切ってるやつである。これは正しくするならば、80行ギリギリになる単語で切る。同じ文章のまとまりで初めて改行を入れるべきである。本来であれば二つの塊で問題ないのに、3つの塊にしてたり、80文字までまだまだ単語が入るのに変な位置で切っていると言うのが問題である。

commit 739a0aac9d26ce2b51bb5ec2da46c8db91129b58 (HEAD)
Author: Takeru Hayasaka <hayatake396@gmail.com>
Date:   Thu Feb 1 03:11:04 2024 +0000

    ice: Implement RSS settings for GTP using ethtool
    
Following the addition of new GTP RSS hash options to ethtool.h,
this patch implements the corresponding RSS settings for
GTP packets in the Intel ice driver. 

It enables users to configure RSS for GTP-U and GTP-C traffic 
over IPv4 and IPv6, utilizing the newly defined hash options.

The implementation covers the handling of gtpu(4|6), gtpc(4|6), 
gtpc(4|6)t, gtpu(4|6)e, gtpu(4|6)u, and gtpu(4|6)d traffic, 
providing enhanced load distribution for GTP traffic across 
multiple processing units.
    
    Signed-off-by: Takeru Hayasaka <hayatake396@gmail.com>

正しく空白行を入れる

引用形式の文を書く

レビューをしてくれた人からメールが来るだろう。 その時には相手の文章に対して返信を書くことになるはず。

> 相手の文章

自分の意見

> 相手の文章

自分の意見

と言った感じで書くことがいい ちなみにだが、gmailとかでメールを返信するときは Content-Type: text/plain; にしなくてはいけないので注意。 この辺が参考になりそうです。 https://www.kernel.org/doc/html/next/process/email-clients.html https://nekomatu.blogspot.com/2014/05/howto-send-patch-to-linux.html

パッチの revisionをするとき

こんな感じでrevisionをするときにv1,v2とかの差分をここに書いてあげると親切らしい。

Signed-off-by: Takeru Hayasaka <hayatake396@gmail.com>
---
v2->v3: Based on Harald-san's review, I added documentation and comments to
ethtool.h and ice.rst.
v3->v4: Based on Marcin-san's review, I added the missing code for GTPC and
GTPC_TEID, and revised the documentation and comments.
v4->v5: Based on Marcin-san's review, I fixed rename and wrong code regarding
GTPC
v5->v6: Based on Marcin-san's review, Undoing the addition of unnecessary
blank lines.Minor fixes.
v6->v7 Based on Jakub-san's review, Split the patch.
 include/uapi/linux/ethtool.h | 48 ++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

CIが落ちたりしたので再度叩き込む時

中身は大きく変わるわけではないが、CIが落ちたりしたので再度叩き込む時に必要だったりする。 RESENDをつけることでレビュワーの混乱を防げる。

git send-email --annotate -v7 --subject-prefix='PATCH net-next RESEND' HEAD^

自分のパッチの送付を確認するとき

https://patchwork.kernel.org/project/netdevbpf/list/?submitter=210976 とかpatchworkを見るのが良い。

https://lore.kernel.org/all/20240201033310.1028154-2-hayatake396@gmail.com/ とかでメーリングリストにタイトルを入れるのも良い。