linux: generalize sections, ranges and linker tables
Subsystems (32)
[email protected]
maintainerv4 cover linux: generalize sections, ranges and linker tables
From: "Luis R. Rodriguez" <[email protected]>
This v4 addresses feedback from the previous v3 series [0], and also addresses a huge array of additional tests against many architectures outside of what 0-day provides. As I mentioned in my last v3 series, 0-day had only found one issue with the series, a blackfin architecture linker issue with the last series. Guenter Rock was kind enough to give my series a test spin on his test bed and he found quite a bit of other oddball issues with obscure architectures, and even on x86 with an old toolchain. After a lot of work and coordinating with a few maintainers I'm happy to report all issues found so far through all possible testing I could do are now fixed, this series also addresses all feedback from the last series, as such this goes submitted as PATCH form.
In addressing fixing this work on a few architectures some of the previous patches are further simplified. The kprobes port to linker tables is made much easier now that I've addressed moving out core kprobe declarations into asm-generic/kprobes.h. Refer to the patch "kprobes: move kprobe declarations to asm-generic/kprobes.h". This makes for a much cleaner solution across architectures.
Boris feedback on making the code bit rot feature optional is addressed by using a new Kconfig symbol for this, CONFIG_BUILD_AVOID_BITROT, but given Greg's concerns over lack of clarity over what this was all about I've ripped that functionality out into its own patch with a bit more extensive documentation and re-wording. See the patch "kbuild: enable option to force compile force-obj-y and force-lib-y". I hope makes it clear how linker tables can help with avoiding code bit rot. I've gone with a new Kconfig symbol CONFIG_BUILD_AVOID_BITROT given CONFIG_COMPILE_TEST is not available on UML, this feature is desirable on all architectures.
The documentation is revamped, now that the DocBook format is deprecated I ported the documention into the trendy hipster Sphinx documentation format.
AT Boris' request I've adapated the userspace linker table application forintegration into the kernel under tools/ to make it easier to keep things in sync, however since this requires a bit of changes to some headers in tools/ I'll submit that separately.
[0] https://lkml.kernel.org/r/[email protected]
If you'd like this in git-form, you can get it on the 20160819-linker-table-v4 branch of my linux-next tree on kernel.org, this also includes the series of the linker table userspace sandbox:
https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linux-next.git/log/?h=20160819-linker-table-v4
Please let me know if there are any concerns or questions.
Luis R. Rodriguez (16):
x86: remove LTO_REFERENCE_INITCALL()
dell-smo8800: include uaccess.h scripts/module-common.lds: enable generation
generic-sections: add section core helpers
xtensa: skip adding literal when SORT() is used ranges.h: add helpers to build and identify Linux section ranges tables.h: add linker table support
kbuild: enable option to force compile force-obj-y and force-lib-y firmware/Makefile: force recompilation if makefile changes
firmware: port built-in section to linker table
jump_label: move guard #endif down where it belongs
jump_label: port __jump_table to linker tables
dynamic_debug: port to use linker tables
kprobes: move kprobe declarations to asm-generic/kprobes.h
kprobes: port .kprobes.text to section range
kprobes: port blacklist kprobes to linker table
.gitignore | 2 +
Documentation/index.rst | 1 +
Documentation/kbuild/makefiles.txt | 36 ++
Documentation/sections/conf.py | 4 +
Documentation/sections/index.rst | 13 +
Documentation/sections/linker-tables.rst | 202 +++++++
Documentation/sections/ranges.rst | 49 ++
Documentation/sections/section-core.rst | 153 +++++
MAINTAINERS | 37 ++
Makefile | 6 +-
arch/alpha/include/asm/Kbuild | 4 +
arch/arc/include/asm/Kbuild | 3 +
arch/arc/include/asm/kprobes.h | 6 +-
arch/arc/kernel/vmlinux.lds.S | 1 -
arch/arm/include/asm/Kbuild | 3 +
arch/arm/include/asm/jump_label.h | 6 +-
arch/arm/include/asm/kprobes.h | 4 +
arch/arm/kernel/entry-armv.S | 3 +-
arch/arm/kernel/vmlinux-xip.lds.S | 1 -
arch/arm/kernel/vmlinux.lds.S | 1 -
arch/arm/probes/decode.h | 1 +
arch/arm64/include/asm/Kbuild | 3 +
arch/arm64/include/asm/jump_label.h | 6 +-
arch/arm64/include/asm/kprobes.h | 4 +
arch/arm64/kernel/armv8_deprecated.c | 1 +
arch/arm64/kernel/insn.c | 1 +
arch/arm64/kernel/probes/kprobes.c | 4 +-
arch/arm64/kernel/vmlinux.lds.S | 1 -
arch/avr32/include/asm/Kbuild | 3 +
arch/avr32/include/asm/kprobes.h | 4 +
arch/avr32/kernel/entry-avr32b.S | 13 +-
arch/avr32/kernel/vmlinux.lds.S | 1 -
arch/blackfin/include/asm/Kbuild | 4 +
arch/blackfin/kernel/vmlinux.lds.S | 1 -
arch/c6x/include/asm/Kbuild | 3 +
arch/c6x/include/asm/tables.h | 26 +
arch/c6x/kernel/vmlinux.lds.S | 1 -
arch/cris/include/asm/Kbuild | 4 +
arch/frv/include/asm/Kbuild | 4 +
arch/h8300/include/asm/Kbuild | 4 +
arch/hexagon/include/asm/Kbuild | 4 +
arch/hexagon/kernel/vmlinux.lds.S | 1 -
arch/ia64/include/asm/Kbuild | 3 +
arch/ia64/include/asm/kprobes.h | 7 +-
arch/ia64/kernel/jprobes.S | 3 +-
arch/ia64/kernel/vmlinux.lds.S | 1 -
arch/ia64/lib/flush.S | 6 +-
arch/m32r/include/asm/Kbuild | 4 +
arch/m68k/include/asm/Kbuild | 4 +
arch/metag/include/asm/Kbuild | 4 +
arch/metag/kernel/vmlinux.lds.S | 1 -
arch/microblaze/include/asm/Kbuild | 4 +
arch/microblaze/kernel/vmlinux.lds.S | 1 -
arch/mips/include/asm/Kbuild | 3 +
arch/mips/include/asm/jump_label.h | 6 +-
arch/mips/include/asm/kprobes.h | 6 +-
arch/mips/kernel/vmlinux.lds.S | 1 -
arch/mn10300/include/asm/Kbuild | 3 +
arch/mn10300/include/asm/kprobes.h | 4 +
arch/mn10300/kernel/vmlinux.lds.S | 1 -
arch/nios2/include/asm/Kbuild | 4 +
arch/nios2/kernel/vmlinux.lds.S | 1 -
arch/openrisc/include/asm/Kbuild | 4 +
arch/openrisc/kernel/vmlinux.lds.S | 1 -
arch/parisc/include/asm/Kbuild | 4 +
arch/parisc/kernel/vmlinux.lds.S | 1 -
arch/powerpc/include/asm/Kbuild | 3 +
arch/powerpc/include/asm/jump_label.h | 8 +-
arch/powerpc/include/asm/kprobes.h | 6 +
arch/powerpc/include/asm/ppc_asm.h | 7 +-
arch/powerpc/kernel/vmlinux.lds.S | 1 -
arch/s390/include/asm/Kbuild | 3 +
arch/s390/include/asm/jump_label.h | 6 +-
arch/s390/include/asm/kprobes.h | 4 +
arch/s390/kernel/entry.S | 5 +-
arch/s390/kernel/kprobes.c | 6 +-
arch/s390/kernel/mcount.S | 3 +-
arch/s390/kernel/vmlinux.lds.S | 1 -
arch/score/include/asm/Kbuild | 4 +
arch/score/kernel/vmlinux.lds.S | 1 -
arch/sh/include/asm/Kbuild | 3 +
arch/sh/include/asm/kprobes.h | 2 +
arch/sh/kernel/vmlinux.lds.S | 1 -
arch/sparc/include/asm/Kbuild | 3 +
arch/sparc/include/asm/jump_label.h | 6 +-
arch/sparc/include/asm/kprobes.h | 5 +
arch/sparc/kernel/vmlinux.lds.S | 1 -
arch/sparc/mm/ultra.S | 3 +-
arch/tile/include/asm/Kbuild | 3 +
arch/tile/include/asm/kprobes.h | 6 +-
arch/tile/kernel/vmlinux.lds.S | 1 -
arch/um/include/asm/Kbuild | 4 +
arch/unicore32/include/asm/Kbuild | 3 +
arch/unicore32/include/asm/section-core.h | 19 +
arch/x86/include/asm/Kbuild | 3 +
arch/x86/include/asm/jump_label.h | 10 +-
arch/x86/include/asm/kprobes.h | 6 +
arch/x86/kernel/cpu/microcode/core.c | 8 +-
arch/x86/kernel/kprobes/core.c | 11 +-
arch/x86/kernel/vmlinux.lds.S | 1 -
arch/x86/tools/relocs.c | 4 +
arch/xtensa/include/asm/Kbuild | 4 +
arch/xtensa/kernel/Makefile | 8 +-
drivers/base/firmware_class.c | 12 +-
drivers/platform/x86/dell-smo8800.c | 1 +
firmware/Makefile | 6 +-
include/asm-generic/kprobes.h | 26 +
include/asm-generic/ranges.h | 103 ++++
include/asm-generic/section-core.h | 341 +++++++++++
include/asm-generic/sections.h | 4 +-
include/asm-generic/tables.h | 50 ++
include/asm-generic/vmlinux.lds.h | 73 +--
include/linux/compiler.h | 8 -
include/linux/dynamic_debug.h | 5 +-
include/linux/init.h | 20 +-
include/linux/jump_label.h | 8 +-
include/linux/kprobes.h | 24 +-
include/linux/ranges.h | 128 +++++
include/linux/sections.h | 111 ++++
include/linux/tables.h | 638 +++++++++++++++++++++
init/Kconfig | 22 +
kernel/jump_label.c | 17 +-
kernel/kprobes.c | 17 +-
lib/dynamic_debug.c | 13 +-
scripts/Makefile.build | 7 +-
scripts/Makefile.clean | 2 +
scripts/Makefile.lib | 11 +
scripts/Makefile.modpost | 2 +-
scripts/mod/modpost.c | 2 +-
scripts/{module-common.lds => module-common.lds.S} | 6 +
scripts/recordmcount.c | 2 +-
scripts/recordmcount.pl | 2 +-
tools/objtool/special.c | 2 +-
133 files changed, 2328 insertions(+), 214 deletions(-)
create mode 100644 Documentation/sections/conf.py
create mode 100644 Documentation/sections/index.rst
create mode 100644 Documentation/sections/linker-tables.rst
create mode 100644 Documentation/sections/ranges.rst
create mode 100644 Documentation/sections/section-core.rst
create mode 100644 arch/c6x/include/asm/tables.h
create mode 100644 arch/unicore32/include/asm/section-core.h
create mode 100644 include/asm-generic/kprobes.h
create mode 100644 include/asm-generic/ranges.h
create mode 100644 include/asm-generic/section-core.h
create mode 100644 include/asm-generic/tables.h
create mode 100644 include/linux/ranges.h
create mode 100644 include/linux/sections.h
create mode 100644 include/linux/tables.h
rename scripts/{module-common.lds => module-common.lds.S} (80%)Signature · 1 line
2.9.2
[email protected]
maintainerPATCH v4 1/16 x86: remove LTO_REFERENCE_INITCALL()
From: "Luis R. Rodriguez" <[email protected]>
The setup for LTO never made it upstream, and although this has some users, this is now really old stuff for a gcc 4.7 LTO problem. We know that at least LTO_REFERENCE_INITCALL() work around can be removed if LTO is not supported on v4.7 anymore.
As per Andi the DISABLE_LTO and LTO_CFLAGS are still neeeded though.
v3: added to this series, removing LTO_REFERENCE_INITCALL()
justifies that other future similar macros do not need a respective LTO_REFERENCE_INITCALL() on them therefore simplifying new code.
--- include/linux/init.h | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-)
include/linux/init.h +1 -19
@@ -151,23 +151,6 @@ extern bool initcall_debug;#ifndef __ASSEMBLY__ -#ifdef CONFIG_LTO -/* Work around a LTO gcc problem: when there is no reference to a variable -* in a module it will be moved to the end of the program. This causes -* reordering of initcalls which the kernel does not like. -* Add a dummy reference function to avoid this. The function is -* deleted by the linker. -*/ -#define LTO_REFERENCE_INITCALL(x) \ - ; /* yes this is needed */ \ - static __used __exit void *reference_##x(void) \ - { \ - return &x; \ - } -#else -#define LTO_REFERENCE_INITCALL (x) -#endif -/* initcalls are now grouped by functionality into separate * subsections. Ordering inside the subsections is determined * by link order.
@@ -180,8 +163,7 @@ extern bool initcall_debug;#define __define_initcall (fn, id) \ static initcall_t __initcall_##fn##id __used \ - __attribute__((__section__(".initcall" #id ".init"))) = fn; \ - LTO_REFERENCE_INITCALL(__initcall_##fn##id) + __attribute__((__section__(".initcall" #id ".init"))) = fn;/* * Early initcalls run before initializing SMP.
Signature · 1 line
2.9.2
[email protected]
maintainerPATCH v4 2/16 dell-smo8800: include uaccess.h
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
sections.h is currently included and it provides dell-smo8800 with what it needs, an upcoming change will decouple uaccess.h from sections.h. This driver needs to explicitly require uaccess.h before this change.
v3: new to this series -- needed due to collateral of the split of
old linker tables from tables.h into 3 files: sections.h, ranges.h and tables.h
--- drivers/platform/x86/dell-smo8800.c | 1 + 1 file changed, 1 insertion(+)
drivers/platform/x86/dell-smo8800.c +1 -0
@@ -24,6 +24,7 @@#include <linux/acpi.h> #include <linux/interrupt.h> #include <linux/miscdevice.h> +#include <linux/uaccess.h> struct smo8800_device {u32 irq;/* acpi device irq */
Signature · 7 lines
2.9.2 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
[email protected]
maintainerPATCH v4 3/16 scripts/module-common.lds: enable generation
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
scripts/module-common.lds is currently pretty static, in the future this may change and we will want access to kernel macros to help expands certain areas. To get access to use macros we need to generate module-common.lds from module-common.lds.S, for now though only enable the generation. We'll later expand on this as needed.
Since this file is now generated add it to .gitignore.
v4: add file to MAINTAINERS
v3: new to this series
---
.gitignore | 2 ++
MAINTAINERS | 1 +
Makefile | 6 +++++-
scripts/Makefile.modpost | 2 +-
scripts/{module-common.lds => module-common.lds.S} | 0
5 files changed, 9 insertions(+), 2 deletions(-)
rename scripts/{module-common.lds => module-common.lds.S} (100%).gitignore +2 -0
@@ -114,3 +114,5 @@ all.config # Kdevelop4 *.kdev4 + +scripts/module-common.lds
MAINTAINERS +1 -0
@@ -7887,6 +7887,7 @@ M: Rusty Russell <[email protected]> S: Maintained F: include/linux/module.h F: kernel/module.c +F: scripts/module-common.lds.S MOTION EYE VAIO PICTUREBOOK CAMERA DRIVER W: http://popies.net/meye/
Makefile +5 -1
@@ -408,6 +408,10 @@ KBUILD_AFLAGS_MODULE := -DMODULE KBUILD_CFLAGS_MODULE := -DMODULE KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds +$(srctree)/scripts/module-common.lds: $(srctree)/scripts/module-common.lds.S + $(Q)$(CC) $(CFLAGS) $(INCLUDES) $(LINUXINCLUDE) -E -P \ + -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $< + # Read KERNELRELEASE from include/config/kernel.release (if it exists) KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null) KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
@@ -1174,7 +1178,7 @@ all: modules # using awk while concatenating to the final file. PHONY += modules -modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin +modules: $(srctree)/scripts/module-common.lds $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order @$(kecho) ' Building modules, stage 2.'; $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
scripts/Makefile.modpost +1 -1
@@ -121,7 +121,7 @@ quiet_cmd_ld_ko_o = LD [M] $@ $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ -o $@ $(filter-out FORCE,$^) -$(modules): %.ko :%.o %.mod.o FORCE +$(modules): %.ko : $(srctree)/scripts/module-common.lds %.o %.mod.o FORCE $(call if_changed,ld_ko_o) targets += $(modules)
scripts/module-common.lds.S renamed from scripts/module-common.lds +0 -0
Signature · 7 lines
2.9.2 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
[email protected]
maintainerPATCH v4 4/16 generic-sections: add section core helpers
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
Linux makes extensive use of custom ELF header sections, documentation for these are well scatterred. Unify this documentation in a central place and provide helpers to build custom Linux sections.
This also generalizes sections code to enable avoiding modifying the linker scripts when we want to add new custom Linux sections. In order to make this generally useful we need to ensure all architectures can make use of core section helpers but that they can also override should this be needed. Instead of relying on section.h this adds a sections-core.h since this will be targetted to be safe to be used on asm code, linker scripts and C code.
v4:
o Port to shiny new sphinx documentation format
o fix a unicore32 build, turns out this actually fixes unicore32 defconfig builds which were failing for a long while. unicore32 does not seem to grok well the type passed on a section declaration, this ignores it.
o Use VMLINUX_SYMBOL() in more user symbols (extern C code), not doing this was causing final linker issues with blackfin -- this is a CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX=y architecture. The other one being metatag. metatag is not supported on 0-day so I cannot confirm compilation there.
o Added SECTION_CORE() for C code, used later by __LINUX_RANGE()
o Since SECTION_CORE() is defined for linker script and C code, share the same helper and just use a __stringify() for the C code as is done for the other C helpers.
o move generic sections to asm-generic/section-core.h instead. PowerPC compilation blows up if asm/jump_labels.h gets section.h included, fixing this is not in any way easy. The list of issues are endless. Moving new data to a new simple file resolves this.
o since things are now in asm-generic/section-core.h the guard changes on asm-generic/sections.h and each architecture sections.h are no longer needed
o Give generic sections some maintainer love, that change is Acked-by Arnd Bergmann, Josh and hpa.
o A few checkpatch.pl style fixes
o As suggested by James Hogan use generic-y to copy generic header files on architectures that do not have a sections.h instead of writing a simple file only to include the generic one.
v3:
o add missing sections.h for architectures that did not have it
o move generic sections to asm-generic/sections.h
o add generic asm helpers section_type(), section_type_asmtype(), push_section_type() -- these helpers enable easy use for for later declaring and using of custom linux sections using more standard APIs in both C code, asm code (C asm calls, or asm files), enabling future standardized section types to be more immediately accessible to asm code, not just C code. Note for ASM_CMD_SEP we use by default "\n", architectures needed to override can do so on their own sections.h prior to inclusion of asm-generic/sections.h
--- Documentation/index.rst | 1 + Documentation/sections/conf.py | 4 + Documentation/sections/index.rst | 11 + Documentation/sections/section-core.rst | 153 ++++++++++++++ MAINTAINERS | 14 ++ arch/alpha/include/asm/Kbuild | 1 + arch/arc/include/asm/Kbuild | 1 + arch/arm/include/asm/Kbuild | 1 + arch/arm64/include/asm/Kbuild | 1 + arch/avr32/include/asm/Kbuild | 1 + arch/blackfin/include/asm/Kbuild | 1 + arch/c6x/include/asm/Kbuild | 1 + arch/cris/include/asm/Kbuild | 1 + arch/frv/include/asm/Kbuild | 1 + arch/h8300/include/asm/Kbuild | 1 + arch/hexagon/include/asm/Kbuild | 1 + arch/ia64/include/asm/Kbuild | 1 + arch/m32r/include/asm/Kbuild | 1 + arch/m68k/include/asm/Kbuild | 1 + arch/metag/include/asm/Kbuild | 1 + arch/microblaze/include/asm/Kbuild | 1 + arch/mips/include/asm/Kbuild | 1 + arch/mn10300/include/asm/Kbuild | 1 + arch/nios2/include/asm/Kbuild | 1 + arch/openrisc/include/asm/Kbuild | 1 + arch/parisc/include/asm/Kbuild | 1 + arch/powerpc/include/asm/Kbuild | 1 + arch/s390/include/asm/Kbuild | 1 + arch/score/include/asm/Kbuild | 1 + arch/sh/include/asm/Kbuild | 1 + arch/sparc/include/asm/Kbuild | 1 + arch/tile/include/asm/Kbuild | 1 + arch/um/include/asm/Kbuild | 1 + arch/unicore32/include/asm/section-core.h | 19 ++ arch/x86/include/asm/Kbuild | 1 + arch/xtensa/include/asm/Kbuild | 1 + include/asm-generic/section-core.h | 341 ++++++++++++++++++++++++++++++ include/asm-generic/sections.h | 2 + include/asm-generic/vmlinux.lds.h | 27 +-- include/linux/sections.h | 111 ++++++++++ 40 files changed, 700 insertions(+), 13 deletions(-) create mode 100644 Documentation/sections/conf.py create mode 100644 Documentation/sections/index.rst create mode 100644 Documentation/sections/section-core.rst create mode 100644 arch/unicore32/include/asm/section-core.h create mode 100644 include/asm-generic/section-core.h create mode 100644 include/linux/sections.h
Documentation/index.rst +1 -0
@@ -14,6 +14,7 @@ Contents: kernel-documentation media/index gpu/index + sections/index Indices and tables ==================
Documentation/sections/conf.py new file +4 -0
@@ -0,0 +1,4 @@ +# -*- coding: utf-8; mode: python -*- + +project = 'Linux Kernel ELF sections' +html_search_language = 'en'
Documentation/sections/index.rst new file +11 -0
@@ -0,0 +1,11 @@ +========================= +Linux Kernel ELF sections +========================= + +This book documents the Linux kernel's use of ELF sections, as well as helpers +used throughout the kernel to help declare and define them. + +.. toctree:: + :maxdepth: 4 + + section-core
Documentation/sections/section-core.rst new file +153 -0
153 lines not on this page · raw message
MAINTAINERS +14 -0
@@ -5217,6 +5217,20 @@ S: Supported F: drivers/base/power/domain*.c F: include/linux/pm_domain.h +GENERIC SECTIONS +M: "Luis R. Rodriguez" <[email protected]> +M: Josh Poimboeuf <[email protected]> +M: "H. Peter Anvin" <[email protected]> +L: [email protected] +L: [email protected] +T: git git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git for-arnd +T: git git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux-next.git for-arnd +S: Supported +F: include/asm-generic/section-core.h +F: include/asm-generic/sections.h +F: include/asm-generic/vmlinux.lds.h +F: Documentation/sections/section-core.rst + GENERIC UIO DRIVER FOR PCI DEVICES M: "Michael S. Tsirkin" <[email protected]> L: [email protected]
arch/alpha/include/asm/Kbuild +1 -0
@@ -10,3 +10,4 @@ generic-y += mm-arch-hooks.h generic-y += preempt.h generic-y += sections.h generic-y += trace_clock.h +generic-y += section-core.h
arch/arc/include/asm/Kbuild +1 -0
@@ -50,3 +50,4 @@ generic-y += user.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/arm/include/asm/Kbuild +1 -0
@@ -39,3 +39,4 @@ generic-y += termios.h generic-y += timex.h generic-y += trace_clock.h generic-y += unaligned.h +generic-y += section-core.h
arch/arm64/include/asm/Kbuild +1 -0
@@ -52,3 +52,4 @@ generic-y += unaligned.h generic-y += user.h generic-y += vga.h generic-y += xor.h +generic-y += section-core.h
arch/avr32/include/asm/Kbuild +1 -0
@@ -22,3 +22,4 @@ generic-y += trace_clock.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/blackfin/include/asm/Kbuild +1 -0
@@ -48,3 +48,4 @@ generic-y += unaligned.h generic-y += user.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/c6x/include/asm/Kbuild +1 -0
@@ -62,3 +62,4 @@ generic-y += user.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/cris/include/asm/Kbuild +1 -0
@@ -45,3 +45,4 @@ generic-y += types.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/frv/include/asm/Kbuild +1 -0
@@ -8,3 +8,4 @@ generic-y += mm-arch-hooks.h generic-y += preempt.h generic-y += trace_clock.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/h8300/include/asm/Kbuild +1 -0
@@ -75,3 +75,4 @@ generic-y += unaligned.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/hexagon/include/asm/Kbuild +1 -0
@@ -60,3 +60,4 @@ generic-y += unaligned.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/ia64/include/asm/Kbuild +1 -0
@@ -9,3 +9,4 @@ generic-y += preempt.h generic-y += trace_clock.h generic-y += vtime.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/m32r/include/asm/Kbuild +1 -0
@@ -11,3 +11,4 @@ generic-y += preempt.h generic-y += sections.h generic-y += trace_clock.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/m68k/include/asm/Kbuild +1 -0
@@ -35,3 +35,4 @@ generic-y += trace_clock.h generic-y += types.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/metag/include/asm/Kbuild +1 -0
@@ -56,3 +56,4 @@ generic-y += user.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/microblaze/include/asm/Kbuild +1 -0
@@ -11,3 +11,4 @@ generic-y += preempt.h generic-y += syscalls.h generic-y += trace_clock.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/mips/include/asm/Kbuild +1 -0
@@ -20,3 +20,4 @@ generic-y += trace_clock.h generic-y += user.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/mn10300/include/asm/Kbuild +1 -0
@@ -10,3 +10,4 @@ generic-y += preempt.h generic-y += sections.h generic-y += trace_clock.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/nios2/include/asm/Kbuild +1 -0
@@ -63,3 +63,4 @@ generic-y += user.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/openrisc/include/asm/Kbuild +1 -0
@@ -71,3 +71,4 @@ generic-y += user.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/parisc/include/asm/Kbuild +1 -0
@@ -29,3 +29,4 @@ generic-y += user.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/powerpc/include/asm/Kbuild +1 -0
@@ -7,3 +7,4 @@ generic-y += mcs_spinlock.h generic-y += preempt.h generic-y += rwsem.h generic-y += vtime.h +generic-y += section-core.h
arch/s390/include/asm/Kbuild +1 -0
@@ -8,3 +8,4 @@ generic-y += mm-arch-hooks.h generic-y += preempt.h generic-y += trace_clock.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/score/include/asm/Kbuild +1 -0
@@ -14,3 +14,4 @@ generic-y += trace_clock.h generic-y += xor.h generic-y += serial.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/sh/include/asm/Kbuild +1 -0
@@ -39,3 +39,4 @@ generic-y += termios.h generic-y += trace_clock.h generic-y += ucontext.h generic-y += xor.h +generic-y += section-core.h
arch/sparc/include/asm/Kbuild +1 -0
@@ -22,3 +22,4 @@ generic-y += serial.h generic-y += trace_clock.h generic-y += types.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/tile/include/asm/Kbuild +1 -0
@@ -41,3 +41,4 @@ generic-y += termios.h generic-y += trace_clock.h generic-y += types.h generic-y += xor.h +generic-y += section-core.h
arch/um/include/asm/Kbuild +1 -0
@@ -27,3 +27,4 @@ generic-y += topology.h generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/unicore32/include/asm/section-core.h new file +19 -0
@@ -0,0 +1,19 @@ +#ifndef __UNICORE_SECTION_CORE_ASM_H__ +#define __UNICORE_SECTION_CORE_ASM_H__ +/* +* Copyright (C) 2016 Luis R. Rodriguez <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of copyleft-next (version 0.3.1 or later) as published +* at http://copyleft-next.org/. +*/ + +/* Unicore32 has known to not work properly with the type set, so ignore it */ + +#define __set_section_core_type (___section, ___core, ___name, \ + ___level, ___flags, ___type) \ + .section ___section.___core.___name.___level, ___flags + +#include <asm-generic/section-core.h> + +#endif /* __UNICORE_SECTION_CORE_ASM_H__ */
arch/x86/include/asm/Kbuild +1 -0
@@ -16,3 +16,4 @@ generic-y += dma-contiguous.h generic-y += early_ioremap.h generic-y += mcs_spinlock.h generic-y += mm-arch-hooks.h +generic-y += section-core.h
arch/xtensa/include/asm/Kbuild +1 -0
@@ -31,3 +31,4 @@ generic-y += topology.h generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
include/asm-generic/section-core.h new file +341 -0
341 lines not on this page · raw message
include/asm-generic/sections.h +2 -0
@@ -1,6 +1,8 @@#ifndef _ASM_GENERIC_SECTIONS_H_#define _ASM_GENERIC_SECTIONS_H_ +#include <asm/section-core.h> +/* References to section boundaries */ #include <linux/compiler.h>
include/asm-generic/vmlinux.lds.h +14 -13
@@ -55,6 +55,7 @@#endif #include <linux/export.h> +#include <asm/section-core.h> /* Align . to a 8 byte boundary equals to maximum function alignment. */ #define ALIGN_FUNCTION () . = ALIGN(8)
@@ -198,8 +199,8 @@/* .data section */ #define DATA_DATA \ - *(.data) \ - *(.ref.data) \ + *(SECTION_DATA) \ + *(SECTION_REF_DATA) \ *(.data..shared_aligned)/* percpu related */ \ MEM_KEEP(init.data) \MEM_KEEP (exit.data) \
@@ -262,9 +263,9 @@*/ #define RO_DATA_SECTION (align) \ . = ALIGN((align)); \ - .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \ + SECTION_RODATA : AT(ADDR(SECTION_RODATA) - LOAD_OFFSET) { \ VMLINUX_SYMBOL(__start_rodata) = .; \ - *(.rodata) *(.rodata.*) \ + *(SECTION_RODATA) *(SECTION_ALL(SECTION_RODATA)) \ RO_AFTER_INIT_DATA/* Read only after init */ \ *(__vermagic)/* Kernel version magic */ \ . = ALIGN(8); \
@@ -394,7 +395,7 @@ \/* __*init sections */ \ __init_rodata : AT(ADDR(__init_rodata) - LOAD_OFFSET) { \ - *(.ref.rodata) \ + *(SECTION_REF_RODATA ) \ MEM_KEEP(init.rodata) \MEM_KEEP (exit.rodata) \ } \
@@ -432,8 +433,8 @@* during second ld run in second ld pass when generating System.map */ #define TEXT_TEXT \ ALIGN_FUNCTION(); \ - *(.text.hot .text .text.fixup .text.unlikely) \ - *(.ref.text) \ + *(.text.hot SECTION_TEXT .text.fixup .text.unlikely) \ + *(SECTION_REF) \ MEM_KEEP(init.text) \ MEM_KEEP(exit.text) \
@@ -527,11 +528,11 @@/* init and exit section handling */ #define INIT_DATA \ - *(.init.data) \ + *(SECTION_INIT_DATA) \ MEM_DISCARD(init.data) \ KERNEL_CTORS() \ MCOUNT_REC() \ - *(.init.rodata) \ + *(SECTION_INIT_RODATA) \ FTRACE_EVENTS() \ TRACE_SYSCALLS() \ KPROBE_BLACKLIST() \
@@ -549,24 +550,24 @@ EARLYCON_TABLE()#define INIT_TEXT \ - *(.init.text) \ + *(SECTION_INIT) \ *(.text.startup) \ MEM_DISCARD(init.text)#define EXIT_DATA \ - *(.exit.data) \ + *(SECTION_EXIT_DATA) \ *(.fini_array) \ *(.dtors) \ MEM_DISCARD(exit.data) \ MEM_DISCARD(exit.rodata)#define EXIT_TEXT \ - *(.exit.text) \ + *(SECTION_EXIT) \ *(.text.exit) \ MEM_DISCARD(exit.text)#define EXIT_CALL \ - *(.exitcall.exit) + *(SECTION_EXIT_CALL)/* * bss (Block Started by Symbol) - uninitialized data
include/linux/sections.h new file +111 -0
111 lines not on this page · raw message
Signature · 7 lines
2.9.2 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Nicholas Piggin
reviewerRe: [PATCH v4 04/16] generic-sections: add section core helpers
Quoted 7 lines · On Fri, 19 Aug 2016 14:34:02 -0700 [email protected] wrote:
From: "Luis R. Rodriguez" <[email protected]>
Linux makes extensive use of custom ELF header sections, documentation for these are well scatterred. Unify this documentation in a central place and provide helpers to build custom Linux sections.
Quoted 8 lines
This also generalizes sections code to enable avoiding modifying the linker scripts when we want to add new custom Linux sections. In order to make this generally useful we need to ensure all architectures can make use of core section helpers but that they can also override should this be needed. Instead of relying on
section.hthis adds asections-core.hsince this will be targetted to be safe to be used on asm code, linker scripts and C code.
Hi Luis,
The linker stuff in the kernel definitely needs someone to take care of it, so it's good to see some effort to clean up and generalize some of it.
Not all your patches seem to depend on each other, so it might be good to push some of the cleanups through first. And some of these core patches could go in bit by bit if necessary.
On this specific patch: while the as and ld sections syntax and semantics are pretty ugly and esoteric, I question how much of this is actually an improvement. Some of it seems to just be wrapping one name with another, or hiding some behaviour in a maybe not intuitive way.
Quoted 4 lines
include/asm-generic/section-core.h new file +4
-0+/** +* DOC: Standard ELF section use in Linux +* +* Linux makes use of the standard ELF sections, this sections documents
include/asm-generic/section-core.h line 37
Quoted 10 lines
include/asm-generic/section-core.h new file +10
-0+* these. +*/ + +/** +* DOC: SECTION_RODATA +* +* Macro name for code which must be protected from write access, read only +* data. +*/ +#define SECTION_RODATA .rodata
These, for example. The exact name of the section is important in linker scripts and asm, so I can't see the benefit of hiding it. I could be missing the bigger picture.
include/asm-generic/section-core.h line 47
Quoted 9 lines
include/asm-generic/section-core.h new file +9
-0+/** +* DOC: SECTION_TEXT +* +* Macro name used to annotate code (functions) used during regular +* kernel run time. This is combined with `SECTION_RODATA`, only this +* section also allows for execution. +* +*/ +#define SECTION_TEXT .text
I can't see how these comments are right. .rodata doesn't seem like it should be combined with .text, and is not currently on powerpc. I think it's for data, not code.
include/asm-generic/section-core.h line 195
Quoted 5 lines
include/asm-generic/section-core.h new file +5
-0+/* +* These section _ALL() helpers are for use on linker scripts and helpers +*/ +#define SECTION_ALL (__section) \ + __section##.*
This is another example. We know what .text.* does in the linker scripts -- it's self documenting. But SECTION_ALL(.text)? I'm not sure that's an improvement. Actually I saw it in the linker script changes and had to come find the definition because I was a bit mislead:
SECTION_ALL(.text)
Initially I would expect this to be
.text*
Not
.text.*
The latter does not grab the .text section!
include/asm-generic/section-core.h line 279
Quoted 12 lines
include/asm-generic/section-core.h new file +12
-0+/* +* As per gcc's documentation a common asm separator is a new line followed +* by tab [0], it however seems possible to also just use a newline as its +* the most commonly empirically observed semantic and folks seem to agree +* this even works on S390. In case your architecture disagrees you may +* override this and define your own and keep the rest of the macros. +* +* [0] https://gcc.gnu.org/onlinedocs/gcc/Basic-Asm.html#Basic-Asm +*/ +# ifndef ASM_CMD_SEP +# define ASM_CMD_SEP "\n" +# endif
This does not seem like it belongs here. The name is fairly ugly too. I guess something might be needed like this when dealing with generic as directives common to all architectures, though. I would say include/asm-generic/asm.h should be a better place.
Quoted 19 lines
include/linux/sections.h new file +13
-0@@ -0,0 +1,111 @@ +#ifndef _LINUX_SECTIONS_H +#define _LINUX_SECTIONS_H +/* +* Linux de-facto sections +* +* Copyright (C) 2016 Luis R. Rodriguez <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of copyleft-next (version 0.3.1 or later) as published +* at http://copyleft-next.org/. +*/ + +#include <asm/section-core.h>
include/linux/sections.h line 23
Quoted 10 lines
include/linux/sections.h new file +10
-0+#include <linux/export.h> + +#ifndef __ASSEMBLY__ + +/** +* DOC: Introduction +* +* Linux defines a set of common helpers which can be used to against its use +* of standard or custom Linux sections, this section is dedicated to these +* helpers.
I'm still not quite sure what a Linux de-facto/standard/common section is after this. Are they output sections?
I think it would be reasonable to drop the LINUX_ prefix and references to Linux.
Thanks,
Nick
Luis R. Rodriguez
maintainerRe: [PATCH v4 04/16] generic-sections: add section core helpers
Quoted 12 lines · Nicholas Piggin
Quoted 10 lines · On Fri, 19 Aug 2016 14:34:02 -0700 [email protected] wrote:
include/asm-generic/section-core.h new file +10
-0+/** +* DOC: Standard ELF section use in Linux +* +* Linux makes use of the standard ELF sections, this sections documents +* these. +*/ + +/** +* DOC: SECTION_RODATA +*
Quoted 8 lines
Quoted 4 lines
+ * Macro name for code which must be protected from write access, read only
+ * data.
+ */
+#defineSECTION_RODATA.rodataThese, for example. The exact name of the section is important in linker scripts and asm, so I can't see the benefit of hiding it. I could be missing the bigger picture.
There's two goals by using a macro for these core names. One is to allow us to easily aggregate documentation in central place for each, the second is to then provide more easily grep'able helpers so we can use them when devising extensions or using them in extensions which further customize the sections in the kernel.
Quoted 5 lines
Quoted 5 lines
+/**
+ * DOC:SECTION_TEXT
+ *
+ * Macro name used to annotate code (functions) used during regular
+ * kernel run time. This is combined withSECTION_RODATA, only this
Quoted 8 lines
Quoted 4 lines
+ * section also allows for execution.
+ *
+ */
+#defineSECTION_TEXT.textI can't see how these comments are right. .rodata doesn't seem like it should be combined with .text, and is not currently on powerpc. I think it's for data, not code.
On x86 and powerpc .rodata follows .text. On power currently the comment above in .rodata is:
/* Text, read only data and other permanent read-only sections */
When this was introduced however read commit 14cf11af6cf60 ("powerpc: Merge enough to start building in arch/powerpc.")
/* Read-only sections, merged into text segment: */
The format and style of putting rodata after text is kept from the older commits.
This begs the question. What the hell is this thing talking about?
On Linux this is done via mark_rodata_ro() on init/main.c when CONFIG_DEBUG_RODATA on architectures that support it. Architectures that implement this typically use issues set_memory_ro() -- on x86 a start address used is PFN_ALIGN(_text) with an end address of &__end_rodata_hpage_align.
When architectures do not have CONFIG_DEBUG_RODATA() you end up with:
static inline void mark_readonly(void)
{
pr_warn("This architecture does not have kernel memory protection.\n");
}So -- I should I clarify then in Linux we strive to have helpers adjust text and rodata set to ro with memory protection implemented via mark_readonly(). Architectures that do not support memory protection will lack a mark_readonly() implementation.
For now I figured a less controversial introduction to the documentation as bland as it was above in my original patch would suffice, we can then expand on it with something like the above. Thoughts?
Quoted 15 lines
include/asm-generic/section-core.h line 195
Quoted 5 lines
include/asm-generic/section-core.h new file +5
-0+/* +* These section _ALL() helpers are for use on linker scripts and helpers +*/ +#define SECTION_ALL (__section) \ + __section##.*This is another example. We know what .text.* does in the linker scripts -- it's self documenting. But
SECTION_ALL(.text)? I'm not sure that's an improvement. Actually I saw it in the linker script changes and had to come find the definition because I was a bit mislead:
SECTION_ALL(.text)Initially I would expect this to be
Quoted 7 lines
.text*
Not
.text.*
The latter does not grab the .text section!
Its not intended to grab .text but rather its for helpers that provide customizations based on a core section as base, in this case given your example it would be used by section ranges and linker tables for .text. Both section ranges and linker tables use postfix .something for their customizations. The SECTION_ALL() macro then is a helper for customizations on a core section.
If the name is misleading would SECTION_CORE_ALL() be better with some documentation explaining this and the above goal ?
Quoted 6 lines
Quoted 6 lines
+/*
+ * As per gcc's documentation a common asm separator is a new line followed
+ * by tab [0], it however seems possible to also just use a newline as its
+ * the most commonly empirically observed semantic and folks seem to agree
+ * this even works on S390. In case your architecture disagrees you may
+ * override this and define your own and keep the rest of the macros.
Quoted 8 lines
include/asm-generic/section-core.h line 279
Quoted 6 lines
+ *
+ * [0] https://gcc.gnu.org/onlinedocs/gcc/Basic-Asm.html#Basic-Asm
+ */include/asm-generic/section-core.h new file +3
-0+# ifndef ASM_CMD_SEP +# define ASM_CMD_SEP "\n" +# endif This does not seem like it belongs here. The name is fairly ugly too.
Help me bikeshed, any name suggestions?
Quoted 2 lines
I guess something might be needed like this when dealing with generic as directives common to all architectures, though.
Indeed, it actually seems we don't have much in this area, so this is small baby step in that direction.
Quoted 1 line
I would say
include/asm-generic/asm.hshould be a better place.
I thought about this -- I'd be adding a new asm-generic/asm.h -- are folks OK with that right now? Or should we do that as a secondary step ? I preferred to do this as a secondary step as this series is long enough already and there is quite a bit that can be dumped in a common asm-generic/asm.h, a few thoughts on this already:
o x86's asm/asm.h's use of __ASM_FORM() and include/linux/stringify.h share some traits which deserve possible consideration / rebranding.
o Since C asm() just wrap things in strings defining a core set of helpers for a task seems justifiable, so for example we have __set_section_core_type(). Raw asm code then would use __set_section_core_type() directly and C asm() would just __stringify() it.
I figured a bit of bikeshedding would be possible here, so I decided to leave this for a later set of patches. But indeed, I agree with you. If we want this meshed out now.. let me know and lets bikeshed away...
Quoted 24 lines
Quoted 24 lines
include/linux/sections.h new file +18
-0@@ -0,0 +1,111 @@ +#ifndef _LINUX_SECTIONS_H +#define _LINUX_SECTIONS_H +/* +* Linux de-facto sections +* +* Copyright (C) 2016 Luis R. Rodriguez <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of copyleft-next (version 0.3.1 or later) as published +* at http://copyleft-next.org/. +*/ + +#include <asm/section-core.h> +#include <linux/export.h> + +#ifndef __ASSEMBLY__ + +/**
Quoted 8 lines
include/linux/sections.h line 23
Quoted 5 lines
include/linux/sections.h new file +5
-0+* DOC: Introduction +* +* Linux defines a set of common helpers which can be used to against its use +* of standard or custom Linux sections, this section is dedicated to these +* helpers. I'm still not quite sure what a Linux de-facto/standard/common section is after this. Are they output sections?
We have ELF standard sections, and we have then sections which Linux has introduced over the years which are now just known to be expected part of Linux, such as init stuff which we free after boot. The combination of the ELF standard sections and series of expected sections in Linux across all architectures is what this refers to as Linux de-facto/standard/common sections. The header file is intended to document these, step by step, and also provide helpers which allow further customizations based on these sections.
Quoted 3 lines
I think it would be reasonable to drop the
LINUX_prefix and references to Linux.
I'm not so sure about this for section stuff -- are we certain we won't ever clash with some built in compiler things? I'm fine to drop the prefix -- bikeshedding -- will drop it for the next series unless I hear otherwise...
Luis
Nicholas Piggin
reviewerRe: [PATCH v4 04/16] generic-sections: add section core helpers
Quoted 22 lines · On Tue, 23 Aug 2016 19:33:06 +0200 "Luis R. Rodriguez" <[email protected]>…
Quoted 12 lines · Nicholas Piggin
Quoted 10 lines · On Fri, 19 Aug 2016 14:34:02 -0700 [email protected] wrote:
include/asm-generic/section-core.h new file +10
-0+/** +* DOC: Standard ELF section use in Linux +* +* Linux makes use of the standard ELF sections, this sections documents +* these. +*/ + +/** +* DOC: SECTION_RODATA +* Quoted 8 lines
Quoted 4 lines
+ * Macro name for code which must be protected from write access, read only
+ * data.
+ */
+#defineSECTION_RODATA.rodataThese, for example. The exact name of the section is important in linker scripts and asm, so I can't see the benefit of hiding it. I could be missing the bigger picture.
Quoted 5 lines
There's two goals by using a macro for these core names. One is to allow us to easily aggregate documentation in central place for each, the second is to then provide more easily grep'able helpers so we can use them when devising extensions or using them in extensions which further customize the sections in the kernel.
Documentation is good, but not necessary to have the extra name indirection. Sections tend (not always, but it would be nice if they did) to follow the .name convention, which makes them reasonably easy to grep for. They are also the names you'll be grepping for when you look at disassembly.
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
+/**
+ * DOC:SECTION_TEXT
+ *
+ * Macro name used to annotate code (functions) used during regular
+ * kernel run time. This is combined withSECTION_RODATA, only thisQuoted 8 lines
Quoted 4 lines
+ * section also allows for execution.
+ *
+ */
+#defineSECTION_TEXT.textI can't see how these comments are right. .rodata doesn't seem like it should be combined with .text, and is not currently on powerpc. I think it's for data, not code.
Quoted 1 line
On x86 and powerpc .rodata follows .text.
But follows is not the same as combined. And together with the comment that RODATA is for code (which is wrong, it's data), it make it seem like it is actually combined.
Quoted 22 lines
On power currently the comment
above in .rodata is:/* Text, read only data and other permanent read-only sections */
When this was introduced however read commit
14cf11af6cf60("powerpc: Merge enough to start building inarch/powerpc.")/* Read-only sections, merged into text segment: */
The format and style of putting rodata after text is kept from the older commits.
This begs the question. What the hell is this thing talking about?
On Linux this is done via
mark_rodata_ro()oninit/main.cwhenCONFIG_DEBUG_RODATAon architectures that support it. Architectures that implement this typically use issuesset_memory_ro()-- on x86 a start address used isPFN_ALIGN(_text)with an end address of&__end_rodata_hpage_align.When architectures do not have
CONFIG_DEBUG_RODATA()you end up with:
Quoted 8 lines
static inline void
mark_readonly(void){ pr_warn("This architecture does not have kernel memory protection.\n"); }So -- I should I clarify then in Linux we strive to have helpers adjust text and rodata set to ro with memory protection implemented via
mark_readonly(). Architectures that do not support memory protection will lack amark_readonly()implementation.
Right, I wasn't talking about arch implementation of how the ro protection is done, so much as just the comments being a bit misleading.
Quoted 3 lines
For now I figured a less controversial introduction to the documentation as bland as it was above in my original patch would suffice, we can then expand on it with something like the above. Thoughts?
I think comments are one of the key features of this patch series (or at least this patch, I've not looked through the others so much yet). I'm no expert on linker stuff, but I think a lot of arch maintainers aren't necessarily either so you tend to get a lot of copy and paste without always people knowing what exactly is happening. It would be really good to have some longer explanations and justifications/examples IMO. So I don't think that would be controversial if you wanted to expand on it.
Quoted 21 lines
Quoted 21 lines
include/asm-generic/section-core.h line 195
Quoted 5 lines
include/asm-generic/section-core.h new file +5
-0+/* +* These section _ALL() helpers are for use on linker scripts and helpers +*/ +#define SECTION_ALL (__section) \ + __section##.*This is another example. We know what .text.* does in the linker scripts -- it's self documenting. But
SECTION_ALL(.text)? I'm not sure that's an improvement. Actually I saw it in the linker script changes and had to come find the definition because I was a bit mislead:
SECTION_ALL(.text)Initially I would expect this to be
.text*
Not
.text.*
Quoted 7 lines
Quoted 1 line
The latter does not grab the .text section!
Its not intended to grab .text but rather its for helpers that provide customizations based on a core section as base, in this case given your example it would be used by section ranges and linker tables for .text. Both section ranges and linker tables use postfix .something for their customizations. The
SECTION_ALL()macro then is a helper for customizations on a core section.
Right, it's just that .text.* is *immediately* obvious. SECTION_ALL() is not.
Quoted 2 lines
If the name is misleading would
SECTION_CORE_ALL()be better with some documentation explaining this and the above goal ?
I don't know... not to be glib, but .section.* would be better and not require documentation.
CORE does not really add anything as far as I can see. Other types of .text including ones which are automatically generated by the compiler, for better or worse, are .text.x sections too.
I would like to see more standardisation of naming convention -- some sections start with .., some start with no dots, some use . to separate logical "subsections", others use underscores or something else. I just don't see it would be a problem to simply use the raw names and linker wildcards for it.
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
+/*
+ * As per gcc's documentation a common asm separator is a new line followed
+ * by tab [0], it however seems possible to also just use a newline as its
+ * the most commonly empirically observed semantic and folks seem to agree
+ * this even works on S390. In case your architecture disagrees you may
+ * override this and define your own and keep the rest of the macros.Quoted 8 lines
include/asm-generic/section-core.h line 279
Quoted 6 lines
+ *
+ * [0] https://gcc.gnu.org/onlinedocs/gcc/Basic-Asm.html#Basic-Asm
+ */include/asm-generic/section-core.h new file +3
-0+# ifndef ASM_CMD_SEP +# define ASM_CMD_SEP "\n" +# endif This does not seem like it belongs here. The name is fairly ugly too.
Quoted 1 line
Help me bikeshed, any name suggestions?
BTW, I'm not trying to bikeshed :) This doesn't affect the value of your patch at all, it was just an offhand thing I saw.
Quoted 22 lines
Quoted 3 lines
I guess something might be needed like this when dealing with generic as directives common to all architectures, though.
Indeed, it actually seems we don't have much in this area, so this is small baby step in that direction.
Quoted 1 line
I would say
include/asm-generic/asm.hshould be a better place.I thought about this -- I'd be adding a new
asm-generic/asm.h-- are folks OK with that right now? Or should we do that as a secondary step ? I preferred to do this as a secondary step as this series is long enough already and there is quite a bit that can be dumped in a commonasm-generic/asm.h, a few thoughts on this already:o x86's asm/asm.h's use of
__ASM_FORM()andinclude/linux/stringify.hshare some traits which deserve possible consideration / rebranding.
o Since Casm()just wrap things in strings defining a core set of helpers for a task seems justifiable, so for example we have__set_section_core_type(). Raw asm code then would use__set_section_core_type()directly and Casm()would just__stringify()it.
Quoted 3 lines
I figured a bit of bikeshedding would be possible here, so I decided to leave this for a later set of patches. But indeed, I agree with you. If we want this meshed out now.. let me know and lets bikeshed away...
It's fine, I don't mind too much. I think asm-generic/asm.h should be fine for generic asm'isms though. Or assembler.h to match compiler.h.
Quoted 33 lines
Quoted 24 lines
Quoted 24 lines
include/linux/sections.h new file +18
-0@@ -0,0 +1,111 @@ +#ifndef _LINUX_SECTIONS_H +#define _LINUX_SECTIONS_H +/* +* Linux de-facto sections +* +* Copyright (C) 2016 Luis R. Rodriguez <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of copyleft-next (version 0.3.1 or later) as published +* at http://copyleft-next.org/. +*/ + +#include <asm/section-core.h> +#include <linux/export.h> + +#ifndef __ASSEMBLY__ + +/** Quoted 8 lines
include/linux/sections.h line 23
Quoted 5 lines
include/linux/sections.h new file +5
-0+* DOC: Introduction +* +* Linux defines a set of common helpers which can be used to against its use +* of standard or custom Linux sections, this section is dedicated to these +* helpers. I'm still not quite sure what a Linux de-facto/standard/common section is after this. Are they output sections?
Quoted 7 lines
We have ELF standard sections, and we have then sections which Linux has introduced over the years which are now just known to be expected part of Linux, such as init stuff which we free after boot. The combination of the ELF standard sections and series of expected sections in Linux across all architectures is what this refers to as Linux de-facto/standard/common sections. The header file is intended to document these, step by step, and also provide helpers which allow further customizations based on these sections.
Well but your macros are not linker sections. They are "Linux sections", which appear to give you a start and end symbol name, but does not direct the linker to create a specific output section. I just can't work out what exactly is a "custom Linux section", and what DECLARE_LINUX_SECTION(), for example, actaully gives you.
Thanks,
Nick
Luis R. Rodriguez
maintainerRe: [PATCH v4 04/16] generic-sections: add section core helpers
Quoted 25 lines · Nicholas Piggin
Quoted 22 lines · On Tue, 23 Aug 2016 19:33:06 +0200 "Luis R. Rodriguez" <[email protected]>…
Quoted 20 lines · Nicholas Piggin
Quoted 4 lines · On Fri, 19 Aug 2016 14:34:02 -0700 [email protected] wrote:
include/asm-generic/section-core.h new file +4
-0+/** +* DOC: Standard ELF section use in Linux +* +* Linux makes use of the standard ELF sections, this sections documents include/asm-generic/section-core.h line 37
Quoted 10 lines
include/asm-generic/section-core.h new file +10
-0+* these. +*/ + +/** +* DOC: SECTION_RODATA +* +* Macro name for code which must be protected from write access, read only +* data. +*/ +#define SECTION_RODATA .rodataThese, for example. The exact name of the section is important in linker scripts and asm, so I can't see the benefit of hiding it. I could be missing the bigger picture.
Quoted 5 lines
Quoted 5 lines
There's two goals by using a macro for these core names. One is to allow us to easily aggregate documentation in central place for each, the second is to then provide more easily grep'able helpers so we can use them when devising extensions or using them in extensions which further customize the sections in the kernel.
Just thought of more more justification I had forgotten. I cover it below.
Quoted 1 line
Documentation is good, but not necessary to have the extra name indirection.
Fair point.
Quoted 2 lines
Sections tend (not always, but it would be nice if they did) to follow the .name convention, which makes them reasonably easy to grep for.
git grep .text doesn't work but that is typically expected... git grep \.text doesn't work as expected
Ah finally:
git grep "\.text" seems to work. But WTF.
But:
git grep SECTION_TEXT works as expected immediately.
I guess its a matter of perspective.
Quoted 2 lines
They are also
the names you'll be grepping for when you look at disassembly.
Sure but if you're grepping asm, you very likely know what to look for.
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
include/asm-generic/section-core.h line 47
Quoted 9 lines
include/asm-generic/section-core.h new file +9
-0+/** +* DOC: SECTION_TEXT +* +* Macro name used to annotate code (functions) used during regular +* kernel run time. This is combined with `SECTION_RODATA`, only this +* section also allows for execution. +* +*/ +#define SECTION_TEXT .textI can't see how these comments are right. .rodata doesn't seem like it should be combined with .text, and is not currently on powerpc. I think it's for data, not code.
Quoted 3 lines
Quoted 1 line
On x86 and powerpc .rodata follows .text.
But follows is not the same as combined.
True and as I confirmed below, on PowerPC this is certainly not true.
Quoted 1 line
And together with the comment that RODATA is for code (which is wrong, it's data),
Where did I have that? If you refer to the above SECTION_TEXT documentation, it refers to SECTION_TEXT being for code, but the goal was to highlight that SECTION_TEXT is for execution, while SECTION_RODATA was for data. This certainly can use some love though, thanks, will just drop the SECTION_RODATA reference *or* properly explain the whole thing below.
Quoted 1 line
it make it seem like it is actually combined.
Will fix to ensure this is understood in proper context.
Quoted 27 lines
Quoted 27 lines
On power currently the comment
above in .rodata is:/* Text, read only data and other permanent read-only sections */
When this was introduced however read commit
14cf11af6cf60("powerpc: Merge enough to start building inarch/powerpc.")/* Read-only sections, merged into text segment: */
The format and style of putting rodata after text is kept from the older commits.
This begs the question. What the hell is this thing talking about?
On Linux this is done via
mark_rodata_ro()oninit/main.cwhenCONFIG_DEBUG_RODATAon architectures that support it. Architectures that implement this typically use issuesset_memory_ro()-- on x86 a start address used isPFN_ALIGN(_text)with an end address of&__end_rodata_hpage_align.When architectures do not have
CONFIG_DEBUG_RODATA()you end up with:static inline void
mark_readonly(void){ pr_warn("This architecture does not have kernel memory protection.\n"); }
Quoted 6 lines
Quoted 3 lines
So -- I should I clarify then in Linux we strive to have helpers adjust text and rodata set to ro with memory protection implemented via
mark_readonly(). Architectures that do not support memory protection will lack amark_readonly()implementation.Right, I wasn't talking about arch implementation of how the ro protection is done, so much as just the comments being a bit misleading.
Sure, got it, thanks, will fix.
Quoted 6 lines
Quoted 3 lines
For now I figured a less controversial introduction to the documentation as bland as it was above in my original patch would suffice, we can then expand on it with something like the above. Thoughts?
I think comments are one of the key features of this patch series (or at least this patch, I've not looked through the others so much yet).
Definitely -- the goal was to give us central place to document some of this obscure dark magic only a few witches and warlocks tend to be aware of.
Quoted 4 lines
I'm no
expert on linker stuff, but I think a lot of arch maintainers aren't necessarily either so you tend to get a lot of copy and paste without always people knowing what exactly is happening.
:) Yes indeed, the little crusade over the PowerPC linker script comments on .text and ro data is an example of how easily things can be misleading.
Quoted 3 lines
It would be really good
to have some longer explanations and justifications/examples IMO. So I don't think that would be controversial if you wanted to expand on it.
Sure, but what I was trying to say above is I'd rather have the basic layout of the documentation finalized before we start getting into very specific detailed elaborate details on some of these things. For instance we still haven't decided if we wanted SECTION_TEXT or just require everyone to hard code in .text in every place a user wants to use .text sections. I'd rather settle that before trying to document mark_readonly().
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
include/asm-generic/section-core.h line 195
Quoted 5 lines
include/asm-generic/section-core.h new file +5
-0+/* +* These section _ALL() helpers are for use on linker scripts and helpers +*/ +#define SECTION_ALL (__section) \ + __section##.*This is another example. We know what .text.* does in the linker scripts -- it's self documenting. But
SECTION_ALL(.text)? I'm not sure that's an improvement. Actually I saw it in the linker script changes and had to come find the definition because I was a bit mislead:
SECTION_ALL(.text)Initially I would expect this to be
.text*
Not
.text.*
The latter does not grab the .text section!
Quoted 7 lines
Quoted 5 lines
Its not intended to grab .text but rather its for helpers that provide customizations based on a core section as base, in this case given your example it would be used by section ranges and linker tables for .text. Both section ranges and linker tables use postfix .something for their customizations. The
SECTION_ALL()macro then is a helper for customizations on a core section.Right, it's just that .text.* is *immediately* obvious.
SECTION_ALL()is not.
Which is why I was suggesting perhaps an alternative name.
Quoted 5 lines
Quoted 2 lines
If the name is misleading would
SECTION_CORE_ALL()be better with some documentation explaining this and the above goal ?I don't know... not to be glib, but .section.* would be better and not require documentation.
Well consider the issues below for a second... and keep in mind with linker tables we are about to open the prospect to add more things into the kernel's sections more easily than before.
Quoted 3 lines
CORE does not really add anything as far as I can see. Other types of .text including ones which are automatically generated by the compiler, for better or worse, are .text.x sections too.
Actually, sorry, in this case SECTION_ALL() *was* intended for things that are not linker tables or section ranges, instead this was for globs that want to use the new section macro names, so we only use this for:
*(SECTION_ALL(SECTION_RODATA)) at this time. It would seem we just did not have .text.* and friends (other section names documented here). So this is more of a reaction to provide a way to use a glob for section names if they have a macro name.
The idea was to add helpers to do the globbing more easily.
The glob for sections now documented is SECTION_ALL()
The glob that is range specific is SECTION_RNG_ALL()
The glob that is linker table specific is SECTION_TBL_ALL()
The only one needing SECTION_ALL() it turns out was .rodata:
- *(.rodata) *(.rodata.*) \ + *(SECTION_RODATA) *(SECTION_ALL(SECTION_RODATA)) \
Quoted 3 lines
I would like to see more standardisation of naming convention -- some sections start with .., some start with no dots, some use . to separate logical "subsections", others use underscores or something else.
Agreed... Actually while at it -- anyone happen to know why the two dot thing started creeping up?
Quoted 2 lines
I just don't see it would be a problem to simply use the raw names and linker wildcards for it.
A concern here is more abuse over this if we now expose APIs to users to more easily customize sections. So let's review what the chances are.
$ git grep DEFINE_SECTION_RANGE| egrep -v "tools|include|Document" kernel/kprobes.c:DEFINE_SECTION_RANGE(kprobes, SECTION_TEXT);
These require the actual desired section specified. Do we want to just hide that ? Or are we OK in assuming users willing to use proper names here?
For linker tables we actually provide full helpers for each section type. So we have:
$ git grep DEFINE_LINKTABLE| egrep -v "tools|include|Document" drivers/base/firmware_class.c:DEFINE_LINKTABLE_RO(struct builtin_fw, builtin_fw); kernel/jump_label.c:DEFINE_LINKTABLE(struct jump_entry, __jump_table); kernel/kprobes.c:DEFINE_LINKTABLE_INIT_DATA(unsigned long, _kprobe_blacklist); lib/dynamic_debug.c:DEFINE_LINKTABLE(struct _ddebug, __verbose);
So for linker tables we're safe from abuse as we provide all direct use of the section up to the implementation behind the scenes.
If we're happy then with people using a proper section name for section ranges then I think we can require the full section name being spelled out.
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
include/asm-generic/section-core.h line 279
Quoted 12 lines
include/asm-generic/section-core.h new file +12
-0+/* +* As per gcc's documentation a common asm separator is a new line followed +* by tab [0], it however seems possible to also just use a newline as its +* the most commonly empirically observed semantic and folks seem to agree +* this even works on S390. In case your architecture disagrees you may +* override this and define your own and keep the rest of the macros. +* +* [0] https://gcc.gnu.org/onlinedocs/gcc/Basic-Asm.html#Basic-Asm +*/ +# ifndef ASM_CMD_SEP +# define ASM_CMD_SEP "\n" +# endif This does not seem like it belongs here. The name is fairly ugly too.
Quoted 4 lines
Quoted 1 line
Help me bikeshed, any name suggestions?
BTW, I'm not trying to bikeshed :) This doesn't affect the value of your patch at all, it was just an offhand thing I saw.
Just saying, if you say its ugly please help me with a different name then.
Quoted 21 lines
Quoted 21 lines
Quoted 2 lines
I guess something might be needed like this when dealing with generic as directives common to all architectures, though.
Indeed, it actually seems we don't have much in this area, so this is small baby step in that direction.
Quoted 1 line
I would say
include/asm-generic/asm.hshould be a better place.I thought about this -- I'd be adding a new
asm-generic/asm.h-- are folks OK with that right now? Or should we do that as a secondary step ? I preferred to do this as a secondary step as this series is long enough already and there is quite a bit that can be dumped in a commonasm-generic/asm.h, a few thoughts on this already:o x86's asm/asm.h's use of
__ASM_FORM()andinclude/linux/stringify.hshare some traits which deserve possible consideration / rebranding.
o Since Casm()just wrap things in strings defining a core set of helpers for a task seems justifiable, so for example we have__set_section_core_type(). Raw asm code then would use__set_section_core_type()directly and Casm()would just__stringify()it.
Quoted 6 lines
Quoted 3 lines
I figured a bit of bikeshedding would be possible here, so I decided to leave this for a later set of patches. But indeed, I agree with you. If we want this meshed out now.. let me know and lets bikeshed away...
It's fine, I don't mind too much. I think
asm-generic/asm.hshould be fine for generic asm'isms though. Orassembler.hto matchcompiler.h.
I'd like address this in asm.h but I would hope we can do this as a secondary step, given the length of this patch set already. Thoughts ?
Quoted 42 lines
Quoted 34 lines
Quoted 25 lines
Quoted 25 lines
include/linux/sections.h new file +18
-0@@ -0,0 +1,111 @@ +#ifndef _LINUX_SECTIONS_H +#define _LINUX_SECTIONS_H +/* +* Linux de-facto sections +* +* Copyright (C) 2016 Luis R. Rodriguez <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of copyleft-next (version 0.3.1 or later) as published +* at http://copyleft-next.org/. +*/ + +#include <asm/section-core.h> +#include <linux/export.h> + +#ifndef __ASSEMBLY__ + +/** Quoted 8 lines
include/linux/sections.h line 23
Quoted 5 lines
include/linux/sections.h new file +5
-0+* DOC: Introduction +* +* Linux defines a set of common helpers which can be used to against its use +* of standard or custom Linux sections, this section is dedicated to these +* helpers. I'm still not quite sure what a Linux de-facto/standard/common section is after this. Are they output sections?
Quoted 7 lines
We have ELF standard sections, and we have then sections which Linux has introduced over the years which are now just known to be expected part of Linux, such as init stuff which we free after boot. The combination of the ELF standard sections and series of expected sections in Linux across all architectures is what this refers to as Linux de-facto/standard/common sections. The header file is intended to document these, step by step, and also provide helpers which allow further customizations based on these sections.
Quoted 3 lines
Well but your macros are not linker sections. They are "Linux sections", which appear to give you a start and end symbol name, but does not direct the linker to create a specific output section.
You're right the above can use some love to help explain this better.
How about:
At the top just use "Linux sections helpers"
Then:
/**
* DOC: Introduction
*
* We document below a dedicated set of helpers used in Linux to make sections
* defined in the Linux linker script accessible in C code in a generic form and
* and provide certain attributes about them.
*/
Quoted 3 lines
I just can't work out what exactly is a
"custom Linux section", and whatDECLARE_LINUX_SECTION(), for example, actaully gives you.
Its a way to replace the:
extern char foo[], foo__end[];
So this provides a generalized form to use declarations used in C code to make the linker script start and end symbols from esctions accessible in C code. Since DEFINE_SECTION_RANGE() and DEFINE_LINKTABLE() macros use this, then the DECLARE_LINUX_SECTION() is only needed if you need access to these symbols in C code outside of the one that is defining and mainly in charge of managing the section. We provide DECLARE_*() helpers for section ranges and linker tables though so those can be used instead to help annotate the type of a custom section they are.
So for instance, since the following tables are used in C code outside of the code that implemented and manages them:
mcgrof@ergon ~/linux-next (git::20160822-linker-table-v5)$ git grep DECLARE_LINKTA| egrep -v "Documentation|tools|tables" arch/x86/kernel/cpu/microcode/core.c:DECLARE_LINKTABLE_RO(struct builtin_fw, builtin_fw); include/linux/dynamic_debug.h:DECLARE_LINKTABLE(struct _ddebug, __verbose); include/linux/jump_label.h:DECLARE_LINKTABLE(struct jump_entry, __jump_table); include/linux/kprobes.h:DECLARE_LINKTABLE(unsigned long, _kprobe_blacklist);
Note that the big trick here was to enable users to associate a new custom section in C to a well defined already existing Linux section without modifying the Linux linker script. Then, since as we observe and study uses of how Linux sections are used, we've noticed a pattern -- most declarations of these sections of really of two types, a section ranges or linker table. The patch set then provides generic building blocks for these and ports a few existing custom Linux sections to them as an example.
Luis
Nicholas Piggin
reviewerRe: [PATCH v4 04/16] generic-sections: add section core helpers
Quoted 41 lines · On Wed, 24 Aug 2016 22:12:53 +0200 "Luis R. Rodriguez" <[email protected]>…
Quoted 25 lines · Nicholas Piggin
Quoted 22 lines · On Tue, 23 Aug 2016 19:33:06 +0200 "Luis R. Rodriguez" <[email protected]>…
Quoted 20 lines · Nicholas Piggin
Quoted 4 lines · On Fri, 19 Aug 2016 14:34:02 -0700 [email protected] wrote:
include/asm-generic/section-core.h new file +4
-0+/** +* DOC: Standard ELF section use in Linux +* +* Linux makes use of the standard ELF sections, this sections documents include/asm-generic/section-core.h line 37
Quoted 10 lines
include/asm-generic/section-core.h new file +10
-0+* these. +*/ + +/** +* DOC: SECTION_RODATA +* +* Macro name for code which must be protected from write access, read only +* data. +*/ +#define SECTION_RODATA .rodataThese, for example. The exact name of the section is important in linker scripts and asm, so I can't see the benefit of hiding it. I could be missing the bigger picture.
Quoted 5 lines
Quoted 5 lines
There's two goals by using a macro for these core names. One is to allow us to easily aggregate documentation in central place for each, the second is to then provide more easily grep'able helpers so we can use them when devising extensions or using them in extensions which further customize the sections in the kernel.
Just thought of more more justification I had forgotten. I cover it below.
Quoted 1 line
Documentation is good, but not necessary to have the extra name indirection.
Fair point.
Quoted 2 lines
Sections tend (not always, but it would be nice if they did) to follow the .name convention, which makes them reasonably easy to grep for.
Quoted 6 lines
git grep .text doesn't work but that is typically expected... git grep \.text doesn't work as expected
Ah finally:
git grep "\.text" seems to work. But WTF.
This is simply how grep works though.
Quoted 10 lines
But:
git grep
SECTION_TEXTworks as expected immediately.I guess its a matter of perspective.
Quoted 2 lines
They are also
the names you'll be grepping for when you look at disassembly.Sure but if you're grepping asm, you very likely know what to look for.
After you have gone through the extra layer of naming indirection to work out what it is. I'm still not sold on the name indirection and hiding wildcards. Not just for asm grepping, but I don't think it's a negative thing for devs working on the linker to know what actual section names and commands are being used, as much as possible.
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
include/asm-generic/section-core.h line 47
Quoted 9 lines
include/asm-generic/section-core.h new file +9
-0+/** +* DOC: SECTION_TEXT +* +* Macro name used to annotate code (functions) used during regular +* kernel run time. This is combined with `SECTION_RODATA`, only this +* section also allows for execution. +* +*/ +#define SECTION_TEXT .textI can't see how these comments are right. .rodata doesn't seem like it should be combined with .text, and is not currently on powerpc. I think it's for data, not code.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
On x86 and powerpc .rodata follows .text.
But follows is not the same as combined.
True and as I confirmed below, on PowerPC this is certainly not true.
OK.
Quoted 7 lines
Quoted 1 line
And together with the comment that RODATA is for code (which is wrong, it's data),
Where did I have that? If you refer to the above
SECTION_TEXTdocumentation, it refers toSECTION_TEXTbeing for code, but the goal was to highlight thatSECTION_TEXTis for execution, whileSECTION_RODATAwas for data. This certainly can use some love though, thanks, will just drop theSECTION_RODATAreference *or* properly explain the whole thing below.
+/**
+ * DOC: SECTION_RODATA
+ *
+ * Macro name for code which must be protected from write access, read only
+ * data.
+ */
+#define SECTION_RODATA .rodata
This together with the "combined with .text" part confused me.
Quoted 3 lines
Quoted 1 line
it make it seem like it is actually combined.
Will fix to ensure this is understood in proper context.
Thanks.
Quoted 32 lines
Quoted 7 lines
Quoted 5 lines
Its not intended to grab .text but rather its for helpers that provide customizations based on a core section as base, in this case given your example it would be used by section ranges and linker tables for .text. Both section ranges and linker tables use postfix .something for their customizations. The
SECTION_ALL()macro then is a helper for customizations on a core section.Right, it's just that .text.* is *immediately* obvious.
SECTION_ALL()is not.Which is why I was suggesting perhaps an alternative name.
Quoted 5 lines
Quoted 2 lines
If the name is misleading would
SECTION_CORE_ALL()be better with some documentation explaining this and the above goal ?I don't know... not to be glib, but .section.* would be better and not require documentation.
Well consider the issues below for a second... and keep in mind with linker tables we are about to open the prospect to add more things into the kernel's sections more easily than before.
Quoted 3 lines
CORE does not really add anything as far as I can see. Other types of .text including ones which are automatically generated by the compiler, for better or worse, are .text.x sections too.
Actually, sorry, in this case
SECTION_ALL()*was* intended for things that are not linker tables or section ranges, instead this was for globs that want to use the new section macro names, so we only use this for:
*(SECTION_ALL(SECTION_RODATA)) at this time. It would seem we just did not have .text.* and friends (other section names documented here). So this is more of a reaction to provide a way to use a glob for section names if they have a macro name.
Quoted 5 lines
The idea was to add helpers to do the globbing more easily.
The glob for sections now documented is
SECTION_ALL()
The glob that is range specific isSECTION_RNG_ALL()
The glob that is linker table specific isSECTION_TBL_ALL()
I still don't see this is better than
.text*
.text.*
.text.range.*
.text.table.*
etc.
Quoted 6 lines
The only one needing
SECTION_ALL()it turns out was .rodata:include/asm-generic/vmlinux.lds.h +1
-1- *(.rodata) *(.rodata.*) \ + *(SECTION_RODATA ) *(SECTION_ALL (SECTION_RODATA )) \
Quoted 6 lines
Quoted 3 lines
I would like to see more standardisation of naming convention -- some sections start with .., some start with no dots, some use . to separate logical "subsections", others use underscores or something else.
Agreed... Actually while at it -- anyone happen to know why the two dot thing started creeping up?
I'm not sure, but I suspect it may have been due to . not being a valid C symbol name. I'm not saying it's always the wrong thing to do, but I think copy&paste and lack of documentation has left the naming conventions in need of some love.
The section names themselves of course can and should have some greppable distinguishing conventions -- we don't need macro name for that.
Quoted 6 lines
Quoted 2 lines
I just don't see it would be a problem to simply use the raw names and linker wildcards for it.
A concern here is more abuse over this if we now expose APIs to users to more easily customize sections. So let's review what the chances are.
Quoted 6 lines
$ git grep DEFINE_SECTION_RANGE| egrep -v "tools|include|Document" kernel/kprobes.c:DEFINE_SECTION_RANGE(kprobes, SECTION_TEXT);These require the actual desired section specified. Do we want to just hide that ? Or are we OK in assuming users willing to use proper names here?
For me, DEFINE_SECTION_RANGE(kprobes, .text) would be fine.
Quoted 4 lines
Quoted 2 lines
BTW, I'm not trying to bikeshed :) This doesn't affect the value of your patch at all, it was just an offhand thing I saw.
Just saying, if you say its ugly please help me with a different name then.
Sure, but point taken it's more productive to discuss fundamentals first. Let's consider exact details afterward.
Quoted 5 lines
Quoted 2 lines
It's fine, I don't mind too much. I think
asm-generic/asm.hshould be fine for generic asm'isms though. Orassembler.hto matchcompiler.h.I'd like address this in
asm.hbut I would hope we can do this as a secondary step, given the length of this patch set already. Thoughts ?
It's not a big deal, so whatever suits you. Some of the bugfixes and cleanups could be pushed through various arch and other maintainers first too, which would make the core series look more managable and touch fewer parts.
Quoted 28 lines
Quoted 3 lines
Well but your macros are not linker sections. They are "Linux sections", which appear to give you a start and end symbol name, but does not direct the linker to create a specific output section.
You're right the above can use some love to help explain this better.
How about:
At the top just use "Linux sections helpers"
Then:
/**
* DOC: Introduction
*
* We document below a dedicated set of helpers used in Linux to make sections
* defined in the Linux linker script accessible in C code in a generic form and
* and provide certain attributes about them.
*/Quoted 3 lines
I just can't work out what exactly is a
"custom Linux section", and whatDECLARE_LINUX_SECTION(), for example, actaully gives you.Its a way to replace the:
extern char foo[], foo__end[];
Quoted 8 lines
So this provides a generalized form to use declarations used in C code to make the linker script start and end symbols from esctions accessible in C code. Since
DEFINE_SECTION_RANGE()andDEFINE_LINKTABLE()macros use this, then theDECLARE_LINUX_SECTION()is only needed if you need access to these symbols in C code outside of the one that is defining and mainly in charge of managing the section. We provide DECLARE_*() helpers for section ranges and linker tables though so those can be used instead to help annotate the type of a custom section they are.
Oh, that makes more sense. The SECTION stuff and custom sections was confusing me. I would prefer just to drop all the LINUX_SECTION naming and make it match the functionality you're using. For example:
+DEFINE_LINKTABLE(struct jump_entry, __jump_table);
+
/* mutex to protect coming/going of the the jump_label table */ static DEFINE_MUTEX(jump_label_mutex);
@@ -274,8 +277,6 @@ static void __jump_label_update(struct static_key *key,
void __init jump_label_init(void)
{
- struct jump_entry *iter_start = __start___jump_table;
- struct jump_entry *iter_stop = __stop___jump_table;
struct static_key *key = NULL;
struct jump_entry *iter;
@@ -292,9 +293,10 @@ void __init jump_label_init(void)
return;
jump_label_lock();
- jump_label_sort_entries(iter_start, iter_stop);
+ jump_label_sort_entries(LINUX_SECTION_START(__jump_table),
+ LINUX_SECTION_END(__jump_table));
Now I think this is a fine abstraction to have. I think it would look even cleaner if you had:
LINKTABLE_START(__jump_table)LINKTABLE_END(__jump_table)
Then do we need to even have the LINUX_SECTION middle man at all?
Thanks,
Nick
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Luis R. Rodriguez
maintainerRe: [PATCH v4 04/16] generic-sections: add section core helpers
Quoted 11 lines · Nicholas Piggin
Quoted 9 lines · On Wed, 24 Aug 2016 22:12:53 +0200 "Luis R. Rodriguez" <[email protected]>…
But:
git grep
SECTION_TEXTworks as expected immediately.I guess its a matter of perspective.
Quoted 2 lines
They are also
the names you'll be grepping for when you look at disassembly.
Quoted 7 lines
Quoted 1 line
Sure but if you're grepping asm, you very likely know what to look for.
After you have gone through the extra layer of naming indirection to work out what it is. I'm still not sold on the name indirection and hiding wildcards. Not just for asm grepping, but I don't think it's a negative thing for devs working on the linker to know what actual section names and commands are being used, as much as possible.
OK lets see what it looks like after dropping them. Will try that.
Quoted 6 lines
Quoted 5 lines
The idea was to add helpers to do the globbing more easily.
The glob for sections now documented is
SECTION_ALL()
The glob that is range specific isSECTION_RNG_ALL()
The glob that is linker table specific isSECTION_TBL_ALL()
Quoted 7 lines
I still don't see this is better than
.text*
.text.*
.text.range.*
.text.table.*
etc.
OK will drop it.
Quoted 57 lines
Quoted 22 lines
How about:
At the top just use "Linux sections helpers"
Then:
/**
* DOC: Introduction
*
* We document below a dedicated set of helpers used in Linux to make sections
* defined in the Linux linker script accessible in C code in a generic form and
* and provide certain attributes about them.
*/Quoted 3 lines
I just can't work out what exactly is a
"custom Linux section", and whatDECLARE_LINUX_SECTION(), for example, actaully gives you.Its a way to replace the:
extern char foo[], foo__end[];
Quoted 8 lines
So this provides a generalized form to use declarations used in C code to make the linker script start and end symbols from esctions accessible in C code. Since
DEFINE_SECTION_RANGE()andDEFINE_LINKTABLE()macros use this, then theDECLARE_LINUX_SECTION()is only needed if you need access to these symbols in C code outside of the one that is defining and mainly in charge of managing the section. We provide DECLARE_*() helpers for section ranges and linker tables though so those can be used instead to help annotate the type of a custom section they are.Oh, that makes more sense. The SECTION stuff and custom sections was confusing me. I would prefer just to drop all the
LINUX_SECTIONnaming and make it match the functionality you're using. For example:(quoted diff) +4
-3+DEFINE_LINKTABLE(struct jump_entry, __jump_table); + /* mutex to protect coming/going of the the jump_label table */ static DEFINE_MUTEX(jump_label_mutex);@@ -274,8 +277,6 @@ static void __jump_label_update(struct static_key *key, void __init jump_label_init(void) { - struct jump_entry *iter_start = __start___jump_table; - struct jump_entry *iter_stop = __stop___jump_table; struct static_key *key = NULL; struct jump_entry *iter;@@ -292,9 +293,10 @@ void __init jump_label_init(void) return; jump_label_lock(); - jump_label_sort_entries(iter_start, iter_stop); + jump_label_sort_entries(LINUX_SECTION_START(__jump_table), + LINUX_SECTION_END(__jump_table));
Quoted 1 line
Now I think this is a fine abstraction to have.
OK will keep this one.
Quoted 7 lines
I think it would look
even cleaner if you had:
LINKTABLE_START(__jump_table)LINKTABLE_END(__jump_table)Then do we need to even have the
LINUX_SECTIONmiddle man at all?
Ah, thing is we use this for both linktables and section ranges. Or do we want macros for both that do the same thing ?
Luis
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Nicholas Piggin
reviewerRe: [PATCH v4 04/16] generic-sections: add section core helpers
Quoted 30 lines · On Thu, 25 Aug 2016 08:05:40 +0200 "Luis R. Rodriguez" <[email protected]>…
Quoted 11 lines · Nicholas Piggin
Quoted 9 lines · On Wed, 24 Aug 2016 22:12:53 +0200 "Luis R. Rodriguez" <[email protected]>…
But:
git grep
SECTION_TEXTworks as expected immediately.I guess its a matter of perspective.
Quoted 2 lines
They are also
the names you'll be grepping for when you look at disassembly.Quoted 7 lines
Quoted 1 line
Sure but if you're grepping asm, you very likely know what to look for.
After you have gone through the extra layer of naming indirection to work out what it is. I'm still not sold on the name indirection and hiding wildcards. Not just for asm grepping, but I don't think it's a negative thing for devs working on the linker to know what actual section names and commands are being used, as much as possible.
OK lets see what it looks like after dropping them. Will try that.
Quoted 8 lines
Quoted 5 lines
The idea was to add helpers to do the globbing more easily.
The glob for sections now documented is
SECTION_ALL()
The glob that is range specific isSECTION_RNG_ALL()
The glob that is linker table specific isSECTION_TBL_ALL()I still don't see this is better than
Quoted 7 lines
Quoted 5 lines
.text*
.text.*
.text.range.*
.text.table.*
etc.OK will drop it.
Thank you for considering it, I appreciate that.
Quoted 64 lines
Quoted 57 lines
Quoted 22 lines
How about:
At the top just use "Linux sections helpers"
Then:
/**
* DOC: Introduction
*
* We document below a dedicated set of helpers used in Linux to make sections
* defined in the Linux linker script accessible in C code in a generic form and
* and provide certain attributes about them.
*/Quoted 3 lines
I just can't work out what exactly is a
"custom Linux section", and whatDECLARE_LINUX_SECTION(), for example, actaully gives you.Its a way to replace the:
extern char foo[], foo__end[];
Quoted 8 lines
So this provides a generalized form to use declarations used in C code to make the linker script start and end symbols from esctions accessible in C code. Since
DEFINE_SECTION_RANGE()andDEFINE_LINKTABLE()macros use this, then theDECLARE_LINUX_SECTION()is only needed if you need access to these symbols in C code outside of the one that is defining and mainly in charge of managing the section. We provide DECLARE_*() helpers for section ranges and linker tables though so those can be used instead to help annotate the type of a custom section they are.Oh, that makes more sense. The SECTION stuff and custom sections was confusing me. I would prefer just to drop all the
LINUX_SECTIONnaming and make it match the functionality you're using. For example:(quoted diff) +4
-3+DEFINE_LINKTABLE(struct jump_entry, __jump_table); + /* mutex to protect coming/going of the the jump_label table */ static DEFINE_MUTEX(jump_label_mutex);@@ -274,8 +277,6 @@ static void __jump_label_update(struct static_key *key, void __init jump_label_init(void) { - struct jump_entry *iter_start = __start___jump_table; - struct jump_entry *iter_stop = __stop___jump_table; struct static_key *key = NULL; struct jump_entry *iter;@@ -292,9 +293,10 @@ void __init jump_label_init(void) return; jump_label_lock(); - jump_label_sort_entries(iter_start, iter_stop); + jump_label_sort_entries(LINUX_SECTION_START(__jump_table), + LINUX_SECTION_END(__jump_table));Quoted 1 line
Now I think this is a fine abstraction to have.
OK will keep this one.
Quoted 3 lines
I think it would look
even cleaner if you had:
Quoted 7 lines
Quoted 4 lines
LINKTABLE_START(__jump_table)LINKTABLE_END(__jump_table)Then do we need to even have the
LINUX_SECTIONmiddle man at all?Ah, thing is we use this for both linktables and section ranges. Or do we want macros for both that do the same thing ?
I think it would make the code using it more readable.
Thanks,
Nick
Luis R. Rodriguez
maintainerRe: [PATCH v4 04/16] generic-sections: add section core helpers
Quoted 38 lines · Nicholas Piggin
Quoted 36 lines · On Thu, 25 Aug 2016 08:05:40 +0200 "Luis R. Rodriguez" <[email protected]>…
Quoted 26 lines
Oh, that makes more sense. The SECTION stuff and custom sections was confusing me. I would prefer just to drop all the
LINUX_SECTIONnaming and make it match the functionality you're using. For example:(quoted diff) +4
-3+DEFINE_LINKTABLE(struct jump_entry, __jump_table); + /* mutex to protect coming/going of the the jump_label table */ static DEFINE_MUTEX(jump_label_mutex);@@ -274,8 +277,6 @@ static void __jump_label_update(struct static_key *key, void __init jump_label_init(void) { - struct jump_entry *iter_start = __start___jump_table; - struct jump_entry *iter_stop = __stop___jump_table; struct static_key *key = NULL; struct jump_entry *iter;@@ -292,9 +293,10 @@ void __init jump_label_init(void) return; jump_label_lock(); - jump_label_sort_entries(iter_start, iter_stop); + jump_label_sort_entries(LINUX_SECTION_START(__jump_table), + LINUX_SECTION_END(__jump_table));Quoted 1 line
Now I think this is a fine abstraction to have.
OK will keep this one.
Quoted 6 lines
I think it would look
even cleaner if you had:
LINKTABLE_START(__jump_table)LINKTABLE_END(__jump_table)
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Then do we need to even have the
LINUX_SECTIONmiddle man at all?Ah, thing is we use this for both linktables and section ranges. Or do we want macros for both that do the same thing ?
I think it would make the code using it more readable.
Alrighty... so:
LINKTABLE_START()LINKTABLE_END()
SECTION_RANGE_START()SECTION_RANGE_END()
And these macros do the exact same thing. Ie, nothing shared. Right?
Luis
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Nicholas Piggin
reviewerRe: [PATCH v4 04/16] generic-sections: add section core helpers
Quoted 48 lines · On Thu, 25 Aug 2016 19:52:39 +0200 "Luis R. Rodriguez" <[email protected]>…
Quoted 38 lines · Nicholas Piggin
Quoted 36 lines · On Thu, 25 Aug 2016 08:05:40 +0200 "Luis R. Rodriguez" <[email protected]>…
Quoted 26 lines
Oh, that makes more sense. The SECTION stuff and custom sections was confusing me. I would prefer just to drop all the
LINUX_SECTIONnaming and make it match the functionality you're using. For example:(quoted diff) +4
-3+DEFINE_LINKTABLE(struct jump_entry, __jump_table); + /* mutex to protect coming/going of the the jump_label table */ static DEFINE_MUTEX(jump_label_mutex);@@ -274,8 +277,6 @@ static void __jump_label_update(struct static_key *key, void __init jump_label_init(void) { - struct jump_entry *iter_start = __start___jump_table; - struct jump_entry *iter_stop = __stop___jump_table; struct static_key *key = NULL; struct jump_entry *iter;@@ -292,9 +293,10 @@ void __init jump_label_init(void) return; jump_label_lock(); - jump_label_sort_entries(iter_start, iter_stop); + jump_label_sort_entries(LINUX_SECTION_START(__jump_table), + LINUX_SECTION_END(__jump_table));Quoted 1 line
Now I think this is a fine abstraction to have.
OK will keep this one.
Quoted 6 lines
I think it would look
even cleaner if you had:
LINKTABLE_START(__jump_table)LINKTABLE_END(__jump_table)Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Then do we need to even have the
LINUX_SECTIONmiddle man at all?Ah, thing is we use this for both linktables and section ranges. Or do we want macros for both that do the same thing ?
I think it would make the code using it more readable.
Alrighty... so:
Quoted 7 lines
LINKTABLE_START()LINKTABLE_END()
SECTION_RANGE_START()SECTION_RANGE_END()And these macros do the exact same thing. Ie, nothing shared. Right?
Yeah I think so. Internally they would probably be aliased to the same common definition (unless you had some type check or something), but user would know about such details.
Thanks,
Nick
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Luis R. Rodriguez
maintainerRe: [PATCH v4 04/16] generic-sections: add section core helpers
Quoted 8 lines · Nicholas Piggin
Quoted 4 lines · On Thu, 25 Aug 2016 19:52:39 +0200 "Luis R. Rodriguez" <[email protected]>…
Quoted 3 lines · Nicholas Piggin
Quoted 1 line · On Thu, 25 Aug 2016 08:05:40 +0200 "Luis R. Rodriguez" <[email protected]>…
Quoted 1 line
Oh, that makes more sense. The SECTION stuff and custom sections
was
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
confusing me. I would prefer just to drop all the
LINUX_SECTION
naming
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Review static void __jump_label_update(struct
Quoted 8 lines
and make it match the functionality you're using. For example:
(quoted diff) +2
-0+DEFINE_LINKTABLE(struct jump_entry, __jump_table); + /* mutex to protect coming/going of the the jump_label table */ static DEFINE_MUTEX(jump_label_mutex);@@ -274,8 +277,6 @@ static void __jump_label_update(struct
static_key *key,
Quoted 38 lines
Quoted 38 lines
Quoted 26 lines
Quoted 26 lines
Quoted 16 lines
(quoted diff) +2
-3void __init jump_label_init(void) { - struct jump_entry *iter_start = __start___jump_table; - struct jump_entry *iter_stop = __stop___jump_table; struct static_key *key = NULL; struct jump_entry *iter;@@ -292,9 +293,10 @@ void __init jump_label_init(void) return; jump_label_lock(); - jump_label_sort_entries(iter_start, iter_stop); + jump_label_sort_entries(LINUX_SECTION_START(__jump_table), + LINUX_SECTION_END(__jump_table));Quoted 1 line
Now I think this is a fine abstraction to have.
OK will keep this one.
Quoted 6 lines
I think it would look
even cleaner if you had:
LINKTABLE_START(__jump_table)LINKTABLE_END(__jump_table)Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Then do we need to even have the
LINUX_SECTIONmiddle man at all?Ah, thing is we use this for both linktables and section ranges. Or do we want macros for both that do the same thing ?
I think it would make the code using it more readable.
Alrighty... so:
LINKTABLE_START()LINKTABLE_END()
Quoted 8 lines
Quoted 4 lines
SECTION_RANGE_START()SECTION_RANGE_END()And these macros do the exact same thing. Ie, nothing shared. Right?
Yeah I think so. Internally they would probably be aliased to the same common definition (unless you had some type check or something), but user would know about such details.
What name should we use for such common macro definition ?
Luis
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Nicholas Piggin
reviewerRe: [PATCH v4 04/16] generic-sections: add section core helpers
Quoted 62 lines · On Thu, 25 Aug 2016 23:38:44 -0700 "Luis R. Rodriguez" <[email protected]>…
Quoted 8 lines · Nicholas Piggin
Quoted 4 lines · On Thu, 25 Aug 2016 19:52:39 +0200 "Luis R. Rodriguez" <[email protected]>…
Quoted 3 lines · Nicholas Piggin
Quoted 1 line · On Thu, 25 Aug 2016 08:05:40 +0200 "Luis R. Rodriguez" <[email protected]>…
Quoted 1 line
Oh, that makes more sense. The SECTION stuff and custom sections
was
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
confusing me. I would prefer just to drop all the
LINUX_SECTIONnaming
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Review static void __jump_label_update(struct
Quoted 8 lines
and make it match the functionality you're using. For example:
(quoted diff) +2
-0+DEFINE_LINKTABLE(struct jump_entry, __jump_table); + /* mutex to protect coming/going of the the jump_label table */ static DEFINE_MUTEX(jump_label_mutex);@@ -274,8 +277,6 @@ static void __jump_label_update(struct
static_key*key,Quoted 41 lines
Quoted 41 lines
Quoted 26 lines
Quoted 26 lines
Quoted 16 lines
(quoted diff) +2
-3void __init jump_label_init(void) { - struct jump_entry *iter_start = __start___jump_table; - struct jump_entry *iter_stop = __stop___jump_table; struct static_key *key = NULL; struct jump_entry *iter;@@ -292,9 +293,10 @@ void __init jump_label_init(void) return; jump_label_lock(); - jump_label_sort_entries(iter_start, iter_stop); + jump_label_sort_entries(LINUX_SECTION_START(__jump_table), + LINUX_SECTION_END(__jump_table));Quoted 1 line
Now I think this is a fine abstraction to have.
OK will keep this one.
Quoted 6 lines
I think it would look
even cleaner if you had:
LINKTABLE_START(__jump_table)LINKTABLE_END(__jump_table)Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Then do we need to even have the
LINUX_SECTIONmiddle man at all?Ah, thing is we use this for both linktables and section ranges. Or do we want macros for both that do the same thing ?
I think it would make the code using it more readable.
Alrighty... so:
LINKTABLE_START()LINKTABLE_END()
SECTION_RANGE_START()SECTION_RANGE_END()
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
And these macros do the exact same thing. Ie, nothing shared. Right?
Yeah I think so. Internally they would probably be aliased to the same common definition (unless you had some type check or something), but user would know about such details.
What name should we use for such common macro definition ?
Ah, not really sure. I guess the "link table" is some kind of section range? I haven't actually looked closely at both of them in the subsequent patches. It matters less if it's not expected to be used as an API though.
Luis R. Rodriguez
maintainerRe: [PATCH v4 04/16] generic-sections: add section core helpers
Quoted 21 lines · Nicholas Piggin
Quoted 19 lines · On Thu, 25 Aug 2016 23:38:44 -0700 "Luis R. Rodriguez" <[email protected]>…
Quoted 18 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Ah, thing is we use this for both linktables and section ranges. Or do we want macros for both that do the same thing ?
I think it would make the code using it more readable.
Alrighty... so:
Quoted 7 lines
LINKTABLE_START()LINKTABLE_END()
SECTION_RANGE_START()SECTION_RANGE_END()And these macros do the exact same thing. Ie, nothing shared. Right?
Yeah I think so. Internally they would probably be aliased to the same common definition (unless you had some type check or something), but user would know about such details.
Quoted 8 lines
Quoted 1 line
What name should we use for such common macro definition ?
Ah, not really sure. I guess the "link table" is some kind of section range? I haven't actually looked closely at both of them in the subsequent patches. It matters less if it's not expected to be used as an API though.
OK well, going with LINUX_SECTION_START() so we'll have:
#define LINKTABLE_START LINUX_SECTION_START
#define LINKTABLE_END LINUX_SECTION_END
#define SECTION_RANGE_START LINUX_SECTION_START
#define SECTION_RANGE_END LINUX_SECTION_END
Is that OK?
Luis
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Nicholas Piggin
reviewerRe: [PATCH v4 04/16] generic-sections: add section core helpers
Quoted 33 lines · On Fri, 26 Aug 2016 15:22:19 +0200 "Luis R. Rodriguez" <[email protected]>…
Quoted 21 lines · Nicholas Piggin
Quoted 19 lines · On Thu, 25 Aug 2016 23:38:44 -0700 "Luis R. Rodriguez" <[email protected]>…
Quoted 18 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Ah, thing is we use this for both linktables and section ranges. Or do we want macros for both that do the same thing ?
I think it would make the code using it more readable.
Alrighty... so:
Quoted 7 lines
LINKTABLE_START()LINKTABLE_END()
SECTION_RANGE_START()SECTION_RANGE_END()And these macros do the exact same thing. Ie, nothing shared. Right?
Yeah I think so. Internally they would probably be aliased to the same common definition (unless you had some type check or something), but user would know about such details.
Quoted 8 lines
Quoted 1 line
What name should we use for such common macro definition ?
Ah, not really sure. I guess the "link table" is some kind of section range? I haven't actually looked closely at both of them in the subsequent patches. It matters less if it's not expected to be used as an API though.
OK well, going with
LINUX_SECTION_START()so we'll have:
Quoted 7 lines
#define
LINKTABLE_STARTLINUX_SECTION_START
#defineLINKTABLE_ENDLINUX_SECTION_END#define
SECTION_RANGE_STARTLINUX_SECTION_START
#defineSECTION_RANGE_ENDLINUX_SECTION_ENDIs that OK?
I guess so, without having seen the updated, although I don't see why you'd not just
#define LINKTABLE_START SECTION_RANGE_START
[email protected]
maintainerPATCH v4 5/16 xtensa: skip adding literal when SORT() is used
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
When SORT(foo.*) is used the current sed replacements add SORT(foo.literal foo.*), this breaks linking. Avoid adding literals for SORT globs, if needed, these need to be added manually.
--- arch/xtensa/kernel/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/xtensa/kernel/Makefile +4 -4
@@ -29,10 +29,10 @@ AFLAGS_mxhead.o += -mtext-section-literals # # Replicate rules in scripts/Makefile.build -sed-y = -e ':a; s/\*(\([^)]*\)\.text\.unlikely/*(\1.literal.unlikely .{text}.unlikely/; ta; ' \ - -e ':b; s/\*(\([^)]*\)\.text\(\.[a-z]*\)/*(\1.{text}\2.literal .{text}\2/; tb; ' \ - -e ':c; s/\*(\([^)]*\)\(\.[a-z]*it\|\.ref\)\.text/*(\1\2.literal \2.{text}/; tc; ' \ - -e ':d; s/\*(\([^)]\+ \|\)\.text/*(\1.literal .{text}/; td; ' \ +sed-y = -e ':a; s/\*(\([^)SORT]*\)\.text\.unlikely/*(\1.literal.unlikely .{text}.unlikely/; ta; ' \ + -e ':b; s/\*(\([^)SORT]*\)\.text\(\.[a-z]*\)/*(\1.{text}\2.literal .{text}\2/; tb; ' \ + -e ':c; s/\*(\([^SORT)]*\)\(\.[a-z]*it\|\.ref\)\.text/*(\1\2.literal \2.{text}/; tc; ' \ + -e ':d; s/\*(\([^SORT)]\+ \|\)\.text/*(\1.literal .{text}/; td; ' \ -e 's/\.{text}/.text/g' quiet_cmd__cpp_lds_S = LDS $@
Signature · 7 lines
2.9.2 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
[email protected]
maintainerPATCH v4 6/16 ranges.h: add helpers to build and identify Linux section ranges
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
Section ranges are on one of the types of custom sections types used in Linux. This provides a series of helpers for defining them and using them. Most importantly this also enables us to avoid modifying the linker script when we add a new section range.
It turns out a lot of custom sections are actually section ranges, and these are typically spelled out in their architecture specific asm/sections.h file -- we anable architectures to override what asm is used for section ranges but start by default trusting the asm-generic version all around.
v4:
o tons of documentation love
o fix arch/x86/tools/relocs.c typo - which caused compilation issues on old toolchains
o port to new shiny sphinx documentation
o sprinkle a few more needed VMLINUX_SYMBOL() - fixes compilation on blackfin
o name changes as suggested by Boris:
- %s/SECTION_TYPE_RANGES/rng/g
- %s/SECTION_TYPE/SECTION_CORE/g
- %s/section_type_asmtype/section_core_type/g
- %s/section_type/section_core/g
- %s/section_rng/set_section_rng/g
- rebrand DECLARE_SECTION_RNG() as DEFINE_SECTION_RANGE() - this is the asm version of the respective C version, this will have a userspace C demo added later.
o move __LINUX_RANGE() and __LINUX_RANGE_ORDER() - fixes builds on sparc
o adds section ranges to linker script
o rename SECTION_RANGE_ALL()
o use default alignment, fixes builds on powerpc and arm for both __LINUX_RANGE() and __LINUX_RANGE_ORDER()
o expand documentation to document modules support
o add maintainers
o use generic-y
v3: new in this series, uses copyleft-next
--- Documentation/sections/index.rst | 1 + Documentation/sections/ranges.rst | 49 ++++++++++++++ MAINTAINERS | 10 +++ arch/alpha/include/asm/Kbuild | 1 + arch/arc/include/asm/Kbuild | 1 + arch/arm/include/asm/Kbuild | 1 + arch/arm64/include/asm/Kbuild | 1 + arch/avr32/include/asm/Kbuild | 1 + arch/blackfin/include/asm/Kbuild | 1 + arch/c6x/include/asm/Kbuild | 1 + arch/cris/include/asm/Kbuild | 1 + arch/frv/include/asm/Kbuild | 1 + arch/h8300/include/asm/Kbuild | 1 + arch/hexagon/include/asm/Kbuild | 1 + arch/ia64/include/asm/Kbuild | 1 + arch/m32r/include/asm/Kbuild | 1 + arch/m68k/include/asm/Kbuild | 1 + arch/metag/include/asm/Kbuild | 1 + arch/microblaze/include/asm/Kbuild | 1 + arch/mips/include/asm/Kbuild | 1 + arch/mn10300/include/asm/Kbuild | 1 + arch/nios2/include/asm/Kbuild | 1 + arch/openrisc/include/asm/Kbuild | 1 + arch/parisc/include/asm/Kbuild | 1 + arch/powerpc/include/asm/Kbuild | 1 + arch/s390/include/asm/Kbuild | 1 + arch/score/include/asm/Kbuild | 1 + arch/sh/include/asm/Kbuild | 1 + arch/sparc/include/asm/Kbuild | 1 + arch/tile/include/asm/Kbuild | 1 + arch/um/include/asm/Kbuild | 1 + arch/unicore32/include/asm/Kbuild | 1 + arch/x86/include/asm/Kbuild | 1 + arch/x86/tools/relocs.c | 2 + arch/xtensa/include/asm/Kbuild | 1 + include/asm-generic/ranges.h | 89 ++++++++++++++++++++++++++ include/asm-generic/vmlinux.lds.h | 12 +++- include/linux/ranges.h | 128 +++++++++++++++++++++++++++++++++++++ 38 files changed, 320 insertions(+), 2 deletions(-) create mode 100644 Documentation/sections/ranges.rst create mode 100644 include/asm-generic/ranges.h create mode 100644 include/linux/ranges.h
Documentation/sections/index.rst +1 -0
@@ -9,3 +9,4 @@ used throughout the kernel to help declare and define them. :maxdepth: 4 section-core + ranges
Documentation/sections/ranges.rst new file +49 -0
49 lines not on this page · raw message
MAINTAINERS +10 -0
@@ -5217,6 +5217,16 @@ S: Supported F: drivers/base/power/domain*.c F: include/linux/pm_domain.h +GENERIC SECTION RANGES +M: "Luis R. Rodriguez" <[email protected]> +M: "H. Peter Anvin" <[email protected]> +L: [email protected] +L: [email protected] +S: Supported +F: include/asm-generic/ranges.h +F: include/linux/ranges.h +F: Documentation/sections/ranges.rst + GENERIC SECTIONS M: "Luis R. Rodriguez" <[email protected]> M: Josh Poimboeuf <[email protected]>
arch/alpha/include/asm/Kbuild +1 -0
@@ -11,3 +11,4 @@ generic-y += preempt.h generic-y += sections.h generic-y += trace_clock.h generic-y += section-core.h +generic-y += ranges.h
arch/arc/include/asm/Kbuild +1 -0
@@ -51,3 +51,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/arm/include/asm/Kbuild +1 -0
@@ -40,3 +40,4 @@ generic-y += timex.h generic-y += trace_clock.h generic-y += unaligned.h generic-y += section-core.h +generic-y += ranges.h
arch/arm64/include/asm/Kbuild +1 -0
@@ -53,3 +53,4 @@ generic-y += user.h generic-y += vga.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/avr32/include/asm/Kbuild +1 -0
@@ -23,3 +23,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/blackfin/include/asm/Kbuild +1 -0
@@ -49,3 +49,4 @@ generic-y += user.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/c6x/include/asm/Kbuild +1 -0
@@ -63,3 +63,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/cris/include/asm/Kbuild +1 -0
@@ -46,3 +46,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/frv/include/asm/Kbuild +1 -0
@@ -9,3 +9,4 @@ generic-y += preempt.h generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/h8300/include/asm/Kbuild +1 -0
@@ -76,3 +76,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/hexagon/include/asm/Kbuild +1 -0
@@ -61,3 +61,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/ia64/include/asm/Kbuild +1 -0
@@ -10,3 +10,4 @@ generic-y += trace_clock.h generic-y += vtime.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/m32r/include/asm/Kbuild +1 -0
@@ -12,3 +12,4 @@ generic-y += sections.h generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/m68k/include/asm/Kbuild +1 -0
@@ -36,3 +36,4 @@ generic-y += types.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/metag/include/asm/Kbuild +1 -0
@@ -57,3 +57,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/microblaze/include/asm/Kbuild +1 -0
@@ -12,3 +12,4 @@ generic-y += syscalls.h generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/mips/include/asm/Kbuild +1 -0
@@ -21,3 +21,4 @@ generic-y += user.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/mn10300/include/asm/Kbuild +1 -0
@@ -11,3 +11,4 @@ generic-y += sections.h generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/nios2/include/asm/Kbuild +1 -0
@@ -64,3 +64,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/openrisc/include/asm/Kbuild +1 -0
@@ -72,3 +72,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/parisc/include/asm/Kbuild +1 -0
@@ -30,3 +30,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/powerpc/include/asm/Kbuild +1 -0
@@ -8,3 +8,4 @@ generic-y += preempt.h generic-y += rwsem.h generic-y += vtime.h generic-y += section-core.h +generic-y += ranges.h
arch/s390/include/asm/Kbuild +1 -0
@@ -9,3 +9,4 @@ generic-y += preempt.h generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/score/include/asm/Kbuild +1 -0
@@ -15,3 +15,4 @@ generic-y += xor.h generic-y += serial.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/sh/include/asm/Kbuild +1 -0
@@ -40,3 +40,4 @@ generic-y += trace_clock.h generic-y += ucontext.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/sparc/include/asm/Kbuild +1 -0
@@ -23,3 +23,4 @@ generic-y += trace_clock.h generic-y += types.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/tile/include/asm/Kbuild +1 -0
@@ -42,3 +42,4 @@ generic-y += trace_clock.h generic-y += types.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/um/include/asm/Kbuild +1 -0
@@ -28,3 +28,4 @@ generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/unicore32/include/asm/Kbuild +1 -0
@@ -64,3 +64,4 @@ generic-y += user.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += ranges.h
arch/x86/include/asm/Kbuild +1 -0
@@ -17,3 +17,4 @@ generic-y += early_ioremap.h generic-y += mcs_spinlock.h generic-y += mm-arch-hooks.h generic-y += section-core.h +generic-y += ranges.h
arch/x86/tools/relocs.c +2 -0
@@ -68,6 +68,8 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = {"__end_rodata|" "__initramfs_start|" "(jiffies|jiffies_64)|" +".rodata.rng.*|" + ".init.text.rng.*|"#if ELF_BITS ==64 "__per_cpu_load|" "init_per_cpu__.*|"
arch/xtensa/include/asm/Kbuild +1 -0
@@ -32,3 +32,4 @@ generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
include/asm-generic/ranges.h new file +89 -0
89 lines not on this page · raw message
include/asm-generic/vmlinux.lds.h +10 -2
@@ -56,6 +56,7 @@#include <linux/export.h> #include <asm/section-core.h> +#include <asm/ranges.h> /* Align . to a 8 byte boundary equals to maximum function alignment. */ #define ALIGN_FUNCTION () . = ALIGN(8)
@@ -200,6 +201,7 @@/* .data section */ #define DATA_DATA \ *(SECTION_DATA) \ + *(SORT(SECTION_RNG_ALL(SECTION_DATA))) \ *(SECTION_REF_DATA) \ *(.data..shared_aligned)/* percpu related */ \MEM_KEEP (init.data) \
@@ -265,7 +267,9 @@ . = ALIGN((align)); \ SECTION_RODATA : AT(ADDR(SECTION_RODATA) - LOAD_OFFSET) { \ VMLINUX_SYMBOL(__start_rodata) = .; \ - *(SECTION_RODATA ) *(SECTION_ALL (SECTION_RODATA )) \ + *(SECTION_RODATA ) \ + *(SORT (SECTION_RNG_ALL (SECTION_RODATA ))) \ + *(SECTION_ALL (SECTION_RODATA )) \RO_AFTER_INIT_DATA /* Read only after init */ \ *(__vermagic)/* Kernel version magic */ \ . = ALIGN(8); \
@@ -433,7 +437,9 @@* during second ld run in second ld pass when generating System.map */ #define TEXT_TEXT \ ALIGN_FUNCTION(); \ - *(.text.hot SECTION_TEXT .text.fixup .text.unlikely) \ + *(.text.hot SECTION_TEXT) \ + *(SORT(SECTION_RNG_ALL(SECTION_TEXT))) \ + *(.text.fixup .text.unlikely) \ *(SECTION_REF) \ MEM_KEEP(init.text) \ MEM_KEEP(exit.text) \
@@ -529,6 +535,7 @@/* init and exit section handling */ #define INIT_DATA \ *(SECTION_INIT_DATA) \ + *(SORT(SECTION_RNG_ALL(SECTION_INIT_DATA))) \ MEM_DISCARD(init.data) \ KERNEL_CTORS() \ MCOUNT_REC() \
@@ -551,6 +558,7 @@#define INIT_TEXT \ *(SECTION_INIT) \ + *(SORT(SECTION_RNG_ALL(SECTION_INIT))) \ *(.text.startup) \ MEM_DISCARD(init.text)
include/linux/ranges.h new file +128 -0
128 lines not on this page · raw message
Signature · 7 lines
2.9.2 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
[email protected]
maintainerPATCH v4 7/16 tables.h: add linker table support
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
A linker table is a data structure that is stitched together from items in multiple object files. Linux has historically implicitly used linker tables for ages, however they were all built in an adhoc manner which requires linker script modifications, per architecture. This adds a general linker table solution so that a new linker table can be implemented by changing C code only. The Linux linker table was inspired by Michael Brown's iPXE's linker table solution, it has been been completely re-written and adapted for integration and use on Linux.
The same philosophy is borrowed, extended and further simplified:
Linker tables enable an extremely light weight linker build time solution for feature ordering and selection, this can help to both simplify init sequences in a generic fashion and helps avoiding code bit-rotting when desirable. Further changes will be added later which will make more evident how code bit rot can be avoided using linker tables.
v4:
o Split out kbuild additions to help with code bit rot into its own patch
o tons of documentation love
o fix arch/x86/tools/relocs.c typo - which caused compilation issues on old toolchains
o add c6x toolchain work around as discussed with Mark Salter
o sprinkle a few more needed VMLINUX_SYMBOL() - fixes compilation on blackfin
o suggested name changes by boris:
- %s/SECTION_TYPE_RANGES/rng/g
- %s/SECTION_TYPE/SECTION_CORE/g
- %s/section_type_asmtype/section_core_type/g
- %s/section_type/section_core/g
- %s/section_rng/set_section_rng/g
- Drop DECLARE_SECTION_TBL() -- this is an asm equivalent DEFINE_LINKTABLE() -- this however is not used yet, and it requires a bit more work to match the C code definitions.
o drop tools/include/linux/sections.h in favor of the more popular open coding the names for tools
o expand documentation to include module support
o add maintaners
o Use generic-y
o move .text.tbl before unlikely to match the other sections
v3:
o addressed initial modular support test cases
o added generic asm macros so linker tables can be used in asm code / C asm calls
o section ranges are now split up into their own set of files
o use asm/sections.h instead of linux/sections.h for the linker script
o add a sections.h file for each architecture that was missing one, this is needed now as we'll be relying on sections.h for custom section types in code rather than custom architecture specific linker script hacks.
o full rewrite at this point, decided to pick copyleft-next license for this work
v2:
o modified completely to match feedback by community, made equivalent modifications to userspace solution. This is pretty much a complete rewrite of how we present and use linker tables. By using standard sections we no longer have to make custom linker script extensions for each new linker table solution, you just pick a linker table type by section type.
o extend documention considerably, including use of kdoc
o drop ICC hacks per popular request to ignore such issues for now
o use sections.h - this lets us streamline a clean use case of well documented sections. To help further with this make use of SECTION_TBL() to allow use of these in code and SECTION_TBL_ALL() on linker scripts, as well as SECTION_TBL_ALL_STR() on relocs.c when needed.
--- Documentation/sections/index.rst | 1 + Documentation/sections/linker-tables.rst | 187 ++++++++++ MAINTAINERS | 12 + arch/alpha/include/asm/Kbuild | 1 + arch/arc/include/asm/Kbuild | 1 + arch/arm/include/asm/Kbuild | 1 + arch/arm64/include/asm/Kbuild | 1 + arch/avr32/include/asm/Kbuild | 1 + arch/blackfin/include/asm/Kbuild | 1 + arch/c6x/include/asm/tables.h | 26 ++ arch/cris/include/asm/Kbuild | 1 + arch/frv/include/asm/Kbuild | 1 + arch/h8300/include/asm/Kbuild | 1 + arch/hexagon/include/asm/Kbuild | 1 + arch/ia64/include/asm/Kbuild | 1 + arch/m32r/include/asm/Kbuild | 1 + arch/m68k/include/asm/Kbuild | 1 + arch/metag/include/asm/Kbuild | 1 + arch/microblaze/include/asm/Kbuild | 1 + arch/mips/include/asm/Kbuild | 1 + arch/mn10300/include/asm/Kbuild | 1 + arch/nios2/include/asm/Kbuild | 1 + arch/openrisc/include/asm/Kbuild | 1 + arch/parisc/include/asm/Kbuild | 1 + arch/powerpc/include/asm/Kbuild | 1 + arch/s390/include/asm/Kbuild | 1 + arch/score/include/asm/Kbuild | 1 + arch/sh/include/asm/Kbuild | 1 + arch/sparc/include/asm/Kbuild | 1 + arch/tile/include/asm/Kbuild | 1 + arch/um/include/asm/Kbuild | 1 + arch/unicore32/include/asm/Kbuild | 1 + arch/x86/include/asm/Kbuild | 1 + arch/x86/tools/relocs.c | 2 + arch/xtensa/include/asm/Kbuild | 1 + include/asm-generic/ranges.h | 14 + include/asm-generic/tables.h | 50 +++ include/asm-generic/vmlinux.lds.h | 6 + include/linux/tables.h | 567 +++++++++++++++++++++++++++++++ scripts/Makefile.clean | 2 + 40 files changed, 897 insertions(+) create mode 100644 Documentation/sections/linker-tables.rst create mode 100644 arch/c6x/include/asm/tables.h create mode 100644 include/asm-generic/tables.h create mode 100644 include/linux/tables.h
Documentation/sections/index.rst +1 -0
@@ -10,3 +10,4 @@ used throughout the kernel to help declare and define them. section-core ranges + linker-tables
Documentation/sections/linker-tables.rst new file +187 -0
187 lines not on this page · raw message
MAINTAINERS +12 -0
@@ -5200,6 +5200,18 @@ S: Maintained F: include/asm-generic/ F: include/uapi/asm-generic/ +GENERIC LINKER TABLES +M: "Luis R. Rodriguez" <[email protected]> +M: "H. Peter Anvin" <[email protected]> +L: [email protected] +L: [email protected] +T: git git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git sections +T: git git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux-next.git sections +S: Supported +F: include/asm-generic/tables.h +F: include/linux/tables.h +F: Documentation/sections/linker-tables.rst + GENERIC PHY FRAMEWORK M: Kishon Vijay Abraham I <[email protected]> L: [email protected]
arch/alpha/include/asm/Kbuild +1 -0
@@ -12,3 +12,4 @@ generic-y += sections.h generic-y += trace_clock.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/arc/include/asm/Kbuild +1 -0
@@ -52,3 +52,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/arm/include/asm/Kbuild +1 -0
@@ -41,3 +41,4 @@ generic-y += trace_clock.h generic-y += unaligned.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/arm64/include/asm/Kbuild +1 -0
@@ -54,3 +54,4 @@ generic-y += vga.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/avr32/include/asm/Kbuild +1 -0
@@ -24,3 +24,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/blackfin/include/asm/Kbuild +1 -0
@@ -50,3 +50,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/c6x/include/asm/tables.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef _ASM_C6X_ASM_TABLES_H +#define _ASM_C6X_ASM_TABLES_H +/* +* Copyright (C) 2016 Luis R. Rodriguez <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of copyleft-next (version 0.3.1 or later) as published +* at http://copyleft-next.org/. +*/ + +/* +* The c6x toolchain has a bug present even on gcc-6 when non-weak attributes +* are used and sends them to .rodata even though const data with weak +* attributes are put in .const, this forces the linker to believe the address +* is relative relative to the a base + offset and you end up with SB-relative +* reloc error upon linking. Work around this by by forcing both start and +* ending const RO waek linker table entry to be .const to fix this for now. +* +* [0] https://lkml.kernel.org/r/[email protected] +*/ + +#define SECTION_TBL_RO .const + +#include <asm-generic/tables.h> + +#endif /* _ASM_C6X_ASM_TABLES_H */
arch/cris/include/asm/Kbuild +1 -0
@@ -47,3 +47,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/frv/include/asm/Kbuild +1 -0
@@ -10,3 +10,4 @@ generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/h8300/include/asm/Kbuild +1 -0
@@ -77,3 +77,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/hexagon/include/asm/Kbuild +1 -0
@@ -62,3 +62,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/ia64/include/asm/Kbuild +1 -0
@@ -11,3 +11,4 @@ generic-y += vtime.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/m32r/include/asm/Kbuild +1 -0
@@ -13,3 +13,4 @@ generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/m68k/include/asm/Kbuild +1 -0
@@ -37,3 +37,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/metag/include/asm/Kbuild +1 -0
@@ -58,3 +58,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/microblaze/include/asm/Kbuild +1 -0
@@ -13,3 +13,4 @@ generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/mips/include/asm/Kbuild +1 -0
@@ -22,3 +22,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/mn10300/include/asm/Kbuild +1 -0
@@ -12,3 +12,4 @@ generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/nios2/include/asm/Kbuild +1 -0
@@ -65,3 +65,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/openrisc/include/asm/Kbuild +1 -0
@@ -73,3 +73,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/parisc/include/asm/Kbuild +1 -0
@@ -31,3 +31,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/powerpc/include/asm/Kbuild +1 -0
@@ -9,3 +9,4 @@ generic-y += rwsem.h generic-y += vtime.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/s390/include/asm/Kbuild +1 -0
@@ -10,3 +10,4 @@ generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/score/include/asm/Kbuild +1 -0
@@ -16,3 +16,4 @@ generic-y += serial.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/sh/include/asm/Kbuild +1 -0
@@ -41,3 +41,4 @@ generic-y += ucontext.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/sparc/include/asm/Kbuild +1 -0
@@ -24,3 +24,4 @@ generic-y += types.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/tile/include/asm/Kbuild +1 -0
@@ -43,3 +43,4 @@ generic-y += types.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/um/include/asm/Kbuild +1 -0
@@ -29,3 +29,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/unicore32/include/asm/Kbuild +1 -0
@@ -65,3 +65,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += ranges.h +generic-y += tables.h
arch/x86/include/asm/Kbuild +1 -0
@@ -18,3 +18,4 @@ generic-y += mcs_spinlock.h generic-y += mm-arch-hooks.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/x86/tools/relocs.c +2 -0
@@ -69,7 +69,9 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = {"__initramfs_start|" "(jiffies|jiffies_64)|" ".rodata.rng.*|" +".rodata.tbl.*|" ".init.text.rng.*|" + ".init.text.tbl.*|"#if ELF_BITS ==64 "__per_cpu_load|" "init_per_cpu__.*|"
arch/xtensa/include/asm/Kbuild +1 -0
@@ -33,3 +33,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
include/asm-generic/ranges.h +14 -0
@@ -86,4 +86,18 @@#endif /* __ASSEMBLY__ */ +#ifdef __ASSEMBLER__ + +#ifndef DEFINE_SECTION_RANGE +#define DEFINE_SECTION_RANGE (section, name) \ + push_section_rng_level(section, name,,) ; \ + .globl name ; \ +name: ; \ + .popsection \ + \ + push_section_rng_level(section, name, ~,) ; \ + .popsection +#endif +#endif /* __ASSEMBLER__ */ +#endif /* _ASM_GENERIC_RANGES_H_ */
include/asm-generic/tables.h new file +50 -0
50 lines not on this page · raw message
include/asm-generic/vmlinux.lds.h +6 -0
@@ -57,6 +57,7 @@#include <linux/export.h> #include <asm/section-core.h> #include <asm/ranges.h> +#include <asm/tables.h> /* Align . to a 8 byte boundary equals to maximum function alignment. */ #define ALIGN_FUNCTION () . = ALIGN(8)
@@ -202,6 +203,7 @@#define DATA_DATA \ *(SECTION_DATA) \ *(SORT(SECTION_RNG_ALL(SECTION_DATA))) \ + *(SORT(SECTION_TBL_ALL(SECTION_DATA))) \ *(SECTION_REF_DATA) \ *(.data..shared_aligned)/* percpu related */ \MEM_KEEP (init.data) \
@@ -269,6 +271,7 @@ VMLINUX_SYMBOL(__start_rodata) = .; \ *(SECTION_RODATA ) \ *(SORT (SECTION_RNG_ALL (SECTION_RODATA ))) \ + *(SORT (SECTION_TBL_ALL (SECTION_RODATA ))) \ *(SECTION_ALL (SECTION_RODATA )) \RO_AFTER_INIT_DATA /* Read only after init */ \ *(__vermagic)/* Kernel version magic */ \
@@ -439,6 +442,7 @@ALIGN_FUNCTION (); \ *(.text.hot SECTION_TEXT) \ *(SORT (SECTION_RNG_ALL (SECTION_TEXT ))) \ + *(SORT (SECTION_TBL_ALL (SECTION_TEXT ))) \ *(.text.fixup .text.unlikely) \ *(SECTION_REF ) \MEM_KEEP (init.text) \
@@ -536,6 +540,7 @@#define INIT_DATA \ *(SECTION_INIT_DATA) \ *(SORT(SECTION_RNG_ALL(SECTION_INIT_DATA))) \ + *(SORT(SECTION_TBL_ALL(SECTION_INIT_DATA))) \ MEM_DISCARD(init.data) \ KERNEL_CTORS() \ MCOUNT_REC() \
@@ -559,6 +564,7 @@#define INIT_TEXT \ *(SECTION_INIT) \ *(SORT(SECTION_RNG_ALL(SECTION_INIT))) \ + *(SORT(SECTION_TBL_ALL(SECTION_INIT))) \ *(.text.startup) \ MEM_DISCARD(init.text)
include/linux/tables.h new file +567 -0
567 lines not on this page · raw message
scripts/Makefile.clean +2 -0
@@ -36,6 +36,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn)) # directory __clean-files := $(extra-y) $(extra-m) $(extra-) \ + $(force-obj-y) $(force-obj-m) $(force-obj-) \ + $(force-lib-y) $(force-lib-m) $(force-lib-) \ $(always) $(targets) $(clean-files) \ $(host-progs) \ $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
Signature · 1 line
2.9.2
[email protected]
maintainerPATCH v4 8/16 kbuild: enable option to force compile force-obj-y and force-lib-y
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
Linux provides a rich array of features, enabling each feature however increases the size of the kernel and there are many features which users often want disabled. The traditional solution to this problem is for each feature to have its own Kconfig symbol, followed by a series of #ifdef statements in C code and header files, allowing the feature to be compiled only when desirable. As the variability of Linux increases build tests can and are often done with random kernel configurations, allyesconfig, and allmodconfig to help find code issues. This however doesn't catch all errors and as a consequence code that is typically not enabled often can suffer from bit-rot over time.
An alternative approach for subsystems, which refer to as the 'build-all link-selectively philosophy' is to keep the Kconfig symbols, replace the #ifdef approach by having each feature implemented it its own C file, and force compilation for all features to avoid the code bit-rot problem. With this strategy only features that are enabled via Kconfig get linked into the kernel, so the forced compilation has no size impact on the kernel. The practice of having each feature implemented in its own C file is already prevalent in many subsystems, however #ifdefs are still typically required during feature initialization. For instance in:
#ifdef CONFIG_FOO foo_init(); #endif
We cannot remove the #ifdef and leave foo_init() as we'd either need to always enable the feature or add a respective #ifdef in a foo.h which makes foo_init() do nothing when CONFIG_FOO is disabled.
Linker tables enable lifting the requirement to use of #ifdefs during initialization. With linker tables initialization sequences can instead be aggregated into a custom ELF section at link time, during run time the table can be iterated over and each init sequence enabled can be called. A feature's init routine is only added to a table when its respective Kconfig symbols has been enabled and therefore linked in. Linker tables enable subsystems to completely do away with #ifdefs if one is comfortable in accepting all subsystem's feature's structural size implications.
Subsystems which want to follow the 'build-all link-selectively philosophy' still need a way to easily express and annotate that they wish for all code to always be compiled to help avoid code bit rot, as such two new targets force-obj-y and force-lib-y are provided to help with this. Its not fair to require everyone to force compilation of all features of a subsystem though, so as a compromise, the new targets only force compilation when CONFIG_BUILD_AVOID_BITROT is enabled.
Only built-in features are supported at the moment. Module support is expected to be added after a generic solution to add linker tables to modules more easily is developed.
v4: this patch was added to this series, it was split off from the
linker tables addition due to the confusion over the code bit rot alternatives that are possible with linker tables.
--- Documentation/kbuild/makefiles.txt | 36 ++++++++++++++++ Documentation/sections/linker-tables.rst | 15 +++++++ include/linux/tables.h | 71 ++++++++++++++++++++++++++++++++ init/Kconfig | 22 ++++++++++ scripts/Makefile.build | 7 ++-- scripts/Makefile.lib | 11 +++++ 6 files changed, 159 insertions(+), 3 deletions(-)
Documentation/kbuild/makefiles.txt +36 -0
@@ -1089,6 +1089,42 @@ When kbuild executes, the following steps are followed (roughly): In this example, extra-y is used to list object files that shall be built, but shall not be linked as part of built-in.o. + force-obj-y force-lib-y + + When CONFIG_BUILD_AVOID_BITROT is enabled using these targets for your + kconfig symbols forces compilation of the associated objects if the + kconfig's symbol's dependencies are met, the objects however are only + linked into to the kernel if and only if the kconfig symbol was + enabled. If CONFIG_BUILD_AVOID_BITROT is disabled the force-obj-y and + force-lib-y targets are functionally equilvalent to obj-y and lib-y + respectively. + + Using force-obj-y and force-lib-y are part of a code architecture and + build philosophy further enabled by linker tables, for more details + refer to the documention in include/linux/tables.h, refer to the + sections: + + o The code bit-rot problem + o The build-all selective-link philosophy + o Avoiding the code bit-rot problem with linker tables + o Linker table module support + + Modules support is expected to be enhanced in the future, so for now + only built-in features are supported. + + Example use: + + force-obj-$(CONFIG_FEATURE_FOO) += foo.o + + An alternative to using force-obj-y, is to use extra-y followed by the + respective obj-y: + + extra-y += foo.o + obj-$(CONFIG_FEATURE_FOO) += foo.o + + Using force-obj-y and force-lib-y can be used to help annotate the + targets follow the 'build-all selective-link philosophy' further + enabled by linker tables. --- 6.7 Commands useful for building a boot image
Documentation/sections/linker-tables.rst +15 -0
@@ -30,6 +30,21 @@ How linker tables simplify initialization code .. kernel-doc:: include/linux/tables.h :doc: How linker tables simplify initialization code +The code bit-rot problem +------------------------ +.. kernel-doc:: include/linux/tables.h + :doc: The code bit-rot problem + +The build-all selective-link philosophy +--------------------------------------- +.. kernel-doc:: include/linux/tables.h + :doc: The build-all selective-link philosophy + +Avoiding the code bit-rot problem with linker tables +---------------------------------------------------- +.. kernel-doc:: include/linux/tables.h + :doc: Avoiding the code bit-rot problem with linker tables + Using linker tables in Linux ============================
include/linux/tables.h +71 -0
77 lines not on this page · raw message
init/Kconfig +22 -0
@@ -53,6 +53,28 @@ config CROSS_COMPILE need to set this unless you want the configured kernel build directory to select the cross-compiler automatically. +config BUILD_AVOID_BITROT + bool "Enable force building of force-obj-y and force-lib-y" + default n + help + When enabled objects under the force-obj-y and force-lib-y targets + using a Kconfig symbol will be forced to compile if the Kconfig + symbol's dependencies are met but only linked into the kernel if + the Kconfig symbol is enabled. If a Kconfig symbol on a force-obj-y + or force-lib-y target is disabled, it will be compiled but not linked + into the kernel. + + The force-obj-y and force-lib-y targets can be used by subsystems + which wish to want to follow the 'build-all selective-link philosophy' + documented under include/linux/tables.h. + + Say Y if you have a decent build machine and would like to help test + building code for more subsystems. Say N if you do you not have a + good build machine or only want to compile what you've enabled for + your kernel. + + Enabling this option never increases the size of your kernel. + config COMPILE_TEST bool "Compile also drivers which will not load" depends on !UML
scripts/Makefile.build +4 -3
@@ -92,7 +92,8 @@ modorder-target := $(obj)/modules.order # We keep a list of all modules in $(MODVERDIR) -__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \ +__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y) \ + $(force-obj-y)) \ $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \ $(subdir-ym) $(always) @:
@@ -326,8 +327,8 @@ cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< $(obj)/%.o: $(src)/%.S $(objtool_obj) FORCE $(call if_changed_rule,as_o_S) -targets += $(real-objs-y) $(real-objs-m) $(lib-y) -targets += $(extra-y) $(MAKECMDGOALS) $(always) +targets += $(real-objs-y) $(real-objs-m) $(lib-y) $(force-lib-y) +targets += $(extra-y) $(force-obj-y) $(MAKECMDGOALS) $(always) # Linker scripts preprocessor (.lds.S -> .lds) # ---------------------------------------------------------------------------
scripts/Makefile.lib +11 -0
@@ -12,6 +12,15 @@ export KBUILD_SUBDIR_CCFLAGS := $(KBUILD_SUBDIR_CCFLAGS) $(subdir-ccflags-y) # Figure out what we need to build from the various variables # =========================================================================== +ifeq ($(CONFIG_BUILD_AVOID_BITROT),y) +extra-y += $(force-obj-) $(force-lib-) +endif + +obj-m += $(force-obj-m) +obj-y += $(force-obj-y) +lib-m += $(force-lib-m) +lib-y += $(force-lib-y) + # When an object is listed to be built compiled-in and modular, # only build the compiled-in version
@@ -72,6 +81,8 @@ real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y) # Add subdir path extra-y := $(addprefix $(obj)/,$(extra-y)) +force-obj-y := $(addprefix $(obj)/,$(force-obj-y)) +force-obj-m := $(addprefix $(obj)/,$(force-obj-m)) always := $(addprefix $(obj)/,$(always)) targets := $(addprefix $(obj)/,$(targets)) modorder := $(addprefix $(obj)/,$(modorder))
Signature · 1 line
2.9.2
[email protected]
maintainerPATCH v4 9/16 firmware/Makefile: force recompilation if makefile changes
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
If you modify the target asm we currently do not force the recompilation of the firmware files. The target asm is in the firmware/Makefile, peg this file as a dependency to require re-compilation of firmware targets when the asm changes.
v3: introduced in this series
--- firmware/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
firmware/Makefile +2 -1
@@ -176,7 +176,8 @@ quiet_cmd_fwbin = MK_FW $@ wordsize_deps := $(wildcard include/config/64bit.h include/config/32bit.h \ include/config/ppc32.h include/config/ppc64.h \ include/config/superh32.h include/config/superh64.h \ - include/config/x86_32.h include/config/x86_64.h) + include/config/x86_32.h include/config/x86_64.h \ + firmware/Makefile) $(patsubst %,$(obj)/%.gen.S, $(fw-shipped-y)): %: $(wordsize_deps) $(call cmd,fwbin,$(patsubst %.gen.S,%,$@))
Signature · 1 line
2.9.2
[email protected]
maintainerPATCH v4 10/16 firmware: port built-in section to linker table
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
This ports built-in firmware to use linker tables, this replaces the custom section solution with a generic solution.
This also demos the use of the .rodata (SECTION_RO) linker tables.
Tested with 0 built-in firmware, 1 and 2 built-in firmwares successfully.
v4:
o work around c6x toolchain bug by using SECTION_TBL_RO
o fix compilation on blackfin
v3:
o explicitly include tables.h as we no longer include tables.h from sections.h
o use new section_tbl_asmtype() helper on firmware/Makefile to enable having to unfold things on our own.
v2: introduced this file in this version of the series
--- arch/x86/kernel/cpu/microcode/core.c | 8 ++++---- drivers/base/firmware_class.c | 12 ++++++------ firmware/Makefile | 3 ++- include/asm-generic/vmlinux.lds.h | 7 ------- 4 files changed, 12 insertions(+), 18 deletions(-)
arch/x86/kernel/cpu/microcode/core.c +4 -4
@@ -31,6 +31,7 @@#include <linux/cpu.h> #include <linux/fs.h> #include <linux/mm.h> +#include <linux/tables.h> #include <asm/microcode_intel.h> #include <asm/cpu_device_id.h>
@@ -91,15 +92,14 @@ static bool __init check_loader_disabled_bsp(void)return *res; } -extern struct builtin_fw __start_builtin_fw[]; -extern struct builtin_fw __end_builtin_fw[]; +DECLARE_LINKTABLE_RO(struct builtin_fw, builtin_fw);bool get_builtin_firmware (struct cpio_data *cd,const char *name) {#ifdef CONFIG_FW_LOADER -struct builtin_fw *b_fw; +const struct builtin_fw *b_fw; -for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) { + LINKTABLE_FOR_EACH(b_fw, builtin_fw) {if (!strcmp (name, b_fw->name)) { cd->size = b_fw->size; cd->data = b_fw->data;
drivers/base/firmware_class.c +6 -6
@@ -30,6 +30,7 @@#include <linux/syscore_ops.h> #include <linux/reboot.h> #include <linux/security.h> +#include <linux/tables.h> #include <generated/utsrelease.h>
@@ -43,15 +44,14 @@ MODULE_LICENSE("GPL");#ifdef CONFIG_FW_LOADER -extern struct builtin_fw __start_builtin_fw[]; -extern struct builtin_fw __end_builtin_fw[]; +DEFINE_LINKTABLE_RO(struct builtin_fw, builtin_fw);static bool fw_get_builtin_firmware (struct firmware *fw,const char *name,void *buf,size_t size) { -struct builtin_fw *b_fw; +const struct builtin_fw *b_fw; -for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) { + LINKTABLE_FOR_EACH(b_fw, builtin_fw) {if (strcmp (name, b_fw->name) ==0 ) { fw->size = b_fw->size; fw->data = b_fw->data;
@@ -67,9 +67,9 @@ static bool fw_get_builtin_firmware(struct firmware *fw, const char *name,static bool fw_is_builtin_firmware (const struct firmware *fw) { -struct builtin_fw *b_fw; +const struct builtin_fw *b_fw; -for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) + LINKTABLE_FOR_EACH(b_fw, builtin_fw)if (fw->data == b_fw->data)return true;
firmware/Makefile +2 -1
@@ -155,6 +155,7 @@ quiet_cmd_fwbin = MK_FW $@ ASM_ALIGN=$(if $(CONFIG_64BIT),3,2); \ PROGBITS=$(if $(CONFIG_ARM),%,@)progbits; \ echo "/* Generated by firmware/Makefile */" > $@;\ + echo "\#include <asm/tables.h>" >>$@;\ echo " .section .rodata" >>$@;\ echo " .p2align $${ASM_ALIGN}" >>$@;\ echo "_fw_$${FWSTR}_bin:" >>$@;\
@@ -164,7 +165,7 @@ quiet_cmd_fwbin = MK_FW $@ echo " .p2align $${ASM_ALIGN}" >>$@;\ echo "_fw_$${FWSTR}_name:" >>$@;\ echo " .string \"$$FWNAME\"" >>$@;\ - echo " .section .builtin_fw,\"a\",$${PROGBITS}" >>$@;\ + echo " set_section_tbl_type(SECTION_TBL_RO, builtin_fw, SECTION_ORDER_ANY, a,$${PROGBITS})" >>$@;\ echo " .p2align $${ASM_ALIGN}" >>$@;\ echo " $${ASM_WORD} _fw_$${FWSTR}_name" >>$@;\ echo " $${ASM_WORD} _fw_$${FWSTR}_bin" >>$@;\
include/asm-generic/vmlinux.lds.h +0 -7
@@ -316,13 +316,6 @@ VMLINUX_SYMBOL(__end_pci_fixups_suspend_late) = .; \ } \ \ -/* Built-in firmware blobs */ \ - .builtin_fw : AT(ADDR(.builtin_fw) - LOAD_OFFSET) { \ - VMLINUX_SYMBOL(__start_builtin_fw) = .; \ - *(.builtin_fw) \ - VMLINUX_SYMBOL(__end_builtin_fw) = .; \ - } \ - \TRACEDATA \ \/* Kernel symbol table: Normal symbols */ \
Signature · 1 line
2.9.2
[email protected]
maintainerPATCH v4 11/16 jump_label: move guard #endif down where it belongs
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
The ending header guard is misplaced. This has no
functional change, this is just an eye-sore.
--- include/linux/jump_label.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/jump_label.h +2 -2
@@ -384,6 +384,6 @@ extern bool ____wrong_branch_error(void);#define static_branch_enable (x) static_key_enable(&(x)->key)#define static_branch_disable (x) static_key_disable(&(x)->key) -#endif /* _LINUX_JUMP_LABEL_H */ -#endif /* __ASSEMBLY__ */ + +#endif /* _LINUX_JUMP_LABEL_H */
Signature · 1 line
2.9.2
[email protected]
maintainerPATCH v4 12/16 jump_label: port __jump_table to linker tables
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
Move the __jump_table from the a custom section solution to a generic solution, this avoiding extra vmlinux.lds.h customizations.
This also demos the use of the .data (SECTION_DATA) linker table and of the shared asm call push_section_tbl().
Built-in kernel functionality was tested with CONFIG_STATIC_KEYS_SELFTEST. Moduler kernel functionality was tested with CONFIG_TEST_STATIC_KEYS. Both work as expected.
Since __jump_table sections are also supported per module this also required expanding module-common.lds.S to capture and fold all .data.tlb.__jump_table.* onto the the section __jump_table -- in this case for modules need to keep a reference in place, given the alternative is to use DEFINE_LINKTABLE(struct jump_entry, __jump_table) per module -- and later through macro hacks instantiate the jump entries per module upon init. This is doable but we'd loose out on the sorting of the table using the linker, to sort we'd always still need to expand the module common linker script. An alternative mechanism is possible which would make these custom module sections extensions dynamic without requiring manual changes, this however is best done later through a separate evolution once linker tables are in place.
A careful reviewer may note that some architectures use "\n\t" to separate asm code, while others just use a new line. Upon review last time it was deemed reasonable to for all architectures to just use "\n", this is defined as ASM_CMD_SEP, and if an architecture needs to override they can do so on their architecture sections.h prior to including asm-generic/sections.h
v4:
o Some architectures allow linker scripts to follow including header files, some others do not, so if you need a helper on a linker script you need to explicitly include it. So for instance although scripts/module-common.lds.S includes <asm/tables.h> and this file includes <asm/section-core.h>, you still need to explicitly include it on the linker script. This issue is present on ARM.
o as per Josh Poimboeuf open code the section table name instead of including the kernel section headers, the simplicity and independence from the kernel is preferred.
v3:
o More elaborate tests performed
o first modular support use case, module tested was CONFIG_TEST_STATIC_KEYS (lib/test_static_keys.ko), this required us to extend module-common.lds.S
o use generic push_section_tbl_any() for all architectures
o Makes use of ASM_CMD_SEP to enable architectures to override later if needed
o guard tables.h inclusion and table definition with __KERNEL__
v2: introduced in this series
--- arch/arm/include/asm/jump_label.h | 6 ++++-- arch/arm64/include/asm/jump_label.h | 6 ++++-- arch/mips/include/asm/jump_label.h | 6 ++++-- arch/powerpc/include/asm/jump_label.h | 8 +++++--- arch/s390/include/asm/jump_label.h | 6 ++++-- arch/sparc/include/asm/jump_label.h | 6 ++++-- arch/x86/include/asm/jump_label.h | 10 ++++++---- include/asm-generic/vmlinux.lds.h | 4 ---- include/linux/jump_label.h | 4 ++-- kernel/jump_label.c | 17 ++++++++++------- scripts/module-common.lds.S | 5 +++++ tools/objtool/special.c | 2 +- 12 files changed, 49 insertions(+), 31 deletions(-)
arch/arm/include/asm/jump_label.h +4 -2
@@ -1,6 +1,8 @@#ifndef _ASM_ARM_JUMP_LABEL_H#define _ASM_ARM_JUMP_LABEL_H +#include <asm/tables.h> +#ifndef __ASSEMBLY__#include <linux/types.h>
@@ -12,7 +14,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran { asm_volatile_goto("1:\n\t" WASM(nop) "\n\t" - ".pushsection __jump_table, \"aw\"\n\t" + push_section_tbl_any(SECTION_DATA, __jump_table, aw) ".word 1b, %l[l_yes], %c0\n\t" ".popsection\n\t" : : "i" (&((char *)key)[branch]) : : l_yes);
@@ -26,7 +28,7 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool { asm_volatile_goto("1:\n\t" WASM(b) " %l[l_yes]\n\t" - ".pushsection __jump_table, \"aw\"\n\t" + push_section_tbl_any(SECTION_DATA, __jump_table, aw) ".word 1b, %l[l_yes], %c0\n\t" ".popsection\n\t" : : "i" (&((char *)key)[branch]) : : l_yes);
arch/arm64/include/asm/jump_label.h +4 -2
@@ -19,6 +19,8 @@#ifndef __ASM_JUMP_LABEL_H#define __ASM_JUMP_LABEL_H +#include <asm/tables.h> +#ifndef __ASSEMBLY__#include <linux/types.h>
@@ -29,7 +31,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool branch) { asm goto("1: nop\n\t" -".pushsection __jump_table, \"aw\"\n\t" + push_section_tbl_any(SECTION_DATA, __jump_table, aw)".align 3\n\t" ".quad 1b, %l[l_yes], %c0\n\t" ".popsection\n\t"
@@ -43,7 +45,7 @@ l_yes: static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch) { asm goto("1: b %l[l_yes]\n\t" -".pushsection __jump_table, \"aw\"\n\t" + push_section_tbl_any(SECTION_DATA, __jump_table, aw)".align 3\n\t" ".quad 1b, %l[l_yes], %c0\n\t" ".popsection\n\t"
arch/mips/include/asm/jump_label.h +4 -2
@@ -8,6 +8,8 @@#ifndef _ASM_MIPS_JUMP_LABEL_H#define _ASM_MIPS_JUMP_LABEL_H +#include <asm/tables.h> +#ifndef __ASSEMBLY__#include <linux/types.h>
@@ -30,7 +32,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran { asm_volatile_goto("1:\t" NOP_INSN "\n\t" "nop\n\t" - ".pushsection __jump_table, \"aw\"\n\t" + push_section_tbl_any(SECTION_DATA, __jump_table, aw) WORD_INSN " 1b, %l[l_yes], %0\n\t" ".popsection\n\t" : : "i" (&((char *)key)[branch]) : : l_yes);
@@ -44,7 +46,7 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool { asm_volatile_goto("1:\tj %l[l_yes]\n\t" "nop\n\t" - ".pushsection __jump_table, \"aw\"\n\t" + push_section_tbl_any(SECTION_DATA, __jump_table, aw) WORD_INSN " 1b, %l[l_yes], %0\n\t" ".popsection\n\t" : : "i" (&((char *)key)[branch]) : : l_yes);
arch/powerpc/include/asm/jump_label.h +5 -3
@@ -10,6 +10,8 @@* 2 of the License, or (at your option) any later version. */ +#include <asm/tables.h> +#ifndef __ASSEMBLY__#include <linux/types.h>
@@ -23,7 +25,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran { asm_volatile_goto("1:\n\t" "nop # arch_static_branch\n\t" - ".pushsection __jump_table, \"aw\"\n\t" + push_section_tbl_any(SECTION_DATA, __jump_table, aw) JUMP_ENTRY_TYPE "1b, %l[l_yes], %c0\n\t" ".popsection \n\t" : : "i" (&((char *)key)[branch]) : : l_yes);
@@ -37,7 +39,7 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool { asm_volatile_goto("1:\n\t" "b %l[l_yes] # arch_static_branch_jump\n\t" - ".pushsection __jump_table, \"aw\"\n\t" + push_section_tbl_any(SECTION_DATA, __jump_table, aw) JUMP_ENTRY_TYPE "1b, %l[l_yes], %c0\n\t" ".popsection \n\t" : : "i" (&((char *)key)[branch]) : : l_yes);
@@ -62,7 +64,7 @@ struct jump_entry {#else #define ARCH_STATIC_BRANCH (LABEL ,KEY ) \ 1098: nop; \ - .pushsection __jump_table, "aw"; \ + push_section_tbl_any(SECTION_DATA, __jump_table, aw); \ FTR_ENTRY_LONG 1098b, LABEL, KEY; \ .popsection#endif
arch/s390/include/asm/jump_label.h +4 -2
@@ -1,6 +1,8 @@#ifndef _ASM_S390_JUMP_LABEL_H#define _ASM_S390_JUMP_LABEL_H +#include <asm/tables.h> +#ifndef __ASSEMBLY__#include <linux/types.h>
@@ -16,7 +18,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool branch) { asm_volatile_goto("0: brcl 0,"__stringify(JUMP_LABEL_NOP_OFFSET)"\n" -".pushsection __jump_table, \"aw\"\n" + push_section_tbl_any(SECTION_DATA, __jump_table, aw)".balign 8\n" ".quad 0b, %l[label], %0\n" ".popsection\n"
@@ -30,7 +32,7 @@ label: static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch) { asm_volatile_goto("0: brcl 15, %l[label]\n" -".pushsection __jump_table, \"aw\"\n" + push_section_tbl_any(SECTION_DATA, __jump_table, aw)".balign 8\n" ".quad 0b, %l[label], %0\n" ".popsection\n"
arch/sparc/include/asm/jump_label.h +4 -2
@@ -1,6 +1,8 @@#ifndef _ASM_SPARC_JUMP_LABEL_H#define _ASM_SPARC_JUMP_LABEL_H +#include <asm/tables.h> +#ifndef __ASSEMBLY__#include <linux/types.h>
@@ -12,7 +14,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran asm_volatile_goto("1:\n\t" "nop\n\t" "nop\n\t" -".pushsection __jump_table, \"aw\"\n\t" + push_section_tbl_any(SECTION_DATA, __jump_table, aw)".align 4\n\t" ".word 1b, %l[l_yes], %c0\n\t" ".popsection \n\t"
@@ -28,7 +30,7 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool asm_volatile_goto("1:\n\t" "b %l[l_yes]\n\t" "nop\n\t" -".pushsection __jump_table, \"aw\"\n\t" + push_section_tbl_any(SECTION_DATA, __jump_table, aw)".align 4\n\t" ".word 1b, %l[l_yes], %c0\n\t" ".popsection \n\t"
arch/x86/include/asm/jump_label.h +6 -4
@@ -1,6 +1,8 @@#ifndef _ASM_X86_JUMP_LABEL_H#define _ASM_X86_JUMP_LABEL_H +#include <asm/tables.h> +#ifndef HAVE_JUMP_LABEL /* * For better or for worse, if jump labels (the gcc extension) are missing,
@@ -34,7 +36,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran { asm_volatile_goto("1:" ".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t" -".pushsection __jump_table, \"aw\" \n\t" + push_section_tbl_any(SECTION_DATA, __jump_table, aw) _ASM_ALIGN"\n\t" _ASM_PTR"1b, %l[l_yes], %c0 + %c1 \n\t" ".popsection \n\t"
@@ -50,7 +52,7 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool asm_volatile_goto("1:" ".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t" "2:\n\t" -".pushsection __jump_table, \"aw\" \n\t" + push_section_tbl_any(SECTION_DATA, __jump_table, aw) _ASM_ALIGN"\n\t" _ASM_PTR"1b, %l[l_yes], %c0 + %c1 \n\t" ".popsection \n\t"
@@ -85,7 +87,7 @@ struct jump_entry { .else .byte STATIC_KEY_INIT_NOP .endif - .pushsection __jump_table, "aw" + push_section_tbl_any(SECTION_DATA, __jump_table, aw) _ASM_ALIGN _ASM_PTR .Lstatic_jump_\@, \target, \key .popsection
@@ -101,7 +103,7 @@ struct jump_entry { .long \target - .Lstatic_jump_after_\@ .Lstatic_jump_after_\@: .endif - .pushsection __jump_table, "aw" + push_section_tbl_any(SECTION_DATA, __jump_table, aw) _ASM_ALIGN _ASM_PTR .Lstatic_jump_\@, \target, \key + 1 .popsection
include/asm-generic/vmlinux.lds.h +0 -4
@@ -212,10 +212,6 @@STRUCT_ALIGN (); \ *(__tracepoints) \/* implement dynamic printk debug */ \ - . = ALIGN(8); \ - VMLINUX_SYMBOL(__start___jump_table) = .; \ - *(__jump_table ) \ - VMLINUX_SYMBOL(__stop___jump_table) = .; \ . = ALIGN(8); \ VMLINUX_SYMBOL(__start___verbose) = .; \ *(__verbose) \
include/linux/jump_label.h +2 -2
@@ -115,6 +115,7 @@ enum jump_label_type {struct module ;#ifdef HAVE_JUMP_LABEL +#include <linux/tables.h> #define JUMP_TYPE_FALSE 0UL#define JUMP_TYPE_TRUE 1UL
@@ -130,8 +131,7 @@ static __always_inline bool static_key_true(struct static_key *key)return !arch_static_branch (key, true); } -extern struct jump_entry __start___jump_table[]; -extern struct jump_entry __stop___jump_table[]; +DECLARE_LINKTABLE(struct jump_entry, __jump_table);extern void jump_label_init (void );extern void jump_label_lock (void );
kernel/jump_label.c +10 -7
@@ -15,9 +15,12 @@#include <linux/static_key.h> #include <linux/jump_label_ratelimit.h> #include <linux/bug.h> +#include <linux/tables.h> #ifdef HAVE_JUMP_LABEL +DEFINE_LINKTABLE(struct jump_entry, __jump_table); +/* mutex to protect coming/going of the the jump_label table */ static DEFINE_MUTEX (jump_label_mutex);
@@ -274,8 +277,6 @@ static void __jump_label_update(struct static_key *key,void __init jump_label_init (void ) { -struct jump_entry *iter_start = __start___jump_table; -struct jump_entry *iter_stop = __stop___jump_table;struct static_key *key =NULL ;struct jump_entry *iter;
@@ -292,9 +293,10 @@ void __init jump_label_init(void)return ;jump_label_lock (); -jump_label_sort_entries (iter_start, iter_stop); +jump_label_sort_entries (LINUX_SECTION_START (__jump_table), +LINUX_SECTION_END (__jump_table)); -for (iter = iter_start; iter < iter_stop; iter++) { + LINKTABLE_FOR_EACH(iter, __jump_table) {struct static_key *iterk;/* rewrite NOPs */
@@ -539,8 +541,9 @@ early_initcall(jump_label_init_module);*/ int jump_label_text_reserved (void *start,void *end) { -int ret =__jump_label_text_reserved (__start___jump_table, - __stop___jump_table, start, end); +int ret =__jump_label_text_reserved (LINUX_SECTION_START (__jump_table), +LINUX_SECTION_END (__jump_table), + start, end);if (ret)return ret;
@@ -553,7 +556,7 @@ int jump_label_text_reserved(void *start, void *end)static void jump_label_update (struct static_key *key) { -struct jump_entry *stop = __stop___jump_table; +struct jump_entry *stop =LINUX_SECTION_END (__jump_table);struct jump_entry *entry =static_key_entries (key);#ifdef CONFIG_MODULES struct module *mod;
scripts/module-common.lds.S +5 -0
@@ -3,6 +3,10 @@ * Archs are free to supply their own linker scripts. ld will * combine them automatically. */ + +#include <asm/section-core.h> +#include <asm/tables.h> + SECTIONS { /DISCARD/ : { *(.discard) }
@@ -16,6 +20,7 @@ SECTIONS { __kcrctab_unused 0 : { *(SORT(___kcrctab_unused+*)) } __kcrctab_unused_gpl 0 : { *(SORT(___kcrctab_unused_gpl+*)) } __kcrctab_gpl_future 0 : { *(SORT(___kcrctab_gpl_future+*)) } + __jump_table 0 : { *(SORT(SECTION_TBL(SECTION_DATA, __jump_table, *))) } . = ALIGN(8); .init_array 0 : { *(SORT(.init_array.*)) *(.init_array) }
tools/objtool/special.c +1 -1
@@ -63,7 +63,7 @@ struct special_entry entries[] = { .feature = ALT_FEATURE_OFFSET, }, { - .sec = "__jump_table", + .sec = ".data.tbl.__jump_table.any", .jump_or_nop = true, .size = JUMP_ENTRY_SIZE, .orig = JUMP_ORIG_OFFSET,
Signature · 1 line
2.9.2
[email protected]
maintainerPATCH v4 13/16 dynamic_debug: port to use linker tables
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
This removes the custom vmlinux.lds.h hacks and uses the generalized solution for .data (SECTION_DATA) entries.
This is much more potential for further fine tuning here though in the future. For instance, linker tables enable an extra postfix for order level annotations, this could easily be used as the KBUILD_MODNAME and with a bit of linker table changes we may be able to get a direct O(1) count of the entries for that KBUILD_MODNAME: it would just be a count on the number of entries for the given order level. This should help make dynamic_debug_init() cleaner and also reduce the amount of time it takes at boot time. Instead of iterating over each print until we have all for a KBUILD_MODNAME, we'd instead directly operate on each KBUILD_MODNAME directly.
Tested dynamic debug with dyndbg query ana debugfs control and it works as expected, for both built-in code and modules.
v4: fix compilation on blackfin
v3: added modular support
v2: introduced this patch into the series
--- include/asm-generic/vmlinux.lds.h | 5 ----- include/linux/dynamic_debug.h | 5 +++-- lib/dynamic_debug.c | 13 ++++++------- scripts/module-common.lds.S | 1 + 4 files changed, 10 insertions(+), 14 deletions(-)
include/asm-generic/vmlinux.lds.h +0 -5
@@ -211,11 +211,6 @@ *(.data.unlikely) \STRUCT_ALIGN (); \ *(__tracepoints ) \ -/* implement dynamic printk debug */ \ - . = ALIGN(8); \ - VMLINUX_SYMBOL(__start___verbose) = .; \ - *(__verbose ) \ - VMLINUX_SYMBOL(__stop___verbose) = .; \ LIKELY_PROFILE() \ BRANCH_PROFILE() \TRACE_PRINTKS () \
include/linux/dynamic_debug.h +3 -2
@@ -4,6 +4,7 @@#if defined(CC_HAVE_ASM_GOTO ) && defined(CONFIG_JUMP_LABEL )#include <linux/jump_label.h> #endif +#include <linux/tables.h> /* * An instance of this structure is created in a special
@@ -50,6 +51,7 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n, const char *modname);#if defined(CONFIG_DYNAMIC_DEBUG ) +DECLARE_LINKTABLE(struct _ddebug, __verbose);extern int ddebug_remove_module (const char *mod_name); extern __printf(2, 3) void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...);
@@ -71,8 +73,7 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor, const char *fmt, ...);#define DEFINE_DYNAMIC_DEBUG_METADATA_KEY (name, fmt, key, init) \ - static struct _ddebug __aligned(8) \ - __attribute__((section("__verbose"))) name = { \ + static LINKTABLE(__verbose, SECTION_ORDER_ANY) name = { \ .modname = KBUILD_MODNAME, \ .function = __func__, \ .filename = __FILE__, \
lib/dynamic_debug.c +6 -7
@@ -37,8 +37,7 @@#include <linux/device.h> #include <linux/netdevice.h> -extern struct _ddebug __start___verbose[]; -extern struct _ddebug __stop___verbose[]; +DEFINE_LINKTABLE(struct _ddebug, __verbose);struct ddebug_table {struct list_head link;
@@ -978,14 +977,14 @@ static int __init dynamic_debug_init(void)int n =0 , entries =0 , modct =0 ;int verbose_bytes =0 ; -if (__start___verbose == __stop___verbose) { -pr_warn ("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n" ); +if (LINUX_SECTION_EMPTY (__verbose)) { +pr_warn ("dynamic debug linker table empty on CONFIG_DYNAMIC_DEBUG build\n" );return 1 ; } - iter = __start___verbose; + iter =LINUX_SECTION_START (__verbose); modname = iter->modname; iter_start = iter; -for (; iter < __stop___verbose; iter++) { + LINKTABLE_FOR_EACH(iter, __verbose) { entries++; verbose_bytes +=strlen (iter->modname) +strlen (iter->function) +strlen (iter->filename) +strlen (iter->format);
@@ -1008,7 +1007,7 @@ static int __init dynamic_debug_init(void) ddebug_init_success =1 ;vpr_info ("%d modules, %d entries and %d bytes in ddebug tables, %d bytes in (readonly) verbose section\n" , modct, entries, (int )(modct *sizeof (struct ddebug_table )), - verbose_bytes + (int )(__stop___verbose - __start___verbose)); + verbose_bytes + (int )(LINUX_SECTION_SIZE (__verbose)));/* apply ddebug_query boot param, dont unload tables on err */ if (ddebug_setup_string[0 ] !='\0' ) {
scripts/module-common.lds.S +1 -0
@@ -21,6 +21,7 @@ SECTIONS { __kcrctab_unused_gpl 0 : { *(SORT(___kcrctab_unused_gpl+*)) } __kcrctab_gpl_future 0 : { *(SORT(___kcrctab_gpl_future+*)) } __jump_table 0 : { *(SORT(SECTION_TBL(SECTION_DATA, __jump_table, *))) } + __verbose 0 : { *(SORT(SECTION_TBL(SECTION_DATA, __verbose, *))) } . = ALIGN(8); .init_array 0 : { *(SORT(.init_array.*)) *(.init_array) }
Signature · 1 line
2.9.2
[email protected]
maintainerPATCH v4 14/16 kprobes: move kprobe declarations to asm-generic/kprobes.h
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
Often all is needed is these small helpers, instead of compiler.h or a full kprobes.h. This is important for asm helpers, in fact even some asm/kprobes.h make use of these helpers... instead just keep a generic asm file with helpers useful for asm code with the least amount of clutter as possible.
Likewise we need now to also address what to do about this file for both when architectures have CONFIG_HAVE_KPROBES, and when they do not. Then for when architectures have CONFIG_HAVE_KPROBES but have disabled CONFIG_KPROBES.
Right now most asm/kprobes.h do not have guards against CONFIG_KPROBES, this means most architecture code cannot include asm/kprobes.h safely. Correct this and add guards for architectures missing them. Additionally provide architectures that not have kprobes support with the default asm-generic solution. This lets us force asm/kprobes.h on the header include/linux/kprobes.h always, but most importantly we can now safely include just asm/kprobes.h on architecture code without bringing the full kitchen sink of header files.
Two architectures already provided a guard against CONFIG_KPROBES on its kprobes.h: sh, arch. The rest of the architectures needed gaurds added. We avoid including any not-needed headers on asm/kprobes.h unless kprobes have been enabled.
In a subsequent atomic change we can try now to remove compiler.h from include/linux/kprobes.h.
--- arch/alpha/include/asm/Kbuild | 1 + arch/arc/include/asm/kprobes.h | 6 ++++-- arch/arm/include/asm/kprobes.h | 4 ++++ arch/arm/probes/decode.h | 1 + arch/arm64/include/asm/kprobes.h | 4 ++++ arch/arm64/kernel/insn.c | 1 + arch/avr32/include/asm/kprobes.h | 4 ++++ arch/blackfin/include/asm/Kbuild | 1 + arch/c6x/include/asm/Kbuild | 1 + arch/cris/include/asm/Kbuild | 1 + arch/frv/include/asm/Kbuild | 1 + arch/h8300/include/asm/Kbuild | 1 + arch/hexagon/include/asm/Kbuild | 1 + arch/ia64/include/asm/kprobes.h | 7 ++++++- arch/m32r/include/asm/Kbuild | 1 + arch/m68k/include/asm/Kbuild | 1 + arch/metag/include/asm/Kbuild | 1 + arch/microblaze/include/asm/Kbuild | 1 + arch/mips/include/asm/kprobes.h | 6 +++++- arch/mn10300/include/asm/kprobes.h | 4 ++++ arch/nios2/include/asm/Kbuild | 1 + arch/openrisc/include/asm/Kbuild | 1 + arch/parisc/include/asm/Kbuild | 1 + arch/powerpc/include/asm/kprobes.h | 6 ++++++ arch/s390/include/asm/kprobes.h | 4 ++++ arch/score/include/asm/Kbuild | 1 + arch/sh/include/asm/kprobes.h | 2 ++ arch/sparc/include/asm/kprobes.h | 5 +++++ arch/tile/include/asm/kprobes.h | 6 +++++- arch/um/include/asm/Kbuild | 1 + arch/unicore32/include/asm/Kbuild | 1 + arch/x86/include/asm/kprobes.h | 6 ++++++ arch/xtensa/include/asm/Kbuild | 1 + include/asm-generic/kprobes.h | 25 +++++++++++++++++++++++++ include/linux/compiler.h | 8 -------- include/linux/kprobes.h | 19 +++---------------- 36 files changed, 107 insertions(+), 29 deletions(-) create mode 100644 include/asm-generic/kprobes.h
arch/alpha/include/asm/Kbuild +1 -0
@@ -13,3 +13,4 @@ generic-y += trace_clock.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/arc/include/asm/kprobes.h +4 -2
@@ -9,6 +9,8 @@#ifndef _ARC_KPROBES_H#define _ARC_KPROBES_H +#include <asm-generic/kprobes.h> +#ifdef CONFIG_KPROBES typedef u16 kprobe_opcode_t ;
@@ -55,6 +57,6 @@ void trap_is_kprobe(unsigned long address, struct pt_regs *regs);static void trap_is_kprobe (unsigned long address,struct pt_regs *regs) { } -#endif +#endif /* CONFIG_KPROBES */ -#endif +#endif /* _ARC_KPROBES_H */
arch/arm/include/asm/kprobes.h +4 -0
@@ -16,6 +16,9 @@#ifndef _ARM_KPROBES_H#define _ARM_KPROBES_H +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/types.h> #include <linux/ptrace.h> #include <linux/notifier.h>
@@ -83,4 +86,5 @@ struct arch_optimized_insn {*/ }; +#endif /* CONFIG_KPROBES */ #endif /* _ARM_KPROBES_H */
arch/arm/probes/decode.h +1 -0
@@ -22,6 +22,7 @@#include <linux/types.h> #include <linux/stddef.h> #include <asm/probes.h> +#include <asm/kprobes.h> void __init arm_probes_decode_init (void );
arch/arm64/include/asm/kprobes.h +4 -0
@@ -16,6 +16,9 @@#ifndef _ARM_KPROBES_H#define _ARM_KPROBES_H +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/types.h> #include <linux/ptrace.h> #include <linux/percpu.h>
@@ -57,4 +60,5 @@ int kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr);void kretprobe_trampoline (void );void __kprobes *trampoline_probe_handler (struct pt_regs *regs); +#endif /* CONFIG_KPROBES */ #endif /* _ARM_KPROBES_H */
arch/arm64/kernel/insn.c +1 -0
@@ -32,6 +32,7 @@#include <asm/fixmap.h> #include <asm/opcodes.h> #include <asm/insn.h> +#include <asm/kprobes.h> #define AARCH64_INSN_SF_BIT BIT(31)#define AARCH64_INSN_N_BIT BIT(22)
arch/avr32/include/asm/kprobes.h +4 -0
@@ -11,6 +11,9 @@#ifndef __ASM_AVR32_KPROBES_H#define __ASM_AVR32_KPROBES_H +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/types.h> typedef u16 kprobe_opcode_t ;
@@ -46,4 +49,5 @@ extern int kprobe_exceptions_notify(struct notifier_block *self,#define flush_insn_slot (p) do { } while (0) +#endif /* CONFIG_KPROBES */ #endif /* __ASM_AVR32_KPROBES_H */
arch/blackfin/include/asm/Kbuild +1 -0
@@ -51,3 +51,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/c6x/include/asm/Kbuild +1 -0
@@ -64,3 +64,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += kprobes.h
arch/cris/include/asm/Kbuild +1 -0
@@ -48,3 +48,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/frv/include/asm/Kbuild +1 -0
@@ -11,3 +11,4 @@ generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/h8300/include/asm/Kbuild +1 -0
@@ -78,3 +78,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/hexagon/include/asm/Kbuild +1 -0
@@ -63,3 +63,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/ia64/include/asm/kprobes.h +6 -1
@@ -23,6 +23,10 @@* 2005-Apr Rusty Lynch <[email protected]> and Anil S Keshavamurthy * <[email protected]> adapted from i386 */ +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES +#include <linux/types.h> #include <linux/ptrace.h> #include <linux/percpu.h>
@@ -124,4 +128,5 @@ extern void invalidate_stacked_regs(void);extern void flush_register_stack (void );extern void arch_remove_kprobe (struct kprobe *p); -#endif /* _ASM_KPROBES_H */ +#endif /* CONFIG_KPROBES */ +#endif /* _ASM_KPROBES_H */
arch/m32r/include/asm/Kbuild +1 -0
@@ -14,3 +14,4 @@ generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/m68k/include/asm/Kbuild +1 -0
@@ -38,3 +38,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/metag/include/asm/Kbuild +1 -0
@@ -59,3 +59,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/microblaze/include/asm/Kbuild +1 -0
@@ -14,3 +14,4 @@ generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/mips/include/asm/kprobes.h +5 -1
@@ -22,6 +22,9 @@#ifndef _ASM_KPROBES_H#define _ASM_KPROBES_H +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/ptrace.h> #include <linux/types.h>
@@ -94,4 +97,5 @@ struct kprobe_ctlblk {extern int kprobe_exceptions_notify (struct notifier_block *self,unsigned long val,void *data); -#endif /* _ASM_KPROBES_H */ +#endif /* CONFIG_KPROBES */ +#endif /* _ASM_KPROBES_H */
arch/mn10300/include/asm/kprobes.h +4 -0
@@ -21,6 +21,9 @@#ifndef _ASM_KPROBES_H#define _ASM_KPROBES_H +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/types.h> #include <linux/ptrace.h>
@@ -47,4 +50,5 @@ extern int kprobe_exceptions_notify(struct notifier_block *self,extern void arch_remove_kprobe (struct kprobe *p); +#endif /* CONFIG_KPROBES */ #endif /* _ASM_KPROBES_H */
arch/nios2/include/asm/Kbuild +1 -0
@@ -66,3 +66,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/openrisc/include/asm/Kbuild +1 -0
@@ -74,3 +74,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/parisc/include/asm/Kbuild +1 -0
@@ -32,3 +32,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/powerpc/include/asm/kprobes.h +6 -0
@@ -1,5 +1,9 @@#ifndef _ASM_POWERPC_KPROBES_H#define _ASM_POWERPC_KPROBES_H + +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #ifdef __KERNEL__/* * Kernel Probes (KProbes)
@@ -127,5 +131,7 @@ struct kprobe_ctlblk {extern int kprobe_exceptions_notify (struct notifier_block *self,unsigned long val,void *data);extern int kprobe_fault_handler (struct pt_regs *regs,int trapnr); +#endif /* __KERNEL__ */ +#endif /* CONFIG_KPROBES */ #endif /* _ASM_POWERPC_KPROBES_H */
arch/s390/include/asm/kprobes.h +4 -0
@@ -27,6 +27,9 @@* 2005-Dec Used as a template for s390 by Mike Grundy * <[email protected]> */ +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/types.h> #include <linux/ptrace.h> #include <linux/percpu.h>
@@ -91,4 +94,5 @@ int probe_is_insn_relative_long(u16 *insn);#define flush_insn_slot (p) do { } while (0) +#endif /* CONFIG_KPROBES */ #endif /* _ASM_S390_KPROBES_H */
arch/score/include/asm/Kbuild +1 -0
@@ -17,3 +17,4 @@ generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/sh/include/asm/kprobes.h +2 -0
@@ -1,6 +1,8 @@#ifndef __ASM_SH_KPROBES_H#define __ASM_SH_KPROBES_H +#include <asm-generic/kprobes.h> +#ifdef CONFIG_KPROBES #include <linux/types.h>
arch/sparc/include/asm/kprobes.h +5 -0
@@ -1,6 +1,9 @@#ifndef _SPARC64_KPROBES_H#define _SPARC64_KPROBES_H +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/types.h> #include <linux/percpu.h>
@@ -48,4 +51,6 @@ int kprobe_exceptions_notify(struct notifier_block *self,int kprobe_fault_handler (struct pt_regs *regs,int trapnr); asmlinkage void __kprobes kprobe_trap(unsigned long trap_level,struct pt_regs *regs); + +#endif /* CONFIG_KPROBES */ #endif /* _SPARC64_KPROBES_H */
arch/tile/include/asm/kprobes.h +5 -1
@@ -17,10 +17,13 @@#ifndef _ASM_TILE_KPROBES_H#define _ASM_TILE_KPROBES_H +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES +#include <linux/types.h> #include <linux/ptrace.h> #include <linux/percpu.h> -#include <arch/opcode.h> #define __ARCH_WANT_KPROBES_INSN_SLOT
@@ -76,4 +79,5 @@ void arch_remove_kprobe(struct kprobe *);extern int kprobe_exceptions_notify (struct notifier_block *self,unsigned long val,void *data); +#endif /* CONFIG_KPROBES */ #endif /* _ASM_TILE_KPROBES_H */
arch/um/include/asm/Kbuild +1 -0
@@ -30,3 +30,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/unicore32/include/asm/Kbuild +1 -0
@@ -66,3 +66,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/x86/include/asm/kprobes.h +6 -0
@@ -21,6 +21,10 @@* * See arch/x86/kernel/kprobes.c for x86 kprobes history. */ + +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/types.h> #include <linux/ptrace.h> #include <linux/percpu.h>
@@ -116,4 +120,6 @@ extern int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *data);extern int kprobe_int3_handler (struct pt_regs *regs);extern int kprobe_debug_handler (struct pt_regs *regs); + +#endif /* CONFIG_KPROBES */ #endif /* _ASM_X86_KPROBES_H */
arch/xtensa/include/asm/Kbuild +1 -0
@@ -34,3 +34,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
include/asm-generic/kprobes.h new file +25 -0
@@ -0,0 +1,25 @@ +#ifndef _ASM_GENERIC_KPROBES_H +#define _ASM_GENERIC_KPROBES_H + +#if defined(__KERNEL__) && !defined(__ASSEMBLY__) +#ifdef CONFIG_KPROBES +/* +* Blacklist ganerating macro. Specify functions which is not probed +* by using this macro. +*/ +# define __NOKPROBE_SYMBOL (fname) \ +static unsigned long __used \ + __attribute__((__section__("_kprobe_blacklist"))) \ + _kbl_addr_##fname = (unsigned long)fname; +# define NOKPROBE_SYMBOL (fname) __NOKPROBE_SYMBOL(fname) +/* Use this to forbid a kprobes attach on very low level functions */ +# define __kprobes __attribute__((__section__(".kprobes.text"))) +# define nokprobe_inline __always_inline +#else +# define NOKPROBE_SYMBOL (fname) +# define __kprobes +# define nokprobe_inline inline +#endif +#endif /* defined(__KERNEL__) && !defined(__ASSEMBLY__) */ + +#endif /* _ASM_GENERIC_KPROBES_H */
include/linux/compiler.h +0 -8
@@ -542,12 +542,4 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s (_________p1); \ }) -/* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */ -#ifdef CONFIG_KPROBES -# define __kprobes __attribute__((__section__(".kprobes.text"))) -# define nokprobe_inline __always_inline -#else -# define __kprobes -# define nokprobe_inline inline -#endif #endif /* __LINUX_COMPILER_H */
include/linux/kprobes.h +3 -16
@@ -29,7 +29,7 @@* <[email protected]> and Prasanna S Panchamukhi * <[email protected]> added function-return probes. */ -#include <linux/compiler.h> /* for __kprobes */ +#include <linux/compiler.h> #include <linux/linkage.h> #include <linux/list.h> #include <linux/notifier.h>
@@ -40,9 +40,9 @@#include <linux/rcupdate.h> #include <linux/mutex.h> #include <linux/ftrace.h> +#include <asm/kprobes.h> #ifdef CONFIG_KPROBES -#include <asm/kprobes.h> /* kprobe_status settings */ #define KPROBE_HIT_ACTIVE 0x00000001
@@ -51,6 +51,7 @@ #define KPROBE_HIT_SSDONE 0x00000008 #else /* CONFIG_KPROBES */ +#include <asm-generic/kprobes.h> typedef int kprobe_opcode_t; struct arch_specific_insn { int dummy;
@@ -481,18 +482,4 @@ static inline int enable_jprobe(struct jprobe *jp) return enable_kprobe(&jp->kp); } -#ifdef CONFIG_KPROBES -/* -* Blacklist ganerating macro. Specify functions which is not probed -* by using this macro. -*/ -#define __NOKPROBE_SYMBOL (fname) \ -static unsigned long __used \ - __attribute__((section("_kprobe_blacklist"))) \ - _kbl_addr_##fname = (unsigned long)fname; -#define NOKPROBE_SYMBOL (fname) __NOKPROBE_SYMBOL(fname) -#else -#define NOKPROBE_SYMBOL (fname) -#endif -#endif /* _LINUX_KPROBES_H */
Signature · 1 line
2.9.2
Masami Hiramatsu
maintainerRe: [PATCH v4 14/16] kprobes: move kprobe declarations to asm-generic/kprobes.h
Quoted 22 lines · On Fri, 19 Aug 2016 14:34:12 -0700 [email protected] wrote:
From: "Luis R. Rodriguez" <[email protected]>
Often all is needed is these small helpers, instead of
compiler.hor a fullkprobes.h. This is important for asm helpers, in fact even someasm/kprobes.hmake use of these helpers... instead just keep a generic asm file with helpers useful for asm code with the least amount of clutter as possible.Likewise we need now to also address what to do about this file for both when architectures have
CONFIG_HAVE_KPROBES, and when they do not. Then for when architectures haveCONFIG_HAVE_KPROBESbut have disabledCONFIG_KPROBES.Right now most
asm/kprobes.hdo not have guards againstCONFIG_KPROBES, this means most architecture code cannot includeasm/kprobes.hsafely. Correct this and add guards for architectures missing them. Additionally provide architectures that not have kprobes support with the default asm-generic solution. This lets us forceasm/kprobes.hon the headerinclude/linux/kprobes.halways, but most importantly we can now safely include justasm/kprobes.hon architecture code without bringing the full kitchen sink of header files.
Quoted 7 lines
Two architectures already provided a guard against
CONFIG_KPROBESon itskprobes.h: sh, arch. The rest of the architectures needed gaurds added. We avoid including any not-needed headers onasm/kprobes.hunless kprobes have been enabled.In a subsequent atomic change we can try now to remove
compiler.hfrominclude/linux/kprobes.h.
Hmm, this looks a bit overkill... I rather like move it into linux/table.h.
Thanks,
Quoted 598 lines
Signed-off-by Luis R. Rodriguez <[email protected]>--- arch/alpha/include/asm/Kbuild | 1 + arch/arc/include/asm/kprobes.h | 6 ++++-- arch/arm/include/asm/kprobes.h | 4 ++++ arch/arm/probes/decode.h | 1 + arch/arm64/include/asm/kprobes.h | 4 ++++ arch/arm64/kernel/insn.c | 1 + arch/avr32/include/asm/kprobes.h | 4 ++++ arch/blackfin/include/asm/Kbuild | 1 + arch/c6x/include/asm/Kbuild | 1 + arch/cris/include/asm/Kbuild | 1 + arch/frv/include/asm/Kbuild | 1 + arch/h8300/include/asm/Kbuild | 1 + arch/hexagon/include/asm/Kbuild | 1 + arch/ia64/include/asm/kprobes.h | 7 ++++++- arch/m32r/include/asm/Kbuild | 1 + arch/m68k/include/asm/Kbuild | 1 + arch/metag/include/asm/Kbuild | 1 + arch/microblaze/include/asm/Kbuild | 1 + arch/mips/include/asm/kprobes.h | 6 +++++- arch/mn10300/include/asm/kprobes.h | 4 ++++ arch/nios2/include/asm/Kbuild | 1 + arch/openrisc/include/asm/Kbuild | 1 + arch/parisc/include/asm/Kbuild | 1 + arch/powerpc/include/asm/kprobes.h | 6 ++++++ arch/s390/include/asm/kprobes.h | 4 ++++ arch/score/include/asm/Kbuild | 1 + arch/sh/include/asm/kprobes.h | 2 ++ arch/sparc/include/asm/kprobes.h | 5 +++++ arch/tile/include/asm/kprobes.h | 6 +++++- arch/um/include/asm/Kbuild | 1 + arch/unicore32/include/asm/Kbuild | 1 + arch/x86/include/asm/kprobes.h | 6 ++++++ arch/xtensa/include/asm/Kbuild | 1 + include/asm-generic/kprobes.h | 25 +++++++++++++++++++++++++ include/linux/compiler.h | 8 -------- include/linux/kprobes.h | 19 +++---------------- 36 files changed, 107 insertions(+), 29 deletions(-) create mode 100644 include/asm-generic/kprobes.harch/alpha/include/asm/Kbuild +1
-0@@ -13,3 +13,4 @@ generic-y += trace_clock.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.harch/arc/include/asm/kprobes.h +4
-2@@ -9,6 +9,8 @@#ifndef _ARC_KPROBES_H#define _ARC_KPROBES_H +#include <asm-generic/kprobes.h> +#ifdef CONFIG_KPROBES typedef u16 kprobe_opcode_t ;@@ -55,6 +57,6 @@ void trap_is_kprobe(unsigned long address, struct pt_regs *regs);static void trap_is_kprobe (unsigned long address,struct pt_regs *regs) { } -#endif +#endif /* CONFIG_KPROBES */ -#endif +#endif /* _ARC_KPROBES_H */ arch/arm/include/asm/kprobes.h +4
-0@@ -16,6 +16,9 @@#ifndef _ARM_KPROBES_H#define _ARM_KPROBES_H +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/types.h> #include <linux/ptrace.h> #include <linux/notifier.h> @@ -83,4 +86,5 @@ struct arch_optimized_insn {*/ }; +#endif /* CONFIG_KPROBES */ #endif /* _ARM_KPROBES_H */ arch/arm/probes/decode.h +1
-0@@ -22,6 +22,7 @@#include <linux/types.h> #include <linux/stddef.h> #include <asm/probes.h> +#include <asm/kprobes.h> void __init arm_probes_decode_init (void );arch/arm64/include/asm/kprobes.h +4
-0@@ -16,6 +16,9 @@#ifndef _ARM_KPROBES_H#define _ARM_KPROBES_H +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/types.h> #include <linux/ptrace.h> #include <linux/percpu.h> @@ -57,4 +60,5 @@ int kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr);void kretprobe_trampoline (void );void __kprobes *trampoline_probe_handler (struct pt_regs *regs); +#endif /* CONFIG_KPROBES */ #endif /* _ARM_KPROBES_H */ arch/arm64/kernel/insn.c +1
-0@@ -32,6 +32,7 @@#include <asm/fixmap.h> #include <asm/opcodes.h> #include <asm/insn.h> +#include <asm/kprobes.h> #define AARCH64_INSN_SF_BIT BIT(31)#define AARCH64_INSN_N_BIT BIT(22)arch/avr32/include/asm/kprobes.h +4
-0@@ -11,6 +11,9 @@#ifndef __ASM_AVR32_KPROBES_H#define __ASM_AVR32_KPROBES_H +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/types.h> typedef u16 kprobe_opcode_t ;@@ -46,4 +49,5 @@ extern int kprobe_exceptions_notify(struct notifier_block *self,#define flush_insn_slot (p) do { } while (0) +#endif /* CONFIG_KPROBES */ #endif /* __ASM_AVR32_KPROBES_H */ arch/blackfin/include/asm/Kbuild +1
-0@@ -51,3 +51,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.harch/c6x/include/asm/Kbuild +1
-0@@ -64,3 +64,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += kprobes.harch/cris/include/asm/Kbuild +1
-0@@ -48,3 +48,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.harch/frv/include/asm/Kbuild +1
-0@@ -11,3 +11,4 @@ generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.harch/h8300/include/asm/Kbuild +1
-0@@ -78,3 +78,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.harch/hexagon/include/asm/Kbuild +1
-0@@ -63,3 +63,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.harch/ia64/include/asm/kprobes.h +6
-1@@ -23,6 +23,10 @@* 2005-Apr Rusty Lynch <[email protected]> and Anil S Keshavamurthy * <[email protected]> adapted from i386 */ +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES +#include <linux/types.h> #include <linux/ptrace.h> #include <linux/percpu.h> @@ -124,4 +128,5 @@ extern void invalidate_stacked_regs(void);extern void flush_register_stack (void );extern void arch_remove_kprobe (struct kprobe *p); -#endif /* _ASM_KPROBES_H */ +#endif /* CONFIG_KPROBES */ +#endif /* _ASM_KPROBES_H */ arch/m32r/include/asm/Kbuild +1
-0@@ -14,3 +14,4 @@ generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.harch/m68k/include/asm/Kbuild +1
-0@@ -38,3 +38,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.harch/metag/include/asm/Kbuild +1
-0@@ -59,3 +59,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.harch/microblaze/include/asm/Kbuild +1
-0@@ -14,3 +14,4 @@ generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.harch/mips/include/asm/kprobes.h +5
-1@@ -22,6 +22,9 @@#ifndef _ASM_KPROBES_H#define _ASM_KPROBES_H +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/ptrace.h> #include <linux/types.h> @@ -94,4 +97,5 @@ struct kprobe_ctlblk {extern int kprobe_exceptions_notify (struct notifier_block *self,unsigned long val,void *data); -#endif /* _ASM_KPROBES_H */ +#endif /* CONFIG_KPROBES */ +#endif /* _ASM_KPROBES_H */ arch/mn10300/include/asm/kprobes.h +4
-0@@ -21,6 +21,9 @@#ifndef _ASM_KPROBES_H#define _ASM_KPROBES_H +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/types.h> #include <linux/ptrace.h> @@ -47,4 +50,5 @@ extern int kprobe_exceptions_notify(struct notifier_block *self,extern void arch_remove_kprobe (struct kprobe *p); +#endif /* CONFIG_KPROBES */ #endif /* _ASM_KPROBES_H */ arch/nios2/include/asm/Kbuild +1
-0@@ -66,3 +66,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.harch/openrisc/include/asm/Kbuild +1
-0@@ -74,3 +74,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.harch/parisc/include/asm/Kbuild +1
-0@@ -32,3 +32,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.harch/powerpc/include/asm/kprobes.h +6
-0@@ -1,5 +1,9 @@#ifndef _ASM_POWERPC_KPROBES_H#define _ASM_POWERPC_KPROBES_H + +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #ifdef __KERNEL__/* * Kernel Probes (KProbes) @@ -127,5 +131,7 @@ struct kprobe_ctlblk {extern int kprobe_exceptions_notify (struct notifier_block *self,unsigned long val,void *data);extern int kprobe_fault_handler (struct pt_regs *regs,int trapnr); +#endif /* __KERNEL__ */ +#endif /* CONFIG_KPROBES */ #endif /* _ASM_POWERPC_KPROBES_H */ arch/s390/include/asm/kprobes.h +4
-0@@ -27,6 +27,9 @@* 2005-Dec Used as a template for s390 by Mike Grundy * <[email protected]> */ +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/types.h> #include <linux/ptrace.h> #include <linux/percpu.h> @@ -91,4 +94,5 @@ int probe_is_insn_relative_long(u16 *insn);#define flush_insn_slot (p) do { } while (0) +#endif /* CONFIG_KPROBES */ #endif /* _ASM_S390_KPROBES_H */ arch/score/include/asm/Kbuild +1
-0@@ -17,3 +17,4 @@ generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.harch/sh/include/asm/kprobes.h +2
-0@@ -1,6 +1,8 @@#ifndef __ASM_SH_KPROBES_H#define __ASM_SH_KPROBES_H +#include <asm-generic/kprobes.h> +#ifdef CONFIG_KPROBES #include <linux/types.h> arch/sparc/include/asm/kprobes.h +5
-0@@ -1,6 +1,9 @@#ifndef _SPARC64_KPROBES_H#define _SPARC64_KPROBES_H +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/types.h> #include <linux/percpu.h> @@ -48,4 +51,6 @@ int kprobe_exceptions_notify(struct notifier_block *self,int kprobe_fault_handler (struct pt_regs *regs,int trapnr); asmlinkage void __kprobes kprobe_trap(unsigned long trap_level,struct pt_regs *regs); + +#endif /* CONFIG_KPROBES */ #endif /* _SPARC64_KPROBES_H */ arch/tile/include/asm/kprobes.h +5
-1@@ -17,10 +17,13 @@#ifndef _ASM_TILE_KPROBES_H#define _ASM_TILE_KPROBES_H +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES +#include <linux/types.h> #include <linux/ptrace.h> #include <linux/percpu.h> -#include <arch/opcode.h> #define __ARCH_WANT_KPROBES_INSN_SLOT@@ -76,4 +79,5 @@ void arch_remove_kprobe(struct kprobe *);extern int kprobe_exceptions_notify (struct notifier_block *self,unsigned long val,void *data); +#endif /* CONFIG_KPROBES */ #endif /* _ASM_TILE_KPROBES_H */ arch/um/include/asm/Kbuild +1
-0@@ -30,3 +30,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.harch/unicore32/include/asm/Kbuild +1
-0@@ -66,3 +66,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.harch/x86/include/asm/kprobes.h +6
-0@@ -21,6 +21,10 @@* * See arch/x86/kernel/kprobes.c for x86 kprobes history. */ + +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/types.h> #include <linux/ptrace.h> #include <linux/percpu.h> @@ -116,4 +120,6 @@ extern int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *data);extern int kprobe_int3_handler (struct pt_regs *regs);extern int kprobe_debug_handler (struct pt_regs *regs); + +#endif /* CONFIG_KPROBES */ #endif /* _ASM_X86_KPROBES_H */ arch/xtensa/include/asm/Kbuild +1
-0@@ -34,3 +34,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.hinclude/asm-generic/kprobes.h new file +25
-0@@ -0,0 +1,25 @@ +#ifndef _ASM_GENERIC_KPROBES_H +#define _ASM_GENERIC_KPROBES_H + +#if defined(__KERNEL__) && !defined(__ASSEMBLY__) +#ifdef CONFIG_KPROBES +/* +* Blacklist ganerating macro. Specify functions which is not probed +* by using this macro. +*/ +# define __NOKPROBE_SYMBOL (fname) \ +static unsigned long __used \ + __attribute__((__section__("_kprobe_blacklist"))) \ + _kbl_addr_##fname = (unsigned long)fname; +# define NOKPROBE_SYMBOL (fname) __NOKPROBE_SYMBOL(fname) +/* Use this to forbid a kprobes attach on very low level functions */ +# define __kprobes __attribute__((__section__(".kprobes.text"))) +# define nokprobe_inline __always_inline +#else +# define NOKPROBE_SYMBOL (fname) +# define __kprobes +# define nokprobe_inline inline +#endif +#endif /* defined(__KERNEL__) && !defined(__ASSEMBLY__) */ + +#endif /* _ASM_GENERIC_KPROBES_H */ include/linux/compiler.h +0
-8@@ -542,12 +542,4 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s (_________p1); \ }) -/* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */ -#ifdef CONFIG_KPROBES -# define __kprobes __attribute__((__section__(".kprobes.text"))) -# define nokprobe_inline __always_inline -#else -# define __kprobes -# define nokprobe_inline inline -#endif #endif /* __LINUX_COMPILER_H */ include/linux/kprobes.h +3
-16@@ -29,7 +29,7 @@* <[email protected]> and Prasanna S Panchamukhi * <[email protected]> added function-return probes. */ -#include <linux/compiler.h> /* for __kprobes */ +#include <linux/compiler.h> #include <linux/linkage.h> #include <linux/list.h> #include <linux/notifier.h> @@ -40,9 +40,9 @@#include <linux/rcupdate.h> #include <linux/mutex.h> #include <linux/ftrace.h> +#include <asm/kprobes.h> #ifdef CONFIG_KPROBES -#include <asm/kprobes.h> /* kprobe_status settings */ #define KPROBE_HIT_ACTIVE 0x00000001@@ -51,6 +51,7 @@ #define KPROBE_HIT_SSDONE 0x00000008 #else /* CONFIG_KPROBES */ +#include <asm-generic/kprobes.h> typedef int kprobe_opcode_t; struct arch_specific_insn { int dummy;@@ -481,18 +482,4 @@ static inline int enable_jprobe(struct jprobe *jp) return enable_kprobe(&jp->kp); } -#ifdef CONFIG_KPROBES -/* -* Blacklist ganerating macro. Specify functions which is not probed -* by using this macro. -*/ -#define __NOKPROBE_SYMBOL (fname) \ -static unsigned long __used \ - __attribute__((section("_kprobe_blacklist"))) \ - _kbl_addr_##fname = (unsigned long)fname; -#define NOKPROBE_SYMBOL (fname) __NOKPROBE_SYMBOL(fname) -#else -#define NOKPROBE_SYMBOL (fname) -#endif -#endif /* _LINUX_KPROBES_H */ Signature · 1 line
2.9.2
Signature · 6 lines
Masami Hiramatsu <[email protected]> _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Luis R. Rodriguez
maintainerRe: [PATCH v4 14/16] kprobes: move kprobe declarations to asm-generic/kprobes.h
Quoted 30 lines · Masami Hiramatsu
Quoted 27 lines · On Fri, 19 Aug 2016 14:34:12 -0700 [email protected] wrote:
From: "Luis R. Rodriguez" <[email protected]>
Often all is needed is these small helpers, instead of
compiler.hor a fullkprobes.h. This is important for asm helpers, in fact even someasm/kprobes.hmake use of these helpers... instead just keep a generic asm file with helpers useful for asm code with the least amount of clutter as possible.Likewise we need now to also address what to do about this file for both when architectures have
CONFIG_HAVE_KPROBES, and when they do not. Then for when architectures haveCONFIG_HAVE_KPROBESbut have disabledCONFIG_KPROBES.Right now most
asm/kprobes.hdo not have guards againstCONFIG_KPROBES, this means most architecture code cannot includeasm/kprobes.hsafely. Correct this and add guards for architectures missing them. Additionally provide architectures that not have kprobes support with the default asm-generic solution. This lets us forceasm/kprobes.hon the headerinclude/linux/kprobes.halways, but most importantly we can now safely include justasm/kprobes.hon architecture code without bringing the full kitchen sink of header files.Two architectures already provided a guard against
CONFIG_KPROBESon itskprobes.h: sh, arch. The rest of the architectures needed gaurds added. We avoid including any not-needed headers onasm/kprobes.hunless kprobes have been enabled.
Quoted 4 lines
Quoted 2 lines
In a subsequent atomic change we can try now to remove
compiler.hfrominclude/linux/kprobes.h.Hmm, this looks a bit overkill... I rather like move it into
linux/table.h.
That's the thing, we can't reasonably expect every table to add an entry into table.h, this should be up to each user. Moving it to tables.h just prolongs what needs to be done. In this case the change is justifiable given kprobe annotations are required for some architectures early in architecture code, and including compiler.h on early architecture code blows up. There is no easy fix to this, and this this was *actually* the cleanest solution I could devise without much changes.
Luis
Re: [PATCH v4 14/16] kprobes: move kprobe declarations to asm-generic/kprobes.h
Quoted 36 lines · On Tue, 23 Aug 2016 18:31:05 +0200 "Luis R. Rodriguez" <[email protected]>…
Quoted 30 lines · Masami Hiramatsu
Quoted 27 lines · On Fri, 19 Aug 2016 14:34:12 -0700 [email protected] wrote:
From: "Luis R. Rodriguez" <[email protected]>
Often all is needed is these small helpers, instead of
compiler.hor a fullkprobes.h. This is important for asm helpers, in fact even someasm/kprobes.hmake use of these helpers... instead just keep a generic asm file with helpers useful for asm code with the least amount of clutter as possible.Likewise we need now to also address what to do about this file for both when architectures have
CONFIG_HAVE_KPROBES, and when they do not. Then for when architectures haveCONFIG_HAVE_KPROBESbut have disabledCONFIG_KPROBES.Right now most
asm/kprobes.hdo not have guards againstCONFIG_KPROBES, this means most architecture code cannot includeasm/kprobes.hsafely. Correct this and add guards for architectures missing them. Additionally provide architectures that not have kprobes support with the default asm-generic solution. This lets us forceasm/kprobes.hon the headerinclude/linux/kprobes.halways, but most importantly we can now safely include justasm/kprobes.hon architecture code without bringing the full kitchen sink of header files.Two architectures already provided a guard against
CONFIG_KPROBESon itskprobes.h: sh, arch. The rest of the architectures needed gaurds added. We avoid including any not-needed headers onasm/kprobes.hunless kprobes have been enabled.Quoted 4 lines
Quoted 2 lines
In a subsequent atomic change we can try now to remove
compiler.hfrominclude/linux/kprobes.h.Hmm, this looks a bit overkill... I rather like move it into
linux/table.h.
Quoted 7 lines
That's the thing, we can't reasonably expect every table to add an entry into
table.h, this should be up to each user. Moving it totables.hjust prolongs what needs to be done. In this case the change is justifiable given kprobe annotations are required for some architectures early in architecture code, and includingcompiler.hon early architecture code blows up. There is no easy fix to this, and this this was *actually* the cleanest solution I could devise without much changes.
Aah, I misread your patch, it is asm-generic/kprobes.h, not asm/kprobes.h. I think it is OK now.
Thanks!
Quoted 2 lines
Luis
Signature · 1 line
Masami Hiramatsu <[email protected]>
Luis R. Rodriguez
maintainerRe: [PATCH v4 14/16] kprobes: move kprobe declarations to asm-generic/kprobes.h
Quoted 47 lines · Masami Hiramatsu
Quoted 36 lines · On Tue, 23 Aug 2016 18:31:05 +0200 "Luis R. Rodriguez" <[email protected]>…
Quoted 30 lines · Masami Hiramatsu
Quoted 27 lines · On Fri, 19 Aug 2016 14:34:12 -0700 [email protected] wrote:
From: "Luis R. Rodriguez" <[email protected]>
Often all is needed is these small helpers, instead of
compiler.hor a fullkprobes.h. This is important for asm helpers, in fact even someasm/kprobes.hmake use of these helpers... instead just keep a generic asm file with helpers useful for asm code with the least amount of clutter as possible.Likewise we need now to also address what to do about this file for both when architectures have
CONFIG_HAVE_KPROBES, and when they do not. Then for when architectures haveCONFIG_HAVE_KPROBESbut have disabledCONFIG_KPROBES.Right now most
asm/kprobes.hdo not have guards againstCONFIG_KPROBES, this means most architecture code cannot includeasm/kprobes.hsafely. Correct this and add guards for architectures missing them. Additionally provide architectures that not have kprobes support with the default asm-generic solution. This lets us forceasm/kprobes.hon the headerinclude/linux/kprobes.halways, but most importantly we can now safely include justasm/kprobes.hon architecture code without bringing the full kitchen sink of header files.Two architectures already provided a guard against
CONFIG_KPROBESon itskprobes.h: sh, arch. The rest of the architectures needed gaurds added. We avoid including any not-needed headers onasm/kprobes.hunless kprobes have been enabled.Quoted 4 lines
Quoted 2 lines
In a subsequent atomic change we can try now to remove
compiler.hfrominclude/linux/kprobes.h.Hmm, this looks a bit overkill... I rather like move it into
linux/table.h.Quoted 7 lines
That's the thing, we can't reasonably expect every table to add an entry into
table.h, this should be up to each user. Moving it totables.hjust prolongs what needs to be done. In this case the change is justifiable given kprobe annotations are required for some architectures early in architecture code, and includingcompiler.hon early architecture code blows up. There is no easy fix to this, and this this was *actually* the cleanest solution I could devise without much changes.
Quoted 4 lines
Aah, I misread your patch, it is
asm-generic/kprobes.h, notasm/kprobes.h. I think it is OK now.Acked-by Masami Hiramatsu <[email protected]>
Thanks! Can you also review: patch 15:
kprobes: port .kprobes.text to section range
Luis
Luis R. Rodriguez
maintainerRe: [PATCH v4 14/16] kprobes: move kprobe declarations to asm-generic/kprobes.h
In reply to Masami HiramatsuQuoted 47 lines · Masami Hiramatsu
Quoted 36 lines · On Tue, 23 Aug 2016 18:31:05 +0200 "Luis R. Rodriguez" <[email protected]>…
Quoted 30 lines · Masami Hiramatsu
Quoted 27 lines · On Fri, 19 Aug 2016 14:34:12 -0700 [email protected] wrote:
From: "Luis R. Rodriguez" <[email protected]>
Often all is needed is these small helpers, instead of
compiler.hor a fullkprobes.h. This is important for asm helpers, in fact even someasm/kprobes.hmake use of these helpers... instead just keep a generic asm file with helpers useful for asm code with the least amount of clutter as possible.Likewise we need now to also address what to do about this file for both when architectures have
CONFIG_HAVE_KPROBES, and when they do not. Then for when architectures haveCONFIG_HAVE_KPROBESbut have disabledCONFIG_KPROBES.Right now most
asm/kprobes.hdo not have guards againstCONFIG_KPROBES, this means most architecture code cannot includeasm/kprobes.hsafely. Correct this and add guards for architectures missing them. Additionally provide architectures that not have kprobes support with the default asm-generic solution. This lets us forceasm/kprobes.hon the headerinclude/linux/kprobes.halways, but most importantly we can now safely include justasm/kprobes.hon architecture code without bringing the full kitchen sink of header files.Two architectures already provided a guard against
CONFIG_KPROBESon itskprobes.h: sh, arch. The rest of the architectures needed gaurds added. We avoid including any not-needed headers onasm/kprobes.hunless kprobes have been enabled.Quoted 4 lines
Quoted 2 lines
In a subsequent atomic change we can try now to remove
compiler.hfrominclude/linux/kprobes.h.Hmm, this looks a bit overkill... I rather like move it into
linux/table.h.Quoted 7 lines
That's the thing, we can't reasonably expect every table to add an entry into
table.h, this should be up to each user. Moving it totables.hjust prolongs what needs to be done. In this case the change is justifiable given kprobe annotations are required for some architectures early in architecture code, and includingcompiler.hon early architecture code blows up. There is no easy fix to this, and this this was *actually* the cleanest solution I could devise without much changes.
Quoted 4 lines
Aah, I misread your patch, it is
asm-generic/kprobes.h, notasm/kprobes.h. I think it is OK now.Acked-by Masami Hiramatsu <[email protected]>
I'm going to send this patch out separately shortly as its independent.
Luis
[email protected]
maintainerPATCH v4 15/16 kprobes: port .kprobes.text to section range
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
kprobe makes use of two custom sections, each custom section is folded into one of the standard Linux sections types as follows, it currently relies on the linker script to fold the custom section onto the respective Linux section:
type Linux-section custom section name begin end table .init.data _kprobe_blacklist __start_kprobe_blacklist __stop_kprobe_blacklist range .text .kprobes.text __kprobes_text_start __kprobes_text_end
This ports the .kprobes.text custom section to the standard Linux ranges API allowing us remove all the custom kprobe section declarations from the linker script.
Tested with CONFIG_KPROBES_SANITY_TEST, it passes with:
Kprobe smoke test: started
Kprobe smoke test: passed successfully
Then tested CONFIG_SAMPLE_KPROBES on do_fork, and the kprobe bites and kicks as expected.
Also ran ./ftracetest with no issues:
$ sudo ./ftracetest === Ftrace unit tests === [1] Basic trace file check [PASS] [2] Basic test for tracers [PASS] [3] Basic trace clock test [PASS] [4] Basic event tracing check [PASS] [5] event tracing - enable/disable with event level files [PASS] [6] event tracing - restricts events based on pid [PASS] [7] event tracing - enable/disable with subsystem level files [PASS] [8] event tracing - enable/disable with top level files [PASS] [9] ftrace - function graph filters with stack tracer [PASS] [10] ftrace - function graph filters [PASS] [11] ftrace - function profiler with function tracing [PASS] [12] Test creation and deletion of trace instances while setting an event[PASS] [13] Test creation and deletion of trace instances [PASS] [14] Kprobe dynamic event - adding and removing [PASS] [15] Kprobe dynamic event - busy event check [PASS] [16] Kprobe dynamic event with arguments [PASS] [17] Kprobe dynamic event with function tracer [PASS] [18] Kretprobe dynamic event with arguments [PASS] [19] event trigger - test event enable/disable trigger [PASS] [20] event trigger - test trigger filter [PASS] [21] event trigger - test histogram modifiers [PASS] [22] event trigger - test histogram trigger [PASS] [23] event trigger - test multiple histogram triggers [PASS] [24] event trigger - test snapshot-trigger [PASS] [25] event trigger - test stacktrace-trigger [PASS] [26] event trigger - test traceon/off trigger [PASS]
# of passed: 26 # of failed: 0 # of unresolved: 0 # of untested: 0 # of unsupported: 0 # of xfailed: 0 # of undefined(test bug): 0
v4:
o arm64 build fixes with allmodconfig
o build fix suggested for avr32 with allnoconfig, otherwise we end up with:
arch/avr32/kernel/built-in.o: In function `save_full_context_ex':
(.ex.text+0x1c4): relocation truncated to fit: R_AVR32_16N_PCREL against symbol `debug_trampoline' defined in .text.rng.kprobes.any section in arch/avr32/kernel/built-in.oarch/avr32/kernel/built-in.o: In function `debug_exit_work':
(.text.rng.kprobes.any+0xa8): relocation truncated to fit:R_AVR32_16N_PCREL against `.ex.text'+3aa
make: *** [Makefile:953: vmlinux] Error 1
o open-code section use on scripts/ code -- folks to prefer the simplicity over dealing with having more tool code access kernel headers.
o NOPE: include #include <asm-generic/ranges.h> on compiler.h -- solves a few 0-day compilation issues
v3:
o after v2 arch/arm/kernel/vmlinux-xip.lds.S got kprobe support, this just removes the custom linker script reference to kprobes as that is no longer needed with linker tables.
o split kprobe linker table and kprobe section ranges use into two separate patches. This should make it easier to review and also demos both distinct use types, one a linker table another a simple section range.
v2: introduced this patch in this series
--- arch/arc/kernel/vmlinux.lds.S | 1 - arch/arm/kernel/entry-armv.S | 3 ++- arch/arm/kernel/vmlinux-xip.lds.S | 1 - arch/arm/kernel/vmlinux.lds.S | 1 - arch/arm64/kernel/armv8_deprecated.c | 1 + arch/arm64/kernel/probes/kprobes.c | 4 ++-- arch/arm64/kernel/vmlinux.lds.S | 1 - arch/avr32/kernel/entry-avr32b.S | 13 +++++++++++-- arch/avr32/kernel/vmlinux.lds.S | 1 - arch/blackfin/kernel/vmlinux.lds.S | 1 - arch/c6x/kernel/vmlinux.lds.S | 1 - arch/hexagon/kernel/vmlinux.lds.S | 1 - arch/ia64/kernel/jprobes.S | 3 ++- arch/ia64/kernel/vmlinux.lds.S | 1 - arch/ia64/lib/flush.S | 6 +++--- arch/metag/kernel/vmlinux.lds.S | 1 - arch/microblaze/kernel/vmlinux.lds.S | 1 - arch/mips/kernel/vmlinux.lds.S | 1 - arch/mn10300/kernel/vmlinux.lds.S | 1 - arch/nios2/kernel/vmlinux.lds.S | 1 - arch/openrisc/kernel/vmlinux.lds.S | 1 - arch/parisc/kernel/vmlinux.lds.S | 1 - arch/powerpc/include/asm/ppc_asm.h | 7 ++++--- arch/powerpc/kernel/vmlinux.lds.S | 1 - arch/s390/kernel/entry.S | 5 +++-- arch/s390/kernel/kprobes.c | 6 +++--- arch/s390/kernel/mcount.S | 3 ++- arch/s390/kernel/vmlinux.lds.S | 1 - arch/score/kernel/vmlinux.lds.S | 1 - arch/sh/kernel/vmlinux.lds.S | 1 - arch/sparc/kernel/vmlinux.lds.S | 1 - arch/sparc/mm/ultra.S | 3 ++- arch/tile/kernel/vmlinux.lds.S | 1 - arch/x86/kernel/kprobes/core.c | 11 +++++------ arch/x86/kernel/vmlinux.lds.S | 1 - include/asm-generic/kprobes.h | 3 ++- include/asm-generic/sections.h | 2 -- include/asm-generic/vmlinux.lds.h | 6 ------ include/linux/kprobes.h | 3 +++ kernel/kprobes.c | 6 ++++-- scripts/mod/modpost.c | 2 +- scripts/recordmcount.c | 2 +- scripts/recordmcount.pl | 2 +- 43 files changed, 52 insertions(+), 62 deletions(-)
arch/arc/kernel/vmlinux.lds.S +0 -1
@@ -98,7 +98,6 @@ SECTIONS TEXT_TEXT SCHED_TEXT LOCK_TEXT - KPROBES_TEXT *(.fixup) *(.gnu.warning) }
arch/arm/kernel/entry-armv.S +2 -1
@@ -34,6 +34,7 @@ #include "entry-header.S" #include <asm/entry-macro-multi.S> #include <asm/probes.h> +#include <asm/ranges.h> /* * Interrupt handling.
@@ -83,7 +84,7 @@ .endm #ifdef CONFIG_KPROBES - .section .kprobes.text,"ax",%progbits + set_section_rng_type(SECTION_TEXT, kprobes, ax, %progbits) #else .text #endif
arch/arm/kernel/vmlinux-xip.lds.S +0 -1
@@ -99,7 +99,6 @@ SECTIONS TEXT_TEXT SCHED_TEXT LOCK_TEXT - KPROBES_TEXT *(.gnu.warning) *(.glue_7) *(.glue_7t)
arch/arm/kernel/vmlinux.lds.S +0 -1
@@ -113,7 +113,6 @@ SECTIONS SCHED_TEXT LOCK_TEXT HYPERVISOR_TEXT - KPROBES_TEXT *(.gnu.warning) *(.glue_7) *(.glue_7t)
arch/arm64/kernel/armv8_deprecated.c +1 -0
@@ -23,6 +23,7 @@#include <asm/traps.h> #include <asm/uaccess.h> #include <asm/cpufeature.h> +#include <asm/kprobes.h> #define CREATE_TRACE_POINTS #include "trace-events-emulation.h"
arch/arm64/kernel/probes/kprobes.c +2 -2
@@ -23,6 +23,7 @@#include <linux/slab.h> #include <linux/stop_machine.h> #include <linux/stringify.h> +#include <linux/ranges.h> #include <asm/traps.h> #include <asm/ptrace.h> #include <asm/cacheflush.h>
@@ -546,8 +547,7 @@ bool arch_within_kprobe_blacklist(unsigned long addr)extern char __idmap_text_start[], __idmap_text_end[];extern char __hyp_idmap_text_start[], __hyp_idmap_text_end[]; - if ((addr >= (unsigned long)__kprobes_text_start && - addr < (unsigned long)__kprobes_text_end) || + if (SECTION_ADDR_IN_RANGE(kprobes, addr) || (addr >= (unsigned long)__entry_text_start && addr < (unsigned long)__entry_text_end) || (addr >= (unsigned long)__idmap_text_start &&
arch/arm64/kernel/vmlinux.lds.S +0 -1
@@ -123,7 +123,6 @@ SECTIONS TEXT_TEXT SCHED_TEXT LOCK_TEXT - KPROBES_TEXT HYPERVISOR_TEXT IDMAP_TEXT HIBERNATE_TEXT
arch/avr32/kernel/entry-avr32b.S +11 -2
@@ -23,6 +23,7 @@ #include <asm/sysreg.h> #include <asm/thread_info.h> #include <asm/unistd.h> +#include <asm/ranges.h> #ifdef CONFIG_PREEMPT # define preempt_stop mask_interrupts
@@ -605,7 +606,11 @@ fault_exit_work: brcc fault_resume_user rjmp enter_monitor_mode - .section .kprobes.text, "ax", @progbits +#ifdef CONFIG_KPROBES + set_section_rng_type(SECTION_TEXT, kprobes, ax, @progbits) +#else + .text +#endif .type handle_debug, @function handle_debug: sub sp, 4 /* r12_orig */
@@ -826,7 +831,11 @@ irq_level\level: IRQ_LEVEL 2 IRQ_LEVEL 3 - .section .kprobes.text, "ax", @progbits +#ifdef CONFIG_KPROBES + set_section_rng_type(SECTION_TEXT, kprobes, ax, @progbits) +#else + .text +#endif .type enter_monitor_mode, @function enter_monitor_mode: /*
arch/avr32/kernel/vmlinux.lds.S +0 -1
@@ -49,7 +49,6 @@ SECTIONS _stext = .; *(.ex.text) *(.irq.text) - KPROBES_TEXT TEXT_TEXT SCHED_TEXT LOCK_TEXT
arch/blackfin/kernel/vmlinux.lds.S +0 -1
@@ -36,7 +36,6 @@ SECTIONS LOCK_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT - KPROBES_TEXT #ifdef CONFIG_ROMKERNEL __sinittext = .; INIT_TEXT
arch/c6x/kernel/vmlinux.lds.S +0 -1
@@ -73,7 +73,6 @@ SECTIONS LOCK_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT - KPROBES_TEXT *(.fixup) *(.gnu.warning) }
arch/hexagon/kernel/vmlinux.lds.S +0 -1
@@ -51,7 +51,6 @@ SECTIONS TEXT_TEXT SCHED_TEXT LOCK_TEXT - KPROBES_TEXT *(.fixup) } _etext = .;
arch/ia64/kernel/jprobes.S +2 -1
@@ -46,11 +46,12 @@ */ #include <asm/asmmacro.h> #include <asm/break.h> +#include <asm/ranges.h> /* * void jprobe_break(void) */ - .section .kprobes.text, "ax" + set_section_rng(SECTION_TEXT, kprobes, ax) ENTRY(jprobe_break) break.m __IA64_BREAK_JPROBE END(jprobe_break)
arch/ia64/kernel/vmlinux.lds.S +0 -1
@@ -47,7 +47,6 @@ SECTIONS { TEXT_TEXT SCHED_TEXT LOCK_TEXT - KPROBES_TEXT *(.gnu.linkonce.t*) }
arch/ia64/lib/flush.S +3 -3
@@ -9,7 +9,7 @@ #include <asm/asmmacro.h> #include <asm/export.h> - +#include <asm/ranges.h> /* * flush_icache_range(start,end)
@@ -21,7 +21,7 @@ * * Note: "in0" and "in1" are preserved for debugging purposes. */ - .section .kprobes.text,"ax" + set_section_rng(SECTION_TEXT, kprobes, ax) GLOBAL_ENTRY(flush_icache_range) .prologue
@@ -74,7 +74,7 @@ EXPORT_SYMBOL_GPL(flush_icache_range) * * Note: "in0" and "in1" are preserved for debugging purposes. */ - .section .kprobes.text,"ax" + set_section_rng(SECTION_TEXT, kprobes, ax) GLOBAL_ENTRY(clflush_cache_range) .prologue
arch/metag/kernel/vmlinux.lds.S +0 -1
@@ -22,7 +22,6 @@ SECTIONS TEXT_TEXT SCHED_TEXT LOCK_TEXT - KPROBES_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT *(.text.*)
arch/microblaze/kernel/vmlinux.lds.S +0 -1
@@ -34,7 +34,6 @@ SECTIONS { EXIT_CALL SCHED_TEXT LOCK_TEXT - KPROBES_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT . = ALIGN (4) ;
arch/mips/kernel/vmlinux.lds.S +0 -1
@@ -56,7 +56,6 @@ SECTIONS TEXT_TEXT SCHED_TEXT LOCK_TEXT - KPROBES_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT *(.text.*)
arch/mn10300/kernel/vmlinux.lds.S +0 -1
@@ -31,7 +31,6 @@ SECTIONS TEXT_TEXT SCHED_TEXT LOCK_TEXT - KPROBES_TEXT *(.fixup) *(.gnu.warning) } = 0xcb
arch/nios2/kernel/vmlinux.lds.S +0 -1
@@ -40,7 +40,6 @@ SECTIONS LOCK_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT - KPROBES_TEXT } =0 _etext = .;
arch/openrisc/kernel/vmlinux.lds.S +0 -1
@@ -48,7 +48,6 @@ SECTIONS TEXT_TEXT SCHED_TEXT LOCK_TEXT - KPROBES_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT *(.fixup)
arch/parisc/kernel/vmlinux.lds.S +0 -1
@@ -70,7 +70,6 @@ SECTIONS TEXT_TEXT SCHED_TEXT LOCK_TEXT - KPROBES_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT *(.text.do_softirq)
arch/powerpc/include/asm/ppc_asm.h +4 -3
@@ -9,6 +9,7 @@#include <asm/processor.h> #include <asm/ppc-opcode.h> #include <asm/firmware.h> +#include <asm/ranges.h> #ifndef __ASSEMBLY__#error __FILE__ should only be used in assembler files
@@ -218,7 +219,7 @@ name: \ .localentry name,.-name#define _KPROBE (name) \ - .section ".kprobes.text","a"; \ + set_section_rng(SECTION_TEXT, kprobes, a); \ .align 2 ; \ .type name,@function; \ .globl name; \
@@ -248,7 +249,7 @@ GLUE(.,name):#define _GLOBAL_TOC (name) _GLOBAL(name)#define _KPROBE (name) \ - .section ".kprobes.text","a"; \ + set_section_rng(SECTION_TEXT, kprobes, a); \ .align 2 ; \ .globl name; \ .globl GLUE(.,name); \
@@ -280,7 +281,7 @@ n:#define _GLOBAL_TOC (name) _GLOBAL(name)#define _KPROBE (n) \ - .section ".kprobes.text","a"; \ + set_section_rng(SECTION_TEXT, kprobes, a); \ .globl n; \ n:
arch/powerpc/kernel/vmlinux.lds.S +0 -1
@@ -53,7 +53,6 @@ SECTIONS *(.text .fixup __ftr_alt_* .ref.text) SCHED_TEXT LOCK_TEXT - KPROBES_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT
arch/s390/kernel/entry.S +3 -2
@@ -24,6 +24,7 @@ #include <asm/setup.h> #include <asm/nmi.h> #include <asm/export.h> +#include <asm/ranges.h> __PT_R0 = __PT_GPRS __PT_R1 = __PT_GPRS + 8
@@ -163,7 +164,7 @@ _PIF_WORK = (_PIF_PER_TRAP) tm off+\addr, \mask .endm - .section .kprobes.text, "ax" + set_section_rng(SECTION_TEXT, kprobes, ax) .Ldummy: /* * This nop exists only in order to avoid that __switch_to starts at
@@ -981,7 +982,7 @@ ENTRY(restart_int_handler) brc 2,2b 3: j 3b - .section .kprobes.text, "ax" + set_section_rng(SECTION_TEXT, kprobes, ax) #ifdef CONFIG_CHECK_STACK /*
arch/s390/kernel/kprobes.c +3 -3
@@ -287,9 +287,9 @@ static void kprobe_reenter_check(struct kprobe_ctlblk *kcb, struct kprobe *p)case KPROBE_REENTER :default :/* -* A kprobe on the code path to single step an instruction -* is a BUG. The code path resides in the .kprobes.text -* section and is executed with interrupts disabled. +* A kprobe on the code path to single step an instruction is a +* BUG. The code path resides in the kprobes section range and +* is executed with interrupts disabled. */ printk (KERN_EMERG "Invalid kprobe detected at %p.\n" , p->addr);dump_kprobe (p);
arch/s390/kernel/mcount.S +2 -1
@@ -10,8 +10,9 @@ #include <asm/ftrace.h> #include <asm/ptrace.h> #include <asm/export.h> +#include <asm/ranges.h> - .section .kprobes.text, "ax" + set_section_rng(SECTION_TEXT, kprobes, ax) ENTRY(ftrace_stub) br %r14
arch/s390/kernel/vmlinux.lds.S +0 -1
@@ -36,7 +36,6 @@ SECTIONS TEXT_TEXT SCHED_TEXT LOCK_TEXT - KPROBES_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT *(.fixup)
arch/score/kernel/vmlinux.lds.S +0 -1
@@ -41,7 +41,6 @@ SECTIONS TEXT_TEXT SCHED_TEXT LOCK_TEXT - KPROBES_TEXT *(.text.*) *(.fixup) . = ALIGN (4) ;
arch/sh/kernel/vmlinux.lds.S +0 -1
@@ -37,7 +37,6 @@ SECTIONS EXTRA_TEXT SCHED_TEXT LOCK_TEXT - KPROBES_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT *(.fixup)
arch/sparc/kernel/vmlinux.lds.S +0 -1
@@ -50,7 +50,6 @@ SECTIONS TEXT_TEXT SCHED_TEXT LOCK_TEXT - KPROBES_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT *(.gnu.warning)
arch/sparc/mm/ultra.S +2 -1
@@ -16,6 +16,7 @@ #include <asm/cacheflush.h> #include <asm/hypervisor.h> #include <asm/cpudata.h> +#include <asm/ranges.h> /* Basically, most of the Spitfire vs. Cheetah madness * has to do with the fact that Cheetah does not support
@@ -148,7 +149,7 @@ __spitfire_flush_tlb_mm_slow: /* * The following code flushes one page_size worth. */ - .section .kprobes.text, "ax" + set_section_rng(SECTION_TEXT, kprobes, ax) .align 32 .globl __flush_icache_page __flush_icache_page: /* %o0 = phys_page */
arch/tile/kernel/vmlinux.lds.S +0 -1
@@ -43,7 +43,6 @@ SECTIONS HEAD_TEXT SCHED_TEXT LOCK_TEXT - KPROBES_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT __fix_text_end = .; /* tile-cpack won't rearrange before this */
arch/x86/kernel/kprobes/core.c +5 -6
@@ -579,9 +579,9 @@ static int reenter_kprobe(struct kprobe *p, struct pt_regs *regs,case KPROBE_REENTER :/* A probe has been hit in the codepath leading up to, or just * after, single-stepping of a probed instruction. This entire -* codepath should strictly reside in .kprobes.text section. -* Raise a BUG or we'll continue in an endless reentering loop -* and eventually a stack overflow. +* codepath should strictly reside in the kprobes section +* range. Raise a BUG or we'll continue in an endless +* reentering loop and eventually a stack overflow. */ printk (KERN_WARNING "Unrecoverable kprobe detected at %p.\n" , p->addr);
@@ -1128,10 +1128,9 @@ NOKPROBE_SYMBOL(longjmp_break_handler);bool arch_within_kprobe_blacklist (unsigned long addr) { -return (addr >= (unsigned long )__kprobes_text_start && - addr < (unsigned long )__kprobes_text_end) || +return (SECTION_ADDR_IN_RANGE (kprobes, addr) || (addr >= (unsigned long )__entry_text_start && - addr < (unsigned long )__entry_text_end); + addr < (unsigned long )__entry_text_end)); }int __init arch_init_kprobes (void )
arch/x86/kernel/vmlinux.lds.S +0 -1
@@ -98,7 +98,6 @@ SECTIONS TEXT_TEXT SCHED_TEXT LOCK_TEXT - KPROBES_TEXT ENTRY_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT
include/asm-generic/kprobes.h +2 -1
@@ -3,6 +3,7 @@#if defined(__KERNEL__) && !defined(__ASSEMBLY__)#ifdef CONFIG_KPROBES +#include <asm/ranges.h> /* * Blacklist ganerating macro. Specify functions which is not probed * by using this macro.
@@ -13,7 +14,7 @@ static unsigned long __used \ _kbl_addr_##fname = (unsigned long)fname;# define NOKPROBE_SYMBOL (fname) __NOKPROBE_SYMBOL(fname)/* Use this to forbid a kprobes attach on very low level functions */ -# define __kprobes __attribute__((__section__(".kprobes.text"))) +# define __kprobes __LINUX_RANGE(SECTION_TEXT, kprobes)# define nokprobe_inline __always_inline#else # define NOKPROBE_SYMBOL (fname)
include/asm-generic/sections.h +0 -2
@@ -24,7 +24,6 @@* Following global variables are optional and may be unavailable on some * architectures and/or kernel configurations. * _text, _data -* __kprobes_text_start, __kprobes_text_end * __entry_text_start, __entry_text_end * __ctors_start, __ctors_end */
@@ -35,7 +34,6 @@ extern char __init_begin[], __init_end[];extern char _sinittext[], _einittext[];extern char _end[];extern char __per_cpu_load[], __per_cpu_start[], __per_cpu_end[]; -extern char __kprobes_text_start[], __kprobes_text_end[];extern char __entry_text_start[], __entry_text_end[];extern char __start_rodata[], __end_rodata[];
include/asm-generic/vmlinux.lds.h +0 -6
@@ -449,12 +449,6 @@ *(.spinlock.text) \ VMLINUX_SYMBOL(__lock_text_end) = .; -#define KPROBES_TEXT \ - ALIGN_FUNCTION(); \ - VMLINUX_SYMBOL(__kprobes_text_start) = .; \ - *(.kprobes.text) \ - VMLINUX_SYMBOL(__kprobes_text_end) = .; -#define ENTRY_TEXT \ ALIGN_FUNCTION(); \ VMLINUX_SYMBOL(__entry_text_start) = .; \
include/linux/kprobes.h +3 -0
@@ -43,6 +43,9 @@#include <asm/kprobes.h> #ifdef CONFIG_KPROBES +#include <linux/ranges.h> + +DECLARE_SECTION_RANGE (kprobes);/* kprobe_status settings */ #define KPROBE_HIT_ACTIVE 0x00000001
kernel/kprobes.c +4 -2
@@ -1328,8 +1328,7 @@ out:bool __weak arch_within_kprobe_blacklist (unsigned long addr) {/* The __kprobes marked functions and entry code must not be probed */ -return addr >= (unsigned long )__kprobes_text_start && - addr < (unsigned long )__kprobes_text_end; +return SECTION_ADDR_IN_RANGE (kprobes, addr); }bool within_kprobe_blacklist (unsigned long addr)
@@ -2129,6 +2128,9 @@ static struct notifier_block kprobe_module_nb = {extern unsigned long __start_kprobe_blacklist[];extern unsigned long __stop_kprobe_blacklist[]; +/* Actual kprobes section range */ +DEFINE_SECTION_RANGE (kprobes,SECTION_TEXT ); +static int __init init_kprobes (void ) {int i, err =0 ;
scripts/mod/modpost.c +1 -1
@@ -888,7 +888,7 @@ static void check_section(const char *modname, struct elf_info *elf,#define DATA_SECTIONS ".data", ".data.rel"#define TEXT_SECTIONS ".text", ".text.unlikely", ".sched.text", \ - ".kprobes.text" + ".text.rng.kprobes.any"#define OTHER_TEXT_SECTIONS ".ref.text", ".head.text", ".spinlock.text", \ ".fixup", ".entry.text", ".exception.text", ".text.*", \ ".coldtext"
scripts/recordmcount.c +1 -1
@@ -363,7 +363,7 @@ is_mcounted_section_name(char const *const txtname)strcmp (".sched.text" , txtname) ==0 ||strcmp (".spinlock.text" , txtname) ==0 ||strcmp (".irqentry.text" , txtname) ==0 || -strcmp (".kprobes.text" , txtname) ==0 || +strcmp (".text.rng.kprobes.any" , txtname) ==0 ||strcmp (".text.unlikely" , txtname) ==0 ; }
scripts/recordmcount.pl +1 -1
@@ -134,7 +134,7 @@ my %text_sections = ( ".sched.text" => 1, ".spinlock.text" => 1, ".irqentry.text" => 1, - ".kprobes.text" => 1, + ".text.rng.kprobes.any" => 1, ".text.unlikely" => 1, );
Signature · 1 line
2.9.2
[email protected]
maintainerPATCH v4 16/16 kprobes: port blacklist kprobes to linker table
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
kprobe makes use of two sections, the one dealing with the actual kprobes was recently ported using the standard section range API. The blacklist functionality of kprobes is still using a custom section and declaring its custom section using the linker script as follows:
type Linux-section custom section name begin end
table .init.data _kprobe_blacklist __start_kprobe_blacklist __stop_kprobe_blacklist
This ports the _kprobe_blacklist custom section to the standard Linux linker table API allowing us remove all the custom blacklist kprobe section declarations from the linker script.
This has been tested by trying to register a kprobe on a blacklisted symbol (these are declared with NOKPROBE_SYMBOL()), and confirms that this fails to work as expected. This was tested with:
# insmod samples/kprobes/kprobe_example.ko symbol="get_kprobe"
This fails to load as expected with:
insmod: ERROR: could not insert module samples/kprobes/kprobe_example.ko: Invalid parameters
v3: this patch was introduced in this series
--- include/asm-generic/kprobes.h | 4 ++-- include/asm-generic/vmlinux.lds.h | 10 ---------- include/linux/kprobes.h | 2 ++ kernel/kprobes.c | 11 ++++------- 4 files changed, 8 insertions(+), 19 deletions(-)
include/asm-generic/kprobes.h +2 -2
@@ -3,14 +3,14 @@#if defined(__KERNEL__) && !defined(__ASSEMBLY__)#ifdef CONFIG_KPROBES +#include <linux/tables.h> #include <asm/ranges.h> /* * Blacklist ganerating macro. Specify functions which is not probed * by using this macro. */ # define __NOKPROBE_SYMBOL (fname) \ -static unsigned long __used \ - __attribute__((__section__("_kprobe_blacklist"))) \ +static LINKTABLE_INIT_DATA(_kprobe_blacklist, all) \ _kbl_addr_##fname = (unsigned long)fname;# define NOKPROBE_SYMBOL (fname) __NOKPROBE_SYMBOL(fname)/* Use this to forbid a kprobes attach on very low level functions */
include/asm-generic/vmlinux.lds.h +0 -10
@@ -114,15 +114,6 @@#define BRANCH_PROFILE ()#endif -#ifdef CONFIG_KPROBES -#define KPROBE_BLACKLIST () . = ALIGN(8); \ - VMLINUX_SYMBOL(__start_kprobe_blacklist) = .; \ - *(_kprobe_blacklist) \ - VMLINUX_SYMBOL(__stop_kprobe_blacklist) = .; -#else -#define KPROBE_BLACKLIST () -#endif -#ifdef CONFIG_EVENT_TRACING #define FTRACE_EVENTS () . = ALIGN(8); \ VMLINUX_SYMBOL(__start_ftrace_events) = .; \
@@ -525,7 +516,6 @@ *(SECTION_INIT_RODATA ) \ FTRACE_EVENTS() \ TRACE_SYSCALLS() \ - KPROBE_BLACKLIST() \ MEM_DISCARD(init.rodata) \ CLK_OF_TABLES() \RESERVEDMEM_OF_TABLES () \
include/linux/kprobes.h +2 -0
@@ -44,8 +44,10 @@#ifdef CONFIG_KPROBES #include <linux/ranges.h> +#include <linux/tables.h> DECLARE_SECTION_RANGE (kprobes); +DECLARE_LINKTABLE(unsigned long, _kprobe_blacklist);/* kprobe_status settings */ #define KPROBE_HIT_ACTIVE 0x00000001
kernel/kprobes.c +4 -7
@@ -2053,14 +2053,13 @@ NOKPROBE_SYMBOL(dump_kprobe);* since a kprobe need not necessarily be at the beginning * of a function. */ -static int __init populate_kprobe_blacklist (unsigned long *start, -unsigned long *end) +static int __init populate_kprobe_blacklist (void ) {unsigned long *iter;struct kprobe_blacklist_entry *ent;unsigned long entry, offset =0 , size =0 ; -for (iter = start; iter < end; iter++) { + LINKTABLE_FOR_EACH(iter, _kprobe_blacklist) { entry =arch_deref_entry_point ((void *)*iter); if (!kernel_text_address(entry) ||
@@ -2125,8 +2124,7 @@ static struct notifier_block kprobe_module_nb = { };/* Markers of _kprobe_blacklist section */ -extern unsigned long __start_kprobe_blacklist[]; -extern unsigned long __stop_kprobe_blacklist[]; +DEFINE_LINKTABLE_INIT_DATA(unsigned long, _kprobe_blacklist);/* Actual kprobes section range */ DEFINE_SECTION_RANGE (kprobes,SECTION_TEXT );
@@ -2143,8 +2141,7 @@ static int __init init_kprobes(void)raw_spin_lock_init (&(kretprobe_table_locks[i].lock)); } - err =populate_kprobe_blacklist (__start_kprobe_blacklist, - __stop_kprobe_blacklist); + err =populate_kprobe_blacklist ();if (err) {pr_err ("kprobes: failed to populate blacklist: %d\n" , err);pr_err ("Please take care of using kprobes.\n" );
Signature · 1 line
2.9.2
[email protected]
maintainercover tools: add linker table userspace sandbox
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
The original v3 series for linker tables made reference only to an external repository userspace sandbox application, however Boris noted it'd be difficult ot keep this in sync with the kernel so advised to consider integrate with the kernel. I've taken steps in this direction.
A bit of prepping is done to help make use of the tools/include and tools/arch/$(ARCH)/include/asm directories. For now the tool only supports x86_64, however quite a bit of work was done to help make it work with a cross compiler, and try to make as architecture agnostic as possible. Adding suppor for another architecture should not require much work, mosty just generating a userspace custom linker script, modifying it for linker tables, section ranges, and finally testing this with its toolchain.
This is being submitted separately than the patches which adds linker table support into the kernel. This should be considered only if that gets merged.
If you'd like this in git-form, you can get it on the 20160819-linker-table-v4 branch of my linux-next tree on kernel.org, this also includes the series of that introduces linker tables into the kernel:
https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linux-next.git/log/?h=20160819-linker-table-v4
Please let me know if there are any issue or questions.
Luis R. Rodriguez (7):
tools: add a userspace tools bug.h
tools: add a basic tools printk.h
tools: add init.h for tools
tools: add __used and enable to override
tools: expand export.h with VMLINUX_SYMBOL()
tools: add __section() to compiler.h
tools: add userspace linker table sandbox
Documentation/sections/linker-tables.rst | 4 +- MAINTAINERS | 1 + include/linux/tables.h | 5 +- tools/Makefile | 3 +- .../arch/x86/include/generated/asm/section-core.h | 1 + tools/arch/x86/include/generated/ranges.h | 1 + tools/arch/x86/include/generated/tables.h | 1 + tools/include/asm-generic/bug.h | 24 + tools/include/asm-generic/ranges.h | 103 ++++ tools/include/asm-generic/section-core.h | 341 +++++++++++ tools/include/asm-generic/tables.h | 50 ++ tools/include/linux/bug.h | 6 + tools/include/linux/compiler.h | 8 + tools/include/linux/export.h | 22 + tools/include/linux/init.h | 9 + tools/include/linux/kernel.h | 3 + tools/include/linux/printk.h | 14 + tools/include/linux/ranges.h | 128 ++++ tools/include/linux/sections.h | 111 ++++ tools/include/linux/string.h | 1 + tools/include/linux/tables.h | 664 +++++++++++++++++++++ tools/linker-tables/.gitignore | 2 + tools/linker-tables/Makefile | 184 ++++++ tools/linker-tables/README | 114 ++++ tools/linker-tables/arch/x86/include/asm/asm.h | 17 + tools/linker-tables/arch/x86/include/asm/boot.h | 1 + .../linker-tables/arch/x86/include/asm/bootparam.h | 32 + tools/linker-tables/arch/x86/include/asm/kprobes.h | 7 + .../linker-tables/arch/x86/include/asm/ps_const.h | 21 + tools/linker-tables/arch/x86/include/asm/ranges.h | 6 + .../arch/x86/include/asm/section-core.h | 1 + tools/linker-tables/arch/x86/include/asm/setup.h | 6 + tools/linker-tables/arch/x86/include/asm/tables.h | 6 + tools/linker-tables/arch/x86/include/asm/x86.h | 4 + .../arch/x86/include/asm/x86_init_fn.h | 169 ++++++ tools/linker-tables/arch/x86/kernel/alpha.c | 9 + tools/linker-tables/arch/x86/kernel/alternative.c | 31 + tools/linker-tables/arch/x86/kernel/beta.c | 9 + tools/linker-tables/arch/x86/kernel/head64.c | 58 ++ tools/linker-tables/arch/x86/kernel/init.c | 42 ++ tools/linker-tables/arch/x86/kernel/kasan.c | 10 + tools/linker-tables/arch/x86/kernel/kprobes.c | 51 ++ tools/linker-tables/arch/x86/kernel/vmlinux.lds.S | 273 +++++++++ tools/linker-tables/arch/x86/mm/init.c | 10 + tools/linker-tables/arch/x86/xen/init.c | 13 + tools/linker-tables/drivers/acme.c | 32 + tools/linker-tables/drivers/synth/common.c | 16 + tools/linker-tables/drivers/synth/common.h | 2 + tools/linker-tables/drivers/synth/main.c | 35 ++ tools/linker-tables/drivers/synth/or.S | 39 ++ tools/linker-tables/drivers/synth/synth.h | 2 + tools/linker-tables/drivers/xen-driver.c | 11 + .../include/asm-generic/arch_init_fn.h | 50 ++ tools/linker-tables/include/asm-generic/kprobes.h | 26 + tools/linker-tables/include/linux/bitops.h | 6 + tools/linker-tables/include/linux/init.h | 40 ++ tools/linker-tables/include/linux/kasan.h | 5 + tools/linker-tables/include/linux/kprobes.h | 11 + tools/linker-tables/include/linux/module.h | 14 + tools/linker-tables/include/linux/mutex.h | 17 + tools/linker-tables/include/linux/pci.h | 7 + tools/linker-tables/include/linux/ps_const.h | 46 ++ tools/linker-tables/include/linux/sched.h | 9 + tools/linker-tables/include/linux/spinlock.h | 13 + tools/linker-tables/include/linux/start_kernel.h | 1 + tools/linker-tables/include/linux/types.h | 13 + tools/linker-tables/include/linux/workqueue.h | 51 ++ tools/linker-tables/include/xen/xen.h | 4 + tools/linker-tables/kernel/locking/mutex.c | 28 + tools/linker-tables/kernel/locking/spinlock.c | 26 + tools/linker-tables/kernel/main.c | 32 + tools/linker-tables/kernel/workqueue.c | 43 ++ tools/linker-tables/lib/string.c | 26 + tools/linker-tables/main.c | 20 + tools/linker-tables/pci-quirks.c | 13 + tools/linker-tables/pci.c | 29 + 76 files changed, 3238 insertions(+), 5 deletions(-) create mode 100644 tools/arch/x86/include/generated/asm/section-core.h create mode 100644 tools/arch/x86/include/generated/ranges.h create mode 100644 tools/arch/x86/include/generated/tables.h create mode 100644 tools/include/asm-generic/bug.h create mode 100644 tools/include/asm-generic/ranges.h create mode 100644 tools/include/asm-generic/section-core.h create mode 100644 tools/include/asm-generic/tables.h create mode 100644 tools/include/linux/bug.h create mode 100644 tools/include/linux/init.h create mode 100644 tools/include/linux/printk.h create mode 100644 tools/include/linux/ranges.h create mode 100644 tools/include/linux/sections.h create mode 100644 tools/include/linux/tables.h create mode 100644 tools/linker-tables/.gitignore create mode 100644 tools/linker-tables/Makefile create mode 100644 tools/linker-tables/README create mode 100644 tools/linker-tables/arch/x86/include/asm/asm.h create mode 100644 tools/linker-tables/arch/x86/include/asm/boot.h create mode 100644 tools/linker-tables/arch/x86/include/asm/bootparam.h create mode 100644 tools/linker-tables/arch/x86/include/asm/kprobes.h create mode 100644 tools/linker-tables/arch/x86/include/asm/ps_const.h create mode 100644 tools/linker-tables/arch/x86/include/asm/ranges.h create mode 100644 tools/linker-tables/arch/x86/include/asm/section-core.h create mode 100644 tools/linker-tables/arch/x86/include/asm/setup.h create mode 100644 tools/linker-tables/arch/x86/include/asm/tables.h create mode 100644 tools/linker-tables/arch/x86/include/asm/x86.h create mode 100644 tools/linker-tables/arch/x86/include/asm/x86_init_fn.h create mode 100644 tools/linker-tables/arch/x86/kernel/alpha.c create mode 100644 tools/linker-tables/arch/x86/kernel/alternative.c create mode 100644 tools/linker-tables/arch/x86/kernel/beta.c create mode 100644 tools/linker-tables/arch/x86/kernel/head64.c create mode 100644 tools/linker-tables/arch/x86/kernel/init.c create mode 100644 tools/linker-tables/arch/x86/kernel/kasan.c create mode 100644 tools/linker-tables/arch/x86/kernel/kprobes.c create mode 100644 tools/linker-tables/arch/x86/kernel/vmlinux.lds.S create mode 100644 tools/linker-tables/arch/x86/mm/init.c create mode 100644 tools/linker-tables/arch/x86/xen/init.c create mode 100644 tools/linker-tables/drivers/acme.c create mode 100644 tools/linker-tables/drivers/synth/common.c create mode 100644 tools/linker-tables/drivers/synth/common.h create mode 100644 tools/linker-tables/drivers/synth/main.c create mode 100644 tools/linker-tables/drivers/synth/or.S create mode 100644 tools/linker-tables/drivers/synth/synth.h create mode 100644 tools/linker-tables/drivers/xen-driver.c create mode 100644 tools/linker-tables/include/asm-generic/arch_init_fn.h create mode 100644 tools/linker-tables/include/asm-generic/kprobes.h create mode 100644 tools/linker-tables/include/linux/bitops.h create mode 100644 tools/linker-tables/include/linux/init.h create mode 100644 tools/linker-tables/include/linux/kasan.h create mode 100644 tools/linker-tables/include/linux/kprobes.h create mode 100644 tools/linker-tables/include/linux/module.h create mode 100644 tools/linker-tables/include/linux/mutex.h create mode 100644 tools/linker-tables/include/linux/pci.h create mode 100644 tools/linker-tables/include/linux/ps_const.h create mode 100644 tools/linker-tables/include/linux/sched.h create mode 100644 tools/linker-tables/include/linux/spinlock.h create mode 100644 tools/linker-tables/include/linux/start_kernel.h create mode 100644 tools/linker-tables/include/linux/types.h create mode 100644 tools/linker-tables/include/linux/workqueue.h create mode 100644 tools/linker-tables/include/xen/xen.h create mode 100644 tools/linker-tables/kernel/locking/mutex.c create mode 100644 tools/linker-tables/kernel/locking/spinlock.c create mode 100644 tools/linker-tables/kernel/main.c create mode 100644 tools/linker-tables/kernel/workqueue.c create mode 100644 tools/linker-tables/lib/string.c create mode 100644 tools/linker-tables/main.c create mode 100644 tools/linker-tables/pci-quirks.c create mode 100644 tools/linker-tables/pci.c
Signature · 1 line
2.9.2
[email protected]
maintainerPATCH 1/7 tools: add a userspace tools bug.h
From: "Luis R. Rodriguez" <[email protected]>
This will be used later by the userspace linker-tables sandbox. As a convenience, include bug.h on kernel.h -- this is not done on upstream kernel.h, however most header files do include bug.h eventually, if we were to only add the ones that need it we'd need to copy a lot of headers to tools for the ony purpose of includeing bug.h. This simplifies that.
--- tools/include/asm-generic/bug.h | 24 ++++++++++++++++++++++++ tools/include/linux/bug.h | 6 ++++++ tools/include/linux/kernel.h | 2 ++ 3 files changed, 32 insertions(+) create mode 100644 tools/include/asm-generic/bug.h create mode 100644 tools/include/linux/bug.h
tools/include/asm-generic/bug.h new file +24 -0
@@ -0,0 +1,24 @@ +#ifndef __TOOLS_ASM_GENERIC_BUG +#define __TOOLS_ASM_GENERIC_BUG + +#include <stdio.h> +#include <stdlib.h> + +#define BUG () do { \ + fprintf(stderr, "----------------------------------------------------------\n"); \ + fprintf (stderr, "BUG on %s at %s: %i\n", __func__, __FILE__, __LINE__); \ + abort(); \ +} \ +while (0) + +#define BUG_ON (cond) do { if (cond) BUG(); } while (0) + +#define WARN_ON (__test) do { \ + if (__test) { \ + fprintf(stderr, "----------------------------------------------------------\n");\ + fprintf (stderr, "WARN_ON on %s at %s: %i\n", __func__, __FILE__, __LINE__); \ + } \ +} \ +while (0) + +#endif /* __TOOLS_ASM_GENERIC_BUG */
tools/include/linux/bug.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _TOOLS_LINUX_BUG_H +#define _TOOLS_LINUX_BUG_H + +#include <asm-generic/bug.h> + +#endif /* _TOOLS_LINUX_BUG_H */
tools/include/linux/kernel.h +2 -0
@@ -5,6 +5,8 @@#include <stddef.h> #include <assert.h> +#include <linux/bug.h> +#define DIV_ROUND_UP (n,d) (((n) + (d) - 1) / (d))#define PERF_ALIGN (x, a) __PERF_ALIGN_MASK(x, (typeof(x))(a)-1)
Signature · 1 line
2.9.2
[email protected]
maintainerPATCH 2/7 tools: add a basic tools printk.h
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
This will be used later by the userspace linker-tables sandbox. Since upstream kernel.h includes printk.h mimic this so we can match and replicate C code as-is on userspace sandbox tools.
--- tools/include/linux/kernel.h | 1 + tools/include/linux/printk.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 tools/include/linux/printk.h
tools/include/linux/kernel.h +1 -0
@@ -6,6 +6,7 @@#include <assert.h> #include <linux/bug.h> +#include <linux/printk.h> #define DIV_ROUND_UP (n,d) (((n) + (d) - 1) / (d))
tools/include/linux/printk.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef __TOOLS_KERNEL_PRINTK__ +#define __TOOLS_KERNEL_PRINTK__ + +#include <stdio.h> + +#ifndef pr_fmt +#define pr_fmt (fmt) fmt +#endif + +#define pr_info (fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__) +#define pr_err (fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__) +#define pr_debug (fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__) + +#endif /* __TOOLS_KERNEL_PRINTK__ */
Signature · 1 line
2.9.2
[email protected]
maintainerPATCH 3/7 tools: add init.h for tools
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
Start off with just __ref -- we enalbe you to override, if you do that then you can define your own. The way you'd use this, if you do override, is define your own __ref and then use include_next.
--- tools/include/linux/init.h | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tools/include/linux/init.h
tools/include/linux/init.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef _TOOLS_LINUX_INIT_H +#define _TOOLS_LINUX_INIT_H + +/* this means you can add your own to fit you own userspace needs */ +#ifndef __ref +#define __ref +#endif + +#endif /* _TOOLS_LINUX_INIT_H */
Signature · 1 line
2.9.2
[email protected]
maintainerPATCH 4/7 tools: add __used and enable to override
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
This adds __used, to be used later in the userspace linker-tables sandbox. If any userspace applicaiton wants to override they can add their own definition and then use include_next.
This definition should probably suffice for most uses cases though.
--- tools/include/linux/compiler.h | 6 ++++++ 1 file changed, 6 insertions(+)
tools/include/linux/compiler.h +6 -0
@@ -5,6 +5,12 @@/* The "volatile" is due to gcc bugs */ #define barrier () __asm__ __volatile__("": : :"memory") + +/* You can override as you see fit on your userspace tool */ +#ifndef __used +#define __used __attribute__((__used__)) +#endif +#ifndef __always_inline# define __always_inline inline __attribute__((always_inline))#endif
Signature · 1 line
2.9.2
[email protected]
maintainerPATCH 5/7 tools: expand export.h with VMLINUX_SYMBOL()
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
This will be used later by the linker-table userspace sandbox.
--- tools/include/linux/export.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
tools/include/linux/export.h +22 -0
@@ -1,6 +1,28 @@#ifndef _TOOLS_LINUX_EXPORT_H_#define _TOOLS_LINUX_EXPORT_H_ +/* +* Export symbols from the kernel to modules. Forked from module.h +* to reduce the amount of pointless cruft we feed to gcc when only +* exporting a simple symbol or two. +* +* Try not to add #includes here. It slows compilation and makes kernel +* hackers place grumpy comments in header files. +*/ + +/* Some toolchains use a `_' prefix for all user symbols. */ +#ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX +#define __VMLINUX_SYMBOL (x) _##x +#define __VMLINUX_SYMBOL_STR (x) "_" #x +#else +#define __VMLINUX_SYMBOL (x) x +#define __VMLINUX_SYMBOL_STR (x) #x +#endif + +/* Indirect, so macros are expanded before pasting. */ +#define VMLINUX_SYMBOL (x) __VMLINUX_SYMBOL(x) +#define VMLINUX_SYMBOL_STR (x) __VMLINUX_SYMBOL_STR(x) +#define EXPORT_SYMBOL (sym)#define EXPORT_SYMBOL_GPL (sym)#define EXPORT_SYMBOL_GPL_FUTURE (sym)
Signature · 1 line
2.9.2
[email protected]
maintainerPATCH 6/7 tools: add __section() to compiler.h
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
This will be used later by the userspace linker table.
--- tools/include/linux/compiler.h | 2 ++ 1 file changed, 2 insertions(+)
tools/include/linux/compiler.h +2 -0
@@ -132,4 +132,6 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s#define WRITE_ONCE (x, val) \ ({ union { typeof(x) __val; char __c[1]; } __u = { .__val = (val) }; __write_once_size(&(x), __u.__c, sizeof(x)); __u.__val; }) +#define __section (S ) __attribute__ ((__section__(#S))) +#endif /* _TOOLS_LINUX_COMPILER_H */
Signature · 1 line
2.9.2
[email protected]
maintainerPATCH 7/7 tools: add userspace linker table sandbox
In reply to [email protected]From: "Luis R. Rodriguez" <[email protected]>
Add a userspace sandbox to allow easy experimentation and test extensions with linker tables, section ranges and the new section core definitions.
The userspace sandbox tries to mimic the Linux kernel development flow as much as possible, it however relies on and uses libc. Support is currently only provided to x86_64.
v4: this patch is new in this series -- added to the kenrel as
suggested by Boris, as otherwise it'd be really hard to keep an external userspace repository in sync.
--- Documentation/sections/linker-tables.rst | 4 +- MAINTAINERS | 1 + include/linux/tables.h | 5 +- tools/Makefile | 3 +- .../arch/x86/include/generated/asm/section-core.h | 1 + tools/arch/x86/include/generated/ranges.h | 1 + tools/arch/x86/include/generated/tables.h | 1 + tools/include/asm-generic/ranges.h | 103 ++++ tools/include/asm-generic/section-core.h | 341 +++++++++++ tools/include/asm-generic/tables.h | 50 ++ tools/include/linux/ranges.h | 128 ++++ tools/include/linux/sections.h | 111 ++++ tools/include/linux/string.h | 1 + tools/include/linux/tables.h | 664 +++++++++++++++++++++ tools/linker-tables/.gitignore | 2 + tools/linker-tables/Makefile | 184 ++++++ tools/linker-tables/README | 114 ++++ tools/linker-tables/arch/x86/include/asm/asm.h | 17 + tools/linker-tables/arch/x86/include/asm/boot.h | 1 + .../linker-tables/arch/x86/include/asm/bootparam.h | 32 + tools/linker-tables/arch/x86/include/asm/kprobes.h | 7 + .../linker-tables/arch/x86/include/asm/ps_const.h | 21 + tools/linker-tables/arch/x86/include/asm/ranges.h | 6 + .../arch/x86/include/asm/section-core.h | 1 + tools/linker-tables/arch/x86/include/asm/setup.h | 6 + tools/linker-tables/arch/x86/include/asm/tables.h | 6 + tools/linker-tables/arch/x86/include/asm/x86.h | 4 + .../arch/x86/include/asm/x86_init_fn.h | 169 ++++++ tools/linker-tables/arch/x86/kernel/alpha.c | 9 + tools/linker-tables/arch/x86/kernel/alternative.c | 31 + tools/linker-tables/arch/x86/kernel/beta.c | 9 + tools/linker-tables/arch/x86/kernel/head64.c | 58 ++ tools/linker-tables/arch/x86/kernel/init.c | 42 ++ tools/linker-tables/arch/x86/kernel/kasan.c | 10 + tools/linker-tables/arch/x86/kernel/kprobes.c | 51 ++ tools/linker-tables/arch/x86/kernel/vmlinux.lds.S | 273 +++++++++ tools/linker-tables/arch/x86/mm/init.c | 10 + tools/linker-tables/arch/x86/xen/init.c | 13 + tools/linker-tables/drivers/acme.c | 32 + tools/linker-tables/drivers/synth/common.c | 16 + tools/linker-tables/drivers/synth/common.h | 2 + tools/linker-tables/drivers/synth/main.c | 35 ++ tools/linker-tables/drivers/synth/or.S | 39 ++ tools/linker-tables/drivers/synth/synth.h | 2 + tools/linker-tables/drivers/xen-driver.c | 11 + .../include/asm-generic/arch_init_fn.h | 50 ++ tools/linker-tables/include/asm-generic/kprobes.h | 26 + tools/linker-tables/include/linux/bitops.h | 6 + tools/linker-tables/include/linux/init.h | 40 ++ tools/linker-tables/include/linux/kasan.h | 5 + tools/linker-tables/include/linux/kprobes.h | 11 + tools/linker-tables/include/linux/module.h | 14 + tools/linker-tables/include/linux/mutex.h | 17 + tools/linker-tables/include/linux/pci.h | 7 + tools/linker-tables/include/linux/ps_const.h | 46 ++ tools/linker-tables/include/linux/sched.h | 9 + tools/linker-tables/include/linux/spinlock.h | 13 + tools/linker-tables/include/linux/start_kernel.h | 1 + tools/linker-tables/include/linux/types.h | 13 + tools/linker-tables/include/linux/workqueue.h | 51 ++ tools/linker-tables/include/xen/xen.h | 4 + tools/linker-tables/kernel/locking/mutex.c | 28 + tools/linker-tables/kernel/locking/spinlock.c | 26 + tools/linker-tables/kernel/main.c | 32 + tools/linker-tables/kernel/workqueue.c | 43 ++ tools/linker-tables/lib/string.c | 26 + tools/linker-tables/main.c | 20 + tools/linker-tables/pci-quirks.c | 13 + tools/linker-tables/pci.c | 29 + 69 files changed, 3152 insertions(+), 5 deletions(-) create mode 100644 tools/arch/x86/include/generated/asm/section-core.h create mode 100644 tools/arch/x86/include/generated/ranges.h create mode 100644 tools/arch/x86/include/generated/tables.h create mode 100644 tools/include/asm-generic/ranges.h create mode 100644 tools/include/asm-generic/section-core.h create mode 100644 tools/include/asm-generic/tables.h create mode 100644 tools/include/linux/ranges.h create mode 100644 tools/include/linux/sections.h create mode 100644 tools/include/linux/tables.h create mode 100644 tools/linker-tables/.gitignore create mode 100644 tools/linker-tables/Makefile create mode 100644 tools/linker-tables/README create mode 100644 tools/linker-tables/arch/x86/include/asm/asm.h create mode 100644 tools/linker-tables/arch/x86/include/asm/boot.h create mode 100644 tools/linker-tables/arch/x86/include/asm/bootparam.h create mode 100644 tools/linker-tables/arch/x86/include/asm/kprobes.h create mode 100644 tools/linker-tables/arch/x86/include/asm/ps_const.h create mode 100644 tools/linker-tables/arch/x86/include/asm/ranges.h create mode 100644 tools/linker-tables/arch/x86/include/asm/section-core.h create mode 100644 tools/linker-tables/arch/x86/include/asm/setup.h create mode 100644 tools/linker-tables/arch/x86/include/asm/tables.h create mode 100644 tools/linker-tables/arch/x86/include/asm/x86.h create mode 100644 tools/linker-tables/arch/x86/include/asm/x86_init_fn.h create mode 100644 tools/linker-tables/arch/x86/kernel/alpha.c create mode 100644 tools/linker-tables/arch/x86/kernel/alternative.c create mode 100644 tools/linker-tables/arch/x86/kernel/beta.c create mode 100644 tools/linker-tables/arch/x86/kernel/head64.c create mode 100644 tools/linker-tables/arch/x86/kernel/init.c create mode 100644 tools/linker-tables/arch/x86/kernel/kasan.c create mode 100644 tools/linker-tables/arch/x86/kernel/kprobes.c create mode 100644 tools/linker-tables/arch/x86/kernel/vmlinux.lds.S create mode 100644 tools/linker-tables/arch/x86/mm/init.c create mode 100644 tools/linker-tables/arch/x86/xen/init.c create mode 100644 tools/linker-tables/drivers/acme.c create mode 100644 tools/linker-tables/drivers/synth/common.c create mode 100644 tools/linker-tables/drivers/synth/common.h create mode 100644 tools/linker-tables/drivers/synth/main.c create mode 100644 tools/linker-tables/drivers/synth/or.S create mode 100644 tools/linker-tables/drivers/synth/synth.h create mode 100644 tools/linker-tables/drivers/xen-driver.c create mode 100644 tools/linker-tables/include/asm-generic/arch_init_fn.h create mode 100644 tools/linker-tables/include/asm-generic/kprobes.h create mode 100644 tools/linker-tables/include/linux/bitops.h create mode 100644 tools/linker-tables/include/linux/init.h create mode 100644 tools/linker-tables/include/linux/kasan.h create mode 100644 tools/linker-tables/include/linux/kprobes.h create mode 100644 tools/linker-tables/include/linux/module.h create mode 100644 tools/linker-tables/include/linux/mutex.h create mode 100644 tools/linker-tables/include/linux/pci.h create mode 100644 tools/linker-tables/include/linux/ps_const.h create mode 100644 tools/linker-tables/include/linux/sched.h create mode 100644 tools/linker-tables/include/linux/spinlock.h create mode 100644 tools/linker-tables/include/linux/start_kernel.h create mode 100644 tools/linker-tables/include/linux/types.h create mode 100644 tools/linker-tables/include/linux/workqueue.h create mode 100644 tools/linker-tables/include/xen/xen.h create mode 100644 tools/linker-tables/kernel/locking/mutex.c create mode 100644 tools/linker-tables/kernel/locking/spinlock.c create mode 100644 tools/linker-tables/kernel/main.c create mode 100644 tools/linker-tables/kernel/workqueue.c create mode 100644 tools/linker-tables/lib/string.c create mode 100644 tools/linker-tables/main.c create mode 100644 tools/linker-tables/pci-quirks.c create mode 100644 tools/linker-tables/pci.c
Documentation/sections/linker-tables.rst +2 -2
@@ -11,11 +11,11 @@ About Linker tables .. kernel-doc:: include/linux/tables.h :doc: Introduction -Linker table provenance +Linker table provenance and userspace testing --------------------------------------------- .. kernel-doc:: include/linux/tables.h - :doc: Linker table provenance + :doc: Linker table provenance and userspace testing Benefits of using Linker tables ===============================
MAINTAINERS +1 -0
@@ -5210,6 +5210,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux-next.git secti S: Supported F: include/asm-generic/tables.h F: include/linux/tables.h +F: tools/linker-tables/ F: Documentation/sections/linker-tables.rst GENERIC PHY FRAMEWORK
include/linux/tables.h +3 -2
@@ -35,12 +35,13 @@*/ /** -* DOC: Linker table provenance +* DOC: Linker table provenance and userspace testing * * The Linux implementation of linker tables was inspired by the iPXE linker * table's solution (iPXE commit 67a10ef000cb7 "[contrib] Add rom-o-matic to * contrib "[0]). To see how this code evolved refer to the out of tree -* userspace linker-table tree [1]. +* userspace linker-table tree [1]. Linux has a similar userspace application +* in tools/linker-tables/ to help more easily test adding new extensions. * * Contrary to iPXE's solution which strives to force compilation of * everything using linker tables, Linux's solution allows for developers to be
tools/Makefile +2 -1
@@ -18,6 +18,7 @@ help: @echo ' iio - IIO tools' @echo ' kvm_stat - top-like utility for displaying kvm statistics' @echo ' lguest - a minimal 32-bit x86 hypervisor' + @echo ' linker-tables - userspace liker table sandbox and related tools' @echo ' net - misc networking tools' @echo ' perf - Linux performance measurement and analysis tool' @echo ' selftests - various kernel selftests'
@@ -85,7 +86,7 @@ tmon: FORCE freefall: FORCE $(call descend,laptop/$@) -all: acpi cgroup cpupower gpio hv firewire lguest \ +all: acpi cgroup cpupower gpio hv firewire lguest linker-tables \ perf selftests turbostat usb \ virtio vm net x86_energy_perf_policy \ tmon freefall objtool
tools/arch/x86/include/generated/asm/section-core.h new file +1 -0
@@ -0,0 +1 @@ +#include <asm-generic/section-core.h>
tools/arch/x86/include/generated/ranges.h new file +1 -0
@@ -0,0 +1 @@ +#include <asm-generic/ranges.h>
tools/arch/x86/include/generated/tables.h new file +1 -0
@@ -0,0 +1 @@ +#include <asm-generic/tables.h>
tools/include/asm-generic/ranges.h new file +103 -0
103 lines not on this page · raw message
tools/include/asm-generic/section-core.h new file +341 -0
341 lines not on this page · raw message
tools/include/asm-generic/tables.h new file +50 -0
50 lines not on this page · raw message
tools/include/linux/ranges.h new file +128 -0
128 lines not on this page · raw message
tools/include/linux/sections.h new file +111 -0
111 lines not on this page · raw message
tools/include/linux/string.h +1 -0
@@ -3,6 +3,7 @@#include <linux/types.h> /* for size_t */ +#include <string.h> void *memdup (const void *src,size_t len);
tools/include/linux/tables.h new file +664 -0
664 lines not on this page · raw message
tools/linker-tables/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +arch/x86/kernel/vmlinux.lds +demo
tools/linker-tables/Makefile new file +184 -0
184 lines not on this page · raw message
tools/linker-tables/README new file +114 -0
114 lines not on this page · raw message
tools/linker-tables/arch/x86/include/asm/asm.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef _ASM_X86_ASM_H + +#ifdef __ASSEMBLY__ +# define __ASM_FORM (x) x +# define __ASM_FORM_RAW (x) x +# define __ASM_FORM_COMMA (x) x, +#else +# define __ASM_FORM (x) " " #x " " +# define __ASM_FORM_RAW (x) #x +# define __ASM_FORM_COMMA (x) " " #x "," +#endif + +# define __ASM_SEL (a,b) __ASM_FORM(b) +# define __ASM_SEL_RAW (a,b) __ASM_FORM_RAW(b) +#define _ASM_PTR __ASM_SEL(.long, .quad) + +#endif /* _ASM_X86_ASM_H */
tools/linker-tables/arch/x86/include/asm/boot.h new file +1 -0
@@ -0,0 +1 @@ +extern struct boot_params boot_params;
tools/linker-tables/arch/x86/include/asm/bootparam.h new file +32 -0
@@ -0,0 +1,32 @@ +#ifndef __BOOTPARAM_H +#define __BOOTPARAM_H + +#include <linux/types.h> + +struct setup_header { +__u32 hardware_subarch; +} __attribute__((packed)); + +struct boot_params { +struct setup_header hdr; +} __attribute__((packed)); + +enum { +X86_SUBARCH_PC =0 , +X86_SUBARCH_LGUEST , +X86_SUBARCH_XEN , +X86_SUBARCH_INTEL_MID , +X86_SUBARCH_CE4100 , +X86_NR_SUBARCHS , +}; + +#define X86_SUBARCH_ALL_SUBARCHS \ + ( \ + BIT(X86_SUBARCH_PC) | \ + BIT(X86_SUBARCH_LGUEST) | \ + BIT(X86_SUBARCH_XEN) | \ + BIT(X86_SUBARCH_INTEL_MID) | \ + BIT(X86_SUBARCH_CE4100) \ + ) + +#endif /* __BOOTPARAM_H */
tools/linker-tables/arch/x86/include/asm/kprobes.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _SANDBOX_ASM_X86_KPROBES_H +#define _SANDBOX_ASM_X86_KPROBES_H + +/* This is all we need for the demo */ +#include <asm-generic/kprobes.h> + +#endif /* _SANDBOX_ASM_X86_KPROBES_H */
tools/linker-tables/arch/x86/include/asm/ps_const.h new file +21 -0
@@ -0,0 +1,21 @@ +#ifndef __X86_PS_CONST +#define __X86_PS_CONST + +#include <linux/tables.h> +#include <asm/asm.h> + +#define ps_shr (_in, _func) \ +({ \ + __typeof__(_in) _out; \ + asm volatile( \ + "shr $0,%0\n" \ + "1:\n" \ + SECTION_TBL_STR(SECTION_INIT_DATA, ps_set_const_table, 01)\ + _ASM_PTR "1b-1, %P2, %P3\n" \ + ".popsection\n" \ + : "=rm" (_out) \ + : "0" (_in), "i" (SET_CONST_U8), "i" (_func)); \ + (_out); \ +}) + +#endif /* __X86_PS_CONST */
tools/linker-tables/arch/x86/include/asm/ranges.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _ASM_X86_RANGES_H +#define _ASM_X86_RANGES_H + +#include <asm-generic/ranges.h> + +#endif /* _ASM_X86_RANGES_H */
tools/linker-tables/arch/x86/include/asm/section-core.h new file +1 -0
@@ -0,0 +1 @@ +#include <asm-generic/section-core.h>
tools/linker-tables/arch/x86/include/asm/setup.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef __LINUX_X86_USER_SETUP_H +#define __LINUX_X86_USER_SETUP_H + +/* I'm lazy */ + +#endif /* __LINUX_X86_USER_SETUP_H */
tools/linker-tables/arch/x86/include/asm/tables.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _ASM_X86_TABLES_H +#define _ASM_X86_TABLES_H + +#include <asm-generic/tables.h> + +#endif /* _ASM_X86_RANGES_H */
tools/linker-tables/arch/x86/include/asm/x86.h new file +4 -0
@@ -0,0 +1,4 @@ +int startup_64 (void ); +int x86_64_start_reservations (void ); +void setup_arch (void ); +void late_init (void );
tools/linker-tables/arch/x86/include/asm/x86_init_fn.h new file +169 -0
169 lines not on this page · raw message
tools/linker-tables/arch/x86/kernel/alpha.c new file +9 -0
@@ -0,0 +1,9 @@ +#include <linux/kernel.h> +#include <asm/x86_init_fn.h> + +static void early_init_alpha (void ) { +pr_info ("Initializing alpha ...\n" ); +pr_info ("Completed initializing alpha !\n" ); +} + +x86_init_early_pc (early_init_alpha);
tools/linker-tables/arch/x86/kernel/alternative.c new file +31 -0
@@ -0,0 +1,31 @@ +#include <asm/x86_init_fn.h> + +#include <linux/kernel.h> +#include <linux/ps_const.h> + +void apply_alternatives_linker_tables (void ) +{ +unsigned int num_consts =LINUX_SECTION_SIZE (ps_set_const_table); +struct ps_set_const *ps_const; + +if (!num_consts) +return ; + +pr_debug ("Number of init entries: %d\n" , num_consts); + + LINKTABLE_FOR_EACH(ps_const, ps_set_const_table) { +switch (ps_const->type) { +case SET_CONST_U8 : + *ps_const->count = (__u8 ) ps_const->func (); +break ; +case SET_CONST_U16 : + *ps_const->count = (__u16 ) ps_const->func (); +break ; +case SET_CONST_U32 : + *ps_const->count = (__u16 ) ps_const->func (); +break ; + } + } +} + +x86_init_early_pc (apply_alternatives_linker_tables);
tools/linker-tables/arch/x86/kernel/beta.c new file +9 -0
@@ -0,0 +1,9 @@ +#include <linux/kernel.h> +#include <asm/x86_init_fn.h> + +static void early_init_beta (void ) { +pr_info ("Initializing beta ...\n" ); +pr_info ("Completed initializing beta !\n" ); +} + +x86_init_early_pc (early_init_beta);
tools/linker-tables/arch/x86/kernel/head64.c new file +58 -0
58 lines not on this page · raw message
tools/linker-tables/arch/x86/kernel/init.c new file +42 -0
42 lines not on this page · raw message
tools/linker-tables/arch/x86/kernel/kasan.c new file +10 -0
@@ -0,0 +1,10 @@ +#include <linux/kernel.h> +#include <asm/x86_init_fn.h> + +void kasan_early_init (void ) { +pr_info ("Initializing kasan ...\n" ); +pr_info ("Early init for Kasan...\n" ); +pr_info ("Completed initializing kasan !\n" ); +} + +x86_init_early_pc (kasan_early_init);
tools/linker-tables/arch/x86/kernel/kprobes.c new file +51 -0
51 lines not on this page · raw message
tools/linker-tables/arch/x86/kernel/vmlinux.lds.S new file +273 -0
273 lines not on this page · raw message
tools/linker-tables/arch/x86/mm/init.c new file +10 -0
@@ -0,0 +1,10 @@ +#include <linux/kernel.h> +#include <asm/x86_init_fn.h> + +static void early_init_memory (void ) { +pr_info ("Initializing memory ...\n" ); +sleep (1 ); +pr_info ("Completed initializing memory !\n" ); +} + +x86_init_early_all (early_init_memory);
tools/linker-tables/arch/x86/xen/init.c new file +13 -0
@@ -0,0 +1,13 @@ +#include <linux/kernel.h> +#include <linux/tables.h> +#include <asm/x86_init_fn.h> +#include <asm/x86.h> + +void startup_xen (void ) +{ +pr_info ("Initializing Xen guest\n" ); + +x86_init_fn_early_init (); + +x86_64_start_reservations (); +}
tools/linker-tables/drivers/acme.c new file +32 -0
@@ -0,0 +1,32 @@ +#define pr_fmt (fmt) "ACME: " fmt + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/workqueue.h> + +void *acme_todo (void *arg); +static DECLARE_WORK(acme_work, acme_todo); + +void *acme_todo (void *arg) +{ +pr_info ("Running scheduled work\n" ); +pthread_exit (NULL ); +} + +static int acme_init_driver (void ) { +pr_info ("Initializing ...\n" ); +sleep (2 ); +pr_info ("Finished init ... !\n" ); + +init_work (&acme_work); +schedule_work (&acme_work); + +return 0 ; +} +module_init (acme_init_driver); + +static void acme_exit (void ) +{ +cancel_work_sync (&acme_work); +}; +module_exit (acme_exit);
tools/linker-tables/drivers/synth/common.c new file +16 -0
@@ -0,0 +1,16 @@ +int demo_or_1 (int arg) +{ +switch (arg) { +case 1 : +return 0xDEA00000 ; +case 2 : +return 0X000D0000 ; +default : +return arg *2 ; + } +} + +int demo_or_2 (void ) +{ +return 0x0000BEEF ; +}
tools/linker-tables/drivers/synth/common.h new file +2 -0
@@ -0,0 +1,2 @@ +int demo_or_1 (int arg); +int demo_or_2 (void );
tools/linker-tables/drivers/synth/main.c new file +35 -0
@@ -0,0 +1,35 @@ +#define pr_fmt (fmt) "Synthetics: " fmt + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/ps_const.h> + +#include "common.h" +#include "synth.h" + +DEFINE_LINKTABLE_INIT_DATA(struct ps_set_const, ps_set_const_table); + +unsigned int get_demo_shr (void ) +{ +return 16 ; +} + +static int synth_init (void ) +{ +int synth_or; +int val =2 ; +const unsigned int reg =ps_shr (0xDEADBEEF , get_demo_shr); + + synth_or =synth_init_or (val); +pr_info ("synth_init_or(%d) returns: 0x%08X\n" , val, synth_or); + +pr_info ("ps_shr(0x%08X, get_demo_shr) returns: 0x%08X\n" ,0xDEADBEEF , reg); + +return 0 ; +} +module_init (synth_init); + +static void synth_exit (void ) +{ +} +module_exit (synth_exit);
tools/linker-tables/drivers/synth/or.S new file +39 -0
@@ -0,0 +1,39 @@ +#include <asm/ranges.h> + + DEFINE_SECTION_RANGE(SECTION_TEXT, synth_init_or) + + push_section_rng_level(SECTION_TEXT, synth_init_or, "01", ) + /* err = 0; */ + pushq %rbp + movq %rsp,%rbp + pushq %rbx + xorq %rbx,%rbx + .popsection + + push_section_rng_level(SECTION_TEXT, synth_init_or, "99", ) + /* return err; */ + movq %rbx,%rax + popq %rbx + popq %rbp + retq + .popsection + + push_section_rng_level(SECTION_TEXT, synth_init_or, "50", ) + /* err |= demo_or_1(1); */ + movl $1,%edi + call demo_or_1 + orq %rax,%rbx + .popsection + + push_section_rng_level(SECTION_TEXT, synth_init_or, "50", ) + /* err |= demo_or_1(2); */ + movl $2,%edi + call demo_or_1 + orq %rax,%rbx + .popsection + + push_section_rng_level(SECTION_TEXT, synth_init_or, "50", ) + /* err |= demo_or_2(); */ + call demo_or_2 + orq %rax,%rbx + .popsection
tools/linker-tables/drivers/synth/synth.h new file +2 -0
@@ -0,0 +1,2 @@ +/* Synthetic demos go here */ +int synth_init_or (int arg);
tools/linker-tables/drivers/xen-driver.c new file +11 -0
@@ -0,0 +1,11 @@ +#include <asm/x86_init_fn.h> +#include <linux/kernel.h> +#include <linux/pci.h> +#include <xen/xen.h> + +static void early_xen_init_driver (void ) { +pr_info ("Initializing xen driver\n" ); +sleep (2 ); +} + +x86_init_early_xen (early_xen_init_driver);
tools/linker-tables/include/asm-generic/arch_init_fn.h new file +50 -0
50 lines not on this page · raw message
tools/linker-tables/include/asm-generic/kprobes.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef _SANDBOX_ASM_GENERIC_KPROBES_H +#define _SANDBOX_ASM_GENERIC_KPROBES_H + +#if defined(__KERNEL__) && !defined(__ASSEMBLY__) +#ifdef CONFIG_KPROBES +#include <linux/tables.h> +#include <asm/ranges.h> +/* +* Blacklist ganerating macro. Specify functions which is not probed +* by using this macro. +*/ +# define __NOKPROBE_SYMBOL (fname) \ +static LINKTABLE_INIT_DATA(_kprobe_blacklist, all) \ + _kbl_addr_##fname = (unsigned long)fname; +# define NOKPROBE_SYMBOL (fname) __NOKPROBE_SYMBOL(fname) +/* Use this to forbid a kprobes attach on very low level functions */ +# define __kprobes __LINUX_RANGE(SECTION_TEXT, kprobes) +# define nokprobe_inline __always_inline +#else +# define NOKPROBE_SYMBOL (fname) +# define __kprobes +# define nokprobe_inline inline +#endif +#endif /* defined(__KERNEL__) && !defined(__ASSEMBLY__) */ + +#endif /* _SANDBOX_ASM_GENERIC_KPROBES_H */
tools/linker-tables/include/linux/bitops.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _LINUX_BITOPS_H +#define _LINUX_BITOPS_H + +#define BIT (nr) (1UL << (nr)) + +#endif /* _LINUX_BITOPS_H */
tools/linker-tables/include/linux/init.h new file +40 -0
@@ -0,0 +1,40 @@ +#ifndef _SANDBOX_LINUX_INIT_H +#define _SANDBOX_LINUX_INIT_H + +#include_next <linux/init.h> +#include <linux/types.h> +#include <linux/sections.h> + +#define __init __section(SECTION_INIT) +#define __exit __section(SECTION_EXIT) + +#ifndef __ASSEMBLY__ +#include <linux/tables.h> +typedef int (*initcall_t )(void ); +typedef void (*exitcall_t )(void ); + +DECLARE_LINKTABLE (initcall_t, init_calls); +DECLARE_LINKTABLE (exitcall_t, exit_calls); + +#define __define_initcall (fn, id) \ + static LINKTABLE_INIT_DATA(init_calls, id) \ + __initcall_##fn##id = fn + +#define pure_initcall (fn) __define_initcall(fn, 0) +#define core_initcall (fn) __define_initcall(fn, 1) +#define postcore_initcall (fn) __define_initcall(fn, 2) +#define arch_initcall (fn) __define_initcall(fn, 3) +#define subsys_initcall (fn) __define_initcall(fn, 4) +#define fs_initcall (fn) __define_initcall(fn, 5) +#define device_initcall (fn) __define_initcall(fn, 6) +#define late_initcall (fn) __define_initcall(fn, 7) + +#define __initcall (fn) device_initcall(fn) + +#define __exitcall (fn) \ + static LINKTABLE_INIT_DATA(exit_calls, SECTION_ORDER_ANY) \ + __exitcall_##fn = fn; + +#endif + +#endif /* _SANDBOX_LINUX_INIT_H */
tools/linker-tables/include/linux/kasan.h new file +5 -0
@@ -0,0 +1,5 @@ +#include <linux/types.h> + +void kasan_early_init (void ); +int kasan_init (void ); +bool is_kasan_setup (void );
tools/linker-tables/include/linux/kprobes.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef _SANDBOX_LINUX_KPROBES_H +#define _SANDBOX_LINUX_KPROBES_H + +#include <asm/kprobes.h> +#include <linux/ranges.h> + +#ifdef CONFIG_KPROBES +DECLARE_SECTION_RANGE (kprobes); +#endif + +#endif /* _SANDBOX_LINUX_KPROBES_H */
tools/linker-tables/include/linux/module.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef _LINUX_MODULE_H +#define _LINUX_MODULE_H + +#include <linux/init.h> + +#define module_init (x) __initcall(x); +#define module_exit (x) __exitcall(x); + +struct module { +int (*init)(void ); +void (*exit)(void ); +}; + +#endif /* _LINUX_MODULE_H */
tools/linker-tables/include/linux/mutex.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef __LINUX_MUTEX_H +#define __LINUX_MUTEX_H + +#include <sys/types.h> +#include <linux/sched.h> +#include <pthread.h> + +struct mutex { +pthread_mutex_t lock; +}; + +void mutex_init (struct mutex *lock); +void mutex_destroy (struct mutex *lock); +void mutex_lock (struct mutex *lock); +void mutex_unlock (struct mutex *lock); + +#endif /* __LINUX_MUTEX_H */
tools/linker-tables/include/linux/pci.h new file +7 -0
@@ -0,0 +1,7 @@ +#include <linux/types.h> + +struct pci_fixup { +void (*hook)(void ); +}; + +bool detect_pci (void );
tools/linker-tables/include/linux/ps_const.h new file +46 -0
46 lines not on this page · raw message
tools/linker-tables/include/linux/sched.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef _LINUX_SCHED_H +#define _LINUX_SCHED_H + +#include <linux/ranges.h> + +DECLARE_SECTION_RANGE (sched_text); +#define __sched __LINUX_RANGE(SECTION_TEXT, sched_text) + +#endif /* _LINUX_SCHED_H */
tools/linker-tables/include/linux/spinlock.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef __LINUX_SPINLOCK_H +#define __LINUX_SPINLOCK_H + +#include <pthread.h> + +#define spinlock_t pthread_spinlock_t + +void spin_lock_init (spinlock_t *lock); +void spin_lock_destroy (spinlock_t *lock); +void spin_lock (spinlock_t *lock); +void spin_unlock (spinlock_t *lock); + +#endif /* __LINUX_SPINLOCK_H */
tools/linker-tables/include/linux/start_kernel.h new file +1 -0
@@ -0,0 +1 @@ +int start_kernel (void );
tools/linker-tables/include/linux/types.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef __LINUX_USER_TYPES_H +#define __LINUX_USER_TYPES_H + +#include <stdbool.h> +#include <stdint.h> +#include <unistd.h> +#include <stdlib.h> + +typedef unsigned char __u8 ; +typedef unsigned short __u16 ; +typedef unsigned int __u32 ; + +#endif /* __LINUX_USER_TYPES_H */
tools/linker-tables/include/linux/workqueue.h new file +51 -0
51 lines not on this page · raw message
tools/linker-tables/include/xen/xen.h new file +4 -0
@@ -0,0 +1,4 @@ +#include <linux/types.h> + +bool booting_xen (void ); +int startup_xen (void );
tools/linker-tables/kernel/locking/mutex.c new file +28 -0
@@ -0,0 +1,28 @@ +#include <linux/kernel.h> +#include <linux/mutex.h> + +DEFINE_SECTION_RANGE (sched_text,SECTION_TEXT ); + +void __sched mutex_init(struct mutex *lock) +{ +int r; + + r =pthread_mutex_init (&lock->lock,NULL ); +if (r) +BUG_ON (r); +} + +void __sched mutex_destroy(struct mutex *lock) +{ +pthread_mutex_destroy (&lock->lock);
Lines of this file are not shown. View the raw message.
tools/linker-tables/kernel/locking/spinlock.c new file +26 -0
Lines of this file are not shown. View the raw message.
tools/linker-tables/kernel/main.c new file +32 -0
Lines of this file are not shown. View the raw message.
tools/linker-tables/kernel/workqueue.c new file +43 -0
43 lines not on this page · raw message
tools/linker-tables/lib/string.c new file +26 -0
Lines of this file are not shown. View the raw message.
tools/linker-tables/pci-quirks.c new file +13 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.9.2
Part of the diff is not shown here. View the raw message.
Re: [PATCH v1 7/7] tools: add userspace linker table sandbox
Quoted 15 lines · On Fri, Aug 19, 2016 at 2:41 PM, <[email protected]> wrote:
From: "Luis R. Rodriguez" <[email protected]>
Add a userspace sandbox to allow easy experimentation and test extensions with linker tables, section ranges and the new section core definitions.
The userspace sandbox tries to mimic the Linux kernel development flow as much as possible, it however relies on and uses libc. Support is currently only provided to
x86_64.v4: this patch is new in this series -- added to the kenrel as
suggested by Boris, as otherwise it'd be really hard to keep an external userspace repository in sync.Signed-off-by Luis R. Rodriguez <[email protected]>
Quoted 11 lines
--- Documentation/sections/linker-tables.rst | 4 +- MAINTAINERS | 1 + include/linux/tables.h | 5 +- tools/Makefile | 3 +- .../arch/x86/include/generated/asm/section-core.h | 1 + tools/arch/x86/include/generated/ranges.h | 1 + tools/arch/x86/include/generated/tables.h | 1 + tools/include/asm-generic/ranges.h | 103 ++++ tools/include/asm-generic/section-core.h | 341 +++++++++++ tools/include/asm-generic/tables.h | 50 ++
Aren't a bunch of these files exact duplicates of the headers in include/linux?
-Kees
Signature · 7 lines
Kees Cook Nexus Security _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Luis R. Rodriguez
maintainerRe: [PATCH v1 7/7] tools: add userspace linker table sandbox
Quoted 28 lines · Kees Cook
Quoted 15 lines · On Fri, Aug 19, 2016 at 2:41 PM, <[email protected]> wrote:
From: "Luis R. Rodriguez" <[email protected]>
Add a userspace sandbox to allow easy experimentation and test extensions with linker tables, section ranges and the new section core definitions.
The userspace sandbox tries to mimic the Linux kernel development flow as much as possible, it however relies on and uses libc. Support is currently only provided to
x86_64.v4: this patch is new in this series -- added to the kenrel as
suggested by Boris, as otherwise it'd be really hard to keep an external userspace repository in sync.Signed-off-by Luis R. Rodriguez <[email protected]>Quoted 11 lines
--- Documentation/sections/linker-tables.rst | 4 +- MAINTAINERS | 1 + include/linux/tables.h | 5 +- tools/Makefile | 3 +- .../arch/x86/include/generated/asm/section-core.h | 1 + tools/arch/x86/include/generated/ranges.h | 1 + tools/arch/x86/include/generated/tables.h | 1 + tools/include/asm-generic/ranges.h | 103 ++++ tools/include/asm-generic/section-core.h | 341 +++++++++++ tools/include/asm-generic/tables.h | 50 ++
Quoted 1 line
Aren't a bunch of these files exact duplicates of the headers in
include/linux?
Indeed... This a userspace tools/ architecture decision that was made long ago, so its not up to me, I am just following the strategy devised and picked up. Refer to 7d7d1bf1d1dabe435ef50efb051724b8664749cb ("perf bench: Copy kernel files needed to build mem{cpy,set} x86_64 benchmarks") for an example of previous similar work. By sharing header files this enable more tools/ to be hacked on.
Luis
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
H. Peter Anvin
reviewerRe: [PATCH v1 7/7] tools: add userspace linker table sandbox
Vrabel <[email protected]>,Konrad Rzeszutek Wilk <[email protected]>,Michael Brown <[email protected]>,Juergen Gross <[email protected]>,Andrew Cooper <[email protected]>,Andy Shevchenko <[email protected]>,Paul Gortmaker <[email protected]>,"[email protected]" <[email protected]>,Andi Kleen <[email protected]>,[email protected],[email protected],[email protected],Michal Marek <[email protected]>,Rasmus Villemoes <[email protected]>,Jiri Kosina <[email protected]>,=?UTF-8?B?7KGw6rK966+8?= <[email protected]>,linux-kbuild <[email protected]>,Tony Luck <[email protected]>,Andrew Morton <[email protected]>,[email protected],"[email protected]" <linu
[email protected]>,linux-sh <[email protected]>,sparclinux <[email protected]>,Catalin Marinas <[email protected]>,Will Deacon <[email protected]>,Ste!
ven
Rostedt <[email protected]>,Jani Nikula <[email protected]>,Mauro Carvalho Chehab <[email protected]>,[email protected],[email protected],Mark Salter <[email protected]>,Chris Zankel <[email protected]>,Max Filippov <[email protected]>,[email protected],Paul Mackerras <[email protected]>,Michael Ellerman <[email protected]>,James Bottomley <[email protected]>
Message-ID: <[email protected]>
Quoted 45 lines · Luis R. Rodriguez
Quoted 9 lines · Kees Cook
Quoted 8 lines · On Fri, Aug 19, 2016 at 2:41 PM, <[email protected]> wrote:
From: "Luis R. Rodriguez" <[email protected]>
Add a userspace sandbox to allow easy experimentation and test extensions with linker tables, section ranges and the new section core definitions.
The userspace sandbox tries to mimic the Linux kernel development flow as much as possible, it however relies on and uses libc.
Support
Quoted 6 lines
Quoted 6 lines
is currently only provided to
x86_64.v4: this patch is new in this series -- added to the kenrel as
suggested by Boris, as otherwise it'd be really hard to keep an external userspace repository in sync.Quoted 11 lines
Quoted 11 lines
Signed-off-by Luis R. Rodriguez <[email protected]>--- Documentation/sections/linker-tables.rst | 4 +- MAINTAINERS | 1 + include/linux/tables.h | 5 +- tools/Makefile | 3 +- .../arch/x86/include/generated/asm/section-core.h | 1 + tools/arch/x86/include/generated/ranges.h | 1 + tools/arch/x86/include/generated/tables.h | 1 + tools/include/asm-generic/ranges.h | 103 ++++ tools/include/asm-generic/section-core.h | 341+++++++++++
Quoted 3 lines
Quoted 1 line
tools/include/asm-generic/tables.h | 50 ++Aren't a bunch of these files exact duplicates of the headers in
include/linux?Indeed... This a userspace
tools/architecture decision that was made long ago,
so its not up to me, I am just following the strategy devised and picked up.
Refer to7d7d1bf1d1dabe435ef50efb051724b8664749cb("perf bench: Copy kernel
files needed to build mem{cpy,set}x86_64benchmarks") for an example of
previous similar work. By sharing header files this enable moretools/to be hacked on.
Quoted 1 line
Luis
I think this is a legacy from before the uapi change that should really be fixed. If we need to export additional kernel structures for the tools, we could define a third level of we really need it.
Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse brevity and formatting.
Re: [PATCH v1 7/7] tools: add userspace linker table sandbox
Em Mon, Aug 22, 2016 at 05:28:42PM -0700, H. Peter Anvin escreveu:
Quoted 23 lines · Luis R. Rodriguez
Quoted 14 lines · Kees Cook
Quoted 11 lines · On Fri, Aug 19, 2016 at 2:41 PM, <[email protected]> wrote:
Quoted 8 lines
tools/Makefile | 3 +- .../arch/x86/include/generated/asm/section-core.h | 1 + tools/arch/x86/include/generated/ranges.h | 1 + tools/arch/x86/include/generated/tables.h | 1 + tools/include/asm-generic/ranges.h | 103 ++++ tools/include/asm-generic/section-core.h | 341tools/include/asm-generic/tables.h | 50 ++Aren't a bunch of these files exact duplicates of the headers in
include/linux?Quoted 7 lines
Indeed... This a userspace
tools/architecture decision that was made long ago, so its not up to me, I am just following the strategy devised and picked up. Refer to7d7d1bf1d1dabe435ef50efb051724b8664749cb("perf bench: Copy kernel files needed to build mem{cpy,set}x86_64benchmarks") for an example of previous similar work. By sharing header files this enable moretools/to be hacked on.
Quoted 3 lines
I think this is a legacy from before the uapi change that should really be fixed. If we need to export additional kernel structures for the tools, we could define a third level of we really need it.
No, it is something recent, its just that from time to time files that tools/ included from outside, i.e. from the kernel sources, made tools/ break, so after discussion with Linus and Ingo[1], it was decided we would grab copies and never more access anything outside tools/ directly.
Instead we would check for changes and warn the tools/ developers about it, so that they could check what has changed, that could mean changes should/could be done to tools/ using those headers.
- Arnaldo
Re: [PATCH v1 7/7] tools: add userspace linker table sandbox
Quoted 24 lines · Arnaldo Carvalho de Melo
Em Mon, Aug 22, 2016 at 05:28:42PM -0700, H. Peter Anvin escreveu:
Quoted 22 lines · Luis R. Rodriguez
Quoted 21 lines · Kees Cook
Quoted 11 lines · On Fri, Aug 19, 2016 at 2:41 PM, <[email protected]> wrote:
Quoted 8 lines
tools/Makefile | 3 +- .../arch/x86/include/generated/asm/section-core.h | 1 + tools/arch/x86/include/generated/ranges.h | 1 + tools/arch/x86/include/generated/tables.h | 1 + tools/include/asm-generic/ranges.h | 103 ++++ tools/include/asm-generic/section-core.h | 341tools/include/asm-generic/tables.h | 50 ++Aren't a bunch of these files exact duplicates of the headers in
include/linux?Indeed... This a userspace
tools/architecture decision that was made long ago, so its not up to me, I am just following the strategy devised and picked up. Refer to7d7d1bf1d1dabe435ef50efb051724b8664749cb("perf bench: Copy kernel files needed to build mem{cpy,set}x86_64benchmarks") for an example of previous similar work. By sharing header files this enable moretools/to be hacked on.
Quoted 7 lines
Quoted 3 lines
I think this is a legacy from before the uapi change that should really be fixed. If we need to export additional kernel structures for the tools, we could define a third level of we really need it.
No, it is something recent, its just that from time to time files that
tools/included from outside, i.e. from the kernel sources, madetools/break, so after discussion with Linus and Ingo[1], it was decided we would
This [1] reference seems missing. I'm curious to see the thread. I wonder if something could be done to just generate the needed headers from the canonical locations into the tools/ locations?
Quoted 5 lines
grab copies and never more access anything outside
tools/directly.Instead we would check for changes and warn the
tools/developers about it, so that they could check what has changed, that could mean changes should/could be done totools/using those headers.
Is there anything automated in place to notice when these changes happen?
-Kees
Signature · 2 lines
Kees Cook Nexus Security
Re: [PATCH v1 7/7] tools: add userspace linker table sandbox
Em Tue, Aug 23, 2016 at 10:28:39PM -0400, Kees Cook escreveu:
Quoted 21 lines
Quoted 18 lines · Arnaldo Carvalho de Melo
Em Mon, Aug 22, 2016 at 05:28:42PM -0700, H. Peter Anvin escreveu:
Quoted 17 lines · Luis R. Rodriguez
Quoted 5 lines · Kees Cook
Quoted 2 lines
Aren't a bunch of these files exact duplicates of the headers in
include/linux?Quoted 7 lines
Indeed... This a userspace
tools/architecture decision that was made long ago, so its not up to me, I am just following the strategy devised and picked up. Refer to7d7d1bf1d1dabe435ef50efb051724b8664749cb("perf bench: Copy kernel files needed to build mem{cpy,set}x86_64benchmarks") for an example of previous similar work. By sharing header files this enable moretools/to be hacked on.I think this is a legacy from before the uapi change that should really be fixed. If we need to export additional kernel structures for the tools, we could define a third level of we really need it.
Quoted 5 lines
Quoted 3 lines
No, it is something recent, its just that from time to time files that
tools/included from outside, i.e. from the kernel sources, madetools/break, so after discussion with Linus and Ingo[1], it was decided we wouldThis [1] reference seems missing. I'm curious to see the thread. I
I added the '[1]', went to look for the discussion yesterday, but it was a private conversation with ~15 people, bummer, but the one below has Ingo describing it in another occasion where a new utility got added to tools/, objtool:
https://lkml.kernel.org/r/[email protected]
And yeah, I started using stuff directly from the kernel, breakage took place, we changed course.
Quoted 2 lines
wonder if something could be done to just generate the needed headers from the canonical locations into the
tools/locations?
Then that would bring possible problems, better to do it manually when auto-detected.
Quoted 7 lines
Quoted 5 lines
grab copies and never more access anything outside
tools/directly.Instead we would check for changes and warn the
tools/developers about it, so that they could check what has changed, that could mean changes should/could be done totools/using those headers.Is there anything automated in place to notice when these changes happen?
See 791cceb89f7987c0375ff2e8971928a47f62ccae, among others, but it will amount to something like:
Changes detected by the tools build system:
$ make -C tools/perf O=/tmp/build/perf install-bin
make: Entering directory '/home/acme/git/linux/tools/perf'
BUILD: Doing 'make -j4' parallel build
---> Warning: tools/include/uapi/linux/bpf.h differs from kernel <-------
INSTALL GTK UI
CC /tmp/build/perf/bench/mem-memcpy-x86-64-asm.o
<SNIP>
$- Arnaldo
Luis R. Rodriguez
maintainerRe: [PATCH v1 7/7] tools: add userspace linker table sandbox
Quoted 10 lines · Arnaldo Carvalho de Melo
Changes detected by the tools build system:
$ make -C tools/perf O=/tmp/build/perf install-bin make: Entering directory '/home/acme/git/linux/tools/perf' BUILD: Doing 'make -j4' parallel build ---> Warning: tools/include/uapi/linux/bpf.h differs from kernel <------- INSTALL GTK UI CC /tmp/build/perf/bench/mem-memcpy-x86-64-asm.o <SNIP> $
I borrowed the same strategy from perf tools and generalized this through helpers a bit as Makefile helpers in the linker-tables sandbox:
HEADERS = \
../../include/asm-generic/section-core.h \
../../include/asm-generic/ranges.h \
../../include/asm-generic/tables.h \
../../include/linux/sections.h \
../../include/linux/ranges.h \
../../include/linux/tables.h__check_headers: $(HEADERS)
@$(foreach h, $(HEADERS), \
(test -f $(h) && ( \
(diff -B $(subst ../,../,$(h)) $(h) >/dev/null) \
|| echo "Warning: $(subst ../../,tools/,$(h))differs from kernel" >&2 ) || true);)
Instead of doing the check / complaint at install it complains at build time. Its up to the tools to decide when they want this check, but perhaps later a generic check can be set up. My thought was later to move some of this as helpers in a generic tools Makefile to more easily enable other tools/ to do similar checks more easily. I suspect we may later want to keep a tighter tab on what tools need what headers and instead have a generic place to keep tabs on this, but we can do that slowly later after generalizing a checker.
In doing the linker table sandbox one of the needs I found in needing separate headers was that often you don't want the same copy as the kernel provides, as you want to port things over to work in userspace and often ported to libc. So other than the direct copies -- we also have another category of headers -- ported headers. Its possible not all tools may end up wanting the same port, this can be addressed through two means. One is having a generic port which should suffice for most tools that need libc, and for those that don't want the generic port they can just carry their own port in their own tree. The linker tables tools sandbox enables this by allowing first headers to be search in its own directory, that way it can override what is provided as generic in tools. However it may still be useful later to have two separate directories to be able to easily distinguish between "copies" and "ports". But this can be done later.
Thoughts?
Luis
Re: [PATCH v1 7/7] tools: add userspace linker table sandbox
Em Wed, Aug 24, 2016 at 09:20:12AM -0700, Luis R. Rodriguez escreveu:
Quoted 32 lines
Quoted 10 lines · Arnaldo Carvalho de Melo
Changes detected by the tools build system:
$ make -C tools/perf O=/tmp/build/perf install-bin make: Entering directory '/home/acme/git/linux/tools/perf' BUILD: Doing 'make -j4' parallel build ---> Warning: tools/include/uapi/linux/bpf.h differs from kernel <------- INSTALL GTK UI CC /tmp/build/perf/bench/mem-memcpy-x86-64-asm.o <SNIP> $I borrowed the same strategy from perf tools and generalized this through helpers a bit as
Makefilehelpers in the linker-tables sandbox:HEADERS = \ ../../include/asm-generic/section-core.h \ ../../include/asm-generic/ranges.h \ ../../include/asm-generic/tables.h \ ../../include/linux/sections.h \ ../../include/linux/ranges.h \ ../../include/linux/tables.h
__check_headers: $(HEADERS)@$(foreach h, $(HEADERS), \ (test -f $(h) && ( \ (diff -B $(subst ../,../,$(h)) $(h) >/dev/null) \ || echo "Warning: $(subst ../../,tools/,$(h))differs from kernel" >&2 ) || true);)
Quoted 8 lines
Instead of doing the check / complaint at install it complains at build time. Its up to the tools to decide when they want this check, but perhaps later a generic check can be set up. My thought was later to move some of this as helpers in a generic tools
Makefileto more easily enable othertools/to do similar checks more easily. I suspect we may later want to keep a tighter tab on what tools need what headers and instead have a generic place to keep tabs on this, but we can do that slowly later after generalizing a checker.
Right
Quoted 3 lines
In doing the linker table sandbox one of the needs I found in needing separate headers was that often you don't want the same copy as the kernel provides, as you want to port things over to work in userspace
Right, the ones that are direct copies are the ones being checked with diff, there are others, as you say, that are not copies and are not being checked at all :-\
Example:
tools/include/linux/rbtree.h
The kernel one has RCU stuff, in it and tools still doesn't have some userspace RCU implementation that could provide what it expects.
Without collaboration from the kernel people working on include/linux/rbtree.h, that is what we can do.
Quoted 2 lines
and often ported to libc. So other than the direct copies -- we also have another category of headers -- ported headers. Its possible not
yeah
Quoted 11 lines
all tools may end up wanting the same port, this can be addressed through two means. One is having a generic port which should suffice for most tools that need libc, and for those that don't want the generic port they can just carry their own port in their own tree. The linker tables tools sandbox enables this by allowing first headers to be search in its own directory, that way it can override what is provided as generic in tools. However it may still be useful later to have two separate directories to be able to easily distinguish between "copies" and "ports". But this can be done later.
Thoughts?
I don't see problems with your reasoning, do what is faster for having your tool in place and we can go on improving the way tools/ gets stuff from the kernel, how we detect changes that could be interesting to get and eventually how kernel developers can help in this process.
What we don't want is to burden the kernel developers with things for tools/.
- Arnaldo
H. Peter Anvin
reviewerRe: [PATCH v1 7/7] tools: add userspace linker table sandbox
In reply to Luis R. RodriguezVrabel <[email protected]>,Konrad Rzeszutek Wilk <[email protected]>,Michael Brown <[email protected]>,Juergen Gross <[email protected]>,Andrew Cooper <[email protected]>,Andy Shevchenko <[email protected]>,Paul Gortmaker <[email protected]>,"[email protected]" <[email protected]>,Andi Kleen <[email protected]>,[email protected],[email protected],[email protected],Michal Marek <[email protected]>,Rasmus Villemoes <[email protected]>,Jiri Kosina <[email protected]>,=?UTF-8?B?7KGw6rK966+8?= <[email protected]>,linux-kbuild <[email protected]>,Tony Luck <[email protected]>,Andrew Morton <[email protected]>,[email protected],"[email protected]" <[email protected]>,linux-sh <[email protected]>,sparclinux <[email protected]>,Catalin Marinas <[email protected]>,Will Deacon <[email protected]>,Ste!
ven
Rostedt <[email protected]>,Jani Nikula <[email protected]>,Mauro Carvalho Chehab <[email protected]>,[email protected],[email protected],Mark Salter <[email protected]>,Chris Zankel <[email protected]>,Max Filippov <[email protected]>,[email protected],Paul Mackerras <[email protected]>,Michael Ellerman <[email protected]>,James Bottomley <[email protected]>
Message-ID: <[email protected]>
Quoted 45 lines · Luis R. Rodriguez
Quoted 9 lines · Kees Cook
Quoted 8 lines · On Fri, Aug 19, 2016 at 2:41 PM, <[email protected]> wrote:
From: "Luis R. Rodriguez" <[email protected]>
Add a userspace sandbox to allow easy experimentation and test extensions with linker tables, section ranges and the new section core definitions.
The userspace sandbox tries to mimic the Linux kernel development flow as much as possible, it however relies on and uses libc.
Support
Quoted 6 lines
Quoted 6 lines
is currently only provided to
x86_64.v4: this patch is new in this series -- added to the kenrel as
suggested by Boris, as otherwise it'd be really hard to keep an external userspace repository in sync.Quoted 11 lines
Quoted 11 lines
Signed-off-by Luis R. Rodriguez <[email protected]>--- Documentation/sections/linker-tables.rst | 4 +- MAINTAINERS | 1 + include/linux/tables.h | 5 +- tools/Makefile | 3 +- .../arch/x86/include/generated/asm/section-core.h | 1 + tools/arch/x86/include/generated/ranges.h | 1 + tools/arch/x86/include/generated/tables.h | 1 + tools/include/asm-generic/ranges.h | 103 ++++ tools/include/asm-generic/section-core.h | 341+++++++++++
Quoted 3 lines
Quoted 1 line
tools/include/asm-generic/tables.h | 50 ++Aren't a bunch of these files exact duplicates of the headers in
include/linux?Indeed... This a userspace
tools/architecture decision that was made long ago,
so its not up to me, I am just following the strategy devised and picked up.
Refer to7d7d1bf1d1dabe435ef50efb051724b8664749cb("perf bench: Copy kernel
files needed to build mem{cpy,set}x86_64benchmarks") for an example of
previous similar work. By sharing header files this enable moretools/to be hacked on.
Quoted 1 line
Luis
I think this is a legacy from before the uapi change that should really be fixed. If we need to export additional kernel structures for the tools, we could define a third level of we really need it.
Signature · 6 lines
Sent from my Android device with K-9 Mail. Please excuse brevity and formatting. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
H. Peter Anvin
reviewerRe: [PATCH v1 7/7] tools: add userspace linker table sandbox
In reply to Luis R. RodriguezVrabel <[email protected]>,Konrad Rzeszutek Wilk <[email protected]>,Michael Brown <[email protected]>,Juergen Gross <[email protected]>,Andrew Cooper <[email protected]>,Andy Shevchenko <[email protected]>,Paul Gortmaker <[email protected]>,"[email protected]" <[email protected]>,Andi Kleen <[email protected]>,[email protected],[email protected],[email protected],Michal Marek <[email protected]>,Rasmus Villemoes <[email protected]>,Jiri Kosina <[email protected]>,=?UTF-8?B?7KGw6rK966+8?= <[email protected]>,linux-kbuild <[email protected]>,Tony Luck <[email protected]>,Andrew Morton <[email protected]>,[email protected],"[email protected]" <linu
[email protected]>,linux-sh <[email protected]>,sparclinux <[email protected]>,Catalin Marinas <[email protected]>,Will Deacon <[email protected]>,Ste!
ven
Rostedt <[email protected]>,Jani Nikula <[email protected]>,Mauro Carvalho Chehab <[email protected]>,[email protected],[email protected],Mark Salter <[email protected]>,Chris Zankel <[email protected]>,Max Filippov <[email protected]>,[email protected],Paul Mackerras <[email protected]>,Michael Ellerman <[email protected]>,James Bottomley <[email protected]>
Message-ID: <[email protected]>
Quoted 45 lines · Luis R. Rodriguez
Quoted 9 lines · Kees Cook
Quoted 8 lines · On Fri, Aug 19, 2016 at 2:41 PM, <[email protected]> wrote:
From: "Luis R. Rodriguez" <[email protected]>
Add a userspace sandbox to allow easy experimentation and test extensions with linker tables, section ranges and the new section core definitions.
The userspace sandbox tries to mimic the Linux kernel development flow as much as possible, it however relies on and uses libc.
Support
Quoted 6 lines
Quoted 6 lines
is currently only provided to
x86_64.v4: this patch is new in this series -- added to the kenrel as
suggested by Boris, as otherwise it'd be really hard to keep an external userspace repository in sync.Quoted 11 lines
Quoted 11 lines
Signed-off-by Luis R. Rodriguez <[email protected]>--- Documentation/sections/linker-tables.rst | 4 +- MAINTAINERS | 1 + include/linux/tables.h | 5 +- tools/Makefile | 3 +- .../arch/x86/include/generated/asm/section-core.h | 1 + tools/arch/x86/include/generated/ranges.h | 1 + tools/arch/x86/include/generated/tables.h | 1 + tools/include/asm-generic/ranges.h | 103 ++++ tools/include/asm-generic/section-core.h | 341+++++++++++
Quoted 3 lines
Quoted 1 line
tools/include/asm-generic/tables.h | 50 ++Aren't a bunch of these files exact duplicates of the headers in
include/linux?Indeed... This a userspace
tools/architecture decision that was made long ago,
so its not up to me, I am just following the strategy devised and picked up.
Refer to7d7d1bf1d1dabe435ef50efb051724b8664749cb("perf bench: Copy kernel
files needed to build mem{cpy,set}x86_64benchmarks") for an example of
previous similar work. By sharing header files this enable moretools/to be hacked on.
Quoted 1 line
Luis
I think this is a legacy from before the uapi change that should really be fixed. If we need to export additional kernel structures for the tools, we could define a third level of we really need it.
Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse brevity and formatting.
Re: [PATCH v1 0/7] tools: add linker table userspace sandbox
In reply to [email protected]Quoted 1 line · On 08/19/2016 04:41 PM, [email protected] wrote:
Please let me know if there are any issue or questions.
Only that this has been the majority of the traffic on the linux-sh mailing list for over a month and I'm still not sure why anyone should care.
I have no idea what problem it solves, despite reading a couple dozen messages in the thread, and the most recent two 0/x intro messages. Its purpose seems to be ensuring that lld.llvm.org has more work to do if it ever wants to build the kernel without binutils?
I also am not certain why every revision of it is cc'd to linux-sh. Is it generic linker infrastructure change, or is it something that affects this architecture specifically? As far as I can tell nothing in this most recent 7-patch series touches arch/sh at all, you just cc'd our list because you think the work you're doing is _important_, not that it's specifically relevant to us.
Rob
Rich Felker
maintainerRe: [PATCH v1 0/7] tools: add linker table userspace sandbox
Quoted 11 lines · Rob Landley
Quoted 1 line · On 08/19/2016 04:41 PM, [email protected] wrote:
Please let me know if there are any issue or questions.
Only that this has been the majority of the traffic on the linux-sh mailing list for over a month and I'm still not sure why anyone should care.
I have no idea what problem it solves, despite reading a couple dozen messages in the thread, and the most recent two 0/x intro messages. Its purpose seems to be ensuring that lld.llvm.org has more work to do if it ever wants to build the kernel without binutils?
Quoted 6 lines
I also am not certain why every revision of it is cc'd to linux-sh. Is it generic linker infrastructure change, or is it something that affects this architecture specifically? As far as I can tell nothing in this most recent 7-patch series touches
arch/shat all, you just cc'd our list because you think the work you're doing is _important_, not that it's specifically relevant to us.
Incidentally I'm happy to have been CC'd since this infrastructure is _really_ nice for doing things generically with device tree. The ability to add new linker-section-based tables without having to manually hack up linker script templates will make it so we can do things like adding tables for cache controllers or mmus (that are needed quite early in init and can't go through the platform device system).
BTW we kinda lucked out that there was already the linker table infrastructure for cpu enable methods for smp; this patch series makes it so future stuff doesn't have to rely on luck or invasive changes.
Rich
H. Peter Anvin
reviewerRe: [PATCH v1 0/7] tools: add linker table userspace sandbox
[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],linux@ra!
smusville
moes.dk,[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]
Message-ID: <[email protected]>
Quoted 32 lines · Rich Felker
Quoted 5 lines · Rob Landley
Quoted 1 line · On 08/19/2016 04:41 PM, [email protected] wrote:
Please let me know if there are any issue or questions.
Only that this has been the majority of the traffic on the linux-sh mailing list for over a month and I'm still not sure why anyone
should care.
Quoted 3 lines
I have no idea what problem it solves, despite reading a couple dozen messages in the thread, and the most recent two 0/x intro messages.
Its
Quoted 1 line
purpose seems to be ensuring that lld.llvm.org has more work to do if
it
Quoted 3 lines
ever wants to build the kernel without binutils?
I also am not certain why every revision of it is cc'd to linux-sh.
Is
Quoted 1 line
it generic linker infrastructure change, or is it something that
affects
Quoted 4 lines
this architecture specifically? As far as I can tell nothing in this most recent 7-patch series touches
arch/shat all, you just cc'd our list because you think the work you're doing is _important_, not that it's specifically relevant to us.Incidentally I'm happy to have been CC'd since this infrastructure is _really_ nice for doing things generically with device tree. The ability to add new linker-section-based tables without having to manually hack up linker script templates will make it so we can do things like adding tables for cache controllers or mmus (that are needed quite early in init and can't go through the platform device system).
Quoted 5 lines
BTW we kinda lucked out that there was already the linker table infrastructure for cpu enable methods for smp; this patch series makes it so future stuff doesn't have to rely on luck or invasive changes.
Rich
Incidentally, I want to use this for the RAID algorithms.
Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse brevity and formatting.
H. Peter Anvin
reviewerRe: [PATCH v1 0/7] tools: add linker table userspace sandbox
In reply to Rich Felker[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],linux@ra!
smusville
moes.dk,[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]
Message-ID: <[email protected]>
Quoted 32 lines · Rich Felker
Quoted 5 lines · Rob Landley
Quoted 1 line · On 08/19/2016 04:41 PM, [email protected] wrote:
Please let me know if there are any issue or questions.
Only that this has been the majority of the traffic on the linux-sh mailing list for over a month and I'm still not sure why anyone
should care.
Quoted 3 lines
I have no idea what problem it solves, despite reading a couple dozen messages in the thread, and the most recent two 0/x intro messages.
Its
Quoted 1 line
purpose seems to be ensuring that lld.llvm.org has more work to do if
it
Quoted 3 lines
ever wants to build the kernel without binutils?
I also am not certain why every revision of it is cc'd to linux-sh.
Is
Quoted 1 line
it generic linker infrastructure change, or is it something that
affects
Quoted 4 lines
this architecture specifically? As far as I can tell nothing in this most recent 7-patch series touches
arch/shat all, you just cc'd our list because you think the work you're doing is _important_, not that it's specifically relevant to us.Incidentally I'm happy to have been CC'd since this infrastructure is _really_ nice for doing things generically with device tree. The ability to add new linker-section-based tables without having to manually hack up linker script templates will make it so we can do things like adding tables for cache controllers or mmus (that are needed quite early in init and can't go through the platform device system).
Quoted 5 lines
BTW we kinda lucked out that there was already the linker table infrastructure for cpu enable methods for smp; this patch series makes it so future stuff doesn't have to rely on luck or invasive changes.
Rich
Incidentally, I want to use this for the RAID algorithms.
Signature · 6 lines
Sent from my Android device with K-9 Mail. Please excuse brevity and formatting. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
H. Peter Anvin
reviewerRe: [PATCH v1 0/7] tools: add linker table userspace sandbox
In reply to Rich Felker[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]
ntel.com,[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],linux@ra!
smusville
moes.dk,[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]
Message-ID: <[email protected]>
Quoted 32 lines · Rich Felker
Quoted 5 lines · Rob Landley
Quoted 1 line · On 08/19/2016 04:41 PM, [email protected] wrote:
Please let me know if there are any issue or questions.
Only that this has been the majority of the traffic on the linux-sh mailing list for over a month and I'm still not sure why anyone
should care.
Quoted 3 lines
I have no idea what problem it solves, despite reading a couple dozen messages in the thread, and the most recent two 0/x intro messages.
Its
Quoted 1 line
purpose seems to be ensuring that lld.llvm.org has more work to do if
it
Quoted 3 lines
ever wants to build the kernel without binutils?
I also am not certain why every revision of it is cc'd to linux-sh.
Is
Quoted 1 line
it generic linker infrastructure change, or is it something that
affects
Quoted 4 lines
this architecture specifically? As far as I can tell nothing in this most recent 7-patch series touches
arch/shat all, you just cc'd our list because you think the work you're doing is _important_, not that it's specifically relevant to us.Incidentally I'm happy to have been CC'd since this infrastructure is _really_ nice for doing things generically with device tree. The ability to add new linker-section-based tables without having to manually hack up linker script templates will make it so we can do things like adding tables for cache controllers or mmus (that are needed quite early in init and can't go through the platform device system).
Quoted 5 lines
BTW we kinda lucked out that there was already the linker table infrastructure for cpu enable methods for smp; this patch series makes it so future stuff doesn't have to rely on luck or invasive changes.
Rich
Incidentally, I want to use this for the RAID algorithms.
Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse brevity and formatting.
H. Peter Anvin
reviewerRe: [PATCH v1 0/7] tools: add linker table userspace sandbox
In reply to Rich Felker[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]
ntel.com,[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],linux@ra!
smusville
moes.dk,[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]
Message-ID: <[email protected]>
Quoted 32 lines · Rich Felker
Quoted 5 lines · Rob Landley
Quoted 1 line · On 08/19/2016 04:41 PM, [email protected] wrote:
Please let me know if there are any issue or questions.
Only that this has been the majority of the traffic on the linux-sh mailing list for over a month and I'm still not sure why anyone
should care.
Quoted 3 lines
I have no idea what problem it solves, despite reading a couple dozen messages in the thread, and the most recent two 0/x intro messages.
Its
Quoted 1 line
purpose seems to be ensuring that lld.llvm.org has more work to do if
it
Quoted 3 lines
ever wants to build the kernel without binutils?
I also am not certain why every revision of it is cc'd to linux-sh.
Is
Quoted 1 line
it generic linker infrastructure change, or is it something that
affects
Quoted 4 lines
this architecture specifically? As far as I can tell nothing in this most recent 7-patch series touches
arch/shat all, you just cc'd our list because you think the work you're doing is _important_, not that it's specifically relevant to us.Incidentally I'm happy to have been CC'd since this infrastructure is _really_ nice for doing things generically with device tree. The ability to add new linker-section-based tables without having to manually hack up linker script templates will make it so we can do things like adding tables for cache controllers or mmus (that are needed quite early in init and can't go through the platform device system).
Quoted 5 lines
BTW we kinda lucked out that there was already the linker table infrastructure for cpu enable methods for smp; this patch series makes it so future stuff doesn't have to rely on luck or invasive changes.
Rich
Incidentally, I want to use this for the RAID algorithms.
Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse brevity and formatting.
Re: [PATCH v1 0/7] tools: add linker table userspace sandbox
In reply to [email protected](trimmed Ccs... jeez)
Quoted 7 lines · On 19 August 2016 at 23:41, <[email protected]> wrote:
From: "Luis R. Rodriguez" <[email protected]>
The original v3 series for linker tables made reference only to an external repository userspace sandbox application, however Boris noted it'd be difficult ot keep this in sync with the kernel so advised to consider integrate with the kernel. I've taken steps in this direction.
[...]
Quoted 1 line
Please let me know if there are any issue or questions.
+#define __VMLINUX_SYMBOL(x) x
+#define VMLINUX_SYMBOL(x) __VMLINUX_SYMBOL(x)
+#define LINUX_SECTION_START(name) VMLINUX_SYMBOL(name)
+#define DECLARE_LINUX_SECTION(type, name) \
+ extern type VMLINUX_SYMBOL(name)[], \
+ VMLINUX_SYMBOL(name##__end)[]
+#define DECLARE_LINKTABLE(type, name) \
+ DECLARE_LINUX_SECTION(type, name)
+#define LINKTABLE_FOR_EACH(pointer, tbl) \ + for (pointer = LINUX_SECTION_START(tbl); \ + pointer < LINUX_SECTION_END(tbl); \
+ pointer++)
I think this is subject to getting optimised out by newer gccs, since it sees the START(tbl) and END(tbl) symbols as two completely different arrays. See the short discussion here:
https://lkml.org/lkml/2016/6/26/73 (the first attempt is wrong, so don't look at that)
It is possible that < is different from != and always does the right thing, but I haven't checked.
I have a WIP branch that converts most of the existing tables in the kernel to use the external_array() macro which makes gcc throw away any knowledge it had about a pointer being part of an array.
Vegard
Luis R. Rodriguez
maintainerRe: [PATCH v1 0/7] tools: add linker table userspace sandbox
Quoted 36 lines · Vegard Nossum
Quoted 7 lines · On 19 August 2016 at 23:41, <[email protected]> wrote:
From: "Luis R. Rodriguez" <[email protected]>
The original v3 series for linker tables made reference only to an external repository userspace sandbox application, however Boris noted it'd be difficult ot keep this in sync with the kernel so advised to consider integrate with the kernel. I've taken steps in this direction.
[...]
Quoted 1 line
Please let me know if there are any issue or questions.
(quoted diff) +12
-0+#define __VMLINUX_SYMBOL(x) x +#define VMLINUX_SYMBOL(x) __VMLINUX_SYMBOL(x) +#define LINUX_SECTION_START(name) VMLINUX_SYMBOL(name) +#define DECLARE_LINUX_SECTION(type, name) \ + extern type VMLINUX_SYMBOL(name)[], \ + VMLINUX_SYMBOL(name##__end)[] +#define DECLARE_LINKTABLE(type, name) \ + DECLARE_LINUX_SECTION(type, name) +#define LINKTABLE_FOR_EACH(pointer, tbl) \ + for (pointer = LINUX_SECTION_START(tbl); \ + pointer < LINUX_SECTION_END(tbl); \ + pointer++)I think this is subject to getting optimised out by newer gccs, since it sees the START(tbl) and END(tbl) symbols as two completely different arrays. See the short discussion here:
https://lkml.org/lkml/2016/6/26/73 (the first attempt is wrong, so don't look at that)
Quoted 6 lines
It is possible that < is different from != and always does the right thing, but I haven't checked.
I have a WIP branch that converts most of the existing tables in the kernel to use the
external_array()macro which makes gcc throw away any knowledge it had about a pointer being part of an array.
Was there no compiler option to disable the optimization ?
Please do Cc me on your patches, either way we can coordinate changes depending on which series gets merged. If your external_array() change lands upstream first I'll see it on linux-next shortly can rebase and adjust code then as that is what I base my patches on.
Do we know if there exceptions to the optimization issue for this and if so what patterns follow ? We can test with simple userspace code if this will be an issue with gcc 7 by trying the demo in tools/linker-tables/ using this git tree and branch 20160819-linker-table-v4 :
https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linux-next.git/log/?h=20160819-linker-table-v4
Luis
Luis R. Rodriguez
maintainerv2 cover tools: add linker table userspace sandbox
In reply to [email protected]This v2 is just bump refresh from the v1. The last series did not receive any criticism, however as expected there was much more substantial feedback on the real kernel side. This series just refreshes all the userspace code to work with the latest changes made in kernel space.
This patch is the second part to the linker table work, the first part is the kernel work. I've split it up to make it easier to review. All the code is present on my linux-next 20161221-linker-tables-v5 branch on kernel.org [1], if you check that code out you can disregard the last patch as it was a debug patch to force enable a driver on 0-day and Guenter's testbed.
[0] https://lkml.kernel.org/r/[email protected]
[1] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linux-next.git/log/?h=20161221-linker-tables-v5
Luis R. Rodriguez (6):
tools: add a userspace tools bug.h
tools: add init.h for tools
tools: add __used and enable to override
tools: expand export.h with VMLINUX_SYMBOL()
tools: add __section() to compiler.h
tools: add userspace linker table sandbox
Documentation/sections/linker-tables.rst | 4 +- MAINTAINERS | 1 + include/linux/tables.h | 5 +- tools/Makefile | 3 +- .../arch/x86/include/generated/asm/section-core.h | 1 + tools/arch/x86/include/generated/ranges.h | 1 + tools/arch/x86/include/generated/tables.h | 1 + tools/include/asm-generic/bug.h | 24 + tools/include/asm-generic/ranges.h | 93 +++ tools/include/asm-generic/section-core.h | 348 +++++++++++ tools/include/asm-generic/tables.h | 48 ++ tools/include/linux/bug.h | 6 + tools/include/linux/compiler.h | 8 + tools/include/linux/export.h | 22 + tools/include/linux/init.h | 9 + tools/include/linux/kernel.h | 2 + tools/include/linux/ranges.h | 183 ++++++ tools/include/linux/sections.h | 87 +++ tools/include/linux/string.h | 1 + tools/include/linux/tables.h | 684 +++++++++++++++++++++ tools/linker-tables/.gitignore | 2 + tools/linker-tables/Makefile | 184 ++++++ tools/linker-tables/README | 114 ++++ tools/linker-tables/arch/x86/include/asm/asm.h | 17 + tools/linker-tables/arch/x86/include/asm/boot.h | 1 + .../linker-tables/arch/x86/include/asm/bootparam.h | 32 + tools/linker-tables/arch/x86/include/asm/kprobes.h | 7 + .../linker-tables/arch/x86/include/asm/ps_const.h | 23 + tools/linker-tables/arch/x86/include/asm/ranges.h | 6 + .../arch/x86/include/asm/section-core.h | 1 + tools/linker-tables/arch/x86/include/asm/setup.h | 6 + tools/linker-tables/arch/x86/include/asm/tables.h | 6 + tools/linker-tables/arch/x86/include/asm/x86.h | 4 + .../arch/x86/include/asm/x86_init_fn.h | 169 +++++ tools/linker-tables/arch/x86/kernel/alpha.c | 9 + tools/linker-tables/arch/x86/kernel/alternative.c | 31 + tools/linker-tables/arch/x86/kernel/beta.c | 9 + tools/linker-tables/arch/x86/kernel/head64.c | 58 ++ tools/linker-tables/arch/x86/kernel/init.c | 42 ++ tools/linker-tables/arch/x86/kernel/kasan.c | 10 + tools/linker-tables/arch/x86/kernel/kprobes.c | 51 ++ tools/linker-tables/arch/x86/kernel/vmlinux.lds.S | 277 +++++++++ tools/linker-tables/arch/x86/mm/init.c | 10 + tools/linker-tables/arch/x86/xen/init.c | 13 + tools/linker-tables/drivers/acme.c | 32 + tools/linker-tables/drivers/synth/common.c | 16 + tools/linker-tables/drivers/synth/common.h | 2 + tools/linker-tables/drivers/synth/main.c | 35 ++ tools/linker-tables/drivers/synth/or.S | 39 ++ tools/linker-tables/drivers/synth/synth.h | 2 + tools/linker-tables/drivers/xen-driver.c | 11 + .../include/asm-generic/arch_init_fn.h | 50 ++ tools/linker-tables/include/asm-generic/kprobes.h | 26 + tools/linker-tables/include/linux/bitops.h | 6 + tools/linker-tables/include/linux/init.h | 40 ++ tools/linker-tables/include/linux/kasan.h | 5 + tools/linker-tables/include/linux/kernel.h | 2 + tools/linker-tables/include/linux/kprobes.h | 11 + tools/linker-tables/include/linux/module.h | 14 + tools/linker-tables/include/linux/mutex.h | 17 + tools/linker-tables/include/linux/pci.h | 7 + tools/linker-tables/include/linux/printk.h | 26 + tools/linker-tables/include/linux/ps_const.h | 46 ++ tools/linker-tables/include/linux/sched.h | 9 + tools/linker-tables/include/linux/spinlock.h | 13 + tools/linker-tables/include/linux/start_kernel.h | 1 + tools/linker-tables/include/linux/types.h | 13 + tools/linker-tables/include/linux/workqueue.h | 51 ++ tools/linker-tables/include/xen/xen.h | 4 + tools/linker-tables/kernel/locking/mutex.c | 28 + tools/linker-tables/kernel/locking/spinlock.c | 26 + tools/linker-tables/kernel/main.c | 32 + tools/linker-tables/kernel/workqueue.c | 43 ++ tools/linker-tables/lib/string.c | 26 + tools/linker-tables/main.c | 20 + tools/linker-tables/pci-quirks.c | 13 + tools/linker-tables/pci.c | 29 + 77 files changed, 3303 insertions(+), 5 deletions(-) create mode 100644 tools/arch/x86/include/generated/asm/section-core.h create mode 100644 tools/arch/x86/include/generated/ranges.h create mode 100644 tools/arch/x86/include/generated/tables.h create mode 100644 tools/include/asm-generic/bug.h create mode 100644 tools/include/asm-generic/ranges.h create mode 100644 tools/include/asm-generic/section-core.h create mode 100644 tools/include/asm-generic/tables.h create mode 100644 tools/include/linux/bug.h create mode 100644 tools/include/linux/init.h create mode 100644 tools/include/linux/ranges.h create mode 100644 tools/include/linux/sections.h create mode 100644 tools/include/linux/tables.h create mode 100644 tools/linker-tables/.gitignore create mode 100644 tools/linker-tables/Makefile create mode 100644 tools/linker-tables/README create mode 100644 tools/linker-tables/arch/x86/include/asm/asm.h create mode 100644 tools/linker-tables/arch/x86/include/asm/boot.h create mode 100644 tools/linker-tables/arch/x86/include/asm/bootparam.h create mode 100644 tools/linker-tables/arch/x86/include/asm/kprobes.h create mode 100644 tools/linker-tables/arch/x86/include/asm/ps_const.h create mode 100644 tools/linker-tables/arch/x86/include/asm/ranges.h create mode 100644 tools/linker-tables/arch/x86/include/asm/section-core.h create mode 100644 tools/linker-tables/arch/x86/include/asm/setup.h create mode 100644 tools/linker-tables/arch/x86/include/asm/tables.h create mode 100644 tools/linker-tables/arch/x86/include/asm/x86.h create mode 100644 tools/linker-tables/arch/x86/include/asm/x86_init_fn.h create mode 100644 tools/linker-tables/arch/x86/kernel/alpha.c create mode 100644 tools/linker-tables/arch/x86/kernel/alternative.c create mode 100644 tools/linker-tables/arch/x86/kernel/beta.c create mode 100644 tools/linker-tables/arch/x86/kernel/head64.c create mode 100644 tools/linker-tables/arch/x86/kernel/init.c create mode 100644 tools/linker-tables/arch/x86/kernel/kasan.c create mode 100644 tools/linker-tables/arch/x86/kernel/kprobes.c create mode 100644 tools/linker-tables/arch/x86/kernel/vmlinux.lds.S create mode 100644 tools/linker-tables/arch/x86/mm/init.c create mode 100644 tools/linker-tables/arch/x86/xen/init.c create mode 100644 tools/linker-tables/drivers/acme.c create mode 100644 tools/linker-tables/drivers/synth/common.c create mode 100644 tools/linker-tables/drivers/synth/common.h create mode 100644 tools/linker-tables/drivers/synth/main.c create mode 100644 tools/linker-tables/drivers/synth/or.S create mode 100644 tools/linker-tables/drivers/synth/synth.h create mode 100644 tools/linker-tables/drivers/xen-driver.c create mode 100644 tools/linker-tables/include/asm-generic/arch_init_fn.h create mode 100644 tools/linker-tables/include/asm-generic/kprobes.h create mode 100644 tools/linker-tables/include/linux/bitops.h create mode 100644 tools/linker-tables/include/linux/init.h create mode 100644 tools/linker-tables/include/linux/kasan.h create mode 100644 tools/linker-tables/include/linux/kernel.h create mode 100644 tools/linker-tables/include/linux/kprobes.h create mode 100644 tools/linker-tables/include/linux/module.h create mode 100644 tools/linker-tables/include/linux/mutex.h create mode 100644 tools/linker-tables/include/linux/pci.h create mode 100644 tools/linker-tables/include/linux/printk.h create mode 100644 tools/linker-tables/include/linux/ps_const.h create mode 100644 tools/linker-tables/include/linux/sched.h create mode 100644 tools/linker-tables/include/linux/spinlock.h create mode 100644 tools/linker-tables/include/linux/start_kernel.h create mode 100644 tools/linker-tables/include/linux/types.h create mode 100644 tools/linker-tables/include/linux/workqueue.h create mode 100644 tools/linker-tables/include/xen/xen.h create mode 100644 tools/linker-tables/kernel/locking/mutex.c create mode 100644 tools/linker-tables/kernel/locking/spinlock.c create mode 100644 tools/linker-tables/kernel/main.c create mode 100644 tools/linker-tables/kernel/workqueue.c create mode 100644 tools/linker-tables/lib/string.c create mode 100644 tools/linker-tables/main.c create mode 100644 tools/linker-tables/pci-quirks.c create mode 100644 tools/linker-tables/pci.c
Signature · 1 line
2.10.1
Luis R. Rodriguez
maintainerPATCH v2 1/6 tools: add a userspace tools bug.h
This will be used later by the userspace linker-tables sandbox. As a convenience, include bug.h on kernel.h -- this is not done on upstream kernel.h, however most header files do include bug.h eventually, if we were to only add the ones that need it we'd need to copy a lot of headers to tools for the ony purpose of includeing bug.h. This simplifies that.
--- tools/include/asm-generic/bug.h | 24 ++++++++++++++++++++++++ tools/include/linux/bug.h | 6 ++++++ tools/include/linux/kernel.h | 2 ++ 3 files changed, 32 insertions(+) create mode 100644 tools/include/asm-generic/bug.h create mode 100644 tools/include/linux/bug.h
tools/include/asm-generic/bug.h new file +24 -0
@@ -0,0 +1,24 @@ +#ifndef __TOOLS_ASM_GENERIC_BUG +#define __TOOLS_ASM_GENERIC_BUG + +#include <stdio.h> +#include <stdlib.h> + +#define BUG () do { \ + fprintf(stderr, "----------------------------------------------------------\n"); \ + fprintf (stderr, "BUG on %s at %s: %i\n", __func__, __FILE__, __LINE__); \ + abort(); \ +} \ +while (0) + +#define BUG_ON (cond) do { if (cond) BUG(); } while (0) + +#define WARN_ON (__test) do { \ + if (__test) { \ + fprintf(stderr, "----------------------------------------------------------\n");\ + fprintf (stderr, "WARN_ON on %s at %s: %i\n", __func__, __FILE__, __LINE__); \ + } \ +} \ +while (0) + +#endif /* __TOOLS_ASM_GENERIC_BUG */
tools/include/linux/bug.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _TOOLS_LINUX_BUG_H +#define _TOOLS_LINUX_BUG_H + +#include <asm-generic/bug.h> + +#endif /* _TOOLS_LINUX_BUG_H */
tools/include/linux/kernel.h +2 -0
@@ -5,6 +5,8 @@#include <stddef.h> #include <assert.h> +#include <linux/bug.h> +#define DIV_ROUND_UP (n,d) (((n) + (d) - 1) / (d))#define PERF_ALIGN (x, a) __PERF_ALIGN_MASK(x, (typeof(x))(a)-1)
Signature · 1 line
2.10.1
Luis R. Rodriguez
maintainerPATCH v2 2/6 tools: add init.h for tools
In reply to Luis R. RodriguezStart off with just __ref -- we enalbe you to override, if you do that then you can define your own. The way you'd use this, if you do override, is define your own __ref and then use include_next.
--- tools/include/linux/init.h | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tools/include/linux/init.h
tools/include/linux/init.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef _TOOLS_LINUX_INIT_H +#define _TOOLS_LINUX_INIT_H + +/* this means you can add your own to fit you own userspace needs */ +#ifndef __ref +#define __ref +#endif + +#endif /* _TOOLS_LINUX_INIT_H */
Signature · 1 line
2.10.1
Luis R. Rodriguez
maintainerPATCH v2 3/6 tools: add __used and enable to override
In reply to Luis R. RodriguezThis adds __used, to be used later in the userspace linker-tables sandbox. If any userspace applicaiton wants to override they can add their own definition and then use include_next.
This definition should probably suffice for most uses cases though.
--- tools/include/linux/compiler.h | 6 ++++++ 1 file changed, 6 insertions(+)
tools/include/linux/compiler.h +6 -0
@@ -5,6 +5,12 @@/* The "volatile" is due to gcc bugs */ #define barrier () __asm__ __volatile__("": : :"memory") + +/* You can override as you see fit on your userspace tool */ +#ifndef __used +#define __used __attribute__((__used__)) +#endif +#ifndef __always_inline# define __always_inline inline __attribute__((always_inline))#endif
Signature · 1 line
2.10.1
Luis R. Rodriguez
maintainerPATCH v2 4/6 tools: expand export.h with VMLINUX_SYMBOL()
In reply to Luis R. RodriguezThis will be used later by the linker-table userspace sandbox.
--- tools/include/linux/export.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
tools/include/linux/export.h +22 -0
@@ -1,6 +1,28 @@#ifndef _TOOLS_LINUX_EXPORT_H_#define _TOOLS_LINUX_EXPORT_H_ +/* +* Export symbols from the kernel to modules. Forked from module.h +* to reduce the amount of pointless cruft we feed to gcc when only +* exporting a simple symbol or two. +* +* Try not to add #includes here. It slows compilation and makes kernel +* hackers place grumpy comments in header files. +*/ + +/* Some toolchains use a `_' prefix for all user symbols. */ +#ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX +#define __VMLINUX_SYMBOL (x) _##x +#define __VMLINUX_SYMBOL_STR (x) "_" #x +#else +#define __VMLINUX_SYMBOL (x) x +#define __VMLINUX_SYMBOL_STR (x) #x +#endif + +/* Indirect, so macros are expanded before pasting. */ +#define VMLINUX_SYMBOL (x) __VMLINUX_SYMBOL(x) +#define VMLINUX_SYMBOL_STR (x) __VMLINUX_SYMBOL_STR(x) +#define EXPORT_SYMBOL (sym)#define EXPORT_SYMBOL_GPL (sym)#define EXPORT_SYMBOL_GPL_FUTURE (sym)
Signature · 1 line
2.10.1
Luis R. Rodriguez
maintainerPATCH v2 5/6 tools: add __section() to compiler.h
In reply to Luis R. RodriguezThis will be used later by the userspace linker table.
--- tools/include/linux/compiler.h | 2 ++ 1 file changed, 2 insertions(+)
tools/include/linux/compiler.h +2 -0
@@ -132,4 +132,6 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s#define WRITE_ONCE (x, val) \ ({ union { typeof(x) __val; char __c[1]; } __u = { .__val = (val) }; __write_once_size(&(x), __u.__c, sizeof(x)); __u.__val; }) +#define __section (S ) __attribute__ ((__section__(#S))) +#endif /* _TOOLS_LINUX_COMPILER_H */
Signature · 1 line
2.10.1
Luis R. Rodriguez
maintainerPATCH v2 6/6 tools: add userspace linker table sandbox
In reply to Luis R. RodriguezAdd a userspace sandbox to allow easy experimentation and test extensions with linker tables, section ranges and the new section core definitions.
The userspace sandbox tries to mimic the Linux kernel development flow as much as possible, it however relies on and uses libc. Support is currently only provided to x86_64.
Demo run:
cd tools/linker-tables
make clean; make;
./demo
Initializing x86 bare metal world
x86-init: Number of init entries: 8
Initializing memory ...
Completed initializing memory !
Initializing pci ...
PCI fixup size: 1
Demo: Using LINKTABLE_FOR_EACHfoo_fixup
Demo: Using LINKTABLE_RUN_ALLfoo_fixup
Completed initializing pci !
Number of init entries: 1
Initializing kprobes ...
== OK: test_kprobe_0001 within range!
== OK: test_kprobe_0002 not in range as expected! Completed initializing kprobes !
Initializing kasan ...
Early init for Kasan...
Completed initializing kasan !
Initializing beta ...
Completed initializing beta !
Initializing alpha ...
Completed initializing alpha !
Booting bare metal
Calling start_kernel()...
ACME: Initializing ...
ACME: Finished init ... !
Synthetics: synth_init_or(2) returns: 0xDEADBEEF
Synthetics: ps_shr(0xDEADBEEF, get_demo_shr) returns: 0x0000DEAD
v5:
o Use ..rng.* instead of .rng.* as suggested by Nicholas Piggin. This is the typical way to avoid clashes with compiler generated sections.
o moves tools/include/linux/printk.h to tools linker-table/include/linux/printk.h -- we cannot generalize this just yet, more work is needed in terms of providing a namespace for headers for types of ports of kernel functionality to userspace.
o Adjust code according to the latest discussions for the linker tables API (section name macros are now gone).
o Give CONFIG_HAVE_ARCH_PS_CONST for x86 another good 'ol college try, still fails, but this is just a demo anyway. We can amend and fix make this more optimized for x86 later. Thanks Boris!
v4: this patch is new in this series -- added to the kenrel as
suggested by Boris, as otherwise it'd be really hard to keep an external userspace repository in sync.
--- Documentation/sections/linker-tables.rst | 4 +- MAINTAINERS | 1 + include/linux/tables.h | 5 +- tools/Makefile | 3 +- .../arch/x86/include/generated/asm/section-core.h | 1 + tools/arch/x86/include/generated/ranges.h | 1 + tools/arch/x86/include/generated/tables.h | 1 + tools/include/asm-generic/ranges.h | 93 +++ tools/include/asm-generic/section-core.h | 348 +++++++++++ tools/include/asm-generic/tables.h | 48 ++ tools/include/linux/ranges.h | 183 ++++++ tools/include/linux/sections.h | 87 +++ tools/include/linux/string.h | 1 + tools/include/linux/tables.h | 684 +++++++++++++++++++++ tools/linker-tables/.gitignore | 2 + tools/linker-tables/Makefile | 184 ++++++ tools/linker-tables/README | 114 ++++ tools/linker-tables/arch/x86/include/asm/asm.h | 17 + tools/linker-tables/arch/x86/include/asm/boot.h | 1 + .../linker-tables/arch/x86/include/asm/bootparam.h | 32 + tools/linker-tables/arch/x86/include/asm/kprobes.h | 7 + .../linker-tables/arch/x86/include/asm/ps_const.h | 23 + tools/linker-tables/arch/x86/include/asm/ranges.h | 6 + .../arch/x86/include/asm/section-core.h | 1 + tools/linker-tables/arch/x86/include/asm/setup.h | 6 + tools/linker-tables/arch/x86/include/asm/tables.h | 6 + tools/linker-tables/arch/x86/include/asm/x86.h | 4 + .../arch/x86/include/asm/x86_init_fn.h | 169 +++++ tools/linker-tables/arch/x86/kernel/alpha.c | 9 + tools/linker-tables/arch/x86/kernel/alternative.c | 31 + tools/linker-tables/arch/x86/kernel/beta.c | 9 + tools/linker-tables/arch/x86/kernel/head64.c | 58 ++ tools/linker-tables/arch/x86/kernel/init.c | 42 ++ tools/linker-tables/arch/x86/kernel/kasan.c | 10 + tools/linker-tables/arch/x86/kernel/kprobes.c | 51 ++ tools/linker-tables/arch/x86/kernel/vmlinux.lds.S | 277 +++++++++ tools/linker-tables/arch/x86/mm/init.c | 10 + tools/linker-tables/arch/x86/xen/init.c | 13 + tools/linker-tables/drivers/acme.c | 32 + tools/linker-tables/drivers/synth/common.c | 16 + tools/linker-tables/drivers/synth/common.h | 2 + tools/linker-tables/drivers/synth/main.c | 35 ++ tools/linker-tables/drivers/synth/or.S | 39 ++ tools/linker-tables/drivers/synth/synth.h | 2 + tools/linker-tables/drivers/xen-driver.c | 11 + .../include/asm-generic/arch_init_fn.h | 50 ++ tools/linker-tables/include/asm-generic/kprobes.h | 26 + tools/linker-tables/include/linux/bitops.h | 6 + tools/linker-tables/include/linux/init.h | 40 ++ tools/linker-tables/include/linux/kasan.h | 5 + tools/linker-tables/include/linux/kernel.h | 2 + tools/linker-tables/include/linux/kprobes.h | 11 + tools/linker-tables/include/linux/module.h | 14 + tools/linker-tables/include/linux/mutex.h | 17 + tools/linker-tables/include/linux/pci.h | 7 + tools/linker-tables/include/linux/printk.h | 26 + tools/linker-tables/include/linux/ps_const.h | 46 ++ tools/linker-tables/include/linux/sched.h | 9 + tools/linker-tables/include/linux/spinlock.h | 13 + tools/linker-tables/include/linux/start_kernel.h | 1 + tools/linker-tables/include/linux/types.h | 13 + tools/linker-tables/include/linux/workqueue.h | 51 ++ tools/linker-tables/include/xen/xen.h | 4 + tools/linker-tables/kernel/locking/mutex.c | 28 + tools/linker-tables/kernel/locking/spinlock.c | 26 + tools/linker-tables/kernel/main.c | 32 + tools/linker-tables/kernel/workqueue.c | 43 ++ tools/linker-tables/lib/string.c | 26 + tools/linker-tables/main.c | 20 + tools/linker-tables/pci-quirks.c | 13 + tools/linker-tables/pci.c | 29 + 71 files changed, 3232 insertions(+), 5 deletions(-) create mode 100644 tools/arch/x86/include/generated/asm/section-core.h create mode 100644 tools/arch/x86/include/generated/ranges.h create mode 100644 tools/arch/x86/include/generated/tables.h create mode 100644 tools/include/asm-generic/ranges.h create mode 100644 tools/include/asm-generic/section-core.h create mode 100644 tools/include/asm-generic/tables.h create mode 100644 tools/include/linux/ranges.h create mode 100644 tools/include/linux/sections.h create mode 100644 tools/include/linux/tables.h create mode 100644 tools/linker-tables/.gitignore create mode 100644 tools/linker-tables/Makefile create mode 100644 tools/linker-tables/README create mode 100644 tools/linker-tables/arch/x86/include/asm/asm.h create mode 100644 tools/linker-tables/arch/x86/include/asm/boot.h create mode 100644 tools/linker-tables/arch/x86/include/asm/bootparam.h create mode 100644 tools/linker-tables/arch/x86/include/asm/kprobes.h create mode 100644 tools/linker-tables/arch/x86/include/asm/ps_const.h create mode 100644 tools/linker-tables/arch/x86/include/asm/ranges.h create mode 100644 tools/linker-tables/arch/x86/include/asm/section-core.h create mode 100644 tools/linker-tables/arch/x86/include/asm/setup.h create mode 100644 tools/linker-tables/arch/x86/include/asm/tables.h create mode 100644 tools/linker-tables/arch/x86/include/asm/x86.h create mode 100644 tools/linker-tables/arch/x86/include/asm/x86_init_fn.h create mode 100644 tools/linker-tables/arch/x86/kernel/alpha.c create mode 100644 tools/linker-tables/arch/x86/kernel/alternative.c create mode 100644 tools/linker-tables/arch/x86/kernel/beta.c create mode 100644 tools/linker-tables/arch/x86/kernel/head64.c create mode 100644 tools/linker-tables/arch/x86/kernel/init.c create mode 100644 tools/linker-tables/arch/x86/kernel/kasan.c create mode 100644 tools/linker-tables/arch/x86/kernel/kprobes.c create mode 100644 tools/linker-tables/arch/x86/kernel/vmlinux.lds.S create mode 100644 tools/linker-tables/arch/x86/mm/init.c create mode 100644 tools/linker-tables/arch/x86/xen/init.c create mode 100644 tools/linker-tables/drivers/acme.c create mode 100644 tools/linker-tables/drivers/synth/common.c create mode 100644 tools/linker-tables/drivers/synth/common.h create mode 100644 tools/linker-tables/drivers/synth/main.c create mode 100644 tools/linker-tables/drivers/synth/or.S create mode 100644 tools/linker-tables/drivers/synth/synth.h create mode 100644 tools/linker-tables/drivers/xen-driver.c create mode 100644 tools/linker-tables/include/asm-generic/arch_init_fn.h create mode 100644 tools/linker-tables/include/asm-generic/kprobes.h create mode 100644 tools/linker-tables/include/linux/bitops.h create mode 100644 tools/linker-tables/include/linux/init.h create mode 100644 tools/linker-tables/include/linux/kasan.h create mode 100644 tools/linker-tables/include/linux/kernel.h create mode 100644 tools/linker-tables/include/linux/kprobes.h create mode 100644 tools/linker-tables/include/linux/module.h create mode 100644 tools/linker-tables/include/linux/mutex.h create mode 100644 tools/linker-tables/include/linux/pci.h create mode 100644 tools/linker-tables/include/linux/printk.h create mode 100644 tools/linker-tables/include/linux/ps_const.h create mode 100644 tools/linker-tables/include/linux/sched.h create mode 100644 tools/linker-tables/include/linux/spinlock.h create mode 100644 tools/linker-tables/include/linux/start_kernel.h create mode 100644 tools/linker-tables/include/linux/types.h create mode 100644 tools/linker-tables/include/linux/workqueue.h create mode 100644 tools/linker-tables/include/xen/xen.h create mode 100644 tools/linker-tables/kernel/locking/mutex.c create mode 100644 tools/linker-tables/kernel/locking/spinlock.c create mode 100644 tools/linker-tables/kernel/main.c create mode 100644 tools/linker-tables/kernel/workqueue.c create mode 100644 tools/linker-tables/lib/string.c create mode 100644 tools/linker-tables/main.c create mode 100644 tools/linker-tables/pci-quirks.c create mode 100644 tools/linker-tables/pci.c
Documentation/sections/linker-tables.rst +2 -2
@@ -11,11 +11,11 @@ About Linker tables .. kernel-doc:: include/linux/tables.h :doc: Introduction -Linker table provenance +Linker table provenance and userspace testing --------------------------------------------- .. kernel-doc:: include/linux/tables.h - :doc: Linker table provenance + :doc: Linker table provenance and userspace testing Benefits of using Linker tables ===============================
MAINTAINERS +1 -0
@@ -5413,6 +5413,7 @@ L: [email protected] S: Supported F: include/asm-generic/tables.h F: include/linux/tables.h +F: tools/linker-tables/ F: Documentation/sections/linker-tables.rst GENERIC PHY FRAMEWORK
include/linux/tables.h +3 -2
@@ -35,12 +35,13 @@*/ /** -* DOC: Linker table provenance +* DOC: Linker table provenance and userspace testing * * The Linux implementation of linker tables was inspired by the iPXE linker * table's solution (iPXE commit 67a10ef000cb7 "[contrib] Add rom-o-matic to * contrib "[0]). To see how this code evolved refer to the out of tree -* userspace linker-table tree [1]. +* userspace linker-table tree [1]. Linux has a similar userspace application +* in tools/linker-tables/ to help more easily test adding new extensions. * * Contrary to iPXE's solution which strives to force compilation of * everything using linker tables, Linux's solution allows for developers to be
tools/Makefile +2 -1
@@ -19,6 +19,7 @@ help: @echo ' kvm_stat - top-like utility for displaying kvm statistics' @echo ' leds - LEDs tools' @echo ' lguest - a minimal 32-bit x86 hypervisor' + @echo ' linker-tables - userspace liker table sandbox and related tools' @echo ' net - misc networking tools' @echo ' perf - Linux performance measurement and analysis tool' @echo ' selftests - various kernel selftests'
@@ -86,7 +87,7 @@ tmon: FORCE freefall: FORCE $(call descend,laptop/$@) -all: acpi cgroup cpupower gpio hv firewire lguest \ +all: acpi cgroup cpupower gpio hv firewire lguest linker-tables \ perf selftests turbostat usb \ virtio vm net x86_energy_perf_policy \ tmon freefall objtool
tools/arch/x86/include/generated/asm/section-core.h new file +1 -0
@@ -0,0 +1 @@ +#include <asm-generic/section-core.h>
tools/arch/x86/include/generated/ranges.h new file +1 -0
@@ -0,0 +1 @@ +#include <asm-generic/ranges.h>
tools/arch/x86/include/generated/tables.h new file +1 -0
@@ -0,0 +1 @@ +#include <asm-generic/tables.h>
tools/include/asm-generic/ranges.h new file +93 -0
93 lines not on this page · raw message
tools/include/asm-generic/section-core.h new file +348 -0
348 lines not on this page · raw message
tools/include/asm-generic/tables.h new file +48 -0
48 lines not on this page · raw message
tools/include/linux/ranges.h new file +183 -0
183 lines not on this page · raw message
tools/include/linux/sections.h new file +87 -0
87 lines not on this page · raw message
tools/include/linux/string.h +1 -0
@@ -3,6 +3,7 @@#include <linux/types.h> /* for size_t */ +#include <string.h> void *memdup (const void *src,size_t len);
tools/include/linux/tables.h new file +684 -0
684 lines not on this page · raw message
tools/linker-tables/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +arch/x86/kernel/vmlinux.lds +demo
tools/linker-tables/Makefile new file +184 -0
184 lines not on this page · raw message
tools/linker-tables/README new file +114 -0
114 lines not on this page · raw message
tools/linker-tables/arch/x86/include/asm/asm.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef _ASM_X86_ASM_H + +#ifdef __ASSEMBLY__ +# define __ASM_FORM (x) x +# define __ASM_FORM_RAW (x) x +# define __ASM_FORM_COMMA (x) x, +#else +# define __ASM_FORM (x) " " #x " " +# define __ASM_FORM_RAW (x) #x +# define __ASM_FORM_COMMA (x) " " #x "," +#endif + +# define __ASM_SEL (a,b) __ASM_FORM(b) +# define __ASM_SEL_RAW (a,b) __ASM_FORM_RAW(b) +#define _ASM_PTR __ASM_SEL(.long, .quad) + +#endif /* _ASM_X86_ASM_H */
tools/linker-tables/arch/x86/include/asm/boot.h new file +1 -0
@@ -0,0 +1 @@ +extern struct boot_params boot_params;
tools/linker-tables/arch/x86/include/asm/bootparam.h new file +32 -0
@@ -0,0 +1,32 @@ +#ifndef __BOOTPARAM_H +#define __BOOTPARAM_H + +#include <linux/types.h> + +struct setup_header { +__u32 hardware_subarch; +} __attribute__((packed)); + +struct boot_params { +struct setup_header hdr; +} __attribute__((packed)); + +enum { +X86_SUBARCH_PC =0 , +X86_SUBARCH_LGUEST , +X86_SUBARCH_XEN , +X86_SUBARCH_INTEL_MID , +X86_SUBARCH_CE4100 , +X86_NR_SUBARCHS , +}; + +#define X86_SUBARCH_ALL_SUBARCHS \ + ( \ + BIT(X86_SUBARCH_PC) | \ + BIT(X86_SUBARCH_LGUEST) | \ + BIT(X86_SUBARCH_XEN) | \ + BIT(X86_SUBARCH_INTEL_MID) | \ + BIT(X86_SUBARCH_CE4100) \ + ) + +#endif /* __BOOTPARAM_H */
tools/linker-tables/arch/x86/include/asm/kprobes.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _SANDBOX_ASM_X86_KPROBES_H +#define _SANDBOX_ASM_X86_KPROBES_H + +/* This is all we need for the demo */ +#include <asm-generic/kprobes.h> + +#endif /* _SANDBOX_ASM_X86_KPROBES_H */
tools/linker-tables/arch/x86/include/asm/ps_const.h new file +23 -0
@@ -0,0 +1,23 @@ +#ifndef __X86_PS_CONST +#define __X86_PS_CONST + +#include <linux/stringify.h> +#include <linux/tables.h> +#include <asm/asm.h> + +#define ps_shr (in, _func) \ +({ \ + __typeof__(in) _count; \ + \ + asm volatile( \ + "shr %P[_in],%[_count]\n" \ + "1:\n" \ + push_section_tbl(.init.data, ps_set_const_table, 01,) \ + _ASM_PTR "1b-1, %P2, %P3\n" \ + ".popsection\n" \ + : [_count] "=g" (_count) \ + : [_in] "i" (in), "i" (SET_CONST_U8), "i" (_func)); \ + (_count); \ +}) + +#endif /* __X86_PS_CONST */
tools/linker-tables/arch/x86/include/asm/ranges.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _ASM_X86_RANGES_H +#define _ASM_X86_RANGES_H + +#include <asm-generic/ranges.h> + +#endif /* _ASM_X86_RANGES_H */
tools/linker-tables/arch/x86/include/asm/section-core.h new file +1 -0
@@ -0,0 +1 @@ +#include <asm-generic/section-core.h>
tools/linker-tables/arch/x86/include/asm/setup.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef __LINUX_X86_USER_SETUP_H +#define __LINUX_X86_USER_SETUP_H + +/* I'm lazy */ + +#endif /* __LINUX_X86_USER_SETUP_H */
tools/linker-tables/arch/x86/include/asm/tables.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _ASM_X86_TABLES_H +#define _ASM_X86_TABLES_H + +#include <asm-generic/tables.h> + +#endif /* _ASM_X86_RANGES_H */
tools/linker-tables/arch/x86/include/asm/x86.h new file +4 -0
@@ -0,0 +1,4 @@ +int startup_64 (void ); +int x86_64_start_reservations (void ); +void setup_arch (void ); +void late_init (void );
tools/linker-tables/arch/x86/include/asm/x86_init_fn.h new file +169 -0
169 lines not on this page · raw message
tools/linker-tables/arch/x86/kernel/alpha.c new file +9 -0
@@ -0,0 +1,9 @@ +#include <linux/kernel.h> +#include <asm/x86_init_fn.h> + +static void early_init_alpha (void ) { +pr_info ("Initializing alpha ...\n" ); +pr_info ("Completed initializing alpha !\n" ); +} + +x86_init_early_pc (early_init_alpha);
tools/linker-tables/arch/x86/kernel/alternative.c new file +31 -0
@@ -0,0 +1,31 @@ +#include <asm/x86_init_fn.h> + +#include <linux/kernel.h> +#include <linux/ps_const.h> + +void apply_alternatives_linker_tables (void ) +{ +unsigned int num_consts =LINKTABLE_SIZE (ps_set_const_table); +struct ps_set_const *ps_const; + +if (!num_consts) +return ; + +pr_debug ("Number of init entries: %d\n" , num_consts); + + LINKTABLE_FOR_EACH(ps_const, ps_set_const_table) { +switch (ps_const->type) { +case SET_CONST_U8 : + *ps_const->count = (__u8 ) ps_const->func (); +break ; +case SET_CONST_U16 : + *ps_const->count = (__u16 ) ps_const->func (); +break ; +case SET_CONST_U32 : + *ps_const->count = (__u16 ) ps_const->func (); +break ; + } + } +} + +x86_init_early_pc (apply_alternatives_linker_tables);
tools/linker-tables/arch/x86/kernel/beta.c new file +9 -0
@@ -0,0 +1,9 @@ +#include <linux/kernel.h> +#include <asm/x86_init_fn.h> + +static void early_init_beta (void ) { +pr_info ("Initializing beta ...\n" ); +pr_info ("Completed initializing beta !\n" ); +} + +x86_init_early_pc (early_init_beta);
tools/linker-tables/arch/x86/kernel/head64.c new file +58 -0
58 lines not on this page · raw message
tools/linker-tables/arch/x86/kernel/init.c new file +42 -0
42 lines not on this page · raw message
tools/linker-tables/arch/x86/kernel/kasan.c new file +10 -0
@@ -0,0 +1,10 @@ +#include <linux/kernel.h> +#include <asm/x86_init_fn.h> + +void kasan_early_init (void ) { +pr_info ("Initializing kasan ...\n" ); +pr_info ("Early init for Kasan...\n" ); +pr_info ("Completed initializing kasan !\n" ); +} + +x86_init_early_pc (kasan_early_init);
tools/linker-tables/arch/x86/kernel/kprobes.c new file +51 -0
51 lines not on this page · raw message
tools/linker-tables/arch/x86/kernel/vmlinux.lds.S new file +277 -0
277 lines not on this page · raw message
tools/linker-tables/arch/x86/mm/init.c new file +10 -0
@@ -0,0 +1,10 @@ +#include <linux/kernel.h> +#include <asm/x86_init_fn.h> + +static void early_init_memory (void ) { +pr_info ("Initializing memory ...\n" ); +sleep (1 ); +pr_info ("Completed initializing memory !\n" ); +} + +x86_init_early_all (early_init_memory);
tools/linker-tables/arch/x86/xen/init.c new file +13 -0
@@ -0,0 +1,13 @@ +#include <linux/kernel.h> +#include <linux/tables.h> +#include <asm/x86_init_fn.h> +#include <asm/x86.h> + +void startup_xen (void ) +{ +pr_info ("Initializing Xen guest\n" ); + +x86_init_fn_early_init (); + +x86_64_start_reservations (); +}
tools/linker-tables/drivers/acme.c new file +32 -0
@@ -0,0 +1,32 @@ +#define pr_fmt (fmt) "ACME: " fmt + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/workqueue.h> + +void *acme_todo (void *arg); +static DECLARE_WORK(acme_work, acme_todo); + +void *acme_todo (void *arg) +{ +pr_info ("Running scheduled work\n" ); +pthread_exit (NULL ); +} + +static int acme_init_driver (void ) { +pr_info ("Initializing ...\n" ); +sleep (2 ); +pr_info ("Finished init ... !\n" ); + +init_work (&acme_work); +schedule_work (&acme_work); + +return 0 ; +} +module_init (acme_init_driver); + +static void acme_exit (void ) +{ +cancel_work_sync (&acme_work); +}; +module_exit (acme_exit);
tools/linker-tables/drivers/synth/common.c new file +16 -0
@@ -0,0 +1,16 @@ +int demo_or_1 (int arg) +{ +switch (arg) { +case 1 : +return 0xDEA00000 ; +case 2 : +return 0X000D0000 ; +default : +return arg *2 ; + } +} + +int demo_or_2 (void ) +{ +return 0x0000BEEF ; +}
tools/linker-tables/drivers/synth/common.h new file +2 -0
@@ -0,0 +1,2 @@ +int demo_or_1 (int arg); +int demo_or_2 (void );
tools/linker-tables/drivers/synth/main.c new file +35 -0
@@ -0,0 +1,35 @@ +#define pr_fmt (fmt) "Synthetics: " fmt + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/ps_const.h> + +#include "common.h" +#include "synth.h" + +DEFINE_LINKTABLE_INIT_DATA(struct ps_set_const, ps_set_const_table); + +unsigned int get_demo_shr (void ) +{ +return 16 ; +} + +static int synth_init (void ) +{ +int synth_or; +int val =2 ; +const unsigned int reg =ps_shr (0xDEADBEEF , get_demo_shr); + + synth_or =synth_init_or (val); +pr_info ("synth_init_or(%d) returns: 0x%08X\n" , val, synth_or); + +pr_info ("ps_shr(0x%08X, get_demo_shr) returns: 0x%08X\n" ,0xDEADBEEF , reg); + +return 0 ; +} +module_init (synth_init); + +static void synth_exit (void ) +{ +} +module_exit (synth_exit);
tools/linker-tables/drivers/synth/or.S new file +39 -0
@@ -0,0 +1,39 @@ +#include <asm/ranges.h> + + DEFINE_SECTION_RANGE(.text, synth_init_or) + + push_section_rng_level(.text, synth_init_or, "01", ) + /* err = 0; */ + pushq %rbp + movq %rsp,%rbp + pushq %rbx + xorq %rbx,%rbx + .popsection + + push_section_rng_level(.text, synth_init_or, "99", ) + /* return err; */ + movq %rbx,%rax + popq %rbx + popq %rbp + retq + .popsection + + push_section_rng_level(.text, synth_init_or, "50", ) + /* err |= demo_or_1(1); */ + movl $1,%edi + call demo_or_1 + orq %rax,%rbx + .popsection + + push_section_rng_level(.text, synth_init_or, "50", ) + /* err |= demo_or_1(2); */ + movl $2,%edi + call demo_or_1 + orq %rax,%rbx + .popsection + + push_section_rng_level(.text, synth_init_or, "50", ) + /* err |= demo_or_2(); */ + call demo_or_2 + orq %rax,%rbx + .popsection
tools/linker-tables/drivers/synth/synth.h new file +2 -0
@@ -0,0 +1,2 @@ +/* Synthetic demos go here */ +int synth_init_or (int arg);
tools/linker-tables/drivers/xen-driver.c new file +11 -0
@@ -0,0 +1,11 @@ +#include <asm/x86_init_fn.h> +#include <linux/kernel.h> +#include <linux/pci.h> +#include <xen/xen.h> + +static void early_xen_init_driver (void ) { +pr_info ("Initializing xen driver\n" ); +sleep (2 ); +} + +x86_init_early_xen (early_xen_init_driver);
tools/linker-tables/include/asm-generic/arch_init_fn.h new file +50 -0
50 lines not on this page · raw message
tools/linker-tables/include/asm-generic/kprobes.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef _SANDBOX_ASM_GENERIC_KPROBES_H +#define _SANDBOX_ASM_GENERIC_KPROBES_H + +#if defined(__KERNEL__) && !defined(__ASSEMBLY__) +#ifdef CONFIG_KPROBES +#include <linux/tables.h> +#include <asm/ranges.h> +/* +* Blacklist ganerating macro. Specify functions which is not probed +* by using this macro. +*/ +# define __NOKPROBE_SYMBOL (fname) \ +static LINKTABLE_INIT_DATA(_kprobe_blacklist, all) \ + _kbl_addr_##fname = (unsigned long)fname; +# define NOKPROBE_SYMBOL (fname) __NOKPROBE_SYMBOL(fname) +/* Use this to forbid a kprobes attach on very low level functions */ +# define __kprobes __LINUX_RANGE(.text, kprobes) +# define nokprobe_inline __always_inline +#else +# define NOKPROBE_SYMBOL (fname) +# define __kprobes +# define nokprobe_inline inline +#endif +#endif /* defined(__KERNEL__) && !defined(__ASSEMBLY__) */ + +#endif /* _SANDBOX_ASM_GENERIC_KPROBES_H */
tools/linker-tables/include/linux/bitops.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _LINUX_BITOPS_H +#define _LINUX_BITOPS_H + +#define BIT (nr) (1UL << (nr)) + +#endif /* _LINUX_BITOPS_H */
tools/linker-tables/include/linux/init.h new file +40 -0
@@ -0,0 +1,40 @@ +#ifndef _SANDBOX_LINUX_INIT_H +#define _SANDBOX_LINUX_INIT_H + +#include_next <linux/init.h> +#include <linux/types.h> +#include <linux/sections.h> + +#define __init __section(.init.text) +#define __exit __section(.exit.text) + +#ifndef __ASSEMBLY__ +#include <linux/tables.h> +typedef int (*initcall_t )(void ); +typedef void (*exitcall_t )(void ); + +DECLARE_LINKTABLE (initcall_t, init_calls); +DECLARE_LINKTABLE (exitcall_t, exit_calls); + +#define __define_initcall (fn, id) \ + static LINKTABLE_INIT_DATA(init_calls, id) \ + __initcall_##fn##id = fn + +#define pure_initcall (fn) __define_initcall(fn, 0) +#define core_initcall (fn) __define_initcall(fn, 1) +#define postcore_initcall (fn) __define_initcall(fn, 2) +#define arch_initcall (fn) __define_initcall(fn, 3) +#define subsys_initcall (fn) __define_initcall(fn, 4) +#define fs_initcall (fn) __define_initcall(fn, 5) +#define device_initcall (fn) __define_initcall(fn, 6) +#define late_initcall (fn) __define_initcall(fn, 7) + +#define __initcall (fn) device_initcall(fn) + +#define __exitcall (fn) \ + static LINKTABLE_INIT_DATA(exit_calls, any) \ + __exitcall_##fn = fn; + +#endif + +#endif /* _SANDBOX_LINUX_INIT_H */
tools/linker-tables/include/linux/kasan.h new file +5 -0
@@ -0,0 +1,5 @@ +#include <linux/types.h> + +void kasan_early_init (void ); +int kasan_init (void ); +bool is_kasan_setup (void );
tools/linker-tables/include/linux/kernel.h new file +2 -0
@@ -0,0 +1,2 @@ +#include_next <linux/kernel.h> +#include <linux/printk.h>
tools/linker-tables/include/linux/kprobes.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef _SANDBOX_LINUX_KPROBES_H +#define _SANDBOX_LINUX_KPROBES_H + +#include <asm/kprobes.h> +#include <linux/ranges.h> + +#ifdef CONFIG_KPROBES +DECLARE_SECTION_RANGE (kprobes); +#endif + +#endif /* _SANDBOX_LINUX_KPROBES_H */
tools/linker-tables/include/linux/module.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef _LINUX_MODULE_H +#define _LINUX_MODULE_H + +#include <linux/init.h> + +#define module_init (x) __initcall(x); +#define module_exit (x) __exitcall(x); + +struct module { +int (*init)(void ); +void (*exit)(void ); +}; + +#endif /* _LINUX_MODULE_H */
tools/linker-tables/include/linux/mutex.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef __LINUX_MUTEX_H +#define __LINUX_MUTEX_H + +#include <sys/types.h> +#include <linux/sched.h> +#include <pthread.h> + +struct mutex { +pthread_mutex_t lock; +}; + +void mutex_init (struct mutex *lock); +void mutex_destroy (struct mutex *lock); +void mutex_lock (struct mutex *lock); +void mutex_unlock (struct mutex *lock); + +#endif /* __LINUX_MUTEX_H */
tools/linker-tables/include/linux/pci.h new file +7 -0
@@ -0,0 +1,7 @@ +#include <linux/types.h> + +struct pci_fixup { +void (*hook)(void ); +}; + +bool detect_pci (void );
tools/linker-tables/include/linux/printk.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef _SANDBOX_KERNEL_PRINTK +#define _SANDBOX_KERNEL_PRINTK + +#ifdef __KERNEL__ + +#include <stdio.h> + +#ifndef pr_fmt +#define pr_fmt (fmt) fmt +#endif + +#ifndef pr_info +#define pr_info (fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__) +#endif + +#ifndef pr_err +#define pr_err (fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__) +#endif + +#ifndef pr_debug +#define pr_debug (fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__) +#endif + +#endif /* __KERNEL__ */ + +#endif /* _SANDBOX_KERNEL_PRINTK */
tools/linker-tables/include/linux/ps_const.h new file +46 -0
46 lines not on this page · raw message
tools/linker-tables/include/linux/sched.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef _LINUX_SCHED_H +#define _LINUX_SCHED_H + +#include <linux/ranges.h> + +DECLARE_SECTION_RANGE (sched_text); +#define __sched __LINUX_RANGE(.text, sched_text) + +#endif /* _LINUX_SCHED_H */
tools/linker-tables/include/linux/spinlock.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef __LINUX_SPINLOCK_H +#define __LINUX_SPINLOCK_H + +#include <pthread.h> + +#define spinlock_t pthread_spinlock_t + +void spin_lock_init (spinlock_t *lock); +void spin_lock_destroy (spinlock_t *lock); +void spin_lock (spinlock_t *lock); +void spin_unlock (spinlock_t *lock); + +#endif /* __LINUX_SPINLOCK_H */
tools/linker-tables/include/linux/start_kernel.h new file +1 -0
@@ -0,0 +1 @@ +int start_kernel (void );
tools/linker-tables/include/linux/types.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef __LINUX_USER_TYPES_H +#define __LINUX_USER_TYPES_H + +#include <stdbool.h> +#include <stdint.h>
Lines of this file are not shown. View the raw message.
tools/linker-tables/include/linux/workqueue.h new file +51 -0
51 lines not on this page · raw message
tools/linker-tables/include/xen/xen.h new file +4 -0
Lines of this file are not shown. View the raw message.
tools/linker-tables/kernel/locking/mutex.c new file +28 -0
Lines of this file are not shown. View the raw message.
tools/linker-tables/kernel/locking/spinlock.c new file +26 -0
Lines of this file are not shown. View the raw message.
tools/linker-tables/kernel/main.c new file +32 -0
Lines of this file are not shown. View the raw message.
tools/linker-tables/kernel/workqueue.c new file +43 -0
43 lines not on this page · raw message
tools/linker-tables/lib/string.c new file +26 -0
Lines of this file are not shown. View the raw message.
tools/linker-tables/pci-quirks.c new file +13 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.10.1
Part of the diff is not shown here. View the raw message.
Luis R. Rodriguez
maintainerv3 cover tools: add linker table userspace sandbox
In reply to Luis R. RodriguezThis v3 only modifies the tools sandbox to adjust for the linker tables macro renames suggested by Andy Shevchenko. It applies after the kernel changes, a public tree is available with both series applied [0] based on linux-next tag next-20170109, if you pull from there please drop the last patch as it is a debug patch used to force 0-day to force-enable the test driver.
[0] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linux-next.git/log/?h=20170109-linker-tables-v6
Luis
Luis R. Rodriguez (6):
tools: add a userspace tools bug.h
tools: add init.h for tools
tools: add __used and enable to override
tools: expand export.h with VMLINUX_SYMBOL()
tools: add __section() to compiler.h
tools: add userspace linker table sandbox
Documentation/sections/linker-tables.rst | 4 +- MAINTAINERS | 1 + include/linux/tables.h | 5 +- tools/Makefile | 3 +- .../arch/x86/include/generated/asm/section-core.h | 1 + tools/arch/x86/include/generated/ranges.h | 1 + tools/arch/x86/include/generated/tables.h | 1 + tools/include/asm-generic/bug.h | 24 + tools/include/asm-generic/ranges.h | 93 +++ tools/include/asm-generic/section-core.h | 348 +++++++++++ tools/include/asm-generic/tables.h | 48 ++ tools/include/linux/bug.h | 6 + tools/include/linux/compiler.h | 8 + tools/include/linux/export.h | 22 + tools/include/linux/init.h | 9 + tools/include/linux/kernel.h | 2 + tools/include/linux/ranges.h | 183 ++++++ tools/include/linux/sections.h | 87 +++ tools/include/linux/string.h | 1 + tools/include/linux/tables.h | 684 +++++++++++++++++++++ tools/linker-tables/.gitignore | 2 + tools/linker-tables/Makefile | 184 ++++++ tools/linker-tables/README | 114 ++++ tools/linker-tables/arch/x86/include/asm/asm.h | 17 + tools/linker-tables/arch/x86/include/asm/boot.h | 1 + .../linker-tables/arch/x86/include/asm/bootparam.h | 32 + tools/linker-tables/arch/x86/include/asm/kprobes.h | 7 + .../linker-tables/arch/x86/include/asm/ps_const.h | 23 + tools/linker-tables/arch/x86/include/asm/ranges.h | 6 + .../arch/x86/include/asm/section-core.h | 1 + tools/linker-tables/arch/x86/include/asm/setup.h | 6 + tools/linker-tables/arch/x86/include/asm/tables.h | 6 + tools/linker-tables/arch/x86/include/asm/x86.h | 4 + .../arch/x86/include/asm/x86_init_fn.h | 169 +++++ tools/linker-tables/arch/x86/kernel/alpha.c | 9 + tools/linker-tables/arch/x86/kernel/alternative.c | 31 + tools/linker-tables/arch/x86/kernel/beta.c | 9 + tools/linker-tables/arch/x86/kernel/head64.c | 58 ++ tools/linker-tables/arch/x86/kernel/init.c | 42 ++ tools/linker-tables/arch/x86/kernel/kasan.c | 10 + tools/linker-tables/arch/x86/kernel/kprobes.c | 51 ++ tools/linker-tables/arch/x86/kernel/vmlinux.lds.S | 277 +++++++++ tools/linker-tables/arch/x86/mm/init.c | 10 + tools/linker-tables/arch/x86/xen/init.c | 13 + tools/linker-tables/drivers/acme.c | 32 + tools/linker-tables/drivers/synth/common.c | 16 + tools/linker-tables/drivers/synth/common.h | 2 + tools/linker-tables/drivers/synth/main.c | 35 ++ tools/linker-tables/drivers/synth/or.S | 39 ++ tools/linker-tables/drivers/synth/synth.h | 2 + tools/linker-tables/drivers/xen-driver.c | 11 + .../include/asm-generic/arch_init_fn.h | 50 ++ tools/linker-tables/include/asm-generic/kprobes.h | 26 + tools/linker-tables/include/linux/bitops.h | 6 + tools/linker-tables/include/linux/init.h | 40 ++ tools/linker-tables/include/linux/kasan.h | 5 + tools/linker-tables/include/linux/kernel.h | 2 + tools/linker-tables/include/linux/kprobes.h | 11 + tools/linker-tables/include/linux/module.h | 14 + tools/linker-tables/include/linux/mutex.h | 17 + tools/linker-tables/include/linux/pci.h | 7 + tools/linker-tables/include/linux/printk.h | 26 + tools/linker-tables/include/linux/ps_const.h | 46 ++ tools/linker-tables/include/linux/sched.h | 9 + tools/linker-tables/include/linux/spinlock.h | 13 + tools/linker-tables/include/linux/start_kernel.h | 1 + tools/linker-tables/include/linux/types.h | 13 + tools/linker-tables/include/linux/workqueue.h | 51 ++ tools/linker-tables/include/xen/xen.h | 4 + tools/linker-tables/kernel/locking/mutex.c | 28 + tools/linker-tables/kernel/locking/spinlock.c | 26 + tools/linker-tables/kernel/main.c | 32 + tools/linker-tables/kernel/workqueue.c | 43 ++ tools/linker-tables/lib/string.c | 26 + tools/linker-tables/main.c | 20 + tools/linker-tables/pci-quirks.c | 13 + tools/linker-tables/pci.c | 29 + 77 files changed, 3303 insertions(+), 5 deletions(-) create mode 100644 tools/arch/x86/include/generated/asm/section-core.h create mode 100644 tools/arch/x86/include/generated/ranges.h create mode 100644 tools/arch/x86/include/generated/tables.h create mode 100644 tools/include/asm-generic/bug.h create mode 100644 tools/include/asm-generic/ranges.h create mode 100644 tools/include/asm-generic/section-core.h create mode 100644 tools/include/asm-generic/tables.h create mode 100644 tools/include/linux/bug.h create mode 100644 tools/include/linux/init.h create mode 100644 tools/include/linux/ranges.h create mode 100644 tools/include/linux/sections.h create mode 100644 tools/include/linux/tables.h create mode 100644 tools/linker-tables/.gitignore create mode 100644 tools/linker-tables/Makefile create mode 100644 tools/linker-tables/README create mode 100644 tools/linker-tables/arch/x86/include/asm/asm.h create mode 100644 tools/linker-tables/arch/x86/include/asm/boot.h create mode 100644 tools/linker-tables/arch/x86/include/asm/bootparam.h create mode 100644 tools/linker-tables/arch/x86/include/asm/kprobes.h create mode 100644 tools/linker-tables/arch/x86/include/asm/ps_const.h create mode 100644 tools/linker-tables/arch/x86/include/asm/ranges.h create mode 100644 tools/linker-tables/arch/x86/include/asm/section-core.h create mode 100644 tools/linker-tables/arch/x86/include/asm/setup.h create mode 100644 tools/linker-tables/arch/x86/include/asm/tables.h create mode 100644 tools/linker-tables/arch/x86/include/asm/x86.h create mode 100644 tools/linker-tables/arch/x86/include/asm/x86_init_fn.h create mode 100644 tools/linker-tables/arch/x86/kernel/alpha.c create mode 100644 tools/linker-tables/arch/x86/kernel/alternative.c create mode 100644 tools/linker-tables/arch/x86/kernel/beta.c create mode 100644 tools/linker-tables/arch/x86/kernel/head64.c create mode 100644 tools/linker-tables/arch/x86/kernel/init.c create mode 100644 tools/linker-tables/arch/x86/kernel/kasan.c create mode 100644 tools/linker-tables/arch/x86/kernel/kprobes.c create mode 100644 tools/linker-tables/arch/x86/kernel/vmlinux.lds.S create mode 100644 tools/linker-tables/arch/x86/mm/init.c create mode 100644 tools/linker-tables/arch/x86/xen/init.c create mode 100644 tools/linker-tables/drivers/acme.c create mode 100644 tools/linker-tables/drivers/synth/common.c create mode 100644 tools/linker-tables/drivers/synth/common.h create mode 100644 tools/linker-tables/drivers/synth/main.c create mode 100644 tools/linker-tables/drivers/synth/or.S create mode 100644 tools/linker-tables/drivers/synth/synth.h create mode 100644 tools/linker-tables/drivers/xen-driver.c create mode 100644 tools/linker-tables/include/asm-generic/arch_init_fn.h create mode 100644 tools/linker-tables/include/asm-generic/kprobes.h create mode 100644 tools/linker-tables/include/linux/bitops.h create mode 100644 tools/linker-tables/include/linux/init.h create mode 100644 tools/linker-tables/include/linux/kasan.h create mode 100644 tools/linker-tables/include/linux/kernel.h create mode 100644 tools/linker-tables/include/linux/kprobes.h create mode 100644 tools/linker-tables/include/linux/module.h create mode 100644 tools/linker-tables/include/linux/mutex.h create mode 100644 tools/linker-tables/include/linux/pci.h create mode 100644 tools/linker-tables/include/linux/printk.h create mode 100644 tools/linker-tables/include/linux/ps_const.h create mode 100644 tools/linker-tables/include/linux/sched.h create mode 100644 tools/linker-tables/include/linux/spinlock.h create mode 100644 tools/linker-tables/include/linux/start_kernel.h create mode 100644 tools/linker-tables/include/linux/types.h create mode 100644 tools/linker-tables/include/linux/workqueue.h create mode 100644 tools/linker-tables/include/xen/xen.h create mode 100644 tools/linker-tables/kernel/locking/mutex.c create mode 100644 tools/linker-tables/kernel/locking/spinlock.c create mode 100644 tools/linker-tables/kernel/main.c create mode 100644 tools/linker-tables/kernel/workqueue.c create mode 100644 tools/linker-tables/lib/string.c create mode 100644 tools/linker-tables/main.c create mode 100644 tools/linker-tables/pci-quirks.c create mode 100644 tools/linker-tables/pci.c
Signature · 1 line
2.11.0
Luis R. Rodriguez
maintainerPATCH v3 1/6 tools: add a userspace tools bug.h
This will be used later by the userspace linker-tables sandbox. As a convenience, include bug.h on kernel.h -- this is not done on upstream kernel.h, however most header files do include bug.h eventually, if we were to only add the ones that need it we'd need to copy a lot of headers to tools for the ony purpose of includeing bug.h. This simplifies that.
--- tools/include/asm-generic/bug.h | 24 ++++++++++++++++++++++++ tools/include/linux/bug.h | 6 ++++++ tools/include/linux/kernel.h | 2 ++ 3 files changed, 32 insertions(+) create mode 100644 tools/include/asm-generic/bug.h create mode 100644 tools/include/linux/bug.h
tools/include/asm-generic/bug.h new file +24 -0
@@ -0,0 +1,24 @@ +#ifndef __TOOLS_ASM_GENERIC_BUG +#define __TOOLS_ASM_GENERIC_BUG + +#include <stdio.h> +#include <stdlib.h> + +#define BUG () do { \ + fprintf(stderr, "----------------------------------------------------------\n"); \ + fprintf (stderr, "BUG on %s at %s: %i\n", __func__, __FILE__, __LINE__); \ + abort(); \ +} \ +while (0) + +#define BUG_ON (cond) do { if (cond) BUG(); } while (0) + +#define WARN_ON (__test) do { \ + if (__test) { \ + fprintf(stderr, "----------------------------------------------------------\n");\ + fprintf (stderr, "WARN_ON on %s at %s: %i\n", __func__, __FILE__, __LINE__); \ + } \ +} \ +while (0) + +#endif /* __TOOLS_ASM_GENERIC_BUG */
tools/include/linux/bug.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _TOOLS_LINUX_BUG_H +#define _TOOLS_LINUX_BUG_H + +#include <asm-generic/bug.h> + +#endif /* _TOOLS_LINUX_BUG_H */
tools/include/linux/kernel.h +2 -0
@@ -5,6 +5,8 @@#include <stddef.h> #include <assert.h> +#include <linux/bug.h> +#define DIV_ROUND_UP (n,d) (((n) + (d) - 1) / (d))#define PERF_ALIGN (x, a) __PERF_ALIGN_MASK(x, (typeof(x))(a)-1)
Signature · 1 line
2.11.0
Luis R. Rodriguez
maintainerPATCH v3 2/6 tools: add init.h for tools
In reply to Luis R. RodriguezStart off with just __ref -- we enalbe you to override, if you do that then you can define your own. The way you'd use this, if you do override, is define your own __ref and then use include_next.
--- tools/include/linux/init.h | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tools/include/linux/init.h
tools/include/linux/init.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef _TOOLS_LINUX_INIT_H +#define _TOOLS_LINUX_INIT_H + +/* this means you can add your own to fit you own userspace needs */ +#ifndef __ref +#define __ref +#endif + +#endif /* _TOOLS_LINUX_INIT_H */
Signature · 1 line
2.11.0
Luis R. Rodriguez
maintainerPATCH v3 3/6 tools: add __used and enable to override
In reply to Luis R. RodriguezThis adds __used, to be used later in the userspace linker-tables sandbox. If any userspace applicaiton wants to override they can add their own definition and then use include_next.
This definition should probably suffice for most uses cases though.
--- tools/include/linux/compiler.h | 6 ++++++ 1 file changed, 6 insertions(+)
tools/include/linux/compiler.h +6 -0
@@ -5,6 +5,12 @@/* The "volatile" is due to gcc bugs */ #define barrier () __asm__ __volatile__("": : :"memory") + +/* You can override as you see fit on your userspace tool */ +#ifndef __used +#define __used __attribute__((__used__)) +#endif +#ifndef __always_inline# define __always_inline inline __attribute__((always_inline))#endif
Signature · 1 line
2.11.0
Luis R. Rodriguez
maintainerPATCH v3 4/6 tools: expand export.h with VMLINUX_SYMBOL()
In reply to Luis R. RodriguezThis will be used later by the linker-table userspace sandbox.
--- tools/include/linux/export.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
tools/include/linux/export.h +22 -0
@@ -1,6 +1,28 @@#ifndef _TOOLS_LINUX_EXPORT_H_#define _TOOLS_LINUX_EXPORT_H_ +/* +* Export symbols from the kernel to modules. Forked from module.h +* to reduce the amount of pointless cruft we feed to gcc when only +* exporting a simple symbol or two. +* +* Try not to add #includes here. It slows compilation and makes kernel +* hackers place grumpy comments in header files. +*/ + +/* Some toolchains use a `_' prefix for all user symbols. */ +#ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX +#define __VMLINUX_SYMBOL (x) _##x +#define __VMLINUX_SYMBOL_STR (x) "_" #x +#else +#define __VMLINUX_SYMBOL (x) x +#define __VMLINUX_SYMBOL_STR (x) #x +#endif + +/* Indirect, so macros are expanded before pasting. */ +#define VMLINUX_SYMBOL (x) __VMLINUX_SYMBOL(x) +#define VMLINUX_SYMBOL_STR (x) __VMLINUX_SYMBOL_STR(x) +#define EXPORT_SYMBOL (sym)#define EXPORT_SYMBOL_GPL (sym)#define EXPORT_SYMBOL_GPL_FUTURE (sym)
Signature · 1 line
2.11.0
Luis R. Rodriguez
maintainerPATCH v3 5/6 tools: add __section() to compiler.h
In reply to Luis R. RodriguezThis will be used later by the userspace linker table.
--- tools/include/linux/compiler.h | 2 ++ 1 file changed, 2 insertions(+)
tools/include/linux/compiler.h +2 -0
@@ -132,4 +132,6 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s#define WRITE_ONCE (x, val) \ ({ union { typeof(x) __val; char __c[1]; } __u = { .__val = (val) }; __write_once_size(&(x), __u.__c, sizeof(x)); __u.__val; }) +#define __section (S ) __attribute__ ((__section__(#S))) +#endif /* _TOOLS_LINUX_COMPILER_H */
Signature · 1 line
2.11.0
Luis R. Rodriguez
maintainerPATCH v3 6/6 tools: add userspace linker table sandbox
In reply to Luis R. RodriguezAdd a userspace sandbox to allow easy experimentation and test extensions with linker tables, section ranges and the new section core definitions.
The userspace sandbox tries to mimic the Linux kernel development flow as much as possible, it however relies on and uses libc. Support is currently only provided to x86_64.
Demo run:
cd tools/linker-tables
make clean; make;
./demo
Initializing x86 bare metal world
x86-init: Number of init entries: 8
Initializing memory ...
Completed initializing memory !
Initializing pci ...
PCI fixup size: 1
Demo: Using LINKTABLE_FOR_EACHfoo_fixup
Demo: Using LINKTABLE_RUN_ALLfoo_fixup
Completed initializing pci !
Number of init entries: 1
Initializing kprobes ...
== OK: test_kprobe_0001 within range!
== OK: test_kprobe_0002 not in range as expected! Completed initializing kprobes !
Initializing kasan ...
Early init for Kasan...
Completed initializing kasan !
Initializing beta ...
Completed initializing beta !
Initializing alpha ...
Completed initializing alpha !
Booting bare metal
Calling start_kernel()...
ACME: Initializing ...
ACME: Finished init ... !
Synthetics: synth_init_or(2) returns: 0xDEADBEEF
Synthetics: ps_shr(0xDEADBEEF, get_demo_shr) returns: 0x0000DEAD
v6: rename table macros as suggested by Andy Shevchenko
v5:
o Use ..rng.* instead of .rng.* as suggested by Nicholas Piggin. This is the typical way to avoid clashes with compiler generated sections.
o moves tools/include/linux/printk.h to tools linker-table/include/linux/printk.h -- we cannot generalize this just yet, more work is needed in terms of providing a namespace for headers for types of ports of kernel functionality to userspace.
o Adjust code according to the latest discussions for the linker tables API (section name macros are now gone).
o Give CONFIG_HAVE_ARCH_PS_CONST for x86 another good 'ol college try, still fails, but this is just a demo anyway. We can amend and fix make this more optimized for x86 later. Thanks Boris!
v4: this patch is new in this series -- added to the kenrel as
suggested by Boris, as otherwise it'd be really hard to keep an external userspace repository in sync.
--- Documentation/sections/linker-tables.rst | 4 +- MAINTAINERS | 1 + include/linux/tables.h | 5 +- tools/Makefile | 3 +- .../arch/x86/include/generated/asm/section-core.h | 1 + tools/arch/x86/include/generated/ranges.h | 1 + tools/arch/x86/include/generated/tables.h | 1 + tools/include/asm-generic/ranges.h | 93 +++ tools/include/asm-generic/section-core.h | 348 +++++++++++ tools/include/asm-generic/tables.h | 48 ++ tools/include/linux/ranges.h | 183 ++++++ tools/include/linux/sections.h | 87 +++ tools/include/linux/string.h | 1 + tools/include/linux/tables.h | 684 +++++++++++++++++++++ tools/linker-tables/.gitignore | 2 + tools/linker-tables/Makefile | 184 ++++++ tools/linker-tables/README | 114 ++++ tools/linker-tables/arch/x86/include/asm/asm.h | 17 + tools/linker-tables/arch/x86/include/asm/boot.h | 1 + .../linker-tables/arch/x86/include/asm/bootparam.h | 32 + tools/linker-tables/arch/x86/include/asm/kprobes.h | 7 + .../linker-tables/arch/x86/include/asm/ps_const.h | 23 + tools/linker-tables/arch/x86/include/asm/ranges.h | 6 + .../arch/x86/include/asm/section-core.h | 1 + tools/linker-tables/arch/x86/include/asm/setup.h | 6 + tools/linker-tables/arch/x86/include/asm/tables.h | 6 + tools/linker-tables/arch/x86/include/asm/x86.h | 4 + .../arch/x86/include/asm/x86_init_fn.h | 169 +++++ tools/linker-tables/arch/x86/kernel/alpha.c | 9 + tools/linker-tables/arch/x86/kernel/alternative.c | 31 + tools/linker-tables/arch/x86/kernel/beta.c | 9 + tools/linker-tables/arch/x86/kernel/head64.c | 58 ++ tools/linker-tables/arch/x86/kernel/init.c | 42 ++ tools/linker-tables/arch/x86/kernel/kasan.c | 10 + tools/linker-tables/arch/x86/kernel/kprobes.c | 51 ++ tools/linker-tables/arch/x86/kernel/vmlinux.lds.S | 277 +++++++++ tools/linker-tables/arch/x86/mm/init.c | 10 + tools/linker-tables/arch/x86/xen/init.c | 13 + tools/linker-tables/drivers/acme.c | 32 + tools/linker-tables/drivers/synth/common.c | 16 + tools/linker-tables/drivers/synth/common.h | 2 + tools/linker-tables/drivers/synth/main.c | 35 ++ tools/linker-tables/drivers/synth/or.S | 39 ++ tools/linker-tables/drivers/synth/synth.h | 2 + tools/linker-tables/drivers/xen-driver.c | 11 + .../include/asm-generic/arch_init_fn.h | 50 ++ tools/linker-tables/include/asm-generic/kprobes.h | 26 + tools/linker-tables/include/linux/bitops.h | 6 + tools/linker-tables/include/linux/init.h | 40 ++ tools/linker-tables/include/linux/kasan.h | 5 + tools/linker-tables/include/linux/kernel.h | 2 + tools/linker-tables/include/linux/kprobes.h | 11 + tools/linker-tables/include/linux/module.h | 14 + tools/linker-tables/include/linux/mutex.h | 17 + tools/linker-tables/include/linux/pci.h | 7 + tools/linker-tables/include/linux/printk.h | 26 + tools/linker-tables/include/linux/ps_const.h | 46 ++ tools/linker-tables/include/linux/sched.h | 9 + tools/linker-tables/include/linux/spinlock.h | 13 + tools/linker-tables/include/linux/start_kernel.h | 1 + tools/linker-tables/include/linux/types.h | 13 + tools/linker-tables/include/linux/workqueue.h | 51 ++ tools/linker-tables/include/xen/xen.h | 4 + tools/linker-tables/kernel/locking/mutex.c | 28 + tools/linker-tables/kernel/locking/spinlock.c | 26 + tools/linker-tables/kernel/main.c | 32 + tools/linker-tables/kernel/workqueue.c | 43 ++ tools/linker-tables/lib/string.c | 26 + tools/linker-tables/main.c | 20 + tools/linker-tables/pci-quirks.c | 13 + tools/linker-tables/pci.c | 29 + 71 files changed, 3232 insertions(+), 5 deletions(-) create mode 100644 tools/arch/x86/include/generated/asm/section-core.h create mode 100644 tools/arch/x86/include/generated/ranges.h create mode 100644 tools/arch/x86/include/generated/tables.h create mode 100644 tools/include/asm-generic/ranges.h create mode 100644 tools/include/asm-generic/section-core.h create mode 100644 tools/include/asm-generic/tables.h create mode 100644 tools/include/linux/ranges.h create mode 100644 tools/include/linux/sections.h create mode 100644 tools/include/linux/tables.h create mode 100644 tools/linker-tables/.gitignore create mode 100644 tools/linker-tables/Makefile create mode 100644 tools/linker-tables/README create mode 100644 tools/linker-tables/arch/x86/include/asm/asm.h create mode 100644 tools/linker-tables/arch/x86/include/asm/boot.h create mode 100644 tools/linker-tables/arch/x86/include/asm/bootparam.h create mode 100644 tools/linker-tables/arch/x86/include/asm/kprobes.h create mode 100644 tools/linker-tables/arch/x86/include/asm/ps_const.h create mode 100644 tools/linker-tables/arch/x86/include/asm/ranges.h create mode 100644 tools/linker-tables/arch/x86/include/asm/section-core.h create mode 100644 tools/linker-tables/arch/x86/include/asm/setup.h create mode 100644 tools/linker-tables/arch/x86/include/asm/tables.h create mode 100644 tools/linker-tables/arch/x86/include/asm/x86.h create mode 100644 tools/linker-tables/arch/x86/include/asm/x86_init_fn.h create mode 100644 tools/linker-tables/arch/x86/kernel/alpha.c create mode 100644 tools/linker-tables/arch/x86/kernel/alternative.c create mode 100644 tools/linker-tables/arch/x86/kernel/beta.c create mode 100644 tools/linker-tables/arch/x86/kernel/head64.c create mode 100644 tools/linker-tables/arch/x86/kernel/init.c create mode 100644 tools/linker-tables/arch/x86/kernel/kasan.c create mode 100644 tools/linker-tables/arch/x86/kernel/kprobes.c create mode 100644 tools/linker-tables/arch/x86/kernel/vmlinux.lds.S create mode 100644 tools/linker-tables/arch/x86/mm/init.c create mode 100644 tools/linker-tables/arch/x86/xen/init.c create mode 100644 tools/linker-tables/drivers/acme.c create mode 100644 tools/linker-tables/drivers/synth/common.c create mode 100644 tools/linker-tables/drivers/synth/common.h create mode 100644 tools/linker-tables/drivers/synth/main.c create mode 100644 tools/linker-tables/drivers/synth/or.S create mode 100644 tools/linker-tables/drivers/synth/synth.h create mode 100644 tools/linker-tables/drivers/xen-driver.c create mode 100644 tools/linker-tables/include/asm-generic/arch_init_fn.h create mode 100644 tools/linker-tables/include/asm-generic/kprobes.h create mode 100644 tools/linker-tables/include/linux/bitops.h create mode 100644 tools/linker-tables/include/linux/init.h create mode 100644 tools/linker-tables/include/linux/kasan.h create mode 100644 tools/linker-tables/include/linux/kernel.h create mode 100644 tools/linker-tables/include/linux/kprobes.h create mode 100644 tools/linker-tables/include/linux/module.h create mode 100644 tools/linker-tables/include/linux/mutex.h create mode 100644 tools/linker-tables/include/linux/pci.h create mode 100644 tools/linker-tables/include/linux/printk.h create mode 100644 tools/linker-tables/include/linux/ps_const.h create mode 100644 tools/linker-tables/include/linux/sched.h create mode 100644 tools/linker-tables/include/linux/spinlock.h create mode 100644 tools/linker-tables/include/linux/start_kernel.h create mode 100644 tools/linker-tables/include/linux/types.h create mode 100644 tools/linker-tables/include/linux/workqueue.h create mode 100644 tools/linker-tables/include/xen/xen.h create mode 100644 tools/linker-tables/kernel/locking/mutex.c create mode 100644 tools/linker-tables/kernel/locking/spinlock.c create mode 100644 tools/linker-tables/kernel/main.c create mode 100644 tools/linker-tables/kernel/workqueue.c create mode 100644 tools/linker-tables/lib/string.c create mode 100644 tools/linker-tables/main.c create mode 100644 tools/linker-tables/pci-quirks.c create mode 100644 tools/linker-tables/pci.c
Documentation/sections/linker-tables.rst +2 -2
@@ -11,11 +11,11 @@ About Linker tables .. kernel-doc:: include/linux/tables.h :doc: Introduction -Linker table provenance +Linker table provenance and userspace testing --------------------------------------------- .. kernel-doc:: include/linux/tables.h - :doc: Linker table provenance + :doc: Linker table provenance and userspace testing Benefits of using Linker tables ===============================
MAINTAINERS +1 -0
@@ -5415,6 +5415,7 @@ L: [email protected] S: Supported F: include/asm-generic/tables.h F: include/linux/tables.h +F: tools/linker-tables/ F: Documentation/sections/linker-tables.rst GENERIC PHY FRAMEWORK
include/linux/tables.h +3 -2
@@ -35,12 +35,13 @@*/ /** -* DOC: Linker table provenance +* DOC: Linker table provenance and userspace testing * * The Linux implementation of linker tables was inspired by the iPXE linker * table's solution (iPXE commit 67a10ef000cb7 "[contrib] Add rom-o-matic to * contrib "[0]). To see how this code evolved refer to the out of tree -* userspace linker-table tree [1]. +* userspace linker-table tree [1]. Linux has a similar userspace application +* in tools/linker-tables/ to help more easily test adding new extensions. * * Contrary to iPXE's solution which strives to force compilation of * everything using linker tables, Linux's solution allows for developers to be
tools/Makefile +2 -1
@@ -19,6 +19,7 @@ help: @echo ' kvm_stat - top-like utility for displaying kvm statistics' @echo ' leds - LEDs tools' @echo ' lguest - a minimal 32-bit x86 hypervisor' + @echo ' linker-tables - userspace liker table sandbox and related tools' @echo ' net - misc networking tools' @echo ' perf - Linux performance measurement and analysis tool' @echo ' selftests - various kernel selftests'
@@ -86,7 +87,7 @@ tmon: FORCE freefall: FORCE $(call descend,laptop/$@) -all: acpi cgroup cpupower gpio hv firewire lguest \ +all: acpi cgroup cpupower gpio hv firewire lguest linker-tables \ perf selftests turbostat usb \ virtio vm net x86_energy_perf_policy \ tmon freefall objtool
tools/arch/x86/include/generated/asm/section-core.h new file +1 -0
@@ -0,0 +1 @@ +#include <asm-generic/section-core.h>
tools/arch/x86/include/generated/ranges.h new file +1 -0
@@ -0,0 +1 @@ +#include <asm-generic/ranges.h>
tools/arch/x86/include/generated/tables.h new file +1 -0
@@ -0,0 +1 @@ +#include <asm-generic/tables.h>
tools/include/asm-generic/ranges.h new file +93 -0
93 lines not on this page · raw message
tools/include/asm-generic/section-core.h new file +348 -0
348 lines not on this page · raw message
tools/include/asm-generic/tables.h new file +48 -0
48 lines not on this page · raw message
tools/include/linux/ranges.h new file +183 -0
183 lines not on this page · raw message
tools/include/linux/sections.h new file +87 -0
87 lines not on this page · raw message
tools/include/linux/string.h +1 -0
@@ -3,6 +3,7 @@#include <linux/types.h> /* for size_t */ +#include <string.h> void *memdup (const void *src,size_t len);
tools/include/linux/tables.h new file +684 -0
684 lines not on this page · raw message
tools/linker-tables/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +arch/x86/kernel/vmlinux.lds +demo
tools/linker-tables/Makefile new file +184 -0
184 lines not on this page · raw message
tools/linker-tables/README new file +114 -0
114 lines not on this page · raw message
tools/linker-tables/arch/x86/include/asm/asm.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef _ASM_X86_ASM_H + +#ifdef __ASSEMBLY__ +# define __ASM_FORM (x) x +# define __ASM_FORM_RAW (x) x +# define __ASM_FORM_COMMA (x) x, +#else +# define __ASM_FORM (x) " " #x " " +# define __ASM_FORM_RAW (x) #x +# define __ASM_FORM_COMMA (x) " " #x "," +#endif + +# define __ASM_SEL (a,b) __ASM_FORM(b) +# define __ASM_SEL_RAW (a,b) __ASM_FORM_RAW(b) +#define _ASM_PTR __ASM_SEL(.long, .quad) + +#endif /* _ASM_X86_ASM_H */
tools/linker-tables/arch/x86/include/asm/boot.h new file +1 -0
@@ -0,0 +1 @@ +extern struct boot_params boot_params;
tools/linker-tables/arch/x86/include/asm/bootparam.h new file +32 -0
@@ -0,0 +1,32 @@ +#ifndef __BOOTPARAM_H +#define __BOOTPARAM_H + +#include <linux/types.h> + +struct setup_header { +__u32 hardware_subarch; +} __attribute__((packed)); + +struct boot_params { +struct setup_header hdr; +} __attribute__((packed)); + +enum { +X86_SUBARCH_PC =0 , +X86_SUBARCH_LGUEST , +X86_SUBARCH_XEN , +X86_SUBARCH_INTEL_MID , +X86_SUBARCH_CE4100 , +X86_NR_SUBARCHS , +}; + +#define X86_SUBARCH_ALL_SUBARCHS \ + ( \ + BIT(X86_SUBARCH_PC) | \ + BIT(X86_SUBARCH_LGUEST) | \ + BIT(X86_SUBARCH_XEN) | \ + BIT(X86_SUBARCH_INTEL_MID) | \ + BIT(X86_SUBARCH_CE4100) \ + ) + +#endif /* __BOOTPARAM_H */
tools/linker-tables/arch/x86/include/asm/kprobes.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _SANDBOX_ASM_X86_KPROBES_H +#define _SANDBOX_ASM_X86_KPROBES_H + +/* This is all we need for the demo */ +#include <asm-generic/kprobes.h> + +#endif /* _SANDBOX_ASM_X86_KPROBES_H */
tools/linker-tables/arch/x86/include/asm/ps_const.h new file +23 -0
@@ -0,0 +1,23 @@ +#ifndef __X86_PS_CONST +#define __X86_PS_CONST + +#include <linux/stringify.h> +#include <linux/tables.h> +#include <asm/asm.h> + +#define ps_shr (in, _func) \ +({ \ + __typeof__(in) _count; \ + \ + asm volatile( \ + "shr %P[_in],%[_count]\n" \ + "1:\n" \ + push_section_tbl(.init.data, ps_set_const_table, 01,) \ + _ASM_PTR "1b-1, %P2, %P3\n" \ + ".popsection\n" \ + : [_count] "=g" (_count) \ + : [_in] "i" (in), "i" (SET_CONST_U8), "i" (_func)); \ + (_count); \ +}) + +#endif /* __X86_PS_CONST */
tools/linker-tables/arch/x86/include/asm/ranges.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _ASM_X86_RANGES_H +#define _ASM_X86_RANGES_H + +#include <asm-generic/ranges.h> + +#endif /* _ASM_X86_RANGES_H */
tools/linker-tables/arch/x86/include/asm/section-core.h new file +1 -0
@@ -0,0 +1 @@ +#include <asm-generic/section-core.h>
tools/linker-tables/arch/x86/include/asm/setup.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef __LINUX_X86_USER_SETUP_H +#define __LINUX_X86_USER_SETUP_H + +/* I'm lazy */ + +#endif /* __LINUX_X86_USER_SETUP_H */
tools/linker-tables/arch/x86/include/asm/tables.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _ASM_X86_TABLES_H +#define _ASM_X86_TABLES_H + +#include <asm-generic/tables.h> + +#endif /* _ASM_X86_RANGES_H */
tools/linker-tables/arch/x86/include/asm/x86.h new file +4 -0
@@ -0,0 +1,4 @@ +int startup_64 (void ); +int x86_64_start_reservations (void ); +void setup_arch (void ); +void late_init (void );
tools/linker-tables/arch/x86/include/asm/x86_init_fn.h new file +169 -0
169 lines not on this page · raw message
tools/linker-tables/arch/x86/kernel/alpha.c new file +9 -0
@@ -0,0 +1,9 @@ +#include <linux/kernel.h> +#include <asm/x86_init_fn.h> + +static void early_init_alpha (void ) { +pr_info ("Initializing alpha ...\n" ); +pr_info ("Completed initializing alpha !\n" ); +} + +x86_init_early_pc (early_init_alpha);
tools/linker-tables/arch/x86/kernel/alternative.c new file +31 -0
@@ -0,0 +1,31 @@ +#include <asm/x86_init_fn.h> + +#include <linux/kernel.h> +#include <linux/ps_const.h> + +void apply_alternatives_linker_tables (void ) +{ +unsigned int num_consts =LINKTABLE_SIZE (ps_set_const_table); +struct ps_set_const *ps_const; + +if (!num_consts) +return ; + +pr_debug ("Number of init entries: %d\n" , num_consts); + +linktable_for_each (ps_const, ps_set_const_table) { +switch (ps_const->type) { +case SET_CONST_U8 : + *ps_const->count = (__u8 ) ps_const->func (); +break ; +case SET_CONST_U16 : + *ps_const->count = (__u16 ) ps_const->func (); +break ; +case SET_CONST_U32 : + *ps_const->count = (__u16 ) ps_const->func (); +break ; + } + } +} + +x86_init_early_pc (apply_alternatives_linker_tables);
tools/linker-tables/arch/x86/kernel/beta.c new file +9 -0
@@ -0,0 +1,9 @@ +#include <linux/kernel.h> +#include <asm/x86_init_fn.h> + +static void early_init_beta (void ) { +pr_info ("Initializing beta ...\n" ); +pr_info ("Completed initializing beta !\n" ); +} + +x86_init_early_pc (early_init_beta);
tools/linker-tables/arch/x86/kernel/head64.c new file +58 -0
58 lines not on this page · raw message
tools/linker-tables/arch/x86/kernel/init.c new file +42 -0
42 lines not on this page · raw message
tools/linker-tables/arch/x86/kernel/kasan.c new file +10 -0
@@ -0,0 +1,10 @@ +#include <linux/kernel.h> +#include <asm/x86_init_fn.h> + +void kasan_early_init (void ) { +pr_info ("Initializing kasan ...\n" ); +pr_info ("Early init for Kasan...\n" ); +pr_info ("Completed initializing kasan !\n" ); +} + +x86_init_early_pc (kasan_early_init);
tools/linker-tables/arch/x86/kernel/kprobes.c new file +51 -0
51 lines not on this page · raw message
tools/linker-tables/arch/x86/kernel/vmlinux.lds.S new file +277 -0
277 lines not on this page · raw message
tools/linker-tables/arch/x86/mm/init.c new file +10 -0
@@ -0,0 +1,10 @@ +#include <linux/kernel.h> +#include <asm/x86_init_fn.h> + +static void early_init_memory (void ) { +pr_info ("Initializing memory ...\n" ); +sleep (1 ); +pr_info ("Completed initializing memory !\n" ); +} + +x86_init_early_all (early_init_memory);
tools/linker-tables/arch/x86/xen/init.c new file +13 -0
@@ -0,0 +1,13 @@ +#include <linux/kernel.h> +#include <linux/tables.h> +#include <asm/x86_init_fn.h> +#include <asm/x86.h> + +void startup_xen (void ) +{ +pr_info ("Initializing Xen guest\n" ); + +x86_init_fn_early_init (); + +x86_64_start_reservations (); +}
tools/linker-tables/drivers/acme.c new file +32 -0
@@ -0,0 +1,32 @@ +#define pr_fmt (fmt) "ACME: " fmt + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/workqueue.h> + +void *acme_todo (void *arg); +static DECLARE_WORK(acme_work, acme_todo); + +void *acme_todo (void *arg) +{ +pr_info ("Running scheduled work\n" ); +pthread_exit (NULL ); +} + +static int acme_init_driver (void ) { +pr_info ("Initializing ...\n" ); +sleep (2 ); +pr_info ("Finished init ... !\n" ); + +init_work (&acme_work); +schedule_work (&acme_work); + +return 0 ; +} +module_init (acme_init_driver); + +static void acme_exit (void ) +{ +cancel_work_sync (&acme_work); +}; +module_exit (acme_exit);
tools/linker-tables/drivers/synth/common.c new file +16 -0
@@ -0,0 +1,16 @@ +int demo_or_1 (int arg) +{ +switch (arg) { +case 1 : +return 0xDEA00000 ; +case 2 : +return 0X000D0000 ; +default : +return arg *2 ; + } +} + +int demo_or_2 (void ) +{ +return 0x0000BEEF ; +}
tools/linker-tables/drivers/synth/common.h new file +2 -0
@@ -0,0 +1,2 @@ +int demo_or_1 (int arg); +int demo_or_2 (void );
tools/linker-tables/drivers/synth/main.c new file +35 -0
@@ -0,0 +1,35 @@ +#define pr_fmt (fmt) "Synthetics: " fmt + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/ps_const.h> + +#include "common.h" +#include "synth.h" + +DEFINE_LINKTABLE_INIT_DATA(struct ps_set_const, ps_set_const_table); + +unsigned int get_demo_shr (void ) +{ +return 16 ; +} + +static int synth_init (void ) +{ +int synth_or; +int val =2 ; +const unsigned int reg =ps_shr (0xDEADBEEF , get_demo_shr); + + synth_or =synth_init_or (val); +pr_info ("synth_init_or(%d) returns: 0x%08X\n" , val, synth_or); + +pr_info ("ps_shr(0x%08X, get_demo_shr) returns: 0x%08X\n" ,0xDEADBEEF , reg); + +return 0 ; +} +module_init (synth_init); + +static void synth_exit (void ) +{ +} +module_exit (synth_exit);
tools/linker-tables/drivers/synth/or.S new file +39 -0
@@ -0,0 +1,39 @@ +#include <asm/ranges.h> + + DEFINE_SECTION_RANGE(.text, synth_init_or) + + push_section_rng_level(.text, synth_init_or, "01", ) + /* err = 0; */ + pushq %rbp + movq %rsp,%rbp + pushq %rbx + xorq %rbx,%rbx + .popsection + + push_section_rng_level(.text, synth_init_or, "99", ) + /* return err; */ + movq %rbx,%rax + popq %rbx + popq %rbp + retq + .popsection + + push_section_rng_level(.text, synth_init_or, "50", ) + /* err |= demo_or_1(1); */ + movl $1,%edi + call demo_or_1 + orq %rax,%rbx + .popsection + + push_section_rng_level(.text, synth_init_or, "50", ) + /* err |= demo_or_1(2); */ + movl $2,%edi + call demo_or_1 + orq %rax,%rbx + .popsection + + push_section_rng_level(.text, synth_init_or, "50", ) + /* err |= demo_or_2(); */ + call demo_or_2 + orq %rax,%rbx + .popsection
tools/linker-tables/drivers/synth/synth.h new file +2 -0
@@ -0,0 +1,2 @@ +/* Synthetic demos go here */ +int synth_init_or (int arg);
tools/linker-tables/drivers/xen-driver.c new file +11 -0
@@ -0,0 +1,11 @@ +#include <asm/x86_init_fn.h> +#include <linux/kernel.h> +#include <linux/pci.h> +#include <xen/xen.h> + +static void early_xen_init_driver (void ) { +pr_info ("Initializing xen driver\n" ); +sleep (2 ); +} + +x86_init_early_xen (early_xen_init_driver);
tools/linker-tables/include/asm-generic/arch_init_fn.h new file +50 -0
50 lines not on this page · raw message
tools/linker-tables/include/asm-generic/kprobes.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef _SANDBOX_ASM_GENERIC_KPROBES_H +#define _SANDBOX_ASM_GENERIC_KPROBES_H + +#if defined(__KERNEL__) && !defined(__ASSEMBLY__) +#ifdef CONFIG_KPROBES +#include <linux/tables.h> +#include <asm/ranges.h> +/* +* Blacklist ganerating macro. Specify functions which is not probed +* by using this macro. +*/ +# define __NOKPROBE_SYMBOL (fname) \ +static LINKTABLE_INIT_DATA(_kprobe_blacklist, all) \ + _kbl_addr_##fname = (unsigned long)fname; +# define NOKPROBE_SYMBOL (fname) __NOKPROBE_SYMBOL(fname) +/* Use this to forbid a kprobes attach on very low level functions */ +# define __kprobes __LINUX_RANGE(.text, kprobes) +# define nokprobe_inline __always_inline +#else +# define NOKPROBE_SYMBOL (fname) +# define __kprobes +# define nokprobe_inline inline +#endif +#endif /* defined(__KERNEL__) && !defined(__ASSEMBLY__) */ + +#endif /* _SANDBOX_ASM_GENERIC_KPROBES_H */
tools/linker-tables/include/linux/bitops.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _LINUX_BITOPS_H +#define _LINUX_BITOPS_H + +#define BIT (nr) (1UL << (nr)) + +#endif /* _LINUX_BITOPS_H */
tools/linker-tables/include/linux/init.h new file +40 -0
@@ -0,0 +1,40 @@ +#ifndef _SANDBOX_LINUX_INIT_H +#define _SANDBOX_LINUX_INIT_H + +#include_next <linux/init.h> +#include <linux/types.h> +#include <linux/sections.h> + +#define __init __section(.init.text) +#define __exit __section(.exit.text) + +#ifndef __ASSEMBLY__ +#include <linux/tables.h> +typedef int (*initcall_t )(void ); +typedef void (*exitcall_t )(void ); + +DECLARE_LINKTABLE (initcall_t, init_calls); +DECLARE_LINKTABLE (exitcall_t, exit_calls); + +#define __define_initcall (fn, id) \ + static LINKTABLE_INIT_DATA(init_calls, id) \ + __initcall_##fn##id = fn + +#define pure_initcall (fn) __define_initcall(fn, 0) +#define core_initcall (fn) __define_initcall(fn, 1) +#define postcore_initcall (fn) __define_initcall(fn, 2) +#define arch_initcall (fn) __define_initcall(fn, 3) +#define subsys_initcall (fn) __define_initcall(fn, 4) +#define fs_initcall (fn) __define_initcall(fn, 5) +#define device_initcall (fn) __define_initcall(fn, 6) +#define late_initcall (fn) __define_initcall(fn, 7) + +#define __initcall (fn) device_initcall(fn) + +#define __exitcall (fn) \ + static LINKTABLE_INIT_DATA(exit_calls, any) \ + __exitcall_##fn = fn; + +#endif + +#endif /* _SANDBOX_LINUX_INIT_H */
tools/linker-tables/include/linux/kasan.h new file +5 -0
@@ -0,0 +1,5 @@ +#include <linux/types.h> + +void kasan_early_init (void ); +int kasan_init (void ); +bool is_kasan_setup (void );
tools/linker-tables/include/linux/kernel.h new file +2 -0
@@ -0,0 +1,2 @@ +#include_next <linux/kernel.h> +#include <linux/printk.h>
tools/linker-tables/include/linux/kprobes.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef _SANDBOX_LINUX_KPROBES_H +#define _SANDBOX_LINUX_KPROBES_H + +#include <asm/kprobes.h> +#include <linux/ranges.h> + +#ifdef CONFIG_KPROBES +DECLARE_SECTION_RANGE (kprobes); +#endif + +#endif /* _SANDBOX_LINUX_KPROBES_H */
tools/linker-tables/include/linux/module.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef _LINUX_MODULE_H +#define _LINUX_MODULE_H + +#include <linux/init.h> + +#define module_init (x) __initcall(x); +#define module_exit (x) __exitcall(x); + +struct module { +int (*init)(void ); +void (*exit)(void ); +}; + +#endif /* _LINUX_MODULE_H */
tools/linker-tables/include/linux/mutex.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef __LINUX_MUTEX_H +#define __LINUX_MUTEX_H + +#include <sys/types.h> +#include <linux/sched.h> +#include <pthread.h> + +struct mutex { +pthread_mutex_t lock; +}; + +void mutex_init (struct mutex *lock); +void mutex_destroy (struct mutex *lock); +void mutex_lock (struct mutex *lock); +void mutex_unlock (struct mutex *lock); + +#endif /* __LINUX_MUTEX_H */
tools/linker-tables/include/linux/pci.h new file +7 -0
@@ -0,0 +1,7 @@ +#include <linux/types.h> + +struct pci_fixup { +void (*hook)(void ); +}; + +bool detect_pci (void );
tools/linker-tables/include/linux/printk.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef _SANDBOX_KERNEL_PRINTK +#define _SANDBOX_KERNEL_PRINTK + +#ifdef __KERNEL__ + +#include <stdio.h> + +#ifndef pr_fmt +#define pr_fmt (fmt) fmt +#endif + +#ifndef pr_info +#define pr_info (fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__) +#endif + +#ifndef pr_err +#define pr_err (fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__) +#endif + +#ifndef pr_debug +#define pr_debug (fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__) +#endif + +#endif /* __KERNEL__ */ + +#endif /* _SANDBOX_KERNEL_PRINTK */
tools/linker-tables/include/linux/ps_const.h new file +46 -0
46 lines not on this page · raw message
tools/linker-tables/include/linux/sched.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef _LINUX_SCHED_H +#define _LINUX_SCHED_H + +#include <linux/ranges.h> + +DECLARE_SECTION_RANGE (sched_text); +#define __sched __LINUX_RANGE(.text, sched_text) + +#endif /* _LINUX_SCHED_H */
tools/linker-tables/include/linux/spinlock.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef __LINUX_SPINLOCK_H +#define __LINUX_SPINLOCK_H + +#include <pthread.h> + +#define spinlock_t pthread_spinlock_t + +void spin_lock_init (spinlock_t *lock); +void spin_lock_destroy (spinlock_t *lock); +void spin_lock (spinlock_t *lock); +void spin_unlock (spinlock_t *lock); + +#endif /* __LINUX_SPINLOCK_H */
tools/linker-tables/include/linux/start_kernel.h new file +1 -0
@@ -0,0 +1 @@ +int start_kernel (void );
tools/linker-tables/include/linux/types.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef __LINUX_USER_TYPES_H +#define __LINUX_USER_TYPES_H + +#include <stdbool.h> +#include <stdint.h>
Lines of this file are not shown. View the raw message.
tools/linker-tables/include/linux/workqueue.h new file +51 -0
51 lines not on this page · raw message
tools/linker-tables/include/xen/xen.h new file +4 -0
Lines of this file are not shown. View the raw message.
tools/linker-tables/kernel/locking/mutex.c new file +28 -0
Lines of this file are not shown. View the raw message.
tools/linker-tables/kernel/locking/spinlock.c new file +26 -0
Lines of this file are not shown. View the raw message.
tools/linker-tables/kernel/main.c new file +32 -0
Lines of this file are not shown. View the raw message.
tools/linker-tables/kernel/workqueue.c new file +43 -0
43 lines not on this page · raw message
tools/linker-tables/lib/string.c new file +26 -0
Lines of this file are not shown. View the raw message.
tools/linker-tables/pci-quirks.c new file +13 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.11.0
Part of the diff is not shown here. View the raw message.
Luis R. Rodriguez
maintainerv4 cover tools: add linker table userspace sandbox
In reply to Luis R. RodriguezThis v4 also addresses some spelling / checkpatch comlplains. The remaining checkpatch complaints are not valid for the code in question. This applies after the series:
[PATCH v7 00/14] linux: generalize sections, ranges and linker tables
Luis R. Rodriguez (6):
tools: add a userspace tools bug.h
tools: add init.h for tools
tools: add __used and enable to override
tools: expand export.h with VMLINUX_SYMBOL()
tools: add __section() to compiler.h
tools: add userspace linker table sandbox
Documentation/sections/linker-tables.rst | 4 +- MAINTAINERS | 1 + include/linux/tables.h | 5 +- tools/Makefile | 3 +- .../arch/x86/include/generated/asm/section-core.h | 1 + tools/arch/x86/include/generated/ranges.h | 1 + tools/arch/x86/include/generated/tables.h | 1 + tools/include/asm-generic/bug.h | 26 + tools/include/asm-generic/ranges.h | 93 +++ tools/include/asm-generic/section-core.h | 348 +++++++++++ tools/include/asm-generic/tables.h | 48 ++ tools/include/linux/bug.h | 6 + tools/include/linux/compiler.h | 8 + tools/include/linux/export.h | 22 + tools/include/linux/init.h | 9 + tools/include/linux/kernel.h | 2 + tools/include/linux/ranges.h | 183 ++++++ tools/include/linux/sections.h | 87 +++ tools/include/linux/string.h | 1 + tools/include/linux/tables.h | 684 +++++++++++++++++++++ tools/linker-tables/.gitignore | 2 + tools/linker-tables/Makefile | 184 ++++++ tools/linker-tables/README | 114 ++++ tools/linker-tables/arch/x86/include/asm/asm.h | 17 + tools/linker-tables/arch/x86/include/asm/boot.h | 1 + .../linker-tables/arch/x86/include/asm/bootparam.h | 32 + tools/linker-tables/arch/x86/include/asm/kprobes.h | 7 + .../linker-tables/arch/x86/include/asm/ps_const.h | 23 + tools/linker-tables/arch/x86/include/asm/ranges.h | 6 + .../arch/x86/include/asm/section-core.h | 1 + tools/linker-tables/arch/x86/include/asm/setup.h | 6 + tools/linker-tables/arch/x86/include/asm/tables.h | 6 + tools/linker-tables/arch/x86/include/asm/x86.h | 4 + .../arch/x86/include/asm/x86_init_fn.h | 169 +++++ tools/linker-tables/arch/x86/kernel/alpha.c | 10 + tools/linker-tables/arch/x86/kernel/alternative.c | 31 + tools/linker-tables/arch/x86/kernel/beta.c | 10 + tools/linker-tables/arch/x86/kernel/head64.c | 58 ++ tools/linker-tables/arch/x86/kernel/init.c | 42 ++ tools/linker-tables/arch/x86/kernel/kasan.c | 11 + tools/linker-tables/arch/x86/kernel/kprobes.c | 51 ++ tools/linker-tables/arch/x86/kernel/vmlinux.lds.S | 277 +++++++++ tools/linker-tables/arch/x86/mm/init.c | 11 + tools/linker-tables/arch/x86/xen/init.c | 13 + tools/linker-tables/drivers/acme.c | 33 + tools/linker-tables/drivers/synth/common.c | 16 + tools/linker-tables/drivers/synth/common.h | 2 + tools/linker-tables/drivers/synth/main.c | 36 ++ tools/linker-tables/drivers/synth/or.S | 39 ++ tools/linker-tables/drivers/synth/synth.h | 2 + tools/linker-tables/drivers/xen-driver.c | 12 + .../include/asm-generic/arch_init_fn.h | 50 ++ tools/linker-tables/include/asm-generic/kprobes.h | 26 + tools/linker-tables/include/linux/bitops.h | 6 + tools/linker-tables/include/linux/init.h | 40 ++ tools/linker-tables/include/linux/kasan.h | 5 + tools/linker-tables/include/linux/kernel.h | 2 + tools/linker-tables/include/linux/kprobes.h | 11 + tools/linker-tables/include/linux/module.h | 14 + tools/linker-tables/include/linux/mutex.h | 17 + tools/linker-tables/include/linux/pci.h | 7 + tools/linker-tables/include/linux/printk.h | 26 + tools/linker-tables/include/linux/ps_const.h | 46 ++ tools/linker-tables/include/linux/sched.h | 9 + tools/linker-tables/include/linux/spinlock.h | 13 + tools/linker-tables/include/linux/start_kernel.h | 1 + tools/linker-tables/include/linux/types.h | 13 + tools/linker-tables/include/linux/workqueue.h | 51 ++ tools/linker-tables/include/xen/xen.h | 4 + tools/linker-tables/kernel/locking/mutex.c | 28 + tools/linker-tables/kernel/locking/spinlock.c | 26 + tools/linker-tables/kernel/main.c | 32 + tools/linker-tables/kernel/workqueue.c | 43 ++ tools/linker-tables/lib/string.c | 26 + tools/linker-tables/main.c | 20 + tools/linker-tables/pci-quirks.c | 14 + tools/linker-tables/pci.c | 30 + 77 files changed, 3314 insertions(+), 5 deletions(-) create mode 100644 tools/arch/x86/include/generated/asm/section-core.h create mode 100644 tools/arch/x86/include/generated/ranges.h create mode 100644 tools/arch/x86/include/generated/tables.h create mode 100644 tools/include/asm-generic/bug.h create mode 100644 tools/include/asm-generic/ranges.h create mode 100644 tools/include/asm-generic/section-core.h create mode 100644 tools/include/asm-generic/tables.h create mode 100644 tools/include/linux/bug.h create mode 100644 tools/include/linux/init.h create mode 100644 tools/include/linux/ranges.h create mode 100644 tools/include/linux/sections.h create mode 100644 tools/include/linux/tables.h create mode 100644 tools/linker-tables/.gitignore create mode 100644 tools/linker-tables/Makefile create mode 100644 tools/linker-tables/README create mode 100644 tools/linker-tables/arch/x86/include/asm/asm.h create mode 100644 tools/linker-tables/arch/x86/include/asm/boot.h create mode 100644 tools/linker-tables/arch/x86/include/asm/bootparam.h create mode 100644 tools/linker-tables/arch/x86/include/asm/kprobes.h create mode 100644 tools/linker-tables/arch/x86/include/asm/ps_const.h create mode 100644 tools/linker-tables/arch/x86/include/asm/ranges.h create mode 100644 tools/linker-tables/arch/x86/include/asm/section-core.h create mode 100644 tools/linker-tables/arch/x86/include/asm/setup.h create mode 100644 tools/linker-tables/arch/x86/include/asm/tables.h create mode 100644 tools/linker-tables/arch/x86/include/asm/x86.h create mode 100644 tools/linker-tables/arch/x86/include/asm/x86_init_fn.h create mode 100644 tools/linker-tables/arch/x86/kernel/alpha.c create mode 100644 tools/linker-tables/arch/x86/kernel/alternative.c create mode 100644 tools/linker-tables/arch/x86/kernel/beta.c create mode 100644 tools/linker-tables/arch/x86/kernel/head64.c create mode 100644 tools/linker-tables/arch/x86/kernel/init.c create mode 100644 tools/linker-tables/arch/x86/kernel/kasan.c create mode 100644 tools/linker-tables/arch/x86/kernel/kprobes.c create mode 100644 tools/linker-tables/arch/x86/kernel/vmlinux.lds.S create mode 100644 tools/linker-tables/arch/x86/mm/init.c create mode 100644 tools/linker-tables/arch/x86/xen/init.c create mode 100644 tools/linker-tables/drivers/acme.c create mode 100644 tools/linker-tables/drivers/synth/common.c create mode 100644 tools/linker-tables/drivers/synth/common.h create mode 100644 tools/linker-tables/drivers/synth/main.c create mode 100644 tools/linker-tables/drivers/synth/or.S create mode 100644 tools/linker-tables/drivers/synth/synth.h create mode 100644 tools/linker-tables/drivers/xen-driver.c create mode 100644 tools/linker-tables/include/asm-generic/arch_init_fn.h create mode 100644 tools/linker-tables/include/asm-generic/kprobes.h create mode 100644 tools/linker-tables/include/linux/bitops.h create mode 100644 tools/linker-tables/include/linux/init.h create mode 100644 tools/linker-tables/include/linux/kasan.h create mode 100644 tools/linker-tables/include/linux/kernel.h create mode 100644 tools/linker-tables/include/linux/kprobes.h create mode 100644 tools/linker-tables/include/linux/module.h create mode 100644 tools/linker-tables/include/linux/mutex.h create mode 100644 tools/linker-tables/include/linux/pci.h create mode 100644 tools/linker-tables/include/linux/printk.h create mode 100644 tools/linker-tables/include/linux/ps_const.h create mode 100644 tools/linker-tables/include/linux/sched.h create mode 100644 tools/linker-tables/include/linux/spinlock.h create mode 100644 tools/linker-tables/include/linux/start_kernel.h create mode 100644 tools/linker-tables/include/linux/types.h create mode 100644 tools/linker-tables/include/linux/workqueue.h create mode 100644 tools/linker-tables/include/xen/xen.h create mode 100644 tools/linker-tables/kernel/locking/mutex.c create mode 100644 tools/linker-tables/kernel/locking/spinlock.c create mode 100644 tools/linker-tables/kernel/main.c create mode 100644 tools/linker-tables/kernel/workqueue.c create mode 100644 tools/linker-tables/lib/string.c create mode 100644 tools/linker-tables/main.c create mode 100644 tools/linker-tables/pci-quirks.c create mode 100644 tools/linker-tables/pci.c
Signature · 1 line
2.11.0
Luis R. Rodriguez
maintainerPATCH v4 1/6 tools: add a userspace tools bug.h
This will be used later by the userspace linker-tables sandbox. As a convenience, include bug.h on kernel.h -- this is not done on upstream kernel.h, however most header files do include bug.h eventually, if we were to only add the ones that need it we'd need to copy a lot of headers to tools for the only purpose of includeing bug.h. This simplifies that.
v4: address ./scripts/checkpatch.pl --codespell complaints
--- tools/include/asm-generic/bug.h | 26 ++++++++++++++++++++++++++ tools/include/linux/bug.h | 6 ++++++ tools/include/linux/kernel.h | 2 ++ 3 files changed, 34 insertions(+) create mode 100644 tools/include/asm-generic/bug.h create mode 100644 tools/include/linux/bug.h
tools/include/asm-generic/bug.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef __TOOLS_ASM_GENERIC_BUG +#define __TOOLS_ASM_GENERIC_BUG + +#include <stdio.h> +#include <stdlib.h> + +#define BUG () do { \ + fprintf(stderr, "------------------------------------------n"); \ + fprintf(stderr, "BUG on %s at %s: %i\n", \ + __func__, __FILE__, __LINE__); \ + abort(); \ +} \ +while (0) + +#define BUG_ON (cond) do { if (cond) BUG(); } while (0) + +#define WARN_ON (__test) do { \ + if (__test) { \ + fprintf(stderr, "----------------------------------n"); \ + fprintf(stderr, "WARN_ON on %s at %s: %i\n", \ + __func__, __FILE__, __LINE__); \ + } \ +} \ +while (0) + +#endif /* __TOOLS_ASM_GENERIC_BUG */
tools/include/linux/bug.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _TOOLS_LINUX_BUG_H +#define _TOOLS_LINUX_BUG_H + +#include <asm-generic/bug.h> + +#endif /* _TOOLS_LINUX_BUG_H */
tools/include/linux/kernel.h +2 -0
@@ -5,6 +5,8 @@#include <stddef.h> #include <assert.h> +#include <linux/bug.h> +#define DIV_ROUND_UP (n,d) (((n) + (d) - 1) / (d))#define PERF_ALIGN (x, a) __PERF_ALIGN_MASK(x, (typeof(x))(a)-1)
Signature · 1 line
2.11.0
Greg KH
maintainerRe: [PATCH v4 1/6] tools: add a userspace tools bug.h
Quoted 1 line · Luis R. Rodriguez
This will be used later by the userspace linker-tables sandbox.
What is that?
Quoted 5 lines
As a convenience, include
bug.honkernel.h-- this is not done on upstreamkernel.h, however most header files do includebug.heventually, if we were to only add the ones that need it we'd need to copy a lot of headers to tools for the only purpose of includeingbug.h.
I can't parse this sentance at all, please simplify or clarify or something so that I understand what is going on here.
Quoted 1 line
This simplifies that.
What is "that"? You can't do that for such a complex previous sentence.
thanks,
greg k-h
Luis R. Rodriguez
maintainerPATCH v4 2/6 tools: add init.h for tools
In reply to Luis R. RodriguezStart off with just __ref -- we enalbe you to override, if you do that then you can define your own. The way you'd use this, if you do override, is define your own __ref and then use include_next.
--- tools/include/linux/init.h | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tools/include/linux/init.h
tools/include/linux/init.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef _TOOLS_LINUX_INIT_H +#define _TOOLS_LINUX_INIT_H + +/* this means you can add your own to fit you own userspace needs */ +#ifndef __ref +#define __ref +#endif + +#endif /* _TOOLS_LINUX_INIT_H */
Signature · 1 line
2.11.0
Greg KH
maintainerRe: [PATCH v4 2/6] tools: add init.h for tools
Quoted 2 lines · Luis R. Rodriguez
Start off with just
__ref-- we enalbe you to override, if you do that then you can define your own.
I have no idea what this means, do you?
Quoted 2 lines
The way you'd use this, if you
do override, is define your own__refand then useinclude_next.
Huh?
Again, please be more specific or clear or something, I have no idea again what this patch is for.
thanks,
greg k-h
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Luis R. Rodriguez
maintainerPATCH v4 3/6 tools: add __used and enable to override
In reply to Luis R. RodriguezThis adds __used, to be used later in the userspace linker-tables sandbox. If any userspace applicaiton wants to override they can add their own definition and then use include_next.
This definition should probably suffice for most uses cases though.
--- tools/include/linux/compiler.h | 6 ++++++ 1 file changed, 6 insertions(+)
tools/include/linux/compiler.h +6 -0
@@ -5,6 +5,12 @@/* The "volatile" is due to gcc bugs */ #define barrier () __asm__ __volatile__("": : :"memory") + +/* You can override as you see fit on your userspace tool */ +#ifndef __used +#define __used __attribute__((__used__)) +#endif +#ifndef __always_inline# define __always_inline inline __attribute__((always_inline))#endif
Signature · 1 line
2.11.0
Greg KH
maintainerRe: [PATCH v4 3/6] tools: add __used and enable to override
Quoted 3 lines · Luis R. Rodriguez
This adds
__used, to be used later in the userspace linker-tables sandbox. If any userspace applicaiton wants to override they can add their own definition and then useinclude_next.
I think you need a spell checker :(
Luis R. Rodriguez
maintainerPATCH v4 4/6 tools: expand export.h with VMLINUX_SYMBOL()
In reply to Luis R. RodriguezThis will be used later by the linker-table userspace sandbox.
--- tools/include/linux/export.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
tools/include/linux/export.h +22 -0
@@ -1,6 +1,28 @@#ifndef _TOOLS_LINUX_EXPORT_H_#define _TOOLS_LINUX_EXPORT_H_ +/* +* Export symbols from the kernel to modules. Forked from module.h +* to reduce the amount of pointless cruft we feed to gcc when only +* exporting a simple symbol or two. +* +* Try not to add #includes here. It slows compilation and makes kernel +* hackers place grumpy comments in header files. +*/ + +/* Some toolchains use a `_' prefix for all user symbols. */ +#ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX +#define __VMLINUX_SYMBOL (x) _##x +#define __VMLINUX_SYMBOL_STR (x) "_" #x +#else +#define __VMLINUX_SYMBOL (x) x +#define __VMLINUX_SYMBOL_STR (x) #x +#endif + +/* Indirect, so macros are expanded before pasting. */ +#define VMLINUX_SYMBOL (x) __VMLINUX_SYMBOL(x) +#define VMLINUX_SYMBOL_STR (x) __VMLINUX_SYMBOL_STR(x) +#define EXPORT_SYMBOL (sym)#define EXPORT_SYMBOL_GPL (sym)#define EXPORT_SYMBOL_GPL_FUTURE (sym)
Signature · 1 line
2.11.0
Greg KH
maintainerRe: [PATCH v4 4/6] tools: expand export.h with VMLINUX_SYMBOL()
Quoted 1 line · Luis R. Rodriguez
This will be used later by the linker-table userspace sandbox.
That does not explan what this is, why it is needed, or anything at all :(
Greg KH
maintainerRe: [PATCH v4 4/6] tools: expand export.h with VMLINUX_SYMBOL()
In reply to Luis R. RodriguezQuoted 12 lines · Luis R. Rodriguez
This will be used later by the linker-table userspace sandbox.
Signed-off-by Luis R. Rodriguez <[email protected]>--- tools/include/linux/export.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)tools/include/linux/export.h +0
-0
tools/include/linux/export.h line 7
Quoted 7 lines
tools/include/linux/export.h +4
-0@@ -1,6 +1,28 @@#ifndef _TOOLS_LINUX_EXPORT_H_#define _TOOLS_LINUX_EXPORT_H_ +/* +* Export symbols from the kernel to modules. Forked from module.h +* to reduce the amount of pointless cruft we feed to gcc when only +* exporting a simple symbol or two.
You copied it, yet did not remove it from the original?
tools/include/linux/export.h line 10
Quoted 3 lines
tools/include/linux/export.h +3
-0+* +* Try not to add #includes here. It slows compilation and makes kernel +* hackers place grumpy comments in header files.
Define "slows" please. I doubt it is measurable, and so, why even mention it here?
thanks,
greg k-h
Luis R. Rodriguez
maintainerPATCH v4 5/6 tools: add __section() to compiler.h
In reply to Luis R. RodriguezThis will be used later by the userspace linker table.
--- tools/include/linux/compiler.h | 2 ++ 1 file changed, 2 insertions(+)
tools/include/linux/compiler.h +2 -0
@@ -132,4 +132,6 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s#define WRITE_ONCE (x, val) \ ({ union { typeof(x) __val; char __c[1]; } __u = { .__val = (val) }; __write_once_size(&(x), __u.__c, sizeof(x)); __u.__val; }) +#define __section (S ) __attribute__ ((__section__(#S))) +#endif /* _TOOLS_LINUX_COMPILER_H */
Signature · 1 line
2.11.0
Greg KH
maintainerRe: [PATCH v4 5/6] tools: add __section() to compiler.h
Quoted 1 line · Luis R. Rodriguez
This will be used later by the userspace linker table.
same comment as the last time you used this sentence as a changelog text...
thanks,
greg k-h