Skip to contentSkip to conversation

Provide in-kernel headers for making it easy to extend the kernel

PATCH Superseded Joel Fernandes (Google) 6 participants 21 messages Feb 11, 2019 – Apr 4, 2019

Subsystems (5)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 Provide in-kernel headers for making it easy to extend the kernel

Introduce in-kernel headers and other artifacts which are made available as an archive through proc (/proc/kheaders.txz file). This archive makes it possible to build kernel modules, run eBPF programs, and other tracing programs that need to extend the kernel for tracing purposes without any dependency on the file system having headers and build artifacts.

On Android and embedded systems, it is common to switch kernels but not have kernel headers available on the file system. Raw kernel headers also cannot be copied into the filesystem like they can be on other distros, due to licensing and other issues. There's no linux-headers package on Android. Further once a different kernel is booted, any headers stored on the file system will no longer be useful. By storing the headers as a compressed archive within the kernel, we can avoid these issues that have been a hindrance for a long time.

The feature is also buildable as a module just in case the user desires it not being part of the kernel image. This makes it possible to load and unload the headers on demand. A tracing program, or a kernel module builder can load the module, do its operations, and then unload the module to save kernel memory. The total memory needed is 3.8MB.

The code to read the headers is based on /proc/config.gz code and uses the same technique to embed the headers.

To build a module, the below steps have been tested on an x86 machine:
modprobe kheaders
rm -rf $HOME/headers
mkdir -p $HOME/headers
tar -xvf /proc/kheaders.txz -C $HOME/headers >/dev/null
cd my-kernel-module
make -C $HOME/headers M=$(pwd) modules
rmmod kheaders

Signed-off-by Joel Fernandes (Google) <joel at joelfernandes.org>

---

Changes since v1:
- removed IKH_EXTRA variable, not needed (Masahiro Yamada)
- small fix ups to selftest
- added target to main Makefile etc
- added MODULE_LICENSE to test module
- made selftest more quiet

Changes since RFC:
Both changes bring size down to 3.8MB:
- use xz for compression
- strip comments except SPDX lines
- Call out the module name in Kconfig
- Also added selftests in second patch to ensure headers are always working.

 Documentation/dontdiff    |  1 +
 init/Kconfig              | 11 ++++++
 kernel/.gitignore         |  2 ++
 kernel/Makefile           | 27 ++++++++++++++
 kernel/kheaders.c         | 74 +++++++++++++++++++++++++++++++++++++++
 scripts/gen_ikh_data.sh   | 19 ++++++++++
 scripts/strip-comments.pl |  8 +++++
 7 files changed, 142 insertions(+)
 create mode 100644 kernel/kheaders.c
 create mode 100755 scripts/gen_ikh_data.sh
 create mode 100755 scripts/strip-comments.pl
Documentation/dontdiff +1 -0
index 2228fcc8e29f..05a2319ee2a2 100644
@@ -151,6 +151,7 @@ int8.c
 kallsyms
 kconfig
 keywords.c
+kheaders_data.h*
 ksym.c*
 ksym.h*
 kxgettext
init/Kconfig +11 -0
index c9386a365eea..9fbf4f73d98c 100644
@@ -563,6 +563,17 @@ config IKCONFIG_PROC
 	  This option enables access to the kernel configuration file
 	  through /proc/config.gz.
 
+config IKHEADERS_PROC
+	tristate "Enable kernel header artifacts through /proc/kheaders.txz"
+	select BUILD_BIN2C
+	depends on PROC_FS
+	help
+	  This option enables access to the kernel header and other artifacts that
+          are generated during the build process. These can be used to build kernel
+          modules, and other in-kernel programs such as those generated by eBPF
+          and systemtap tools. If you build the headers as a module, a module
+          called kheaders.ko is built which can be loaded to get access to them.
+
 config LOG_BUF_SHIFT
 	int "Kernel log buffer size (16 => 64KB, 17 => 128KB)"
 	range 12 25
kernel/.gitignore +2 -0
index b3097bde4e9c..6acf71acbdcb 100644
@@ -3,5 +3,7 @@
 #
 config_data.h
 config_data.gz
+kheaders_data.h
+kheaders_data.txz
 timeconst.h
 hz.bc
kernel/Makefile +27 -0
index 6aa7543bcdb2..1d13a7a6c537 100644
@@ -70,6 +70,7 @@ obj-$(CONFIG_UTS_NS) += utsname.o
 obj-$(CONFIG_USER_NS) += user_namespace.o
 obj-$(CONFIG_PID_NS) += pid_namespace.o
 obj-$(CONFIG_IKCONFIG) += configs.o
+obj-$(CONFIG_IKHEADERS_PROC) += kheaders.o
 obj-$(CONFIG_SMP) += stop_machine.o
 obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o
 obj-$(CONFIG_AUDIT) += audit.o auditfilter.o
@@ -130,3 +131,29 @@ filechk_ikconfiggz = \
 targets += config_data.h
 $(obj)/config_data.h: $(obj)/config_data.gz FORCE
 	$(call filechk,ikconfiggz)
+
+# Build a list of in-kernel headers for building kernel modules
+ikh_file_list := include/
+ikh_file_list += arch/$(ARCH)/Makefile
+ikh_file_list += arch/$(ARCH)/include/
+ikh_file_list += scripts/
+ikh_file_list += Makefile
+ikh_file_list += Module.symvers
+ifeq ($(CONFIG_STACK_VALIDATION), y)
+ikh_file_list += $(objtree)/tools/objtool/objtool
+endif
+
+$(obj)/kheaders.o: $(obj)/kheaders_data.h
+
+targets += kheaders_data.txz
+
+quiet_cmd_genikh = GEN     $(obj)/kheaders_data.txz
+cmd_genikh = $(srctree)/scripts/gen_ikh_data.sh $@ $^ >/dev/null 2>&1
+$(obj)/kheaders_data.txz: $(ikh_file_list) FORCE
+	$(call cmd,genikh)
+
+filechk_ikheadersxz = (echo "static const char kernel_headers_data[] __used = KH_MAGIC_START"; cat $< | scripts/bin2c; echo "KH_MAGIC_END;")
+
+targets += kheaders_data.h
+$(obj)/kheaders_data.h: $(obj)/kheaders_data.txz FORCE
+	$(call filechk,ikheadersxz)
kernel/kheaders.c new file +74 -0

74 lines not on this page · raw message

scripts/gen_ikh_data.sh new file +19 -0
new file mode 100755
index 000000000000..609196b5cea2
@@ -0,0 +1,19 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+spath="$(dirname "$(readlink -f "$0")")"
+
+rm -rf $1.tmp
+mkdir $1.tmp
+
+for f in "${@:2}";
+	do find "$f" ! -name "*.c" ! -name "*.o" ! -name "*.cmd" ! -name ".*";
+done | cpio -pd $1.tmp
+
+for f in $(find $1.tmp); do
+	$spath/strip-comments.pl $f
+done
+
+tar -Jcf $1 -C $1.tmp/ . > /dev/null
+
+rm -rf $1.tmp
scripts/strip-comments.pl new file +8 -0
new file mode 100755
index 000000000000..f8ada87c5802
@@ -0,0 +1,8 @@
+#!/usr/bin/perl -pi
+# SPDX-License-Identifier: GPL-2.0
+
+# This script removes /**/ comments from a file, unless such comments
+# contain "SPDX". It is used when building compressed in-kernel headers.
+
+BEGIN {undef $/;}
+s/\/\*((?!SPDX).)*?\*\///smg;
Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
#1 lore raw

PATCH v2 2/2 Add selftests for module build using in-kernel headers

This test tries to build a module successfully using the in-kernel headers found in /proc/kheaders.txz.

Verified pass and fail scenarios by running:
make -C tools/testing/selftests TARGETS=kheaders run_tests

Signed-off-by Joel Fernandes (Google) <joel at joelfernandes.org>
---
 tools/testing/selftests/Makefile              |  1 +
 tools/testing/selftests/kheaders/Makefile     |  5 +++++
 tools/testing/selftests/kheaders/config       |  1 +
 .../kheaders/run_kheaders_modbuild.sh         | 18 +++++++++++++++++
 .../selftests/kheaders/testmod/Makefile       |  3 +++
 .../testing/selftests/kheaders/testmod/test.c | 20 +++++++++++++++++++
 6 files changed, 48 insertions(+)
 create mode 100644 tools/testing/selftests/kheaders/Makefile
 create mode 100644 tools/testing/selftests/kheaders/config
 create mode 100755 tools/testing/selftests/kheaders/run_kheaders_modbuild.sh
 create mode 100644 tools/testing/selftests/kheaders/testmod/Makefile
 create mode 100644 tools/testing/selftests/kheaders/testmod/test.c
tools/testing/selftests/Makefile +1 -0
index 400ee81a3043..5a9287fddd0d 100644
@@ -20,6 +20,7 @@ TARGETS += intel_pstate
 TARGETS += ipc
 TARGETS += ir
 TARGETS += kcmp
+TARGETS += kheaders
 TARGETS += kvm
 TARGETS += lib
 TARGETS += membarrier
tools/testing/selftests/kheaders/Makefile new file +5 -0
new file mode 100644
index 000000000000..51035ab0732b
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+
+TEST_PROGS := run_kheaders_modbuild.sh
+
+include ../lib.mk
tools/testing/selftests/kheaders/config new file +1 -0
new file mode 100644
index 000000000000..5221f9fb5e79
@@ -0,0 +1 @@
+CONFIG_IKHEADERS_PROC=y
tools/testing/selftests/kheaders/run_kheaders_modbuild.sh new file +18 -0
new file mode 100755
index 000000000000..69d6fa237661
@@ -0,0 +1,18 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+HEADERS_XZ=/proc/kheaders.txz
+TMP_DIR_HEADERS=$(mktemp -d)
+TMP_DIR_MODULE=$(mktemp -d)
+SPATH="$(dirname "$(readlink -f "$0")")"
+
+tar -xvf $HEADERS_XZ -C $TMP_DIR_HEADERS > /dev/null
+
+cp -r $SPATH/testmod $TMP_DIR_MODULE/
+
+pushd $TMP_DIR_MODULE/testmod > /dev/null
+make -C $TMP_DIR_HEADERS M=$(pwd) modules
+popd > /dev/null
+
+rm -rf $TMP_DIR_HEADERS
+rm -rf $TMP_DIR_MODULE
tools/testing/selftests/kheaders/testmod/Makefile new file +3 -0
new file mode 100644
index 000000000000..7083e28706e8
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-m += test.o
tools/testing/selftests/kheaders/testmod/test.c new file +20 -0
new file mode 100644
index 000000000000..9178bf6f0cc8
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+
+static int __init hello_init(void)
+{
+	printk(KERN_INFO "Hello, world\n");
+	return 0;
+}
+
+static void __exit hello_exit(void)
+{
+	printk(KERN_INFO "Goodbye, world\n");
+}
+
+module_init(hello_init);
+module_exit(hello_exit);
+MODULE_LICENSE("GPL");
Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
Acked-by on v2 1/2
#2 lore raw
In reply to Joel Fernandes (Google)
Quoted 34 lines · Joel Fernandes (Google)

Introduce in-kernel headers and other artifacts which are made available as an archive through proc (/proc/kheaders.txz file). This archive makes it possible to build kernel modules, run eBPF programs, and other tracing programs that need to extend the kernel for tracing purposes without any dependency on the file system having headers and build artifacts.

On Android and embedded systems, it is common to switch kernels but not have kernel headers available on the file system. Raw kernel headers also cannot be copied into the filesystem like they can be on other distros, due to licensing and other issues. There's no linux-headers package on Android. Further once a different kernel is booted, any headers stored on the file system will no longer be useful. By storing the headers as a compressed archive within the kernel, we can avoid these issues that have been a hindrance for a long time.

The feature is also buildable as a module just in case the user desires it not being part of the kernel image. This makes it possible to load and unload the headers on demand. A tracing program, or a kernel module builder can load the module, do its operations, and then unload the module to save kernel memory. The total memory needed is 3.8MB.

The code to read the headers is based on /proc/config.gz code and uses the same technique to embed the headers.

To build a module, the below steps have been tested on an x86 machine:
modprobe kheaders
rm -rf $HOME/headers
mkdir -p $HOME/headers
tar -xvf /proc/kheaders.txz -C $HOME/headers >/dev/null
cd my-kernel-module
make -C $HOME/headers M=$(pwd) modules
rmmod kheaders

Quoted 1 line
Signed-off-by Joel Fernandes (Google) <joel at joelfernandes.org>
Acked-by Karim Yaghmour <karim.yaghmour at opersys.com>
Quoted 28 lines

---

Changes since v1:
- removed IKH_EXTRA variable, not needed (Masahiro Yamada)
- small fix ups to selftest
- added target to main Makefile etc
- added MODULE_LICENSE to test module
- made selftest more quiet

Changes since RFC:
Both changes bring size down to 3.8MB:
- use xz for compression
- strip comments except SPDX lines
- Call out the module name in Kconfig
- Also added selftests in second patch to ensure headers are always working.

  Documentation/dontdiff    |  1 +
  init/Kconfig              | 11 ++++++
  kernel/.gitignore         |  2 ++
  kernel/Makefile           | 27 ++++++++++++++
  kernel/kheaders.c         | 74 +++++++++++++++++++++++++++++++++++++++
  scripts/gen_ikh_data.sh   | 19 ++++++++++
  scripts/strip-comments.pl |  8 +++++
  7 files changed, 142 insertions(+)

create mode 100644 kernel/kheaders.c
create mode 100755 scripts/gen_ikh_data.sh
create mode 100755 scripts/strip-comments.pl

[snip]

Signature · 3 lines
Karim Yaghmour
CEO - Opersys inc. / www.opersys.com
http://twitter.com/karimyaghmour
#3 lore raw
In reply to Joel Fernandes (Google)
Quoted 7 lines · Joel Fernandes (Google)

Introduce in-kernel headers and other artifacts which are made available as an archive through proc (/proc/kheaders.txz file). This archive makes it possible to build kernel modules, run eBPF programs, and other tracing programs that need to extend the kernel for tracing purposes without any dependency on the file system having headers and build artifacts.

Quoted 8 lines

On Android and embedded systems, it is common to switch kernels but not have kernel headers available on the file system. Raw kernel headers also cannot be copied into the filesystem like they can be on other distros, due to licensing and other issues. There's no linux-headers package on Android. Further once a different kernel is booted, any headers stored on the file system will no longer be useful. By storing the headers as a compressed archive within the kernel, we can avoid these issues that have been a hindrance for a long time.

The set looks good to me and since the main use case is building bpf progs I can route it via bpf-next tree if there are no objections. Masahiro, could you please ack it?

#4 lore raw
Quoted 17 lines · Alexei Starovoitov
Quoted 7 lines · Joel Fernandes (Google)

Introduce in-kernel headers and other artifacts which are made available as an archive through proc (/proc/kheaders.txz file). This archive makes it possible to build kernel modules, run eBPF programs, and other tracing programs that need to extend the kernel for tracing purposes without any dependency on the file system having headers and build artifacts.

Quoted 8 lines

On Android and embedded systems, it is common to switch kernels but not have kernel headers available on the file system. Raw kernel headers also cannot be copied into the filesystem like they can be on other distros, due to licensing and other issues. There's no linux-headers package on Android. Further once a different kernel is booted, any headers stored on the file system will no longer be useful. By storing the headers as a compressed archive within the kernel, we can avoid these issues that have been a hindrance for a long time.

Quoted 4 lines

The set looks good to me and since the main use case is building bpf progs I can route it via bpf-next tree if there are no objections. Masahiro, could you please ack it?

Yes, eBPF is one of the usecases. After this, I am also planning to send patches to BCC so that it can use this feature when compiling C to eBPF.

Thanks!

- Joel

Tested-by
#5 lore raw
Quoted 18 lines · Joel Fernandes
Quoted 17 lines · Alexei Starovoitov
Quoted 15 lines · Joel Fernandes (Google)

Introduce in-kernel headers and other artifacts which are made available as an archive through proc (/proc/kheaders.txz file). This archive makes it possible to build kernel modules, run eBPF programs, and other tracing programs that need to extend the kernel for tracing purposes without any dependency on the file system having headers and build artifacts.

On Android and embedded systems, it is common to switch kernels but not have kernel headers available on the file system. Raw kernel headers also cannot be copied into the filesystem like they can be on other distros, due to licensing and other issues. There's no linux-headers package on Android. Further once a different kernel is booted, any headers stored on the file system will no longer be useful. By storing the headers as a compressed archive within the kernel, we can avoid these issues that have been a hindrance for a long time.

Quoted 8 lines
Quoted 4 lines

The set looks good to me and since the main use case is building bpf progs I can route it via bpf-next tree if there are no objections. Masahiro, could you please ack it?

Yes, eBPF is one of the usecases. After this, I am also planning to send patches to BCC so that it can use this feature when compiling C to eBPF.

Tested-by Manoj Rao <linux at manojrajarao.com>

I think this can definitely make it easier to use eBPF on Android. Thanks for initiating this.

Quoted 3 lines

Thanks!

- Joel

Signature · 2 lines
Manoj
http://www.mycpu.org
#6 lore raw
In reply to Alexei Starovoitov
Quoted 4 lines · Alexei Starovoitov
Quoted 2 lines · Joel Fernandes (Google)

Introduce in-kernel headers and other artifacts which are made available as an archive through proc (/proc/kheaders.txz file).

The extension '.txz' is not used in kernel code.

'.tar.xz' is used for 'tarxz-pkg', 'perf-tarxz-src-pkg' etc.

$ git grep  '\.txz'
$ git grep  '\.tar\.xz'
Documentation/admin-guide/README.rst:     xz -cd linux-4.X.tar.xz | tar xvf -
arch/x86/crypto/camellia-aesni-avx-asm_64.S: *
http://koti.mbnet.fi/axh/crypto/camellia-BSD-1.2.0-aesni1.tar.xz
crypto/testmgr.h: *   https://bench.cr.yp.to/supercop/supercop-20170228.tar.xz
crypto/testmgr.h: *   https://bench.cr.yp.to/supercop/supercop-20170228.tar.xz
crypto/testmgr.h: *   https://bench.cr.yp.to/supercop/supercop-20170228.tar.xz
crypto/testmgr.h: *   https://bench.cr.yp.to/supercop/supercop-20170228.tar.xz
crypto/testmgr.h: *   https://bench.cr.yp.to/supercop/supercop-20170228.tar.xz
scripts/package/Makefile:       @echo '  perf-tarxz-src-pkg  - Build
$(perf-tar).tar.xz source tarball'
tools/testing/selftests/gen_kselftest_tar.sh:
 ext=".tar.xz"

I prefer '.tar.xz' for consistency.

BTW, have you ever looked at scripts/extract-ikconfig?

You added IKHD_ST and IKHD_ED
just to mimic kernel/configs.c

It is currently pointless without the extracting tool, but you might think it is useful to extract headers from vmlinux or the module without mounting procfs.

Quoted 15 lines
Quoted 6 lines

This archive makes
it possible to build kernel modules, run eBPF programs, and other tracing programs that need to extend the kernel for tracing purposes without any dependency on the file system having headers and build artifacts.

Quoted 8 lines

On Android and embedded systems, it is common to switch kernels but not have kernel headers available on the file system. Raw kernel headers also cannot be copied into the filesystem like they can be on other distros, due to licensing and other issues. There's no linux-headers package on Android. Further once a different kernel is booted, any headers stored on the file system will no longer be useful. By storing the headers as a compressed archive within the kernel, we can avoid these issues that have been a hindrance for a long time.

Quoted 3 lines

The set looks good to me and since the main use case is building bpf progs I can route it via bpf-next tree if there are no objections. Masahiro, could you please ack it?

Honestly, I was not tracking this thread
since I did not know I was responsible for this.

I just started to take a closer look, then immediately got scared.

This version is not mature enough for the merge.

First of all, this patch cannot be compiled out-of-tree (O= option).

I do not know why 0-day bot did not catch this apparent breakage.

$ make -j8 O=hoge
make[1]: Entering directory '/home/masahiro/workspace/bsp/linux/hoge'
  GEN     Makefile
  Using .. as source for kernel
  DESCEND  objtool
  CALL    ../scripts/checksyscalls.sh
  CHK     include/generated/compile.h
make[2]: *** No rule to make target 'Module.symvers', needed by
'kernel/kheaders_data.txz'.  Stop.
make[2]: *** Waiting for unfinished jobs....
/home/masahiro/workspace/bsp/linux/Makefile:1043: recipe for target
'kernel' failed
make[1]: *** [kernel] Error 2
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/home/masahiro/workspace/bsp/linux/hoge'
Makefile:152: recipe for target 'sub-make' failed
make: *** [sub-make] Error 2

I was able to compile it in-tree
but it makes the incremental build extremely slow.

(Here, the incremental build means
"make" without changing any code after the full build.)

Before this patch, "make -j8" took 11 sec on my machine.

real 0m11.777s
user 0m16.608s
sys 0m5.164s

After this patch, x86_64_defconfig + CONFIG_IKHEADERS_PROC=y takes 53 sec for me since kernel/kheaders_data.txz is regenerated every time even when you did not touch any source file.

$ time make -j8
  DESCEND  objtool
  CALL    scripts/checksyscalls.sh
  CHK     include/generated/compile.h
  GEN     kernel/kheaders_data.txz
  UPD     kernel/kheaders_data.h
  CC      kernel/kheaders.o
  AR      kernel/built-in.a
  GEN     .version
  CHK     include/generated/compile.h
  UPD     include/generated/compile.h
  CC      init/version.o
  AR      init/built-in.a
  AR      built-in.a
  LD      vmlinux.o
  MODPOST vmlinux.o
  KSYM    .tmp_kallsyms1.o
  KSYM    .tmp_kallsyms2.o
  LD      vmlinux
  SORTEX  vmlinux
  SYSMAP  System.map
  Building modules, stage 2.
  CC      arch/x86/boot/version.o
  MODPOST 17 modules
  VOFFSET arch/x86/boot/compressed/../voffset.h
  OBJCOPY arch/x86/boot/compressed/vmlinux.bin
  RELOCS  arch/x86/boot/compressed/vmlinux.relocs
  CC      arch/x86/boot/compressed/kaslr.o
  GZIP    arch/x86/boot/compressed/vmlinux.bin.gz
  CC      arch/x86/boot/compressed/misc.o
  MKPIGGY arch/x86/boot/compressed/piggy.S
  AS      arch/x86/boot/compressed/piggy.o
  LD      arch/x86/boot/compressed/vmlinux
  ZOFFSET arch/x86/boot/zoffset.h
  OBJCOPY arch/x86/boot/vmlinux.bin
  AS      arch/x86/boot/header.o
  LD      arch/x86/boot/setup.elf
  OBJCOPY arch/x86/boot/setup.bin
  BUILD   arch/x86/boot/bzImage
Setup is 15612 bytes (padded to 15872 bytes).
System is 12673 kB
CRC 697aaf88
Kernel: arch/x86/boot/bzImage is ready  (#6)

real 0m53.024s
user 0m32.076s
sys 0m9.296s

Also, I notice $(ARCH) must be fixed to $(SRCARCH), but that is one of minor issues.

We should take time for careful review and test.

Please give me more time for thorough review.

--
Best Regards
Masahiro Yamada

#7 lore raw
Quoted 9 lines · Masahiro Yamada

I was able to compile it in-tree
but it makes the incremental build extremely slow.

(Here, the incremental build means
"make" without changing any code after the full build.)

Before this patch, "make -j8" took 11 sec on my machine.

Quoted 7 lines

After this patch, x86_64_defconfig + CONFIG_IKHEADERS_PROC=y takes 53 sec for me since kernel/kheaders_data.txz is regenerated every time even when you did not touch any source file.

We should take time for careful review and test.

Please give me more time for thorough review.

Thanks for taking a look. All are very valid points. Incremental build is must have.

#8 lore raw
In reply to Masahiro Yamada
Quoted 31 lines · Masahiro Yamada
Quoted 4 lines · Alexei Starovoitov
Quoted 2 lines · Joel Fernandes (Google)

Introduce in-kernel headers and other artifacts which are made available as an archive through proc (/proc/kheaders.txz file).

The extension '.txz' is not used in kernel code.

'.tar.xz' is used for 'tarxz-pkg', 'perf-tarxz-src-pkg' etc.

$ git grep  '\.txz'
$ git grep  '\.tar\.xz'
Documentation/admin-guide/README.rst:     xz -cd linux-4.X.tar.xz | tar xvf -
arch/x86/crypto/camellia-aesni-avx-asm_64.S: *
http://koti.mbnet.fi/axh/crypto/camellia-BSD-1.2.0-aesni1.tar.xz
crypto/testmgr.h: *   https://bench.cr.yp.to/supercop/supercop-20170228.tar.xz
crypto/testmgr.h: *   https://bench.cr.yp.to/supercop/supercop-20170228.tar.xz
crypto/testmgr.h: *   https://bench.cr.yp.to/supercop/supercop-20170228.tar.xz
crypto/testmgr.h: *   https://bench.cr.yp.to/supercop/supercop-20170228.tar.xz
crypto/testmgr.h: *   https://bench.cr.yp.to/supercop/supercop-20170228.tar.xz
scripts/package/Makefile:       @echo '  perf-tarxz-src-pkg  - Build
$(perf-tar).tar.xz source tarball'
tools/testing/selftests/gen_kselftest_tar.sh:
 ext=".tar.xz"
Quoted 1 line

I prefer '.tar.xz' for consistency.

Ok, I will change it to that.

Quoted 8 lines

BTW, have you ever looked at scripts/extract-ikconfig?

You added IKHD_ST and IKHD_ED
just to mimic kernel/configs.c

It is currently pointless without the extracting tool, but you might think it is useful to extract headers from vmlinux or the module without mounting procfs.

I am planing add to extraction support in the future, so I prefer to leave the markers as it is for now. Hope that's Ok with you.

Quoted 20 lines
Quoted 15 lines
Quoted 6 lines

This archive makes
it possible to build kernel modules, run eBPF programs, and other tracing programs that need to extend the kernel for tracing purposes without any dependency on the file system having headers and build artifacts.

Quoted 8 lines

On Android and embedded systems, it is common to switch kernels but not have kernel headers available on the file system. Raw kernel headers also cannot be copied into the filesystem like they can be on other distros, due to licensing and other issues. There's no linux-headers package on Android. Further once a different kernel is booted, any headers stored on the file system will no longer be useful. By storing the headers as a compressed archive within the kernel, we can avoid these issues that have been a hindrance for a long time.

Quoted 3 lines

The set looks good to me and since the main use case is building bpf progs I can route it via bpf-next tree if there are no objections. Masahiro, could you please ack it?

Quoted 8 lines

Honestly, I was not tracking this thread
since I did not know I was responsible for this.

I just started to take a closer look, then immediately got scared.

This version is not mature enough for the merge.
First of all, this patch cannot be compiled out-of-tree (O= option).

Oh, ok. This is not how I build the kernel. So I am sorry for missing that. I will try this out-of-tree build option and fix it.

Quoted 42 lines

I do not know why 0-day bot did not catch this apparent breakage.

$ make -j8 O=hoge
make[1]: Entering directory '/home/masahiro/workspace/bsp/linux/hoge'
  GEN     Makefile
  Using .. as source for kernel
  DESCEND  objtool
  CALL    ../scripts/checksyscalls.sh
  CHK     include/generated/compile.h
make[2]: *** No rule to make target 'Module.symvers', needed by
'kernel/kheaders_data.txz'.  Stop.
make[2]: *** Waiting for unfinished jobs....
/home/masahiro/workspace/bsp/linux/Makefile:1043: recipe for target
'kernel' failed
make[1]: *** [kernel] Error 2
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/home/masahiro/workspace/bsp/linux/hoge'
Makefile:152: recipe for target 'sub-make' failed
make: *** [sub-make] Error 2

I was able to compile it in-tree
but it makes the incremental build extremely slow.

(Here, the incremental build means
"make" without changing any code after the full build.)

Before this patch, "make -j8" took 11 sec on my machine.

real 0m11.777s
user 0m16.608s
sys 0m5.164s

Quoted 3 lines

After this patch, x86_64_defconfig + CONFIG_IKHEADERS_PROC=y takes 53 sec for me since kernel/kheaders_data.txz is regenerated every time even when you did not touch any source file.

Hmm, true. Let me know look into that as well..

Quoted 51 lines
$ time make -j8
  DESCEND  objtool
  CALL    scripts/checksyscalls.sh
  CHK     include/generated/compile.h
  GEN     kernel/kheaders_data.txz
  UPD     kernel/kheaders_data.h
  CC      kernel/kheaders.o
  AR      kernel/built-in.a
  GEN     .version
  CHK     include/generated/compile.h
  UPD     include/generated/compile.h
  CC      init/version.o
  AR      init/built-in.a
  AR      built-in.a
  LD      vmlinux.o
  MODPOST vmlinux.o
  KSYM    .tmp_kallsyms1.o
  KSYM    .tmp_kallsyms2.o
  LD      vmlinux
  SORTEX  vmlinux
  SYSMAP  System.map
  Building modules, stage 2.
  CC      arch/x86/boot/version.o
  MODPOST 17 modules
  VOFFSET arch/x86/boot/compressed/../voffset.h
  OBJCOPY arch/x86/boot/compressed/vmlinux.bin
  RELOCS  arch/x86/boot/compressed/vmlinux.relocs
  CC      arch/x86/boot/compressed/kaslr.o
  GZIP    arch/x86/boot/compressed/vmlinux.bin.gz
  CC      arch/x86/boot/compressed/misc.o
  MKPIGGY arch/x86/boot/compressed/piggy.S
  AS      arch/x86/boot/compressed/piggy.o
  LD      arch/x86/boot/compressed/vmlinux
  ZOFFSET arch/x86/boot/zoffset.h
  OBJCOPY arch/x86/boot/vmlinux.bin
  AS      arch/x86/boot/header.o
  LD      arch/x86/boot/setup.elf
  OBJCOPY arch/x86/boot/setup.bin
  BUILD   arch/x86/boot/bzImage
Setup is 15612 bytes (padded to 15872 bytes).
System is 12673 kB
CRC 697aaf88
Kernel: arch/x86/boot/bzImage is ready  (#6)

real 0m53.024s
user 0m32.076s
sys 0m9.296s

Quoted 2 lines

Also, I notice $(ARCH) must be fixed to $(SRCARCH), but that is one of minor issues.

Ok.

Quoted 1 line

We should take time for careful review and test.

Yes, I agree.

Quoted 1 line

Please give me more time for thorough review.

Sure. Thanks a lot for the feedback provided so far. I will send another revision soon with all the suggestions addressed.

thanks,

- Joel

#9 lore raw
In reply to Masahiro Yamada
Quoted 96 lines · Masahiro Yamada
Quoted 4 lines · Alexei Starovoitov
Quoted 2 lines · Joel Fernandes (Google)

Introduce in-kernel headers and other artifacts which are made available as an archive through proc (/proc/kheaders.txz file).

The extension '.txz' is not used in kernel code.

'.tar.xz' is used for 'tarxz-pkg', 'perf-tarxz-src-pkg' etc.

$ git grep  '\.txz'
$ git grep  '\.tar\.xz'
Documentation/admin-guide/README.rst:     xz -cd linux-4.X.tar.xz | tar xvf -
arch/x86/crypto/camellia-aesni-avx-asm_64.S: *
http://koti.mbnet.fi/axh/crypto/camellia-BSD-1.2.0-aesni1.tar.xz
crypto/testmgr.h: *   https://bench.cr.yp.to/supercop/supercop-20170228.tar.xz
crypto/testmgr.h: *   https://bench.cr.yp.to/supercop/supercop-20170228.tar.xz
crypto/testmgr.h: *   https://bench.cr.yp.to/supercop/supercop-20170228.tar.xz
crypto/testmgr.h: *   https://bench.cr.yp.to/supercop/supercop-20170228.tar.xz
crypto/testmgr.h: *   https://bench.cr.yp.to/supercop/supercop-20170228.tar.xz
scripts/package/Makefile:       @echo '  perf-tarxz-src-pkg  - Build
$(perf-tar).tar.xz source tarball'
tools/testing/selftests/gen_kselftest_tar.sh:
 ext=".tar.xz"

I prefer '.tar.xz' for consistency.

BTW, have you ever looked at scripts/extract-ikconfig?

You added IKHD_ST and IKHD_ED
just to mimic kernel/configs.c

It is currently pointless without the extracting tool, but you might think it is useful to extract headers from vmlinux or the module without mounting procfs.

Quoted 15 lines
Quoted 6 lines

This archive makes
it possible to build kernel modules, run eBPF programs, and other tracing programs that need to extend the kernel for tracing purposes without any dependency on the file system having headers and build artifacts.

Quoted 8 lines

On Android and embedded systems, it is common to switch kernels but not have kernel headers available on the file system. Raw kernel headers also cannot be copied into the filesystem like they can be on other distros, due to licensing and other issues. There's no linux-headers package on Android. Further once a different kernel is booted, any headers stored on the file system will no longer be useful. By storing the headers as a compressed archive within the kernel, we can avoid these issues that have been a hindrance for a long time.

Quoted 3 lines

The set looks good to me and since the main use case is building bpf progs I can route it via bpf-next tree if there are no objections. Masahiro, could you please ack it?

Honestly, I was not tracking this thread
since I did not know I was responsible for this.

I just started to take a closer look, then immediately got scared.

This version is not mature enough for the merge.

First of all, this patch cannot be compiled out-of-tree (O= option).

I do not know why 0-day bot did not catch this apparent breakage.

$ make -j8 O=hoge
make[1]: Entering directory '/home/masahiro/workspace/bsp/linux/hoge'
  GEN     Makefile
  Using .. as source for kernel
  DESCEND  objtool
  CALL    ../scripts/checksyscalls.sh
  CHK     include/generated/compile.h
make[2]: *** No rule to make target 'Module.symvers', needed by
'kernel/kheaders_data.txz'.  Stop.
Quoted 8 lines
make[2]: *** Waiting for unfinished jobs....
/home/masahiro/workspace/bsp/linux/Makefile:1043: recipe for target
'kernel' failed
make[1]: *** [kernel] Error 2
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/home/masahiro/workspace/bsp/linux/hoge'
Makefile:152: recipe for target 'sub-make' failed
make: *** [sub-make] Error 2

I saw this build error for in-tree building as well.

We cannot build this from a pristine source tree.

For example, I observed the build error in the following procedure.

$ make mrproper
$ make defconfig
 Set CONFIG_IKHEADERS_PROC=y
$ make

Module.symvers is generated in the modpost stage
(the very last stage of build).

But, vmlinux depends on kernel/kheaders_data.txz,
which includes Module.symvers.

So, this is not so simple since it is a circular dependency...

Signature · 2 lines
Best Regards
Masahiro Yamada
#10 lore raw

On Tue, Feb 19, 2019@01:42:13PM +0900, Masahiro Yamada wrote:
[..]

Quoted 71 lines
Quoted 45 lines
Quoted 15 lines
Quoted 6 lines

This archive makes
it possible to build kernel modules, run eBPF programs, and other tracing programs that need to extend the kernel for tracing purposes without any dependency on the file system having headers and build artifacts.

Quoted 8 lines

On Android and embedded systems, it is common to switch kernels but not have kernel headers available on the file system. Raw kernel headers also cannot be copied into the filesystem like they can be on other distros, due to licensing and other issues. There's no linux-headers package on Android. Further once a different kernel is booted, any headers stored on the file system will no longer be useful. By storing the headers as a compressed archive within the kernel, we can avoid these issues that have been a hindrance for a long time.

Quoted 3 lines

The set looks good to me and since the main use case is building bpf progs I can route it via bpf-next tree if there are no objections. Masahiro, could you please ack it?

Honestly, I was not tracking this thread
since I did not know I was responsible for this.

I just started to take a closer look, then immediately got scared.

This version is not mature enough for the merge.

First of all, this patch cannot be compiled out-of-tree (O= option).

I do not know why 0-day bot did not catch this apparent breakage.

$ make -j8 O=hoge
make[1]: Entering directory '/home/masahiro/workspace/bsp/linux/hoge'
  GEN     Makefile
  Using .. as source for kernel
  DESCEND  objtool
  CALL    ../scripts/checksyscalls.sh
  CHK     include/generated/compile.h
make[2]: *** No rule to make target 'Module.symvers', needed by
'kernel/kheaders_data.txz'.  Stop.
Quoted 8 lines
make[2]: *** Waiting for unfinished jobs....
/home/masahiro/workspace/bsp/linux/Makefile:1043: recipe for target
'kernel' failed
make[1]: *** [kernel] Error 2
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/home/masahiro/workspace/bsp/linux/hoge'
Makefile:152: recipe for target 'sub-make' failed
make: *** [sub-make] Error 2

I saw this build error for in-tree building as well.

We cannot build this from a pristine source tree.

For example, I observed the build error in the following procedure.

$ make mrproper
$ make defconfig
 Set CONFIG_IKHEADERS_PROC=y
$ make
Quoted 7 lines

Module.symvers is generated in the modpost stage
(the very last stage of build).

But, vmlinux depends on kernel/kheaders_data.txz,
which includes Module.symvers.

So, this is not so simple since it is a circular dependency...

I guess I was not building a pristine tree either and missed this circular dependency :-/ . Any ideas on how we can fix the Module.symvers issue? One idea is to reserve the space in the binaries, but only populate the space reserved in the binary *after* the modpost stage, once the archive is ready..

thanks,

- Joel

#11 lore raw
In reply to Masahiro Yamada
Quoted 124 lines · Masahiro Yamada
Quoted 96 lines · Masahiro Yamada
Quoted 4 lines · Alexei Starovoitov
Quoted 2 lines · Joel Fernandes (Google)

Introduce in-kernel headers and other artifacts which are made available as an archive through proc (/proc/kheaders.txz file).

The extension '.txz' is not used in kernel code.

'.tar.xz' is used for 'tarxz-pkg', 'perf-tarxz-src-pkg' etc.

$ git grep  '\.txz'
$ git grep  '\.tar\.xz'
Documentation/admin-guide/README.rst:     xz -cd linux-4.X.tar.xz | tar xvf -
arch/x86/crypto/camellia-aesni-avx-asm_64.S: *
http://koti.mbnet.fi/axh/crypto/camellia-BSD-1.2.0-aesni1.tar.xz
crypto/testmgr.h: *   https://bench.cr.yp.to/supercop/supercop-20170228.tar.xz
crypto/testmgr.h: *   https://bench.cr.yp.to/supercop/supercop-20170228.tar.xz
crypto/testmgr.h: *   https://bench.cr.yp.to/supercop/supercop-20170228.tar.xz
crypto/testmgr.h: *   https://bench.cr.yp.to/supercop/supercop-20170228.tar.xz
crypto/testmgr.h: *   https://bench.cr.yp.to/supercop/supercop-20170228.tar.xz
scripts/package/Makefile:       @echo '  perf-tarxz-src-pkg  - Build
$(perf-tar).tar.xz source tarball'
tools/testing/selftests/gen_kselftest_tar.sh:
 ext=".tar.xz"

I prefer '.tar.xz' for consistency.

BTW, have you ever looked at scripts/extract-ikconfig?

You added IKHD_ST and IKHD_ED
just to mimic kernel/configs.c

It is currently pointless without the extracting tool, but you might think it is useful to extract headers from vmlinux or the module without mounting procfs.

Quoted 15 lines
Quoted 6 lines

This archive makes
it possible to build kernel modules, run eBPF programs, and other tracing programs that need to extend the kernel for tracing purposes without any dependency on the file system having headers and build artifacts.

Quoted 8 lines

On Android and embedded systems, it is common to switch kernels but not have kernel headers available on the file system. Raw kernel headers also cannot be copied into the filesystem like they can be on other distros, due to licensing and other issues. There's no linux-headers package on Android. Further once a different kernel is booted, any headers stored on the file system will no longer be useful. By storing the headers as a compressed archive within the kernel, we can avoid these issues that have been a hindrance for a long time.

Quoted 3 lines

The set looks good to me and since the main use case is building bpf progs I can route it via bpf-next tree if there are no objections. Masahiro, could you please ack it?

Honestly, I was not tracking this thread
since I did not know I was responsible for this.

I just started to take a closer look, then immediately got scared.

This version is not mature enough for the merge.

First of all, this patch cannot be compiled out-of-tree (O= option).

I do not know why 0-day bot did not catch this apparent breakage.

$ make -j8 O=hoge
make[1]: Entering directory '/home/masahiro/workspace/bsp/linux/hoge'
  GEN     Makefile
  Using .. as source for kernel
  DESCEND  objtool
  CALL    ../scripts/checksyscalls.sh
  CHK     include/generated/compile.h
make[2]: *** No rule to make target 'Module.symvers', needed by
'kernel/kheaders_data.txz'.  Stop.
Quoted 8 lines
make[2]: *** Waiting for unfinished jobs....
/home/masahiro/workspace/bsp/linux/Makefile:1043: recipe for target
'kernel' failed
make[1]: *** [kernel] Error 2
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/home/masahiro/workspace/bsp/linux/hoge'
Makefile:152: recipe for target 'sub-make' failed
make: *** [sub-make] Error 2

I saw this build error for in-tree building as well.

We cannot build this from a pristine source tree.

For example, I observed the build error in the following procedure.

$ make mrproper
$ make defconfig
 Set CONFIG_IKHEADERS_PROC=y
$ make
Quoted 5 lines

Module.symvers is generated in the modpost stage
(the very last stage of build).

But, vmlinux depends on kernel/kheaders_data.txz,
which includes Module.symvers.

Firstly, I want to apologize for not testing this and other corner cases you brought up. I should have known better. Since my build was working, I assumed that the feature is working. For that, I am very sorry.

Secondly, it turns out Module.symvers circularly dependency problem also exists with another use case.
If one does 'make modules_prepare' in a base kernel tree and then tries to build modules with that tree, a warning like this is printed but the module still gets built:

WARNING: Symbol version dump ./Module.symvers
is missing; modules will have no dependencies and modversions.

CC [M] /tmp/testmod/test.o
Building modules, stage 2.
MODPOST 1 modules
CC /tmp/testmod/test.mod.o
LD [M] /tmp/testmod/test.ko

So, I am thinking that at least for first pass I will just drop the inclusion of Module.symvers in the archive and allow any modules built using /proc/kheaders.tar.xz to not use it.

Kbuild will print a warning anyway when anyone tries to build using /proc/kheaders.tar.xz, so if the user really wants module symbol versioning then they should probably use a full kernel source tree with Module.symvers available. For our usecase, kernel symbol versioning is a bit useless when using /proc/kheaders.tar.gz because the proc file is generated with the same kernel that the module is being built against, and subsequently loaded into the kernel. So it is not likely that the CRC of a kernel symbol will be different from what the module expects.

I can't think any other ways at the moment to break the circular dependency so I'm thinking this is good enough for now especially since Kbuild will print a proper warning. Let me know what you think?

thanks,

- Joel

#12 lore raw
Quoted 4 lines · Joel Fernandes

Firstly, I want to apologize for not testing this and other corner cases you brought up. I should have known better. Since my build was working, I assumed that the feature is working. For that, I am very sorry.

You do not need to apologize. 0day bot usually catches build errors. I guess 0day bot performs compile-tests only incrementally and that is why we did not get any report.

Quoted 19 lines

Secondly, it turns out Module.symvers circularly dependency problem also exists with another use case.
If one does 'make modules_prepare' in a base kernel tree and then tries to build modules with that tree, a warning like this is printed but the module still gets built:

WARNING: Symbol version dump ./Module.symvers
is missing; modules will have no dependencies and modversions.

CC [M] /tmp/testmod/test.o
Building modules, stage 2.
MODPOST 1 modules
CC /tmp/testmod/test.mod.o
LD [M] /tmp/testmod/test.ko

So, I am thinking that at least for first pass I will just drop the inclusion of Module.symvers in the archive and allow any modules built using /proc/kheaders.tar.xz to not use it.

Quoted 8 lines

Kbuild will print a warning anyway when anyone tries to build using /proc/kheaders.tar.xz, so if the user really wants module symbol versioning then they should probably use a full kernel source tree with Module.symvers available. For our usecase, kernel symbol versioning is a bit useless when using /proc/kheaders.tar.gz because the proc file is generated with the same kernel that the module is being built against, and subsequently loaded into the kernel. So it is not likely that the CRC of a kernel symbol will be different from what the module expects.

Without Module.symver, modpost cannot check whether references are resolvable or not.

You will see "WARNING ... undefined" for every symbol referenced from the module.

I am not an Android developer.
So, I will leave this judge to other people.

One more request if you have a chance to submit the next version. Please do not hide error messages.

I wondered why you redirected stdout/stderr from the script.

I applied the following patch, and I tested. Then I see why.

Please fix your code instead of hiding underlying problems.

kernel/Makefile +1 -1
index 1d13a7a..a76ccbd 100644
@@ -148,7 +148,7 @@ $(obj)/kheaders.o: $(obj)/kheaders_data.h
 targets += kheaders_data.txz
 
 quiet_cmd_genikh = GEN     $(obj)/kheaders_data.txz
-cmd_genikh = $(srctree)/scripts/gen_ikh_data.sh $@ $^ >/dev/null 2>&1
+cmd_genikh = $(srctree)/scripts/gen_ikh_data.sh $@ $^
 $(obj)/kheaders_data.txz: $(ikh_file_list) FORCE
        $(call cmd,genikh)
 

masahiro at grover:~/workspace/linux-yamada$ make
CALL scripts/checksyscalls.sh
DESCEND objtool
CHK include/generated/compile.h
GEN kernel/kheaders_data.txz
find: ‘FORCE’: No such file or directory
70106 blocks
Can't do inplace edit: kernel/kheaders_data.txz.tmp is not a regular file. Can't do inplace edit: kernel/kheaders_data.txz.tmp/arch is not a regular file. Can't do inplace edit: kernel/kheaders_data.txz.tmp/arch/x86 is not a regular file.
Can't do inplace edit: kernel/kheaders_data.txz.tmp/arch/x86/include is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/uapi is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/uapi/asm is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/generated is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/generated/uapi is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/generated/uapi/asm is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/generated/asm is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/asm is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/asm/xen is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/asm/uv is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/asm/numachip is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/asm/e820 is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/asm/fpu is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/asm/crypto is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/asm/trace is not a regular file.
Can't do inplace edit: kernel/kheaders_data.txz.tmp/scripts is not a regular file.
Can't do inplace edit: kernel/kheaders_data.txz.tmp/scripts/genksyms is not a regular file.
Can't do inplace edit: kernel/kheaders_data.txz.tmp/scripts/ksymoops is not a regular file.
Can't do inplace edit: kernel/kheaders_data.txz.tmp/scripts/gdb is not a regular file.
Can't do inplace edit: kernel/kheaders_data.txz.tmp/scripts/gdb/linux is not a regular file.
Can't do inplace edit: kernel/kheaders_data.txz.tmp/scripts/basic is not a regular file.
Can't do inplace edit: kernel/kheaders_data.txz.tmp/scripts/dtc is not a regular file.
Can't do inplace edit: kernel/kheaders_data.txz.tmp/scripts/dtc/libfdt is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes is not a regular file.
Can't open kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/arm64:
No such file or directory.
Can't open kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/xtensa:
No such file or directory.
Can't open kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/openrisc:
No such file or directory.
Can't open kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/nios2:
No such file or directory.
Can't open kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/mips:
No such file or directory.
Can't open kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/arm:
No such file or directory.
Can't open kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/microblaze:
No such file or directory.
Can't open kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/arc:
No such file or directory.
Can't open kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/sh:
No such file or directory.
Can't open kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/powerpc:
No such file or directory.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/dt-bindings is not a regular file.

[ massive amount of error messages continues ]

Quoted 8 lines

I can't think any other ways at the moment to break the circular dependency so I'm thinking this is good enough for now especially since Kbuild will print a proper warning. Let me know what you think?

thanks,

- Joel

--
Best Regards
Masahiro Yamada

#13 lore raw
Quoted 11 lines · Masahiro Yamada
Quoted 4 lines · Joel Fernandes

Firstly, I want to apologize for not testing this and other corner cases you brought up. I should have known better. Since my build was working, I assumed that the feature is working. For that, I am very sorry.

You do not need to apologize. 0day bot usually catches build errors. I guess 0day bot performs compile-tests only incrementally and that is why we did not get any report.

Oh ok :) thanks.

Quoted 32 lines
Quoted 19 lines

Secondly, it turns out Module.symvers circularly dependency problem also exists with another use case.
If one does 'make modules_prepare' in a base kernel tree and then tries to build modules with that tree, a warning like this is printed but the module still gets built:

WARNING: Symbol version dump ./Module.symvers
is missing; modules will have no dependencies and modversions.

CC [M] /tmp/testmod/test.o
Building modules, stage 2.
MODPOST 1 modules
CC /tmp/testmod/test.mod.o
LD [M] /tmp/testmod/test.ko

So, I am thinking that at least for first pass I will just drop the inclusion of Module.symvers in the archive and allow any modules built using /proc/kheaders.tar.xz to not use it.

Quoted 8 lines

Kbuild will print a warning anyway when anyone tries to build using /proc/kheaders.tar.xz, so if the user really wants module symbol versioning then they should probably use a full kernel source tree with Module.symvers available. For our usecase, kernel symbol versioning is a bit useless when using /proc/kheaders.tar.gz because the proc file is generated with the same kernel that the module is being built against, and subsequently loaded into the kernel. So it is not likely that the CRC of a kernel symbol will be different from what the module expects.

Without Module.symver, modpost cannot check whether references are resolvable or not.

Quoted 6 lines

You will see "WARNING ... undefined" for every symbol referenced from the module.

I am not an Android developer.
So, I will leave this judge to other people.

IMO I don't see a way around this limiation but it would be nice if there was a way to make it work. Since the kernel modules being built by this mechanism are for tracing/debugging purposes, it is not a major concern for us.

Quoted 2 lines

One more request if you have a chance to submit the next version. Please do not hide error messages.

Actually it was intended to suppress noise, not hide errors as such. I have fixed all the errors in the next version and will be submitting it soon.

Thanks a lot for the review!

- Joel

Quoted 141 lines

I wondered why you redirected stdout/stderr from the script.

I applied the following patch, and I tested. Then I see why.

Please fix your code instead of hiding underlying problems.

kernel/Makefile +1 -1
index 1d13a7a..a76ccbd 100644
@@ -148,7 +148,7 @@ $(obj)/kheaders.o: $(obj)/kheaders_data.h
 targets += kheaders_data.txz
 
 quiet_cmd_genikh = GEN     $(obj)/kheaders_data.txz
-cmd_genikh = $(srctree)/scripts/gen_ikh_data.sh $@ $^ >/dev/null 2>&1
+cmd_genikh = $(srctree)/scripts/gen_ikh_data.sh $@ $^
 $(obj)/kheaders_data.txz: $(ikh_file_list) FORCE
        $(call cmd,genikh)
 

masahiro at grover:~/workspace/linux-yamada$ make
CALL scripts/checksyscalls.sh
DESCEND objtool
CHK include/generated/compile.h
GEN kernel/kheaders_data.txz
find: ‘FORCE’: No such file or directory
70106 blocks
Can't do inplace edit: kernel/kheaders_data.txz.tmp is not a regular file. Can't do inplace edit: kernel/kheaders_data.txz.tmp/arch is not a regular file. Can't do inplace edit: kernel/kheaders_data.txz.tmp/arch/x86 is not a regular file.
Can't do inplace edit: kernel/kheaders_data.txz.tmp/arch/x86/include is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/uapi is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/uapi/asm is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/generated is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/generated/uapi is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/generated/uapi/asm is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/generated/asm is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/asm is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/asm/xen is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/asm/uv is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/asm/numachip is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/asm/e820 is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/asm/fpu is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/asm/crypto is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/arch/x86/include/asm/trace is not a regular file.
Can't do inplace edit: kernel/kheaders_data.txz.tmp/scripts is not a regular file.
Can't do inplace edit: kernel/kheaders_data.txz.tmp/scripts/genksyms is not a regular file.
Can't do inplace edit: kernel/kheaders_data.txz.tmp/scripts/ksymoops is not a regular file.
Can't do inplace edit: kernel/kheaders_data.txz.tmp/scripts/gdb is not a regular file.
Can't do inplace edit: kernel/kheaders_data.txz.tmp/scripts/gdb/linux is not a regular file.
Can't do inplace edit: kernel/kheaders_data.txz.tmp/scripts/basic is not a regular file.
Can't do inplace edit: kernel/kheaders_data.txz.tmp/scripts/dtc is not a regular file.
Can't do inplace edit: kernel/kheaders_data.txz.tmp/scripts/dtc/libfdt is not a regular file.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes is not a regular file.
Can't open kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/arm64:
No such file or directory.
Can't open kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/xtensa:
No such file or directory.
Can't open kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/openrisc:
No such file or directory.
Can't open kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/nios2:
No such file or directory.
Can't open kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/mips:
No such file or directory.
Can't open kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/arm:
No such file or directory.
Can't open kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/microblaze:
No such file or directory.
Can't open kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/arc:
No such file or directory.
Can't open kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/sh:
No such file or directory.
Can't open kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/powerpc:
No such file or directory.
Can't do inplace edit:
kernel/kheaders_data.txz.tmp/scripts/dtc/include-prefixes/dt-bindings is not a regular file.

[ massive amount of error messages continues ]

Quoted 8 lines

I can't think any other ways at the moment to break the circular dependency so I'm thinking this is good enough for now especially since Kbuild will print a proper warning. Let me know what you think?

thanks,

- Joel

--
Best Regards
Masahiro Yamada

#14 lore raw
In reply to Alexei Starovoitov
Quoted 17 lines · Alexei Starovoitov
Quoted 7 lines · Joel Fernandes (Google)

Introduce in-kernel headers and other artifacts which are made available as an archive through proc (/proc/kheaders.txz file). This archive makes it possible to build kernel modules, run eBPF programs, and other tracing programs that need to extend the kernel for tracing purposes without any dependency on the file system having headers and build artifacts.

Quoted 8 lines

On Android and embedded systems, it is common to switch kernels but not have kernel headers available on the file system. Raw kernel headers also cannot be copied into the filesystem like they can be on other distros, due to licensing and other issues. There's no linux-headers package on Android. Further once a different kernel is booted, any headers stored on the file system will no longer be useful. By storing the headers as a compressed archive within the kernel, we can avoid these issues that have been a hindrance for a long time.

Quoted 3 lines

The set looks good to me and since the main use case is building bpf progs I can route it via bpf-next tree if there are no objections. Masahiro, could you please ack it?

FYI, Masahiro's comments were all address by v5:
https://lore.kernel.org/patchwork/project/lkml/list/?series=387311

I believe aren't more outstanding concerns. Could we consider it for v5.2?

thanks,

- Joel

#15 lore raw
Quoted 18 lines · Joel Fernandes
Quoted 17 lines · Alexei Starovoitov
Quoted 15 lines · Joel Fernandes (Google)

Introduce in-kernel headers and other artifacts which are made available as an archive through proc (/proc/kheaders.txz file). This archive makes it possible to build kernel modules, run eBPF programs, and other tracing programs that need to extend the kernel for tracing purposes without any dependency on the file system having headers and build artifacts.

On Android and embedded systems, it is common to switch kernels but not have kernel headers available on the file system. Raw kernel headers also cannot be copied into the filesystem like they can be on other distros, due to licensing and other issues. There's no linux-headers package on Android. Further once a different kernel is booted, any headers stored on the file system will no longer be useful. By storing the headers as a compressed archive within the kernel, we can avoid these issues that have been a hindrance for a long time.

Quoted 8 lines
Quoted 3 lines

The set looks good to me and since the main use case is building bpf progs I can route it via bpf-next tree if there are no objections. Masahiro, could you please ack it?

FYI, Masahiro's comments were all address by v5:
https://lore.kernel.org/patchwork/project/lkml/list/?series=387311

I believe aren't more outstanding concerns. Could we consider it for v5.2?

Just to highlight the problem, today I booted v5.0 on an emulated Android device for some testing, that didn't have a set of prebuilt headers that we have been packaging on well known kernels, to get around this issue. This caused great pain and issues with what I was doing. I know me and many others really want this. With this I can boot an emulated Android device with IKCONFIG_PROC=y and run BCC with that that. Also I want to do the BCC side of the development, but first want to know if we can merge this upstream.

Masahiro, I believe due diligence has been done in solidifying it as posted in the v5. Anything else we need to do here? Are you with the patches?

thanks!

- Joel

#16 lore raw
Quoted 37 lines · Joel Fernandes
Quoted 18 lines · Joel Fernandes
Quoted 17 lines · Alexei Starovoitov
Quoted 15 lines · Joel Fernandes (Google)

Introduce in-kernel headers and other artifacts which are made available as an archive through proc (/proc/kheaders.txz file). This archive makes it possible to build kernel modules, run eBPF programs, and other tracing programs that need to extend the kernel for tracing purposes without any dependency on the file system having headers and build artifacts.

On Android and embedded systems, it is common to switch kernels but not have kernel headers available on the file system. Raw kernel headers also cannot be copied into the filesystem like they can be on other distros, due to licensing and other issues. There's no linux-headers package on Android. Further once a different kernel is booted, any headers stored on the file system will no longer be useful. By storing the headers as a compressed archive within the kernel, we can avoid these issues that have been a hindrance for a long time.

Quoted 8 lines
Quoted 3 lines

The set looks good to me and since the main use case is building bpf progs I can route it via bpf-next tree if there are no objections. Masahiro, could you please ack it?

FYI, Masahiro's comments were all address by v5:
https://lore.kernel.org/patchwork/project/lkml/list/?series=387311

I believe aren't more outstanding concerns. Could we consider it for v5.2?

Just to highlight the problem, today I booted v5.0 on an emulated Android device for some testing, that didn't have a set of prebuilt headers that we have been packaging on well known kernels, to get around this issue. This caused great pain and issues with what I was doing. I know me and many others really want this. With this I can boot an emulated Android device with IKCONFIG_PROC=y and run BCC with that that. Also I want to do the BCC side of the development, but first want to know if we can merge this upstream.

Quoted 2 lines

Masahiro, I believe due diligence has been done in solidifying it as posted in the v5. Anything else we need to do here? Are you with the patches?

As you said, these updates are "cosmetic". Nobody is worried about (or interested in) them. Even if we miss something, they are fixable later.

I accept embedding headers in the kernel,
but I do not like the part about external module build.
- kernel embeds build artifacts that depend on a particular host-arch
- users do not know which compiler to use

Perhaps, you may remember my concerns.
https://lore.kernel.org/patchwork/patch/1046307/#1239501

I reviewed this, and already expressed my opinion, so I finished all job I can do.

Anyway, you believe this approach is solid. All that is left is somebody makes a decision. Already you are asking this to Andrew. Good luck!

--
Best Regards
Masahiro Yamada

#17 lore raw
Quoted 46 lines · Masahiro Yamada
Quoted 37 lines · Joel Fernandes
Quoted 18 lines · Joel Fernandes
Quoted 17 lines · Alexei Starovoitov
Quoted 15 lines · Joel Fernandes (Google)

Introduce in-kernel headers and other artifacts which are made available as an archive through proc (/proc/kheaders.txz file). This archive makes it possible to build kernel modules, run eBPF programs, and other tracing programs that need to extend the kernel for tracing purposes without any dependency on the file system having headers and build artifacts.

On Android and embedded systems, it is common to switch kernels but not have kernel headers available on the file system. Raw kernel headers also cannot be copied into the filesystem like they can be on other distros, due to licensing and other issues. There's no linux-headers package on Android. Further once a different kernel is booted, any headers stored on the file system will no longer be useful. By storing the headers as a compressed archive within the kernel, we can avoid these issues that have been a hindrance for a long time.

Quoted 8 lines
Quoted 3 lines

The set looks good to me and since the main use case is building bpf progs I can route it via bpf-next tree if there are no objections. Masahiro, could you please ack it?

FYI, Masahiro's comments were all address by v5:
https://lore.kernel.org/patchwork/project/lkml/list/?series=387311

I believe aren't more outstanding concerns. Could we consider it for v5.2?

Just to highlight the problem, today I booted v5.0 on an emulated Android device for some testing, that didn't have a set of prebuilt headers that we have been packaging on well known kernels, to get around this issue. This caused great pain and issues with what I was doing. I know me and many others really want this. With this I can boot an emulated Android device with IKCONFIG_PROC=y and run BCC with that that. Also I want to do the BCC side of the development, but first want to know if we can merge this upstream.

Quoted 2 lines

Masahiro, I believe due diligence has been done in solidifying it as posted in the v5. Anything else we need to do here? Are you with the patches?

As you said, these updates are "cosmetic". Nobody is worried about (or interested in) them. Even if we miss something, they are fixable later.

Quoted 7 lines

I accept embedding headers in the kernel,
but I do not like the part about external module build.
- kernel embeds build artifacts that depend on a particular host-arch
- users do not know which compiler to use
Perhaps, you may remember my concerns.
https://lore.kernel.org/patchwork/patch/1046307/#1239501

Masahiro,
I think we already discussed this right. The compiler issue is a user-issue - it is not a problem that has arisen because this patch. Anyone can build a kernel module today without this patch - using a compiler that is different from the running kernel. So I did not fully understand your concern. This patch does not ship a compiler in the archive. The compiler is upto the user based on user environment. They can already shoot themself in foot without this patch.

Greg,
Would be great to get your thoughts here as well about Masami's concern.

Honestly, the "kernel module building artifacts" bit is a bonus with this patch. The main thing we are adding or that we need is really the headers (for BCC). I just thought shipping the kernel build artifacts would also be awesome because people can now build kernel modules without needing a kernel tree at all.

But I also want this stuff merged so if folks are really unhappy with the module build artifacts and only want headers - then that's also fine with me and I can yank them - that would also mean though that this work cannot be a replacement for linux-headers package on distros, so that would be sad.

thanks!

- Joel

Quoted 4 lines

--
Best Regards
Masahiro Yamada

#18 lore raw
Quoted 74 lines · Joel Fernandes
Quoted 46 lines · Masahiro Yamada
Quoted 37 lines · Joel Fernandes
Quoted 18 lines · Joel Fernandes
Quoted 17 lines · Alexei Starovoitov
Quoted 15 lines · Joel Fernandes (Google)

Introduce in-kernel headers and other artifacts which are made available as an archive through proc (/proc/kheaders.txz file). This archive makes it possible to build kernel modules, run eBPF programs, and other tracing programs that need to extend the kernel for tracing purposes without any dependency on the file system having headers and build artifacts.

On Android and embedded systems, it is common to switch kernels but not have kernel headers available on the file system. Raw kernel headers also cannot be copied into the filesystem like they can be on other distros, due to licensing and other issues. There's no linux-headers package on Android. Further once a different kernel is booted, any headers stored on the file system will no longer be useful. By storing the headers as a compressed archive within the kernel, we can avoid these issues that have been a hindrance for a long time.

Quoted 8 lines
Quoted 3 lines

The set looks good to me and since the main use case is building bpf progs I can route it via bpf-next tree if there are no objections. Masahiro, could you please ack it?

FYI, Masahiro's comments were all address by v5:
https://lore.kernel.org/patchwork/project/lkml/list/?series=387311

I believe aren't more outstanding concerns. Could we consider it for v5.2?

Just to highlight the problem, today I booted v5.0 on an emulated Android device for some testing, that didn't have a set of prebuilt headers that we have been packaging on well known kernels, to get around this issue. This caused great pain and issues with what I was doing. I know me and many others really want this. With this I can boot an emulated Android device with IKCONFIG_PROC=y and run BCC with that that. Also I want to do the BCC side of the development, but first want to know if we can merge this upstream.

Quoted 2 lines

Masahiro, I believe due diligence has been done in solidifying it as posted in the v5. Anything else we need to do here? Are you with the patches?

As you said, these updates are "cosmetic". Nobody is worried about (or interested in) them. Even if we miss something, they are fixable later.

Quoted 7 lines

I accept embedding headers in the kernel,
but I do not like the part about external module build.
- kernel embeds build artifacts that depend on a particular host-arch
- users do not know which compiler to use
Perhaps, you may remember my concerns.
https://lore.kernel.org/patchwork/patch/1046307/#1239501

Masahiro,
I think we already discussed this right. The compiler issue is a user-issue - it is not a problem that has arisen because this patch. Anyone can build a kernel module today without this patch - using a compiler that is different from the running kernel. So I did not fully understand your concern. This patch does not ship a compiler in the archive. The compiler is upto the user based on user environment. They can already shoot themself in foot without this patch.

Greg,
Would be great to get your thoughts here as well about Masami's concern.

Honestly, the "kernel module building artifacts" bit is a bonus with this patch. The main thing we are adding or that we need is really the headers (for BCC). I just thought shipping the kernel build artifacts would also be awesome because people can now build kernel modules without needing a kernel tree at all.

Quoted 6 lines

But I also want this stuff merged so if folks are really unhappy with the module build artifacts and only want headers - then that's also fine with me and I can yank them - that would also mean though that this work cannot be a replacement for linux-headers package on distros, so that would be sad.

thanks!

IMHO, including the module build stuff is fine, and the stuff that Masahiro mentions doesn't matter much. To be specific about the concerns:

Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line

- kernel embeds build artifacts that depend on a

particular host-arch

What are these artifacts? We build the kernel as a standalone system. It's not as if we statically link host glibc into it or something.

Quoted 1 line
Quoted 1 line

- users do not know which compiler to use

Does that matter much? Do things ever break if the kernel proper is built with GCC x.y.z and we build a module with GCC x.y.(z+1)? Why would it? Structure layout is invariant across compiler version, or at least ought to be. And don't we have exactly the same problem with any kernel headers package? I don't think it'd hurt to include the output of $(CC) --version though.

Like Joel, I'd like to see this change merged. It'll make life easier for a lot of people.

#19 lore raw
Quoted 86 lines · Daniel Colascione
Quoted 74 lines · Joel Fernandes
Quoted 46 lines · Masahiro Yamada
Quoted 37 lines · Joel Fernandes
Quoted 18 lines · Joel Fernandes
Quoted 17 lines · Alexei Starovoitov
Quoted 15 lines · Joel Fernandes (Google)

Introduce in-kernel headers and other artifacts which are made available as an archive through proc (/proc/kheaders.txz file). This archive makes it possible to build kernel modules, run eBPF programs, and other tracing programs that need to extend the kernel for tracing purposes without any dependency on the file system having headers and build artifacts.

On Android and embedded systems, it is common to switch kernels but not have kernel headers available on the file system. Raw kernel headers also cannot be copied into the filesystem like they can be on other distros, due to licensing and other issues. There's no linux-headers package on Android. Further once a different kernel is booted, any headers stored on the file system will no longer be useful. By storing the headers as a compressed archive within the kernel, we can avoid these issues that have been a hindrance for a long time.

Quoted 8 lines
Quoted 3 lines

The set looks good to me and since the main use case is building bpf progs I can route it via bpf-next tree if there are no objections. Masahiro, could you please ack it?

FYI, Masahiro's comments were all address by v5:
https://lore.kernel.org/patchwork/project/lkml/list/?series=387311

I believe aren't more outstanding concerns. Could we consider it for v5.2?

Just to highlight the problem, today I booted v5.0 on an emulated Android device for some testing, that didn't have a set of prebuilt headers that we have been packaging on well known kernels, to get around this issue. This caused great pain and issues with what I was doing. I know me and many others really want this. With this I can boot an emulated Android device with IKCONFIG_PROC=y and run BCC with that that. Also I want to do the BCC side of the development, but first want to know if we can merge this upstream.

Quoted 2 lines

Masahiro, I believe due diligence has been done in solidifying it as posted in the v5. Anything else we need to do here? Are you with the patches?

As you said, these updates are "cosmetic". Nobody is worried about (or interested in) them. Even if we miss something, they are fixable later.

Quoted 7 lines

I accept embedding headers in the kernel,
but I do not like the part about external module build.
- kernel embeds build artifacts that depend on a particular host-arch
- users do not know which compiler to use
Perhaps, you may remember my concerns.
https://lore.kernel.org/patchwork/patch/1046307/#1239501

Masahiro,
I think we already discussed this right. The compiler issue is a user-issue - it is not a problem that has arisen because this patch. Anyone can build a kernel module today without this patch - using a compiler that is different from the running kernel. So I did not fully understand your concern. This patch does not ship a compiler in the archive. The compiler is upto the user based on user environment. They can already shoot themself in foot without this patch.

Greg,
Would be great to get your thoughts here as well about Masami's concern.

Honestly, the "kernel module building artifacts" bit is a bonus with this patch. The main thing we are adding or that we need is really the headers (for BCC). I just thought shipping the kernel build artifacts would also be awesome because people can now build kernel modules without needing a kernel tree at all.

Quoted 6 lines

But I also want this stuff merged so if folks are really unhappy with the module build artifacts and only want headers - then that's also fine with me and I can yank them - that would also mean though that this work cannot be a replacement for linux-headers package on distros, so that would be sad.

thanks!

IMHO, including the module build stuff is fine, and the stuff that Masahiro mentions doesn't matter much. To be specific about the concerns:

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line

- kernel embeds build artifacts that depend on a

particular host-arch

What are these artifacts? We build the kernel as a standalone system. It's not as if we statically link host glibc into it or something.

There are some scripts/ that are built in the host-arch ABI. These are also put in the archive because they are needed to build modules. So if you cross-compile then the archive will have scripts/ that are in the host arch, not the target arch. This makes it not possible to build modules on the target using the archive. This is not much of an issue because I already proved that such kernel modules can be built using a chroot in this thread:
https://lkml.org/lkml/2019/2/28/1313
And in the non cross-compile case, it will be immensely useful for distros..

Quoted 8 lines
Quoted 1 line
Quoted 1 line

- users do not know which compiler to use

Does that matter much? Do things ever break if the kernel proper is built with GCC x.y.z and we build a module with GCC x.y.(z+1)? Why would it? Structure layout is invariant across compiler version, or at least ought to be. And don't we have exactly the same problem with any kernel headers package? I don't think it'd hurt to include the output of $(CC) --version though.

Apparently there were some issues in some posting where Greg said we don't support anything but modules built with the same compiler as the kernel its being loaded into, even if such modules do work in practice. I don't recall the details, I can dig up that thread if you want. My point is, whether that's an issue or not - it is not an issue introduced by this patch. That's just a module building issue which we neither solve here, nor introduce.

Quoted 2 lines

Like Joel, I'd like to see this change merged. It'll make life easier for a lot of people.

Thanks.

- Joel

#20 lore raw
Quoted 68 lines · Joel Fernandes
Quoted 66 lines · Daniel Colascione
Quoted 65 lines · Joel Fernandes
Quoted 46 lines · Masahiro Yamada
Quoted 37 lines · Joel Fernandes
Quoted 18 lines · Joel Fernandes
Quoted 17 lines · Alexei Starovoitov
Quoted 15 lines · Joel Fernandes (Google)

Introduce in-kernel headers and other artifacts which are made available as an archive through proc (/proc/kheaders.txz file). This archive makes it possible to build kernel modules, run eBPF programs, and other tracing programs that need to extend the kernel for tracing purposes without any dependency on the file system having headers and build artifacts.

On Android and embedded systems, it is common to switch kernels but not have kernel headers available on the file system. Raw kernel headers also cannot be copied into the filesystem like they can be on other distros, due to licensing and other issues. There's no linux-headers package on Android. Further once a different kernel is booted, any headers stored on the file system will no longer be useful. By storing the headers as a compressed archive within the kernel, we can avoid these issues that have been a hindrance for a long time.

Quoted 8 lines
Quoted 3 lines

The set looks good to me and since the main use case is building bpf progs I can route it via bpf-next tree if there are no objections. Masahiro, could you please ack it?

FYI, Masahiro's comments were all address by v5:
https://lore.kernel.org/patchwork/project/lkml/list/?series=387311

I believe aren't more outstanding concerns. Could we consider it for v5.2?

Just to highlight the problem, today I booted v5.0 on an emulated Android device for some testing, that didn't have a set of prebuilt headers that we have been packaging on well known kernels, to get around this issue. This caused great pain and issues with what I was doing. I know me and many others really want this. With this I can boot an emulated Android device with IKCONFIG_PROC=y and run BCC with that that. Also I want to do the BCC side of the development, but first want to know if we can merge this upstream.

Quoted 2 lines

Masahiro, I believe due diligence has been done in solidifying it as posted in the v5. Anything else we need to do here? Are you with the patches?

As you said, these updates are "cosmetic". Nobody is worried about (or interested in) them. Even if we miss something, they are fixable later.

Quoted 7 lines

I accept embedding headers in the kernel,
but I do not like the part about external module build.
- kernel embeds build artifacts that depend on a particular host-arch
- users do not know which compiler to use
Perhaps, you may remember my concerns.
https://lore.kernel.org/patchwork/patch/1046307/#1239501

Masahiro,
I think we already discussed this right. The compiler issue is a user-issue - it is not a problem that has arisen because this patch. Anyone can build a kernel module today without this patch - using a compiler that is different from the running kernel. So I did not fully understand your concern. This patch does not ship a compiler in the archive. The compiler is upto the user based on user environment. They can already shoot themself in foot without this patch.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Greg,
Would be great to get your thoughts here as well about Masami's concern.

Honestly, the "kernel module building artifacts" bit is a bonus with this patch. The main thing we are adding or that we need is really the headers (for BCC).

Yeah, this part looks solid to me.

Quoted 21 lines

I just thought shipping the kernel build artifacts would also be

Quoted 14 lines
Quoted 9 lines

awesome because people can now build kernel modules without needing a kernel tree at all.

But I also want this stuff merged so if folks are really unhappy with the module build artifacts and only want headers - then that's also fine with me and I can yank them - that would also mean though that this work cannot be a replacement for linux-headers package on distros, so that would be sad.

thanks!

IMHO, including the module build stuff is fine, and the stuff that Masahiro mentions doesn't matter much. To be specific about the concerns:

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line

- kernel embeds build artifacts that depend on a

particular host-arch

What are these artifacts? We build the kernel as a standalone system. It's not as if we statically link host glibc into it or something.

Quoted 8 lines

There are some scripts/ that are built in the host-arch ABI. These are also put in the archive because they are needed to build modules. So if you cross-compile then the archive will have scripts/ that are in the host arch, not the target arch. This makes it not possible to build modules on the target using the archive. This is not much of an issue because I already proved that such kernel modules can be built using a chroot in this thread:
https://lkml.org/lkml/2019/2/28/1313
And in the non cross-compile case, it will be immensely useful for distros..

Now the kernel depends on the host-arch that built it. It looks somewhat weird to me.

Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line

- users do not know which compiler to use

Does that matter much? Do things ever break if the kernel proper is built with GCC x.y.z and we build a module with GCC x.y.(z+1)? Why would it? Structure layout is invariant across compiler version, or at least ought to be.

The difference in the minor version
will not be a problem in practice.

The difference in the major version could be a problem.

Difference compilers have a different set of compiler options in general.

In Kbuild Makefiles, unsupported compiler options are disabled by $(call cc-option,...).

So, users may potentially compile external modules wit a slightly different set of flags without noticing that.

It may still work, but some compiler flags insert stubs. There are some cases where compiler flags are sensitive.

For example, if we miss the compiler flag that was given to vmlinux, slightly different code structure may cause kernel panic:
https://bugzilla.kernel.org/show_bug.cgi?id=201891

Quoted 10 lines

And don't we have exactly the same problem with

Quoted 2 lines

any kernel headers package? I don't think it'd hurt to include the output of $(CC) --version though.

Apparently there were some issues in some posting where Greg said we don't support anything but modules built with the same compiler as the kernel its being loaded into, even if such modules do work in practice. I don't recall the details, I can dig up that thread if you want. My point is, whether that's an issue or not - it is not an issue introduced by this patch. That's just a module building issue which we neither solve here, nor introduce.

What I can tell is, distributions provide packages of the compiler, kernel headers, and whatever needed to compile external modules.

I feel this is a double-edged sword.

Quoted 7 lines
Quoted 2 lines

Like Joel, I'd like to see this change merged. It'll make life easier for a lot of people.

Thanks.

- Joel

Signature · 2 lines
Best Regards
Masahiro Yamada