public inbox for linux-modules@vger.kernel.org
 help / color / mirror / Atom feed
From: Alan Maguire <alan.maguire@oracle.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Nathan Chancellor <nathan@kernel.org>,
	Ihor Solodrai <ihor.solodrai@linux.dev>
Cc: Petr Pavlu <petr.pavlu@suse.com>, Nicolas Schier <nsc@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Luis Chamberlain <mcgrof@kernel.org>,
	Daniel Gomez <da.gomez@kernel.org>,
	Sami Tolvanen <samitolvanen@google.com>,
	Aaron Tomlin <atomlin@atomlin.com>,
	Masahiro Yamada <masahiroy@kernel.org>,
	Sasha Levin <sashal@kernel.org>,
	Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>,
	bpf <bpf@vger.kernel.org>,
	linux-modules@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] kbuild/btf: Remove broken module relinking exclusion
Date: Wed, 15 Apr 2026 14:29:40 +0100	[thread overview]
Message-ID: <0b958862-538b-477d-adb2-c36516217bc7@oracle.com> (raw)
In-Reply-To: <CAADnVQKnWftcW0gk8HgFPLXuBf81+mqHMMds3fRmXHgOrRE-1g@mail.gmail.com>



On 15/04/2026 06:14, Alexei Starovoitov wrote:
> On Tue, Apr 14, 2026 at 1:34 PM Nathan Chancellor <nathan@kernel.org> wrote:
>>
>> On Fri, Apr 10, 2026 at 03:13:29PM +0200, Petr Pavlu wrote:
>>> Commit 5f9ae91f7c0d ("kbuild: Build kernel module BTFs if BTF is enabled
>>> and pahole supports it") in 2020 introduced CONFIG_DEBUG_INFO_BTF_MODULES
>>> to enable generation of split BTF for kernel modules. This change required
>>> the %.ko Makefile rule to additionally depend on vmlinux, which is used as
>>> a base for deduplication. The regular ld_ko_o command executed by the rule
>>> was then modified to be skipped if only vmlinux changes. This was done by
>>> introducing a new if_changed_except command and updating the original call
>>> to '+$(call if_changed_except,ld_ko_o,vmlinux)'.
>>>
>>> Later, commit 214c0eea43b2 ("kbuild: add $(objtree)/ prefix to some
>>> in-kernel build artifacts") in 2024 updated the rule's reference to vmlinux
>>> from 'vmlinux' to '$(objtree)/vmlinux'. This accidentally broke the
>>> previous logic to skip relinking modules if only vmlinux changes. The issue
>>> is that '$(objtree)' is typically '.' and GNU Make normalizes the resulting
>>> prerequisite './vmlinux' to just 'vmlinux', while the exclusion logic
>>> retains the raw './vmlinux'. As a result, if_changed_except doesn't
>>> correctly filter out vmlinux. Consequently, with
>>> CONFIG_DEBUG_INFO_BTF_MODULES=y, modules are relinked even if only vmlinux
>>> changes.
>>>
>>> It is possible to fix this Makefile issue. However, having the %.ko rule
>>> update the resulting file in place without starting from the original
>>> inputs is rather fragile. The logic is harder to debug if something breaks
>>> during a subsequent .ko update because the old input is lost due to the
>>> overwrite. Additionally, it requires that the BTF processing is idempotent.
>>> For example, sorting id+flags BTF_SET8 pairs in .BTF_ids by resolve_btfids
>>> currently doesn't have this property.
>>>
>>> One option is to split the %.ko target into two rules: the first for
>>> partial linking and the second one for generating the BTF data. However,
>>> this approach runs into an issue with requiring additional intermediate
>>> files, which increases the size of the build directory. On my system, when
>>> using a large distribution config with ~5500 modules, the size of the build
>>> directory with debuginfo enabled is already ~25 GB, with .ko files
>>> occupying ~8 GB. Duplicating these .ko files doesn't seem practical.
>>>
>>> Measuring the speed of the %.ko processing shows that the link step is
>>> actually relatively fast. It takes about 20% of the overall rule time,
>>> while the BTF processing accounts for 80%. Moreover, skipping the link part
>>> becomes relevant only during local development. In such cases, developers
>>> typically use configs that enable a limited number of modules, so having
>>> the %.ko rule slightly slower doesn't significantly impact the total
>>> rebuild time. This is supported by the fact that no one has complained
>>> about this optimization being broken for the past two years.
>>>
>>> Therefore, remove the logic that prevents module relinking when only
>>> vmlinux changes and simplify Makefile.modfinal.
>>>
>>> Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
>>
>> If the BPF folks want to take this since it deals with BTF:
>>
>> Acked-by: Nathan Chancellor <nathan@kernel.org>
>>
>> Otherwise, either Nicolas can take this for 7.1 or I will pick it up for
>> 7.2 when 7.1-rc1 is out.
> 
> Alan, Ihor,
> 
> As resident btf gen experts, Please take a look.

Tried it out with full build, rebuild, module-only (M=) build etc. All work
well so feel free to add

Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
Tested-by: Alan Maguire <alan.maguire@oracle.com>

  reply	other threads:[~2026-04-15 13:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-10 13:13 [PATCH] kbuild/btf: Remove broken module relinking exclusion Petr Pavlu
2026-04-13  7:54 ` Petr Pavlu
2026-04-14 20:34 ` Nathan Chancellor
2026-04-15  5:14   ` Alexei Starovoitov
2026-04-15 13:29     ` Alan Maguire [this message]
2026-04-15 15:47 ` Ihor Solodrai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0b958862-538b-477d-adb2-c36516217bc7@oracle.com \
    --to=alan.maguire@oracle.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=atomlin@atomlin.com \
    --cc=bpf@vger.kernel.org \
    --cc=da.gomez@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=masahiroy@kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=petr.pavlu@suse.com \
    --cc=samitolvanen@google.com \
    --cc=sashal@kernel.org \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox