On Thu, 2024-02-15 at 05:49 +0900, Masahiro Yamada wrote: > On Wed, Feb 14, 2024 at 11:02 PM Marcos Paulo de Souza > <mpdesouza@xxxxxxxx> wrote: > > > > Hello Masahiro and Kbuild ML, > > > > Recently we added out-of-tree module building on kselftests for the > > livepatch selftests. Everything worked as expected, but kernel test > > robot complained about it[1]. > > > > So far, all our tests were being done targeting different options > > for > > kselftests, but we didn't test using the O= option. The interesting > > part of it is that this can be easily reproducible with any out-of- > > tree > > module building even on current upstream, like the code below: > > > > $ uname -r > > 6.8.0-rc4+ > > $ make > > make -C /lib/modules/6.8.0-rc4+/build M=/home/mpdesouza/test-oot > > modules > > make[1]: Entering directory '/home/mpdesouza/git/linux' > > CC [M] /home/mpdesouza/test-oot/patch_1.o > > MODPOST /home/mpdesouza/test-oot/Module.symvers > > CC [M] /home/mpdesouza/test-oot/patch_1.mod.o > > LD [M] /home/mpdesouza/test-oot/patch_1.ko > > BTF [M] /home/mpdesouza/test-oot/patch_1.ko > > make[1]: Leaving directory '/home/mpdesouza/git/linux' > > > > But it fails when using O= argument: > > $ make O=/tmp/kout > > make -C /lib/modules/6.8.0-rc4+/build M=/home/mpdesouza/test-oot > > modules > > make[1]: Entering directory '/home/mpdesouza/git/linux' > > make[2]: Entering directory '/tmp/kout' > > /home/mpdesouza/git/linux/Makefile:733: include/config/auto.conf: > > No > > such file or directory > > make[2]: *** [/home/mpdesouza/git/linux/Makefile:240: __sub-make] > > Error > > 2 > > make[2]: Leaving directory '/tmp/kout' > > make[1]: *** [Makefile:240: __sub-make] Error 2 > > make[1]: Leaving directory '/home/mpdesouza/git/linux' > > make: *** [Makefile:6: all] Error 2 > > > > As I already described on [2], the O= argument (or KBUILD_OUTPUT) > > makes > > the kernel to jump into the directory specified on the variabled, > > but > > running the Makefile on /lib/modules/6.8.0-rc4+/build. The problem > > is > > thattoplevel Makefile on /lib/modules/.../build includes files > > using > > relative paths. In this case, the makefile tries to find > > include/config/auto.conf on /tmp/kout, which obviously doesn't > > exists. > > > > Do you think this can be a bug on Kbuild? Should we ignore O= when > > building out-of-tree modules? > > > No. > > O= is not meant for the output directory for external modules. > > O= is supposed to point to the object tree of the kernel > (when the kernel was built in the separate output directory) > > Thanks Masahiro. AFAICS, the only way to override/unset a command-line variable from the sub-make calls is to override it on make invocation, like: make -C $(BUILD_PATH) O="" M=$(PWD) modules So it would need a fix like this for it to work. Am I right? BTW, I just noticedthe same problem on the bpf module on kselftests, which is also an out-of-tree module but it's KDIR is the built kernel: make W=1 O=/tmp/kselftest -C tools/testing/selftests/bpf make: Entering directory '/home/mpdesouza/git/linux/tools/testing/selftests/bpf' EXT-COPY [test_maps] MOD bpf_testmod.ko /home/mpdesouza/git/linux/Makefile:733: include/config/auto.conf: No such file or directory make[2]: *** [Makefile:240: __sub-make] Error 2 make[1]: *** [Makefile:16: all] Error 2 make: *** [Makefile:233: /tmp/kselftest//bpf_testmod.ko] Error 2 make: Leaving directory '/home/mpdesouza/git/linux/tools/testing/selftests/bpf' (This was reproduced on upstream/master branch). The reproducer from the kernel built robot is the following: reproduce: # https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=c4bbe83d27c2446a033cc0381c3fb6be5e8c41c7 git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git git fetch --no-tags linux-next master git checkout c4bbe83d27c2446a033cc0381c3fb6be5e8c41c7 make W=1 O=/tmp/kselftest headers make W=1 O=/tmp/kselftest -C tools/testing/selftests make W=1 O=/tmp/kselftest -C tools/testing/selftests/bpf (retrieved from https://download.01.org/0day- ci/archive/20240130/202401300736.GkSZoSrA-lkp@xxxxxxxxx/reproduce ) Masahiro thanks Shuah, the problem is already there even without out livepatch changes. Should the test robot be fixed instead? > > > Also, as noted[3] by Petr Mladek (CCed here as well), kernel-devel > > doesn't include auto.conf, so maybe kernel-devel should be patched > > as > > well? > > > > Thanks in advance, > > Marcos > > > > [1]: > > https://lore.kernel.org/oe-kbuild-all/202401300736.GkSZoSrA-lkp@xxxxxxxxx/ > > [2]: > > https://lore.kernel.org/oe-kbuild-all/fd027fa958a0bc65285a0c6c42e5921e7d28b0ad.camel@xxxxxxxx/ > > [3]: https://lore.kernel.org/oe-kbuild-all/ZbpnBqHUl3pE_3Te@alley/ > > >