[PATCH bpf-next v4 5/8] kbuild: Sync kconfig when PAHOLE_VERSION changes

Ihor Solodrai posted 8 patches 1 month, 3 weeks ago
There is a newer version of this series
[PATCH bpf-next v4 5/8] kbuild: Sync kconfig when PAHOLE_VERSION changes
Posted by Ihor Solodrai 1 month, 3 weeks ago
This patch implements kconfig re-sync when the pahole version changes
between builds, similar to how it happens for compiler version change
via CC_VERSION_TEXT.

Define PAHOLE_VERSION in the top-level Makefile and export it for
config builds. Set CONFIG_PAHOLE_VERSION default to the exported
variable.

Kconfig records the PAHOLE_VERSION value in
include/config/auto.conf.cmd [1].

The Makefile includes auto.conf.cmd, so if PAHOLE_VERSION changes
between builds, make detects a dependency change and triggers
syncconfig to update the kconfig [2].

For external module builds, add a warning message in the prepare
target, similar to the existing compiler version mismatch warning.

Note that if pahole is not installed or available, PAHOLE_VERSION is
set to 0 by pahole-version.sh, so the (un)installation of pahole is
treated as a version change.

See previous discussions for context [3].

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/kconfig/preprocess.c?h=v6.18#n91
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Makefile?h=v6.18#n815
[3] https://lore.kernel.org/bpf/8f946abf-dd88-4fac-8bb4-84fcd8d81cf0@oracle.com/

Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
---
 Makefile     | 9 ++++++++-
 init/Kconfig | 2 +-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index e404e4767944..9b90a2a2218e 100644
--- a/Makefile
+++ b/Makefile
@@ -713,6 +713,7 @@ endif
 # upgrade.
 CC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(CC) --version 2>/dev/null | head -n 1))
 RUSTC_VERSION_TEXT = $(subst $(pound),,$(shell $(RUSTC) --version 2>/dev/null))
+PAHOLE_VERSION = $(shell $(srctree)/scripts/pahole-version.sh $(PAHOLE))
 
 ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
 include $(srctree)/scripts/Makefile.clang
@@ -733,7 +734,7 @@ ifdef config-build
 # KBUILD_DEFCONFIG may point out an alternative default configuration
 # used for 'make defconfig'
 include $(srctree)/arch/$(SRCARCH)/Makefile
-export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT RUSTC_VERSION_TEXT
+export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT RUSTC_VERSION_TEXT PAHOLE_VERSION
 
 config: outputmakefile scripts_basic FORCE
 	$(Q)$(MAKE) $(build)=scripts/kconfig $@
@@ -1921,12 +1922,18 @@ clean: private rm-files := Module.symvers modules.nsdeps compile_commands.json
 PHONY += prepare
 # now expand this into a simple variable to reduce the cost of shell evaluations
 prepare: CC_VERSION_TEXT := $(CC_VERSION_TEXT)
+prepare: PAHOLE_VERSION := $(PAHOLE_VERSION)
 prepare:
 	@if [ "$(CC_VERSION_TEXT)" != "$(CONFIG_CC_VERSION_TEXT)" ]; then \
 		echo >&2 "warning: the compiler differs from the one used to build the kernel"; \
 		echo >&2 "  The kernel was built by: $(CONFIG_CC_VERSION_TEXT)"; \
 		echo >&2 "  You are using:           $(CC_VERSION_TEXT)"; \
 	fi
+	@if [ "$(PAHOLE_VERSION)" != "$(CONFIG_PAHOLE_VERSION)" ]; then \
+		echo >&2 "warning: pahole version differs from the one used to build the kernel"; \
+		echo >&2 "  The kernel was built with: $(CONFIG_PAHOLE_VERSION)"; \
+		echo >&2 "  You are using:             $(PAHOLE_VERSION)"; \
+	fi
 
 PHONY += help
 help:
diff --git a/init/Kconfig b/init/Kconfig
index fa79feb8fe57..317f3c0b13ad 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -171,7 +171,7 @@ config RUSTC_HAS_FILE_AS_C_STR
 
 config PAHOLE_VERSION
 	int
-	default $(shell,$(srctree)/scripts/pahole-version.sh $(PAHOLE))
+	default "$(PAHOLE_VERSION)"
 
 config CONSTRUCTORS
 	bool
-- 
2.52.0
Re: [PATCH bpf-next v4 5/8] kbuild: Sync kconfig when PAHOLE_VERSION changes
Posted by Eduard Zingerman 1 month, 3 weeks ago
On Wed, 2025-12-17 at 16:33 -0800, Ihor Solodrai wrote:
> This patch implements kconfig re-sync when the pahole version changes
> between builds, similar to how it happens for compiler version change
> via CC_VERSION_TEXT.
> 
> Define PAHOLE_VERSION in the top-level Makefile and export it for
> config builds. Set CONFIG_PAHOLE_VERSION default to the exported
> variable.
> 
> Kconfig records the PAHOLE_VERSION value in
> include/config/auto.conf.cmd [1].
> 
> The Makefile includes auto.conf.cmd, so if PAHOLE_VERSION changes
> between builds, make detects a dependency change and triggers
> syncconfig to update the kconfig [2].
> 
> For external module builds, add a warning message in the prepare
> target, similar to the existing compiler version mismatch warning.
> 
> Note that if pahole is not installed or available, PAHOLE_VERSION is
> set to 0 by pahole-version.sh, so the (un)installation of pahole is
> treated as a version change.
> 
> See previous discussions for context [3].
> 
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/kconfig/preprocess.c?h=v6.18#n91
> [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Makefile?h=v6.18#n815
> [3] https://lore.kernel.org/bpf/8f946abf-dd88-4fac-8bb4-84fcd8d81cf0@oracle.com/
> 
> Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
> ---

When building BPF selftest modules the pahole version change was
detected, but it seems that BTF rebuild was not triggered:

  $ (cd ./tools/testing/selftests/bpf/test_kmods/; make -j)
  make[1]: Entering directory '/home/ezingerman/bpf-next'
  make[2]: Entering directory '/home/ezingerman/bpf-next/tools/testing/selftests/bpf/test_kmods'
    CC [M]  bpf_testmod.o
    CC [M]  bpf_test_no_cfi.o
    CC [M]  bpf_test_modorder_x.o
    CC [M]  bpf_test_modorder_y.o
    CC [M]  bpf_test_rqspinlock.o
    MODPOST Module.symvers
    CC [M]  bpf_testmod.mod.o
    CC [M]  .module-common.o
    CC [M]  bpf_test_no_cfi.mod.o
    CC [M]  bpf_test_modorder_x.mod.o
    CC [M]  bpf_test_modorder_y.mod.o
    CC [M]  bpf_test_rqspinlock.mod.o
    LD [M]  bpf_test_modorder_x.ko
    LD [M]  bpf_testmod.ko
    LD [M]  bpf_test_modorder_y.ko
    LD [M]  bpf_test_no_cfi.ko
    BTF [M] bpf_test_modorder_x.ko
    LD [M]  bpf_test_rqspinlock.ko
    BTF     bpf_test_modorder_x.ko
    BTF [M] bpf_test_no_cfi.ko
    BTF [M] bpf_test_modorder_y.ko
    BTF [M] bpf_testmod.ko
    BTF     bpf_test_no_cfi.ko
    BTF     bpf_test_modorder_y.ko
    BTF [M] bpf_test_rqspinlock.ko
    BTF     bpf_testmod.ko
    BTF     bpf_test_rqspinlock.ko
    BTFIDS  bpf_test_modorder_x.ko
    BTFIDS  bpf_test_modorder_y.ko
    BTFIDS  bpf_test_no_cfi.ko
    BTFIDS  bpf_testmod.ko
    OBJCOPY bpf_test_modorder_x.ko.BTF
    BTFIDS  bpf_test_rqspinlock.ko
    OBJCOPY bpf_test_no_cfi.ko.BTF
    OBJCOPY bpf_test_modorder_y.ko.BTF
    OBJCOPY bpf_testmod.ko.BTF
    OBJCOPY bpf_test_rqspinlock.ko.BTF
  make[2]: Leaving directory '/home/ezingerman/bpf-next/tools/testing/selftests/bpf/test_kmods'
  make[1]: Leaving directory '/home/ezingerman/bpf-next'
  [~/bpf-next]
  $ (cd ./tools/testing/selftests/bpf/test_kmods/; make -j)
  make[1]: Entering directory '/home/ezingerman/bpf-next'
  make[2]: Entering directory '/home/ezingerman/bpf-next/tools/testing/selftests/bpf/test_kmods'
  make[2]: Leaving directory '/home/ezingerman/bpf-next/tools/testing/selftests/bpf/test_kmods'
  make[1]: Leaving directory '/home/ezingerman/bpf-next'

... update pahole from version 131 to 132 ...

  [~/bpf-next]
  $ (cd ./tools/testing/selftests/bpf/test_kmods/; make -j)
  make[1]: Entering directory '/home/ezingerman/bpf-next'
  make[2]: Entering directory '/home/ezingerman/bpf-next/tools/testing/selftests/bpf/test_kmods'
  warning: pahole version differs from the one used to build the kernel
    The kernel was built with: 131
    You are using:             132
  make[2]: Leaving directory '/home/ezingerman/bpf-next/tools/testing/selftests/bpf/test_kmods'
  make[1]: Leaving directory '/home/ezingerman/bpf-next'

Is this an expected behavior?
Re: [PATCH bpf-next v4 5/8] kbuild: Sync kconfig when PAHOLE_VERSION changes
Posted by Ihor Solodrai 1 month, 3 weeks ago
On 12/18/25 11:21 AM, Eduard Zingerman wrote:
> On Wed, 2025-12-17 at 16:33 -0800, Ihor Solodrai wrote:
>> This patch implements kconfig re-sync when the pahole version changes
>> between builds, similar to how it happens for compiler version change
>> via CC_VERSION_TEXT.
>>
>> Define PAHOLE_VERSION in the top-level Makefile and export it for
>> config builds. Set CONFIG_PAHOLE_VERSION default to the exported
>> variable.
>>
>> Kconfig records the PAHOLE_VERSION value in
>> include/config/auto.conf.cmd [1].
>>
>> The Makefile includes auto.conf.cmd, so if PAHOLE_VERSION changes
>> between builds, make detects a dependency change and triggers
>> syncconfig to update the kconfig [2].
>>
>> For external module builds, add a warning message in the prepare
>> target, similar to the existing compiler version mismatch warning.
>>
>> Note that if pahole is not installed or available, PAHOLE_VERSION is
>> set to 0 by pahole-version.sh, so the (un)installation of pahole is
>> treated as a version change.
>>
>> See previous discussions for context [3].
>>
>> [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/kconfig/preprocess.c?h=v6.18#n91
>> [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Makefile?h=v6.18#n815
>> [3] https://lore.kernel.org/bpf/8f946abf-dd88-4fac-8bb4-84fcd8d81cf0@oracle.com/
>>
>> Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
>> ---
> 
> When building BPF selftest modules the pahole version change was
> detected, but it seems that BTF rebuild was not triggered:
> 
>   $ (cd ./tools/testing/selftests/bpf/test_kmods/; make -j)
>   make[1]: Entering directory '/home/ezingerman/bpf-next'
>   make[2]: Entering directory '/home/ezingerman/bpf-next/tools/testing/selftests/bpf/test_kmods'
>     CC [M]  bpf_testmod.o
>     CC [M]  bpf_test_no_cfi.o
>     CC [M]  bpf_test_modorder_x.o
>     CC [M]  bpf_test_modorder_y.o
>     CC [M]  bpf_test_rqspinlock.o
>     MODPOST Module.symvers
>     CC [M]  bpf_testmod.mod.o
>     CC [M]  .module-common.o
>     CC [M]  bpf_test_no_cfi.mod.o
>     CC [M]  bpf_test_modorder_x.mod.o
>     CC [M]  bpf_test_modorder_y.mod.o
>     CC [M]  bpf_test_rqspinlock.mod.o
>     LD [M]  bpf_test_modorder_x.ko
>     LD [M]  bpf_testmod.ko
>     LD [M]  bpf_test_modorder_y.ko
>     LD [M]  bpf_test_no_cfi.ko
>     BTF [M] bpf_test_modorder_x.ko
>     LD [M]  bpf_test_rqspinlock.ko
>     BTF     bpf_test_modorder_x.ko
>     BTF [M] bpf_test_no_cfi.ko
>     BTF [M] bpf_test_modorder_y.ko
>     BTF [M] bpf_testmod.ko
>     BTF     bpf_test_no_cfi.ko
>     BTF     bpf_test_modorder_y.ko
>     BTF [M] bpf_test_rqspinlock.ko
>     BTF     bpf_testmod.ko
>     BTF     bpf_test_rqspinlock.ko
>     BTFIDS  bpf_test_modorder_x.ko
>     BTFIDS  bpf_test_modorder_y.ko
>     BTFIDS  bpf_test_no_cfi.ko
>     BTFIDS  bpf_testmod.ko
>     OBJCOPY bpf_test_modorder_x.ko.BTF
>     BTFIDS  bpf_test_rqspinlock.ko
>     OBJCOPY bpf_test_no_cfi.ko.BTF
>     OBJCOPY bpf_test_modorder_y.ko.BTF
>     OBJCOPY bpf_testmod.ko.BTF
>     OBJCOPY bpf_test_rqspinlock.ko.BTF
>   make[2]: Leaving directory '/home/ezingerman/bpf-next/tools/testing/selftests/bpf/test_kmods'
>   make[1]: Leaving directory '/home/ezingerman/bpf-next'
>   [~/bpf-next]
>   $ (cd ./tools/testing/selftests/bpf/test_kmods/; make -j)
>   make[1]: Entering directory '/home/ezingerman/bpf-next'
>   make[2]: Entering directory '/home/ezingerman/bpf-next/tools/testing/selftests/bpf/test_kmods'
>   make[2]: Leaving directory '/home/ezingerman/bpf-next/tools/testing/selftests/bpf/test_kmods'
>   make[1]: Leaving directory '/home/ezingerman/bpf-next'
> 
> ... update pahole from version 131 to 132 ...
> 
>   [~/bpf-next]
>   $ (cd ./tools/testing/selftests/bpf/test_kmods/; make -j)
>   make[1]: Entering directory '/home/ezingerman/bpf-next'
>   make[2]: Entering directory '/home/ezingerman/bpf-next/tools/testing/selftests/bpf/test_kmods'
>   warning: pahole version differs from the one used to build the kernel
>     The kernel was built with: 131
>     You are using:             132
>   make[2]: Leaving directory '/home/ezingerman/bpf-next/tools/testing/selftests/bpf/test_kmods'
>   make[1]: Leaving directory '/home/ezingerman/bpf-next'
> 
> Is this an expected behavior?

Yes, it's expected.

I simply repeated the logic used for compiler version change: for
external modules only the warning is printed.

See https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Makefile?h=v6.18#n1857
Re: [PATCH bpf-next v4 5/8] kbuild: Sync kconfig when PAHOLE_VERSION changes
Posted by Eduard Zingerman 1 month, 3 weeks ago
On Thu, 2025-12-18 at 13:33 -0800, Ihor Solodrai wrote:
> On 12/18/25 11:21 AM, Eduard Zingerman wrote:
> > On Wed, 2025-12-17 at 16:33 -0800, Ihor Solodrai wrote:
> > > This patch implements kconfig re-sync when the pahole version changes
> > > between builds, similar to how it happens for compiler version change
> > > via CC_VERSION_TEXT.
> > > 
> > > Define PAHOLE_VERSION in the top-level Makefile and export it for
> > > config builds. Set CONFIG_PAHOLE_VERSION default to the exported
> > > variable.
> > > 
> > > Kconfig records the PAHOLE_VERSION value in
> > > include/config/auto.conf.cmd [1].
> > > 
> > > The Makefile includes auto.conf.cmd, so if PAHOLE_VERSION changes
> > > between builds, make detects a dependency change and triggers
> > > syncconfig to update the kconfig [2].
> > > 
> > > For external module builds, add a warning message in the prepare
> > > target, similar to the existing compiler version mismatch warning.
> > > 
> > > Note that if pahole is not installed or available, PAHOLE_VERSION is
> > > set to 0 by pahole-version.sh, so the (un)installation of pahole is
> > > treated as a version change.
> > > 
> > > See previous discussions for context [3].
> > > 
> > > [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/kconfig/preprocess.c?h=v6.18#n91
> > > [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Makefile?h=v6.18#n815
> > > [3] https://lore.kernel.org/bpf/8f946abf-dd88-4fac-8bb4-84fcd8d81cf0@oracle.com/
> > > 
> > > Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
> > > ---
> > 
> > When building BPF selftest modules the pahole version change was
> > detected, but it seems that BTF rebuild was not triggered:
> > 
> >   $ (cd ./tools/testing/selftests/bpf/test_kmods/; make -j)
> >   make[1]: Entering directory '/home/ezingerman/bpf-next'
> >   make[2]: Entering directory '/home/ezingerman/bpf-next/tools/testing/selftests/bpf/test_kmods'
> >     CC [M]  bpf_testmod.o
> >     CC [M]  bpf_test_no_cfi.o
> >     CC [M]  bpf_test_modorder_x.o
> >     CC [M]  bpf_test_modorder_y.o
> >     CC [M]  bpf_test_rqspinlock.o
> >     MODPOST Module.symvers
> >     CC [M]  bpf_testmod.mod.o
> >     CC [M]  .module-common.o
> >     CC [M]  bpf_test_no_cfi.mod.o
> >     CC [M]  bpf_test_modorder_x.mod.o
> >     CC [M]  bpf_test_modorder_y.mod.o
> >     CC [M]  bpf_test_rqspinlock.mod.o
> >     LD [M]  bpf_test_modorder_x.ko
> >     LD [M]  bpf_testmod.ko
> >     LD [M]  bpf_test_modorder_y.ko
> >     LD [M]  bpf_test_no_cfi.ko
> >     BTF [M] bpf_test_modorder_x.ko
> >     LD [M]  bpf_test_rqspinlock.ko
> >     BTF     bpf_test_modorder_x.ko
> >     BTF [M] bpf_test_no_cfi.ko
> >     BTF [M] bpf_test_modorder_y.ko
> >     BTF [M] bpf_testmod.ko
> >     BTF     bpf_test_no_cfi.ko
> >     BTF     bpf_test_modorder_y.ko
> >     BTF [M] bpf_test_rqspinlock.ko
> >     BTF     bpf_testmod.ko
> >     BTF     bpf_test_rqspinlock.ko
> >     BTFIDS  bpf_test_modorder_x.ko
> >     BTFIDS  bpf_test_modorder_y.ko
> >     BTFIDS  bpf_test_no_cfi.ko
> >     BTFIDS  bpf_testmod.ko
> >     OBJCOPY bpf_test_modorder_x.ko.BTF
> >     BTFIDS  bpf_test_rqspinlock.ko
> >     OBJCOPY bpf_test_no_cfi.ko.BTF
> >     OBJCOPY bpf_test_modorder_y.ko.BTF
> >     OBJCOPY bpf_testmod.ko.BTF
> >     OBJCOPY bpf_test_rqspinlock.ko.BTF
> >   make[2]: Leaving directory '/home/ezingerman/bpf-next/tools/testing/selftests/bpf/test_kmods'
> >   make[1]: Leaving directory '/home/ezingerman/bpf-next'
> >   [~/bpf-next]
> >   $ (cd ./tools/testing/selftests/bpf/test_kmods/; make -j)
> >   make[1]: Entering directory '/home/ezingerman/bpf-next'
> >   make[2]: Entering directory '/home/ezingerman/bpf-next/tools/testing/selftests/bpf/test_kmods'
> >   make[2]: Leaving directory '/home/ezingerman/bpf-next/tools/testing/selftests/bpf/test_kmods'
> >   make[1]: Leaving directory '/home/ezingerman/bpf-next'
> > 
> > ... update pahole from version 131 to 132 ...
> > 
> >   [~/bpf-next]
> >   $ (cd ./tools/testing/selftests/bpf/test_kmods/; make -j)
> >   make[1]: Entering directory '/home/ezingerman/bpf-next'
> >   make[2]: Entering directory '/home/ezingerman/bpf-next/tools/testing/selftests/bpf/test_kmods'
> >   warning: pahole version differs from the one used to build the kernel
> >     The kernel was built with: 131
> >     You are using:             132
> >   make[2]: Leaving directory '/home/ezingerman/bpf-next/tools/testing/selftests/bpf/test_kmods'
> >   make[1]: Leaving directory '/home/ezingerman/bpf-next'
> > 
> > Is this an expected behavior?
> 
> Yes, it's expected.
> 
> I simply repeated the logic used for compiler version change: for
> external modules only the warning is printed.
> 
> See https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Makefile?h=v6.18#n1857
> 

Ok, it does rebuild BTF for the kernel itself.

Tested-by: Eduard Zingerman <eddyz87@gmail.com>
Re: [PATCH bpf-next v4 5/8] kbuild: Sync kconfig when PAHOLE_VERSION changes
Posted by Andrii Nakryiko 1 month, 3 weeks ago
On Wed, Dec 17, 2025 at 4:34 PM Ihor Solodrai <ihor.solodrai@linux.dev> wrote:
>
> This patch implements kconfig re-sync when the pahole version changes
> between builds, similar to how it happens for compiler version change
> via CC_VERSION_TEXT.
>
> Define PAHOLE_VERSION in the top-level Makefile and export it for
> config builds. Set CONFIG_PAHOLE_VERSION default to the exported
> variable.
>
> Kconfig records the PAHOLE_VERSION value in
> include/config/auto.conf.cmd [1].
>
> The Makefile includes auto.conf.cmd, so if PAHOLE_VERSION changes
> between builds, make detects a dependency change and triggers
> syncconfig to update the kconfig [2].
>
> For external module builds, add a warning message in the prepare
> target, similar to the existing compiler version mismatch warning.
>
> Note that if pahole is not installed or available, PAHOLE_VERSION is
> set to 0 by pahole-version.sh, so the (un)installation of pahole is
> treated as a version change.
>
> See previous discussions for context [3].
>
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/kconfig/preprocess.c?h=v6.18#n91
> [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Makefile?h=v6.18#n815
> [3] https://lore.kernel.org/bpf/8f946abf-dd88-4fac-8bb4-84fcd8d81cf0@oracle.com/
>
> Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
> ---
>  Makefile     | 9 ++++++++-
>  init/Kconfig | 2 +-
>  2 files changed, 9 insertions(+), 2 deletions(-)
>

This is great, we should have done that a long time ago :)

[...]